From bec8359bf7e22c7106b87f2356ef4a5571489861 Mon Sep 17 00:00:00 2001 From: Jeremy Hayes Date: Wed, 21 Dec 2022 14:20:44 -0700 Subject: [PATCH] Fix const parameter debug types Constant qualified parameter types were not being correctly added to the DebugTypeFunction instruction. Fix #3095. --- SPIRV/SpvBuilder.cpp | 21 +++-- .../spv.debuginfo.const_params.glsl.comp.out | 84 +++++++++++++++++++ Test/spv.debuginfo.const_params.glsl.comp | 14 ++++ gtests/Spv.FromFile.cpp | 3 +- 4 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 Test/baseResults/spv.debuginfo.const_params.glsl.comp.out create mode 100644 Test/spv.debuginfo.const_params.glsl.comp diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index bcbaf24ef..764a88602 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -650,8 +650,12 @@ Id Builder::makeDebugFunctionType(Id returnType, const std::vector& paramTyp type->addIdOperand(makeUintConstant(NonSemanticShaderDebugInfo100FlagIsPublic)); type->addIdOperand(debugId[returnType]); for (auto const paramType : paramTypes) { - assert(isPointerType(paramType) || isArrayType(paramType)); - type->addIdOperand(debugId[getContainedTypeId(paramType)]); + if (isPointerType(paramType) || isArrayType(paramType)) { + type->addIdOperand(debugId[getContainedTypeId(paramType)]); + } + else { + type->addIdOperand(debugId[paramType]); + } } constantsTypesGlobals.push_back(std::unique_ptr(type)); module.mapInstruction(type); @@ -2062,11 +2066,16 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const assert(paramTypes.size() == paramNames.size()); for(size_t p = 0; p < paramTypes.size(); ++p) { - auto const& paramType = paramTypes[p]; - assert(isPointerType(paramType) || isArrayType(paramType)); - assert(debugId[getContainedTypeId(paramType)] != 0); + auto getParamTypeId = [this](Id const& typeId) { + if (isPointerType(typeId) || isArrayType(typeId)) { + return getContainedTypeId(typeId); + } + else { + return typeId; + } + }; auto const& paramName = paramNames[p]; - auto const debugLocalVariableId = createDebugLocalVariable(debugId[getContainedTypeId(paramType)], paramName, p+1); + auto const debugLocalVariableId = createDebugLocalVariable(debugId[getParamTypeId(paramTypes[p])], paramName, p+1); debugId[firstParamId + p] = debugLocalVariableId; makeDebugDeclare(debugLocalVariableId, firstParamId + p); diff --git a/Test/baseResults/spv.debuginfo.const_params.glsl.comp.out b/Test/baseResults/spv.debuginfo.const_params.glsl.comp.out new file mode 100644 index 000000000..c0c5cd225 --- /dev/null +++ b/Test/baseResults/spv.debuginfo.const_params.glsl.comp.out @@ -0,0 +1,84 @@ +spv.debuginfo.const_params.glsl.comp +Validation failed +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 64 + + Capability Shader + Extension "SPV_KHR_non_semantic_info" + 1: ExtInstImport "NonSemantic.Shader.DebugInfo.100" + 2: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 13 "main" + ExecutionMode 13 LocalSize 1 1 1 + 8: String "uint" + 14: String "main" + 17: String "" + 24: String "float" + 39: String "function" + 45: String "f" + 49: String "f2" + 52: String "f3" + 55: String "f4" + Name 13 "main" + Name 38 "function(f1;vf2;vf3;vf4;" + Name 34 "f" + Name 35 "f2" + Name 36 "f3" + Name 37 "f4" + 3: TypeVoid + 4: TypeFunction 3 + 6: TypeInt 32 0 + 9: 6(int) Constant 32 + 10: 6(int) Constant 6 + 11: 6(int) Constant 0 + 7: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 2(RoundEven) 8 9 10 11 + 12: 6(int) Constant 3 + 5: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 8(Floor) 12 3 + 16: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 35(Modf) 0 17 + 19: 6(int) Constant 1 + 20: 6(int) Constant 4 + 21: 6(int) Constant 2 + 18: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 1(Round) 19 20 16 21 + 15: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 20(Cosh) 14 5 16 11 11 18 14 12 11 + 23: TypeFloat 32 + 25: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 2(RoundEven) 24 9 12 11 + 26: TypeVector 23(float) 2 + 27: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 6(FSign) 25 21 + 28: TypeVector 23(float) 3 + 29: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 6(FSign) 25 12 + 30: TypeVector 23(float) 4 + 31: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 6(FSign) 25 20 + 32: TypeFunction 3 23(float) 26(fvec2) 28(fvec3) 30(fvec4) + 33: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 8(Floor) 12 3 25 27 29 31 + 40: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 20(Cosh) 39 33 16 11 11 18 39 12 11 + 44: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 26(Pow) 45 25 16 11 11 40 20 19 + 47: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 31(Sqrt) + 48: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 26(Pow) 49 27 16 11 11 40 20 21 + 51: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 26(Pow) 52 29 16 11 11 40 20 12 + 54: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 26(Pow) 55 31 16 11 11 40 20 20 + 59: 23(float) Constant 0 + 60: 26(fvec2) ConstantComposite 59 59 + 61: 28(fvec3) ConstantComposite 59 59 59 + 62: 30(fvec4) ConstantComposite 59 59 59 59 + 13(main): 3 Function None 4 + 22: Label + 58: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 101 15 13(main) + 63: 3 FunctionCall 38(function(f1;vf2;vf3;vf4;) 59 60 61 62 + Return + FunctionEnd +38(function(f1;vf2;vf3;vf4;): 3 Function None 32 + 34(f): 23(float) FunctionParameter + 35(f2): 26(fvec2) FunctionParameter + 36(f3): 28(fvec3) FunctionParameter + 37(f4): 30(fvec4) FunctionParameter + 41: Label + 42: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 23(Acosh) 40 + 43: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 103 16 11 11 11 11 + 46: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 28(Log) 44 34(f) 47 + 50: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 28(Log) 48 35(f2) 47 + 53: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 28(Log) 51 36(f3) 47 + 56: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 28(Log) 54 37(f4) 47 + 57: 3 ExtInst 1(NonSemantic.Shader.DebugInfo.100) 101 40 38(function(f1;vf2;vf3;vf4;) + Return + FunctionEnd diff --git a/Test/spv.debuginfo.const_params.glsl.comp b/Test/spv.debuginfo.const_params.glsl.comp new file mode 100644 index 000000000..112628fe5 --- /dev/null +++ b/Test/spv.debuginfo.const_params.glsl.comp @@ -0,0 +1,14 @@ +#version 450 + +void function( + const float f, + const vec2 f2, + const vec3 f3, + const vec4 f4) +{ +} + +void main() +{ + function(0, vec2(0), vec3(0), vec4(0)); +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index cfe9af0e3..fafd33cfd 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -858,7 +858,8 @@ INSTANTIATE_TEST_SUITE_P( "spv.debuginfo.glsl.comp", "spv.debuginfo.glsl.geom", "spv.debuginfo.glsl.tesc", - "spv.debuginfo.glsl.tese" + "spv.debuginfo.glsl.tese", + "spv.debuginfo.const_params.glsl.comp" })), FileNameAsCustomTestSuffix );