diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.h b/renderdoc/driver/shaders/spirv/spirv_editor.h index fa1dc4988..c2cabf39a 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.h +++ b/renderdoc/driver/shaders/spirv/spirv_editor.h @@ -238,6 +238,28 @@ public: return AddConstant(Operation(Op::Constant, words)); } + template + Id AddSpecConstantImmediate(T t, uint32_t specId) + { + Id typeId = DeclareType(scalar()); + rdcarray words = {typeId.value(), MakeId().value()}; + + words.resize(words.size() + sizeof(T) / 4); + + memcpy(&words[2], &t, sizeof(T)); + + rdcspv::Id ret = AddConstant(Operation(Op::SpecConstant, words)); + + words.clear(); + words.push_back(ret.value()); + words.push_back((uint32_t)rdcspv::Decoration::SpecId); + words.push_back(specId); + + AddDecoration(Operation(Op::Decorate, words)); + + return ret; + } + private: using Processor::Parse; inline void addWords(size_t offs, size_t num) { addWords(offs, (int32_t)num); } diff --git a/renderdoc/driver/vulkan/vk_shaderdebug.cpp b/renderdoc/driver/vulkan/vk_shaderdebug.cpp index 688ae6a1c..b78d3d91d 100644 --- a/renderdoc/driver/vulkan/vk_shaderdebug.cpp +++ b/renderdoc/driver/vulkan/vk_shaderdebug.cpp @@ -1039,28 +1039,17 @@ static void CreatePSInputFetcher(rdcarray &fragspv, uint32_t &structSt rdcspv::Id float4Type = editor.DeclareType(rdcspv::Vector(rdcspv::scalar(), 4)); rdcspv::Id float2Type = editor.DeclareType(rdcspv::Vector(rdcspv::scalar(), 2)); - rdcspv::Id arrayLength = editor.AddConstant(rdcspv::Operation( - rdcspv::Op::SpecConstant, {uint32Type.value(), editor.MakeId().value(), 1U})); - - editor.AddDecoration(rdcspv::OpDecorate( - arrayLength, - rdcspv::DecorationParam((uint32_t)InputSpecConstant::ArrayLength))); + rdcspv::Id arrayLength = + editor.AddSpecConstantImmediate(1U, (uint32_t)InputSpecConstant::ArrayLength); editor.SetName(arrayLength, "arrayLength"); - rdcspv::Id destX = editor.AddConstant(rdcspv::Operation( - rdcspv::Op::SpecConstant, {floatType.value(), editor.MakeId().value(), 0U})); - rdcspv::Id destY = editor.AddConstant(rdcspv::Operation( - rdcspv::Op::SpecConstant, {floatType.value(), editor.MakeId().value(), 0U})); + rdcspv::Id destX = editor.AddSpecConstantImmediate(0.0f, (uint32_t)InputSpecConstant::DestX); + rdcspv::Id destY = editor.AddSpecConstantImmediate(0.0f, (uint32_t)InputSpecConstant::DestY); editor.SetName(destX, "destX"); editor.SetName(destY, "destY"); - editor.AddDecoration(rdcspv::OpDecorate(destX, rdcspv::DecorationParam( - (uint32_t)InputSpecConstant::DestX))); - editor.AddDecoration(rdcspv::OpDecorate(destY, rdcspv::DecorationParam( - (uint32_t)InputSpecConstant::DestY))); - rdcspv::Id destXY = editor.AddConstant( rdcspv::OpSpecConstantComposite(float2Type, editor.MakeId(), {destX, destY})); @@ -1252,13 +1241,8 @@ static void CreatePSInputFetcher(rdcarray &fragspv, uint32_t &structSt // declare the address constant which we will specialise later. There is a chicken-and-egg where // this function determines how big the buffer needs to be so instead of hardcoding the address // here we let it be allocated later and specialised in. - addressConstant = editor.AddConstant(rdcspv::Operation( - rdcspv::Op::SpecConstant, - {editor.DeclareType(rdcspv::scalar()).value(), editor.MakeId().value(), 0U, 0U})); - - editor.AddDecoration(rdcspv::OpDecorate( - addressConstant, - rdcspv::DecorationParam((uint32_t)InputSpecConstant::Address))); + addressConstant = + editor.AddSpecConstantImmediate(0ULL, (uint32_t)InputSpecConstant::Address); editor.SetName(addressConstant, "__rd_bufAddress");