Commit 40efe5ce by steve-lunarg

WIP: HLSL: Fix ordering defect if global SB decl after fn param

This change propagates the storage qualifier from the buffer object to its contained array type so that isStructBufferType() realizes it is one. That propagation was happening before only for global variable declarations, so compilation defects would result if the use of a function parameter happened before a global declaration. This fixes that case, whether or not there ever is a global declaration, and regardless of the relative order. This changes the hlsl.structbuffer.fn.frag test to exercise the alternate order. There are no differences to generated SPIR-V for the cases which successfully compiled before.
parent 33f85b6e
StructuredBuffer<uint4> sbuf : register(t10);
RWStructuredBuffer<uint4> sbuf2;
// Not shared, because of type difference.
StructuredBuffer<uint3> sbuf3 : register(t12);
uint4 get(in StructuredBuffer<uint4> sb, uint bufferOffset)
{
......@@ -15,6 +11,11 @@ void set(in RWStructuredBuffer<uint4> sb, uint bufferOffset, uint4 data)
sb[bufferOffset] = data;
}
RWStructuredBuffer<uint4> sbuf2;
// Not shared, because of type difference.
StructuredBuffer<uint3> sbuf3 : register(t12);
float4 main(uint pos : FOO) : SV_Target0
{
set(sbuf2, 2, get(sbuf, 3));
......
......@@ -1874,6 +1874,7 @@ bool HlslGrammar::acceptStructBufferType(TType& type)
TArraySizes unsizedArray;
unsizedArray.addInnerSize(UnsizedArraySize);
templateType->newArraySizes(unsizedArray);
templateType->getQualifier().storage = storage;
// field name is canonical for all structbuffers
templateType->setFieldName("@data");
......
......@@ -5223,10 +5223,6 @@ void HlslParseContext::shareStructBufferType(TType& type)
return compareQualifiers(lhs, rhs) && lhs == rhs;
};
// TString typeName;
// type.appendMangledName(typeName);
// type.setTypeName(typeName);
// This is an exhaustive O(N) search, but real world shaders have
// only a small number of these.
for (int idx = 0; idx < int(structBufferTypes.size()); ++idx) {
......@@ -5241,8 +5237,6 @@ void HlslParseContext::shareStructBufferType(TType& type)
TType* typeCopy = new TType;
typeCopy->shallowCopy(type);
structBufferTypes.push_back(typeCopy);
// structBuffTypes.push_back(type.getWritableStruct());
}
void HlslParseContext::paramFix(TType& type)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment