Commit 898f5fbe by LoopDawg

HLSL: fix qualifier propagation from user struct types to block definitions.

The HLSL FE tracks four versions of a declared type to avoid losing information, since it is not (at type-decl time) known how the type will be used downstream. If such a type was used in a cbuffer declaration, the cbuffer type's members should have been using the uniform form of the original user structure type, but were not. This would manifest as matrix qualifiers (and other things, such as pack offsets) on user struct members going missing in the SPIR-V module if the struct type was a member of a cbuffer, like so: struct MyBuffer { row_major float4x4 mat1; column_major float4x4 mat2; }; cbuffer Example { MyBuffer g_MyBuffer; }; Fixes: #789
parent 2b4f77f2
...@@ -68,7 +68,7 @@ using depth_greater ...@@ -68,7 +68,7 @@ using depth_greater
0:15 3 (const int) 0:15 3 (const int)
0:? Linker Objects 0:? Linker Objects
0:? 'anon@0' (layout( row_major std140) uniform block{ uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} s}) 0:? 'anon@0' (layout( row_major std140) uniform block{ uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} s})
0:? 'anon@1' (layout( row_major std140) uniform block{layout( row_major std140 offset=88) uniform structure{ temp float f, temp float g, temp float d, temp 4-component vector of float normal} t}) 0:? 'anon@1' (layout( row_major std140) uniform block{layout( row_major std140 offset=88) uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} t})
0:? 'f' (layout( location=0) out float) 0:? 'f' (layout( location=0) out float)
0:? 'g' (layout( location=1) out float) 0:? 'g' (layout( location=1) out float)
0:? 'd' ( out float FragDepth) 0:? 'd' ( out float FragDepth)
...@@ -151,7 +151,7 @@ using depth_greater ...@@ -151,7 +151,7 @@ using depth_greater
0:15 3 (const int) 0:15 3 (const int)
0:? Linker Objects 0:? Linker Objects
0:? 'anon@0' (layout( row_major std140) uniform block{ uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} s}) 0:? 'anon@0' (layout( row_major std140) uniform block{ uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} s})
0:? 'anon@1' (layout( row_major std140) uniform block{layout( row_major std140 offset=88) uniform structure{ temp float f, temp float g, temp float d, temp 4-component vector of float normal} t}) 0:? 'anon@1' (layout( row_major std140) uniform block{layout( row_major std140 offset=88) uniform structure{layout( offset=68) temp float f, temp float g, temp float d, temp 4-component vector of float normal} t})
0:? 'f' (layout( location=0) out float) 0:? 'f' (layout( location=0) out float)
0:? 'g' (layout( location=1) out float) 0:? 'g' (layout( location=1) out float)
0:? 'd' ( out float FragDepth) 0:? 'd' ( out float FragDepth)
...@@ -163,7 +163,7 @@ using depth_greater ...@@ -163,7 +163,7 @@ using depth_greater
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 66 // Id's are bound by 65
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
...@@ -200,14 +200,9 @@ using depth_greater ...@@ -200,14 +200,9 @@ using depth_greater
Name 59 "$Global" Name 59 "$Global"
MemberName 59($Global) 0 "s" MemberName 59($Global) 0 "s"
Name 61 "" Name 61 ""
Name 62 "T" Name 62 "buff"
MemberName 62(T) 0 "f" MemberName 62(buff) 0 "t"
MemberName 62(T) 1 "g" Name 64 ""
MemberName 62(T) 2 "d"
MemberName 62(T) 3 "normal"
Name 63 "buff"
MemberName 63(buff) 0 "t"
Name 65 ""
Decorate 22(f) Location 0 Decorate 22(f) Location 0
Decorate 27(g) Centroid Decorate 27(g) Centroid
Decorate 27(g) Location 1 Decorate 27(g) Location 1
...@@ -224,13 +219,9 @@ using depth_greater ...@@ -224,13 +219,9 @@ using depth_greater
MemberDecorate 59($Global) 0 Offset 0 MemberDecorate 59($Global) 0 Offset 0
Decorate 59($Global) Block Decorate 59($Global) Block
Decorate 61 DescriptorSet 0 Decorate 61 DescriptorSet 0
MemberDecorate 62(T) 0 Offset 0 MemberDecorate 62(buff) 0 Offset 96
MemberDecorate 62(T) 1 Offset 4 Decorate 62(buff) Block
MemberDecorate 62(T) 2 Offset 8 Decorate 64 DescriptorSet 0
MemberDecorate 62(T) 3 Offset 16
MemberDecorate 63(buff) 0 Offset 96
Decorate 63(buff) Block
Decorate 65 DescriptorSet 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
...@@ -261,10 +252,9 @@ using depth_greater ...@@ -261,10 +252,9 @@ using depth_greater
59($Global): TypeStruct 58(T) 59($Global): TypeStruct 58(T)
60: TypePointer Uniform 59($Global) 60: TypePointer Uniform 59($Global)
61: 60(ptr) Variable Uniform 61: 60(ptr) Variable Uniform
62(T): TypeStruct 6(float) 6(float) 6(float) 7(fvec4) 62(buff): TypeStruct 58(T)
63(buff): TypeStruct 62(T) 63: TypePointer Uniform 62(buff)
64: TypePointer Uniform 63(buff) 64: 63(ptr) Variable Uniform
65: 64(ptr) Variable Uniform
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
18(t): 9(ptr) Variable Function 18(t): 9(ptr) Variable Function
......
struct MyBuffer1
{
column_major float4x4 mat1;
row_major float4x4 mat2;
float4 vec1;
float foo;
};
struct MyBuffer2
{
row_major float4x4 mat1;
float4 vec1;
};
cbuffer Example
{
MyBuffer1 g_MyBuffer1;
MyBuffer2 g_MyBuffer2;
column_major float4x4 mat1a;
};
float4 main() : SV_Target0
{
return mul(g_MyBuffer1.mat1, g_MyBuffer1.vec1) +
mul(g_MyBuffer2.mat1, g_MyBuffer2.vec1);
}
...@@ -201,6 +201,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -201,6 +201,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.namespace.frag", "main"}, {"hlsl.namespace.frag", "main"},
{"hlsl.nonint-index.frag", "main"}, {"hlsl.nonint-index.frag", "main"},
{"hlsl.matNx1.frag", "main"}, {"hlsl.matNx1.frag", "main"},
{"hlsl.matpack-1.frag", "main"},
{"hlsl.matrixSwizzle.vert", "ShaderFunction"}, {"hlsl.matrixSwizzle.vert", "ShaderFunction"},
{"hlsl.memberFunCall.frag", "main"}, {"hlsl.memberFunCall.frag", "main"},
{"hlsl.mintypes.frag", "main"}, {"hlsl.mintypes.frag", "main"},
......
...@@ -8010,17 +8010,17 @@ void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TS ...@@ -8010,17 +8010,17 @@ void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TS
case EvqBuffer: case EvqBuffer:
correctUniform(type.getQualifier()); correctUniform(type.getQualifier());
if (it != ioTypeMap.end() && it->second.uniform) if (it != ioTypeMap.end() && it->second.uniform)
type.setStruct(it->second.uniform); memberType.setStruct(it->second.uniform);
break; break;
case EvqVaryingIn: case EvqVaryingIn:
correctInput(type.getQualifier()); correctInput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.input) if (it != ioTypeMap.end() && it->second.input)
type.setStruct(it->second.input); memberType.setStruct(it->second.input);
break; break;
case EvqVaryingOut: case EvqVaryingOut:
correctOutput(type.getQualifier()); correctOutput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.output) if (it != ioTypeMap.end() && it->second.output)
type.setStruct(it->second.output); memberType.setStruct(it->second.output);
break; break;
default: default:
break; break;
......
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