Add support for spirv1.6

Add command line support which enables the following behavior:

- Remap discard

  Map discard to DemoteToHelperInvocation for HLSL shaders. Map to
  OpTerminateInvocation for GLSL shaders.

- Decorate HelperInvocation with Volatile

- Use localSizeId for execution mode

  WorkGroupSize is deprecated in spirv1.6

Also update known goods to SPIRV 1.6
This commit is contained in:
Greg Fischer
2021-09-02 17:37:39 -06:00
parent a0f98ad401
commit 7a49192d23
19 changed files with 556 additions and 218 deletions

View File

@@ -0,0 +1,193 @@
hlsl.spv.1.6.discard.frag
Shader version: 500
0:? Sequence
0:2 Function Definition: foo(f1; ( temp void)
0:2 Function Parameters:
0:2 'f' ( in float)
0:? Sequence
0:3 Test condition and select ( temp void)
0:3 Condition
0:3 Compare Less Than ( temp bool)
0:3 'f' ( in float)
0:3 Constant:
0:3 1.000000
0:3 true case
0:4 Branch: Kill
0:8 Function Definition: @PixelShaderFunction(vf4; ( temp void)
0:8 Function Parameters:
0:8 'input' ( in 4-component vector of float)
0:? Sequence
0:9 Function Call: foo(f1; ( temp void)
0:9 direct index ( temp float)
0:9 'input' ( in 4-component vector of float)
0:9 Constant:
0:9 2 (const int)
0:10 Test condition and select ( temp void)
0:10 Condition
0:10 Convert float to bool ( temp bool)
0:10 direct index ( temp float)
0:10 'input' ( in 4-component vector of float)
0:10 Constant:
0:10 0 (const int)
0:10 true case
0:11 Branch: Kill
0:12 Sequence
0:12 move second child to first child ( temp float)
0:12 'f' ( temp float)
0:12 direct index ( temp float)
0:12 'input' ( in 4-component vector of float)
0:12 Constant:
0:12 0 (const int)
0:13 Branch: Kill
0:8 Function Definition: PixelShaderFunction( ( temp void)
0:8 Function Parameters:
0:? Sequence
0:8 move second child to first child ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
0:8 Function Call: @PixelShaderFunction(vf4; ( temp void)
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'input' (layout( location=0) in 4-component vector of float)
Linked fragment stage:
Shader version: 500
0:? Sequence
0:2 Function Definition: foo(f1; ( temp void)
0:2 Function Parameters:
0:2 'f' ( in float)
0:? Sequence
0:3 Test condition and select ( temp void)
0:3 Condition
0:3 Compare Less Than ( temp bool)
0:3 'f' ( in float)
0:3 Constant:
0:3 1.000000
0:3 true case
0:4 Branch: Kill
0:8 Function Definition: @PixelShaderFunction(vf4; ( temp void)
0:8 Function Parameters:
0:8 'input' ( in 4-component vector of float)
0:? Sequence
0:9 Function Call: foo(f1; ( temp void)
0:9 direct index ( temp float)
0:9 'input' ( in 4-component vector of float)
0:9 Constant:
0:9 2 (const int)
0:10 Test condition and select ( temp void)
0:10 Condition
0:10 Convert float to bool ( temp bool)
0:10 direct index ( temp float)
0:10 'input' ( in 4-component vector of float)
0:10 Constant:
0:10 0 (const int)
0:10 true case
0:11 Branch: Kill
0:12 Sequence
0:12 move second child to first child ( temp float)
0:12 'f' ( temp float)
0:12 direct index ( temp float)
0:12 'input' ( in 4-component vector of float)
0:12 Constant:
0:12 0 (const int)
0:13 Branch: Kill
0:8 Function Definition: PixelShaderFunction( ( temp void)
0:8 Function Parameters:
0:? Sequence
0:8 move second child to first child ( temp 4-component vector of float)
0:? 'input' ( temp 4-component vector of float)
0:? 'input' (layout( location=0) in 4-component vector of float)
0:8 Function Call: @PixelShaderFunction(vf4; ( temp void)
0:? 'input' ( temp 4-component vector of float)
0:? Linker Objects
0:? 'input' (layout( location=0) in 4-component vector of float)
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 47
Capability Shader
Capability DemoteToHelperInvocationEXT
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 42
ExecutionMode 4 OriginLowerLeft
Source HLSL 500
Name 4 "PixelShaderFunction"
Name 10 "foo(f1;"
Name 9 "f"
Name 16 "@PixelShaderFunction(vf4;"
Name 15 "input"
Name 24 "param"
Name 37 "f"
Name 40 "input"
Name 42 "input"
Name 44 "param"
Decorate 42(input) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Function 6(float)
8: TypeFunction 2 7(ptr)
12: TypeVector 6(float) 4
13: TypePointer Function 12(fvec4)
14: TypeFunction 2 13(ptr)
19: 6(float) Constant 1065353216
20: TypeBool
25: TypeInt 32 0
26: 25(int) Constant 2
30: 25(int) Constant 0
33: 6(float) Constant 0
41: TypePointer Input 12(fvec4)
42(input): 41(ptr) Variable Input
4(PixelShaderFunction): 2 Function None 3
5: Label
40(input): 13(ptr) Variable Function
44(param): 13(ptr) Variable Function
43: 12(fvec4) Load 42(input)
Store 40(input) 43
45: 12(fvec4) Load 40(input)
Store 44(param) 45
46: 2 FunctionCall 16(@PixelShaderFunction(vf4;) 44(param)
Return
FunctionEnd
10(foo(f1;): 2 Function None 8
9(f): 7(ptr) FunctionParameter
11: Label
18: 6(float) Load 9(f)
21: 20(bool) FOrdLessThan 18 19
SelectionMerge 23 None
BranchConditional 21 22 23
22: Label
DemoteToHelperInvocationEXT
Branch 23
23: Label
Return
FunctionEnd
16(@PixelShaderFunction(vf4;): 2 Function None 14
15(input): 13(ptr) FunctionParameter
17: Label
24(param): 7(ptr) Variable Function
37(f): 7(ptr) Variable Function
27: 7(ptr) AccessChain 15(input) 26
28: 6(float) Load 27
Store 24(param) 28
29: 2 FunctionCall 10(foo(f1;) 24(param)
31: 7(ptr) AccessChain 15(input) 30
32: 6(float) Load 31
34: 20(bool) FUnordNotEqual 32 33
SelectionMerge 36 None
BranchConditional 34 35 36
35: Label
DemoteToHelperInvocationEXT
Branch 36
36: Label
38: 7(ptr) AccessChain 15(input) 30
39: 6(float) Load 38
Store 37(f) 39
DemoteToHelperInvocationEXT
Return
FunctionEnd

View File

@@ -0,0 +1,59 @@
spv.1.6.conditionalDiscard.frag
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 36
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 13 17 34
ExecutionMode 4 OriginLowerLeft
Source GLSL 400
Name 4 "main"
Name 9 "v"
Name 13 "tex"
Name 17 "coord"
Name 34 "gl_FragColor"
Decorate 13(tex) DescriptorSet 0
Decorate 13(tex) Binding 0
Decorate 17(coord) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
10: TypeImage 6(float) 2D sampled format:Unknown
11: TypeSampledImage 10
12: TypePointer UniformConstant 11
13(tex): 12(ptr) Variable UniformConstant
15: TypeVector 6(float) 2
16: TypePointer Input 15(fvec2)
17(coord): 16(ptr) Variable Input
21: 6(float) Constant 1036831949
22: 6(float) Constant 1045220557
23: 6(float) Constant 1050253722
24: 6(float) Constant 1053609165
25: 7(fvec4) ConstantComposite 21 22 23 24
26: TypeBool
27: TypeVector 26(bool) 4
33: TypePointer Output 7(fvec4)
34(gl_FragColor): 33(ptr) Variable Output
4(main): 2 Function None 3
5: Label
9(v): 8(ptr) Variable Function
14: 11 Load 13(tex)
18: 15(fvec2) Load 17(coord)
19: 7(fvec4) ImageSampleImplicitLod 14 18
Store 9(v) 19
20: 7(fvec4) Load 9(v)
28: 27(bvec4) FOrdEqual 20 25
29: 26(bool) All 28
SelectionMerge 31 None
BranchConditional 29 30 31
30: Label
TerminateInvocation
31: Label
35: 7(fvec4) Load 9(v)
Store 34(gl_FragColor) 35
Return
FunctionEnd

View File

@@ -0,0 +1,41 @@
spv.1.6.helperInvocation.frag
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 20
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 15
ExecutionMode 4 OriginLowerLeft
Source ESSL 310
Name 4 "main"
Name 8 "gl_HelperInvocation"
Name 15 "outp"
Decorate 8(gl_HelperInvocation) BuiltIn HelperInvocation
Decorate 8(gl_HelperInvocation) Volatile
Decorate 15(outp) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeBool
7: TypePointer Input 6(bool)
8(gl_HelperInvocation): 7(ptr) Variable Input
12: TypeFloat 32
13: TypeVector 12(float) 4
14: TypePointer Output 13(fvec4)
15(outp): 14(ptr) Variable Output
17: 12(float) Constant 1065353216
4(main): 2 Function None 3
5: Label
9: 6(bool) Load 8(gl_HelperInvocation)
SelectionMerge 11 None
BranchConditional 9 10 11
10: Label
16: 13(fvec4) Load 15(outp)
18: 13(fvec4) CompositeConstruct 17 17 17 17
19: 13(fvec4) FAdd 16 18
Store 15(outp) 19
Branch 11
11: Label
Return
FunctionEnd

View File

@@ -0,0 +1,69 @@
spv.1.6.specConstant.comp
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 39
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 18
ExecutionModeId 4 LocalSizeId 7 8 9
Source GLSL 450
Name 4 "main"
Name 14 "foo(vu3;"
Name 13 "wgs"
Name 16 "bn"
MemberName 16(bn) 0 "a"
Name 18 "bi"
Name 37 "param"
Decorate 7 SpecId 18
Decorate 9 SpecId 19
MemberDecorate 16(bn) 0 Offset 0
Decorate 16(bn) Block
Decorate 18(bi) DescriptorSet 0
Decorate 18(bi) Binding 0
Decorate 25 SpecId 18
Decorate 26 SpecId 19
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: 6(int) SpecConstant 32
8: 6(int) Constant 32
9: 6(int) SpecConstant 1
10: TypeVector 6(int) 3
11: TypePointer Function 10(ivec3)
12: TypeFunction 2 11(ptr)
16(bn): TypeStruct 6(int)
17: TypePointer StorageBuffer 16(bn)
18(bi): 17(ptr) Variable StorageBuffer
19: TypeInt 32 1
20: 19(int) Constant 0
21: 6(int) Constant 0
22: TypePointer Function 6(int)
25: 6(int) SpecConstant 32
26: 6(int) SpecConstant 1
27: 10(ivec3) SpecConstantComposite 25 8 26
28: 6(int) Constant 1
31: 6(int) Constant 2
35: TypePointer StorageBuffer 6(int)
4(main): 2 Function None 3
5: Label
37(param): 11(ptr) Variable Function
Store 37(param) 27
38: 2 FunctionCall 14(foo(vu3;) 37(param)
Return
FunctionEnd
14(foo(vu3;): 2 Function None 12
13(wgs): 11(ptr) FunctionParameter
15: Label
23: 22(ptr) AccessChain 13(wgs) 21
24: 6(int) Load 23
29: 6(int) CompositeExtract 27 1
30: 6(int) IMul 24 29
32: 22(ptr) AccessChain 13(wgs) 31
33: 6(int) Load 32
34: 6(int) IMul 30 33
36: 35(ptr) AccessChain 18(bi) 20
Store 36 34
Return
FunctionEnd

View File

@@ -0,0 +1,14 @@
void foo(float f)
{
if (f < 1.0)
discard;
}
void PixelShaderFunction(float4 input) : COLOR0
{
foo(input.z);
if (input.x)
discard;
float f = input.x;
discard;
}

View File

@@ -0,0 +1,14 @@
#version 400
uniform sampler2D tex;
in vec2 coord;
void main (void)
{
vec4 v = texture(tex, coord);
if (v == vec4(0.1,0.2,0.3,0.4))
discard;
gl_FragColor = v;
}

View File

@@ -0,0 +1,10 @@
#version 310 es
precision highp float;
out vec4 outp;
void main()
{
if (gl_HelperInvocation)
++outp;
}

View File

@@ -0,0 +1,18 @@
#version 450
layout(local_size_x_id = 18, local_size_z_id = 19) in;
layout(local_size_x = 32, local_size_y = 32) in;
buffer bn {
uint a;
} bi;
void foo(uvec3 wgs)
{
bi.a = wgs.x * gl_WorkGroupSize.y * wgs.z;
}
void main()
{
foo(gl_WorkGroupSize);
}