SPV: Fix #1016: Don't allow non-GLSL-extension protected Layer and ViewportIndex members.

This commit is contained in:
John Kessenich 2017-08-17 23:49:39 -06:00
parent 03e63fa805
commit d6be6da031
5 changed files with 124 additions and 57 deletions

View File

@ -2465,6 +2465,10 @@ bool TGlslangToSpvTraverser::filterMember(const glslang::TType& member)
if (member.getFieldName() == "gl_ViewportMaskPerViewNV" && if (member.getFieldName() == "gl_ViewportMaskPerViewNV" &&
extensions.find("GL_NVX_multiview_per_view_attributes") == extensions.end()) extensions.find("GL_NVX_multiview_per_view_attributes") == extensions.end())
return true; return true;
if ((member.getFieldName() == "gl_ViewportIndex" || member.getFieldName() == "gl_Layer") &&
extensions.find(glslang::E_GL_ARB_shader_viewport_layer_array) == extensions.end() &&
extensions.find(glslang::E_GL_NV_viewport_array2) == extensions.end())
return true;
return false; return false;
}; };

View File

@ -1,13 +1,14 @@
spv.450.geom spv.450.geom
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 26 // Id's are bound by 31
Capability Geometry Capability Geometry
Capability GeometryPointSize Capability GeometryPointSize
Capability MultiViewport
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Geometry 4 "main" 13 20 EntryPoint Geometry 4 "main" 13 20 27 29
ExecutionMode 4 Triangles ExecutionMode 4 Triangles
ExecutionMode 4 Invocations 4 ExecutionMode 4 Invocations 4
ExecutionMode 4 OutputLineStrip ExecutionMode 4 OutputLineStrip
@ -26,6 +27,8 @@ spv.450.geom
MemberName 16(gl_PerVertex) 2 "gl_ClipDistance" MemberName 16(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 16(gl_PerVertex) 3 "gl_CullDistance" MemberName 16(gl_PerVertex) 3 "gl_CullDistance"
Name 20 "gl_in" Name 20 "gl_in"
Name 27 "gl_Layer"
Name 29 "gl_ViewportIndex"
MemberDecorate 11(gl_PerVertex) 0 BuiltIn Position MemberDecorate 11(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 11(gl_PerVertex) 1 BuiltIn PointSize MemberDecorate 11(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 11(gl_PerVertex) 2 BuiltIn ClipDistance MemberDecorate 11(gl_PerVertex) 2 BuiltIn ClipDistance
@ -36,6 +39,8 @@ spv.450.geom
MemberDecorate 16(gl_PerVertex) 2 BuiltIn ClipDistance MemberDecorate 16(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 16(gl_PerVertex) 3 BuiltIn CullDistance MemberDecorate 16(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 16(gl_PerVertex) Block Decorate 16(gl_PerVertex) Block
Decorate 27(gl_Layer) BuiltIn Layer
Decorate 29(gl_ViewportIndex) BuiltIn ViewportIndex
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -55,11 +60,18 @@ spv.450.geom
20(gl_in): 19(ptr) Variable Input 20(gl_in): 19(ptr) Variable Input
21: TypePointer Input 6(float) 21: TypePointer Input 6(float)
24: TypePointer Output 6(float) 24: TypePointer Output 6(float)
26: TypePointer Output 14(int)
27(gl_Layer): 26(ptr) Variable Output
28: 14(int) Constant 2
29(gl_ViewportIndex): 26(ptr) Variable Output
30: 14(int) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
22: 21(ptr) AccessChain 20(gl_in) 15 15 22: 21(ptr) AccessChain 20(gl_in) 15 15
23: 6(float) Load 22 23: 6(float) Load 22
25: 24(ptr) AccessChain 13 15 25: 24(ptr) AccessChain 13 15
Store 25 23 Store 25 23
Store 27(gl_Layer) 28
Store 29(gl_ViewportIndex) 30
Return Return
FunctionEnd FunctionEnd

View File

@ -1,72 +1,120 @@
spv.450.tesc spv.450.tesc
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 23 // Id's are bound by 45
Capability Tessellation Capability Tessellation
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint TessellationControl 4 "main" 9 16 19 22 EntryPoint TessellationControl 4 "main" 15 18 25 32 38 41 44
ExecutionMode 4 OutputVertices 4 ExecutionMode 4 OutputVertices 4
Source GLSL 450 Source GLSL 450
Name 4 "main" Name 4 "main"
Name 9 "patchOut" Name 11 "gl_PerVertex"
Name 10 "S" MemberName 11(gl_PerVertex) 0 "gl_Position"
MemberName 10(S) 0 "sMem1" MemberName 11(gl_PerVertex) 1 "gl_PointSize"
MemberName 10(S) 1 "sMem2" MemberName 11(gl_PerVertex) 2 "gl_ClipDistance"
Name 11 "TheBlock" MemberName 11(gl_PerVertex) 3 "gl_CullDistance"
MemberName 11(TheBlock) 0 "bMem1" Name 15 "gl_out"
MemberName 11(TheBlock) 1 "bMem2" Name 18 "gl_InvocationID"
MemberName 11(TheBlock) 2 "s" Name 21 "gl_PerVertex"
Name 16 "tcBlock" MemberName 21(gl_PerVertex) 0 "gl_Position"
Name 17 "SingleBlock" MemberName 21(gl_PerVertex) 1 "gl_PointSize"
MemberName 17(SingleBlock) 0 "bMem1" MemberName 21(gl_PerVertex) 2 "gl_ClipDistance"
MemberName 17(SingleBlock) 1 "bMem2" MemberName 21(gl_PerVertex) 3 "gl_CullDistance"
MemberName 17(SingleBlock) 2 "s" Name 25 "gl_in"
Name 19 "singleBlock" Name 32 "patchOut"
Name 20 "bn" Name 33 "S"
MemberName 20(bn) 0 "v1" MemberName 33(S) 0 "sMem1"
MemberName 20(bn) 1 "v2" MemberName 33(S) 1 "sMem2"
MemberName 20(bn) 2 "v3" Name 34 "TheBlock"
Name 22 "" MemberName 34(TheBlock) 0 "bMem1"
Decorate 9(patchOut) Patch MemberName 34(TheBlock) 1 "bMem2"
MemberDecorate 11(TheBlock) 0 Patch MemberName 34(TheBlock) 2 "s"
MemberDecorate 11(TheBlock) 1 Patch Name 38 "tcBlock"
MemberDecorate 11(TheBlock) 2 Patch Name 39 "SingleBlock"
Decorate 11(TheBlock) Block MemberName 39(SingleBlock) 0 "bMem1"
Decorate 16(tcBlock) Location 12 MemberName 39(SingleBlock) 1 "bMem2"
MemberDecorate 17(SingleBlock) 0 Patch MemberName 39(SingleBlock) 2 "s"
MemberDecorate 17(SingleBlock) 1 Patch Name 41 "singleBlock"
MemberDecorate 17(SingleBlock) 2 Patch Name 42 "bn"
Decorate 17(SingleBlock) Block MemberName 42(bn) 0 "v1"
Decorate 19(singleBlock) Location 2 MemberName 42(bn) 1 "v2"
MemberDecorate 20(bn) 0 Patch MemberName 42(bn) 2 "v3"
MemberDecorate 20(bn) 0 Location 20 Name 44 ""
MemberDecorate 20(bn) 1 Patch MemberDecorate 11(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 20(bn) 1 Location 24 MemberDecorate 11(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 20(bn) 2 Patch MemberDecorate 11(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 20(bn) 2 Location 25 MemberDecorate 11(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 20(bn) Block Decorate 11(gl_PerVertex) Block
Decorate 18(gl_InvocationID) BuiltIn InvocationId
MemberDecorate 21(gl_PerVertex) 0 BuiltIn Position
MemberDecorate 21(gl_PerVertex) 1 BuiltIn PointSize
MemberDecorate 21(gl_PerVertex) 2 BuiltIn ClipDistance
MemberDecorate 21(gl_PerVertex) 3 BuiltIn CullDistance
Decorate 21(gl_PerVertex) Block
Decorate 32(patchOut) Patch
Decorate 32(patchOut) Location 1
MemberDecorate 34(TheBlock) 0 Patch
MemberDecorate 34(TheBlock) 1 Patch
MemberDecorate 34(TheBlock) 2 Patch
Decorate 34(TheBlock) Block
Decorate 38(tcBlock) Location 12
MemberDecorate 39(SingleBlock) 0 Patch
MemberDecorate 39(SingleBlock) 1 Patch
MemberDecorate 39(SingleBlock) 2 Patch
Decorate 39(SingleBlock) Block
Decorate 41(singleBlock) Location 2
MemberDecorate 42(bn) 0 Patch
MemberDecorate 42(bn) 0 Location 20
MemberDecorate 42(bn) 1 Patch
MemberDecorate 42(bn) 1 Location 24
MemberDecorate 42(bn) 2 Patch
MemberDecorate 42(bn) 2 Location 25
Decorate 42(bn) Block
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
7: TypeVector 6(float) 4 7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4) 8: TypeInt 32 0
9(patchOut): 8(ptr) Variable Output 9: 8(int) Constant 1
10(S): TypeStruct 6(float) 6(float) 10: TypeArray 6(float) 9
11(TheBlock): TypeStruct 6(float) 6(float) 10(S) 11(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 10 10
12: TypeInt 32 0 12: 8(int) Constant 4
13: 12(int) Constant 2 13: TypeArray 11(gl_PerVertex) 12
14: TypeArray 11(TheBlock) 13 14: TypePointer Output 13
15: TypePointer Output 14 15(gl_out): 14(ptr) Variable Output
16(tcBlock): 15(ptr) Variable Output 16: TypeInt 32 1
17(SingleBlock): TypeStruct 6(float) 6(float) 10(S) 17: TypePointer Input 16(int)
18: TypePointer Output 17(SingleBlock) 18(gl_InvocationID): 17(ptr) Variable Input
19(singleBlock): 18(ptr) Variable Output 20: 16(int) Constant 0
20(bn): TypeStruct 7(fvec4) 7(fvec4) 7(fvec4) 21(gl_PerVertex): TypeStruct 7(fvec4) 6(float) 10 10
21: TypePointer Output 20(bn) 22: 8(int) Constant 32
22: 21(ptr) Variable Output 23: TypeArray 21(gl_PerVertex) 22
24: TypePointer Input 23
25(gl_in): 24(ptr) Variable Input
27: TypePointer Input 7(fvec4)
30: TypePointer Output 7(fvec4)
32(patchOut): 30(ptr) Variable Output
33(S): TypeStruct 6(float) 6(float)
34(TheBlock): TypeStruct 6(float) 6(float) 33(S)
35: 8(int) Constant 2
36: TypeArray 34(TheBlock) 35
37: TypePointer Output 36
38(tcBlock): 37(ptr) Variable Output
39(SingleBlock): TypeStruct 6(float) 6(float) 33(S)
40: TypePointer Output 39(SingleBlock)
41(singleBlock): 40(ptr) Variable Output
42(bn): TypeStruct 7(fvec4) 7(fvec4) 7(fvec4)
43: TypePointer Output 42(bn)
44: 43(ptr) Variable Output
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
19: 16(int) Load 18(gl_InvocationID)
26: 16(int) Load 18(gl_InvocationID)
28: 27(ptr) AccessChain 25(gl_in) 26 20
29: 7(fvec4) Load 28
31: 30(ptr) AccessChain 15(gl_out) 19 20
Store 31 29
Return Return
FunctionEnd FunctionEnd

View File

@ -9,4 +9,6 @@ layout(invocations = 4) in;
void main() void main()
{ {
gl_PointSize = gl_in[1].gl_PointSize; gl_PointSize = gl_in[1].gl_PointSize;
gl_Layer = 2;
gl_ViewportIndex = 3;
} }

View File

@ -2,7 +2,7 @@
layout(vertices = 4) out; layout(vertices = 4) out;
patch out vec4 patchOut; layout(location=1) patch out vec4 patchOut;
struct S { struct S {
float sMem1; // should not see a patch decoration float sMem1; // should not see a patch decoration
@ -17,6 +17,7 @@ layout(location = 12) patch out TheBlock {
void main() void main()
{ {
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
} }
layout(location = 2) patch out SingleBlock { layout(location = 2) patch out SingleBlock {