diff --git a/common/common.hpp b/common/common.hpp index f2a3416..ee9a62f 100644 --- a/common/common.hpp +++ b/common/common.hpp @@ -17,7 +17,7 @@ #include #include -#define VKSP_EXTINST_STR "NonSemantic.VkspReflection.3" +#define VKSP_EXTINST_STR "NonSemantic.VkspReflection.4" #define PRINT_IMPL(file, message, ...) \ do { \ diff --git a/common/spirv-extract.hpp b/common/spirv-extract.hpp index d16d397..420c9fa 100644 --- a/common/spirv-extract.hpp +++ b/common/spirv-extract.hpp @@ -166,6 +166,10 @@ class ExtractVkspReflectInfoPass : public spvtools::opt::Pass { } } + spvtools::opt::Instruction *GetInstruction(uint32_t id) { return id_to_inst_[id]; } + const char *GetString(uint32_t id) { return strdup(GetInstruction(id)->GetOperand(1).AsString().c_str()); } + uint32_t GetUInt(uint32_t id) { return (uint32_t)GetInstruction(id)->GetOperand(2).words[0]; } + void ParseInstruction(spvtools::opt::Instruction *inst, uint32_t ext_inst_id, std::map &id_to_descriptor_set, std::map &id_to_binding, int32_t &descriptor_set_0_max_binding, std::vector &start_counters, @@ -192,118 +196,125 @@ class ExtractVkspReflectInfoPass : public spvtools::opt::Pass { } } return; + } else if (inst->opcode() == spv::Op::OpString) { + id_to_inst_[inst->GetOperand(0).AsId()] = inst; + return; + } else if (inst->opcode() == spv::Op::OpConstant) { + id_to_inst_[inst->GetOperand(1).AsId()] = inst; + return; } else if (inst->opcode() != spv::Op::OpExtInst || ext_inst_id != inst->GetOperand(op_id++).AsId()) { return; } + auto *cst_mgr = context()->get_constant_mgr(); auto vksp_inst = inst->GetOperand(op_id++).words[0]; switch (vksp_inst) { case NonSemanticVkspReflectionConfiguration: - config_->enabledExtensionNames = strdup(inst->GetOperand(op_id++).AsString().c_str()); - config_->specializationInfoDataSize = inst->GetOperand(op_id++).words[0]; - config_->specializationInfoData = strdup(inst->GetOperand(op_id++).AsString().c_str()); - config_->shaderName = strdup(inst->GetOperand(op_id++).AsString().c_str()); - config_->entryPoint = strdup(inst->GetOperand(op_id++).AsString().c_str()); - config_->groupCountX = inst->GetOperand(op_id++).words[0]; - config_->groupCountY = inst->GetOperand(op_id++).words[0]; - config_->groupCountZ = inst->GetOperand(op_id++).words[0]; - config_->dispatchId = inst->GetOperand(op_id++).words[0]; + config_->enabledExtensionNames = GetString(inst->GetOperand(op_id++).AsId()); + config_->specializationInfoDataSize = GetUInt(inst->GetOperand(op_id++).AsId()); + config_->specializationInfoData = GetString(inst->GetOperand(op_id++).AsId()); + config_->shaderName = GetString(inst->GetOperand(op_id++).AsId()); + config_->entryPoint = GetString(inst->GetOperand(op_id++).AsId()); + config_->groupCountX = GetUInt(inst->GetOperand(op_id++).AsId()); + config_->groupCountY = GetUInt(inst->GetOperand(op_id++).AsId()); + config_->groupCountZ = GetUInt(inst->GetOperand(op_id++).AsId()); + config_->dispatchId = GetUInt(inst->GetOperand(op_id++).AsId()); break; case NonSemanticVkspReflectionDescriptorSetBuffer: { vksp_descriptor_set ds; - ds.ds = inst->GetOperand(op_id++).words[0]; - ds.binding = inst->GetOperand(op_id++).words[0]; - ds.type = inst->GetOperand(op_id++).words[0]; - ds.buffer.flags = inst->GetOperand(op_id++).words[0]; - ds.buffer.queueFamilyIndexCount = inst->GetOperand(op_id++).words[0]; - ds.buffer.sharingMode = inst->GetOperand(op_id++).words[0]; - ds.buffer.size = inst->GetOperand(op_id++).words[0]; - ds.buffer.usage = inst->GetOperand(op_id++).words[0]; - ds.buffer.range = inst->GetOperand(op_id++).words[0]; - ds.buffer.offset = inst->GetOperand(op_id++).words[0]; - ds.buffer.memorySize = inst->GetOperand(op_id++).words[0]; - ds.buffer.memoryType = inst->GetOperand(op_id++).words[0]; - ds.buffer.bindOffset = inst->GetOperand(op_id++).words[0]; - ds.buffer.viewFlags = inst->GetOperand(op_id++).words[0]; - ds.buffer.viewFormat = inst->GetOperand(op_id++).words[0]; + ds.ds = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.binding = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.type = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.flags = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.queueFamilyIndexCount = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.sharingMode = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.size = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.usage = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.range = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.offset = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.memorySize = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.memoryType = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.bindOffset = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.viewFlags = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.buffer.viewFormat = GetUInt(inst->GetOperand(op_id++).AsId()); ds_->push_back(ds); descriptor_set_0_max_binding = UpdateMaxBinding(ds.ds, ds.binding, descriptor_set_0_max_binding); } break; case NonSemanticVkspReflectionDescriptorSetImage: { vksp_descriptor_set ds; - ds.ds = inst->GetOperand(op_id++).words[0]; - ds.binding = inst->GetOperand(op_id++).words[0]; - ds.type = inst->GetOperand(op_id++).words[0]; - ds.image.imageLayout = inst->GetOperand(op_id++).words[0]; - ds.image.imageFlags = inst->GetOperand(op_id++).words[0]; - ds.image.imageType = inst->GetOperand(op_id++).words[0]; - ds.image.format = inst->GetOperand(op_id++).words[0]; - ds.image.width = inst->GetOperand(op_id++).words[0]; - ds.image.height = inst->GetOperand(op_id++).words[0]; - ds.image.depth = inst->GetOperand(op_id++).words[0]; - ds.image.mipLevels = inst->GetOperand(op_id++).words[0]; - ds.image.arrayLayers = inst->GetOperand(op_id++).words[0]; - ds.image.samples = inst->GetOperand(op_id++).words[0]; - ds.image.tiling = inst->GetOperand(op_id++).words[0]; - ds.image.usage = inst->GetOperand(op_id++).words[0]; - ds.image.sharingMode = inst->GetOperand(op_id++).words[0]; - ds.image.queueFamilyIndexCount = inst->GetOperand(op_id++).words[0]; - ds.image.initialLayout = inst->GetOperand(op_id++).words[0]; - ds.image.aspectMask = inst->GetOperand(op_id++).words[0]; - ds.image.baseMipLevel = inst->GetOperand(op_id++).words[0]; - ds.image.levelCount = inst->GetOperand(op_id++).words[0]; - ds.image.baseArrayLayer = inst->GetOperand(op_id++).words[0]; - ds.image.layerCount = inst->GetOperand(op_id++).words[0]; - ds.image.viewFlags = inst->GetOperand(op_id++).words[0]; - ds.image.viewType = inst->GetOperand(op_id++).words[0]; - ds.image.viewFormat = inst->GetOperand(op_id++).words[0]; - ds.image.component_a = inst->GetOperand(op_id++).words[0]; - ds.image.component_b = inst->GetOperand(op_id++).words[0]; - ds.image.component_g = inst->GetOperand(op_id++).words[0]; - ds.image.component_r = inst->GetOperand(op_id++).words[0]; - ds.image.memorySize = inst->GetOperand(op_id++).words[0]; - ds.image.memoryType = inst->GetOperand(op_id++).words[0]; - ds.image.bindOffset = inst->GetOperand(op_id++).words[0]; + ds.ds = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.binding = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.type = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.imageLayout = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.imageFlags = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.imageType = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.format = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.width = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.height = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.depth = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.mipLevels = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.arrayLayers = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.samples = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.tiling = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.usage = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.sharingMode = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.queueFamilyIndexCount = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.initialLayout = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.aspectMask = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.baseMipLevel = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.levelCount = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.baseArrayLayer = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.layerCount = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.viewFlags = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.viewType = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.viewFormat = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.component_a = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.component_b = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.component_g = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.component_r = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.memorySize = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.memoryType = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.image.bindOffset = GetUInt(inst->GetOperand(op_id++).AsId()); ds_->push_back(ds); descriptor_set_0_max_binding = UpdateMaxBinding(ds.ds, ds.binding, descriptor_set_0_max_binding); } break; case NonSemanticVkspReflectionDescriptorSetSampler: { vksp_descriptor_set ds; - ds.ds = inst->GetOperand(op_id++).words[0]; - ds.binding = inst->GetOperand(op_id++).words[0]; - ds.type = inst->GetOperand(op_id++).words[0]; - ds.sampler.flags = inst->GetOperand(op_id++).words[0]; - ds.sampler.magFilter = inst->GetOperand(op_id++).words[0]; - ds.sampler.minFilter = inst->GetOperand(op_id++).words[0]; - ds.sampler.mipmapMode = inst->GetOperand(op_id++).words[0]; - ds.sampler.addressModeU = inst->GetOperand(op_id++).words[0]; - ds.sampler.addressModeV = inst->GetOperand(op_id++).words[0]; - ds.sampler.addressModeW = inst->GetOperand(op_id++).words[0]; - ds.sampler.uMipLodBias = inst->GetOperand(op_id++).words[0]; - ds.sampler.anisotropyEnable = inst->GetOperand(op_id++).words[0]; - ds.sampler.uMaxAnisotropy = inst->GetOperand(op_id++).words[0]; - ds.sampler.compareEnable = inst->GetOperand(op_id++).words[0]; - ds.sampler.compareOp = inst->GetOperand(op_id++).words[0]; - ds.sampler.uMinLod = inst->GetOperand(op_id++).words[0]; - ds.sampler.uMaxLod = inst->GetOperand(op_id++).words[0]; - ds.sampler.borderColor = inst->GetOperand(op_id++).words[0]; - ds.sampler.unnormalizedCoordinates = inst->GetOperand(op_id++).words[0]; + ds.ds = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.binding = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.type = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.flags = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.magFilter = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.minFilter = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.mipmapMode = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.addressModeU = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.addressModeV = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.addressModeW = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.uMipLodBias = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.anisotropyEnable = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.uMaxAnisotropy = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.compareEnable = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.compareOp = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.uMinLod = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.uMaxLod = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.borderColor = GetUInt(inst->GetOperand(op_id++).AsId()); + ds.sampler.unnormalizedCoordinates = GetUInt(inst->GetOperand(op_id++).AsId()); ds_->push_back(ds); descriptor_set_0_max_binding = UpdateMaxBinding(ds.ds, ds.binding, descriptor_set_0_max_binding); } break; case NonSemanticVkspReflectionPushConstants: vksp_push_constant pc; - pc.offset = inst->GetOperand(op_id++).words[0]; - pc.size = inst->GetOperand(op_id++).words[0]; - pc.pValues = strdup(inst->GetOperand(op_id++).AsString().c_str()); - pc.stageFlags = inst->GetOperand(op_id++).words[0]; + pc.offset = GetUInt(inst->GetOperand(op_id++).AsId()); + pc.size = GetUInt(inst->GetOperand(op_id++).AsId()); + pc.pValues = GetString(inst->GetOperand(op_id++).AsId()); + pc.stageFlags = GetUInt(inst->GetOperand(op_id++).AsId()); pc_->push_back(pc); break; case NonSemanticVkspReflectionSpecializationMapEntry: vksp_specialization_map_entry me; - me.constantID = inst->GetOperand(op_id++).words[0]; - me.offset = inst->GetOperand(op_id++).words[0]; - me.size = inst->GetOperand(op_id++).words[0]; + me.constantID = GetUInt(inst->GetOperand(op_id++).AsId()); + me.offset = GetUInt(inst->GetOperand(op_id++).AsId()); + me.size = GetUInt(inst->GetOperand(op_id++).AsId()); me_->push_back(me); break; case NonSemanticVkspReflectionStartCounter: @@ -492,7 +503,7 @@ class ExtractVkspReflectInfoPass : public spvtools::opt::Pass { uint32_t next_counter_id = 2; for (auto *inst : start_counters) { - const char *counter_name = strdup(inst->GetOperand(4).AsString().c_str()); + const char *counter_name = GetString(inst->GetOperand(4).AsId()); auto read_clock_id = context()->TakeNextId(); auto read_clock_inst = new spvtools::opt::Instruction(context(), spv::Op::OpReadClockKHR, u64_ty_id, @@ -551,6 +562,7 @@ class ExtractVkspReflectInfoPass : public spvtools::opt::Pass { std::vector *ds_; std::vector *me_; std::vector *counters_; + std::map id_to_inst_; vksp_configuration *config_; bool disableCounters_; }; diff --git a/extractor/spirv.cpp b/extractor/spirv.cpp index ddf47e0..44c9a7b 100644 --- a/extractor/spirv.cpp +++ b/extractor/spirv.cpp @@ -26,6 +26,17 @@ namespace vksp { class InsertVkspReflectInfoPass : public spvtools::opt::Pass { +private: + uint32_t GetStringId(const char *string) + { + auto string_vector = spvtools::utils::MakeVector(string); + uint32_t id = context()->TakeNextId(); + auto inst = new spvtools::opt::Instruction( + context(), spv::Op::OpString, 0u, id, { { SPV_OPERAND_TYPE_LITERAL_STRING, string_vector } }); + context()->module()->AddGlobalValue(std::unique_ptr(inst)); + return id; + } + public: InsertVkspReflectInfoPass(std::vector *pc, std::vector *ds, std::vector *me, vksp_configuration *config) @@ -47,39 +58,35 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { module->AddExtInstImport(std::unique_ptr(ExtInst)); uint32_t void_ty_id = context()->get_type_mgr()->GetVoidTypeId(); + auto *cst_mgr = context()->get_constant_mgr(); - std::vector enabledExtensions = spvtools::utils::MakeVector(config_->enabledExtensionNames); - std::vector pData = spvtools::utils::MakeVector(config_->specializationInfoData); - std::vector shaderName = spvtools::utils::MakeVector(config_->shaderName); - std::vector entryPoint = spvtools::utils::MakeVector(config_->entryPoint); auto ConfigId = context()->TakeNextId(); auto ConfigInst = new spvtools::opt::Instruction(context(), spv::Op::OpExtInst, void_ty_id, ConfigId, { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionConfiguration } }, - { SPV_OPERAND_TYPE_LITERAL_STRING, enabledExtensions }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { config_->specializationInfoDataSize } }, - { SPV_OPERAND_TYPE_LITERAL_STRING, pData }, - { SPV_OPERAND_TYPE_LITERAL_STRING, shaderName }, - { SPV_OPERAND_TYPE_LITERAL_STRING, entryPoint }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { config_->groupCountX } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { config_->groupCountY } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { config_->groupCountZ } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { config_->dispatchId } }, + { SPV_OPERAND_TYPE_ID, { GetStringId(config_->enabledExtensionNames) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(config_->specializationInfoDataSize) } }, + { SPV_OPERAND_TYPE_ID, { GetStringId(config_->specializationInfoData) } }, + { SPV_OPERAND_TYPE_ID, { GetStringId(config_->shaderName) } }, + { SPV_OPERAND_TYPE_ID, { GetStringId(config_->entryPoint) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(config_->groupCountX) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(config_->groupCountY) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(config_->groupCountZ) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(config_->dispatchId) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(ConfigInst)); for (auto &pc : *pc_) { - std::vector pValues = spvtools::utils::MakeVector(pc.pValues); auto PcInstId = context()->TakeNextId(); auto PcInst = new spvtools::opt::Instruction(context(), spv::Op::OpExtInst, void_ty_id, PcInstId, { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionPushConstants } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { pc.offset } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { pc.size } }, - { SPV_OPERAND_TYPE_LITERAL_STRING, pValues }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { pc.stageFlags } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(pc.offset) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(pc.size) } }, + { SPV_OPERAND_TYPE_ID, { GetStringId(pc.pValues) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(pc.stageFlags) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(PcInst)); } @@ -96,21 +103,21 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionDescriptorSetBuffer } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.ds } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.binding } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.type } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.flags } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.queueFamilyIndexCount } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.sharingMode } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.size } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.usage } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.range } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.offset } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.memorySize } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.memoryType } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.bindOffset } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.viewFlags } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.buffer.viewFormat } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.ds) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.binding) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.type) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.flags) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.queueFamilyIndexCount) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.sharingMode) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.size) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.usage) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.range) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.offset) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.memorySize) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.memoryType) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.bindOffset) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.viewFlags) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.buffer.viewFormat) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(DstInst)); } break; @@ -122,39 +129,39 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionDescriptorSetImage } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.ds } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.binding } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.type } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.imageLayout } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.imageFlags } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.imageType } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.format } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.width } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.height } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.depth } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.mipLevels } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.arrayLayers } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.samples } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.tiling } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.usage } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.sharingMode } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.queueFamilyIndexCount } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.initialLayout } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.aspectMask } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.baseMipLevel } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.levelCount } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.baseArrayLayer } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.layerCount } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.viewFlags } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.viewType } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.viewFormat } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.component_a } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.component_b } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.component_g } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.component_r } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.memorySize } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.memoryType } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.image.bindOffset } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.ds) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.binding) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.type) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.imageLayout) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.imageFlags) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.imageType) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.format) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.width) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.height) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.depth) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.mipLevels) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.arrayLayers) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.samples) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.tiling) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.usage) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.sharingMode) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.queueFamilyIndexCount) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.initialLayout) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.aspectMask) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.baseMipLevel) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.levelCount) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.baseArrayLayer) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.layerCount) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.viewFlags) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.viewType) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.viewFormat) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.component_a) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.component_b) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.component_g) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.component_r) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.memorySize) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.memoryType) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.image.bindOffset) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(DstInst)); } break; @@ -165,25 +172,25 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionDescriptorSetSampler } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.ds } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.binding } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.type } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.flags } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.magFilter } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.minFilter } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.mipmapMode } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.addressModeU } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.addressModeV } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.addressModeW } }, - { SPV_OPERAND_TYPE_LITERAL_FLOAT, { ds.sampler.uMipLodBias } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.anisotropyEnable } }, - { SPV_OPERAND_TYPE_LITERAL_FLOAT, { ds.sampler.uMaxAnisotropy } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.compareEnable } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.compareOp } }, - { SPV_OPERAND_TYPE_LITERAL_FLOAT, { ds.sampler.uMinLod } }, - { SPV_OPERAND_TYPE_LITERAL_FLOAT, { ds.sampler.uMaxLod } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.borderColor } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { ds.sampler.unnormalizedCoordinates } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.ds) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.binding) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.type) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.flags) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.magFilter) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.minFilter) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.mipmapMode) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.addressModeU) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.addressModeV) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.addressModeW) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetFloatConstId(ds.sampler.uMipLodBias) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.anisotropyEnable) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetFloatConstId(ds.sampler.uMaxAnisotropy) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.compareEnable) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.compareOp) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetFloatConstId(ds.sampler.uMinLod) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetFloatConstId(ds.sampler.uMaxLod) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.borderColor) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(ds.sampler.unnormalizedCoordinates) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(DstInst)); } break; @@ -199,9 +206,9 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { { SPV_OPERAND_TYPE_ID, { ExtInstId } }, { SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER, { NonSemanticVkspReflectionSpecializationMapEntry } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { me.constantID } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { me.offset } }, - { SPV_OPERAND_TYPE_LITERAL_INTEGER, { me.size } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(me.constantID) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(me.offset) } }, + { SPV_OPERAND_TYPE_ID, { cst_mgr->GetUIntConstId(me.size) } }, }); module->AddExtInstDebugInfo(std::unique_ptr(MapEntryInst)); } @@ -215,7 +222,6 @@ class InsertVkspReflectInfoPass : public spvtools::opt::Pass { std::vector *me_; vksp_configuration *config_; }; - } bool text_to_binary(spv_context context, std::string *shader, spv_binary &binary) diff --git a/tests/example-counter.spvasm b/tests/example-counter.spvasm index 28b35c0..ba534d4 100644 --- a/tests/example-counter.spvasm +++ b/tests/example-counter.spvasm @@ -5,7 +5,7 @@ ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "NonSemantic.ClspvReflection.5" - %49 = OpExtInstImport "NonSemantic.VkspReflection.2" + %49 = OpExtInstImport "NonSemantic.VkspReflection.4" OpMemoryModel Logical GLSL450 OpEntryPoint GLCompute %2 "test_simple" %gl_GlobalInvocationID %4 %5 %6 @@ -61,13 +61,26 @@ %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input %4 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize %5 = OpVariable %_ptr_StorageBuffer__struct_14 StorageBuffer - %50 = OpExtInst %void %49 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1 0 - %51 = OpExtInst %void %49 PushConstants 16 12 "000000000000000000000000" 32 - %52 = OpExtInst %void %49 PushConstants 0 12 "000000000000000000000000" 32 - %53 = OpExtInst %void %49 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0 0 0 - %54 = OpExtInst %void %49 SpecializationMapEntry 0 0 4 - %55 = OpExtInst %void %49 SpecializationMapEntry 1 4 4 - %56 = OpExtInst %void %49 SpecializationMapEntry 2 8 4 + %counterName = OpString "my_section" + %144 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" + %145 = OpString "020000000100000001000000" + %146 = OpString "vksp_s0" + %147 = OpString "test_simple" + %uint_128 = OpConstant %uint 128 + %uint_28 = OpConstant %uint 28 + %151 = OpString "00000000000000000000000000000000000000000000000000000000" + %uint_32 = OpConstant %uint 32 + %uint_7 = OpConstant %uint 7 + %uint_1024 = OpConstant %uint 1024 + %uint_63 = OpConstant %uint 63 + %uint_4 = OpConstant %uint 4 + %uint_8 = OpConstant %uint 8 + %143 = OpExtInst %void %49 Configuration %144 %uint_12 %145 %146 %147 %uint_128 %uint_1 %uint_1 %uint_0 + %149 = OpExtInst %void %49 PushConstants %uint_0 %uint_28 %151 %uint_32 + %153 = OpExtInst %void %49 DescriptorSetBuffer %uint_0 %uint_0 %uint_7 %uint_0 %uint_0 %uint_0 %uint_1024 %uint_63 %uint_1024 %uint_0 %uint_1024 %uint_0 %uint_0 %uint_0 %uint_0 + %157 = OpExtInst %void %49 SpecializationMapEntry %uint_0 %uint_0 %uint_4 + %159 = OpExtInst %void %49 SpecializationMapEntry %uint_1 %uint_4 %uint_4 + %160 = OpExtInst %void %49 SpecializationMapEntry %uint_2 %uint_8 %uint_4 ; Function 2 %2 = OpFunction %void None %25 @@ -76,7 +89,7 @@ %38 = OpLoad %uint %37 %39 = OpAccessChain %_ptr_PushConstant_uint %6 %uint_1 %uint_0 %40 = OpLoad %uint %39 - %counter = OpExtInst %void %49 StartCounter "my_section" + %counter = OpExtInst %void %49 StartCounter %counterName %41 = OpIAdd %uint %40 %38 %unused = OpExtInst %void %49 StopCounter %counter %42 = OpAccessChain %_ptr_StorageBuffer_uint %5 %uint_0 %41 diff --git a/tests/example-expectation.spvasm b/tests/example-expectation.spvasm index cb7b7dc..eba39c9 100644 --- a/tests/example-expectation.spvasm +++ b/tests/example-expectation.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.6 ; Generator: Khronos SPIR-V Tools Assembler; 0 -; Bound: 66 +; Bound: 84 ; Schema: 0 OpCapability Shader OpCapability ShaderClockKHR @@ -9,7 +9,7 @@ OpCapability Int64Atomics OpExtension "SPV_KHR_shader_clock" OpExtension "SPV_KHR_storage_buffer_storage_class" - %58 = OpExtInstImport "NonSemantic.VkspReflection.2" + %70 = OpExtInstImport "NonSemantic.VkspReflection.4" OpMemoryModel Logical GLSL450 OpEntryPoint GLCompute %1 "test_simple" %gl_GlobalInvocationID %3 %4 %5 %6 @@ -19,43 +19,48 @@ %8 = OpString " kernel" %9 = OpString "out" %10 = OpString "uint*" + %11 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" + %12 = OpString "020000000100000001000000" + %13 = OpString "vksp_s0" + %14 = OpString "test_simple" + %15 = OpString "00000000000000000000000000000000000000000000000000000000" ; Annotations - OpMemberDecorate %_struct_11 0 Offset 0 - OpMemberDecorate %_struct_11 1 Offset 16 - OpDecorate %_struct_11 Block + OpMemberDecorate %_struct_16 0 Offset 0 + OpMemberDecorate %_struct_16 1 Offset 16 + OpDecorate %_struct_16 Block OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize OpDecorate %_runtimearr_uint ArrayStride 4 - OpMemberDecorate %_struct_14 0 Offset 0 - OpDecorate %_struct_14 Block + OpMemberDecorate %_struct_19 0 Offset 0 + OpDecorate %_struct_19 Block OpDecorate %4 DescriptorSet 0 OpDecorate %4 Binding 0 - OpDecorate %15 SpecId 0 - OpDecorate %16 SpecId 1 - OpDecorate %17 SpecId 2 + OpDecorate %20 SpecId 0 + OpDecorate %21 SpecId 1 + OpDecorate %22 SpecId 2 OpDecorate %_runtimearr_ulong ArrayStride 8 - OpMemberDecorate %_struct_19 0 Offset 0 - OpDecorate %_struct_19 Block + OpMemberDecorate %_struct_24 0 Offset 0 + OpDecorate %_struct_24 Block OpDecorate %6 DescriptorSet 0 OpDecorate %6 Binding 1 ; Types, variables and constants %uint = OpTypeInt 32 0 %v3uint = OpTypeVector %uint 3 - %_struct_11 = OpTypeStruct %v3uint %v3uint ; Block -%_ptr_PushConstant__struct_11 = OpTypePointer PushConstant %_struct_11 + %_struct_16 = OpTypeStruct %v3uint %v3uint ; Block +%_ptr_PushConstant__struct_16 = OpTypePointer PushConstant %_struct_16 %_ptr_Input_v3uint = OpTypePointer Input %v3uint - %15 = OpSpecConstant %uint 1 ; SpecId 0 - %16 = OpSpecConstant %uint 1 ; SpecId 1 - %17 = OpSpecConstant %uint 1 ; SpecId 2 -%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %15 %16 %17 ; BuiltIn WorkgroupSize + %20 = OpSpecConstant %uint 1 ; SpecId 0 + %21 = OpSpecConstant %uint 1 ; SpecId 1 + %22 = OpSpecConstant %uint 1 ; SpecId 2 +%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %20 %21 %22 ; BuiltIn WorkgroupSize %_ptr_Private_v3uint = OpTypePointer Private %v3uint %_runtimearr_uint = OpTypeRuntimeArray %uint ; ArrayStride 4 - %_struct_14 = OpTypeStruct %_runtimearr_uint ; Block -%_ptr_StorageBuffer__struct_14 = OpTypePointer StorageBuffer %_struct_14 + %_struct_19 = OpTypeStruct %_runtimearr_uint ; Block +%_ptr_StorageBuffer__struct_19 = OpTypePointer StorageBuffer %_struct_19 %void = OpTypeVoid - %27 = OpTypeFunction %void + %32 = OpTypeFunction %void %_ptr_Input_uint = OpTypePointer Input %uint %uint_0 = OpConstant %uint 0 %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint @@ -66,43 +71,56 @@ %uint_12 = OpConstant %uint 12 %uint_16 = OpConstant %uint 16 %uint_2 = OpConstant %uint 2 - %5 = OpVariable %_ptr_PushConstant__struct_11 PushConstant + %5 = OpVariable %_ptr_PushConstant__struct_16 PushConstant %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input ; BuiltIn GlobalInvocationId %3 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize - %4 = OpVariable %_ptr_StorageBuffer__struct_14 StorageBuffer ; DescriptorSet 0, Binding 0 + %4 = OpVariable %_ptr_StorageBuffer__struct_19 StorageBuffer ; DescriptorSet 0, Binding 0 + %uint_128 = OpConstant %uint 128 + %uint_28 = OpConstant %uint 28 + %uint_32 = OpConstant %uint 32 + %uint_7 = OpConstant %uint 7 + %uint_1024 = OpConstant %uint 1024 + %uint_63 = OpConstant %uint 63 + %uint_4 = OpConstant %uint 4 + %uint_8 = OpConstant %uint 8 %ulong = OpTypeInt 64 0 %_runtimearr_ulong = OpTypeRuntimeArray %ulong ; ArrayStride 8 - %_struct_19 = OpTypeStruct %_runtimearr_ulong ; Block -%_ptr_StorageBuffer__struct_19 = OpTypePointer StorageBuffer %_struct_19 + %_struct_24 = OpTypeStruct %_runtimearr_ulong ; Block +%_ptr_StorageBuffer__struct_24 = OpTypePointer StorageBuffer %_struct_24 %_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong %uint_3 = OpConstant %uint 3 - %uint_8 = OpConstant %uint 8 - %6 = OpVariable %_ptr_StorageBuffer__struct_19 StorageBuffer ; DescriptorSet 0, Binding 1 + %6 = OpVariable %_ptr_StorageBuffer__struct_24 StorageBuffer ; DescriptorSet 0, Binding 1 %ulong_0 = OpConstant %ulong 0 - %59 = OpExtInst %void %58 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1 0 - %60 = OpExtInst %void %58 PushConstants 0 28 "00000000000000000000000000000000000000000000000000000000" 32 - %61 = OpExtInst %void %58 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0 0 0 - %62 = OpExtInst %void %58 DescriptorSetBuffer 0 1 7 0 0 0 16 34 16 0 16 0 0 0 0 - %63 = OpExtInst %void %58 SpecializationMapEntry 0 0 4 - %64 = OpExtInst %void %58 SpecializationMapEntry 1 4 4 - %65 = OpExtInst %void %58 SpecializationMapEntry 2 8 4 + %72 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock.VK_KHR_shader_clock" + %73 = OpString "020000000100000001000000" + %74 = OpString "vksp_s0" + %75 = OpString "test_simple" + %77 = OpString "00000000000000000000000000000000000000000000000000000000" + %uint_34 = OpConstant %uint 34 + %71 = OpExtInst %void %70 Configuration %72 %uint_12 %73 %74 %75 %uint_128 %uint_1 %uint_1 %uint_0 + %76 = OpExtInst %void %70 PushConstants %uint_0 %uint_28 %77 %uint_32 + %78 = OpExtInst %void %70 DescriptorSetBuffer %uint_0 %uint_0 %uint_7 %uint_0 %uint_0 %uint_0 %uint_1024 %uint_63 %uint_1024 %uint_0 %uint_1024 %uint_0 %uint_0 %uint_0 %uint_0 + %79 = OpExtInst %void %70 DescriptorSetBuffer %uint_0 %uint_1 %uint_7 %uint_0 %uint_0 %uint_0 %uint_16 %uint_34 %uint_16 %uint_0 %uint_16 %uint_0 %uint_0 %uint_0 %uint_0 + %81 = OpExtInst %void %70 SpecializationMapEntry %uint_0 %uint_0 %uint_4 + %82 = OpExtInst %void %70 SpecializationMapEntry %uint_1 %uint_4 %uint_4 + %83 = OpExtInst %void %70 SpecializationMapEntry %uint_2 %uint_8 %uint_4 ; Function 1 - %1 = OpFunction %void None %27 - %44 = OpLabel - %45 = OpReadClockKHR %ulong %uint_3 - %46 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0 - %47 = OpLoad %uint %46 - %48 = OpAccessChain %_ptr_PushConstant_uint %5 %uint_1 %uint_0 - %49 = OpLoad %uint %48 - %50 = OpIAdd %uint %49 %47 - %51 = OpAccessChain %_ptr_StorageBuffer_uint %4 %uint_0 %50 - OpStore %51 %50 - %52 = OpReadClockKHR %ulong %uint_3 - %53 = OpISub %ulong %52 %45 - %54 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_0 - %55 = OpAtomicIIncrement %ulong %54 %uint_1 %uint_8 - %56 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_1 - %57 = OpAtomicIAdd %ulong %56 %uint_1 %uint_8 %53 + %1 = OpFunction %void None %32 + %56 = OpLabel + %57 = OpReadClockKHR %ulong %uint_3 + %58 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0 + %59 = OpLoad %uint %58 + %60 = OpAccessChain %_ptr_PushConstant_uint %5 %uint_1 %uint_0 + %61 = OpLoad %uint %60 + %62 = OpIAdd %uint %61 %59 + %63 = OpAccessChain %_ptr_StorageBuffer_uint %4 %uint_0 %62 + OpStore %63 %62 + %64 = OpReadClockKHR %ulong %uint_3 + %65 = OpISub %ulong %64 %57 + %66 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_0 + %67 = OpAtomicIIncrement %ulong %66 %uint_1 %uint_8 + %68 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_1 + %69 = OpAtomicIAdd %ulong %68 %uint_1 %uint_8 %65 OpReturn OpFunctionEnd diff --git a/tests/example-vksp_s0-expectation.spvasm b/tests/example-vksp_s0-expectation.spvasm index 3885f9d..50c2abf 100644 --- a/tests/example-vksp_s0-expectation.spvasm +++ b/tests/example-vksp_s0-expectation.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.6 ; Generator: Khronos SPIR-V Tools Assembler; 0 -; Bound: 81 +; Bound: 98 ; Schema: 0 OpCapability Shader OpCapability ShaderClockKHR @@ -9,9 +9,9 @@ OpCapability Int64Atomics OpExtension "SPV_KHR_shader_clock" OpExtension "SPV_KHR_storage_buffer_storage_class" - %73 = OpExtInstImport "NonSemantic.VkspReflection.2" + %84 = OpExtInstImport "NonSemantic.VkspReflection.4" OpMemoryModel Logical GLSL450 - OpEntryPoint GLCompute %3 "test_simple" %gl_GlobalInvocationID %5 %6 %7 %64 + OpEntryPoint GLCompute %3 "test_simple" %gl_GlobalInvocationID %5 %6 %7 %75 ; Debug Information OpSource OpenCL_C 120 @@ -19,6 +19,11 @@ %9 = OpString " kernel" %10 = OpString "out" %11 = OpString "uint*" + %37 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" + %38 = OpString "020000000100000001000000" + %39 = OpString "vksp_s0" + %40 = OpString "test_simple" + %43 = OpString "00000000000000000000000000000000000000000000000000000000" ; Annotations OpMemberDecorate %_struct_12 0 Offset 0 @@ -35,10 +40,10 @@ OpDecorate %17 SpecId 1 OpDecorate %18 SpecId 2 OpDecorate %_runtimearr_ulong ArrayStride 8 - OpMemberDecorate %_struct_59 0 Offset 0 - OpDecorate %_struct_59 Block - OpDecorate %64 DescriptorSet 0 - OpDecorate %64 Binding 1 + OpMemberDecorate %_struct_71 0 Offset 0 + OpDecorate %_struct_71 Block + OpDecorate %75 DescriptorSet 0 + OpDecorate %75 Binding 1 ; Types, variables and constants %uint = OpTypeInt 32 0 @@ -70,39 +75,52 @@ %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input ; BuiltIn GlobalInvocationId %5 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize %6 = OpVariable %_ptr_StorageBuffer__struct_15 StorageBuffer ; DescriptorSet 0, Binding 0 + %uint_128 = OpConstant %uint 128 + %uint_28 = OpConstant %uint 28 + %uint_32 = OpConstant %uint 32 + %uint_7 = OpConstant %uint 7 + %uint_1024 = OpConstant %uint 1024 + %uint_63 = OpConstant %uint 63 + %uint_4 = OpConstant %uint 4 + %uint_8 = OpConstant %uint 8 %ulong = OpTypeInt 64 0 %_runtimearr_ulong = OpTypeRuntimeArray %ulong ; ArrayStride 8 - %_struct_59 = OpTypeStruct %_runtimearr_ulong ; Block -%_ptr_StorageBuffer__struct_59 = OpTypePointer StorageBuffer %_struct_59 + %_struct_71 = OpTypeStruct %_runtimearr_ulong ; Block +%_ptr_StorageBuffer__struct_71 = OpTypePointer StorageBuffer %_struct_71 %_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong %uint_3 = OpConstant %uint 3 - %uint_8 = OpConstant %uint 8 - %64 = OpVariable %_ptr_StorageBuffer__struct_59 StorageBuffer ; DescriptorSet 0, Binding 1 + %75 = OpVariable %_ptr_StorageBuffer__struct_71 StorageBuffer ; DescriptorSet 0, Binding 1 %ulong_0 = OpConstant %ulong 0 - %74 = OpExtInst %void %73 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1 0 - %75 = OpExtInst %void %73 PushConstants 0 28 "00000000000000000000000000000000000000000000000000000000" 32 - %76 = OpExtInst %void %73 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0 0 0 - %77 = OpExtInst %void %73 DescriptorSetBuffer 0 1 7 0 0 0 16 34 16 0 16 0 0 0 0 - %78 = OpExtInst %void %73 SpecializationMapEntry 0 0 4 - %79 = OpExtInst %void %73 SpecializationMapEntry 1 4 4 - %80 = OpExtInst %void %73 SpecializationMapEntry 2 8 4 + %86 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock.VK_KHR_shader_clock" + %87 = OpString "020000000100000001000000" + %88 = OpString "vksp_s0" + %89 = OpString "test_simple" + %91 = OpString "00000000000000000000000000000000000000000000000000000000" + %uint_34 = OpConstant %uint 34 + %85 = OpExtInst %void %84 Configuration %86 %uint_12 %87 %88 %89 %uint_128 %uint_1 %uint_1 %uint_0 + %90 = OpExtInst %void %84 PushConstants %uint_0 %uint_28 %91 %uint_32 + %92 = OpExtInst %void %84 DescriptorSetBuffer %uint_0 %uint_0 %uint_7 %uint_0 %uint_0 %uint_0 %uint_1024 %uint_63 %uint_1024 %uint_0 %uint_1024 %uint_0 %uint_0 %uint_0 %uint_0 + %93 = OpExtInst %void %84 DescriptorSetBuffer %uint_0 %uint_1 %uint_7 %uint_0 %uint_0 %uint_0 %uint_16 %uint_34 %uint_16 %uint_0 %uint_16 %uint_0 %uint_0 %uint_0 %uint_0 + %95 = OpExtInst %void %84 SpecializationMapEntry %uint_0 %uint_0 %uint_4 + %96 = OpExtInst %void %84 SpecializationMapEntry %uint_1 %uint_4 %uint_4 + %97 = OpExtInst %void %84 SpecializationMapEntry %uint_2 %uint_8 %uint_4 ; Function 3 %3 = OpFunction %void None %26 - %44 = OpLabel - %66 = OpReadClockKHR %ulong %uint_3 - %45 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0 - %46 = OpLoad %uint %45 - %47 = OpAccessChain %_ptr_PushConstant_uint %7 %uint_1 %uint_0 - %48 = OpLoad %uint %47 - %49 = OpIAdd %uint %48 %46 - %50 = OpAccessChain %_ptr_StorageBuffer_uint %6 %uint_0 %49 - OpStore %50 %49 - %67 = OpReadClockKHR %ulong %uint_3 - %68 = OpISub %ulong %67 %66 - %69 = OpAccessChain %_ptr_StorageBuffer_ulong %64 %uint_0 %uint_0 - %70 = OpAtomicIIncrement %ulong %69 %uint_1 %uint_8 - %71 = OpAccessChain %_ptr_StorageBuffer_ulong %64 %uint_0 %uint_1 - %72 = OpAtomicIAdd %ulong %71 %uint_1 %uint_8 %68 + %56 = OpLabel + %77 = OpReadClockKHR %ulong %uint_3 + %57 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0 + %58 = OpLoad %uint %57 + %59 = OpAccessChain %_ptr_PushConstant_uint %7 %uint_1 %uint_0 + %60 = OpLoad %uint %59 + %61 = OpIAdd %uint %60 %58 + %62 = OpAccessChain %_ptr_StorageBuffer_uint %6 %uint_0 %61 + OpStore %62 %61 + %78 = OpReadClockKHR %ulong %uint_3 + %79 = OpISub %ulong %78 %77 + %80 = OpAccessChain %_ptr_StorageBuffer_ulong %75 %uint_0 %uint_0 + %81 = OpAtomicIIncrement %ulong %80 %uint_1 %uint_8 + %82 = OpAccessChain %_ptr_StorageBuffer_ulong %75 %uint_0 %uint_1 + %83 = OpAtomicIAdd %ulong %82 %uint_1 %uint_8 %79 OpReturn OpFunctionEnd diff --git a/tests/example.spvasm b/tests/example.spvasm index f4dc3dd..d0996ff 100644 --- a/tests/example.spvasm +++ b/tests/example.spvasm @@ -5,7 +5,7 @@ ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "NonSemantic.ClspvReflection.5" - %49 = OpExtInstImport "NonSemantic.VkspReflection.2" + %49 = OpExtInstImport "NonSemantic.VkspReflection.4" OpMemoryModel Logical GLSL450 OpEntryPoint GLCompute %2 "test_simple" %gl_GlobalInvocationID %4 %5 %6 @@ -61,13 +61,25 @@ %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input %4 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize %5 = OpVariable %_ptr_StorageBuffer__struct_14 StorageBuffer - %50 = OpExtInst %void %49 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1 0 - %51 = OpExtInst %void %49 PushConstants 16 12 "000000000000000000000000" 32 - %52 = OpExtInst %void %49 PushConstants 0 12 "000000000000000000000000" 32 - %53 = OpExtInst %void %49 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0 0 0 - %54 = OpExtInst %void %49 SpecializationMapEntry 0 0 4 - %55 = OpExtInst %void %49 SpecializationMapEntry 1 4 4 - %56 = OpExtInst %void %49 SpecializationMapEntry 2 8 4 + %144 = OpString ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing.VK_KHR_shader_clock" + %145 = OpString "020000000100000001000000" + %146 = OpString "vksp_s0" + %147 = OpString "test_simple" + %uint_128 = OpConstant %uint 128 + %uint_28 = OpConstant %uint 28 + %151 = OpString "00000000000000000000000000000000000000000000000000000000" + %uint_32 = OpConstant %uint 32 + %uint_7 = OpConstant %uint 7 + %uint_1024 = OpConstant %uint 1024 + %uint_63 = OpConstant %uint 63 + %uint_4 = OpConstant %uint 4 + %uint_8 = OpConstant %uint 8 + %143 = OpExtInst %void %49 Configuration %144 %uint_12 %145 %146 %147 %uint_128 %uint_1 %uint_1 %uint_0 + %149 = OpExtInst %void %49 PushConstants %uint_0 %uint_28 %151 %uint_32 + %153 = OpExtInst %void %49 DescriptorSetBuffer %uint_0 %uint_0 %uint_7 %uint_0 %uint_0 %uint_0 %uint_1024 %uint_63 %uint_1024 %uint_0 %uint_1024 %uint_0 %uint_0 %uint_0 %uint_0 + %157 = OpExtInst %void %49 SpecializationMapEntry %uint_0 %uint_0 %uint_4 + %159 = OpExtInst %void %49 SpecializationMapEntry %uint_1 %uint_4 %uint_4 + %160 = OpExtInst %void %49 SpecializationMapEntry %uint_2 %uint_8 %uint_4 ; Function 2 %2 = OpFunction %void None %25