From fe54126c05863564eab8325b2725f65d96c450b6 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Tue, 23 Nov 2021 16:40:45 +0800 Subject: [PATCH] Fix an issue of spirv_by_reference When using this qualifier for a parameter, we make it as a pointer. However, the function TranslateStorageClass() is therefore called and the storage class should only be set to Function when it is invoked to translate parameter types rather than actual argument types. --- SPIRV/GlslangToSpv.cpp | 6 ++++-- .../spv.intrinsicsSpirvLiteral.vert.out | 20 +++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 3a906189..e471b9ff 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1256,8 +1256,10 @@ spv::StorageClass TGlslangToSpvTraverser::TranslateStorageClass(const glslang::T if (type.getBasicType() == glslang::EbtRayQuery) return spv::StorageClassPrivate; #ifndef GLSLANG_WEB - if (type.getQualifier().isSpirvByReference()) - return spv::StorageClassFunction; + if (type.getQualifier().isSpirvByReference()) { + if (type.getQualifier().isParamInput() || type.getQualifier().isParamOutput()) + return spv::StorageClassFunction; + } #endif if (type.getQualifier().isPipeInput()) return spv::StorageClassInput; diff --git a/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out b/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out index 68ad949b..096cc611 100644 --- a/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out +++ b/Test/baseResults/spv.intrinsicsSpirvLiteral.vert.out @@ -1,30 +1,30 @@ spv.intrinsicsSpirvLiteral.vert -Validation failed // Module Version 10000 // Generated by (magic number): 8000a -// Id's are bound by 12 +// Id's are bound by 13 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Vertex 4 "main" + EntryPoint Vertex 4 "main" 9 11 Source GLSL 450 SourceExtension "GL_EXT_spirv_intrinsics" Name 4 "main" Name 9 "vec4Out" - Name 10 "vec4In" + Name 11 "vec4In" Decorate 9(vec4Out) Location 1 - Decorate 10(vec4In) Location 0 + Decorate 11(vec4In) Location 0 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 7: TypeVector 6(float) 4 - 8: TypePointer Function 7(fvec4) + 8: TypePointer Output 7(fvec4) + 9(vec4Out): 8(ptr) Variable Output + 10: TypePointer Input 7(fvec4) + 11(vec4In): 10(ptr) Variable Input 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 + 12: 7(fvec4) Load 11(vec4In) None + Store 9(vec4Out) 12 Volatile Return FunctionEnd