Fix struct type sharing

Fixes #2812
This commit is contained in:
Greg Fischer 2021-11-12 16:54:22 -07:00
parent c9706bdda0
commit 10be28ac9b
4 changed files with 154 additions and 0 deletions

View File

@ -0,0 +1,140 @@
hlsl.structbuffer.rwbyte2.comp
Shader version: 500
local_size = (1, 1, 1)
0:? Sequence
0:6 Function Definition: @main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:7 Sequence
0:7 move second child to first child ( temp uint)
0:7 'f' ( temp uint)
0:7 indirect index (layout( row_major std430) buffer uint)
0:7 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint)
0:7 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:7 Constant:
0:7 0 (const uint)
0:7 right-shift ( temp int)
0:7 Constant:
0:7 16 (const int)
0:7 Constant:
0:7 2 (const int)
0:8 move second child to first child ( temp uint)
0:8 direct index (layout( row_major std430) buffer uint)
0:8 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint)
0:8 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:8 Constant:
0:8 0 (const uint)
0:8 Constant:
0:8 0 (const int)
0:8 'f' ( temp uint)
0:6 Function Definition: main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:6 Function Call: @main( ( temp void)
0:? Linker Objects
0:? 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:? 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
Linked compute stage:
Shader version: 500
local_size = (1, 1, 1)
0:? Sequence
0:6 Function Definition: @main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:7 Sequence
0:7 move second child to first child ( temp uint)
0:7 'f' ( temp uint)
0:7 indirect index (layout( row_major std430) buffer uint)
0:7 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint)
0:7 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:7 Constant:
0:7 0 (const uint)
0:7 right-shift ( temp int)
0:7 Constant:
0:7 16 (const int)
0:7 Constant:
0:7 2 (const int)
0:8 move second child to first child ( temp uint)
0:8 direct index (layout( row_major std430) buffer uint)
0:8 @data: direct index for structure (layout( row_major std430) buffer unsized 1-element array of uint)
0:8 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:8 Constant:
0:8 0 (const uint)
0:8 Constant:
0:8 0 (const int)
0:8 'f' ( temp uint)
0:6 Function Definition: main( ( temp void)
0:6 Function Parameters:
0:? Sequence
0:6 Function Call: @main( ( temp void)
0:? Linker Objects
0:? 'g_sbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
0:? 'g_bbuf' (layout( row_major std430) buffer block{layout( row_major std430) buffer unsized 1-element array of uint @data})
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 30
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main"
ExecutionMode 4 LocalSize 1 1 1
Source HLSL 500
Name 4 "main"
Name 6 "@main("
Name 10 "f"
Name 12 "g_bbuf"
MemberName 12(g_bbuf) 0 "@data"
Name 14 "g_bbuf"
Name 24 "g_sbuf"
MemberName 24(g_sbuf) 0 "@data"
Name 26 "g_sbuf"
Decorate 11 ArrayStride 4
MemberDecorate 12(g_bbuf) 0 Offset 0
Decorate 12(g_bbuf) BufferBlock
Decorate 14(g_bbuf) DescriptorSet 0
Decorate 14(g_bbuf) Binding 1
Decorate 23 ArrayStride 4
MemberDecorate 24(g_sbuf) 0 Offset 0
Decorate 24(g_sbuf) BufferBlock
Decorate 26(g_sbuf) DescriptorSet 0
Decorate 26(g_sbuf) Binding 0
2: TypeVoid
3: TypeFunction 2
8: TypeInt 32 0
9: TypePointer Function 8(int)
11: TypeRuntimeArray 8(int)
12(g_bbuf): TypeStruct 11
13: TypePointer Uniform 12(g_bbuf)
14(g_bbuf): 13(ptr) Variable Uniform
15: TypeInt 32 1
16: 15(int) Constant 0
17: 15(int) Constant 16
18: 15(int) Constant 2
20: TypePointer Uniform 8(int)
23: TypeRuntimeArray 8(int)
24(g_sbuf): TypeStruct 23
25: TypePointer Uniform 24(g_sbuf)
26(g_sbuf): 25(ptr) Variable Uniform
4(main): 2 Function None 3
5: Label
29: 2 FunctionCall 6(@main()
Return
FunctionEnd
6(@main(): 2 Function None 3
7: Label
10(f): 9(ptr) Variable Function
19: 15(int) ShiftRightArithmetic 17 18
21: 20(ptr) AccessChain 14(g_bbuf) 16 19
22: 8(int) Load 21
Store 10(f) 22
27: 8(int) Load 10(f)
28: 20(ptr) AccessChain 26(g_sbuf) 16 16
Store 28 27
Return
FunctionEnd

View File

@ -0,0 +1,10 @@
RWStructuredBuffer<uint> g_sbuf;
RWByteAddressBuffer g_bbuf;
void main()
{
uint f = g_bbuf.Load(16);
g_sbuf[0] = f;
}

View File

@ -6935,6 +6935,9 @@ void HlslParseContext::shareStructBufferType(TType& type)
if (lhs.isStruct() != rhs.isStruct())
return false;
if (lhs.getQualifier().builtIn != rhs.getQualifier().builtIn)
return false;
if (lhs.isStruct() && rhs.isStruct()) {
if (lhs.getStruct()->size() != rhs.getStruct()->size())
return false;

View File

@ -385,6 +385,7 @@ INSTANTIATE_TEST_SUITE_P(
{"hlsl.structbuffer.fn2.comp", "main"},
{"hlsl.structbuffer.rw.frag", "main"},
{"hlsl.structbuffer.rwbyte.frag", "main"},
{"hlsl.structbuffer.rwbyte2.comp", "main"},
{"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"},
{"hlsl.structStructName.frag", "main"},