Skip to content

Commit

Permalink
gpu: implement mrtz exp target
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Oct 22, 2024
1 parent f79e16e commit e0e69ea
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions rpcsx/gpu/lib/gcn-shader/src/GcnConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "rx/die.hpp"
#include <iostream>
#include <limits>
#include <print>

using namespace shader;

Expand Down Expand Up @@ -651,9 +652,9 @@ static void expToSpv(GcnConverter &converter, gcn::Stage stage,
continue;
}

auto src =
builder.createSpvBitcast(loc, context.getTypeFloat32(),
inst.getOperand(operandIndex++).getAsValue());
auto src = builder.createSpvBitcast(
loc, context.getTypeFloat32(),
inst.getOperand(operandIndex++).getAsValue());

auto srcType = src.getOperand(0).getAsValue();
ir::Value elementType;
Expand Down Expand Up @@ -786,6 +787,26 @@ static void expToSpv(GcnConverter &converter, gcn::Stage stage,
return;
}

if (target == ET_MRTZ) {
auto output = context.createFragDepth(loc);
auto channelType = context.getTypeFloat32();

for (int channel = 0; channel < 4; ++channel) {
if (~swizzle & (1 << channel)) {
continue;
}

auto channelValue =
builder.createSpvCompositeExtract(loc, elemType, value, {{channel}});
channelValue =
context.createCast(loc, builder, channelType, channelValue);
builder.createSpvStore(loc, output, channelValue);
break;
}

return;
}

if (target >= ET_PARAM0 && target <= ET_PARAM31) {
auto output = context.createOutput(loc, target - ET_PARAM0);
auto floatT = context.getTypeFloat32();
Expand Down Expand Up @@ -849,8 +870,8 @@ static void expToSpv(GcnConverter &converter, gcn::Stage stage,
return result;
};

std::printf("exp target %s.%s\n", targetToString(target).c_str(),
swizzleToString(swizzle).c_str());
std::println(stderr, "exp target {}.{}", targetToString(target),
swizzleToString(swizzle));
std::abort();
}

Expand Down Expand Up @@ -1454,6 +1475,8 @@ static void createEntryPoint(gcn::Context &context, const gcn::Environment &env,
executionModes.createSpvExecutionMode(
mainFn.getLocation(), mainFn,
ir::spv::ExecutionMode::OriginUpperLeft());
executionModes.createSpvExecutionMode(
mainFn.getLocation(), mainFn, ir::spv::ExecutionMode::DepthReplacing());
}

if (executionModel == ir::spv::ExecutionModel::GLCompute) {
Expand Down

0 comments on commit e0e69ea

Please sign in to comment.