From 1de2ea960c19de476a314bc0b764c5fb8c5f250a Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 3 Jul 2024 21:24:56 +0200 Subject: [PATCH] recompiler: restored bfs in image instruction producers search --- .../ir/passes/resource_tracking_pass.cpp | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp index 7f91a63c..7f143ad4 100644 --- a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp +++ b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp @@ -253,15 +253,25 @@ IR::Value PatchCubeCoord(IR::IREmitter& ir, const IR::Value& s, const IR::Value& } void PatchImageInstruction(IR::Block& block, IR::Inst& inst, Info& info, Descriptors& descriptors) { - IR::Inst* producer = inst.Arg(0).InstRecursive(); - while (producer->GetOpcode() == IR::Opcode::Phi) { - producer = producer->Arg(0).InstRecursive(); + std::deque insts{&inst}; + const auto& pred = [](auto opcode) -> bool { + return (opcode == IR::Opcode::CompositeConstructU32x2 || // IMAGE_SAMPLE (image+sampler) + opcode == IR::Opcode::ReadConst || // IMAGE_LOAD (image only) + opcode == IR::Opcode::GetUserData); + }; + + IR::Inst* producer{}; + while (!insts.empty() && (producer = insts.front(), !pred(producer->GetOpcode()))) { + for (auto arg_idx = 0u; arg_idx < producer->NumArgs(); ++arg_idx) { + const auto arg = producer->Arg(arg_idx); + if (arg.TryInstRecursive()) { + insts.push_back(arg.InstRecursive()); + } + } + insts.pop_front(); } - ASSERT(producer->GetOpcode() == - IR::Opcode::CompositeConstructU32x2 || // IMAGE_SAMPLE (image+sampler) - producer->GetOpcode() == IR::Opcode::ReadConst || // IMAGE_LOAD (image only) - producer->GetOpcode() == IR::Opcode::GetUserData); - const auto [tsharp_handle, ssharp_handle] = [&] -> std::pair { + ASSERT(pred(producer->GetOpcode())); + auto [tsharp_handle, ssharp_handle] = [&] -> std::pair { if (producer->GetOpcode() == IR::Opcode::CompositeConstructU32x2) { return std::make_pair(producer->Arg(0).InstRecursive(), producer->Arg(1).InstRecursive());