WIP: HLSL: add refection queries for structuredbuffer counter blocks
authorsteve-lunarg <steve_gh@khasekhemwy.net>
Sat, 15 Apr 2017 14:18:16 +0000 (08:18 -0600)
committersteve-lunarg <steve_gh@khasekhemwy.net>
Tue, 18 Apr 2017 18:58:15 +0000 (12:58 -0600)
This adds TProgram::getUniformBlockCounterIndex(int index), which returns the
index the block of the counter buffer associated with the block of the passed in
index, if any, or -1 if none.

Test/baseResults/hlsl.structbuffer.append.frag.out
glslang/MachineIndependent/ShaderLang.cpp
glslang/MachineIndependent/reflection.cpp
glslang/MachineIndependent/reflection.h
glslang/Public/ShaderLang.h
hlsl/hlslParseHelper.cpp

index 53a46d5..323e960 100644 (file)
@@ -6,7 +6,7 @@ gl_FragCoord origin is upper left
 0:7    Function Parameters: 
 0:7      'pos' ( in uint)
 0:?     Sequence
-0:8      move second child to first child ( temp void)
+0:8      move second child to first child ( temp 4-component vector of float)
 0:8        indirect index (layout( row_major std430) buffer 4-component vector of float)
 0:8          @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of float)
 0:8            'sbuf_a' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of float @data})
@@ -70,7 +70,7 @@ gl_FragCoord origin is upper left
 0:7    Function Parameters: 
 0:7      'pos' ( in uint)
 0:?     Sequence
-0:8      move second child to first child ( temp void)
+0:8      move second child to first child ( temp 4-component vector of float)
 0:8        indirect index (layout( row_major std430) buffer 4-component vector of float)
 0:8          @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of float)
 0:8            'sbuf_a' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of float @data})
index 14f2bde..95c16e8 100644 (file)
@@ -1778,6 +1778,7 @@ const char* TProgram::getUniformBlockName(int index) const   { return reflection
 int TProgram::getUniformBlockSize(int index) const           { return reflection->getUniformBlock(index).size; }
 int TProgram::getUniformIndex(const char* name) const        { return reflection->getIndex(name); }
 int TProgram::getUniformBlockIndex(int index) const          { return reflection->getUniform(index).index; }
+int TProgram::getUniformBlockCounterIndex(int index) const   { return reflection->getUniformBlock(index).counterIndex; }
 int TProgram::getUniformType(int index) const                { return reflection->getUniform(index).glDefineType; }
 int TProgram::getUniformBufferOffset(int index) const        { return reflection->getUniform(index).offset; }
 int TProgram::getUniformArraySize(int index) const           { return reflection->getUniform(index).size; }
index f3f28f0..f0566c6 100644 (file)
@@ -707,6 +707,19 @@ void TReflection::buildAttributeReflection(EShLanguage stage, const TIntermediat
     }
 }
 
+// build counter block index associations for buffers
+void TReflection::buildCounterIndices()
+{
+    // search for ones that have counters
+    for (int i = 0; i < int(indexToUniformBlock.size()); ++i) {
+        const TString counterName(indexToUniformBlock[i].name + "@count");
+        const int index = getIndex(counterName);
+
+        if (index >= 0)
+            indexToUniformBlock[i].counterIndex = index;
+    }
+}
+
 // Merge live symbols from 'intermediate' into the existing reflection database.
 //
 // Returns false if the input is too malformed to do this.
@@ -729,6 +742,8 @@ bool TReflection::addStage(EShLanguage stage, const TIntermediate& intermediate)
         function->traverse(&it);
     }
 
+    buildCounterIndices();
+
     return true;
 }
 
index c80d3ea..7a1cc8e 100644 (file)
@@ -57,11 +57,16 @@ class TObjectReflection {
 public:
     TObjectReflection(const TString& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex) :
         name(pName), offset(pOffset),
-        glDefineType(pGLDefineType), size(pSize), index(pIndex), type(pType.clone()) { }
+        glDefineType(pGLDefineType), size(pSize), index(pIndex), counterIndex(-1), type(pType.clone()) { }
 
     void dump() const {
-        printf("%s: offset %d, type %x, size %d, index %d, binding %d\n",
+        printf("%s: offset %d, type %x, size %d, index %d, binding %d",
                name.c_str(), offset, glDefineType, size, index, getBinding() );
+
+        if (counterIndex != -1)
+            printf(", counter %d", counterIndex);
+
+        printf("\n");
     }
 
     const TType* const getType() const { return type; }
@@ -71,6 +76,7 @@ public:
     int glDefineType;
     int size;         // data size in bytes for a block, array size for a (non-block) object that's an array
     int index;
+    int counterIndex;
 
     static TObjectReflection badReflection() { return TObjectReflection(); }
 
@@ -140,6 +146,9 @@ public:
             return it->second;
     }
 
+    // see getIndex(const char*)
+    int getIndex(const TString& name) const { return getIndex(name.c_str()); }
+
     // Thread local size
     unsigned getLocalSize(int dim) const { return dim <= 2 ? localSize[dim] : 0; }
 
@@ -148,6 +157,7 @@ public:
 protected:
     friend class glslang::TReflectionTraverser;
 
+    void buildCounterIndices();
     void buildAttributeReflection(EShLanguage, const TIntermediate&);
 
     // Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex;
index 7ea9446..e5e5050 100644 (file)
@@ -518,6 +518,7 @@ public:
     int getUniformBlockSize(int blockIndex) const;         // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
     int getUniformIndex(const char* name) const;           // can be used for glGetUniformIndices()
     int getUniformBlockIndex(int index) const;             // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
+    int getUniformBlockCounterIndex(int index) const;      // returns block index of associated counter.
     int getUniformType(int index) const;                   // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
     int getUniformBufferOffset(int index) const;           // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
     int getUniformArraySize(int index) const;              // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
index f13a68e..0dde71a 100755 (executable)
@@ -2801,8 +2801,7 @@ void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TInte
             const TType derefType(argArray->getType(), 0);
             lValue->setType(derefType);
 
-            node = intermediate.addAssign(EOpAssign, lValue, rValue, loc); 
-            node->setType(TType(EbtVoid)); // Append is a void return type
+            node = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
 
             break;
         }