
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.
109 lines
5.0 KiB
Plaintext
109 lines
5.0 KiB
Plaintext
hlsl.struct.split.trivial.vert
|
|
Shader version: 450
|
|
0:? Sequence
|
|
0:16 Function Definition: main(struct-VS_INPUT-vf41;vf4; (temp structure{temp 4-component vector of float Pos})
|
|
0:16 Function Parameters:
|
|
0:16 'vsin' (in structure{temp 4-component vector of float Pos_in})
|
|
0:16 'Pos_loose' (in 4-component vector of float Position)
|
|
0:? Sequence
|
|
0:19 move second child to first child (temp 4-component vector of float)
|
|
0:19 Pos: direct index for structure (temp 4-component vector of float)
|
|
0:19 'vsout' (temp structure{temp 4-component vector of float Pos})
|
|
0:19 Constant:
|
|
0:19 0 (const int)
|
|
0:19 add (temp 4-component vector of float)
|
|
0:? 'Pos_in' (in 4-component vector of float Position)
|
|
0:19 'Pos_loose' (in 4-component vector of float Position)
|
|
0:21 Sequence
|
|
0:21 Sequence
|
|
0:21 move second child to first child (temp 4-component vector of float)
|
|
0:? 'Pos' (out 4-component vector of float Position)
|
|
0:21 Pos: direct index for structure (temp 4-component vector of float)
|
|
0:21 'vsout' (temp structure{temp 4-component vector of float Pos})
|
|
0:21 Constant:
|
|
0:21 0 (const int)
|
|
0:21 Branch: Return
|
|
0:? Linker Objects
|
|
0:? 'Pos' (out 4-component vector of float Position)
|
|
0:? 'Pos_in' (in 4-component vector of float Position)
|
|
0:? 'Pos_loose' (in 4-component vector of float Position)
|
|
|
|
|
|
Linked vertex stage:
|
|
|
|
|
|
Shader version: 450
|
|
0:? Sequence
|
|
0:16 Function Definition: main(struct-VS_INPUT-vf41;vf4; (temp structure{temp 4-component vector of float Pos})
|
|
0:16 Function Parameters:
|
|
0:16 'vsin' (in structure{temp 4-component vector of float Pos_in})
|
|
0:16 'Pos_loose' (in 4-component vector of float Position)
|
|
0:? Sequence
|
|
0:19 move second child to first child (temp 4-component vector of float)
|
|
0:19 Pos: direct index for structure (temp 4-component vector of float)
|
|
0:19 'vsout' (temp structure{temp 4-component vector of float Pos})
|
|
0:19 Constant:
|
|
0:19 0 (const int)
|
|
0:19 add (temp 4-component vector of float)
|
|
0:? 'Pos_in' (in 4-component vector of float Position)
|
|
0:19 'Pos_loose' (in 4-component vector of float Position)
|
|
0:21 Sequence
|
|
0:21 Sequence
|
|
0:21 move second child to first child (temp 4-component vector of float)
|
|
0:? 'Pos' (out 4-component vector of float Position)
|
|
0:21 Pos: direct index for structure (temp 4-component vector of float)
|
|
0:21 'vsout' (temp structure{temp 4-component vector of float Pos})
|
|
0:21 Constant:
|
|
0:21 0 (const int)
|
|
0:21 Branch: Return
|
|
0:? Linker Objects
|
|
0:? 'Pos' (out 4-component vector of float Position)
|
|
0:? 'Pos_in' (in 4-component vector of float Position)
|
|
0:? 'Pos_loose' (in 4-component vector of float Position)
|
|
|
|
// Module Version 10000
|
|
// Generated by (magic number): 80001
|
|
// Id's are bound by 26
|
|
|
|
Capability Shader
|
|
1: ExtInstImport "GLSL.std.450"
|
|
MemoryModel Logical GLSL450
|
|
EntryPoint Vertex 4 "main" 14 16 22
|
|
Name 4 "main"
|
|
Name 8 "VS_OUTPUT"
|
|
MemberName 8(VS_OUTPUT) 0 "Pos"
|
|
Name 10 "vsout"
|
|
Name 14 "Pos_in"
|
|
Name 16 "Pos_loose"
|
|
Name 22 "Pos"
|
|
Decorate 14(Pos_in) BuiltIn Position
|
|
Decorate 16(Pos_loose) BuiltIn Position
|
|
Decorate 22(Pos) BuiltIn Position
|
|
2: TypeVoid
|
|
3: TypeFunction 2
|
|
6: TypeFloat 32
|
|
7: TypeVector 6(float) 4
|
|
8(VS_OUTPUT): TypeStruct 7(fvec4)
|
|
9: TypePointer Function 8(VS_OUTPUT)
|
|
11: TypeInt 32 1
|
|
12: 11(int) Constant 0
|
|
13: TypePointer Input 7(fvec4)
|
|
14(Pos_in): 13(ptr) Variable Input
|
|
16(Pos_loose): 13(ptr) Variable Input
|
|
19: TypePointer Function 7(fvec4)
|
|
21: TypePointer Output 7(fvec4)
|
|
22(Pos): 21(ptr) Variable Output
|
|
4(main): 2 Function None 3
|
|
5: Label
|
|
10(vsout): 9(ptr) Variable Function
|
|
15: 7(fvec4) Load 14(Pos_in)
|
|
17: 7(fvec4) Load 16(Pos_loose)
|
|
18: 7(fvec4) FAdd 15 17
|
|
20: 19(ptr) AccessChain 10(vsout) 12
|
|
Store 20 18
|
|
23: 19(ptr) AccessChain 10(vsout) 12
|
|
24: 7(fvec4) Load 23
|
|
Store 22(Pos) 24
|
|
Return
|
|
FunctionEnd
|