diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.h b/renderdoc/driver/shaders/spirv/spirv_editor.h index a11bd04a9..2aec15d0b 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.h +++ b/renderdoc/driver/shaders/spirv/spirv_editor.h @@ -34,6 +34,57 @@ namespace rdcspv { class Editor; +struct IdOrWord +{ + constexpr inline IdOrWord() : value(0) {} + constexpr inline IdOrWord(uint32_t val) : value(val) {} + inline IdOrWord(Id id) : value(id.value()) {} + inline operator uint32_t() const { return value; } + constexpr inline bool operator==(const IdOrWord o) const { return value == o.value; } + constexpr inline bool operator!=(const IdOrWord o) const { return value != o.value; } + constexpr inline bool operator<(const IdOrWord o) const { return value < o.value; } +private: + uint32_t value; +}; + +// helper in the style of the auto-generated one for GLSL ext insts +struct OpGLSL450 +{ + OpGLSL450(IdResultType resultType, IdResult result, Id glsl450, rdcspv::GLSLstd450 inst, + const rdcarray ¶ms) + : op(OpCode), wordCount(MinWordSize + (uint16_t)params.size()) + { + this->resultType = resultType; + this->result = result; + this->glsl450 = glsl450; + this->inst = inst; + this->params.resize(params.size()); + for(size_t i = 0; i < params.size(); i++) + this->params[i] = params[i]; + } + + operator Operation() const + { + rdcarray words; + words.push_back(resultType.value()); + words.push_back(result.value()); + words.push_back(glsl450.value()); + words.push_back((uint32_t)inst); + words.append(params); + return Operation(OpCode, words); + } + + static constexpr Op OpCode = Op::ExtInst; + static constexpr uint16_t MinWordSize = 4U; + Op op; + uint16_t wordCount; + IdResultType resultType; + IdResult result; + Id glsl450; + rdcspv::GLSLstd450 inst; + rdcarray params; +}; + struct OperationList : public rdcarray { // add an operation and return its result id diff --git a/renderdoc/driver/vulkan/vk_bindless_feedback.cpp b/renderdoc/driver/vulkan/vk_bindless_feedback.cpp index 9ee1afd0e..a2f61d2af 100644 --- a/renderdoc/driver/vulkan/vk_bindless_feedback.cpp +++ b/renderdoc/driver/vulkan/vk_bindless_feedback.cpp @@ -463,12 +463,8 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName, rdcspv::Id clampedtype = editor.DeclareType(rdcspv::Scalar(rdcspv::Op::TypeInt, targetIndexWidth, false)); index = editor.AddOperation( - it, rdcspv::Operation( - rdcspv::Op::ExtInst, - { - clampedtype.value(), editor.MakeId().value(), glsl450.value(), - (uint32_t)rdcspv::GLSLstd450::UMin, index.value(), maxSlotID.value(), - })); + it, rdcspv::OpGLSL450(clampedtype, editor.MakeId(), glsl450, + rdcspv::GLSLstd450::UMin, {index, maxSlotID})); it++; } diff --git a/renderdoc/driver/vulkan/vk_postvs.cpp b/renderdoc/driver/vulkan/vk_postvs.cpp index 20d64d220..27e1ef7d3 100644 --- a/renderdoc/driver/vulkan/vk_postvs.cpp +++ b/renderdoc/driver/vulkan/vk_postvs.cpp @@ -1055,12 +1055,9 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV editor.SetName(packed, StringFormat::Fmt("packed_%c", swizzle[c])); // double comp = PackDouble2x32(packed); - comps[c] = ops.add(rdcspv::Operation( - rdcspv::Op::ExtInst, - { - editor.DeclareType(rdcspv::scalar()).value(), editor.MakeId().value(), - glsl450.value(), (uint32_t)rdcspv::GLSLstd450::PackDouble2x32, packed.value(), - })); + comps[c] = ops.add(rdcspv::OpGLSL450(editor.DeclareType(rdcspv::scalar()), + editor.MakeId(), glsl450, + rdcspv::GLSLstd450::PackDouble2x32, {packed})); } // if there's only one component it's ready, otherwise construct a vector diff --git a/renderdoc/driver/vulkan/vk_shaderdebug.cpp b/renderdoc/driver/vulkan/vk_shaderdebug.cpp index 28a070bff..648eabd16 100644 --- a/renderdoc/driver/vulkan/vk_shaderdebug.cpp +++ b/renderdoc/driver/vulkan/vk_shaderdebug.cpp @@ -623,11 +623,8 @@ static void CreatePSInputFetcher(rdcarray &fragspv, uint32_t &structSt ops.add(rdcspv::OpFSub(float2Type, editor.MakeId(), fragXY, destXY)); // abs() - rdcspv::Id fragXYAbs = ops.add(rdcspv::Operation( - rdcspv::Op::ExtInst, { - float2Type.value(), editor.MakeId().value(), glsl450.value(), - (uint32_t)rdcspv::GLSLstd450::FAbs, fragXYRelative.value(), - })); + rdcspv::Id fragXYAbs = ops.add(rdcspv::OpGLSL450(float2Type, editor.MakeId(), glsl450, + rdcspv::GLSLstd450::FAbs, {fragXYRelative})); rdcspv::Id half = editor.AddConstantImmediate(0.5f); rdcspv::Id threshold =