From 79a35ace7c000171ee3822f542e85f69219584d5 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Thu, 24 Feb 2022 13:50:41 -0700 Subject: [PATCH] Don't do updatePrecision on float16_t operations float16_t does not take GLSL precisions and SPIR-V does not support RelaxedPrecision on float16_t. Fixes #2894 --- .../baseResults/spv.float16NoRelaxed.vert.out | 72 +++++++++++++++++++ Test/spv.float16NoRelaxed.vert | 16 +++++ glslang/MachineIndependent/Intermediate.cpp | 8 +-- gtests/Spv.FromFile.cpp | 1 + 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 Test/baseResults/spv.float16NoRelaxed.vert.out create mode 100644 Test/spv.float16NoRelaxed.vert diff --git a/Test/baseResults/spv.float16NoRelaxed.vert.out b/Test/baseResults/spv.float16NoRelaxed.vert.out new file mode 100644 index 000000000..8872b4637 --- /dev/null +++ b/Test/baseResults/spv.float16NoRelaxed.vert.out @@ -0,0 +1,72 @@ +spv.float16NoRelaxed.vert +// Module Version 10300 +// Generated by (magic number): 8000a +// Id's are bound by 35 + + Capability Shader + Capability Float16 + Capability GroupNonUniform + Capability GroupNonUniformVote + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Vertex 4 "main" 11 30 + Source GLSL 450 + SourceExtension "GL_EXT_shader_explicit_arithmetic_types_float16" + SourceExtension "GL_EXT_shader_subgroup_extended_types_float16" + SourceExtension "GL_KHR_shader_subgroup_basic" + SourceExtension "GL_KHR_shader_subgroup_vote" + Name 4 "main" + Name 8 "valueNoEqual" + Name 11 "gl_SubgroupInvocationID" + Name 15 "tempRes" + Name 26 "Buffer1" + MemberName 26(Buffer1) 0 "result" + Name 28 "" + Name 30 "gl_VertexIndex" + Decorate 11(gl_SubgroupInvocationID) RelaxedPrecision + Decorate 11(gl_SubgroupInvocationID) BuiltIn SubgroupLocalInvocationId + Decorate 12 RelaxedPrecision + Decorate 25 ArrayStride 4 + MemberDecorate 26(Buffer1) 0 Offset 0 + Decorate 26(Buffer1) Block + Decorate 28 DescriptorSet 0 + Decorate 28 Binding 0 + Decorate 30(gl_VertexIndex) BuiltIn VertexIndex + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 16 + 7: TypePointer Function 6(float16_t) + 9: TypeInt 32 0 + 10: TypePointer Input 9(int) +11(gl_SubgroupInvocationID): 10(ptr) Variable Input + 14: TypePointer Function 9(int) + 17: TypeBool + 18: 9(int) Constant 3 + 20: TypeInt 32 1 + 21: 20(int) Constant 0 + 22: 20(int) Constant 16 + 25: TypeRuntimeArray 9(int) + 26(Buffer1): TypeStruct 25 + 27: TypePointer StorageBuffer 26(Buffer1) + 28: 27(ptr) Variable StorageBuffer + 29: TypePointer Input 20(int) +30(gl_VertexIndex): 29(ptr) Variable Input + 33: TypePointer StorageBuffer 9(int) + 4(main): 2 Function None 3 + 5: Label + 8(valueNoEqual): 7(ptr) Variable Function + 15(tempRes): 14(ptr) Variable Function + 12: 9(int) Load 11(gl_SubgroupInvocationID) + 13:6(float16_t) ConvertUToF 12 + Store 8(valueNoEqual) 13 + 16:6(float16_t) Load 8(valueNoEqual) + 19: 17(bool) GroupNonUniformAllEqual 18 16 + 23: 20(int) Select 19 21 22 + 24: 9(int) Bitcast 23 + Store 15(tempRes) 24 + 31: 20(int) Load 30(gl_VertexIndex) + 32: 9(int) Load 15(tempRes) + 34: 33(ptr) AccessChain 28 21 31 + Store 34 32 + Return + FunctionEnd diff --git a/Test/spv.float16NoRelaxed.vert b/Test/spv.float16NoRelaxed.vert new file mode 100644 index 000000000..d594a1d4a --- /dev/null +++ b/Test/spv.float16NoRelaxed.vert @@ -0,0 +1,16 @@ +#version 450 +#extension GL_KHR_shader_subgroup_vote: enable +#extension GL_EXT_shader_subgroup_extended_types_float16 : enable +layout(set = 0, binding = 0, std430) buffer Buffer1 +{ + uint result[]; +}; + +void main (void) +{ + uint tempRes; + float16_t valueNoEqual = float16_t(gl_SubgroupInvocationID); + tempRes = subgroupAllEqual(valueNoEqual) ? 0x0 : 0x10; + result[gl_VertexIndex] = tempRes; +} + diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 6aea5b3d7..14fd053a7 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -2766,7 +2766,7 @@ void TIntermBranch::updatePrecision(TPrecisionQualifier parentPrecision) return; if (exp->getBasicType() == EbtInt || exp->getBasicType() == EbtUint || - exp->getBasicType() == EbtFloat || exp->getBasicType() == EbtFloat16) { + exp->getBasicType() == EbtFloat) { if (parentPrecision != EpqNone && exp->getQualifier().precision == EpqNone) { exp->propagatePrecision(parentPrecision); } @@ -3284,7 +3284,7 @@ bool TIntermediate::promoteUnary(TIntermUnary& node) void TIntermUnary::updatePrecision() { if (getBasicType() == EbtInt || getBasicType() == EbtUint || - getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + getBasicType() == EbtFloat) { if (operand->getQualifier().precision > getQualifier().precision) getQualifier().precision = operand->getQualifier().precision; } @@ -3785,7 +3785,7 @@ bool TIntermediate::promoteAggregate(TIntermAggregate& node) void TIntermAggregate::updatePrecision() { if (getBasicType() == EbtInt || getBasicType() == EbtUint || - getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + getBasicType() == EbtFloat) { TPrecisionQualifier maxPrecision = EpqNone; TIntermSequence operands = getSequence(); for (unsigned int i = 0; i < operands.size(); ++i) { @@ -3807,7 +3807,7 @@ void TIntermAggregate::updatePrecision() void TIntermBinary::updatePrecision() { if (getBasicType() == EbtInt || getBasicType() == EbtUint || - getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + getBasicType() == EbtFloat) { if (op == EOpRightShift || op == EOpLeftShift) { // For shifts get precision from left side only and thus no need to propagate getQualifier().precision = left->getQualifier().precision; diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index ba08226c0..db4ac2683 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -528,6 +528,7 @@ INSTANTIATE_TEST_SUITE_P( "spv.vulkan110.int16.frag", "spv.int32.frag", "spv.explicittypes.frag", + "spv.float16NoRelaxed.vert", "spv.float32.frag", "spv.float64.frag", "spv.memoryScopeSemantics.comp",