HLSL: Type sanitization: create non-IO types for var decl and fn param/ret

This introduces parallel types for IO-type containing aggregates used as
non-entry point function parameters or return types, or declared as variables.
Further uses of the same original type will share the same sanitized deep
structure.

This is intended to be used with the wrap-entry-point branch.
This commit is contained in:
steve-lunarg 2017-01-25 10:03:17 -07:00 committed by John Kessenich
parent 0fe106afd2
commit 5d3023af03
5 changed files with 282 additions and 229 deletions

View File

@ -4,20 +4,20 @@ gl_FragCoord origin is upper left
0:? Sequence 0:? Sequence
0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (temp float) 0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (temp float)
0:8 Function Parameters: 0:8 Function Parameters:
0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:? Sequence 0:? Sequence
0:9 Branch: Return with expression 0:9 Branch: Return with expression
0:9 add (temp float) 0:9 add (temp float)
0:9 direct index (temp float) 0:9 direct index (temp float)
0:9 v: direct index for structure (temp 2-component vector of float) 0:9 v: direct index for structure (temp 2-component vector of float)
0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:9 Constant: 0:9 Constant:
0:9 0 (const int) 0:9 0 (const int)
0:9 Constant: 0:9 Constant:
0:9 1 (const int) 0:9 1 (const int)
0:9 direct index (temp float) 0:9 direct index (temp float)
0:9 fragCoord: direct index for structure (temp 4-component vector of float FragCoord) 0:9 fragCoord: direct index for structure (temp 4-component vector of float)
0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:9 Constant: 0:9 Constant:
0:9 1 (const int) 0:9 1 (const int)
0:9 Constant: 0:9 Constant:
@ -94,20 +94,20 @@ gl_FragCoord origin is upper left
0:? Sequence 0:? Sequence
0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (temp float) 0:8 Function Definition: fun(struct-InParam-vf2-vf4-vi21; (temp float)
0:8 Function Parameters: 0:8 Function Parameters:
0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:8 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:? Sequence 0:? Sequence
0:9 Branch: Return with expression 0:9 Branch: Return with expression
0:9 add (temp float) 0:9 add (temp float)
0:9 direct index (temp float) 0:9 direct index (temp float)
0:9 v: direct index for structure (temp 2-component vector of float) 0:9 v: direct index for structure (temp 2-component vector of float)
0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:9 Constant: 0:9 Constant:
0:9 0 (const int) 0:9 0 (const int)
0:9 Constant: 0:9 Constant:
0:9 1 (const int) 0:9 1 (const int)
0:9 direct index (temp float) 0:9 direct index (temp float)
0:9 fragCoord: direct index for structure (temp 4-component vector of float FragCoord) 0:9 fragCoord: direct index for structure (temp 4-component vector of float)
0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float FragCoord fragCoord, temp 2-component vector of int i2}) 0:9 'p' (in structure{temp 2-component vector of float v, temp 4-component vector of float fragCoord, temp 2-component vector of int i2})
0:9 Constant: 0:9 Constant:
0:9 1 (const int) 0:9 1 (const int)
0:9 Constant: 0:9 Constant:
@ -191,12 +191,12 @@ gl_FragCoord origin is upper left
MemberName 11(InParam) 2 "i2" MemberName 11(InParam) 2 "i2"
Name 15 "fun(struct-InParam-vf2-vf4-vi21;" Name 15 "fun(struct-InParam-vf2-vf4-vi21;"
Name 14 "p" Name 14 "p"
Name 19 "@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;" Name 17 "InParam"
Name 18 "i" MemberName 17(InParam) 0 "v"
Name 34 "InParam" MemberName 17(InParam) 1 "fragCoord"
MemberName 34(InParam) 0 "v" MemberName 17(InParam) 2 "i2"
MemberName 34(InParam) 1 "fragCoord" Name 21 "@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;"
MemberName 34(InParam) 2 "i2" Name 20 "i"
Name 36 "local" Name 36 "local"
Name 48 "ret1" Name 48 "ret1"
Name 49 "param" Name 49 "param"
@ -210,7 +210,7 @@ gl_FragCoord origin is upper left
Name 73 "i_fragCoord" Name 73 "i_fragCoord"
Name 81 "@entryPointOutput" Name 81 "@entryPointOutput"
Name 82 "param" Name 82 "param"
MemberDecorate 11(InParam) 1 BuiltIn FragCoord MemberDecorate 17(InParam) 1 BuiltIn FragCoord
Decorate 67(i) Location 0 Decorate 67(i) Location 0
Decorate 73(i_fragCoord) BuiltIn FragCoord Decorate 73(i_fragCoord) BuiltIn FragCoord
Decorate 81(@entryPointOutput) Location 0 Decorate 81(@entryPointOutput) Location 0
@ -224,15 +224,15 @@ gl_FragCoord origin is upper left
11(InParam): TypeStruct 7(fvec2) 8(fvec4) 10(ivec2) 11(InParam): TypeStruct 7(fvec2) 8(fvec4) 10(ivec2)
12: TypePointer Function 11(InParam) 12: TypePointer Function 11(InParam)
13: TypeFunction 6(float) 12(ptr) 13: TypeFunction 6(float) 12(ptr)
17: TypeFunction 8(fvec4) 12(ptr) 17(InParam): TypeStruct 7(fvec2) 8(fvec4) 10(ivec2)
21: 9(int) Constant 0 18: TypePointer Function 17(InParam)
22: TypeInt 32 0 19: TypeFunction 8(fvec4) 18(ptr)
23: 22(int) Constant 1 23: 9(int) Constant 0
24: TypePointer Function 6(float) 24: TypeInt 32 0
27: 9(int) Constant 1 25: 24(int) Constant 1
28: 22(int) Constant 0 26: TypePointer Function 6(float)
34(InParam): TypeStruct 7(fvec2) 8(fvec4) 10(ivec2) 29: 9(int) Constant 1
35: TypePointer Function 34(InParam) 30: 24(int) Constant 0
39: TypePointer Function 7(fvec2) 39: TypePointer Function 7(fvec2)
42: TypePointer Function 8(fvec4) 42: TypePointer Function 8(fvec4)
45: 9(int) Constant 2 45: 9(int) Constant 2
@ -248,62 +248,62 @@ gl_FragCoord origin is upper left
81(@entryPointOutput): 80(ptr) Variable Output 81(@entryPointOutput): 80(ptr) Variable Output
4(PixelShaderFunction): 2 Function None 3 4(PixelShaderFunction): 2 Function None 3
5: Label 5: Label
64(i): 12(ptr) Variable Function 64(i): 18(ptr) Variable Function
82(param): 12(ptr) Variable Function 82(param): 18(ptr) Variable Function
69: 68(ptr) AccessChain 67(i) 21 69: 68(ptr) AccessChain 67(i) 23
70: 7(fvec2) Load 69 70: 7(fvec2) Load 69
71: 39(ptr) AccessChain 64(i) 21 71: 39(ptr) AccessChain 64(i) 23
Store 71 70 Store 71 70
74: 8(fvec4) Load 73(i_fragCoord) 74: 8(fvec4) Load 73(i_fragCoord)
75: 42(ptr) AccessChain 64(i) 27 75: 42(ptr) AccessChain 64(i) 29
Store 75 74 Store 75 74
77: 76(ptr) AccessChain 67(i) 27 77: 76(ptr) AccessChain 67(i) 29
78: 10(ivec2) Load 77 78: 10(ivec2) Load 77
79: 46(ptr) AccessChain 64(i) 45 79: 46(ptr) AccessChain 64(i) 45
Store 79 78 Store 79 78
83: 11(InParam) Load 64(i) 83: 17(InParam) Load 64(i)
Store 82(param) 83 Store 82(param) 83
84: 8(fvec4) FunctionCall 19(@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;) 82(param) 84: 8(fvec4) FunctionCall 21(@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;) 82(param)
Store 81(@entryPointOutput) 84 Store 81(@entryPointOutput) 84
Return Return
FunctionEnd FunctionEnd
15(fun(struct-InParam-vf2-vf4-vi21;): 6(float) Function None 13 15(fun(struct-InParam-vf2-vf4-vi21;): 6(float) Function None 13
14(p): 12(ptr) FunctionParameter 14(p): 12(ptr) FunctionParameter
16: Label 16: Label
25: 24(ptr) AccessChain 14(p) 21 23 27: 26(ptr) AccessChain 14(p) 23 25
26: 6(float) Load 25 28: 6(float) Load 27
29: 24(ptr) AccessChain 14(p) 27 28 31: 26(ptr) AccessChain 14(p) 29 30
30: 6(float) Load 29 32: 6(float) Load 31
31: 6(float) FAdd 26 30 33: 6(float) FAdd 28 32
ReturnValue 31 ReturnValue 33
FunctionEnd FunctionEnd
19(@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;): 8(fvec4) Function None 17 21(@PixelShaderFunction(struct-InParam-vf2-vf4-vi21;): 8(fvec4) Function None 19
18(i): 12(ptr) FunctionParameter 20(i): 18(ptr) FunctionParameter
20: Label 22: Label
36(local): 35(ptr) Variable Function 36(local): 12(ptr) Variable Function
48(ret1): 24(ptr) Variable Function 48(ret1): 26(ptr) Variable Function
49(param): 35(ptr) Variable Function 49(param): 12(ptr) Variable Function
52(ret2): 24(ptr) Variable Function 52(ret2): 26(ptr) Variable Function
53(param): 12(ptr) Variable Function 53(param): 18(ptr) Variable Function
37: 11(InParam) Load 18(i) 37: 17(InParam) Load 20(i)
38: 7(fvec2) CompositeExtract 37 0 38: 7(fvec2) CompositeExtract 37 0
40: 39(ptr) AccessChain 36(local) 21 40: 39(ptr) AccessChain 36(local) 23
Store 40 38 Store 40 38
41: 8(fvec4) CompositeExtract 37 1 41: 8(fvec4) CompositeExtract 37 1
43: 42(ptr) AccessChain 36(local) 27 43: 42(ptr) AccessChain 36(local) 29
Store 43 41 Store 43 41
44: 10(ivec2) CompositeExtract 37 2 44: 10(ivec2) CompositeExtract 37 2
47: 46(ptr) AccessChain 36(local) 45 47: 46(ptr) AccessChain 36(local) 45
Store 47 44 Store 47 44
50: 34(InParam) Load 36(local) 50: 11(InParam) Load 36(local)
Store 49(param) 50 Store 49(param) 50
51: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 49(param) 51: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 49(param)
Store 48(ret1) 51 Store 48(ret1) 51
54: 11(InParam) Load 18(i) 54: 17(InParam) Load 20(i)
Store 53(param) 54 Store 53(param) 54
55: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 53(param) 55: 6(float) FunctionCall 15(fun(struct-InParam-vf2-vf4-vi21;) 53(param)
Store 52(ret2) 55 Store 52(ret2) 55
56: 42(ptr) AccessChain 36(local) 27 56: 42(ptr) AccessChain 36(local) 29
57: 8(fvec4) Load 56 57: 8(fvec4) Load 56
58: 6(float) Load 48(ret1) 58: 6(float) Load 48(ret1)
59: 8(fvec4) VectorTimesScalar 57 58 59: 8(fvec4) VectorTimesScalar 57 58

View File

@ -4,15 +4,15 @@ Shader version: 450
0:17 Function Definition: Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11; (temp void) 0:17 Function Definition: Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11; (temp void)
0:17 Function Parameters: 0:17 Function Parameters:
0:17 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in}) 0:17 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in})
0:17 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:17 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Pos_out, temp int x1_out})
0:? Sequence 0:? Sequence
0:18 add (temp 4-component vector of float) 0:18 add (temp 4-component vector of float)
0:18 Pos_in: direct index for structure (temp 4-component vector of float Position) 0:18 Pos_in: direct index for structure (temp 4-component vector of float)
0:18 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in}) 0:18 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in})
0:18 Constant: 0:18 Constant:
0:18 1 (const int) 0:18 1 (const int)
0:18 Pos_out: direct index for structure (temp 4-component vector of float Position) 0:18 Pos_out: direct index for structure (temp 4-component vector of float)
0:18 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:18 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Pos_out, temp int x1_out})
0:18 Constant: 0:18 Constant:
0:18 1 (const int) 0:18 1 (const int)
0:22 Function Definition: @main(struct-VS_INPUT-i1-vf4-i11; (temp structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:22 Function Definition: @main(struct-VS_INPUT-i1-vf4-i11; (temp structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out})
@ -118,15 +118,15 @@ Shader version: 450
0:17 Function Definition: Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11; (temp void) 0:17 Function Definition: Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11; (temp void)
0:17 Function Parameters: 0:17 Function Parameters:
0:17 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in}) 0:17 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in})
0:17 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:17 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Pos_out, temp int x1_out})
0:? Sequence 0:? Sequence
0:18 add (temp 4-component vector of float) 0:18 add (temp 4-component vector of float)
0:18 Pos_in: direct index for structure (temp 4-component vector of float Position) 0:18 Pos_in: direct index for structure (temp 4-component vector of float)
0:18 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in}) 0:18 'fn1_in' (in structure{temp int x0_in, temp 4-component vector of float Pos_in, temp int x1_in})
0:18 Constant: 0:18 Constant:
0:18 1 (const int) 0:18 1 (const int)
0:18 Pos_out: direct index for structure (temp 4-component vector of float Position) 0:18 Pos_out: direct index for structure (temp 4-component vector of float)
0:18 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:18 'fn1_out' (in structure{temp int x0_out, temp 4-component vector of float Pos_out, temp int x1_out})
0:18 Constant: 0:18 Constant:
0:18 1 (const int) 0:18 1 (const int)
0:22 Function Definition: @main(struct-VS_INPUT-i1-vf4-i11; (temp structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out}) 0:22 Function Definition: @main(struct-VS_INPUT-i1-vf4-i11; (temp structure{temp int x0_out, temp 4-component vector of float Position Pos_out, temp int x1_out})
@ -225,12 +225,12 @@ Shader version: 450
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 93 // Id's are bound by 95
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 62 66 69 78 84 92 EntryPoint Vertex 4 "main" 64 68 71 80 86 94
Name 4 "main" Name 4 "main"
Name 9 "VS_INPUT" Name 9 "VS_INPUT"
MemberName 9(VS_INPUT) 0 "x0_in" MemberName 9(VS_INPUT) 0 "x0_in"
@ -243,37 +243,41 @@ Shader version: 450
Name 16 "Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;" Name 16 "Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;"
Name 14 "fn1_in" Name 14 "fn1_in"
Name 15 "fn1_out" Name 15 "fn1_out"
Name 20 "@main(struct-VS_INPUT-i1-vf4-i11;" Name 18 "VS_INPUT"
Name 19 "vsin" MemberName 18(VS_INPUT) 0 "x0_in"
Name 29 "VS_OUTPUT" MemberName 18(VS_INPUT) 1 "Pos_in"
MemberName 29(VS_OUTPUT) 0 "x0_out" MemberName 18(VS_INPUT) 2 "x1_in"
MemberName 29(VS_OUTPUT) 1 "Pos_out" Name 20 "VS_OUTPUT"
MemberName 29(VS_OUTPUT) 2 "x1_out" MemberName 20(VS_OUTPUT) 0 "x0_out"
Name 31 "vsout" MemberName 20(VS_OUTPUT) 1 "Pos_out"
Name 44 "param" MemberName 20(VS_OUTPUT) 2 "x1_out"
Name 46 "param" Name 23 "@main(struct-VS_INPUT-i1-vf4-i11;"
Name 60 "vsin" Name 22 "vsin"
Name 62 "x0_in" Name 32 "vsout"
Name 66 "Pos_in" Name 45 "param"
Name 69 "x1_in" Name 47 "param"
Name 72 "flattenTemp" Name 62 "vsin"
Name 73 "param" Name 64 "x0_in"
Name 76 "VS_OUTPUT" Name 68 "Pos_in"
MemberName 76(VS_OUTPUT) 0 "x0_out" Name 71 "x1_in"
MemberName 76(VS_OUTPUT) 1 "x1_out" Name 74 "flattenTemp"
Name 78 "@entryPointOutput" Name 75 "param"
Name 84 "@entryPointOutput_Pos_out" Name 78 "VS_OUTPUT"
Name 90 "PerVertex_out" MemberName 78(VS_OUTPUT) 0 "x0_out"
MemberName 90(PerVertex_out) 0 "@entryPointOutput_Pos_out" MemberName 78(VS_OUTPUT) 1 "x1_out"
Name 80 "@entryPointOutput"
Name 86 "@entryPointOutput_Pos_out"
Name 92 "PerVertex_out" Name 92 "PerVertex_out"
MemberDecorate 11(VS_OUTPUT) 1 BuiltIn Position MemberName 92(PerVertex_out) 0 "@entryPointOutput_Pos_out"
Decorate 62(x0_in) Location 0 Name 94 "PerVertex_out"
Decorate 66(Pos_in) BuiltIn Position MemberDecorate 20(VS_OUTPUT) 1 BuiltIn Position
Decorate 69(x1_in) Location 1 Decorate 64(x0_in) Location 0
Decorate 78(@entryPointOutput) Location 0 Decorate 68(Pos_in) BuiltIn Position
Decorate 84(@entryPointOutput_Pos_out) BuiltIn Position Decorate 71(x1_in) Location 1
MemberDecorate 90(PerVertex_out) 0 BuiltIn Position Decorate 80(@entryPointOutput) Location 0
Decorate 90(PerVertex_out) Block Decorate 86(@entryPointOutput_Pos_out) BuiltIn Position
MemberDecorate 92(PerVertex_out) 0 BuiltIn Position
Decorate 92(PerVertex_out) Block
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeInt 32 1 6: TypeInt 32 1
@ -284,104 +288,106 @@ Shader version: 450
11(VS_OUTPUT): TypeStruct 6(int) 8(fvec4) 6(int) 11(VS_OUTPUT): TypeStruct 6(int) 8(fvec4) 6(int)
12: TypePointer Function 11(VS_OUTPUT) 12: TypePointer Function 11(VS_OUTPUT)
13: TypeFunction 2 10(ptr) 12(ptr) 13: TypeFunction 2 10(ptr) 12(ptr)
18: TypeFunction 11(VS_OUTPUT) 10(ptr) 18(VS_INPUT): TypeStruct 6(int) 8(fvec4) 6(int)
22: 6(int) Constant 1 19: TypePointer Function 18(VS_INPUT)
23: TypePointer Function 8(fvec4) 20(VS_OUTPUT): TypeStruct 6(int) 8(fvec4) 6(int)
29(VS_OUTPUT): TypeStruct 6(int) 8(fvec4) 6(int) 21: TypeFunction 20(VS_OUTPUT) 19(ptr)
30: TypePointer Function 29(VS_OUTPUT) 25: 6(int) Constant 1
32: 6(int) Constant 0 26: TypePointer Function 8(fvec4)
33: TypePointer Function 6(int) 33: 6(int) Constant 0
40: 6(int) Constant 2 34: TypePointer Function 6(int)
61: TypePointer Input 6(int) 41: 6(int) Constant 2
62(x0_in): 61(ptr) Variable Input 51: TypePointer Function 20(VS_OUTPUT)
65: TypePointer Input 8(fvec4) 63: TypePointer Input 6(int)
66(Pos_in): 65(ptr) Variable Input 64(x0_in): 63(ptr) Variable Input
69(x1_in): 61(ptr) Variable Input 67: TypePointer Input 8(fvec4)
76(VS_OUTPUT): TypeStruct 6(int) 6(int) 68(Pos_in): 67(ptr) Variable Input
77: TypePointer Output 76(VS_OUTPUT) 71(x1_in): 63(ptr) Variable Input
78(@entryPointOutput): 77(ptr) Variable Output 78(VS_OUTPUT): TypeStruct 6(int) 6(int)
81: TypePointer Output 6(int) 79: TypePointer Output 78(VS_OUTPUT)
83: TypePointer Output 8(fvec4) 80(@entryPointOutput): 79(ptr) Variable Output
84(@entryPointOutput_Pos_out): 83(ptr) Variable Output 83: TypePointer Output 6(int)
90(PerVertex_out): TypeStruct 8(fvec4) 85: TypePointer Output 8(fvec4)
91: TypePointer Output 90(PerVertex_out) 86(@entryPointOutput_Pos_out): 85(ptr) Variable Output
92(PerVertex_out): 91(ptr) Variable Output 92(PerVertex_out): TypeStruct 8(fvec4)
93: TypePointer Output 92(PerVertex_out)
94(PerVertex_out): 93(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
60(vsin): 10(ptr) Variable Function 62(vsin): 19(ptr) Variable Function
72(flattenTemp): 12(ptr) Variable Function 74(flattenTemp): 51(ptr) Variable Function
73(param): 10(ptr) Variable Function 75(param): 19(ptr) Variable Function
63: 6(int) Load 62(x0_in) 65: 6(int) Load 64(x0_in)
64: 33(ptr) AccessChain 60(vsin) 32 66: 34(ptr) AccessChain 62(vsin) 33
Store 64 63 Store 66 65
67: 8(fvec4) Load 66(Pos_in) 69: 8(fvec4) Load 68(Pos_in)
68: 23(ptr) AccessChain 60(vsin) 22 70: 26(ptr) AccessChain 62(vsin) 25
Store 68 67 Store 70 69
70: 6(int) Load 69(x1_in) 72: 6(int) Load 71(x1_in)
71: 33(ptr) AccessChain 60(vsin) 40 73: 34(ptr) AccessChain 62(vsin) 41
Store 71 70 Store 73 72
74: 9(VS_INPUT) Load 60(vsin) 76:18(VS_INPUT) Load 62(vsin)
Store 73(param) 74 Store 75(param) 76
75:11(VS_OUTPUT) FunctionCall 20(@main(struct-VS_INPUT-i1-vf4-i11;) 73(param) 77:20(VS_OUTPUT) FunctionCall 23(@main(struct-VS_INPUT-i1-vf4-i11;) 75(param)
Store 72(flattenTemp) 75 Store 74(flattenTemp) 77
79: 33(ptr) AccessChain 72(flattenTemp) 32 81: 34(ptr) AccessChain 74(flattenTemp) 33
80: 6(int) Load 79 82: 6(int) Load 81
82: 81(ptr) AccessChain 78(@entryPointOutput) 32 84: 83(ptr) AccessChain 80(@entryPointOutput) 33
Store 82 80 Store 84 82
85: 23(ptr) AccessChain 72(flattenTemp) 22 87: 26(ptr) AccessChain 74(flattenTemp) 25
86: 8(fvec4) Load 85 88: 8(fvec4) Load 87
Store 84(@entryPointOutput_Pos_out) 86 Store 86(@entryPointOutput_Pos_out) 88
87: 33(ptr) AccessChain 72(flattenTemp) 40 89: 34(ptr) AccessChain 74(flattenTemp) 41
88: 6(int) Load 87 90: 6(int) Load 89
89: 81(ptr) AccessChain 78(@entryPointOutput) 22 91: 83(ptr) AccessChain 80(@entryPointOutput) 25
Store 89 88 Store 91 90
Return Return
FunctionEnd FunctionEnd
16(Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;): 2 Function None 13 16(Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;): 2 Function None 13
14(fn1_in): 10(ptr) FunctionParameter 14(fn1_in): 10(ptr) FunctionParameter
15(fn1_out): 12(ptr) FunctionParameter 15(fn1_out): 12(ptr) FunctionParameter
17: Label 17: Label
24: 23(ptr) AccessChain 14(fn1_in) 22 27: 26(ptr) AccessChain 14(fn1_in) 25
25: 8(fvec4) Load 24 28: 8(fvec4) Load 27
26: 23(ptr) AccessChain 15(fn1_out) 22 29: 26(ptr) AccessChain 15(fn1_out) 25
27: 8(fvec4) Load 26 30: 8(fvec4) Load 29
28: 8(fvec4) FAdd 25 27 31: 8(fvec4) FAdd 28 30
Return Return
FunctionEnd FunctionEnd
20(@main(struct-VS_INPUT-i1-vf4-i11;):11(VS_OUTPUT) Function None 18 23(@main(struct-VS_INPUT-i1-vf4-i11;):20(VS_OUTPUT) Function None 21
19(vsin): 10(ptr) FunctionParameter 22(vsin): 19(ptr) FunctionParameter
21: Label 24: Label
31(vsout): 30(ptr) Variable Function 32(vsout): 12(ptr) Variable Function
44(param): 10(ptr) Variable Function 45(param): 19(ptr) Variable Function
46(param): 30(ptr) Variable Function 47(param): 12(ptr) Variable Function
50: 12(ptr) Variable Function 52: 51(ptr) Variable Function
34: 33(ptr) AccessChain 19(vsin) 32 35: 34(ptr) AccessChain 22(vsin) 33
35: 6(int) Load 34 36: 6(int) Load 35
36: 33(ptr) AccessChain 31(vsout) 32 37: 34(ptr) AccessChain 32(vsout) 33
Store 36 35 Store 37 36
37: 23(ptr) AccessChain 19(vsin) 22 38: 26(ptr) AccessChain 22(vsin) 25
38: 8(fvec4) Load 37 39: 8(fvec4) Load 38
39: 23(ptr) AccessChain 31(vsout) 22 40: 26(ptr) AccessChain 32(vsout) 25
Store 39 38 Store 40 39
41: 33(ptr) AccessChain 19(vsin) 40 42: 34(ptr) AccessChain 22(vsin) 41
42: 6(int) Load 41 43: 6(int) Load 42
43: 33(ptr) AccessChain 31(vsout) 40 44: 34(ptr) AccessChain 32(vsout) 41
Store 43 42 Store 44 43
45: 9(VS_INPUT) Load 19(vsin) 46:18(VS_INPUT) Load 22(vsin)
Store 44(param) 45 Store 45(param) 46
47:29(VS_OUTPUT) Load 31(vsout) 48:11(VS_OUTPUT) Load 32(vsout)
Store 46(param) 47 Store 47(param) 48
48: 2 FunctionCall 16(Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;) 44(param) 46(param) 49: 2 FunctionCall 16(Fn1(struct-VS_INPUT-i1-vf4-i11;struct-VS_OUTPUT-i1-vf4-i11;) 45(param) 47(param)
49:29(VS_OUTPUT) Load 31(vsout) 50:11(VS_OUTPUT) Load 32(vsout)
51: 6(int) CompositeExtract 49 0 53: 6(int) CompositeExtract 50 0
52: 33(ptr) AccessChain 50 32 54: 34(ptr) AccessChain 52 33
Store 52 51
53: 8(fvec4) CompositeExtract 49 1
54: 23(ptr) AccessChain 50 22
Store 54 53 Store 54 53
55: 6(int) CompositeExtract 49 2 55: 8(fvec4) CompositeExtract 50 1
56: 33(ptr) AccessChain 50 40 56: 26(ptr) AccessChain 52 25
Store 56 55 Store 56 55
57:11(VS_OUTPUT) Load 50 57: 6(int) CompositeExtract 50 2
ReturnValue 57 58: 34(ptr) AccessChain 52 41
Store 58 57
59:20(VS_OUTPUT) Load 52
ReturnValue 59
FunctionEnd FunctionEnd

View File

@ -401,7 +401,20 @@ public:
// drop qualifiers that don't belong in a temporary variable // drop qualifiers that don't belong in a temporary variable
void makeTemporary() void makeTemporary()
{ {
makeNonIo();
storage = EvqTemporary; storage = EvqTemporary;
specConstant = false;
coherent = false;
volatil = false;
restrict = false;
readonly = false;
writeonly = false;
}
// Remove IO related data from qualifier.
void makeNonIo()
{
// This preserves the storage type
builtIn = EbvNone; builtIn = EbvNone;
centroid = false; centroid = false;
smooth = false; smooth = false;
@ -412,15 +425,18 @@ public:
#endif #endif
patch = false; patch = false;
sample = false; sample = false;
coherent = false;
volatil = false;
restrict = false;
readonly = false;
writeonly = false;
specConstant = false;
clearLayout(); clearLayout();
} }
// Return true if there is data which would be scrubbed by makeNonIo
bool hasIoData() const
{
return builtIn != EbvNone ||
hasLayout() ||
isInterpolation() ||
isAuxiliary();
}
// Drop just the storage qualification, which perhaps should // Drop just the storage qualification, which perhaps should
// never be done, as it is fundamentally inconsistent, but need to // never be done, as it is fundamentally inconsistent, but need to
// explore what downstream consumers need. // explore what downstream consumers need.
@ -1209,6 +1225,30 @@ public:
deepCopy(copyOf, copied); deepCopy(copyOf, copied);
} }
// Return true if type (recursively) contains IO data.
bool hasIoData() const
{
if (getQualifier().hasIoData())
return true;
if (isStruct())
for (unsigned int i = 0; i < structure->size(); ++i)
if ((*structure)[i].type->hasIoData())
return true;
return false;
}
// Remove IO related data from type
void makeNonIo()
{
getQualifier().makeNonIo();
if (isStruct())
for (unsigned int i = 0; i < structure->size(); ++i)
(*structure)[i].type->makeNonIo();
}
// Recursively make temporary // Recursively make temporary
void makeTemporary() void makeTemporary()
{ {
@ -1701,6 +1741,7 @@ public:
const char* getBuiltInVariableString() const { return GetBuiltInVariableString(qualifier.builtIn); } const char* getBuiltInVariableString() const { return GetBuiltInVariableString(qualifier.builtIn); }
const char* getPrecisionQualifierString() const { return GetPrecisionQualifierString(qualifier.precision); } const char* getPrecisionQualifierString() const { return GetPrecisionQualifierString(qualifier.precision); }
const TTypeList* getStruct() const { return structure; } const TTypeList* getStruct() const { return structure; }
void setStruct(TTypeList* s) { structure = s; }
TTypeList* getWritableStruct() const { return structure; } // This should only be used when known to not be sharing with other threads TTypeList* getWritableStruct() const { return structure; } // This should only be used when known to not be sharing with other threads
int computeNumComponents() const int computeNumComponents() const

View File

@ -1803,15 +1803,13 @@ void HlslParseContext::remapEntryPointIO(const TFunction& function, TVariable*&
// declares entry point IO built-ins, but these have to be undone. // declares entry point IO built-ins, but these have to be undone.
void HlslParseContext::remapNonEntryPointIO(TFunction& function) void HlslParseContext::remapNonEntryPointIO(TFunction& function)
{ {
const auto remapBuiltInType = [&](TType& type) { type.getQualifier().builtIn = EbvNone; };
// return value // return value
if (function.getType().getBasicType() != EbtVoid) if (function.getType().getBasicType() != EbtVoid)
remapBuiltInType(function.getWritableType()); makeNonIoType(&function.getWritableType());
// parameters // parameters
for (int i = 0; i < function.getParamCount(); i++) for (int i = 0; i < function.getParamCount(); i++)
remapBuiltInType(*function[i].type); makeNonIoType(function[i].type);
} }
// Handle function returns, including type conversions to the function return type // Handle function returns, including type conversions to the function return type
@ -5393,41 +5391,43 @@ void HlslParseContext::declareTypedef(const TSourceLoc& loc, TString& identifier
error(loc, "name already defined", "typedef", identifier.c_str()); error(loc, "name already defined", "typedef", identifier.c_str());
} }
// Type sanitization: return existing sanitized (temporary) type if there is one, else make new one. // Create a non-IO type from an IO type. If there is no IO data, this
TType* HlslParseContext::sanitizeType(TType* type) // returns the input type unmodified. Otherwise, it modifies the type
// in place, and returns a pointer to it.
TType* HlslParseContext::makeNonIoType(TType* type)
{ {
// We only do this for structs. // early out if there's nothing to do: prevents introduction of unneeded types.
if (!type->hasIoData())
return type;
type->getQualifier().makeNonIo(); // Sanitize the qualifier.
// Nothing more to do if there is no deep structure.
if (!type->isStruct()) if (!type->isStruct())
return type; return type;
// Type sanitization: if this is declaring a variable of a type that contains const auto typeIter = nonIoTypeMap.find(type->getStruct());
// interstage IO, we want to make it a temporary.
const auto sanitizedTypeIter = sanitizedTypeMap.find(type->getStruct());
if (sanitizedTypeIter != sanitizedTypeMap.end()) { if (typeIter != nonIoTypeMap.end()) {
// We've sanitized this before. Use that one. // reuse deep structure if we have sanitized it before, but we must preserve
TType* sanitizedType = new TType(); // our unique shallow structure, which may not be shared with other users of
sanitizedType->shallowCopy(*sanitizedTypeIter->second); // the deep copy. Create a new type with the sanitized qualifier, and the
// shared deep structure
// Arrayness is not part of the sanitized type. Use the input type's arrayness. type->setStruct(typeIter->second); // share already sanitized deep structure.
if (type->isArray())
sanitizedType->newArraySizes(type->getArraySizes());
else
sanitizedType->clearArraySizes();
return sanitizedType;
} else { } else {
if (type->containsBuiltInInterstageIO(language)) { // The type contains interstage IO, but we've never encountered it before.
// This means the type contains interstage IO, but we've never encountered it before. // Copy it, scrub data we don't want for an non-IO type, and remember it in the nonIoTypeMap
// Copy it, sanitize it, and remember it in the sanitizedTypeMap
TType* sanitizedType = type->clone(); TType nonIoType;
sanitizedType->makeTemporary(); nonIoType.deepCopy(*type);
sanitizedTypeMap[type->getStruct()] = sanitizedType; nonIoType.makeNonIo();
return sanitizedType;
} else { // remember the new deep structure in a map, so we can share it in the future.
// This means the type has no interstage IO, so we can use it as is. nonIoTypeMap[type->getStruct()] = nonIoType.getWritableStruct();
return type; type->shallowCopy(nonIoType); // we modify the input type in place
} }
}
return type;
} }
// //
@ -5456,18 +5456,23 @@ TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& i
const bool flattenVar = shouldFlattenUniform(type); const bool flattenVar = shouldFlattenUniform(type);
// Type sanitization: if this is declaring a variable of a type that contains // make non-IO version of type
// interstage IO, we want to make it a temporary. switch (type.getQualifier().storage) {
TType* sanitizedType = sanitizeType(&type); case EvqGlobal:
case EvqTemporary:
makeNonIoType(&type);
default:
break;
}
// Declare the variable // Declare the variable
if (type.isArray()) { if (type.isArray()) {
// array case // array case
declareArray(loc, identifier, *sanitizedType, symbol, !flattenVar); declareArray(loc, identifier, type, symbol, !flattenVar);
} else { } else {
// non-array case // non-array case
if (! symbol) if (! symbol)
symbol = declareNonArray(loc, identifier, *sanitizedType, !flattenVar); symbol = declareNonArray(loc, identifier, type, !flattenVar);
else if (type != symbol->getType()) else if (type != symbol->getType())
error(loc, "cannot change the type of", "redeclaration", symbol->getName().c_str()); error(loc, "cannot change the type of", "redeclaration", symbol->getName().c_str());
} }

View File

@ -228,8 +228,9 @@ protected:
int flattenStruct(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name); int flattenStruct(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
int flattenArray(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name); int flattenArray(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
// Type sanitization: return existing sanitized (temporary) type if there is one, else make new one. // Create a non-IO type from an IO type. If there is no IO data, this returns the input type unmodified.
TType* sanitizeType(TType*); // Otherwise, it modifies the type in place, and returns a pointer to it.
TType* makeNonIoType(TType*);
void finish() override; // post-processing void finish() override; // post-processing
@ -296,9 +297,9 @@ protected:
TVector<int> flattenLevel; // nested postfix operator level for flattening TVector<int> flattenLevel; // nested postfix operator level for flattening
TVector<int> flattenOffset; // cumulative offset for flattening TVector<int> flattenOffset; // cumulative offset for flattening
// Sanitized type map. During declarations we use the sanitized form of the type // Sanitized type map. If the same type is sanitized again, we want to reuse it.
// if it exists. // We cannot index by the TType: the map is typelist to typelist.
TMap<const TTypeList*, TType*> sanitizedTypeMap; TMap<const TTypeList*, TTypeList*> nonIoTypeMap;
// Structure splitting data: // Structure splitting data:
TMap<int, TVariable*> splitIoVars; // variables with the builtin interstage IO removed, indexed by unique ID. TMap<int, TVariable*> splitIoVars; // variables with the builtin interstage IO removed, indexed by unique ID.