From a99cc426d66f47a24b07ad37e6083565a7ffaec1 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 16 May 2026 14:34:48 +0000 Subject: [PATCH] [shader_recompiler] add 'legacy descriptor indices' toggle for tomodachi Signed-off-by: lizzie --- src/common/settings.h | 2 + .../backend/spirv/emit_spirv_image.cpp | 39 ++++++++++++------- src/shader_recompiler/ir_opt/texture_pass.cpp | 13 ++++--- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index e10f5105a1..08005bb7a4 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -591,6 +591,8 @@ struct Values { SwitchableSetting gpu_unswizzle_enabled{linkage, false, "gpu_unswizzle_enabled", Category::RendererHacks}; + SwitchableSetting legacy_descriptor_indices{linkage, true, "legacy_descriptor_indices", Category::RendererHacks}; + SwitchableSetting dyna_state{linkage, #if defined(ANDROID) ExtendedDynamicState::Disabled, diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index 62a82dce9d..7745a73fb9 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp @@ -221,12 +221,17 @@ private: Id Texture(EmitContext& ctx, IR::TextureInstInfo info, [[maybe_unused]] const IR::Value& index) { const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; if (def.count > 1) { - const DescriptorIndex idx{ctx, index}; - const Id pointer{ctx.OpAccessChain(def.pointer_type, def.id, idx.Value())}; - idx.Decorate(ctx, pointer); - const Id object{ctx.OpLoad(def.sampled_type, pointer)}; - idx.Decorate(ctx, object); - return object; + if (Settings::values.legacy_descriptor_indices.GetValue()) { + const Id pointer{ctx.OpAccessChain(def.pointer_type, def.id, ctx.Def(index))}; + return ctx.OpLoad(def.sampled_type, pointer); + } else { + const DescriptorIndex idx{ctx, index}; + const Id pointer{ctx.OpAccessChain(def.pointer_type, def.id, idx.Value())}; + idx.Decorate(ctx, pointer); + const Id object{ctx.OpLoad(def.sampled_type, pointer)}; + idx.Decorate(ctx, object); + return object; + } } else { return ctx.OpLoad(def.sampled_type, def.id); } @@ -244,14 +249,20 @@ Id TextureImage(EmitContext& ctx, IR::TextureInstInfo info, const IR::Value& ind } else { const TextureDefinition& def{ctx.textures.at(info.descriptor_index)}; if (def.count > 1) { - const DescriptorIndex idx{ctx, index}; - const Id ptr{ctx.OpAccessChain(def.pointer_type, def.id, idx.Value())}; - idx.Decorate(ctx, ptr); - const Id object{ctx.OpLoad(def.sampled_type, ptr)}; - idx.Decorate(ctx, object); - const Id image{ctx.OpImage(def.image_type, object)}; - idx.Decorate(ctx, image); - return image; + if (Settings::values.legacy_descriptor_indices.GetValue()) { + const Id idx{index.IsImmediate() ? ctx.Const(index.U32()) : ctx.Def(index)}; + const Id ptr{ctx.OpAccessChain(def.pointer_type, def.id, idx)}; + return ctx.OpImage(def.image_type, ctx.OpLoad(def.sampled_type, ptr)); + } else { + const DescriptorIndex idx{ctx, index}; + const Id ptr{ctx.OpAccessChain(def.pointer_type, def.id, idx.Value())}; + idx.Decorate(ctx, ptr); + const Id object{ctx.OpLoad(def.sampled_type, ptr)}; + idx.Decorate(ctx, object); + const Id image{ctx.OpImage(def.image_type, object)}; + idx.Decorate(ctx, image); + return image; + } } return ctx.OpImage(def.image_type, ctx.OpLoad(def.sampled_type, def.id)); } diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index 55b6f7213c..2366996292 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp @@ -12,6 +12,7 @@ #include #include +#include "common/settings.h" #include "shader_recompiler/environment.h" #include "shader_recompiler/frontend/ir/basic_block.h" #include "shader_recompiler/frontend/ir/breadth_first_search.h" @@ -461,7 +462,7 @@ std::optional TryGetConstBuffer(const IR::Inst* inst, Environme .secondary_offset = 0, .secondary_shift_left = 0, .dynamic_offset = dynamic_offset, - .count = DynamicDescriptorCount(base_offset, size_shift), + .count = Settings::values.legacy_descriptor_indices.GetValue() ? 8 : DynamicDescriptorCount(base_offset, size_shift), .has_secondary = false, }; } @@ -733,9 +734,10 @@ void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo break; } u32 index; - const u32 size_shift{cbuf.count > 1 ? DynamicDescriptorSizeShift(cbuf.dynamic_offset) - : DESCRIPTOR_SIZE_SHIFT}; - u32 count{cbuf.count}; + u32 size_shift = cbuf.count > 1 ? DynamicDescriptorSizeShift(cbuf.dynamic_offset) : DESCRIPTOR_SIZE_SHIFT; + if (Settings::values.legacy_descriptor_indices.GetValue()) + size_shift = DESCRIPTOR_SIZE_SHIFT; + u32 count = cbuf.count; switch (inst->GetOpcode()) { case IR::Opcode::ImageRead: case IR::Opcode::ImageAtomicIAdd32: @@ -821,8 +823,7 @@ void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo const auto insert_point{IR::Block::InstructionList::s_iterator_to(*inst)}; IR::IREmitter ir{*texture_inst.block, insert_point}; const IR::U32 shift{ir.Imm32(size_shift)}; - inst->SetArg(0, ir.UMin(ir.ShiftRightLogical(cbuf.dynamic_offset, shift), - ir.Imm32(count - 1))); + inst->SetArg(0, ir.UMin(ir.ShiftRightLogical(cbuf.dynamic_offset, shift), ir.Imm32(count - 1))); } else { inst->SetArg(0, IR::Value{}); }