diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-05-16 10:05:16 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-03 10:25:46 +0200 |
commit | 940d62907027f388026ba2cac1ac64381af5c78f (patch) | |
tree | 59a1732d958c1a8183a34f6124be9b0ae55f2471 /thirdparty/glslang/SPIRV | |
parent | 3ac98435ce75dbf6e67525c0b3d1aeba2530ae4a (diff) | |
download | redot-engine-940d62907027f388026ba2cac1ac64381af5c78f.tar.gz |
vulkan: Update all components to Vulkan SDK 1.3.183.0
Pass `VMA_ALLOCATOR_CREATE_KHR_MAINTENANCE5_BIT` to VMA when using Vulkan 1.3
features.
Co-authored-by: Pedro J. Estébanez <pedrojrulez@gmail.com>
Diffstat (limited to 'thirdparty/glslang/SPIRV')
-rw-r--r-- | thirdparty/glslang/SPIRV/GLSL.ext.KHR.h | 5 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/GLSL.ext.NV.h | 3 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/GLSL.ext.QCOM.h | 2 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/GlslangToSpv.cpp | 343 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/SpvBuilder.cpp | 401 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/SpvBuilder.h | 116 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/SpvPostProcess.cpp | 1 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/disassemble.cpp | 9 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/doc.cpp | 70 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/spirv.hpp | 27 | ||||
-rw-r--r-- | thirdparty/glslang/SPIRV/spvIR.h | 41 |
11 files changed, 737 insertions, 281 deletions
diff --git a/thirdparty/glslang/SPIRV/GLSL.ext.KHR.h b/thirdparty/glslang/SPIRV/GLSL.ext.KHR.h index 121defa16a..1d3af1403a 100644 --- a/thirdparty/glslang/SPIRV/GLSL.ext.KHR.h +++ b/thirdparty/glslang/SPIRV/GLSL.ext.KHR.h @@ -1,5 +1,6 @@ /* ** Copyright (c) 2014-2020 The Khronos Group Inc. +** Copyright (C) 2022-2024 Arm Limited. ** Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. ** ** Permission is hereby granted, free of charge, to any person obtaining a copy @@ -53,8 +54,12 @@ static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_termi static const char* const E_SPV_KHR_workgroup_memory_explicit_layout = "SPV_KHR_workgroup_memory_explicit_layout"; static const char* const E_SPV_KHR_subgroup_uniform_control_flow = "SPV_KHR_subgroup_uniform_control_flow"; static const char* const E_SPV_KHR_fragment_shader_barycentric = "SPV_KHR_fragment_shader_barycentric"; +static const char* const E_SPV_KHR_quad_control = "SPV_KHR_quad_control"; static const char* const E_SPV_AMD_shader_early_and_late_fragment_tests = "SPV_AMD_shader_early_and_late_fragment_tests"; static const char* const E_SPV_KHR_ray_tracing_position_fetch = "SPV_KHR_ray_tracing_position_fetch"; static const char* const E_SPV_KHR_cooperative_matrix = "SPV_KHR_cooperative_matrix"; +static const char* const E_SPV_KHR_maximal_reconvergence = "SPV_KHR_maximal_reconvergence"; +static const char* const E_SPV_KHR_subgroup_rotate = "SPV_KHR_subgroup_rotate"; +static const char* const E_SPV_KHR_expect_assume = "SPV_KHR_expect_assume"; #endif // #ifndef GLSLextKHR_H diff --git a/thirdparty/glslang/SPIRV/GLSL.ext.NV.h b/thirdparty/glslang/SPIRV/GLSL.ext.NV.h index 9889bc9f9b..e4f11e4bfc 100644 --- a/thirdparty/glslang/SPIRV/GLSL.ext.NV.h +++ b/thirdparty/glslang/SPIRV/GLSL.ext.NV.h @@ -87,4 +87,7 @@ const char* const E_SPV_NV_shader_invocation_reorder = "SPV_NV_shader_invocation //SPV_NV_displacement_micromap const char* const E_SPV_NV_displacement_micromap = "SPV_NV_displacement_micromap"; +//SPV_NV_shader_atomic_fp16_vector +const char* const E_SPV_NV_shader_atomic_fp16_vector = "SPV_NV_shader_atomic_fp16_vector"; + #endif // #ifndef GLSLextNV_H diff --git a/thirdparty/glslang/SPIRV/GLSL.ext.QCOM.h b/thirdparty/glslang/SPIRV/GLSL.ext.QCOM.h index f13bb69359..b52990f023 100644 --- a/thirdparty/glslang/SPIRV/GLSL.ext.QCOM.h +++ b/thirdparty/glslang/SPIRV/GLSL.ext.QCOM.h @@ -37,5 +37,7 @@ static const int GLSLextQCOMRevision = 1; //SPV_QCOM_image_processing const char* const E_SPV_QCOM_image_processing = "SPV_QCOM_image_processing"; +//SPV_QCOM_image_processing2 +const char* const E_SPV_QCOM_image_processing2 = "SPV_QCOM_image_processing2"; #endif // #ifndef GLSLextQCOM_H diff --git a/thirdparty/glslang/SPIRV/GlslangToSpv.cpp b/thirdparty/glslang/SPIRV/GlslangToSpv.cpp index ec40f663a7..1674c55036 100644 --- a/thirdparty/glslang/SPIRV/GlslangToSpv.cpp +++ b/thirdparty/glslang/SPIRV/GlslangToSpv.cpp @@ -1,7 +1,7 @@ // // Copyright (C) 2014-2016 LunarG, Inc. // Copyright (C) 2015-2020 Google, Inc. -// Copyright (C) 2017 ARM Limited. +// Copyright (C) 2017, 2022-2024 Arm Limited. // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. // // All rights reserved. @@ -204,7 +204,8 @@ protected: spv::Id createBinaryMatrixOperation(spv::Op, OpDecorations&, spv::Id typeId, spv::Id left, spv::Id right); spv::Id createUnaryOperation(glslang::TOperator op, OpDecorations&, spv::Id typeId, spv::Id operand, glslang::TBasicType typeProxy, - const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags); + const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags, + const glslang::TType &opType); spv::Id createUnaryMatrixOperation(spv::Op op, OpDecorations&, spv::Id typeId, spv::Id operand, glslang::TBasicType typeProxy); spv::Id createConversion(glslang::TOperator op, OpDecorations&, spv::Id destTypeId, spv::Id operand, @@ -213,7 +214,8 @@ protected: spv::Id makeSmearedConstant(spv::Id constant, int vectorSize); spv::Id createAtomicOperation(glslang::TOperator op, spv::Decoration precision, spv::Id typeId, std::vector<spv::Id>& operands, glslang::TBasicType typeProxy, - const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags); + const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags, + const glslang::TType &opType); spv::Id createInvocationsOperation(glslang::TOperator op, spv::Id typeId, std::vector<spv::Id>& operands, glslang::TBasicType typeProxy); spv::Id CreateInvocationsVectorOperation(spv::Op op, spv::GroupOperation groupOperation, @@ -225,7 +227,9 @@ protected: spv::Id createNoArgOperation(glslang::TOperator op, spv::Decoration precision, spv::Id typeId); spv::Id getSymbolId(const glslang::TIntermSymbol* node); void addMeshNVDecoration(spv::Id id, int member, const glslang::TQualifier & qualifier); + bool hasQCOMImageProceessingDecoration(spv::Id id, spv::Decoration decor); void addImageProcessingQCOMDecoration(spv::Id id, spv::Decoration decor); + void addImageProcessing2QCOMDecoration(spv::Id id, bool isForGather); spv::Id createSpvConstant(const glslang::TIntermTyped&); spv::Id createSpvConstantFromConstUnionArray(const glslang::TType& type, const glslang::TConstUnionArray&, int& nextConst, bool specConstant); @@ -280,6 +284,7 @@ protected: spv::Id taskPayloadID; // Used later for generating OpTraceKHR/OpExecuteCallableKHR/OpHitObjectRecordHit*/OpHitObjectGetShaderBindingTableData std::unordered_map<unsigned int, glslang::TIntermSymbol *> locationToSymbol[4]; + std::unordered_map<spv::Id, std::vector<spv::Decoration> > idToQCOMDecorations; }; // @@ -395,11 +400,11 @@ void TranslateMemoryDecoration(const glslang::TQualifier& qualifier, std::vector bool useVulkanMemoryModel) { if (!useVulkanMemoryModel) { - if (qualifier.isCoherent()) - memory.push_back(spv::DecorationCoherent); if (qualifier.isVolatile()) { memory.push_back(spv::DecorationVolatile); memory.push_back(spv::DecorationCoherent); + } else if (qualifier.isCoherent()) { + memory.push_back(spv::DecorationCoherent); } } if (qualifier.isRestrict()) @@ -1163,6 +1168,7 @@ spv::ImageFormat TGlslangToSpvTraverser::TranslateImageFormat(const glslang::TTy case glslang::ElfR64i: builder.addExtension(spv::E_SPV_EXT_shader_image_int64); builder.addCapability(spv::CapabilityInt64ImageEXT); + break; default: break; } @@ -1558,8 +1564,13 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, this->options.generateDebugInfo = true; if (this->options.generateDebugInfo) { - builder.setEmitOpLines(); - builder.setSourceFile(glslangIntermediate->getSourceFile()); + if (this->options.emitNonSemanticShaderDebugInfo) { + builder.setEmitNonSemanticShaderDebugInfo(this->options.emitNonSemanticShaderDebugSource); + } + else { + builder.setEmitSpirvDebugInfo(); + } + builder.setDebugSourceFile(glslangIntermediate->getSourceFile()); // Set the source shader's text. If for SPV version 1.0, include // a preamble in comments stating the OpModuleProcessed instructions. @@ -1584,9 +1595,6 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, builder.addInclude(iItr->first, iItr->second); } - builder.setEmitNonSemanticShaderDebugInfo(this->options.emitNonSemanticShaderDebugInfo); - builder.setEmitNonSemanticShaderDebugSource(this->options.emitNonSemanticShaderDebugSource); - stdBuiltins = builder.import("GLSL.std.450"); spv::AddressingModel addressingModel = spv::AddressingModelLogical; @@ -1635,6 +1643,24 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, builder.addExtension(spv::E_SPV_KHR_subgroup_uniform_control_flow); builder.addExecutionMode(shaderEntry, spv::ExecutionModeSubgroupUniformControlFlowKHR); } + if (glslangIntermediate->getMaximallyReconverges()) { + builder.addExtension(spv::E_SPV_KHR_maximal_reconvergence); + builder.addExecutionMode(shaderEntry, spv::ExecutionModeMaximallyReconvergesKHR); + } + + if (glslangIntermediate->getQuadDerivMode()) + { + builder.addCapability(spv::CapabilityQuadControlKHR); + builder.addExtension(spv::E_SPV_KHR_quad_control); + builder.addExecutionMode(shaderEntry, spv::ExecutionModeQuadDerivativesKHR); + } + + if (glslangIntermediate->getReqFullQuadsMode()) + { + builder.addCapability(spv::CapabilityQuadControlKHR); + builder.addExtension(spv::E_SPV_KHR_quad_control); + builder.addExecutionMode(shaderEntry, spv::ExecutionModeRequireFullQuadsKHR); + } unsigned int mode; switch (glslangIntermediate->getStage()) { @@ -1983,8 +2009,9 @@ void TGlslangToSpvTraverser::finishSpv(bool compileOnly) } // finish off the entry-point SPV instruction by adding the Input/Output <id> - for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it) - entryPoint->addIdOperand(*it); + entryPoint->reserveOperands(iOSet.size()); + for (auto id : iOSet) + entryPoint->addIdOperand(id); } // Add capabilities, extensions, remove unneeded decorations, etc., @@ -2019,7 +2046,9 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol) { // We update the line information even though no code might be generated here // This is helpful to yield correct lines for control flow instructions - builder.setLine(symbol->getLoc().line, symbol->getLoc().getFilename()); + if (!linkageOnly) { + builder.setDebugSourceLocation(symbol->getLoc().line, symbol->getLoc().getFilename()); + } SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder); if (symbol->getType().isStruct()) @@ -2128,7 +2157,7 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol) bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node) { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); if (node->getLeft()->getAsSymbolNode() != nullptr && node->getLeft()->getType().isStruct()) { glslangTypeToIdMap[node->getLeft()->getType().getStruct()] = node->getLeft()->getAsSymbolNode()->getId(); } @@ -2173,7 +2202,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T spv::Id rValue = accessChainLoad(node->getRight()->getType()); // reset line number for assignment - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); if (node->getOp() != glslang::EOpAssign) { // the left is also an r-value @@ -2506,7 +2535,7 @@ spv::Id TGlslangToSpvTraverser::translateForcedType(spv::Id object) bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node) { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder); if (node->getType().getQualifier().isSpecConstant()) @@ -2670,7 +2699,7 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI // if not, then possibly an operation if (! result) result = createUnaryOperation(node->getOp(), decorations, resultType(), operand, - node->getOperand()->getBasicType(), lvalueCoherentFlags); + node->getOperand()->getBasicType(), lvalueCoherentFlags, node->getType()); // it could be attached to a SPIR-V intruction if (!result) { @@ -2763,6 +2792,11 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI return false; + case glslang::EOpAssumeEXT: + builder.addCapability(spv::CapabilityExpectAssumeKHR); + builder.addExtension(spv::E_SPV_KHR_expect_assume); + builder.createNoResultOp(spv::OpAssumeTrueKHR, operand); + return false; case glslang::EOpEmitStreamVertex: builder.createNoResultOp(spv::OpEmitStreamVertex, operand); return false; @@ -2894,11 +2928,11 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt return false; } else { if (node->getOp() == glslang::EOpScope) - builder.enterScope(0); + builder.enterLexicalBlock(0); } } else { if (sequenceDepth > 1 && node->getOp() == glslang::EOpScope) - builder.leaveScope(); + builder.leaveLexicalBlock(); --sequenceDepth; } @@ -2925,6 +2959,9 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt } case glslang::EOpFunction: if (visit == glslang::EvPreVisit) { + if (options.generateDebugInfo) { + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); + } if (isShaderEntryPoint(node)) { inEntryPoint = true; builder.setBuildPoint(shaderEntry->getLastBlock()); @@ -2933,10 +2970,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt } else { handleFunctionEntry(node); } - if (options.generateDebugInfo) { + if (options.generateDebugInfo && !options.emitNonSemanticShaderDebugInfo) { const auto& loc = node->getLoc(); const char* sourceFileName = loc.getFilename(); - spv::Id sourceFileId = sourceFileName ? builder.getStringId(sourceFileName) : builder.getSourceFile(); + spv::Id sourceFileId = sourceFileName ? builder.getStringId(sourceFileName) : builder.getMainFileId(); currentFunction->setDebugLineInfo(sourceFileId, loc.line, loc.column); } } else { @@ -2954,7 +2991,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt return false; case glslang::EOpFunctionCall: { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); if (node->isUserDefined()) result = handleUserFunctionCall(node); if (result) { @@ -3020,7 +3057,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt case glslang::EOpConstructF16Mat4x3: case glslang::EOpConstructF16Mat4x4: isMatrix = true; - // fall through + [[fallthrough]]; case glslang::EOpConstructFloat: case glslang::EOpConstructVec2: case glslang::EOpConstructVec3: @@ -3075,7 +3112,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt case glslang::EOpConstructCooperativeMatrixNV: case glslang::EOpConstructCooperativeMatrixKHR: { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); std::vector<spv::Id> arguments; translateArguments(*node, arguments, lvalueCoherentFlags); spv::Id constructed; @@ -3191,7 +3228,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt case glslang::EOpAtomicStore: noReturnValue = true; - // fallthrough + [[fallthrough]]; case glslang::EOpAtomicLoad: atomic = true; break; @@ -3221,6 +3258,12 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt binOp = node->getOp(); break; + case glslang::EOpExpectEXT: + builder.addCapability(spv::CapabilityExpectAssumeKHR); + builder.addExtension(spv::E_SPV_KHR_expect_assume); + binOp = node->getOp(); + break; + case glslang::EOpIgnoreIntersectionNV: case glslang::EOpTerminateRayNV: case glslang::EOpTraceNV: @@ -3288,7 +3331,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt case glslang::EOpHitObjectRecordHitWithIndexMotionNV: case glslang::EOpReorderThreadNV: noReturnValue = true; - //Fallthrough + [[fallthrough]]; case glslang::EOpHitObjectIsEmptyNV: case glslang::EOpHitObjectIsMissNV: case glslang::EOpHitObjectIsHitNV: @@ -3331,6 +3374,22 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt builder.addExtension(spv::E_SPV_QCOM_image_processing); break; + case glslang::EOpImageBlockMatchWindowSSDQCOM: + case glslang::EOpImageBlockMatchWindowSADQCOM: + builder.addCapability(spv::CapabilityTextureBlockMatchQCOM); + builder.addExtension(spv::E_SPV_QCOM_image_processing); + builder.addCapability(spv::CapabilityTextureBlockMatch2QCOM); + builder.addExtension(spv::E_SPV_QCOM_image_processing2); + break; + + case glslang::EOpImageBlockMatchGatherSSDQCOM: + case glslang::EOpImageBlockMatchGatherSADQCOM: + builder.addCapability(spv::CapabilityTextureBlockMatchQCOM); + builder.addExtension(spv::E_SPV_QCOM_image_processing); + builder.addCapability(spv::CapabilityTextureBlockMatch2QCOM); + builder.addExtension(spv::E_SPV_QCOM_image_processing2); + break; + case glslang::EOpFetchMicroTriangleVertexPositionNV: case glslang::EOpFetchMicroTriangleVertexBarycentricNV: builder.addExtension(spv::E_SPV_NV_displacement_micromap); @@ -3361,7 +3420,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt right->traverse(this); spv::Id rightId = accessChainLoad(right->getType()); - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); OpDecorations decorations = { precision, TranslateNoContractionDecoration(node->getType().getQualifier()), TranslateNonUniformDecoration(node->getType().getQualifier()) }; @@ -3596,7 +3655,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt lvalueCoherentFlags = builder.getAccessChain().coherentFlags; lvalueCoherentFlags |= TranslateCoherent(glslangOperands[arg]->getAsTyped()->getType()); } else { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); glslang::TOperator glslangOp = node->getOp(); if (arg == 1 && (glslangOp == glslang::EOpRayQueryGetIntersectionType || @@ -3648,7 +3707,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt } } - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); if (node->getOp() == glslang::EOpCooperativeMatrixLoad || node->getOp() == glslang::EOpCooperativeMatrixLoadNV) { std::vector<spv::IdImmediate> idImmOps; @@ -3739,7 +3798,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt glslang::TBasicType typeProxy = (node->getOp() == glslang::EOpAtomicStore) ? node->getSequence()[0]->getAsTyped()->getBasicType() : node->getBasicType(); result = createAtomicOperation(node->getOp(), precision, resultType(), operands, typeProxy, - lvalueCoherentFlags); + lvalueCoherentFlags, node->getType()); } else if (node->getOp() == glslang::EOpSpirvInst) { const auto& spirvInst = node->getSpirvInstruction(); if (spirvInst.set == "") { @@ -3786,7 +3845,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt result = createUnaryOperation( node->getOp(), decorations, resultType(), operands.front(), - glslangOperands[0]->getAsTyped()->getBasicType(), lvalueCoherentFlags); + glslangOperands[0]->getAsTyped()->getBasicType(), lvalueCoherentFlags, node->getType()); } break; default: @@ -3888,7 +3947,7 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang node->getFalseBlock()->traverse(this); spv::Id falseValue = accessChainLoad(node->getFalseBlock()->getAsTyped()->getType()); - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); // done if void if (node->getBasicType() == glslang::EbtVoid) @@ -4096,7 +4155,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn // instructions in it, since the body/test may have arbitrary instructions, // including merges of its own. builder.setBuildPoint(&blocks.head); - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); builder.createLoopMerge(&blocks.merge, &blocks.continue_target, control, operands); if (node->testFirst() && node->getTest()) { spv::Block& test = builder.makeNewBlock(); @@ -4119,7 +4178,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn node->getTerminal()->traverse(this); builder.createBranch(&blocks.head); } else { - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); builder.createBranch(&blocks.body); breakForLoop.push(true); @@ -4154,7 +4213,7 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T if (node->getExpression()) node->getExpression()->traverse(this); - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); switch (node->getFlowOp()) { case glslang::EOpKill: @@ -5322,17 +5381,34 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& structType int memberAlignment = glslangIntermediate->getMemberAlignment(memberType, memberSize, dummyStride, explicitLayout, matrixLayout == glslang::ElmRowMajor); + bool isVectorLike = memberType.isVector(); + if (memberType.isMatrix()) { + if (matrixLayout == glslang::ElmRowMajor) + isVectorLike = memberType.getMatrixRows() == 1; + else + isVectorLike = memberType.getMatrixCols() == 1; + } + // Adjust alignment for HLSL rules // TODO: make this consistent in early phases of code: // adjusting this late means inconsistencies with earlier code, which for reflection is an issue // Until reflection is brought in sync with these adjustments, don't apply to $Global, // which is the most likely to rely on reflection, and least likely to rely implicit layouts if (glslangIntermediate->usingHlslOffsets() && - ! memberType.isArray() && memberType.isVector() && structType.getTypeName().compare("$Global") != 0) { - int dummySize; - int componentAlignment = glslangIntermediate->getBaseAlignmentScalar(memberType, dummySize); - if (componentAlignment <= 4) + ! memberType.isStruct() && structType.getTypeName().compare("$Global") != 0) { + int componentSize; + int componentAlignment = glslangIntermediate->getBaseAlignmentScalar(memberType, componentSize); + if (! memberType.isArray() && isVectorLike && componentAlignment <= 4) memberAlignment = componentAlignment; + + // Don't add unnecessary padding after this member + if (memberType.isMatrix()) { + if (matrixLayout == glslang::ElmRowMajor) + memberSize -= componentSize * (4 - memberType.getMatrixCols()); + else + memberSize -= componentSize * (4 - memberType.getMatrixRows()); + } else if (memberType.isArray()) + memberSize -= componentSize * (4 - memberType.getVectorSize()); } // Bump up to member alignment @@ -5340,7 +5416,7 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& structType // Bump up to vec4 if there is a bad straddle if (explicitLayout != glslang::ElpScalar && glslangIntermediate->improperStraddle(memberType, memberSize, - currentOffset)) + currentOffset, isVectorLike)) glslang::RoundToPow2(currentOffset, 16); nextOffset = currentOffset + memberSize; @@ -5425,8 +5501,10 @@ void TGlslangToSpvTraverser::makeFunctions(const glslang::TIntermSequence& glslF // memory and use RestrictPointer/AliasedPointer. if (originalParam(type.getQualifier().storage, type, false) || !writableParam(type.getQualifier().storage)) { - decorations.push_back(type.getQualifier().isRestrict() ? spv::DecorationRestrict : - spv::DecorationAliased); + // TranslateMemoryDecoration added Restrict decoration already. + if (!type.getQualifier().isRestrict()) { + decorations.push_back(spv::DecorationAliased); + } } else { decorations.push_back(type.getQualifier().isRestrict() ? spv::DecorationRestrictPointerEXT : spv::DecorationAliasedPointerEXT); @@ -5738,7 +5816,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO if (! node->isImage() && ! node->isTexture()) return spv::NoResult; - builder.setLine(node->getLoc().line, node->getLoc().getFilename()); + builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename()); // Process a GLSL texturing op (will be SPV image) @@ -6041,7 +6119,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO operands.push_back(*opIt); return createAtomicOperation(node->getOp(), precision, resultType(), operands, typeProxy, - lvalueCoherentFlags); + lvalueCoherentFlags, node->getType()); } } @@ -6566,6 +6644,10 @@ spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, OpD binOp = isUnsigned ? spv::OpUMul32x16INTEL : spv::OpIMul32x16INTEL; break; + case glslang::EOpExpectEXT: + binOp = spv::OpExpectKHR; + break; + case glslang::EOpLessThan: case glslang::EOpGreaterThan: case glslang::EOpLessThanEqual: @@ -6788,7 +6870,8 @@ spv::Id TGlslangToSpvTraverser::createBinaryMatrixOperation(spv::Op op, OpDecora } spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, OpDecorations& decorations, spv::Id typeId, - spv::Id operand, glslang::TBasicType typeProxy, const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags) + spv::Id operand, glslang::TBasicType typeProxy, const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags, + const glslang::TType &opType) { spv::Op unaryOp = spv::OpNop; int extBuiltins = -1; @@ -7076,7 +7159,7 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, OpDe // Handle all of the atomics in one place, in createAtomicOperation() std::vector<spv::Id> operands; operands.push_back(operand); - return createAtomicOperation(op, decorations.precision, typeId, operands, typeProxy, lvalueCoherentFlags); + return createAtomicOperation(op, decorations.precision, typeId, operands, typeProxy, lvalueCoherentFlags, opType); } case glslang::EOpBitFieldReverse: @@ -7169,7 +7252,9 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, OpDe case glslang::EOpSubgroupExclusiveXor: case glslang::EOpSubgroupQuadSwapHorizontal: case glslang::EOpSubgroupQuadSwapVertical: - case glslang::EOpSubgroupQuadSwapDiagonal: { + case glslang::EOpSubgroupQuadSwapDiagonal: + case glslang::EOpSubgroupQuadAll: + case glslang::EOpSubgroupQuadAny: { std::vector<spv::Id> operands; operands.push_back(operand); return createSubgroupOperation(op, typeId, operands, typeProxy); @@ -7792,7 +7877,7 @@ spv::Id TGlslangToSpvTraverser::makeSmearedConstant(spv::Id constant, int vector // For glslang ops that map to SPV atomic opCodes spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv::Decoration /*precision*/, spv::Id typeId, std::vector<spv::Id>& operands, glslang::TBasicType typeProxy, - const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags) + const spv::Builder::AccessChain::CoherentFlags &lvalueCoherentFlags, const glslang::TType &opType) { spv::Op opCode = spv::OpNop; @@ -7803,14 +7888,20 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv opCode = spv::OpAtomicIAdd; if (typeProxy == glslang::EbtFloat16 || typeProxy == glslang::EbtFloat || typeProxy == glslang::EbtDouble) { opCode = spv::OpAtomicFAddEXT; - builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_add); - if (typeProxy == glslang::EbtFloat16) { - builder.addExtension(spv::E_SPV_EXT_shader_atomic_float16_add); - builder.addCapability(spv::CapabilityAtomicFloat16AddEXT); - } else if (typeProxy == glslang::EbtFloat) { - builder.addCapability(spv::CapabilityAtomicFloat32AddEXT); + if (typeProxy == glslang::EbtFloat16 && + (opType.getVectorSize() == 2 || opType.getVectorSize() == 4)) { + builder.addExtension(spv::E_SPV_NV_shader_atomic_fp16_vector); + builder.addCapability(spv::CapabilityAtomicFloat16VectorNV); } else { - builder.addCapability(spv::CapabilityAtomicFloat64AddEXT); + builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_add); + if (typeProxy == glslang::EbtFloat16) { + builder.addExtension(spv::E_SPV_EXT_shader_atomic_float16_add); + builder.addCapability(spv::CapabilityAtomicFloat16AddEXT); + } else if (typeProxy == glslang::EbtFloat) { + builder.addCapability(spv::CapabilityAtomicFloat32AddEXT); + } else { + builder.addCapability(spv::CapabilityAtomicFloat64AddEXT); + } } } break; @@ -7823,13 +7914,19 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv case glslang::EOpAtomicCounterMin: if (typeProxy == glslang::EbtFloat16 || typeProxy == glslang::EbtFloat || typeProxy == glslang::EbtDouble) { opCode = spv::OpAtomicFMinEXT; - builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_min_max); - if (typeProxy == glslang::EbtFloat16) - builder.addCapability(spv::CapabilityAtomicFloat16MinMaxEXT); - else if (typeProxy == glslang::EbtFloat) - builder.addCapability(spv::CapabilityAtomicFloat32MinMaxEXT); - else - builder.addCapability(spv::CapabilityAtomicFloat64MinMaxEXT); + if (typeProxy == glslang::EbtFloat16 && + (opType.getVectorSize() == 2 || opType.getVectorSize() == 4)) { + builder.addExtension(spv::E_SPV_NV_shader_atomic_fp16_vector); + builder.addCapability(spv::CapabilityAtomicFloat16VectorNV); + } else { + builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_min_max); + if (typeProxy == glslang::EbtFloat16) + builder.addCapability(spv::CapabilityAtomicFloat16MinMaxEXT); + else if (typeProxy == glslang::EbtFloat) + builder.addCapability(spv::CapabilityAtomicFloat32MinMaxEXT); + else + builder.addCapability(spv::CapabilityAtomicFloat64MinMaxEXT); + } } else if (typeProxy == glslang::EbtUint || typeProxy == glslang::EbtUint64) { opCode = spv::OpAtomicUMin; } else { @@ -7841,13 +7938,19 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv case glslang::EOpAtomicCounterMax: if (typeProxy == glslang::EbtFloat16 || typeProxy == glslang::EbtFloat || typeProxy == glslang::EbtDouble) { opCode = spv::OpAtomicFMaxEXT; - builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_min_max); - if (typeProxy == glslang::EbtFloat16) - builder.addCapability(spv::CapabilityAtomicFloat16MinMaxEXT); - else if (typeProxy == glslang::EbtFloat) - builder.addCapability(spv::CapabilityAtomicFloat32MinMaxEXT); - else - builder.addCapability(spv::CapabilityAtomicFloat64MinMaxEXT); + if (typeProxy == glslang::EbtFloat16 && + (opType.getVectorSize() == 2 || opType.getVectorSize() == 4)) { + builder.addExtension(spv::E_SPV_NV_shader_atomic_fp16_vector); + builder.addCapability(spv::CapabilityAtomicFloat16VectorNV); + } else { + builder.addExtension(spv::E_SPV_EXT_shader_atomic_float_min_max); + if (typeProxy == glslang::EbtFloat16) + builder.addCapability(spv::CapabilityAtomicFloat16MinMaxEXT); + else if (typeProxy == glslang::EbtFloat) + builder.addCapability(spv::CapabilityAtomicFloat32MinMaxEXT); + else + builder.addCapability(spv::CapabilityAtomicFloat64MinMaxEXT); + } } else if (typeProxy == glslang::EbtUint || typeProxy == glslang::EbtUint64) { opCode = spv::OpAtomicUMax; } else { @@ -7872,6 +7975,12 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv case glslang::EOpAtomicExchange: case glslang::EOpImageAtomicExchange: case glslang::EOpAtomicCounterExchange: + if ((typeProxy == glslang::EbtFloat16) && + (opType.getVectorSize() == 2 || opType.getVectorSize() == 4)) { + builder.addExtension(spv::E_SPV_NV_shader_atomic_fp16_vector); + builder.addCapability(spv::CapabilityAtomicFloat16VectorNV); + } + opCode = spv::OpAtomicExchange; break; case glslang::EOpAtomicCompSwap: @@ -7970,6 +8079,7 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv } std::vector<spv::Id> spvAtomicOperands; // hold the spv operands + spvAtomicOperands.reserve(6); spvAtomicOperands.push_back(pointerId); spvAtomicOperands.push_back(scopeId); spvAtomicOperands.push_back(semanticsId); @@ -8274,6 +8384,11 @@ spv::Id TGlslangToSpvTraverser::createSubgroupOperation(glslang::TOperator op, s case glslang::EOpSubgroupElect: builder.addCapability(spv::CapabilityGroupNonUniform); break; + case glslang::EOpSubgroupQuadAll: + case glslang::EOpSubgroupQuadAny: + builder.addExtension(spv::E_SPV_KHR_quad_control); + builder.addCapability(spv::CapabilityQuadControlKHR); + [[fallthrough]]; case glslang::EOpSubgroupAll: case glslang::EOpSubgroupAny: case glslang::EOpSubgroupAllEqual: @@ -8293,6 +8408,11 @@ spv::Id TGlslangToSpvTraverser::createSubgroupOperation(glslang::TOperator op, s builder.addCapability(spv::CapabilityGroupNonUniform); builder.addCapability(spv::CapabilityGroupNonUniformBallot); break; + case glslang::EOpSubgroupRotate: + case glslang::EOpSubgroupClusteredRotate: + builder.addExtension(spv::E_SPV_KHR_subgroup_rotate); + builder.addCapability(spv::CapabilityGroupNonUniformRotateKHR); + break; case glslang::EOpSubgroupShuffle: case glslang::EOpSubgroupShuffleXor: builder.addCapability(spv::CapabilityGroupNonUniform); @@ -8381,7 +8501,9 @@ spv::Id TGlslangToSpvTraverser::createSubgroupOperation(glslang::TOperator op, s // Figure out which opcode to use. switch (op) { case glslang::EOpSubgroupElect: opCode = spv::OpGroupNonUniformElect; break; + case glslang::EOpSubgroupQuadAll: opCode = spv::OpGroupNonUniformQuadAllKHR; break; case glslang::EOpSubgroupAll: opCode = spv::OpGroupNonUniformAll; break; + case glslang::EOpSubgroupQuadAny: opCode = spv::OpGroupNonUniformQuadAnyKHR; break; case glslang::EOpSubgroupAny: opCode = spv::OpGroupNonUniformAny; break; case glslang::EOpSubgroupAllEqual: opCode = spv::OpGroupNonUniformAllEqual; break; case glslang::EOpSubgroupBroadcast: opCode = spv::OpGroupNonUniformBroadcast; break; @@ -8398,6 +8520,8 @@ spv::Id TGlslangToSpvTraverser::createSubgroupOperation(glslang::TOperator op, s case glslang::EOpSubgroupShuffleXor: opCode = spv::OpGroupNonUniformShuffleXor; break; case glslang::EOpSubgroupShuffleUp: opCode = spv::OpGroupNonUniformShuffleUp; break; case glslang::EOpSubgroupShuffleDown: opCode = spv::OpGroupNonUniformShuffleDown; break; + case glslang::EOpSubgroupRotate: + case glslang::EOpSubgroupClusteredRotate: opCode = spv::OpGroupNonUniformRotateKHR; break; case glslang::EOpSubgroupAdd: case glslang::EOpSubgroupInclusiveAdd: case glslang::EOpSubgroupExclusiveAdd: @@ -8578,7 +8702,10 @@ spv::Id TGlslangToSpvTraverser::createSubgroupOperation(glslang::TOperator op, s // Every operation begins with the Execution Scope operand. spv::IdImmediate executionScope = { true, builder.makeUintConstant(spv::ScopeSubgroup) }; - spvGroupOperands.push_back(executionScope); + // All other ops need the execution scope. Quad Control Ops don't need scope, it's always Quad. + if (opCode != spv::OpGroupNonUniformQuadAllKHR && opCode != spv::OpGroupNonUniformQuadAnyKHR) { + spvGroupOperands.push_back(executionScope); + } // Next, for all operations that use a Group Operation, push that as an operand. if (groupOperation != spv::GroupOperationMax) { @@ -8821,6 +8948,8 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv:: case glslang::EOpSubgroupShuffleXor: case glslang::EOpSubgroupShuffleUp: case glslang::EOpSubgroupShuffleDown: + case glslang::EOpSubgroupRotate: + case glslang::EOpSubgroupClusteredRotate: case glslang::EOpSubgroupClusteredAdd: case glslang::EOpSubgroupClusteredMul: case glslang::EOpSubgroupClusteredMin: @@ -9179,6 +9308,30 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv:: opCode = spv::OpFetchMicroTriangleVertexPositionNV; break; + case glslang::EOpImageBlockMatchWindowSSDQCOM: + typeId = builder.makeVectorType(builder.makeFloatType(32), 4); + opCode = spv::OpImageBlockMatchWindowSSDQCOM; + addImageProcessing2QCOMDecoration(operands[0], false); + addImageProcessing2QCOMDecoration(operands[2], false); + break; + case glslang::EOpImageBlockMatchWindowSADQCOM: + typeId = builder.makeVectorType(builder.makeFloatType(32), 4); + opCode = spv::OpImageBlockMatchWindowSADQCOM; + addImageProcessing2QCOMDecoration(operands[0], false); + addImageProcessing2QCOMDecoration(operands[2], false); + break; + case glslang::EOpImageBlockMatchGatherSSDQCOM: + typeId = builder.makeVectorType(builder.makeFloatType(32), 4); + opCode = spv::OpImageBlockMatchGatherSSDQCOM; + addImageProcessing2QCOMDecoration(operands[0], true); + addImageProcessing2QCOMDecoration(operands[2], true); + break; + case glslang::EOpImageBlockMatchGatherSADQCOM: + typeId = builder.makeVectorType(builder.makeFloatType(32), 4); + opCode = spv::OpImageBlockMatchGatherSADQCOM; + addImageProcessing2QCOMDecoration(operands[0], true); + addImageProcessing2QCOMDecoration(operands[2], true); + break; default: return 0; } @@ -9685,6 +9838,16 @@ void TGlslangToSpvTraverser::addMeshNVDecoration(spv::Id id, int member, const g } } +bool TGlslangToSpvTraverser::hasQCOMImageProceessingDecoration(spv::Id id, spv::Decoration decor) +{ + std::vector<spv::Decoration> &decoVec = idToQCOMDecorations[id]; + for ( auto d : decoVec ) { + if ( d == decor ) + return true; + } + return false; +} + void TGlslangToSpvTraverser::addImageProcessingQCOMDecoration(spv::Id id, spv::Decoration decor) { spv::Op opc = builder.getOpCode(id); @@ -9695,7 +9858,43 @@ void TGlslangToSpvTraverser::addImageProcessingQCOMDecoration(spv::Id id, spv::D if (opc == spv::OpLoad) { spv::Id texid = builder.getIdOperand(id, 0); - builder.addDecoration(texid, decor); + if (!hasQCOMImageProceessingDecoration(texid, decor)) {// + builder.addDecoration(texid, decor); + idToQCOMDecorations[texid].push_back(decor); + } + } +} + +void TGlslangToSpvTraverser::addImageProcessing2QCOMDecoration(spv::Id id, bool isForGather) +{ + if (isForGather) { + return addImageProcessingQCOMDecoration(id, spv::DecorationBlockMatchTextureQCOM); + } + + auto addDecor = + [this](spv::Id id, spv::Decoration decor) { + spv::Id tsopc = this->builder.getOpCode(id); + if (tsopc == spv::OpLoad) { + spv::Id tsid = this->builder.getIdOperand(id, 0); + if (this->glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_4) { + assert(iOSet.count(tsid) > 0); + } + if (!hasQCOMImageProceessingDecoration(tsid, decor)) { + this->builder.addDecoration(tsid, decor); + idToQCOMDecorations[tsid].push_back(decor); + } + } + }; + + spv::Id opc = builder.getOpCode(id); + bool isInterfaceObject = (opc != spv::OpSampledImage); + + if (!isInterfaceObject) { + addDecor(builder.getIdOperand(id, 0), spv::DecorationBlockMatchTextureQCOM); + addDecor(builder.getIdOperand(id, 1), spv::DecorationBlockMatchSamplerQCOM); + } else { + addDecor(id, spv::DecorationBlockMatchTextureQCOM); + addDecor(id, spv::DecorationBlockMatchSamplerQCOM); } } @@ -10025,6 +10224,7 @@ spv::Id TGlslangToSpvTraverser::createShortCircuit(glslang::TOperator op, glslan // Operands to accumulate OpPhi operands std::vector<spv::Id> phiOperands; + phiOperands.reserve(4); // accumulate left operand's phi information phiOperands.push_back(leftId); phiOperands.push_back(builder.getBuildPoint()->getId()); @@ -10064,7 +10264,6 @@ spv::Id TGlslangToSpvTraverser::getExtBuiltins(const char* name) if (extBuiltinMap.find(name) != extBuiltinMap.end()) return extBuiltinMap[name]; else { - builder.addExtension(name); spv::Id extBuiltins = builder.import(name); extBuiltinMap[name] = extBuiltins; return extBuiltins; diff --git a/thirdparty/glslang/SPIRV/SpvBuilder.cpp b/thirdparty/glslang/SPIRV/SpvBuilder.cpp index 9216817a2a..6613655a8e 100644 --- a/thirdparty/glslang/SPIRV/SpvBuilder.cpp +++ b/thirdparty/glslang/SPIRV/SpvBuilder.cpp @@ -58,13 +58,6 @@ Builder::Builder(unsigned int spvVersion, unsigned int magicNumber, SpvBuildLogg spvVersion(spvVersion), sourceLang(SourceLanguageUnknown), sourceVersion(0), - sourceFileStringId(NoResult), - currentLine(0), - currentFile(nullptr), - currentFileId(NoResult), - lastDebugScopeId(NoResult), - emitOpLines(false), - emitNonSemanticShaderDebugInfo(false), addressModel(AddressingModelLogical), memoryModel(MemoryModelGLSL450), builderNumber(magicNumber), @@ -91,78 +84,6 @@ Id Builder::import(const char* name) return import->getResultId(); } -// Emit instruction for non-filename-based #line directives (ie. no filename -// seen yet): emit an OpLine if we've been asked to emit OpLines and the line -// number has changed since the last time, and is a valid line number. -void Builder::setLine(int lineNum) -{ - if (lineNum != 0 && lineNum != currentLine) { - currentLine = lineNum; - if (emitOpLines) { - if (emitNonSemanticShaderDebugInfo) - addDebugScopeAndLine(currentFileId, currentLine, 0); - else - addLine(sourceFileStringId, currentLine, 0); - } - } -} - -// If no filename, do non-filename-based #line emit. Else do filename-based emit. -// Emit OpLine if we've been asked to emit OpLines and the line number or filename -// has changed since the last time, and line number is valid. -void Builder::setLine(int lineNum, const char* filename) -{ - if (filename == nullptr) { - setLine(lineNum); - return; - } - if ((lineNum != 0 && lineNum != currentLine) || currentFile == nullptr || - strncmp(filename, currentFile, strlen(currentFile) + 1) != 0) { - currentLine = lineNum; - currentFile = filename; - if (emitOpLines) { - spv::Id strId = getStringId(filename); - if (emitNonSemanticShaderDebugInfo) - addDebugScopeAndLine(strId, currentLine, 0); - else - addLine(strId, currentLine, 0); - } - } -} - -void Builder::addLine(Id fileName, int lineNum, int column) -{ - Instruction* line = new Instruction(OpLine); - line->addIdOperand(fileName); - line->addImmediateOperand(lineNum); - line->addImmediateOperand(column); - buildPoint->addInstruction(std::unique_ptr<Instruction>(line)); -} - -void Builder::addDebugScopeAndLine(Id fileName, int lineNum, int column) -{ - assert(!currentDebugScopeId.empty()); - if (currentDebugScopeId.top() != lastDebugScopeId) { - spv::Id resultId = getUniqueId(); - Instruction* scopeInst = new Instruction(resultId, makeVoidType(), OpExtInst); - scopeInst->addIdOperand(nonSemanticShaderDebugInfo); - scopeInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugScope); - scopeInst->addIdOperand(currentDebugScopeId.top()); - buildPoint->addInstruction(std::unique_ptr<Instruction>(scopeInst)); - lastDebugScopeId = currentDebugScopeId.top(); - } - spv::Id resultId = getUniqueId(); - Instruction* lineInst = new Instruction(resultId, makeVoidType(), OpExtInst); - lineInst->addIdOperand(nonSemanticShaderDebugInfo); - lineInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugLine); - lineInst->addIdOperand(makeDebugSource(fileName)); - lineInst->addIdOperand(makeUintConstant(lineNum)); - lineInst->addIdOperand(makeUintConstant(lineNum)); - lineInst->addIdOperand(makeUintConstant(column)); - lineInst->addIdOperand(makeUintConstant(column)); - buildPoint->addInstruction(std::unique_ptr<Instruction>(lineInst)); -} - // For creating new groupedTypes (will return old type if the requested one was already made). Id Builder::makeVoidType() { @@ -236,12 +157,18 @@ Id Builder::makePointer(StorageClass storageClass, Id pointee) // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypePointer); + type->reserveOperands(2); type->addImmediateOperand(storageClass); type->addIdOperand(pointee); groupedTypes[OpTypePointer].push_back(type); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); module.mapInstruction(type); + if (emitNonSemanticShaderDebugInfo) { + const Id debugResultId = makePointerDebugType(storageClass, pointee); + debugId[type->getResultId()] = debugResultId; + } + return type->getResultId(); } @@ -270,6 +197,7 @@ Id Builder::makePointerFromForwardPointer(StorageClass storageClass, Id forwardP } type = new Instruction(forwardPointerType, NoType, OpTypePointer); + type->reserveOperands(2); type->addImmediateOperand(storageClass); type->addIdOperand(pointee); groupedTypes[OpTypePointer].push_back(type); @@ -292,6 +220,7 @@ Id Builder::makeIntegerType(int width, bool hasSign) // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeInt); + type->reserveOperands(2); type->addImmediateOperand(width); type->addImmediateOperand(hasSign ? 1 : 0); groupedTypes[OpTypeInt].push_back(type); @@ -422,6 +351,7 @@ Id Builder::makeVectorType(Id component, int size) // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeVector); + type->reserveOperands(2); type->addIdOperand(component); type->addImmediateOperand(size); groupedTypes[OpTypeVector].push_back(type); @@ -454,6 +384,7 @@ Id Builder::makeMatrixType(Id component, int cols, int rows) // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeMatrix); + type->reserveOperands(2); type->addIdOperand(column); type->addImmediateOperand(cols); groupedTypes[OpTypeMatrix].push_back(type); @@ -485,6 +416,7 @@ Id Builder::makeCooperativeMatrixTypeKHR(Id component, Id scope, Id rows, Id col // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeCooperativeMatrixKHR); + type->reserveOperands(5); type->addIdOperand(component); type->addIdOperand(scope); type->addIdOperand(rows); @@ -510,6 +442,7 @@ Id Builder::makeCooperativeMatrixTypeNV(Id component, Id scope, Id rows, Id cols // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeCooperativeMatrixNV); + type->reserveOperands(4); type->addIdOperand(component); type->addIdOperand(scope); type->addIdOperand(rows); @@ -551,6 +484,7 @@ Id Builder::makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& opera // not found, make it type = new Instruction(getUniqueId(), NoType, opcode); + type->reserveOperands(operands.size()); for (size_t op = 0; op < operands.size(); ++op) { if (operands[op].isId) type->addIdOperand(operands[op].word); @@ -583,6 +517,7 @@ Id Builder::makeArrayType(Id element, Id sizeId, int stride) // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeArray); + type->reserveOperands(2); type->addIdOperand(element); type->addIdOperand(sizeId); groupedTypes[OpTypeArray].push_back(type); @@ -649,6 +584,7 @@ Id Builder::makeFunctionType(Id returnType, const std::vector<Id>& paramTypes) // not found, make it Id typeId = getUniqueId(); type = new Instruction(typeId, NoType, OpTypeFunction); + type->reserveOperands(paramTypes.size() + 1); type->addIdOperand(returnType); for (int p = 0; p < (int)paramTypes.size(); ++p) type->addIdOperand(paramTypes[p]); @@ -671,6 +607,7 @@ Id Builder::makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTyp Id typeId = getUniqueId(); auto type = new Instruction(typeId, makeVoidType(), OpExtInst); + type->reserveOperands(paramTypes.size() + 4); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeFunction); type->addIdOperand(makeUintConstant(NonSemanticShaderDebugInfo100FlagIsPublic)); @@ -709,6 +646,7 @@ Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, boo // not found, make it type = new Instruction(getUniqueId(), NoType, OpTypeImage); + type->reserveOperands(7); type->addIdOperand(sampledType); type->addImmediateOperand( dim); type->addImmediateOperand( depth ? 1 : 0); @@ -819,6 +757,7 @@ Id Builder::makeDebugInfoNone() return debugInfoNone; Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(2); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugInfoNone); @@ -843,6 +782,7 @@ Id Builder::makeBoolDebugType(int const size) } type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(6); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeBasic); @@ -880,6 +820,7 @@ Id Builder::makeIntegerDebugType(int const width, bool const hasSign) // not found, make it type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(6); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeBasic); type->addIdOperand(nameId); // name id @@ -919,6 +860,7 @@ Id Builder::makeFloatDebugType(int const width) // not found, make it type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(6); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeBasic); type->addIdOperand(nameId); // name id @@ -949,6 +891,7 @@ Id Builder::makeSequentialDebugType(Id const baseType, Id const componentCount, // not found, make it type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(4); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(sequenceType); type->addIdOperand(debugId[baseType]); // base type @@ -984,6 +927,7 @@ Id Builder::makeMatrixDebugType(Id const vectorType, int const vectorCount, bool // not found, make it type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(5); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeMatrix); type->addIdOperand(debugId[vectorType]); // vector type id @@ -1002,11 +946,12 @@ Id Builder::makeMemberDebugType(Id const memberType, DebugTypeLoc const& debugTy assert(debugId[memberType] != 0); Instruction* type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(10); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeMember); type->addIdOperand(getStringId(debugTypeLoc.name)); // name id type->addIdOperand(debugId[memberType]); // type id - type->addIdOperand(makeDebugSource(sourceFileStringId)); // source id TODO: verify this works across include directives + type->addIdOperand(makeDebugSource(currentFileId)); // source id type->addIdOperand(makeUintConstant(debugTypeLoc.line)); // line id TODO: currentLine is always zero type->addIdOperand(makeUintConstant(debugTypeLoc.column)); // TODO: column id type->addIdOperand(makeUintConstant(0)); // TODO: offset id @@ -1041,11 +986,12 @@ Id Builder::makeCompositeDebugType(std::vector<Id> const& memberTypes, char cons // Create The structure debug type. Instruction* type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(memberDebugTypes.size() + 11); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypeComposite); type->addIdOperand(getStringId(name)); // name id type->addIdOperand(makeUintConstant(tag)); // tag id - type->addIdOperand(makeDebugSource(sourceFileStringId)); // source id TODO: verify this works across include directives + type->addIdOperand(makeDebugSource(currentFileId)); // source id type->addIdOperand(makeUintConstant(currentLine)); // line id TODO: currentLine always zero? type->addIdOperand(makeUintConstant(0)); // TODO: column id type->addIdOperand(makeDebugCompilationUnit()); // scope id @@ -1070,24 +1016,59 @@ Id Builder::makeCompositeDebugType(std::vector<Id> const& memberTypes, char cons return type->getResultId(); } +Id Builder::makePointerDebugType(StorageClass storageClass, Id const baseType) +{ + const Id debugBaseType = debugId[baseType]; + if (!debugBaseType) { + return makeDebugInfoNone(); + } + const Id scID = makeUintConstant(storageClass); + for (Instruction* otherType : groupedDebugTypes[NonSemanticShaderDebugInfo100DebugTypePointer]) { + if (otherType->getIdOperand(2) == debugBaseType && + otherType->getIdOperand(3) == scID) { + return otherType->getResultId(); + } + } + + Instruction* type = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + type->reserveOperands(5); + type->addIdOperand(nonSemanticShaderDebugInfo); + type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypePointer); + type->addIdOperand(debugBaseType); + type->addIdOperand(scID); + type->addIdOperand(makeUintConstant(0)); + + groupedDebugTypes[NonSemanticShaderDebugInfo100DebugTypePointer].push_back(type); + constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); + module.mapInstruction(type); + + return type->getResultId(); +} + Id Builder::makeDebugSource(const Id fileName) { if (debugSourceId.find(fileName) != debugSourceId.end()) return debugSourceId[fileName]; spv::Id resultId = getUniqueId(); Instruction* sourceInst = new Instruction(resultId, makeVoidType(), OpExtInst); + sourceInst->reserveOperands(3); sourceInst->addIdOperand(nonSemanticShaderDebugInfo); sourceInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugSource); sourceInst->addIdOperand(fileName); if (emitNonSemanticShaderDebugSource) { spv::Id sourceId = 0; - if (fileName == sourceFileStringId) { + if (fileName == mainFileId) { sourceId = getStringId(sourceText); } else { auto incItr = includeFiles.find(fileName); - assert(incItr != includeFiles.end()); - sourceId = getStringId(*incItr->second); + if (incItr != includeFiles.end()) { + sourceId = getStringId(*incItr->second); + } + } + + // We omit the optional source text item if not available in glslang + if (sourceId != 0) { + sourceInst->addIdOperand(sourceId); } - sourceInst->addIdOperand(sourceId); } constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst)); module.mapInstruction(sourceInst); @@ -1100,11 +1081,12 @@ Id Builder::makeDebugCompilationUnit() { return nonSemanticShaderCompilationUnitId; spv::Id resultId = getUniqueId(); Instruction* sourceInst = new Instruction(resultId, makeVoidType(), OpExtInst); + sourceInst->reserveOperands(6); sourceInst->addIdOperand(nonSemanticShaderDebugInfo); sourceInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugCompilationUnit); sourceInst->addIdOperand(makeUintConstant(1)); // TODO(greg-lunarg): Get rid of magic number sourceInst->addIdOperand(makeUintConstant(4)); // TODO(greg-lunarg): Get rid of magic number - sourceInst->addIdOperand(makeDebugSource(sourceFileStringId)); + sourceInst->addIdOperand(makeDebugSource(mainFileId)); sourceInst->addIdOperand(makeUintConstant(sourceLang)); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst)); module.mapInstruction(sourceInst); @@ -1123,11 +1105,12 @@ Id Builder::createDebugGlobalVariable(Id const type, char const*const name, Id c assert(type != 0); Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(11); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugGlobalVariable); inst->addIdOperand(getStringId(name)); // name id inst->addIdOperand(type); // type id - inst->addIdOperand(makeDebugSource(sourceFileStringId)); // source id + inst->addIdOperand(makeDebugSource(currentFileId)); // source id inst->addIdOperand(makeUintConstant(currentLine)); // line id TODO: currentLine always zero? inst->addIdOperand(makeUintConstant(0)); // TODO: column id inst->addIdOperand(makeDebugCompilationUnit()); // scope id @@ -1147,11 +1130,12 @@ Id Builder::createDebugLocalVariable(Id type, char const*const name, size_t cons assert(!currentDebugScopeId.empty()); Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(9); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugLocalVariable); inst->addIdOperand(getStringId(name)); // name id inst->addIdOperand(type); // type id - inst->addIdOperand(makeDebugSource(sourceFileStringId)); // source id + inst->addIdOperand(makeDebugSource(currentFileId)); // source id inst->addIdOperand(makeUintConstant(currentLine)); // line id inst->addIdOperand(makeUintConstant(0)); // TODO: column id inst->addIdOperand(currentDebugScopeId.top()); // scope id @@ -1172,6 +1156,7 @@ Id Builder::makeDebugExpression() return debugExpression; Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(2); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugExpression); @@ -1186,12 +1171,13 @@ Id Builder::makeDebugExpression() Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const pointer) { Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(5); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugDeclare); inst->addIdOperand(debugLocalVariable); // debug local variable id inst->addIdOperand(pointer); // pointer to local variable id inst->addIdOperand(makeDebugExpression()); // expression id - buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); + addInstruction(std::unique_ptr<Instruction>(inst)); return inst->getResultId(); } @@ -1199,12 +1185,13 @@ Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const pointer) Id Builder::makeDebugValue(Id const debugLocalVariable, Id const value) { Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); + inst->reserveOperands(5); inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugValue); inst->addIdOperand(debugLocalVariable); // debug local variable id inst->addIdOperand(value); // value of local variable id inst->addIdOperand(makeDebugExpression()); // expression id - buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); + addInstruction(std::unique_ptr<Instruction>(inst)); return inst->getResultId(); } @@ -1217,6 +1204,10 @@ Id Builder::makeAccelerationStructureType() groupedTypes[OpTypeAccelerationStructureKHR].push_back(type); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); module.mapInstruction(type); + if (emitNonSemanticShaderDebugInfo) { + spv::Id debugType = makeCompositeDebugType({}, "accelerationStructure", NonSemanticShaderDebugInfo100Structure, true); + debugId[type->getResultId()] = debugType; + } } else { type = groupedTypes[OpTypeAccelerationStructureKHR].back(); } @@ -1232,6 +1223,10 @@ Id Builder::makeRayQueryType() groupedTypes[OpTypeRayQueryKHR].push_back(type); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); module.mapInstruction(type); + if (emitNonSemanticShaderDebugInfo) { + spv::Id debugType = makeCompositeDebugType({}, "rayQuery", NonSemanticShaderDebugInfo100Structure, true); + debugId[type->getResultId()] = debugType; + } } else { type = groupedTypes[OpTypeRayQueryKHR].back(); } @@ -1517,17 +1512,6 @@ bool Builder::isSpecConstantOpCode(Op opcode) const } } -bool Builder::isRayTracingOpCode(Op opcode) const -{ - switch (opcode) { - case OpTypeAccelerationStructureKHR: - case OpTypeRayQueryKHR: - return true; - default: - return false; - } -} - Id Builder::makeNullConstant(Id typeId) { Instruction* constant; @@ -1618,6 +1602,7 @@ Id Builder::makeInt64Constant(Id typeId, unsigned long long value, bool specCons } Instruction* c = new Instruction(getUniqueId(), typeId, opcode); + c->reserveOperands(2); c->addImmediateOperand(op1); c->addImmediateOperand(op2); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c)); @@ -1671,6 +1656,7 @@ Id Builder::makeDoubleConstant(double d, bool specConstant) } Instruction* c = new Instruction(getUniqueId(), typeId, opcode); + c->reserveOperands(2); c->addImmediateOperand(op1); c->addImmediateOperand(op2); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c)); @@ -1825,6 +1811,7 @@ Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, boo } Instruction* c = new Instruction(getUniqueId(), typeId, opcode); + c->reserveOperands(members.size()); for (int op = 0; op < (int)members.size(); ++op) c->addIdOperand(members[op]); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c)); @@ -1840,6 +1827,7 @@ Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, boo Instruction* Builder::addEntryPoint(ExecutionModel model, Function* function, const char* name) { Instruction* entryPoint = new Instruction(OpEntryPoint); + entryPoint->reserveOperands(3); entryPoint->addImmediateOperand(model); entryPoint->addIdOperand(function->getId()); entryPoint->addStringOperand(name); @@ -1857,6 +1845,7 @@ void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, int val return; Instruction* instr = new Instruction(OpExecutionMode); + instr->reserveOperands(3); instr->addIdOperand(entryPoint->getId()); instr->addImmediateOperand(mode); if (value1 >= 0) @@ -1876,6 +1865,7 @@ void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, const s return; Instruction* instr = new Instruction(OpExecutionMode); + instr->reserveOperands(literals.size() + 2); instr->addIdOperand(entryPoint->getId()); instr->addImmediateOperand(mode); for (auto literal : literals) @@ -1891,6 +1881,7 @@ void Builder::addExecutionModeId(Function* entryPoint, ExecutionMode mode, const return; Instruction* instr = new Instruction(OpExecutionModeId); + instr->reserveOperands(operandIds.size() + 2); instr->addIdOperand(entryPoint->getId()); instr->addImmediateOperand(mode); for (auto operandId : operandIds) @@ -1902,6 +1893,7 @@ void Builder::addExecutionModeId(Function* entryPoint, ExecutionMode mode, const void Builder::addName(Id id, const char* string) { Instruction* name = new Instruction(OpName); + name->reserveOperands(2); name->addIdOperand(id); name->addStringOperand(string); @@ -1911,6 +1903,7 @@ void Builder::addName(Id id, const char* string) void Builder::addMemberName(Id id, int memberNumber, const char* string) { Instruction* name = new Instruction(OpMemberName); + name->reserveOperands(3); name->addIdOperand(id); name->addImmediateOperand(memberNumber); name->addStringOperand(string); @@ -1924,6 +1917,7 @@ void Builder::addDecoration(Id id, Decoration decoration, int num) return; Instruction* dec = new Instruction(OpDecorate); + dec->reserveOperands(2); dec->addIdOperand(id); dec->addImmediateOperand(decoration); if (num >= 0) @@ -1938,6 +1932,7 @@ void Builder::addDecoration(Id id, Decoration decoration, const char* s) return; Instruction* dec = new Instruction(OpDecorateString); + dec->reserveOperands(3); dec->addIdOperand(id); dec->addImmediateOperand(decoration); dec->addStringOperand(s); @@ -1951,6 +1946,7 @@ void Builder::addDecoration(Id id, Decoration decoration, const std::vector<unsi return; Instruction* dec = new Instruction(OpDecorate); + dec->reserveOperands(literals.size() + 2); dec->addIdOperand(id); dec->addImmediateOperand(decoration); for (auto literal : literals) @@ -1965,6 +1961,7 @@ void Builder::addDecoration(Id id, Decoration decoration, const std::vector<cons return; Instruction* dec = new Instruction(OpDecorateString); + dec->reserveOperands(strings.size() + 2); dec->addIdOperand(id); dec->addImmediateOperand(decoration); for (auto string : strings) @@ -1975,6 +1972,7 @@ void Builder::addDecoration(Id id, Decoration decoration, const std::vector<cons void Builder::addLinkageDecoration(Id id, const char* name, spv::LinkageType linkType) { Instruction* dec = new Instruction(OpDecorate); + dec->reserveOperands(4); dec->addIdOperand(id); dec->addImmediateOperand(spv::DecorationLinkageAttributes); dec->addStringOperand(name); @@ -1989,6 +1987,7 @@ void Builder::addDecorationId(Id id, Decoration decoration, Id idDecoration) return; Instruction* dec = new Instruction(OpDecorateId); + dec->reserveOperands(3); dec->addIdOperand(id); dec->addImmediateOperand(decoration); dec->addIdOperand(idDecoration); @@ -2002,6 +2001,7 @@ void Builder::addDecorationId(Id id, Decoration decoration, const std::vector<Id return; Instruction* dec = new Instruction(OpDecorateId); + dec->reserveOperands(operandIds.size() + 2); dec->addIdOperand(id); dec->addImmediateOperand(decoration); @@ -2017,6 +2017,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat return; Instruction* dec = new Instruction(OpMemberDecorate); + dec->reserveOperands(3); dec->addIdOperand(id); dec->addImmediateOperand(member); dec->addImmediateOperand(decoration); @@ -2032,6 +2033,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat return; Instruction* dec = new Instruction(OpMemberDecorateStringGOOGLE); + dec->reserveOperands(4); dec->addIdOperand(id); dec->addImmediateOperand(member); dec->addImmediateOperand(decoration); @@ -2046,6 +2048,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat return; Instruction* dec = new Instruction(OpMemberDecorate); + dec->reserveOperands(literals.size() + 3); dec->addIdOperand(id); dec->addImmediateOperand(member); dec->addImmediateOperand(decoration); @@ -2061,6 +2064,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat return; Instruction* dec = new Instruction(OpMemberDecorateString); + dec->reserveOperands(strings.size() + 3); dec->addIdOperand(id); dec->addImmediateOperand(member); dec->addImmediateOperand(decoration); @@ -2070,6 +2074,52 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat decorations.push_back(std::unique_ptr<Instruction>(dec)); } +void Builder::addInstruction(std::unique_ptr<Instruction> inst) { + // Optionally insert OpDebugScope + if (emitNonSemanticShaderDebugInfo && dirtyScopeTracker) { + if (buildPoint->updateDebugScope(currentDebugScopeId.top())) { + auto scopeInst = std::make_unique<Instruction>(getUniqueId(), makeVoidType(), OpExtInst); + scopeInst->reserveOperands(3); + scopeInst->addIdOperand(nonSemanticShaderDebugInfo); + scopeInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugScope); + scopeInst->addIdOperand(currentDebugScopeId.top()); + buildPoint->addInstruction(std::move(scopeInst)); + } + + dirtyScopeTracker = false; + } + + // Insert OpLine/OpDebugLine if the debug source location has changed + if (trackDebugInfo && dirtyLineTracker) { + if (buildPoint->updateDebugSourceLocation(currentLine, 0, currentFileId)) { + if (emitSpirvDebugInfo) { + auto lineInst = std::make_unique<Instruction>(OpLine); + lineInst->reserveOperands(3); + lineInst->addIdOperand(currentFileId); + lineInst->addImmediateOperand(currentLine); + lineInst->addImmediateOperand(0); + buildPoint->addInstruction(std::move(lineInst)); + } + if (emitNonSemanticShaderDebugInfo) { + auto lineInst = std::make_unique<Instruction>(getUniqueId(), makeVoidType(), OpExtInst); + lineInst->reserveOperands(7); + lineInst->addIdOperand(nonSemanticShaderDebugInfo); + lineInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugLine); + lineInst->addIdOperand(makeDebugSource(currentFileId)); + lineInst->addIdOperand(makeUintConstant(currentLine)); + lineInst->addIdOperand(makeUintConstant(currentLine)); + lineInst->addIdOperand(makeUintConstant(0)); + lineInst->addIdOperand(makeUintConstant(0)); + buildPoint->addInstruction(std::move(lineInst)); + } + } + + dirtyLineTracker = false; + } + + buildPoint->addInstruction(std::move(inst)); +} + // Comments in header Function* Builder::makeEntryPoint(const char* entryPoint) { @@ -2113,7 +2163,7 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const // reset last debug scope if (emitNonSemanticShaderDebugInfo) { - lastDebugScopeId = NoResult; + dirtyScopeTracker = true; } // CFG @@ -2153,8 +2203,6 @@ void Builder::setupDebugFunctionEntry(Function* function, const char* name, int // DebugScope and DebugLine for parameter DebugDeclares assert(paramTypes.size() == paramNames.size()); if ((int)paramTypes.size() > 0) { - addDebugScopeAndLine(currentFileId, currentLine, 0); - Id firstParamId = function->getParamId(0); for (size_t p = 0; p < paramTypes.size(); ++p) { @@ -2194,6 +2242,7 @@ Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id Id funcId = getUniqueId(); auto type = new Instruction(funcId, makeVoidType(), OpExtInst); + type->reserveOperands(11); type->addIdOperand(nonSemanticShaderDebugInfo); type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugFunction); type->addIdOperand(nameId); @@ -2215,6 +2264,7 @@ Id Builder::makeDebugLexicalBlock(uint32_t line) { Id lexId = getUniqueId(); auto lex = new Instruction(lexId, makeVoidType(), OpExtInst); + lex->reserveOperands(6); lex->addIdOperand(nonSemanticShaderDebugInfo); lex->addImmediateOperand(NonSemanticShaderDebugInfo100DebugLexicalBlock); lex->addIdOperand(makeDebugSource(currentFileId)); @@ -2243,29 +2293,29 @@ void Builder::makeReturn(bool implicit, Id retVal) if (retVal) { Instruction* inst = new Instruction(NoResult, NoType, OpReturnValue); inst->addIdOperand(retVal); - buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); + addInstruction(std::unique_ptr<Instruction>(inst)); } else - buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(NoResult, NoType, OpReturn))); + addInstruction(std::unique_ptr<Instruction>(new Instruction(NoResult, NoType, OpReturn))); if (! implicit) createAndSetNoPredecessorBlock("post-return"); } // Comments in header -void Builder::enterScope(uint32_t line) +void Builder::enterLexicalBlock(uint32_t line) { // Generate new lexical scope debug instruction Id lexId = makeDebugLexicalBlock(line); currentDebugScopeId.push(lexId); - lastDebugScopeId = NoResult; + dirtyScopeTracker = true; } // Comments in header -void Builder::leaveScope() +void Builder::leaveLexicalBlock() { // Pop current scope from stack and clear current scope currentDebugScopeId.pop(); - lastDebugScopeId = NoResult; + dirtyScopeTracker = true; } // Comments in header @@ -2285,11 +2335,12 @@ void Builder::enterFunction(Function const* function) // Create DebugFunctionDefinition spv::Id resultId = getUniqueId(); Instruction* defInst = new Instruction(resultId, makeVoidType(), OpExtInst); + defInst->reserveOperands(4); defInst->addIdOperand(nonSemanticShaderDebugInfo); defInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugFunctionDefinition); defInst->addIdOperand(debugId[funcId]); defInst->addIdOperand(funcId); - buildPoint->addInstruction(std::unique_ptr<Instruction>(defInst)); + addInstruction(std::unique_ptr<Instruction>(defInst)); } if (auto linkType = function->getLinkType(); linkType != LinkageTypeMax) { @@ -2325,7 +2376,7 @@ void Builder::leaveFunction() // Comments in header void Builder::makeStatementTerminator(spv::Op opcode, const char *name) { - buildPoint->addInstruction(std::unique_ptr<Instruction>(new Instruction(opcode))); + addInstruction(std::unique_ptr<Instruction>(new Instruction(opcode))); createAndSetNoPredecessorBlock(name); } @@ -2368,7 +2419,7 @@ Id Builder::createVariable(Decoration precision, StorageClass storageClass, Id t constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(inst)); module.mapInstruction(inst); - if (emitNonSemanticShaderDebugInfo && !isRayTracingOpCode(getOpCode(type))) + if (emitNonSemanticShaderDebugInfo) { auto const debugResultId = createDebugGlobalVariable(debugId[type], name, inst->getResultId()); debugId[inst->getResultId()] = debugResultId; @@ -2387,7 +2438,7 @@ Id Builder::createVariable(Decoration precision, StorageClass storageClass, Id t Id Builder::createUndefined(Id type) { Instruction* inst = new Instruction(getUniqueId(), type, OpUndef); - buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); + addInstruction(std::unique_ptr<Instruction>(inst)); return inst->getResultId(); } @@ -2416,6 +2467,7 @@ void Builder::createStore(Id rValue, Id lValue, spv::MemoryAccessMask memoryAcce unsigned int alignment) { Instruction* store = new Instruction(OpStore); + store->reserveOperands(2); store->addIdOperand(lValue); store->addIdOperand(rValue); @@ -2431,7 +2483,7 @@ void Builder::createStore(Id rValue, Id lValue, spv::MemoryAccessMask memoryAcce } } - buildPoint->addInstruction(std::unique_ptr<Instruction>(store)); + addInstruction(std::unique_ptr<Instruction>(store)); } // Comments in header @@ -2453,7 +2505,7 @@ Id Builder::createLoad(Id lValue, spv::Decoration precision, spv::MemoryAccessMa } } - buildPoint->addInstruction(std::unique_ptr<Instruction>(load)); + addInstruction(std::unique_ptr<Instruction>(load)); setPrecision(load->getResultId(), precision); return load->getResultId(); @@ -2468,10 +2520,11 @@ Id Builder::createAccessChain(StorageClass storageClass, Id base, const std::vec // Make the instruction Instruction* chain = new Instruction(getUniqueId(), typeId, OpAccessChain); + chain->reserveOperands(offsets.size() + 1); chain->addIdOperand(base); for (int i = 0; i < (int)offsets.size(); ++i) chain->addIdOperand(offsets[i]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(chain)); + addInstruction(std::unique_ptr<Instruction>(chain)); return chain->getResultId(); } @@ -2480,9 +2533,10 @@ Id Builder::createArrayLength(Id base, unsigned int member) { spv::Id intType = makeUintType(32); Instruction* length = new Instruction(getUniqueId(), intType, OpArrayLength); + length->reserveOperands(2); length->addIdOperand(base); length->addImmediateOperand(member); - buildPoint->addInstruction(std::unique_ptr<Instruction>(length)); + addInstruction(std::unique_ptr<Instruction>(length)); return length->getResultId(); } @@ -2499,7 +2553,7 @@ Id Builder::createCooperativeMatrixLengthKHR(Id type) Instruction* length = new Instruction(getUniqueId(), intType, OpCooperativeMatrixLengthKHR); length->addIdOperand(type); - buildPoint->addInstruction(std::unique_ptr<Instruction>(length)); + addInstruction(std::unique_ptr<Instruction>(length)); return length->getResultId(); } @@ -2516,7 +2570,7 @@ Id Builder::createCooperativeMatrixLengthNV(Id type) Instruction* length = new Instruction(getUniqueId(), intType, OpCooperativeMatrixLengthNV); length->addIdOperand(type); - buildPoint->addInstruction(std::unique_ptr<Instruction>(length)); + addInstruction(std::unique_ptr<Instruction>(length)); return length->getResultId(); } @@ -2530,9 +2584,10 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, unsigned index) std::vector<Id>(1, index)); } Instruction* extract = new Instruction(getUniqueId(), typeId, OpCompositeExtract); + extract->reserveOperands(2); extract->addIdOperand(composite); extract->addImmediateOperand(index); - buildPoint->addInstruction(std::unique_ptr<Instruction>(extract)); + addInstruction(std::unique_ptr<Instruction>(extract)); return extract->getResultId(); } @@ -2545,10 +2600,11 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, const std::vector<un return createSpecConstantOp(OpCompositeExtract, typeId, std::vector<Id>(1, composite), indexes); } Instruction* extract = new Instruction(getUniqueId(), typeId, OpCompositeExtract); + extract->reserveOperands(indexes.size() + 1); extract->addIdOperand(composite); for (int i = 0; i < (int)indexes.size(); ++i) extract->addImmediateOperand(indexes[i]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(extract)); + addInstruction(std::unique_ptr<Instruction>(extract)); return extract->getResultId(); } @@ -2556,10 +2612,11 @@ Id Builder::createCompositeExtract(Id composite, Id typeId, const std::vector<un Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned index) { Instruction* insert = new Instruction(getUniqueId(), typeId, OpCompositeInsert); + insert->reserveOperands(3); insert->addIdOperand(object); insert->addIdOperand(composite); insert->addImmediateOperand(index); - buildPoint->addInstruction(std::unique_ptr<Instruction>(insert)); + addInstruction(std::unique_ptr<Instruction>(insert)); return insert->getResultId(); } @@ -2567,11 +2624,12 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned i Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes) { Instruction* insert = new Instruction(getUniqueId(), typeId, OpCompositeInsert); + insert->reserveOperands(indexes.size() + 2); insert->addIdOperand(object); insert->addIdOperand(composite); for (int i = 0; i < (int)indexes.size(); ++i) insert->addImmediateOperand(indexes[i]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(insert)); + addInstruction(std::unique_ptr<Instruction>(insert)); return insert->getResultId(); } @@ -2579,9 +2637,10 @@ Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, const std: Id Builder::createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex) { Instruction* extract = new Instruction(getUniqueId(), typeId, OpVectorExtractDynamic); + extract->reserveOperands(2); extract->addIdOperand(vector); extract->addIdOperand(componentIndex); - buildPoint->addInstruction(std::unique_ptr<Instruction>(extract)); + addInstruction(std::unique_ptr<Instruction>(extract)); return extract->getResultId(); } @@ -2589,10 +2648,11 @@ Id Builder::createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex) Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex) { Instruction* insert = new Instruction(getUniqueId(), typeId, OpVectorInsertDynamic); + insert->reserveOperands(3); insert->addIdOperand(vector); insert->addIdOperand(component); insert->addIdOperand(componentIndex); - buildPoint->addInstruction(std::unique_ptr<Instruction>(insert)); + addInstruction(std::unique_ptr<Instruction>(insert)); return insert->getResultId(); } @@ -2601,7 +2661,7 @@ Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id com void Builder::createNoResultOp(Op opCode) { Instruction* op = new Instruction(opCode); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } // An opcode that has one id operand, no result id, and no type @@ -2609,47 +2669,51 @@ void Builder::createNoResultOp(Op opCode, Id operand) { Instruction* op = new Instruction(opCode); op->addIdOperand(operand); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } // An opcode that has one or more operands, no result id, and no type void Builder::createNoResultOp(Op opCode, const std::vector<Id>& operands) { Instruction* op = new Instruction(opCode); - for (auto it = operands.cbegin(); it != operands.cend(); ++it) { - op->addIdOperand(*it); + op->reserveOperands(operands.size()); + for (auto id : operands) { + op->addIdOperand(id); } - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } // An opcode that has multiple operands, no result id, and no type void Builder::createNoResultOp(Op opCode, const std::vector<IdImmediate>& operands) { Instruction* op = new Instruction(opCode); + op->reserveOperands(operands.size()); for (auto it = operands.cbegin(); it != operands.cend(); ++it) { if (it->isId) op->addIdOperand(it->word); else op->addImmediateOperand(it->word); } - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } void Builder::createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask semantics) { Instruction* op = new Instruction(OpControlBarrier); + op->reserveOperands(3); op->addIdOperand(makeUintConstant(execution)); op->addIdOperand(makeUintConstant(memory)); op->addIdOperand(makeUintConstant(semantics)); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } void Builder::createMemoryBarrier(unsigned executionScope, unsigned memorySemantics) { Instruction* op = new Instruction(OpMemoryBarrier); + op->reserveOperands(2); op->addIdOperand(makeUintConstant(executionScope)); op->addIdOperand(makeUintConstant(memorySemantics)); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); } // An opcode that has one operands, a result id, and a type @@ -2662,7 +2726,7 @@ Id Builder::createUnaryOp(Op opCode, Id typeId, Id operand) } Instruction* op = new Instruction(getUniqueId(), typeId, opCode); op->addIdOperand(operand); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2677,9 +2741,10 @@ Id Builder::createBinOp(Op opCode, Id typeId, Id left, Id right) return createSpecConstantOp(opCode, typeId, operands, std::vector<Id>()); } Instruction* op = new Instruction(getUniqueId(), typeId, opCode); + op->reserveOperands(2); op->addIdOperand(left); op->addIdOperand(right); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2697,10 +2762,11 @@ Id Builder::createTriOp(Op opCode, Id typeId, Id op1, Id op2, Id op3) opCode, typeId, operands, std::vector<Id>()); } Instruction* op = new Instruction(getUniqueId(), typeId, opCode); + op->reserveOperands(3); op->addIdOperand(op1); op->addIdOperand(op2); op->addIdOperand(op3); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2708,9 +2774,10 @@ Id Builder::createTriOp(Op opCode, Id typeId, Id op1, Id op2, Id op3) Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands) { Instruction* op = new Instruction(getUniqueId(), typeId, opCode); - for (auto it = operands.cbegin(); it != operands.cend(); ++it) - op->addIdOperand(*it); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + op->reserveOperands(operands.size()); + for (auto id : operands) + op->addIdOperand(id); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2718,13 +2785,14 @@ Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands) Id Builder::createOp(Op opCode, Id typeId, const std::vector<IdImmediate>& operands) { Instruction* op = new Instruction(getUniqueId(), typeId, opCode); + op->reserveOperands(operands.size()); for (auto it = operands.cbegin(); it != operands.cend(); ++it) { if (it->isId) op->addIdOperand(it->word); else op->addImmediateOperand(it->word); } - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2733,6 +2801,7 @@ Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& op const std::vector<unsigned>& literals) { Instruction* op = new Instruction(getUniqueId(), typeId, OpSpecConstantOp); + op->reserveOperands(operands.size() + literals.size() + 1); op->addImmediateOperand((unsigned) opCode); for (auto it = operands.cbegin(); it != operands.cend(); ++it) op->addIdOperand(*it); @@ -2755,10 +2824,11 @@ Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& op Id Builder::createFunctionCall(spv::Function* function, const std::vector<spv::Id>& args) { Instruction* op = new Instruction(getUniqueId(), function->getReturnType(), OpFunctionCall); + op->reserveOperands(args.size() + 1); op->addIdOperand(function->getId()); for (int a = 0; a < (int)args.size(); ++a) op->addIdOperand(args[a]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -2776,11 +2846,12 @@ Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, cons } Instruction* swizzle = new Instruction(getUniqueId(), typeId, OpVectorShuffle); assert(isVector(source)); + swizzle->reserveOperands(channels.size() + 2); swizzle->addIdOperand(source); swizzle->addIdOperand(source); for (int i = 0; i < (int)channels.size(); ++i) swizzle->addImmediateOperand(channels[i]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(swizzle)); + addInstruction(std::unique_ptr<Instruction>(swizzle)); return setPrecision(swizzle->getResultId(), precision); } @@ -2794,6 +2865,7 @@ Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, const std::vect Instruction* swizzle = new Instruction(getUniqueId(), typeId, OpVectorShuffle); assert(isVector(target)); + swizzle->reserveOperands(2); swizzle->addIdOperand(target); assert(getNumComponents(source) == (int)channels.size()); @@ -2811,9 +2883,10 @@ Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, const std::vect components[channels[i]] = numTargetComponents + i; // finish the instruction with these components selectors + swizzle->reserveOperands(numTargetComponents); for (int i = 0; i < numTargetComponents; ++i) swizzle->addImmediateOperand(components[i]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(swizzle)); + addInstruction(std::unique_ptr<Instruction>(swizzle)); return swizzle->getResultId(); } @@ -2856,9 +2929,10 @@ Id Builder::smearScalar(Decoration precision, Id scalar, Id vectorType) smear = module.getInstruction(result_id); } else { smear = new Instruction(getUniqueId(), vectorType, OpCompositeConstruct); + smear->reserveOperands(numComponents); for (int c = 0; c < numComponents; ++c) smear->addIdOperand(scalar); - buildPoint->addInstruction(std::unique_ptr<Instruction>(smear)); + addInstruction(std::unique_ptr<Instruction>(smear)); } return setPrecision(smear->getResultId(), precision); @@ -2868,12 +2942,13 @@ Id Builder::smearScalar(Decoration precision, Id scalar, Id vectorType) Id Builder::createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args) { Instruction* inst = new Instruction(getUniqueId(), resultType, OpExtInst); + inst->reserveOperands(args.size() + 2); inst->addIdOperand(builtins); inst->addImmediateOperand(entryPoint); for (int arg = 0; arg < (int)args.size(); ++arg) inst->addIdOperand(args[arg]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); + addInstruction(std::unique_ptr<Instruction>(inst)); return inst->getResultId(); } @@ -3062,6 +3137,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse, // Build the SPIR-V instruction Instruction* textureInst = new Instruction(getUniqueId(), resultType, opCode); + textureInst->reserveOperands(optArgNum + (texArgs.size() - (optArgNum + 1))); for (size_t op = 0; op < optArgNum; ++op) textureInst->addIdOperand(texArgs[op]); if (optArgNum < texArgs.size()) @@ -3069,7 +3145,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse, for (size_t op = optArgNum + 1; op < texArgs.size(); ++op) textureInst->addIdOperand(texArgs[op]); setPrecision(textureInst->getResultId(), precision); - buildPoint->addInstruction(std::unique_ptr<Instruction>(textureInst)); + addInstruction(std::unique_ptr<Instruction>(textureInst)); Id resultId = textureInst->getResultId(); @@ -3149,7 +3225,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter query->addIdOperand(parameters.coords); if (parameters.lod) query->addIdOperand(parameters.lod); - buildPoint->addInstruction(std::unique_ptr<Instruction>(query)); + addInstruction(std::unique_ptr<Instruction>(query)); addCapability(CapabilityImageQuery); return query->getResultId(); @@ -3246,9 +3322,10 @@ Id Builder::createCompositeConstruct(Id typeId, const std::vector<Id>& constitue } Instruction* op = new Instruction(getUniqueId(), typeId, OpCompositeConstruct); + op->reserveOperands(constituents.size()); for (int c = 0; c < (int)constituents.size(); ++c) op->addIdOperand(constituents[c]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(op)); + addInstruction(std::unique_ptr<Instruction>(op)); return op->getResultId(); } @@ -3332,10 +3409,13 @@ Id Builder::createConstructor(Decoration precision, const std::vector<Id>& sourc } // If the result is a vector, make it from the gathered constituents. - if (constituents.size() > 0) + if (constituents.size() > 0) { result = createCompositeConstruct(resultTypeId, constituents); - - return setPrecision(result, precision); + return setPrecision(result, precision); + } else { + // Precision was set when generating this component. + return result; + } } // Comments in header @@ -3535,6 +3615,7 @@ void Builder::makeSwitch(Id selector, unsigned int control, int numSegments, con // make the switch instruction Instruction* switchInst = new Instruction(NoResult, NoType, OpSwitch); + switchInst->reserveOperands((caseValues.size() * 2) + 2); switchInst->addIdOperand(selector); auto defaultOrMerge = (defaultSegment >= 0) ? segmentBlocks[defaultSegment] : mergeBlock; switchInst->addIdOperand(defaultOrMerge->getId()); @@ -3544,7 +3625,7 @@ void Builder::makeSwitch(Id selector, unsigned int control, int numSegments, con switchInst->addIdOperand(segmentBlocks[valueIndexToSegment[i]]->getId()); segmentBlocks[valueIndexToSegment[i]]->addPredecessor(buildPoint); } - buildPoint->addInstruction(std::unique_ptr<Instruction>(switchInst)); + addInstruction(std::unique_ptr<Instruction>(switchInst)); // push the merge block switchMerges.push(mergeBlock); @@ -4063,37 +4144,40 @@ void Builder::createBranch(Block* block) { Instruction* branch = new Instruction(OpBranch); branch->addIdOperand(block->getId()); - buildPoint->addInstruction(std::unique_ptr<Instruction>(branch)); + addInstruction(std::unique_ptr<Instruction>(branch)); block->addPredecessor(buildPoint); } void Builder::createSelectionMerge(Block* mergeBlock, unsigned int control) { Instruction* merge = new Instruction(OpSelectionMerge); + merge->reserveOperands(2); merge->addIdOperand(mergeBlock->getId()); merge->addImmediateOperand(control); - buildPoint->addInstruction(std::unique_ptr<Instruction>(merge)); + addInstruction(std::unique_ptr<Instruction>(merge)); } void Builder::createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned int control, const std::vector<unsigned int>& operands) { Instruction* merge = new Instruction(OpLoopMerge); + merge->reserveOperands(operands.size() + 3); merge->addIdOperand(mergeBlock->getId()); merge->addIdOperand(continueBlock->getId()); merge->addImmediateOperand(control); for (int op = 0; op < (int)operands.size(); ++op) merge->addImmediateOperand(operands[op]); - buildPoint->addInstruction(std::unique_ptr<Instruction>(merge)); + addInstruction(std::unique_ptr<Instruction>(merge)); } void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* elseBlock) { Instruction* branch = new Instruction(OpBranchConditional); + branch->reserveOperands(3); branch->addIdOperand(condition); branch->addIdOperand(thenBlock->getId()); branch->addIdOperand(elseBlock->getId()); - buildPoint->addInstruction(std::unique_ptr<Instruction>(branch)); + addInstruction(std::unique_ptr<Instruction>(branch)); thenBlock->addPredecessor(buildPoint); elseBlock->addPredecessor(buildPoint); } @@ -4111,6 +4195,7 @@ void Builder::dumpSourceInstructions(const spv::Id fileId, const std::string& te if (sourceLang != SourceLanguageUnknown) { // OpSource Language Version File Source Instruction sourceInst(NoResult, NoType, OpSource); + sourceInst.reserveOperands(3); sourceInst.addImmediateOperand(sourceLang); sourceInst.addImmediateOperand(sourceVersion); // File operand @@ -4145,7 +4230,7 @@ void Builder::dumpSourceInstructions(const spv::Id fileId, const std::string& te void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const { if (emitNonSemanticShaderDebugInfo) return; - dumpSourceInstructions(sourceFileStringId, sourceText, out); + dumpSourceInstructions(mainFileId, sourceText, out); for (auto iItr = includeFiles.begin(); iItr != includeFiles.end(); ++iItr) dumpSourceInstructions(iItr->first, *iItr->second, out); } diff --git a/thirdparty/glslang/SPIRV/SpvBuilder.h b/thirdparty/glslang/SPIRV/SpvBuilder.h index b1ca6ce1f7..a65a98e337 100644 --- a/thirdparty/glslang/SPIRV/SpvBuilder.h +++ b/thirdparty/glslang/SPIRV/SpvBuilder.h @@ -103,31 +103,53 @@ public: stringIds[file_c_str] = strId; return strId; } - spv::Id getSourceFile() const + + spv::Id getMainFileId() const { return mainFileId; } + + // Initialize the main source file name + void setDebugSourceFile(const std::string& file) { - return sourceFileStringId; + if (trackDebugInfo) { + dirtyLineTracker = true; + mainFileId = getStringId(file); + currentFileId = mainFileId; + } } - void setSourceFile(const std::string& file) + + // Set the debug source location tracker in the builder. + // The upcoming instructions in basic blocks will be associated to this location. + void setDebugSourceLocation(int line, const char* filename) { - sourceFileStringId = getStringId(file); - currentFileId = sourceFileStringId; + if (trackDebugInfo) { + dirtyLineTracker = true; + if (line != 0) { + // TODO: This is special handling of some AST nodes having (untracked) line 0. + // But they should have a valid line number. + currentLine = line; + if (filename) { + currentFileId = getStringId(filename); + } + } + } } + void setSourceText(const std::string& text) { sourceText = text; } void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); } void addModuleProcessed(const std::string& p) { moduleProcesses.push_back(p.c_str()); } - void setEmitOpLines() { emitOpLines = true; } - void setEmitNonSemanticShaderDebugInfo(bool const emit) + void setEmitSpirvDebugInfo() { - emitNonSemanticShaderDebugInfo = emit; - - if(emit) - { - importNonSemanticShaderDebugInfoInstructions(); - } + trackDebugInfo = true; + emitSpirvDebugInfo = true; } - void setEmitNonSemanticShaderDebugSource(bool const src) + void setEmitNonSemanticShaderDebugInfo(bool emitSourceText) { - emitNonSemanticShaderDebugSource = src; + trackDebugInfo = true; + emitNonSemanticShaderDebugInfo = true; + importNonSemanticShaderDebugInfoInstructions(); + + if (emitSourceText) { + emitNonSemanticShaderDebugSource = emitSourceText; + } } void addExtension(const char* ext) { extensions.insert(ext); } void removeExtension(const char* ext) @@ -169,20 +191,6 @@ public: return id; } - // Generate OpLine for non-filename-based #line directives (ie no filename - // seen yet): Log the current line, and if different than the last one, - // issue a new OpLine using the new line and current source file name. - void setLine(int line); - - // If filename null, generate OpLine for non-filename-based line directives, - // else do filename-based: Log the current line and file, and if different - // than the last one, issue a new OpLine using the new line and file - // name. - void setLine(int line, const char* filename); - // Low-level OpLine. See setLine() for a layered helper. - void addLine(Id fileName, int line, int column); - void addDebugScopeAndLine(Id fileName, int line, int column); - // For creating new types (will return old type if the requested one was already made). Id makeVoidType(); Id makeBoolType(); @@ -226,6 +234,7 @@ public: Id makeMemberDebugType(Id const memberType, DebugTypeLoc const& debugTypeLoc); Id makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name, NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType = false); + Id makePointerDebugType(StorageClass storageClass, Id const baseType); Id makeDebugSource(const Id fileName); Id makeDebugCompilationUnit(); Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable); @@ -317,8 +326,6 @@ public: // See if a resultId is valid for use as an initializer. bool isValidInitializer(Id resultId) const { return isConstant(resultId) || isGlobalVariable(resultId); } - bool isRayTracingOpCode(Op opcode) const; - int getScalarTypeWidth(Id typeId) const { Id scalarTypeId = getScalarTypeId(typeId); @@ -408,11 +415,16 @@ public: // Also reset current last DebugScope and current source line to unknown void setBuildPoint(Block* bp) { buildPoint = bp; - lastDebugScopeId = NoResult; - currentLine = 0; + // TODO: Technically, change of build point should set line tracker dirty. But we'll have bad line info for + // branch instructions. Commenting this for now because at least this matches the old behavior. + dirtyScopeTracker = true; } Block* getBuildPoint() const { return buildPoint; } + // Append an instruction to the end of the current build point. + // Optionally, additional debug info instructions may also be prepended. + void addInstruction(std::unique_ptr<Instruction> inst); + // Make the entry-point function. The returned pointer is only valid // for the lifetime of this builder. Function* makeEntryPoint(const char*); @@ -429,10 +441,10 @@ public: void makeReturn(bool implicit, Id retVal = 0); // Initialize state and generate instructions for new lexical scope - void enterScope(uint32_t line); + void enterLexicalBlock(uint32_t line); // Set state and generate instructions to exit current lexical scope - void leaveScope(); + void leaveLexicalBlock(); // Prepare builder for generation of instructions for a function. void enterFunction(Function const* function); @@ -881,21 +893,37 @@ public: unsigned int spvVersion; // the version of SPIR-V to emit in the header SourceLanguage sourceLang; int sourceVersion; - spv::Id sourceFileStringId; spv::Id nonSemanticShaderCompilationUnitId {0}; spv::Id nonSemanticShaderDebugInfo {0}; spv::Id debugInfoNone {0}; spv::Id debugExpression {0}; // Debug expression with zero operations. std::string sourceText; - int currentLine; - const char* currentFile; - spv::Id currentFileId; + + // True if an new OpLine/OpDebugLine may need to be inserted. Either: + // 1. The current debug location changed + // 2. The current build point changed + bool dirtyLineTracker; + int currentLine = 0; + // OpString id of the current file name. Always 0 if debug info is off. + spv::Id currentFileId = 0; + // OpString id of the main file name. Always 0 if debug info is off. + spv::Id mainFileId = 0; + + // True if an new OpDebugScope may need to be inserted. Either: + // 1. A new lexical block is pushed + // 2. The current build point changed + bool dirtyScopeTracker; std::stack<spv::Id> currentDebugScopeId; - spv::Id lastDebugScopeId; - bool emitOpLines; - bool emitNonSemanticShaderDebugInfo; - bool restoreNonSemanticShaderDebugInfo; - bool emitNonSemanticShaderDebugSource; + + // This flag toggles tracking of debug info while building the SPIR-V. + bool trackDebugInfo = false; + // This flag toggles emission of SPIR-V debug instructions, like OpLine and OpSource. + bool emitSpirvDebugInfo = false; + // This flag toggles emission of Non-Semantic Debug extension debug instructions. + bool emitNonSemanticShaderDebugInfo = false; + bool restoreNonSemanticShaderDebugInfo = false; + bool emitNonSemanticShaderDebugSource = false; + std::set<std::string> extensions; std::vector<const char*> sourceExtensions; std::vector<const char*> moduleProcesses; diff --git a/thirdparty/glslang/SPIRV/SpvPostProcess.cpp b/thirdparty/glslang/SPIRV/SpvPostProcess.cpp index 13001a67a1..ebc69124e6 100644 --- a/thirdparty/glslang/SPIRV/SpvPostProcess.cpp +++ b/thirdparty/glslang/SPIRV/SpvPostProcess.cpp @@ -181,6 +181,7 @@ void Builder::postProcessType(const Instruction& inst, Id typeId) else if (width == 8) addCapability(CapabilityInt8); } + break; default: if (basicTypeOp == OpTypeInt) { if (width == 16) diff --git a/thirdparty/glslang/SPIRV/disassemble.cpp b/thirdparty/glslang/SPIRV/disassemble.cpp index c5e961cf02..ab77610c4e 100644 --- a/thirdparty/glslang/SPIRV/disassemble.cpp +++ b/thirdparty/glslang/SPIRV/disassemble.cpp @@ -80,6 +80,7 @@ enum ExtInstSet { GLSLextNVInst, OpenCLExtInst, NonSemanticDebugPrintfExtInst, + NonSemanticDebugBreakExtInst, NonSemanticShaderDebugInfo100 }; @@ -360,7 +361,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, switch (stream[word]) { case 8: idDescriptor[resultId] = "int8_t"; break; case 16: idDescriptor[resultId] = "int16_t"; break; - default: assert(0); // fallthrough + default: assert(0); [[fallthrough]]; case 32: idDescriptor[resultId] = "int"; break; case 64: idDescriptor[resultId] = "int64_t"; break; } @@ -368,7 +369,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, case OpTypeFloat: switch (stream[word]) { case 16: idDescriptor[resultId] = "float16_t"; break; - default: assert(0); // fallthrough + default: assert(0); [[fallthrough]]; case 32: idDescriptor[resultId] = "float"; break; case 64: idDescriptor[resultId] = "float64_t"; break; } @@ -506,6 +507,8 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, extInstSet = OpenCLExtInst; } else if (strcmp("NonSemantic.DebugPrintf", name) == 0) { extInstSet = NonSemanticDebugPrintfExtInst; + } else if (strcmp("NonSemantic.DebugBreak", name) == 0) { + extInstSet = NonSemanticDebugBreakExtInst; } else if (strcmp("NonSemantic.Shader.DebugInfo.100", name) == 0) { extInstSet = NonSemanticShaderDebugInfo100; } else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 || @@ -533,6 +536,8 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")"; } else if (extInstSet == NonSemanticDebugPrintfExtInst) { out << "(DebugPrintf)"; + } else if (extInstSet == NonSemanticDebugBreakExtInst) { + out << "(DebugBreak)"; } else if (extInstSet == NonSemanticShaderDebugInfo100) { out << "(" << NonSemanticShaderDebugInfo100GetDebugNames(entrypoint) << ")"; } diff --git a/thirdparty/glslang/SPIRV/doc.cpp b/thirdparty/glslang/SPIRV/doc.cpp index 1a05c67360..ea4915fe78 100644 --- a/thirdparty/glslang/SPIRV/doc.cpp +++ b/thirdparty/glslang/SPIRV/doc.cpp @@ -1,5 +1,6 @@ // // Copyright (C) 2014-2015 LunarG, Inc. +// Copyright (C) 2022-2024 Arm Limited. // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. // // All rights reserved. @@ -198,6 +199,7 @@ const char* ExecutionModeString(int mode) case ExecutionModeStencilRefGreaterBackAMD: return "StencilRefGreaterBackAMD"; case ExecutionModeStencilRefReplacingEXT: return "StencilRefReplacingEXT"; case ExecutionModeSubgroupUniformControlFlowKHR: return "SubgroupUniformControlFlow"; + case ExecutionModeMaximallyReconvergesKHR: return "MaximallyReconverges"; case ExecutionModeOutputLinesNV: return "OutputLinesNV"; case ExecutionModeOutputPrimitivesNV: return "OutputPrimitivesNV"; @@ -217,6 +219,9 @@ const char* ExecutionModeString(int mode) case ExecutionModeNoGlobalOffsetINTEL: return "NoGlobalOffsetINTEL"; case ExecutionModeNumSIMDWorkitemsINTEL: return "NumSIMDWorkitemsINTEL"; + case ExecutionModeRequireFullQuadsKHR: return "RequireFullQuadsKHR"; + case ExecutionModeQuadDerivativesKHR: return "QuadDerivativesKHR"; + case ExecutionModeNonCoherentColorAttachmentReadEXT: return "NonCoherentColorAttachmentReadEXT"; case ExecutionModeNonCoherentDepthAttachmentReadEXT: return "NonCoherentDepthAttachmentReadEXT"; case ExecutionModeNonCoherentStencilAttachmentReadEXT: return "NonCoherentStencilAttachmentReadEXT"; @@ -314,6 +319,7 @@ const char* DecorationString(int decoration) case DecorationWeightTextureQCOM: return "DecorationWeightTextureQCOM"; case DecorationBlockMatchTextureQCOM: return "DecorationBlockMatchTextureQCOM"; + case DecorationBlockMatchSamplerQCOM: return "DecorationBlockMatchSamplerQCOM"; case DecorationExplicitInterpAMD: return "ExplicitInterpAMD"; case DecorationOverrideCoverageNV: return "OverrideCoverageNV"; case DecorationPassthroughNV: return "PassthroughNV"; @@ -938,6 +944,7 @@ const char* CapabilityString(int info) case CapabilitySubgroupBallotKHR: return "SubgroupBallotKHR"; case CapabilityDrawParameters: return "DrawParameters"; case CapabilitySubgroupVoteKHR: return "SubgroupVoteKHR"; + case CapabilityGroupNonUniformRotateKHR: return "CapabilityGroupNonUniformRotateKHR"; case CapabilityStorageUniformBufferBlock16: return "StorageUniformBufferBlock16"; case CapabilityStorageUniform16: return "StorageUniform16"; @@ -1031,11 +1038,15 @@ const char* CapabilityString(int info) case CapabilityFragmentShadingRateKHR: return "FragmentShadingRateKHR"; case CapabilityDemoteToHelperInvocationEXT: return "DemoteToHelperInvocationEXT"; + case CapabilityAtomicFloat16VectorNV: return "AtomicFloat16VectorNV"; case CapabilityShaderClockKHR: return "ShaderClockKHR"; + case CapabilityQuadControlKHR: return "QuadControlKHR"; case CapabilityInt64ImageEXT: return "Int64ImageEXT"; case CapabilityIntegerFunctions2INTEL: return "CapabilityIntegerFunctions2INTEL"; + case CapabilityExpectAssumeKHR: return "ExpectAssumeKHR"; + case CapabilityAtomicFloat16AddEXT: return "AtomicFloat16AddEXT"; case CapabilityAtomicFloat32AddEXT: return "AtomicFloat32AddEXT"; case CapabilityAtomicFloat64AddEXT: return "AtomicFloat64AddEXT"; @@ -1053,6 +1064,7 @@ const char* CapabilityString(int info) case CapabilityTextureSampleWeightedQCOM: return "TextureSampleWeightedQCOM"; case CapabilityTextureBoxFilterQCOM: return "TextureBoxFilterQCOM"; case CapabilityTextureBlockMatchQCOM: return "TextureBlockMatchQCOM"; + case CapabilityTextureBlockMatch2QCOM: return "TextureBlockMatch2QCOM"; default: return "Bad"; } @@ -1432,10 +1444,16 @@ const char* OpcodeString(int op) case 4430: return "OpSubgroupAllEqualKHR"; case 4432: return "OpSubgroupReadInvocationKHR"; + case OpGroupNonUniformQuadAllKHR: return "OpGroupNonUniformQuadAllKHR"; + case OpGroupNonUniformQuadAnyKHR: return "OpGroupNonUniformQuadAnyKHR"; + case OpAtomicFAddEXT: return "OpAtomicFAddEXT"; case OpAtomicFMinEXT: return "OpAtomicFMinEXT"; case OpAtomicFMaxEXT: return "OpAtomicFMaxEXT"; + case OpAssumeTrueKHR: return "OpAssumeTrueKHR"; + case OpExpectKHR: return "OpExpectKHR"; + case 5000: return "OpGroupIAddNonUniformAMD"; case 5001: return "OpGroupFAddNonUniformAMD"; case 5002: return "OpGroupFMinNonUniformAMD"; @@ -1472,6 +1490,8 @@ const char* OpcodeString(int op) case OpEmitMeshTasksEXT: return "OpEmitMeshTasksEXT"; case OpSetMeshOutputsEXT: return "OpSetMeshOutputsEXT"; + case OpGroupNonUniformRotateKHR: return "OpGroupNonUniformRotateKHR"; + case OpTypeRayQueryKHR: return "OpTypeRayQueryKHR"; case OpRayQueryInitializeKHR: return "OpRayQueryInitializeKHR"; case OpRayQueryTerminateKHR: return "OpRayQueryTerminateKHR"; @@ -1559,6 +1579,10 @@ const char* OpcodeString(int op) case OpImageBoxFilterQCOM: return "OpImageBoxFilterQCOM"; case OpImageBlockMatchSADQCOM: return "OpImageBlockMatchSADQCOM"; case OpImageBlockMatchSSDQCOM: return "OpImageBlockMatchSSDQCOM"; + case OpImageBlockMatchWindowSSDQCOM: return "OpImageBlockMatchWindowSSDQCOM"; + case OpImageBlockMatchWindowSADQCOM: return "OpImageBlockMatchWindowSADQCOM"; + case OpImageBlockMatchGatherSSDQCOM: return "OpImageBlockMatchGatherSSDQCOM"; + case OpImageBlockMatchGatherSADQCOM: return "OpImageBlockMatchGatherSADQCOM"; default: return "Bad"; @@ -1678,7 +1702,7 @@ void Parameterize() InstructionDesc[OpCooperativeMatrixStoreKHR].setResultAndType(false, false); InstructionDesc[OpBeginInvocationInterlockEXT].setResultAndType(false, false); InstructionDesc[OpEndInvocationInterlockEXT].setResultAndType(false, false); - + InstructionDesc[OpAssumeTrueKHR].setResultAndType(false, false); // Specific additional context-dependent operands ExecutionModeOperands[ExecutionModeInvocations].push(OperandLiteralNumber, "'Number of <<Invocation,invocations>>'"); @@ -2457,6 +2481,11 @@ void Parameterize() InstructionDesc[OpAtomicFAddEXT].operands.push(OperandMemorySemantics, "'Semantics'"); InstructionDesc[OpAtomicFAddEXT].operands.push(OperandId, "'Value'"); + InstructionDesc[OpAssumeTrueKHR].operands.push(OperandId, "'Condition'"); + + InstructionDesc[OpExpectKHR].operands.push(OperandId, "'Value'"); + InstructionDesc[OpExpectKHR].operands.push(OperandId, "'ExpectedValue'"); + InstructionDesc[OpAtomicISub].operands.push(OperandId, "'Pointer'"); InstructionDesc[OpAtomicISub].operands.push(OperandScope, "'Scope'"); InstructionDesc[OpAtomicISub].operands.push(OperandMemorySemantics, "'Semantics'"); @@ -2885,6 +2914,11 @@ void Parameterize() InstructionDesc[OpSubgroupAllEqualKHR].operands.push(OperandScope, "'Execution'"); InstructionDesc[OpSubgroupAllEqualKHR].operands.push(OperandId, "'Predicate'"); + InstructionDesc[OpGroupNonUniformRotateKHR].operands.push(OperandScope, "'Execution'"); + InstructionDesc[OpGroupNonUniformRotateKHR].operands.push(OperandId, "'X'"); + InstructionDesc[OpGroupNonUniformRotateKHR].operands.push(OperandId, "'Delta'"); + InstructionDesc[OpGroupNonUniformRotateKHR].operands.push(OperandId, "'ClusterSize'", true); + InstructionDesc[OpSubgroupReadInvocationKHR].operands.push(OperandId, "'Value'"); InstructionDesc[OpSubgroupReadInvocationKHR].operands.push(OperandId, "'Index'"); @@ -2931,6 +2965,8 @@ void Parameterize() InstructionDesc[OpGroupNonUniformPartitionNV].operands.push(OperandId, "X"); + InstructionDesc[OpGroupNonUniformQuadAllKHR].operands.push(OperandId, "'Predicate'"); + InstructionDesc[OpGroupNonUniformQuadAnyKHR].operands.push(OperandId, "'Predicate'"); InstructionDesc[OpTypeAccelerationStructureKHR].setResultAndType(true, false); InstructionDesc[OpTraceNV].operands.push(OperandId, "'Acceleration Structure'"); @@ -3403,6 +3439,38 @@ void Parameterize() InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandId, "'block size'"); InstructionDesc[OpImageBlockMatchSSDQCOM].operands.push(OperandImageOperands, "", true); InstructionDesc[OpImageBlockMatchSSDQCOM].setResultAndType(true, true); + + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandId, "'target texture'"); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandId, "'target coordinates'"); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandId, "'reference texture'"); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandId, "'reference coordinates'"); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandId, "'block size'"); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].operands.push(OperandImageOperands, "", true); + InstructionDesc[OpImageBlockMatchWindowSSDQCOM].setResultAndType(true, true); + + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandId, "'target texture'"); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandId, "'target coordinates'"); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandId, "'reference texture'"); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandId, "'reference coordinates'"); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandId, "'block size'"); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].operands.push(OperandImageOperands, "", true); + InstructionDesc[OpImageBlockMatchWindowSADQCOM].setResultAndType(true, true); + + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandId, "'target texture'"); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandId, "'target coordinates'"); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandId, "'reference texture'"); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandId, "'reference coordinates'"); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandId, "'block size'"); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].operands.push(OperandImageOperands, "", true); + InstructionDesc[OpImageBlockMatchGatherSSDQCOM].setResultAndType(true, true); + + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'target texture'"); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'target coordinates'"); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'reference texture'"); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'reference coordinates'"); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'block size'"); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandImageOperands, "", true); + InstructionDesc[OpImageBlockMatchGatherSADQCOM].setResultAndType(true, true); }); } diff --git a/thirdparty/glslang/SPIRV/spirv.hpp b/thirdparty/glslang/SPIRV/spirv.hpp index 5999aba931..6eceabe67e 100644 --- a/thirdparty/glslang/SPIRV/spirv.hpp +++ b/thirdparty/glslang/SPIRV/spirv.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 The Khronos Group Inc. +// Copyright (c) 2014-2024 The Khronos Group Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and/or associated documentation files (the "Materials"), @@ -174,6 +174,8 @@ enum ExecutionMode { ExecutionModeStencilRefUnchangedBackAMD = 5082, ExecutionModeStencilRefGreaterBackAMD = 5083, ExecutionModeStencilRefLessBackAMD = 5084, + ExecutionModeQuadDerivativesKHR = 5088, + ExecutionModeRequireFullQuadsKHR = 5089, ExecutionModeOutputLinesEXT = 5269, ExecutionModeOutputLinesNV = 5269, ExecutionModeOutputPrimitivesEXT = 5270, @@ -198,6 +200,7 @@ enum ExecutionMode { ExecutionModeNoGlobalOffsetINTEL = 5895, ExecutionModeNumSIMDWorkitemsINTEL = 5896, ExecutionModeSchedulerTargetFmaxMhzINTEL = 5903, + ExecutionModeMaximallyReconvergesKHR = 6023, ExecutionModeStreamingInterfaceINTEL = 6154, ExecutionModeNamedBarrierCountINTEL = 6417, ExecutionModeMax = 0x7fffffff, @@ -515,6 +518,7 @@ enum Decoration { DecorationNoUnsignedWrap = 4470, DecorationWeightTextureQCOM = 4487, DecorationBlockMatchTextureQCOM = 4488, + DecorationBlockMatchSamplerQCOM = 4499, DecorationExplicitInterpAMD = 4999, DecorationOverrideCoverageNV = 5248, DecorationPassthroughNV = 5250, @@ -722,8 +726,6 @@ enum BuiltIn { BuiltInHitTriangleVertexPositionsKHR = 5335, BuiltInHitMicroTriangleVertexPositionsNV = 5337, BuiltInHitMicroTriangleVertexBarycentricsNV = 5344, - BuiltInHitKindFrontFacingMicroTriangleNV = 5405, - BuiltInHitKindBackFacingMicroTriangleNV = 5406, BuiltInIncomingRayFlagsKHR = 5351, BuiltInIncomingRayFlagsNV = 5351, BuiltInRayGeometryIndexKHR = 5352, @@ -731,6 +733,8 @@ enum BuiltIn { BuiltInSMCountNV = 5375, BuiltInWarpIDNV = 5376, BuiltInSMIDNV = 5377, + BuiltInHitKindFrontFacingMicroTriangleNV = 5405, + BuiltInHitKindBackFacingMicroTriangleNV = 5406, BuiltInCullMaskKHR = 6021, BuiltInMax = 0x7fffffff, }; @@ -1032,6 +1036,7 @@ enum Capability { CapabilityTextureSampleWeightedQCOM = 4484, CapabilityTextureBoxFilterQCOM = 4485, CapabilityTextureBlockMatchQCOM = 4486, + CapabilityTextureBlockMatch2QCOM = 4498, CapabilityFloat16ImageAMD = 5008, CapabilityImageGatherBiasLodAMD = 5009, CapabilityFragmentMaskAMD = 5010, @@ -1039,6 +1044,7 @@ enum Capability { CapabilityImageReadWriteLodAMD = 5015, CapabilityInt64ImageEXT = 5016, CapabilityShaderClockKHR = 5055, + CapabilityQuadControlKHR = 5087, CapabilitySampleMaskOverrideCoverageNV = 5249, CapabilityGeometryShaderPassthroughNV = 5251, CapabilityShaderViewportIndexLayerEXT = 5254, @@ -1099,11 +1105,12 @@ enum Capability { CapabilityDemoteToHelperInvocation = 5379, CapabilityDemoteToHelperInvocationEXT = 5379, CapabilityDisplacementMicromapNV = 5380, - CapabilityRayTracingDisplacementMicromapNV = 5409, CapabilityRayTracingOpacityMicromapEXT = 5381, CapabilityShaderInvocationReorderNV = 5383, CapabilityBindlessTextureNV = 5390, CapabilityRayQueryPositionFetchKHR = 5391, + CapabilityAtomicFloat16VectorNV = 5404, + CapabilityRayTracingDisplacementMicromapNV = 5409, CapabilitySubgroupShuffleINTEL = 5568, CapabilitySubgroupBufferBlockIOINTEL = 5569, CapabilitySubgroupImageBlockIOINTEL = 5570, @@ -1693,6 +1700,10 @@ enum Op { OpImageBoxFilterQCOM = 4481, OpImageBlockMatchSSDQCOM = 4482, OpImageBlockMatchSADQCOM = 4483, + OpImageBlockMatchWindowSSDQCOM = 4500, + OpImageBlockMatchWindowSADQCOM = 4501, + OpImageBlockMatchGatherSSDQCOM = 4502, + OpImageBlockMatchGatherSADQCOM = 4503, OpGroupIAddNonUniformAMD = 5000, OpGroupFAddNonUniformAMD = 5001, OpGroupFMinNonUniformAMD = 5002, @@ -1704,6 +1715,8 @@ enum Op { OpFragmentMaskFetchAMD = 5011, OpFragmentFetchAMD = 5012, OpReadClockKHR = 5056, + OpGroupNonUniformQuadAllKHR = 5110, + OpGroupNonUniformQuadAnyKHR = 5111, OpHitObjectRecordHitMotionNV = 5249, OpHitObjectRecordHitWithIndexMotionNV = 5250, OpHitObjectRecordMissMotionNV = 5251, @@ -2416,6 +2429,10 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { case OpImageBoxFilterQCOM: *hasResult = true; *hasResultType = true; break; case OpImageBlockMatchSSDQCOM: *hasResult = true; *hasResultType = true; break; case OpImageBlockMatchSADQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchWindowSSDQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchWindowSADQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchGatherSSDQCOM: *hasResult = true; *hasResultType = true; break; + case OpImageBlockMatchGatherSADQCOM: *hasResult = true; *hasResultType = true; break; case OpGroupIAddNonUniformAMD: *hasResult = true; *hasResultType = true; break; case OpGroupFAddNonUniformAMD: *hasResult = true; *hasResultType = true; break; case OpGroupFMinNonUniformAMD: *hasResult = true; *hasResultType = true; break; @@ -2427,6 +2444,8 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { case OpFragmentMaskFetchAMD: *hasResult = true; *hasResultType = true; break; case OpFragmentFetchAMD: *hasResult = true; *hasResultType = true; break; case OpReadClockKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformQuadAllKHR: *hasResult = true; *hasResultType = true; break; + case OpGroupNonUniformQuadAnyKHR: *hasResult = true; *hasResultType = true; break; case OpHitObjectRecordHitMotionNV: *hasResult = false; *hasResultType = false; break; case OpHitObjectRecordHitWithIndexMotionNV: *hasResult = false; *hasResultType = false; break; case OpHitObjectRecordMissMotionNV: *hasResult = false; *hasResultType = false; break; diff --git a/thirdparty/glslang/SPIRV/spvIR.h b/thirdparty/glslang/SPIRV/spvIR.h index 8849f42e75..4c353cfa54 100644 --- a/thirdparty/glslang/SPIRV/spvIR.h +++ b/thirdparty/glslang/SPIRV/spvIR.h @@ -56,6 +56,7 @@ #include <memory> #include <vector> #include <set> +#include <optional> namespace spv { @@ -96,6 +97,10 @@ public: Instruction(Id resultId, Id typeId, Op opCode) : resultId(resultId), typeId(typeId), opCode(opCode), block(nullptr) { } explicit Instruction(Op opCode) : resultId(NoResult), typeId(NoType), opCode(opCode), block(nullptr) { } virtual ~Instruction() {} + void reserveOperands(size_t count) { + operands.reserve(count); + idOperand.reserve(count); + } void addIdOperand(Id id) { // ids can't be 0 assert(id); @@ -190,6 +195,12 @@ protected: // SPIR-V IR block. // +struct DebugSourceLocation { + int line; + int column; + spv::Id fileId; +}; + class Block { public: Block(Id id, Function& parent); @@ -200,6 +211,28 @@ public: Id getId() { return instructions.front()->getResultId(); } Function& getParent() const { return parent; } + // Returns true if the source location is actually updated. + // Note we still need the builder to insert the line marker instruction. This is just a tracker. + bool updateDebugSourceLocation(int line, int column, spv::Id fileId) { + if (currentSourceLoc && currentSourceLoc->line == line && currentSourceLoc->column == column && + currentSourceLoc->fileId == fileId) { + return false; + } + + currentSourceLoc = DebugSourceLocation{line, column, fileId}; + return true; + } + // Returns true if the scope is actually updated. + // Note we still need the builder to insert the debug scope instruction. This is just a tracker. + bool updateDebugScope(spv::Id scopeId) { + assert(scopeId); + if (currentDebugScope && *currentDebugScope == scopeId) { + return false; + } + + currentDebugScope = scopeId; + return true; + } void addInstruction(std::unique_ptr<Instruction> inst); void addPredecessor(Block* pred) { predecessors.push_back(pred); pred->successors.push_back(this);} void addLocalVariable(std::unique_ptr<Instruction> inst) { localVariables.push_back(std::move(inst)); } @@ -292,6 +325,12 @@ protected: std::vector<std::unique_ptr<Instruction> > localVariables; Function& parent; + // Track source location of the last source location marker instruction. + std::optional<DebugSourceLocation> currentSourceLoc; + + // Track scope of the last debug scope instruction. + std::optional<spv::Id> currentDebugScope; + // track whether this block is known to be uncreachable (not necessarily // true for all unreachable blocks, but should be set at least // for the extraneous ones introduced by the builder). @@ -363,6 +402,7 @@ public: void setDebugLineInfo(Id fileName, int line, int column) { lineInstruction = std::unique_ptr<Instruction>{new Instruction(OpLine)}; + lineInstruction->reserveOperands(3); lineInstruction->addIdOperand(fileName); lineInstruction->addImmediateOperand(line); lineInstruction->addImmediateOperand(column); @@ -486,6 +526,7 @@ __inline Function::Function(Id id, Id resultType, Id functionType, Id firstParam linkType(linkage) { // OpFunction + functionInstruction.reserveOperands(2); functionInstruction.addImmediateOperand(FunctionControlMaskNone); functionInstruction.addIdOperand(functionType); parent.mapInstruction(&functionInstruction); |