From 5b9f98854c249b53f3f733c422da163d3c7bdb7c Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sat, 23 Nov 2013 00:44:18 +0000 Subject: [PATCH] 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 --- Test/baseResults/reflection.vert.out | 31 +++++++----- Test/reflection.vert | 7 ++- glslang/MachineIndependent/reflection.cpp | 58 +++++++++++++---------- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/Test/baseResults/reflection.vert.out b/Test/baseResults/reflection.vert.out index f1d0b54a..86f4bf06 100644 --- a/Test/baseResults/reflection.vert.out +++ b/Test/baseResults/reflection.vert.out @@ -13,7 +13,7 @@ sampler_2D: offset -1, type 8b5e, size 1, index -1 sampler_2DMSArray: offset -1, type 910b, size 1, index -1 anonMember3: offset 80, type 8b52, size 1, index 0 s.a: offset -1, type 1404, size 1, index -1 -ablock.scalar: offset 12, type 1404, size 1, index 1 +named.scalar: offset 12, type 1404, size 1, index 1 m23: offset 16, type 8b67, size 1, index 0 scalarAfterm23: offset 48, type 1404, size 1, index 0 c_m23: offset 16, type 8b67, size 1, index 2 @@ -21,18 +21,18 @@ c_scalarAfterm23: offset 64, type 1404, size 1, index 2 scalarBeforeArray: offset 96, type 1404, size 1, index 0 floatArray: offset 112, type 1406, size 5, index 0 scalarAfterArray: offset 192, type 1404, size 1, index 0 -ablock.memvec2: offset 48, type 8b50, size 1, index 1 -ablock.memf1: offset 56, type 1406, size 1, index 1 -ablock.memf2: offset 60, type 8b56, size 1, index 1 -ablock.memf3: offset 64, type 1404, size 1, index 1 -ablock.memvec2a: offset 72, type 8b50, size 1, index 1 -ablock.m22: offset 80, type 8b5a, size 7, index 1 +named.memvec2: offset 48, type 8b50, size 1, index 1 +named.memf1: offset 56, type 1406, size 1, index 1 +named.memf2: offset 60, type 8b56, size 1, index 1 +named.memf3: offset 64, type 1404, size 1, index 1 +named.memvec2a: offset 72, type 8b50, size 1, index 1 +named.m22: offset 80, type 8b5a, size 7, index 1 dm22: offset -1, type 8b5a, size 4, index -1 m22: offset 208, type 8b5a, size 3, index 0 -nest.foo.n1.a: offset 0, type 1406, size 1, index 3 -nest.foo.n2.b: offset 16, type 1406, size 1, index 3 -nest.foo.n2.c: offset 20, type 1406, size 1, index 3 -nest.foo.n2.d: offset 24, type 1406, size 1, index 3 +nested.foo.n1.a: offset 0, type 1406, size 1, index 3 +nested.foo.n2.b: offset 16, type 1406, size 1, index 3 +nested.foo.n2.c: offset 20, type 1406, size 1, index 3 +nested.foo.n2.d: offset 24, type 1406, size 1, index 3 deepA[0].d2.d1[2].va: offset -1, type 8b50, size 2, index -1 deepA[1].d2.d1[2].va: offset -1, type 8b50, size 2, index -1 deepB[1].d2.d1[0].va: offset -1, type 8b50, size 2, index -1 @@ -76,11 +76,12 @@ deepD[1].d2.d1[2].b: offset -1, type 8b56, size 1, index -1 deepD[1].d2.d1[3].va: offset -1, type 8b50, size 3, index -1 deepD[1].d2.d1[3].b: offset -1, type 8b56, size 1, index -1 deepD[1].v3: offset -1, type 8b54, size 1, index -1 -arrBl[2].foo: offset 0, type 1406, size 1, index 7 +abl.foo: offset 0, type 1406, size 1, index 7 +abl2.foo: offset 0, type 1406, size 1, index 11 anonMember1: offset 0, type 8b51, size 1, index 0 uf1: offset -1, type 1406, size 1, index -1 uf2: offset -1, type 1406, size 1, index -1 -ablock.member3: offset 32, type 8b52, size 1, index 1 +named.member3: offset 32, type 8b52, size 1, index 1 Uniform block reflection: nameless: offset -1, type ffffffff, size 496, index -1 @@ -91,4 +92,8 @@ abl[0]: offset -1, type ffffffff, size 4, index -1 abl[1]: offset -1, type ffffffff, size 4, index -1 abl[2]: offset -1, type ffffffff, size 4, index -1 abl[3]: offset -1, type ffffffff, size 4, index -1 +abl2[0]: offset -1, type ffffffff, size 4, index -1 +abl2[1]: offset -1, type ffffffff, size 4, index -1 +abl2[2]: offset -1, type ffffffff, size 4, index -1 +abl2[3]: offset -1, type ffffffff, size 4, index -1 diff --git a/Test/reflection.vert b/Test/reflection.vert index 97eba57e..c08ea26a 100644 --- a/Test/reflection.vert +++ b/Test/reflection.vert @@ -123,6 +123,10 @@ uniform abl { float foo; } arrBl[4]; +uniform abl2 { + float foo; +} arrBl2[4]; + void main() { liveFunction1(image_ui2D, sampler_2D, sampler_2DMSArray); @@ -161,5 +165,6 @@ void main() } else f = ufDead3; - f += arrBl[2].foo; + f += arrBl[2].foo + arrBl[0].foo; + f += arrBl2[i].foo; } 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& derefs, TList::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::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? - 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)); - } - } else - blockIndex = it->second; offset = 0; + anonymous = base->getName().compare(0, 6, "__anon") == 0; + 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 = 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.