Skip to content

Instantly share code, notes, and snippets.

@Themaister
Created April 19, 2017 16:38
Show Gist options
  • Save Themaister/6a866b188edbe0f3e039bd9db3c73c76 to your computer and use it in GitHub Desktop.
Save Themaister/6a866b188edbe0f3e039bd9db3c73c76 to your computer and use it in GitHub Desktop.
AppendStructuredBuffer<float4> append_buffer;
ConsumeStructuredBuffer<float4> consume_buffer;
RWStructuredBuffer<float4> rw_struct_buffer;
RWStructuredBuffer<float4> rw_struct_buffer_no_counter;
StructuredBuffer<float4> struct_buffer;
float4 main(uint pos : FOO) : SV_Target0
{
rw_struct_buffer_no_counter[10] = float4(1.0, 2.0, 3.0, 4.0);
rw_struct_buffer[7];
uint c1 = rw_struct_buffer.IncrementCounter();
append_buffer.Append(float4(1,2,3,4));
return consume_buffer.Consume() + struct_buffer.Load(20);
}
Problem:
It's not possible to distinguish between these four buffer types via reflection.
They are all backed by the same SSBO type, so changing the type probably won't work.
The name alone has no distinguishing feature which we can reliably extract to figure out which of these HLSL buffer types are used.
One approach probably is to to add @struct, @append, @consume to the OpName of the variable itself.
SPIR-V:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 72
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 65 68
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
Name 12 "@main(u1;"
Name 11 "pos"
Name 15 "rw_struct_buffer_no_counter"
MemberName 15(rw_struct_buffer_no_counter) 0 "@data"
Name 17 "rw_struct_buffer_no_counter"
Name 28 "rw_struct_buffer"
Name 30 "c1"
Name 31 "rw_struct_buffer@count"
MemberName 31(rw_struct_buffer@count) 0 "@count"
Name 33 "rw_struct_buffer@count"
Name 40 "append_buffer"
Name 41 "append_buffer@count"
Name 45 "consume_buffer"
Name 46 "consume_buffer@count"
Name 54 "struct_buffer"
MemberName 54(struct_buffer) 0 "@data"
Name 56 "struct_buffer"
Name 63 "pos"
Name 65 "pos"
Name 68 "@entryPointOutput"
Name 69 "param"
Decorate 14 ArrayStride 16
MemberDecorate 15(rw_struct_buffer_no_counter) 0 Offset 0
Decorate 15(rw_struct_buffer_no_counter) BufferBlock
Decorate 17(rw_struct_buffer_no_counter) DescriptorSet 0
Decorate 28(rw_struct_buffer) DescriptorSet 0
MemberDecorate 31(rw_struct_buffer@count) 0 Offset 0
Decorate 31(rw_struct_buffer@count) BufferBlock
Decorate 33(rw_struct_buffer@count) DescriptorSet 0
Decorate 40(append_buffer) DescriptorSet 0
Decorate 41(append_buffer@count) DescriptorSet 0
Decorate 45(consume_buffer) DescriptorSet 0
Decorate 46(consume_buffer@count) DescriptorSet 0
Decorate 53 ArrayStride 16
MemberDecorate 54(struct_buffer) 0 NonWritable
MemberDecorate 54(struct_buffer) 0 Offset 0
Decorate 54(struct_buffer) BufferBlock
Decorate 56(struct_buffer) DescriptorSet 0
Decorate 65(pos) Location 0
Decorate 68(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: TypePointer Function 6(int)
8: TypeFloat 32
9: TypeVector 8(float) 4
10: TypeFunction 9(fvec4) 7(ptr)
14: TypeRuntimeArray 9(fvec4)
15(rw_struct_buffer_no_counter): TypeStruct 14
16: TypePointer Uniform 15(rw_struct_buffer_no_counter)
17(rw_struct_buffer_no_counter): 16(ptr) Variable Uniform
18: TypeInt 32 1
19: 18(int) Constant 0
20: 18(int) Constant 10
21: 8(float) Constant 1065353216
22: 8(float) Constant 1073741824
23: 8(float) Constant 1077936128
24: 8(float) Constant 1082130432
25: 9(fvec4) ConstantComposite 21 22 23 24
26: TypePointer Uniform 9(fvec4)
28(rw_struct_buffer): 16(ptr) Variable Uniform
29: 18(int) Constant 7
31(rw_struct_buffer@count): TypeStruct 18(int)
32: TypePointer Uniform 31(rw_struct_buffer@count)
33(rw_struct_buffer@count): 32(ptr) Variable Uniform
34: TypePointer Uniform 18(int)
36: 18(int) Constant 1
37: 6(int) Constant 1
38: 6(int) Constant 0
40(append_buffer): 16(ptr) Variable Uniform
41(append_buffer@count): 32(ptr) Variable Uniform
45(consume_buffer): 16(ptr) Variable Uniform
46(consume_buffer@count): 32(ptr) Variable Uniform
48: 18(int) Constant 4294967295
53: TypeRuntimeArray 9(fvec4)
54(struct_buffer): TypeStruct 53
55: TypePointer Uniform 54(struct_buffer)
56(struct_buffer): 55(ptr) Variable Uniform
57: 18(int) Constant 20
64: TypePointer Input 6(int)
65(pos): 64(ptr) Variable Input
67: TypePointer Output 9(fvec4)
68(@entryPointOutput): 67(ptr) Variable Output
4(main): 2 Function None 3
5: Label
63(pos): 7(ptr) Variable Function
69(param): 7(ptr) Variable Function
66: 6(int) Load 65(pos)
Store 63(pos) 66
70: 6(int) Load 63(pos)
Store 69(param) 70
71: 9(fvec4) FunctionCall 12(@main(u1;) 69(param)
Store 68(@entryPointOutput) 71
Return
FunctionEnd
12(@main(u1;): 9(fvec4) Function None 10
11(pos): 7(ptr) FunctionParameter
13: Label
30(c1): 7(ptr) Variable Function
27: 26(ptr) AccessChain 17(rw_struct_buffer_no_counter) 19 20
Store 27 25
35: 34(ptr) AccessChain 33(rw_struct_buffer@count) 19
39: 6(int) AtomicIAdd 35 37 38 36
Store 30(c1) 39
42: 34(ptr) AccessChain 41(append_buffer@count) 19
43: 6(int) AtomicIAdd 42 37 38 36
44: 26(ptr) AccessChain 40(append_buffer) 19 43
Store 44 25
47: 34(ptr) AccessChain 46(consume_buffer@count) 19
49: 6(int) AtomicIAdd 47 37 38 48
50: 6(int) IAdd 49 48
51: 26(ptr) AccessChain 45(consume_buffer) 19 50
52: 9(fvec4) Load 51
58: 26(ptr) AccessChain 56(struct_buffer) 19 57
59: 9(fvec4) Load 58
60: 9(fvec4) FAdd 52 59
ReturnValue 60
FunctionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment