diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index c07f3b670..9216817a2 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -2741,6 +2741,14 @@ Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector& op module.mapInstruction(op); constantsTypesGlobals.push_back(std::unique_ptr(op)); + // OpSpecConstantOp's using 8 or 16 bit types require the associated capability + if (containsType(typeId, OpTypeInt, 8)) + addCapability(CapabilityInt8); + if (containsType(typeId, OpTypeInt, 16)) + addCapability(CapabilityInt16); + if (containsType(typeId, OpTypeFloat, 16)) + addCapability(CapabilityFloat16); + return op->getResultId(); } diff --git a/Test/baseResults/spv.specConstantOp.float16.comp.out b/Test/baseResults/spv.specConstantOp.float16.comp.out new file mode 100644 index 000000000..97631f14e --- /dev/null +++ b/Test/baseResults/spv.specConstantOp.float16.comp.out @@ -0,0 +1,47 @@ +spv.specConstantOp.float16.comp +// Module Version 10000 +// Generated by (magic number): 8000b +// 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 8 "S" + MemberName 8(S) 0 "p_out" + Name 10 "" + Name 14 "c" + Decorate 7 ArrayStride 2 + MemberDecorate 8(S) 0 Restrict + MemberDecorate 8(S) 0 NonReadable + MemberDecorate 8(S) 0 Offset 0 + Decorate 8(S) BufferBlock + Decorate 10 DescriptorSet 0 + Decorate 10 Binding 0 + Decorate 14(c) SpecId 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 16 + 7: TypeRuntimeArray 6(float16_t) + 8(S): TypeStruct 7 + 9: TypePointer Uniform 8(S) + 10: 9(ptr) Variable Uniform + 11: TypeInt 32 1 + 12: 11(int) Constant 0 + 13: TypeFloat 32 + 14(c): 13(float) SpecConstant 1090519040 + 15:6(float16_t) SpecConstantOp 115 14(c) + 16: TypePointer Uniform 6(float16_t) + 4(main): 2 Function None 3 + 5: Label + 17: 16(ptr) AccessChain 10 12 12 + Store 17 15 + Return + FunctionEnd diff --git a/Test/baseResults/spv.specConstantOp.int16.comp.out b/Test/baseResults/spv.specConstantOp.int16.comp.out new file mode 100644 index 000000000..13049bed6 --- /dev/null +++ b/Test/baseResults/spv.specConstantOp.int16.comp.out @@ -0,0 +1,49 @@ +spv.specConstantOp.int16.comp +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 20 + + 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 8 "S" + MemberName 8(S) 0 "p_out" + Name 10 "" + Name 13 "c" + Decorate 7 ArrayStride 2 + MemberDecorate 8(S) 0 Restrict + MemberDecorate 8(S) 0 NonReadable + MemberDecorate 8(S) 0 Offset 0 + Decorate 8(S) BufferBlock + Decorate 10 DescriptorSet 0 + Decorate 10 Binding 0 + Decorate 13(c) SpecId 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 16 0 + 7: TypeRuntimeArray 6(int16_t) + 8(S): TypeStruct 7 + 9: TypePointer Uniform 8(S) + 10: 9(ptr) Variable Uniform + 11: TypeInt 32 1 + 12: 11(int) Constant 0 + 13(c): 11(int) SpecConstant 8 + 14: TypeInt 16 1 + 15: 14(int16_t) SpecConstantOp 114 13(c) + 16: 6(int16_t) Constant 0 + 17: 6(int16_t) SpecConstantOp 128 15 16 + 18: TypePointer Uniform 6(int16_t) + 4(main): 2 Function None 3 + 5: Label + 19: 18(ptr) AccessChain 10 12 12 + Store 19 17 + Return + FunctionEnd diff --git a/Test/baseResults/spv.specConstantOp.int8.comp.out b/Test/baseResults/spv.specConstantOp.int8.comp.out new file mode 100644 index 000000000..1cf53014b --- /dev/null +++ b/Test/baseResults/spv.specConstantOp.int8.comp.out @@ -0,0 +1,49 @@ +spv.specConstantOp.int8.comp +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 20 + + 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 8 "S" + MemberName 8(S) 0 "p_out" + Name 10 "" + Name 13 "c" + Decorate 7 ArrayStride 1 + MemberDecorate 8(S) 0 Restrict + MemberDecorate 8(S) 0 NonReadable + MemberDecorate 8(S) 0 Offset 0 + Decorate 8(S) BufferBlock + Decorate 10 DescriptorSet 0 + Decorate 10 Binding 0 + Decorate 13(c) SpecId 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 8 0 + 7: TypeRuntimeArray 6(int8_t) + 8(S): TypeStruct 7 + 9: TypePointer Uniform 8(S) + 10: 9(ptr) Variable Uniform + 11: TypeInt 32 1 + 12: 11(int) Constant 0 + 13(c): 11(int) SpecConstant 8 + 14: TypeInt 8 1 + 15: 14(int8_t) SpecConstantOp 114 13(c) + 16: 6(int8_t) Constant 0 + 17: 6(int8_t) SpecConstantOp 128 15 16 + 18: TypePointer Uniform 6(int8_t) + 4(main): 2 Function None 3 + 5: Label + 19: 18(ptr) AccessChain 10 12 12 + Store 19 17 + Return + FunctionEnd diff --git a/Test/spv.specConstantOp.float16.comp b/Test/spv.specConstantOp.float16.comp new file mode 100644 index 000000000..c3db60c23 --- /dev/null +++ b/Test/spv.specConstantOp.float16.comp @@ -0,0 +1,18 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require + +// Produce an OpSpecConstantOp with 8 bit integer type + +layout(constant_id = 0) const float c = 8; + +layout(binding=0) writeonly restrict buffer S { + float16_t p_out[]; +}; + +void main() +{ + p_out[0] = float16_t(c); +} + + + diff --git a/Test/spv.specConstantOp.int16.comp b/Test/spv.specConstantOp.int16.comp new file mode 100644 index 000000000..c5078436c --- /dev/null +++ b/Test/spv.specConstantOp.int16.comp @@ -0,0 +1,16 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require + +// Produce an OpSpecConstantOp with 16 bit integer type + +layout(constant_id = 0) const int c = 8; + +layout(binding=0) writeonly restrict buffer S { + uint16_t p_out[]; +}; + +void main() +{ + p_out[0] = uint16_t(c); +} + diff --git a/Test/spv.specConstantOp.int8.comp b/Test/spv.specConstantOp.int8.comp new file mode 100644 index 000000000..598821077 --- /dev/null +++ b/Test/spv.specConstantOp.int8.comp @@ -0,0 +1,17 @@ +#version 450 +#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require + +// Produce an OpSpecConstantOp with 8 bit integer type + +layout(constant_id = 0) const int c = 8; + +layout(binding=0) writeonly restrict buffer S { + uint8_t p_out[]; +}; + +void main() +{ + p_out[0] = uint8_t(c); +} + + diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 90fb2fc66..1fd67e6f4 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -514,6 +514,9 @@ INSTANTIATE_TEST_SUITE_P( "spv.specConstant.float16.comp", "spv.specConstant.int16.comp", "spv.specConstant.int8.comp", + "spv.specConstantOp.int16.comp", + "spv.specConstantOp.int8.comp", + "spv.specConstantOp.float16.comp", "spv.storageBuffer.vert", "spv.terminate.frag", "spv.subgroupUniformControlFlow.vert",