Skip to content

Commit

Permalink
gpu: remove unimplemented instructions earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Nov 14, 2024
1 parent 76cf146 commit ddad35e
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ir::Value>());
continue;
}

if (inst.getKind() != ir::Kind::Spv && inst.getKind() != ir::Kind::AmdGpu &&
semanticModuleInfo.findSemanticOf(inst.getInstId()) == nullptr) {
std::println(std::cerr, "unimplemented semantic: ");
inst.print(std::cerr, context.ns);
std::println(std::cerr);

std::vector<ir::Instruction> workList;
std::set<ir::Instruction> 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<ir::Value>()) {
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;
}
}

Expand Down Expand Up @@ -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<ir::Instruction> workList;
std::set<ir::Instruction> 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<ir::Value>()) {
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(
Expand Down

0 comments on commit ddad35e

Please sign in to comment.