Merge pull request #2268 from lriki/hlsl-pack_matrix

HLSL: Fix #pragma pack_matrix(row_major) not work on global uniforms
This commit is contained in:
John Kessenich 2020-07-02 05:21:45 -06:00 committed by GitHub
commit a70f7dea77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 2 deletions

View File

@ -0,0 +1,102 @@
hlsl.matpack-pragma-global.frag
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:6 Function Definition: @main( ( temp 4-component vector of float)
0:6 Function Parameters:
0:? Sequence
0:7 Branch: Return with expression
0:7 direct index ( temp 4-component vector of float)
0:7 g_GlobalMat1: direct index for structure ( uniform 4X4 matrix of float)
0:7 'anon@0' (layout( column_major std140) uniform block{ uniform 4X4 matrix of float g_GlobalMat1})
0:7 Constant:
0:7 0 (const uint)
0:7 Constant:
0:7 0 (const int)
0:6 Function Definition: main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:6 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:6 Function Call: @main( ( temp 4-component vector of float)
0:? Linker Objects
0:? 'anon@0' (layout( column_major std140) uniform block{ uniform 4X4 matrix of float g_GlobalMat1})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
Linked fragment stage:
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:6 Function Definition: @main( ( temp 4-component vector of float)
0:6 Function Parameters:
0:? Sequence
0:7 Branch: Return with expression
0:7 direct index ( temp 4-component vector of float)
0:7 g_GlobalMat1: direct index for structure ( uniform 4X4 matrix of float)
0:7 'anon@0' (layout( column_major std140) uniform block{ uniform 4X4 matrix of float g_GlobalMat1})
0:7 Constant:
0:7 0 (const uint)
0:7 Constant:
0:7 0 (const int)
0:6 Function Definition: main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:6 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:6 Function Call: @main( ( temp 4-component vector of float)
0:? Linker Objects
0:? 'anon@0' (layout( column_major std140) uniform block{ uniform 4X4 matrix of float g_GlobalMat1})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 25
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 23
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
Name 9 "@main("
Name 12 "$Global"
MemberName 12($Global) 0 "g_GlobalMat1"
Name 14 ""
Name 23 "@entryPointOutput"
MemberDecorate 12($Global) 0 ColMajor
MemberDecorate 12($Global) 0 Offset 0
MemberDecorate 12($Global) 0 MatrixStride 16
Decorate 12($Global) Block
Decorate 14 DescriptorSet 0
Decorate 14 Binding 0
Decorate 23(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeFunction 7(fvec4)
11: TypeMatrix 7(fvec4) 4
12($Global): TypeStruct 11
13: TypePointer Uniform 12($Global)
14: 13(ptr) Variable Uniform
15: TypeInt 32 1
16: 15(int) Constant 0
17: TypePointer Uniform 7(fvec4)
22: TypePointer Output 7(fvec4)
23(@entryPointOutput): 22(ptr) Variable Output
4(main): 2 Function None 3
5: Label
24: 7(fvec4) FunctionCall 9(@main()
Store 23(@entryPointOutput) 24
Return
FunctionEnd
9(@main(): 7(fvec4) Function None 8
10: Label
18: 17(ptr) AccessChain 14 16 16
19: 7(fvec4) Load 18
ReturnValue 19
FunctionEnd

View File

@ -0,0 +1,8 @@
#pragma pack_matrix(row_major)
float4x4 g_GlobalMat1;
float4 main() : SV_Target0
{
return g_GlobalMat1[0];
}

View File

@ -60,8 +60,8 @@ public:
virtual const char* getGlobalUniformBlockName() const override { return "$Global"; }
virtual void setUniformBlockDefaults(TType& block) const override
{
block.getQualifier().layoutPacking = ElpStd140;
block.getQualifier().layoutMatrix = ElmRowMajor;
block.getQualifier().layoutPacking = globalUniformDefaults.layoutPacking;
block.getQualifier().layoutMatrix = globalUniformDefaults.layoutMatrix;
}
void reservedPpErrorCheck(const TSourceLoc&, const char* /*name*/, const char* /*op*/) override { }

View File

@ -279,6 +279,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.logical.unary.frag", "main"},
{"hlsl.loopattr.frag", "main"},
{"hlsl.matpack-pragma.frag", "main"},
{"hlsl.matpack-pragma-global.frag", "main"},
{"hlsl.mip.operator.frag", "main"},
{"hlsl.mip.negative.frag", "main"},
{"hlsl.mip.negative2.frag", "main"},