HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case. The salient points of this PR are: * Structure splitting has been changed from "always between stages" to "only into the VS and out of the PS". It had previously happened between stages because it's not legal to pass a struct containing a builtin IO variable. * Structs passed between stages are now split into a struct containing ONLY user types, and a collection of loose builtin IO variables, if any. The user-part is passed as a normal struct between stages, which is valid SPIR-V now that the builtin IO is removed. * Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g, functions can work unmodified. * If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS, the array reference is moved to the split-off loose variable, which is given the array dimension itself. When passing things around inside the shader, such as over a function call, the the original type is used in a sanitized form that removes the builtIn qualifications and makes them temporaries. This means internal function calls do not have to change. However, the type when returned from the shader will be member-wise copied from the internal sanitized one to the external type. The sanitized type is used in variable declarations. When copying split types and unsplit, if a sub-struct contains only user variables, it is copied as a single entity to avoid more AST verbosity. Above strategy arrived at with talks with @johnkslang. This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to real world cases.
This commit is contained in:
@@ -29,7 +29,13 @@ Shader version: 450
|
||||
0:13 Sequence
|
||||
0:13 Sequence
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
@@ -38,7 +44,13 @@ Shader version: 450
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
@@ -47,31 +59,32 @@ Shader version: 450
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 move second child to first child (temp 2-component vector of uint)
|
||||
0:? 'coord' (layout(location=2 ) out 2-component vector of uint)
|
||||
0:13 coord: direct index for structure (temp 2-component vector of uint)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 coord: direct index for structure (temp 2-component vector of uint)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'b' (layout(location=3 ) smooth out 4-component vector of float)
|
||||
0:13 b: direct index for structure (temp 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 2 (const int)
|
||||
0:13 b: direct index for structure (temp 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 2 (const int)
|
||||
0:13 Branch: Return
|
||||
0:? Linker Objects
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:? 'coord' (layout(location=2 ) out 2-component vector of uint)
|
||||
0:? 'b' (layout(location=3 ) smooth out 4-component vector of float)
|
||||
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:? 'd' (layout(location=0 ) in 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
|
||||
0:? 'coord' (layout(location=3 ) in 2-component vector of uint)
|
||||
0:? 'b' (layout(location=4 ) in 4-component vector of float)
|
||||
0:? 'b' (layout(location=4 ) smooth in 4-component vector of float)
|
||||
0:? 'e' (layout(location=5 ) in 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
|
||||
|
||||
@@ -109,7 +122,13 @@ Shader version: 450
|
||||
0:13 Sequence
|
||||
0:13 Sequence
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
@@ -118,7 +137,13 @@ Shader version: 450
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 0 (const int)
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 direct index (temp 4-component vector of float)
|
||||
0:13 m: direct index for structure (temp 2-element array of 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
@@ -127,42 +152,43 @@ Shader version: 450
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 move second child to first child (temp 2-component vector of uint)
|
||||
0:? 'coord' (layout(location=2 ) out 2-component vector of uint)
|
||||
0:13 coord: direct index for structure (temp 2-component vector of uint)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 coord: direct index for structure (temp 2-component vector of uint)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 1 (const int)
|
||||
0:13 move second child to first child (temp 4-component vector of float)
|
||||
0:? 'b' (layout(location=3 ) smooth out 4-component vector of float)
|
||||
0:13 b: direct index for structure (temp 4-component vector of float)
|
||||
0:13 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 2 (const int)
|
||||
0:13 b: direct index for structure (temp 4-component vector of float)
|
||||
0:13 'local' (temp structure{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
|
||||
0:13 Constant:
|
||||
0:13 2 (const int)
|
||||
0:13 Branch: Return
|
||||
0:? Linker Objects
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:? 'coord' (layout(location=2 ) out 2-component vector of uint)
|
||||
0:? 'b' (layout(location=3 ) smooth out 4-component vector of float)
|
||||
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
|
||||
0:? 'd' (layout(location=0 ) in 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
|
||||
0:? 'coord' (layout(location=3 ) in 2-component vector of uint)
|
||||
0:? 'b' (layout(location=4 ) in 4-component vector of float)
|
||||
0:? 'b' (layout(location=4 ) smooth in 4-component vector of float)
|
||||
0:? 'e' (layout(location=5 ) in 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=0 ) out 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=1 ) out 4-component vector of float)
|
||||
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
|
||||
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
|
||||
|
||||
// Module Version 10000
|
||||
// Generated by (magic number): 80001
|
||||
// Id's are bound by 59
|
||||
// Id's are bound by 62
|
||||
|
||||
Capability Shader
|
||||
1: ExtInstImport "GLSL.std.450"
|
||||
MemoryModel Logical GLSL450
|
||||
EntryPoint Vertex 4 "main" 18 20 24 32 35 41 45 50 54 58
|
||||
EntryPoint Vertex 4 "main" 18 20 24 32 35 42 61
|
||||
Name 4 "main"
|
||||
Name 12 "VI"
|
||||
MemberName 12(VI) 0 "m"
|
||||
@@ -174,21 +200,19 @@ Shader version: 450
|
||||
Name 24 "coord"
|
||||
Name 32 "d"
|
||||
Name 35 "e"
|
||||
Name 41 "m[0]"
|
||||
Name 45 "m[1]"
|
||||
Name 50 "coord"
|
||||
Name 54 "b"
|
||||
Name 58 "b"
|
||||
Name 40 "VI"
|
||||
MemberName 40(VI) 0 "m"
|
||||
MemberName 40(VI) 1 "coord"
|
||||
MemberName 40(VI) 2 "b"
|
||||
Name 42 "@entryPointOutput"
|
||||
Name 61 "b"
|
||||
Decorate 18(m[1]) Location 2
|
||||
Decorate 20(m[0]) Location 1
|
||||
Decorate 24(coord) Location 3
|
||||
Decorate 32(d) Location 0
|
||||
Decorate 35(e) Location 5
|
||||
Decorate 41(m[0]) Location 0
|
||||
Decorate 45(m[1]) Location 1
|
||||
Decorate 50(coord) Location 2
|
||||
Decorate 54(b) Location 3
|
||||
Decorate 58(b) Location 4
|
||||
Decorate 42(@entryPointOutput) BuiltIn Position
|
||||
Decorate 61(b) Location 4
|
||||
2: TypeVoid
|
||||
3: TypeFunction 2
|
||||
6: TypeFloat 32
|
||||
@@ -211,16 +235,15 @@ Shader version: 450
|
||||
32(d): 17(ptr) Variable Input
|
||||
35(e): 17(ptr) Variable Input
|
||||
38: TypePointer Function 7(fvec4)
|
||||
40: TypePointer Output 7(fvec4)
|
||||
41(m[0]): 40(ptr) Variable Output
|
||||
42: 15(int) Constant 0
|
||||
45(m[1]): 40(ptr) Variable Output
|
||||
46: 15(int) Constant 1
|
||||
49: TypePointer Output 11(ivec2)
|
||||
50(coord): 49(ptr) Variable Output
|
||||
51: TypePointer Function 11(ivec2)
|
||||
54(b): 40(ptr) Variable Output
|
||||
58(b): 17(ptr) Variable Input
|
||||
40(VI): TypeStruct 10 11(ivec2) 7(fvec4)
|
||||
41: TypePointer Output 40(VI)
|
||||
42(@entryPointOutput): 41(ptr) Variable Output
|
||||
43: 15(int) Constant 0
|
||||
46: TypePointer Output 7(fvec4)
|
||||
48: 15(int) Constant 1
|
||||
52: TypePointer Function 11(ivec2)
|
||||
55: TypePointer Output 11(ivec2)
|
||||
61(b): 17(ptr) Variable Input
|
||||
4(main): 2 Function None 3
|
||||
5: Label
|
||||
14(local): 13(ptr) Variable Function
|
||||
@@ -238,17 +261,21 @@ Shader version: 450
|
||||
37: 7(fvec4) FAdd 34 36
|
||||
39: 38(ptr) AccessChain 14(local) 16
|
||||
Store 39 37
|
||||
43: 38(ptr) AccessChain 14(local) 42 42
|
||||
44: 7(fvec4) Load 43
|
||||
Store 41(m[0]) 44
|
||||
47: 38(ptr) AccessChain 14(local) 42 46
|
||||
48: 7(fvec4) Load 47
|
||||
Store 45(m[1]) 48
|
||||
52: 51(ptr) AccessChain 14(local) 46
|
||||
53: 11(ivec2) Load 52
|
||||
Store 50(coord) 53
|
||||
55: 38(ptr) AccessChain 14(local) 16
|
||||
56: 7(fvec4) Load 55
|
||||
Store 54(b) 56
|
||||
44: 38(ptr) AccessChain 14(local) 43 43
|
||||
45: 7(fvec4) Load 44
|
||||
47: 46(ptr) AccessChain 42(@entryPointOutput) 43 43
|
||||
Store 47 45
|
||||
49: 38(ptr) AccessChain 14(local) 43 48
|
||||
50: 7(fvec4) Load 49
|
||||
51: 46(ptr) AccessChain 42(@entryPointOutput) 43 48
|
||||
Store 51 50
|
||||
53: 52(ptr) AccessChain 14(local) 48
|
||||
54: 11(ivec2) Load 53
|
||||
56: 55(ptr) AccessChain 42(@entryPointOutput) 48
|
||||
Store 56 54
|
||||
57: 38(ptr) AccessChain 14(local) 16
|
||||
58: 7(fvec4) Load 57
|
||||
59: 46(ptr) AccessChain 42(@entryPointOutput) 16
|
||||
Store 59 58
|
||||
Return
|
||||
FunctionEnd
|
||||
|
||||
Reference in New Issue
Block a user