add reflection queries to return a TType. Fix minor issue with interface names.

- Add new queries: TProgram::getUniformTType and getUniformBlockTType,
  which return a const TType*, or nullptr on a bad index.  These are valid for
  any source language.

- Interface name for HLSL cbuffers is taken from the (only) available declaration name,
  whereas before it was always an empty string, which caused some troubles with reflection
  mapping them all to the same index slot.  This also makes it appear in the SPIR-V binary
  instead of an empty string.

- Print the binding as part of the reflection textual dump.

- TType::clone becomes const.  Needed to call it from a const method, and anyway it doesn't
  change the object it's called on.

- Because the TObjectReflection constructor is called with a TType *reference* (not pointer)
  so that it's guaranteed to pass in a type, and the "badReflection" value should use a nullptr
  there, that now has a dedicated static method to obtain the bad value.  It uses a private
  constructor, so external users can't create one with a nullptr type.
This commit is contained in:
steve-lunarg 2016-09-21 14:19:40 -06:00
parent de97fe0ad4
commit 8ffc36aecc
16 changed files with 407 additions and 283 deletions

View file

@ -109,7 +109,7 @@ public:
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name);
if (it == reflection.nameToIndex.end()) {
reflection.nameToIndex[name] = (int)reflection.indexToAttribute.size();
reflection.indexToAttribute.push_back(TObjectReflection(name, 0, mapToGlType(type), 0, 0));
reflection.indexToAttribute.push_back(TObjectReflection(name, type, 0, mapToGlType(type), 0, 0));
}
}
}
@ -245,7 +245,8 @@ public:
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name);
if (it == reflection.nameToIndex.end()) {
reflection.nameToIndex[name] = (int)reflection.indexToUniform.size();
reflection.indexToUniform.push_back(TObjectReflection(name, offset, mapToGlType(*terminalType), arraySize, blockIndex));
reflection.indexToUniform.push_back(TObjectReflection(name, *terminalType, offset, mapToGlType(*terminalType),
arraySize, blockIndex));
} else if (arraySize > 1) {
int& reflectedArraySize = reflection.indexToUniform[it->second].size;
reflectedArraySize = std::max(arraySize, reflectedArraySize);
@ -296,12 +297,18 @@ public:
if (block) {
offset = 0;
anonymous = IsAnonymous(base->getName());
const TString& blockName = base->getType().getTypeName();
if (base->getType().isArray()) {
TType derefType(base->getType(), 0);
assert(! anonymous);
for (int e = 0; e < base->getType().getCumulativeArraySize(); ++e)
blockIndex = addBlockName(base->getType().getTypeName() + "[" + String(e) + "]", getBlockSize(base->getType()));
blockIndex = addBlockName(blockName + "[" + String(e) + "]", derefType,
getBlockSize(base->getType()));
} else
blockIndex = addBlockName(base->getType().getTypeName(), getBlockSize(base->getType()));
blockIndex = addBlockName(blockName, base->getType(), getBlockSize(base->getType()));
}
// Process the dereference chain, backward, accumulating the pieces for later forward traversal.
@ -334,14 +341,14 @@ public:
blowUpActiveAggregate(base->getType(), baseName, derefs, derefs.begin(), offset, blockIndex, arraySize);
}
int addBlockName(const TString& name, int size)
int addBlockName(const TString& name, const TType& type, int size)
{
int blockIndex;
TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name);
if (reflection.nameToIndex.find(name) == reflection.nameToIndex.end()) {
blockIndex = (int)reflection.indexToUniformBlock.size();
reflection.nameToIndex[name] = blockIndex;
reflection.indexToUniformBlock.push_back(TObjectReflection(name, -1, -1, size, -1));
reflection.indexToUniformBlock.push_back(TObjectReflection(name, type, -1, -1, size, -1));
} else
blockIndex = it->second;