From 6c1db7fd6c6790fe9ba5a45c046d9dc6db69f206 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Wed, 24 Nov 2021 17:37:52 +0800 Subject: [PATCH] Fix validation failures of test cases regarding GL_EXT_spirv_intrinsics 1. The test cases of OpReadClockKHR is invalid. The return type is unsigned integer rather than signed integer. 2. When SPIR-V decorate or SPIR-V type is specified, we should avoid auto location mapping because the semantics are totally decided by SPIR-V tokens. --- .../spv.intrinsicsSpirvDecorate.frag.out | 8 --- .../spv.intrinsicsSpirvExecutionMode.frag.out | 2 - .../spv.intrinsicsSpirvInstruction.vert.out | 65 +++++++++++----------- Test/baseResults/spv.intrinsicsSpirvType.rgen.out | 2 - Test/spv.intrinsicsSpirvInstruction.vert | 12 ++-- glslang/Include/Types.h | 2 + glslang/MachineIndependent/iomapper.cpp | 13 +++-- 7 files changed, 48 insertions(+), 56 deletions(-) diff --git a/Test/baseResults/spv.intrinsicsSpirvDecorate.frag.out b/Test/baseResults/spv.intrinsicsSpirvDecorate.frag.out index cbd46b0..c41dcc9 100644 --- a/Test/baseResults/spv.intrinsicsSpirvDecorate.frag.out +++ b/Test/baseResults/spv.intrinsicsSpirvDecorate.frag.out @@ -1,5 +1,4 @@ spv.intrinsicsSpirvDecorate.frag -Validation failed // Module Version 10000 // Generated by (magic number): 8000a // Id's are bound by 43 @@ -28,19 +27,12 @@ Validation failed 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 diff --git a/Test/baseResults/spv.intrinsicsSpirvExecutionMode.frag.out b/Test/baseResults/spv.intrinsicsSpirvExecutionMode.frag.out index 22bc53b..cdea382 100644 --- a/Test/baseResults/spv.intrinsicsSpirvExecutionMode.frag.out +++ b/Test/baseResults/spv.intrinsicsSpirvExecutionMode.frag.out @@ -1,5 +1,4 @@ spv.intrinsicsSpirvExecutionMode.frag -Validation failed // Module Version 10000 // Generated by (magic number): 8000a // Id's are bound by 12 @@ -17,7 +16,6 @@ Validation failed 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 diff --git a/Test/baseResults/spv.intrinsicsSpirvInstruction.vert.out b/Test/baseResults/spv.intrinsicsSpirvInstruction.vert.out index 0e2780c..0e95e42 100644 --- a/Test/baseResults/spv.intrinsicsSpirvInstruction.vert.out +++ b/Test/baseResults/spv.intrinsicsSpirvInstruction.vert.out @@ -1,8 +1,7 @@ spv.intrinsicsSpirvInstruction.vert -Validation failed // Module Version 10000 // Generated by (magic number): 8000a -// Id's are bound by 30 +// Id's are bound by 32 Capability Shader Capability Int64 @@ -10,50 +9,52 @@ Validation failed Extension "SPV_AMD_shader_trinary_minmax" Extension "SPV_KHR_shader_clock" 1: ExtInstImport "GLSL.std.450" - 28: ExtInstImport "SPV_AMD_shader_trinary_minmax" + 30: ExtInstImport "SPV_AMD_shader_trinary_minmax" MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" 9 13 18 21 + EntryPoint Vertex 4 "main" 9 15 20 23 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" + Name 15 "u64Out" + Name 20 "vec2Out" + Name 23 "vec3In" Decorate 9(uvec2Out) Location 0 - Decorate 13(i64Out) Location 1 - Decorate 18(vec2Out) Location 2 - Decorate 21(vec3In) Location 0 + Decorate 15(u64Out) Location 1 + Decorate 20(vec2Out) Location 2 + Decorate 23(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 + 10: TypeInt 32 1 + 11: 10(int) Constant 1 + 13: TypeInt 64 0 + 14: TypePointer Output 13(int64_t) + 15(u64Out): 14(ptr) Variable Output + 17: TypeFloat 32 + 18: TypeVector 17(float) 2 + 19: TypePointer Output 18(fvec2) + 20(vec2Out): 19(ptr) Variable Output + 21: TypeVector 17(float) 3 + 22: TypePointer Input 21(fvec3) + 23(vec3In): 22(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 + 12: 7(ivec2) ReadClockKHR 11 + Store 9(uvec2Out) 12 + 16: 13(int64_t) ReadClockKHR 11 + Store 15(u64Out) 16 + 24: 21(fvec3) Load 23(vec3In) + 25: 18(fvec2) VectorShuffle 24 24 0 1 + 26: 21(fvec3) Load 23(vec3In) + 27: 18(fvec2) VectorShuffle 26 26 1 2 + 28: 21(fvec3) Load 23(vec3In) + 29: 18(fvec2) VectorShuffle 28 28 2 0 + 31: 18(fvec2) ExtInst 30(SPV_AMD_shader_trinary_minmax) 1(FMin3AMD) 25 27 29 + Store 20(vec2Out) 31 Return FunctionEnd diff --git a/Test/baseResults/spv.intrinsicsSpirvType.rgen.out b/Test/baseResults/spv.intrinsicsSpirvType.rgen.out index 021e7a6..f3937b4 100644 --- a/Test/baseResults/spv.intrinsicsSpirvType.rgen.out +++ b/Test/baseResults/spv.intrinsicsSpirvType.rgen.out @@ -1,5 +1,4 @@ spv.intrinsicsSpirvType.rgen -Validation failed // Module Version 10000 // Generated by (magic number): 8000a // Id's are bound by 21 @@ -17,7 +16,6 @@ Validation failed 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 diff --git a/Test/spv.intrinsicsSpirvInstruction.vert b/Test/spv.intrinsicsSpirvInstruction.vert index a4efb7d..2cc1842 100644 --- a/Test/spv.intrinsicsSpirvInstruction.vert +++ b/Test/spv.intrinsicsSpirvInstruction.vert @@ -4,10 +4,10 @@ #extension GL_ARB_gpu_shader_int64: enable spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056) -uvec2 clockRealtime2x32EXT(void); +uvec2 clockRealtime2x32EXT(int); spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056) -int64_t clockRealtimeEXT(void); +uint64_t clockRealtimeEXT(int); spirv_instruction (extensions = ["SPV_AMD_shader_trinary_minmax"], set = "SPV_AMD_shader_trinary_minmax", id = 1) vec2 min3(vec2 x, vec2 y, vec2 z); @@ -15,12 +15,12 @@ vec2 min3(vec2 x, vec2 y, vec2 z); layout(location = 0) in vec3 vec3In; layout(location = 0) out uvec2 uvec2Out; -layout(location = 1) out int64_t i64Out; +layout(location = 1) out uint64_t u64Out; layout(location = 2) out vec2 vec2Out; void main() { - uvec2Out = clockRealtime2x32EXT(); - i64Out = clockRealtimeEXT(); + uvec2Out = clockRealtime2x32EXT(1); + u64Out = clockRealtimeEXT(1); vec2Out = min3(vec3In.xy, vec3In.yz, vec3In.zx); -} +} \ No newline at end of file diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index e87f258..9c1f960 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -1865,10 +1865,12 @@ public: bool isAtomic() const { return false; } bool isCoopMat() const { return false; } bool isReference() const { return false; } + bool isSpirvType() const { return false; } #else bool isAtomic() const { return basicType == EbtAtomicUint; } bool isCoopMat() const { return coopmat; } bool isReference() const { return getBasicType() == EbtReference; } + bool isSpirvType() const { return getBasicType() == EbtSpirvType; } #endif // return true if this type contains any subtype which satisfies the given predicate. diff --git a/glslang/MachineIndependent/iomapper.cpp b/glslang/MachineIndependent/iomapper.cpp index 44cb0ae..a3c53f5 100644 --- a/glslang/MachineIndependent/iomapper.cpp +++ b/glslang/MachineIndependent/iomapper.cpp @@ -845,7 +845,7 @@ int TDefaultIoResolverBase::resolveUniformLocation(EShLanguage /*stage*/, TVarEn } // no locations added if already present, a built-in variable, a block, or an opaque if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getBasicType() == EbtBlock || - type.isAtomic() || (type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) { + type.isAtomic() || type.isSpirvType() || (type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) { return ent.newLocation = -1; } // no locations on blocks of built-in variables @@ -873,8 +873,8 @@ int TDefaultIoResolverBase::resolveInOutLocation(EShLanguage stage, TVarEntryInf return ent.newLocation = -1; } - // no locations added if already present, or a built-in variable - if (type.getQualifier().hasLocation() || type.isBuiltIn()) { + // no locations added if already present, a built-in variable, or a variable with SPIR-V decorate + if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getQualifier().hasSprivDecorate()) { return ent.newLocation = -1; } @@ -960,8 +960,8 @@ int TDefaultGlslIoResolver::resolveInOutLocation(EShLanguage stage, TVarEntryInf if (type.getQualifier().hasLocation()) { return ent.newLocation = type.getQualifier().layoutLocation; } - // no locations added if already present, or a built-in variable - if (type.isBuiltIn()) { + // no locations added if already present, a built-in variable, or a variable with SPIR-V decorate + if (type.isBuiltIn() || type.getQualifier().hasSprivDecorate()) { return ent.newLocation = -1; } // no locations on blocks of built-in variables @@ -1042,7 +1042,8 @@ int TDefaultGlslIoResolver::resolveUniformLocation(EShLanguage /*stage*/, TVarEn } else { // no locations added if already present, a built-in variable, a block, or an opaque if (type.getQualifier().hasLocation() || type.isBuiltIn() || type.getBasicType() == EbtBlock || - type.isAtomic() || (type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) { + type.isAtomic() || type.isSpirvType() || + (type.containsOpaque() && referenceIntermediate.getSpv().openGl == 0)) { return ent.newLocation = -1; } // no locations on blocks of built-in variables -- 2.7.4