From a0dac15d1f4dee13ba06a2114cc37b9d27f9950f Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 14 Nov 2024 20:05:55 +0300 Subject: [PATCH] gpu: remove unimplemented instructions earlier --- rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp | 82 ++++++++++--------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp b/rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp index 6376c18..c733132 100644 --- a/rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp +++ b/rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp @@ -1178,6 +1178,49 @@ static void instructionsToSpv(GcnConverter &converter, gcn::Import &importer, inst == ir::amdgpu::SAMPLER || inst == ir::amdgpu::TBUFFER || inst == ir::amdgpu::IMAGE_BUFFER) { toAnalyze.push_back(inst.staticCast()); + continue; + } + + if (inst.getKind() != ir::Kind::Spv && + semanticModuleInfo.findSemanticOf(inst.getInstId()) == nullptr) { + std::println(std::cerr, "unimplemented semantic: "); + inst.print(std::cerr, context.ns); + std::println(std::cerr); + + std::vector workList; + std::set removed; + workList.push_back(inst); + auto builder = gcn::Builder::createInsertBefore(context, inst); + + while (!workList.empty()) { + auto inst = workList.back(); + workList.pop_back(); + + if (!removed.insert(inst).second) { + continue; + } + + std::println(std::cerr, "removing "); + inst.print(std::cerr, context.ns); + std::println(std::cerr); + + if (auto value = inst.cast()) { + for (auto &use : value.getUseList()) { + if (removed.contains(use.user)) { + continue; + } + + workList.push_back(use.user); + } + + value.replaceAllUsesWith(builder.createSpvUndef( + inst.getLocation(), value.getOperand(0).getAsValue())); + } + + inst.remove(); + } + + continue; } } @@ -1616,45 +1659,6 @@ static void instructionsToSpv(GcnConverter &converter, gcn::Import &importer, auto function = semanticModuleInfo.findSemanticOf(inst.getInstId()); - if (function == nullptr) { - std::println(std::cerr, "unimplemented semantic: "); - inst.print(std::cerr, context.ns); - std::println(std::cerr); - - std::vector workList; - std::set removed; - workList.push_back(inst); - - while (!workList.empty()) { - auto inst = workList.back(); - workList.pop_back(); - - if (!removed.insert(inst).second) { - continue; - } - - std::println(std::cerr, "removing "); - inst.print(std::cerr, context.ns); - std::println(std::cerr); - - if (auto value = inst.cast()) { - for (auto &use : value.getUseList()) { - if (removed.contains(use.user)) { - continue; - } - - workList.push_back(use.user); - } - - value.replaceAllUsesWith(builder.createSpvUndef( - inst.getLocation(), value.getOperand(0).getAsValue())); - } - - inst.remove(); - } - continue; - } - function = ir::clone(function, context, importer); auto spvFnCall = builder.createSpvFunctionCall(