From a1f9c7104ee3cc0204834ab3f4a474d512ee01d3 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Mon, 27 Apr 2020 19:44:15 +0200 Subject: [PATCH] Add SPIR-V capabilities needed for spec constants Fixes #2198. --- SPIRV/GlslangToSpv.cpp | 12 +++++ .../spv.specConstant.float16.comp.out | 51 +++++++++++++++++++ .../spv.specConstant.int16.comp.out | 51 +++++++++++++++++++ .../spv.specConstant.int8.comp.out | 51 +++++++++++++++++++ Test/spv.specConstant.float16.comp | 18 +++++++ Test/spv.specConstant.int16.comp | 18 +++++++ Test/spv.specConstant.int8.comp | 18 +++++++ gtests/Spv.FromFile.cpp | 3 ++ 8 files changed, 222 insertions(+) create mode 100644 Test/baseResults/spv.specConstant.float16.comp.out create mode 100644 Test/baseResults/spv.specConstant.int16.comp.out create mode 100644 Test/baseResults/spv.specConstant.int8.comp.out create mode 100644 Test/spv.specConstant.float16.comp create mode 100644 Test/spv.specConstant.int16.comp create mode 100644 Test/spv.specConstant.int8.comp diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3bed67835f..cbbc388b23 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -8270,6 +8270,18 @@ spv::Id TGlslangToSpvTraverser::createSpvConstant(const glslang::TIntermTyped& n // We now know we have a specialization constant to build + // Extra capabilities may be needed. + if (node.getType().contains8BitInt()) + builder.addCapability(spv::CapabilityInt8); + if (node.getType().contains16BitFloat()) + builder.addCapability(spv::CapabilityFloat16); + if (node.getType().contains16BitInt()) + builder.addCapability(spv::CapabilityInt16); + if (node.getType().contains64BitInt()) + builder.addCapability(spv::CapabilityInt64); + if (node.getType().containsDouble()) + builder.addCapability(spv::CapabilityFloat64); + // gl_WorkGroupSize is a special case until the front-end handles hierarchical specialization constants, // even then, it's specialization ids are handled by special case syntax in GLSL: layout(local_size_x = ... if (node.getType().getQualifier().builtIn == glslang::EbvWorkGroupSize) { diff --git a/Test/baseResults/spv.specConstant.float16.comp.out b/Test/baseResults/spv.specConstant.float16.comp.out new file mode 100644 index 0000000000..a01d606a0c --- /dev/null +++ b/Test/baseResults/spv.specConstant.float16.comp.out @@ -0,0 +1,51 @@ +spv.specConstant.float16.comp +// Module Version 10000 +// Generated by (magic number): 80008 +// Id's are bound by 18 + + Capability Shader + Capability Float16 + Capability StorageUniformBufferBlock16 + Extension "SPV_KHR_16bit_storage" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source GLSL 450 + SourceExtension "GL_EXT_shader_explicit_arithmetic_types_float16" + Name 4 "main" + Name 7 "Output" + MemberName 7(Output) 0 "r0" + MemberName 7(Output) 1 "r1" + Name 9 "sb_out" + Name 12 "sc0" + Name 16 "sc1" + MemberDecorate 7(Output) 0 NonReadable + MemberDecorate 7(Output) 0 Offset 0 + MemberDecorate 7(Output) 1 NonReadable + MemberDecorate 7(Output) 1 Offset 2 + Decorate 7(Output) BufferBlock + Decorate 9(sb_out) DescriptorSet 0 + Decorate 9(sb_out) Binding 0 + Decorate 12(sc0) SpecId 1 + Decorate 16(sc1) SpecId 2 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 16 + 7(Output): TypeStruct 6(float16_t) 6(float16_t) + 8: TypePointer Uniform 7(Output) + 9(sb_out): 8(ptr) Variable Uniform + 10: TypeInt 32 1 + 11: 10(int) Constant 0 + 12(sc0):6(float16_t) SpecConstant 18624 + 13: TypePointer Uniform 6(float16_t) + 15: 10(int) Constant 1 + 16(sc1):6(float16_t) SpecConstant 52000 + 4(main): 2 Function None 3 + 5: Label + 14: 13(ptr) AccessChain 9(sb_out) 11 + Store 14 12(sc0) + 17: 13(ptr) AccessChain 9(sb_out) 15 + Store 17 16(sc1) + Return + FunctionEnd diff --git a/Test/baseResults/spv.specConstant.int16.comp.out b/Test/baseResults/spv.specConstant.int16.comp.out new file mode 100644 index 0000000000..fd206f77d5 --- /dev/null +++ b/Test/baseResults/spv.specConstant.int16.comp.out @@ -0,0 +1,51 @@ +spv.specConstant.int16.comp +// Module Version 10000 +// Generated by (magic number): 80008 +// Id's are bound by 18 + + Capability Shader + Capability Int16 + Capability StorageUniformBufferBlock16 + Extension "SPV_KHR_16bit_storage" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source GLSL 450 + SourceExtension "GL_EXT_shader_explicit_arithmetic_types_int16" + Name 4 "main" + Name 7 "Output" + MemberName 7(Output) 0 "r0" + MemberName 7(Output) 1 "r1" + Name 9 "sb_out" + Name 12 "sc0" + Name 16 "sc1" + MemberDecorate 7(Output) 0 NonReadable + MemberDecorate 7(Output) 0 Offset 0 + MemberDecorate 7(Output) 1 NonReadable + MemberDecorate 7(Output) 1 Offset 2 + Decorate 7(Output) BufferBlock + Decorate 9(sb_out) DescriptorSet 0 + Decorate 9(sb_out) Binding 0 + Decorate 12(sc0) SpecId 1 + Decorate 16(sc1) SpecId 2 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 16 1 + 7(Output): TypeStruct 6(int16_t) 6(int16_t) + 8: TypePointer Uniform 7(Output) + 9(sb_out): 8(ptr) Variable Uniform + 10: TypeInt 32 1 + 11: 10(int) Constant 0 + 12(sc0): 6(int16_t) SpecConstant 20000 + 13: TypePointer Uniform 6(int16_t) + 15: 10(int) Constant 1 + 16(sc1): 6(int16_t) SpecConstant 4294947296 + 4(main): 2 Function None 3 + 5: Label + 14: 13(ptr) AccessChain 9(sb_out) 11 + Store 14 12(sc0) + 17: 13(ptr) AccessChain 9(sb_out) 15 + Store 17 16(sc1) + Return + FunctionEnd diff --git a/Test/baseResults/spv.specConstant.int8.comp.out b/Test/baseResults/spv.specConstant.int8.comp.out new file mode 100644 index 0000000000..9c70b8524b --- /dev/null +++ b/Test/baseResults/spv.specConstant.int8.comp.out @@ -0,0 +1,51 @@ +spv.specConstant.int8.comp +// Module Version 10000 +// Generated by (magic number): 80008 +// Id's are bound by 18 + + Capability Shader + Capability Int8 + Capability UniformAndStorageBuffer8BitAccess + Extension "SPV_KHR_8bit_storage" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source GLSL 450 + SourceExtension "GL_EXT_shader_explicit_arithmetic_types_int8" + Name 4 "main" + Name 7 "Output" + MemberName 7(Output) 0 "r0" + MemberName 7(Output) 1 "r1" + Name 9 "sb_out" + Name 12 "sc0" + Name 16 "sc1" + MemberDecorate 7(Output) 0 NonReadable + MemberDecorate 7(Output) 0 Offset 0 + MemberDecorate 7(Output) 1 NonReadable + MemberDecorate 7(Output) 1 Offset 1 + Decorate 7(Output) BufferBlock + Decorate 9(sb_out) DescriptorSet 0 + Decorate 9(sb_out) Binding 0 + Decorate 12(sc0) SpecId 1 + Decorate 16(sc1) SpecId 2 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 8 1 + 7(Output): TypeStruct 6(int8_t) 6(int8_t) + 8: TypePointer Uniform 7(Output) + 9(sb_out): 8(ptr) Variable Uniform + 10: TypeInt 32 1 + 11: 10(int) Constant 0 + 12(sc0): 6(int8_t) SpecConstant 127 + 13: TypePointer Uniform 6(int8_t) + 15: 10(int) Constant 1 + 16(sc1): 6(int8_t) SpecConstant 4294967169 + 4(main): 2 Function None 3 + 5: Label + 14: 13(ptr) AccessChain 9(sb_out) 11 + Store 14 12(sc0) + 17: 13(ptr) AccessChain 9(sb_out) 15 + Store 17 16(sc1) + Return + FunctionEnd diff --git a/Test/spv.specConstant.float16.comp b/Test/spv.specConstant.float16.comp new file mode 100644 index 0000000000..d729cb973c --- /dev/null +++ b/Test/spv.specConstant.float16.comp @@ -0,0 +1,18 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require + +layout(constant_id = 1) const float16_t sc0 = 9.5hf; +layout(constant_id = 2) const float16_t sc1 = -14.25hf; + +layout (set = 0, binding = 0, std430) writeonly buffer Output { + float16_t r0; + float16_t r1; +} sb_out; + + +void main (void) +{ + sb_out.r0 = sc0; + sb_out.r1 = sc1; +} + diff --git a/Test/spv.specConstant.int16.comp b/Test/spv.specConstant.int16.comp new file mode 100644 index 0000000000..80f63008a6 --- /dev/null +++ b/Test/spv.specConstant.int16.comp @@ -0,0 +1,18 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require + +layout(constant_id = 1) const int16_t sc0 = 20000s; +layout(constant_id = 2) const int16_t sc1 = -20000s; + +layout (set = 0, binding = 0, std430) writeonly buffer Output { + int16_t r0; + int16_t r1; +} sb_out; + + +void main (void) +{ + sb_out.r0 = sc0; + sb_out.r1 = sc1; +} + diff --git a/Test/spv.specConstant.int8.comp b/Test/spv.specConstant.int8.comp new file mode 100644 index 0000000000..e2b6318999 --- /dev/null +++ b/Test/spv.specConstant.int8.comp @@ -0,0 +1,18 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require + +layout(constant_id = 1) const int8_t sc0 = int8_t(127); +layout(constant_id = 2) const int8_t sc1 = int8_t(-127); + +layout (set = 0, binding = 0, std430) writeonly buffer Output { + int8_t r0; + int8_t r1; +} sb_out; + + +void main (void) +{ + sb_out.r0 = sc0; + sb_out.r1 = sc1; +} + diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 1d061fb364..d7b69eb1dd 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -440,6 +440,9 @@ INSTANTIATE_TEST_CASE_P( "spv.specConstant.comp", "spv.specConstantComposite.vert", "spv.specConstantOperations.vert", + "spv.specConstant.float16.comp", + "spv.specConstant.int16.comp", + "spv.specConstant.int8.comp", "spv.storageBuffer.vert", "spv.precise.tese", "spv.precise.tesc",