From 350b94856a5ef49a49237de329be9e43e55519d6 Mon Sep 17 00:00:00 2001 From: steve-lunarg Date: Sat, 15 Apr 2017 08:18:16 -0600 Subject: [PATCH] WIP: HLSL: add refection queries for structuredbuffer counter blocks 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. --- .../baseResults/hlsl.structbuffer.append.frag.out | 4 ++-- glslang/MachineIndependent/ShaderLang.cpp | 1 + glslang/MachineIndependent/reflection.cpp | 15 +++++++++++++++ glslang/MachineIndependent/reflection.h | 14 ++++++++++++-- glslang/Public/ShaderLang.h | 1 + hlsl/hlslParseHelper.cpp | 3 +-- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Test/baseResults/hlsl.structbuffer.append.frag.out b/Test/baseResults/hlsl.structbuffer.append.frag.out index 53a46d5f..323e960c 100644 --- a/Test/baseResults/hlsl.structbuffer.append.frag.out +++ b/Test/baseResults/hlsl.structbuffer.append.frag.out @@ -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}) diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 14f2bde2..95c16e80 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -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; } diff --git a/glslang/MachineIndependent/reflection.cpp b/glslang/MachineIndependent/reflection.cpp index f3f28f02..f0566c64 100644 --- a/glslang/MachineIndependent/reflection.cpp +++ b/glslang/MachineIndependent/reflection.cpp @@ -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; } diff --git a/glslang/MachineIndependent/reflection.h b/glslang/MachineIndependent/reflection.h index c80d3ea9..7a1cc8ed 100644 --- a/glslang/MachineIndependent/reflection.h +++ b/glslang/MachineIndependent/reflection.h @@ -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 TNameToIndex; diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index 7ea94466..e5e50508 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -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) diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index f13a68e5..0dde71af 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -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; }