Skip to content

Commit

Permalink
Implement the extension GL_EXT_spirv_intrinsics
Browse files Browse the repository at this point in the history
- Add support of SPIR-V execution mode qualifiers.
- Add support of SPIR-V storage class qualifier.
- Add support of SPIR-V decorate qualifiers.
- Add support of SPIR-V type specifier.
- Add support of SPIR-V intruction qualifiers.
- Add support of spirv_by_reference/spirv_literal parameter qualifier.
- Add shader stage macros introduced by this extension.
  • Loading branch information
amdrexu committed May 6, 2021
1 parent 41e39c6 commit ed4a2a9
Show file tree
Hide file tree
Showing 40 changed files with 6,629 additions and 3,354 deletions.
2 changes: 2 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ template("glslang_sources_common") {
"glslang/Include/PoolAlloc.h",
"glslang/Include/ResourceLimits.h",
"glslang/Include/ShHandle.h",
"glslang/Include/SpirvIntrinsics.h",
"glslang/Include/Types.h",
"glslang/Include/arrays.h",
"glslang/Include/intermediate.h",
Expand All @@ -151,6 +152,7 @@ template("glslang_sources_common") {
"glslang/MachineIndependent/Scan.h",
"glslang/MachineIndependent/ScanContext.h",
"glslang/MachineIndependent/ShaderLang.cpp",
"glslang/MachineIndependent/SpirvIntrinsics.cpp",
"glslang/MachineIndependent/SymbolTable.cpp",
"glslang/MachineIndependent/SymbolTable.h",
"glslang/MachineIndependent/Versions.cpp",
Expand Down
329 changes: 327 additions & 2 deletions SPIRV/GlslangToSpv.cpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Test/baseResults/cppBad.vert.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ WARNING: 0:1: '#define' : missing space after macro name
ERROR: 0:3: 'preprocessor evaluation' : bad expression
ERROR: 0:3: '#if' : unexpected tokens following directive
ERROR: 0:6: 'string' : End of line in string
ERROR: 0:6: 'string literal' : required extension not requested: GL_EXT_debug_printf
ERROR: 0:6: 'string literal' : required extension not requested: Possible extensions include:
GL_EXT_debug_printf
GL_EXT_spirv_intrinsics
ERROR: 0:6: '' : syntax error, unexpected INT, expecting COMMA or SEMICOLON
ERROR: 5 compilation errors. No code generated.

Expand Down
8 changes: 6 additions & 2 deletions Test/baseResults/cppSimple.vert.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ ERROR: 0:117: '#error' : bad5
ERROR: 0:120: '#if' : unexpected tokens following directive
ERROR: 0:121: '#error' : bad6
ERROR: 0:122: '#endif' : unexpected tokens following directive
ERROR: 0:135: 'string literal' : required extension not requested: GL_EXT_debug_printf
ERROR: 0:136: 'string literal' : required extension not requested: GL_EXT_debug_printf
ERROR: 0:135: 'string literal' : required extension not requested: Possible extensions include:
GL_EXT_debug_printf
GL_EXT_spirv_intrinsics
ERROR: 0:136: 'string literal' : required extension not requested: Possible extensions include:
GL_EXT_debug_printf
GL_EXT_spirv_intrinsics
ERROR: 0:136: 'length' : no matching overloaded function found
ERROR: 0:136: '=' : cannot convert from ' const float' to ' global int'
ERROR: 0:138: ''' : character literals not supported
Expand Down
56 changes: 56 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvByReference.vert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
spv.intrinsicsSpirvByReference.vert
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 30

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 15 17 26
Source GLSL 450
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 10 "func(f1;"
Name 9 "f"
Name 15 "vec2Out"
Name 17 "floatIn"
Name 26 "floatOut"
Name 27 "param"
Decorate 15(vec2Out) Location 0
Decorate 17(floatIn) Location 0
Decorate 26(floatOut) Location 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Function 6(float)
8: TypeFunction 2 7(ptr)
12: 6(float) Constant 1056964608
13: TypeVector 6(float) 2
14: TypePointer Output 13(fvec2)
15(vec2Out): 14(ptr) Variable Output
16: TypePointer Input 6(float)
17(floatIn): 16(ptr) Variable Input
19: TypeInt 32 0
20: 19(int) Constant 1
21: TypePointer Output 6(float)
24: 19(int) Constant 0
26(floatOut): 21(ptr) Variable Output
4(main): 2 Function None 3
5: Label
27(param): 7(ptr) Variable Function
18: 6(float) Load 17(floatIn)
22: 21(ptr) AccessChain 15(vec2Out) 20
23: 6(float) ExtInst 1(GLSL.std.450) 35(Modf) 18 22
25: 21(ptr) AccessChain 15(vec2Out) 24
Store 25 23
28: 6(float) Load 26(floatOut)
Store 27(param) 28
29: 2 FunctionCall 10(func(f1;) 27(param)
Return
FunctionEnd
10(func(f1;): 2 Function None 8
9(f): 7(ptr) FunctionParameter
11: Label
Store 9(f) 12
Return
FunctionEnd
88 changes: 88 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvDecorate.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
spv.intrinsicsSpirvDecorate.frag
Validation failed
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 43

Capability Shader
Extension "SPV_AMD_shader_explicit_vertex_parameter"
1: ExtInstImport "GLSL.std.450"
14: ExtInstImport "SPV_AMD_shader_explicit_vertex_parameter"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 10 18 20 22 25 28 31 34 39
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 8 "floatOut"
Name 10 "floatIn"
Name 18 "vec2Out"
Name 20 "gl_BaryCoordNoPerspAMD"
Name 22 "gl_BaryCoordNoPerspCentroidAMD"
Name 25 "gl_BaryCoordNoPerspSampleAMD"
Name 28 "gl_BaryCoordSmoothAMD"
Name 31 "gl_BaryCoordSmoothCentroidAMD"
Name 34 "gl_BaryCoordSmoothSampleAMD"
Name 39 "gl_BaryCoordPullModelAMD"
Decorate 8(floatOut) Location 0
Decorate 10(floatIn) Location 0
Decorate 10(floatIn) ExplicitInterpAMD
Decorate 18(vec2Out) Location 1
Decorate 20(gl_BaryCoordNoPerspAMD) Location 0
Decorate 20(gl_BaryCoordNoPerspAMD) BuiltIn BaryCoordNoPerspAMD
Decorate 22(gl_BaryCoordNoPerspCentroidAMD) Location 1
Decorate 22(gl_BaryCoordNoPerspCentroidAMD) BuiltIn BaryCoordNoPerspCentroidAMD
Decorate 25(gl_BaryCoordNoPerspSampleAMD) Location 2
Decorate 25(gl_BaryCoordNoPerspSampleAMD) BuiltIn BaryCoordNoPerspSampleAMD
Decorate 28(gl_BaryCoordSmoothAMD) Location 3
Decorate 28(gl_BaryCoordSmoothAMD) BuiltIn BaryCoordSmoothAMD
Decorate 31(gl_BaryCoordSmoothCentroidAMD) Location 4
Decorate 31(gl_BaryCoordSmoothCentroidAMD) BuiltIn BaryCoordSmoothCentroidAMD
Decorate 34(gl_BaryCoordSmoothSampleAMD) Location 5
Decorate 34(gl_BaryCoordSmoothSampleAMD) BuiltIn BaryCoordSmoothSampleAMD
Decorate 39(gl_BaryCoordPullModelAMD) Location 6
Decorate 39(gl_BaryCoordPullModelAMD) BuiltIn BaryCoordPullModelAMD
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Output 6(float)
8(floatOut): 7(ptr) Variable Output
9: TypePointer Input 6(float)
10(floatIn): 9(ptr) Variable Input
12: TypeInt 32 0
13: 12(int) Constant 1
16: TypeVector 6(float) 2
17: TypePointer Output 16(fvec2)
18(vec2Out): 17(ptr) Variable Output
19: TypePointer Input 16(fvec2)
20(gl_BaryCoordNoPerspAMD): 19(ptr) Variable Input
22(gl_BaryCoordNoPerspCentroidAMD): 19(ptr) Variable Input
25(gl_BaryCoordNoPerspSampleAMD): 19(ptr) Variable Input
28(gl_BaryCoordSmoothAMD): 19(ptr) Variable Input
31(gl_BaryCoordSmoothCentroidAMD): 19(ptr) Variable Input
34(gl_BaryCoordSmoothSampleAMD): 19(ptr) Variable Input
37: TypeVector 6(float) 3
38: TypePointer Input 37(fvec3)
39(gl_BaryCoordPullModelAMD): 38(ptr) Variable Input
4(main): 2 Function None 3
5: Label
11: 6(float) Load 10(floatIn)
15: 6(float) ExtInst 14(SPV_AMD_shader_explicit_vertex_parameter) 1(InterpolateAtVertexAMD) 11 13
Store 8(floatOut) 15
21: 16(fvec2) Load 20(gl_BaryCoordNoPerspAMD)
23: 16(fvec2) Load 22(gl_BaryCoordNoPerspCentroidAMD)
24: 16(fvec2) FAdd 21 23
26: 16(fvec2) Load 25(gl_BaryCoordNoPerspSampleAMD)
27: 16(fvec2) FAdd 24 26
29: 16(fvec2) Load 28(gl_BaryCoordSmoothAMD)
30: 16(fvec2) FAdd 27 29
32: 16(fvec2) Load 31(gl_BaryCoordSmoothCentroidAMD)
33: 16(fvec2) FAdd 30 32
35: 16(fvec2) Load 34(gl_BaryCoordSmoothSampleAMD)
36: 16(fvec2) FAdd 33 35
40: 37(fvec3) Load 39(gl_BaryCoordPullModelAMD)
41: 16(fvec2) VectorShuffle 40 40 0 1
42: 16(fvec2) FAdd 36 41
Store 18(vec2Out) 42
Return
FunctionEnd
36 changes: 36 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvExecutionMode.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
spv.intrinsicsSpirvExecutionMode.frag
Validation failed
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 12

Capability Shader
Capability StencilExportEXT
Extension "SPV_EXT_shader_stencil_export"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 8 10
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 StencilRefReplacingEXT
Source GLSL 450
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 8 "gl_FragStencilRef"
Name 10 "color"
Decorate 8(gl_FragStencilRef) Location 0
Decorate 8(gl_FragStencilRef) BuiltIn FragStencilRefEXT
Decorate 10(color) Flat
Decorate 10(color) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypePointer Output 6(int)
8(gl_FragStencilRef): 7(ptr) Variable Output
9: TypePointer Input 6(int)
10(color): 9(ptr) Variable Input
4(main): 2 Function None 3
5: Label
11: 6(int) Load 10(color)
Store 8(gl_FragStencilRef) 11
Return
FunctionEnd
59 changes: 59 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvInstruction.vert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
spv.intrinsicsSpirvInstruction.vert
Validation failed
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 30

Capability Shader
Capability Int64
Capability ShaderClockKHR
Extension "SPV_AMD_shader_trinary_minmax"
Extension "SPV_KHR_shader_clock"
1: ExtInstImport "GLSL.std.450"
28: ExtInstImport "SPV_AMD_shader_trinary_minmax"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 9 13 18 21
Source GLSL 450
SourceExtension "GL_ARB_gpu_shader_int64"
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 9 "uvec2Out"
Name 13 "i64Out"
Name 18 "vec2Out"
Name 21 "vec3In"
Decorate 9(uvec2Out) Location 0
Decorate 13(i64Out) Location 1
Decorate 18(vec2Out) Location 2
Decorate 21(vec3In) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 0
7: TypeVector 6(int) 2
8: TypePointer Output 7(ivec2)
9(uvec2Out): 8(ptr) Variable Output
11: TypeInt 64 1
12: TypePointer Output 11(int64_t)
13(i64Out): 12(ptr) Variable Output
15: TypeFloat 32
16: TypeVector 15(float) 2
17: TypePointer Output 16(fvec2)
18(vec2Out): 17(ptr) Variable Output
19: TypeVector 15(float) 3
20: TypePointer Input 19(fvec3)
21(vec3In): 20(ptr) Variable Input
4(main): 2 Function None 3
5: Label
10: 7(ivec2) ReadClockKHR
Store 9(uvec2Out) 10
14: 11(int64_t) ReadClockKHR
Store 13(i64Out) 14
22: 19(fvec3) Load 21(vec3In)
23: 16(fvec2) VectorShuffle 22 22 0 1
24: 19(fvec3) Load 21(vec3In)
25: 16(fvec2) VectorShuffle 24 24 1 2
26: 19(fvec3) Load 21(vec3In)
27: 16(fvec2) VectorShuffle 26 26 2 0
29: 16(fvec2) ExtInst 28(SPV_AMD_shader_trinary_minmax) 1(FMin3AMD) 23 25 27
Store 18(vec2Out) 29
Return
FunctionEnd
29 changes: 29 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
spv.intrinsicsSpirvLiteral.vert
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 12

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main"
Source GLSL 450
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 9 "vec4Out"
Name 10 "vec4In"
Decorate 9(vec4Out) Location 1
Decorate 10(vec4In) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
4(main): 2 Function None 3
5: Label
9(vec4Out): 8(ptr) Variable Function
10(vec4In): 8(ptr) Variable Function
11: 7(fvec4) Load 10(vec4In) None
Store 9(vec4Out) 11 Volatile
Return
FunctionEnd
30 changes: 30 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvStorageClass.rchit.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
spv.intrinsicsSpirvStorageClass.rchit
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 13

Capability RayTracingKHR
Capability RayTracingProvisionalKHR
Extension "SPV_KHR_ray_tracing"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint ClosestHitKHR 4 "main"
Source GLSL 460
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 9 "payload"
Decorate 9(payload) Location 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer RayPayloadKHR 7(fvec4)
9(payload): 8(ptr) Variable RayPayloadKHR
10: 6(float) Constant 0
11: 6(float) Constant 1065353216
12: 7(fvec4) ConstantComposite 10 11 10 11
4(main): 2 Function None 3
5: Label
Store 9(payload) 12
Return
FunctionEnd
45 changes: 45 additions & 0 deletions Test/baseResults/spv.intrinsicsSpirvType.rgen.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
spv.intrinsicsSpirvType.rgen
Validation failed
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 21

Capability RayQueryKHR
Capability RayTraversalPrimitiveCullingKHR
Capability RayTracingKHR
Extension "SPV_KHR_ray_query"
Extension "SPV_KHR_ray_tracing"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint RayGenerationKHR 4 "main"
Source GLSL 460
SourceExtension "GL_EXT_spirv_intrinsics"
Name 4 "main"
Name 8 "rq"
Name 11 "as"
Decorate 11(as) Location 0
Decorate 11(as) DescriptorSet 0
Decorate 11(as) Binding 0
2: TypeVoid
3: TypeFunction 2
7: TypePointer Function 6
10: TypePointer UniformConstant 9
11(as): 10(ptr) Variable UniformConstant
13: TypeInt 32 0
14: 13(int) Constant 0
15: TypeFloat 32
16: TypeVector 15(float) 3
17: 15(float) Constant 0
18: 16(fvec3) ConstantComposite 17 17 17
19: 15(float) Constant 1065353216
20: 16(fvec3) ConstantComposite 19 19 19
4(main): 2 Function None 3
5: Label
8(rq): 7(ptr) Variable Function
6: TypeRayQueryKHR
9: TypeAccelerationStructureKHR
12: 9 Load 11(as)
RayQueryInitializeKHR 8(rq) 12 14 14 18 17 20 19
RayQueryTerminateKHR 8(rq)
Return
FunctionEnd
Loading

0 comments on commit ed4a2a9

Please sign in to comment.