WIP: HLSL: structuredbuffer counter functionality

This is WIP, heavy on the IP part.  There's not yet enough to use in real workloads.

Currently present:

* Creation of separate counter buffers for structured buffer types needing them.
* IncrementCounter / DecrementCounter methods
* Postprocess to remove unused counter buffers from linkage
* Associated counter buffers are given @count suffix (invalid as a user identifier)

Not yet present:

* reflection queries to obtain bindings for counter buffers
* Append/Consume buffers
* Ability to use SB references passed as fn parameters
This commit is contained in:
steve-lunarg 2017-04-10 08:19:21 -06:00
parent d1141843c0
commit 8e26feb8f2
9 changed files with 520 additions and 24 deletions

View file

@ -0,0 +1,316 @@
hlsl.structbuffer.incdec.frag
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:7 Function Definition: @main(u1; ( temp 4-component vector of float)
0:7 Function Parameters:
0:7 'pos' ( in uint)
0:? Sequence
0:8 Sequence
0:8 move second child to first child ( temp 4-component vector of uint)
0:8 'result' ( temp 4-component vector of uint)
0:8 Constant:
0:8 0 (const uint)
0:8 0 (const uint)
0:8 0 (const uint)
0:8 0 (const uint)
0:10 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:10 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:10 'sbuf_rw_i' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:10 Constant:
0:10 0 (const uint)
0:10 Constant:
0:10 7 (const int)
0:11 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:11 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:11 'sbuf_rw_d' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:11 Constant:
0:11 0 (const uint)
0:11 Constant:
0:11 7 (const int)
0:13 move second child to first child ( temp 4-component vector of uint)
0:13 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:13 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:13 'sbuf_rw_nocounter' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:13 Constant:
0:13 0 (const uint)
0:13 Constant:
0:13 5 (const int)
0:13 Constant:
0:13 2 (const uint)
0:13 2 (const uint)
0:13 2 (const uint)
0:13 2 (const uint)
0:15 Sequence
0:15 move second child to first child ( temp uint)
0:15 'c1' ( temp uint)
0:15 AtomicAdd ( temp uint)
0:15 @count: direct index for structure ( temp int)
0:15 'sbuf_rw_i@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:15 Constant:
0:15 0 (const int)
0:15 Constant:
0:15 1 (const int)
0:16 Sequence
0:16 move second child to first child ( temp uint)
0:16 'c2' ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16 -1 (const int)
0:18 Branch: Return with expression
0:? Construct vec4 ( temp 4-component vector of float)
0:18 Convert uint to float ( temp float)
0:18 direct index ( temp uint)
0:18 'result' ( temp 4-component vector of uint)
0:18 Constant:
0:18 0 (const int)
0:18 Convert uint to float ( temp float)
0:18 direct index ( temp uint)
0:18 'result' ( temp 4-component vector of uint)
0:18 Constant:
0:18 1 (const int)
0:18 Convert uint to float ( temp float)
0:18 'c1' ( temp uint)
0:18 Convert uint to float ( temp float)
0:18 'c2' ( temp uint)
0:7 Function Definition: main( ( temp void)
0:7 Function Parameters:
0:? Sequence
0:7 move second child to first child ( temp uint)
0:? 'pos' ( temp uint)
0:? 'pos' (layout( location=0) in uint)
0:7 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:7 Function Call: @main(u1; ( temp 4-component vector of float)
0:? 'pos' ( temp uint)
0:? Linker Objects
0:? 'sbuf_rw_i' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? 'sbuf_rw_i@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:? 'sbuf_rw_d' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:? 'sbuf_rw_nocounter' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'pos' (layout( location=0) in uint)
Linked fragment stage:
Shader version: 500
gl_FragCoord origin is upper left
0:? Sequence
0:7 Function Definition: @main(u1; ( temp 4-component vector of float)
0:7 Function Parameters:
0:7 'pos' ( in uint)
0:? Sequence
0:8 Sequence
0:8 move second child to first child ( temp 4-component vector of uint)
0:8 'result' ( temp 4-component vector of uint)
0:8 Constant:
0:8 0 (const uint)
0:8 0 (const uint)
0:8 0 (const uint)
0:8 0 (const uint)
0:10 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:10 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:10 'sbuf_rw_i' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:10 Constant:
0:10 0 (const uint)
0:10 Constant:
0:10 7 (const int)
0:11 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:11 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:11 'sbuf_rw_d' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:11 Constant:
0:11 0 (const uint)
0:11 Constant:
0:11 7 (const int)
0:13 move second child to first child ( temp 4-component vector of uint)
0:13 direct index (layout( row_major std430) buffer 4-component vector of uint)
0:13 @data: direct index for structure (layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint)
0:13 'sbuf_rw_nocounter' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:13 Constant:
0:13 0 (const uint)
0:13 Constant:
0:13 5 (const int)
0:13 Constant:
0:13 2 (const uint)
0:13 2 (const uint)
0:13 2 (const uint)
0:13 2 (const uint)
0:15 Sequence
0:15 move second child to first child ( temp uint)
0:15 'c1' ( temp uint)
0:15 AtomicAdd ( temp uint)
0:15 @count: direct index for structure ( temp int)
0:15 'sbuf_rw_i@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:15 Constant:
0:15 0 (const int)
0:15 Constant:
0:15 1 (const int)
0:16 Sequence
0:16 move second child to first child ( temp uint)
0:16 'c2' ( temp uint)
0:16 AtomicAdd ( temp uint)
0:16 @count: direct index for structure ( temp int)
0:16 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:16 Constant:
0:16 0 (const int)
0:16 Constant:
0:16 -1 (const int)
0:18 Branch: Return with expression
0:? Construct vec4 ( temp 4-component vector of float)
0:18 Convert uint to float ( temp float)
0:18 direct index ( temp uint)
0:18 'result' ( temp 4-component vector of uint)
0:18 Constant:
0:18 0 (const int)
0:18 Convert uint to float ( temp float)
0:18 direct index ( temp uint)
0:18 'result' ( temp 4-component vector of uint)
0:18 Constant:
0:18 1 (const int)
0:18 Convert uint to float ( temp float)
0:18 'c1' ( temp uint)
0:18 Convert uint to float ( temp float)
0:18 'c2' ( temp uint)
0:7 Function Definition: main( ( temp void)
0:7 Function Parameters:
0:? Sequence
0:7 move second child to first child ( temp uint)
0:? 'pos' ( temp uint)
0:? 'pos' (layout( location=0) in uint)
0:7 move second child to first child ( temp 4-component vector of float)
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:7 Function Call: @main(u1; ( temp 4-component vector of float)
0:? 'pos' ( temp uint)
0:? Linker Objects
0:? 'sbuf_rw_i' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? 'sbuf_rw_i@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:? 'sbuf_rw_d' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? 'sbuf_rw_d@count' (layout( row_major std430) buffer block{layout( row_major std430) buffer int @count})
0:? 'sbuf_rw_nocounter' (layout( row_major std430) buffer block{layout( row_major std430) buffer implicitly-sized array of 4-component vector of uint @data})
0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float)
0:? 'pos' (layout( location=0) in uint)
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 69
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 62 65
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
Name 12 "@main(u1;"
Name 11 "pos"
Name 16 "result"
Name 20 "sbuf_rw_i"
MemberName 20(sbuf_rw_i) 0 "@data"
Name 22 "sbuf_rw_i"
Name 26 "sbuf_rw_d"
Name 27 "sbuf_rw_nocounter"
Name 33 "c1"
Name 34 "sbuf_rw_i@count"
MemberName 34(sbuf_rw_i@count) 0 "@count"
Name 36 "sbuf_rw_i@count"
Name 42 "c2"
Name 43 "sbuf_rw_d@count"
Name 60 "pos"
Name 62 "pos"
Name 65 "@entryPointOutput"
Name 66 "param"
Decorate 19 ArrayStride 16
MemberDecorate 20(sbuf_rw_i) 0 Offset 0
Decorate 20(sbuf_rw_i) BufferBlock
Decorate 22(sbuf_rw_i) DescriptorSet 0
Decorate 26(sbuf_rw_d) DescriptorSet 0
Decorate 27(sbuf_rw_nocounter) DescriptorSet 0
MemberDecorate 34(sbuf_rw_i@count) 0 Offset 0
Decorate 34(sbuf_rw_i@count) BufferBlock
Decorate 36(sbuf_rw_i@count) DescriptorSet 0
Decorate 43(sbuf_rw_d@count) DescriptorSet 0
Decorate 62(pos) Location 0
Decorate 65(@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: TypeVector 6(int) 4
15: TypePointer Function 14(ivec4)
17: 6(int) Constant 0
18: 14(ivec4) ConstantComposite 17 17 17 17
19: TypeRuntimeArray 14(ivec4)
20(sbuf_rw_i): TypeStruct 19
21: TypePointer Uniform 20(sbuf_rw_i)
22(sbuf_rw_i): 21(ptr) Variable Uniform
23: TypeInt 32 1
24: 23(int) Constant 0
25: 23(int) Constant 7
26(sbuf_rw_d): 21(ptr) Variable Uniform
27(sbuf_rw_nocounter): 21(ptr) Variable Uniform
28: 23(int) Constant 5
29: 6(int) Constant 2
30: 14(ivec4) ConstantComposite 29 29 29 29
31: TypePointer Uniform 14(ivec4)
34(sbuf_rw_i@count): TypeStruct 23(int)
35: TypePointer Uniform 34(sbuf_rw_i@count)
36(sbuf_rw_i@count): 35(ptr) Variable Uniform
37: TypePointer Uniform 23(int)
39: 23(int) Constant 1
40: 6(int) Constant 1
43(sbuf_rw_d@count): 35(ptr) Variable Uniform
45: 23(int) Constant 4294967295
61: TypePointer Input 6(int)
62(pos): 61(ptr) Variable Input
64: TypePointer Output 9(fvec4)
65(@entryPointOutput): 64(ptr) Variable Output
4(main): 2 Function None 3
5: Label
60(pos): 7(ptr) Variable Function
66(param): 7(ptr) Variable Function
63: 6(int) Load 62(pos)
Store 60(pos) 63
67: 6(int) Load 60(pos)
Store 66(param) 67
68: 9(fvec4) FunctionCall 12(@main(u1;) 66(param)
Store 65(@entryPointOutput) 68
Return
FunctionEnd
12(@main(u1;): 9(fvec4) Function None 10
11(pos): 7(ptr) FunctionParameter
13: Label
16(result): 15(ptr) Variable Function
33(c1): 7(ptr) Variable Function
42(c2): 7(ptr) Variable Function
Store 16(result) 18
32: 31(ptr) AccessChain 27(sbuf_rw_nocounter) 24 28
Store 32 30
38: 37(ptr) AccessChain 36(sbuf_rw_i@count) 24
41: 6(int) AtomicIAdd 38 40 17 39
Store 33(c1) 41
44: 37(ptr) AccessChain 43(sbuf_rw_d@count) 24
46: 6(int) AtomicIAdd 44 40 17 45
Store 42(c2) 46
47: 7(ptr) AccessChain 16(result) 17
48: 6(int) Load 47
49: 8(float) ConvertUToF 48
50: 7(ptr) AccessChain 16(result) 40
51: 6(int) Load 50
52: 8(float) ConvertUToF 51
53: 6(int) Load 33(c1)
54: 8(float) ConvertUToF 53
55: 6(int) Load 42(c2)
56: 8(float) ConvertUToF 55
57: 9(fvec4) CompositeConstruct 49 52 54 56
ReturnValue 57
FunctionEnd

View file

@ -0,0 +1,19 @@
RWStructuredBuffer<uint4> sbuf_rw_i;
RWStructuredBuffer<uint4> sbuf_rw_d;
RWStructuredBuffer<uint4> sbuf_rw_nocounter; // doesn't use inc or dec
float4 main(uint pos : FOO) : SV_Target0
{
uint4 result = 0;
sbuf_rw_i[7];
sbuf_rw_d[7];
sbuf_rw_nocounter[5] = 2;
uint c1 = sbuf_rw_i.IncrementCounter();
uint c2 = sbuf_rw_d.DecrementCounter();
return float4(result.x, result.y, c1, c2);
}