aboutsummaryrefslogtreecommitdiff
path: root/glslang/MachineIndependent/reflection.cpp
diff options
context:
space:
mode:
authorJohn Kessenich <cepheus@frii.com>2013-11-23 00:44:18 +0000
committerJohn Kessenich <cepheus@frii.com>2013-11-23 00:44:18 +0000
commit5b9f98854c249b53f3f733c422da163d3c7bdb7c (patch)
tree0442c671df74bd2f0343ded4406b99bf0cc9b8ca /glslang/MachineIndependent/reflection.cpp
parentc4a2b94dfa94d05c9b5003dc6eaf814afea53d07 (diff)
downloadglslang-5b9f98854c249b53f3f733c422da163d3c7bdb7c.tar.gz
Reflection: Eliminate redundant arrayed block entries, and use block name instead of instance name for active uniform enumeration.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24182 e7fa87d3-cd2b-0410-9028-fcbf551c1848
Diffstat (limited to 'glslang/MachineIndependent/reflection.cpp')
-rw-r--r--glslang/MachineIndependent/reflection.cpp56
1 files changed, 32 insertions, 24 deletions
diff --git a/glslang/MachineIndependent/reflection.cpp b/glslang/MachineIndependent/reflection.cpp
index 204e5d5c..53f2d52e 100644
--- a/glslang/MachineIndependent/reflection.cpp
+++ b/glslang/MachineIndependent/reflection.cpp
@@ -248,6 +248,7 @@ public:
void blowUpActiveAggregate(const TType& baseType, const TString& baseName, const TList<TIntermBinary*>& derefs,
TList<TIntermBinary*>::const_iterator deref, int offset, int blockIndex, int arraySize)
{
+ // process the part of the derefence chain that was explicit in the shader
TString name = baseName;
const TType* terminalType = &baseType;
for (; deref != derefs.end(); ++deref) {
@@ -256,10 +257,11 @@ public:
int index;
switch (visitNode->getOp()) {
case EOpIndexIndirect:
- // Visit all the indices of this array, and for each one, then add on the remaining dereferencing
+ // Visit all the indices of this array, and for each one add on the remaining dereferencing
for (int i = 0; i < visitNode->getLeft()->getType().getArraySize(); ++i) {
TString newBaseName = name;
- newBaseName.append(TString("[") + String(i) + "]");
+ if (baseType.getBasicType() != EbtBlock)
+ newBaseName.append(TString("[") + String(i) + "]");
TList<TIntermBinary*>::const_iterator nextDeref = deref;
++nextDeref;
TType derefType(*terminalType, 0);
@@ -270,7 +272,8 @@ public:
return;
case EOpIndexDirect:
index = visitNode->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
- name.append(TString("[") + String(index) + "]");
+ if (baseType.getBasicType() != EbtBlock)
+ name.append(TString("[") + String(index) + "]");
break;
case EOpIndexDirectStruct:
index = visitNode->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst();
@@ -371,27 +374,14 @@ public:
// See if we need to record the block itself
bool block = base->getBasicType() == EbtBlock;
if (block) {
- // TODO: how is an array of blocks handled differently?
+ offset = 0;
anonymous = base->getName().compare(0, 6, "__anon") == 0;
- const TString& blockName = anonymous ? base->getType().getTypeName() : base->getType().getTypeName();
- TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(blockName);
- if (it == reflection.nameToIndex.end()) {
- if (base->getType().isArray()) {
- assert(! anonymous);
- for (int e = 0; e < base->getType().getArraySize(); ++e) {
- TString elementName = blockName + "[" + String(e) + "]";
- blockIndex = reflection.indexToUniformBlock.size();
- reflection.nameToIndex[elementName] = blockIndex;
- reflection.indexToUniformBlock.push_back(TObjectReflection(elementName, offset, -1, getBlockSize(base->getType()), -1));
- }
- } else {
- blockIndex = reflection.indexToUniformBlock.size();
- reflection.nameToIndex[blockName] = blockIndex;
- reflection.indexToUniformBlock.push_back(TObjectReflection(blockName, offset, -1, getBlockSize(base->getType()), -1));
- }
+ if (base->getType().isArray()) {
+ assert(! anonymous);
+ for (int e = 0; e < base->getType().getArraySize(); ++e)
+ blockIndex = addBlockName(base->getType().getTypeName() + "[" + String(e) + "]", getBlockSize(base->getType()));
} else
- blockIndex = it->second;
- offset = 0;
+ blockIndex = addBlockName(base->getType().getTypeName(), getBlockSize(base->getType()));
}
// Process the dereference chain, backward, accumulating the pieces for later forward traversal.
@@ -415,11 +405,29 @@ public:
// Put the dereference chain together, forward
TString baseName;
- if (! anonymous)
- baseName = base->getName();
+ if (! anonymous) {
+ if (block)
+ baseName = base->getType().getTypeName();
+ else
+ baseName = base->getName();
+ }
blowUpActiveAggregate(base->getType(), baseName, derefs, derefs.begin(), offset, blockIndex, arraySize);
}
+ int addBlockName(const TString& name, int size)
+ {
+ int blockIndex;
+ TReflection::TNameToIndex::const_iterator it = reflection.nameToIndex.find(name);
+ if (reflection.nameToIndex.find(name) == reflection.nameToIndex.end()) {
+ blockIndex = reflection.indexToUniformBlock.size();
+ reflection.nameToIndex[name] = blockIndex;
+ reflection.indexToUniformBlock.push_back(TObjectReflection(name, -1, -1, size, -1));
+ } else
+ blockIndex = it->second;
+
+ return blockIndex;
+ }
+
//
// Given a function name, find its subroot in the tree, and push it onto the stack of
// functions left to process.