Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,7 @@ void VulkanDevice::QueuePresent() {
ShaderRecompiler::SpirvTarget VulkanDevice::Target() const {
const auto& limits = state->properties.limits;
ShaderRecompiler::SpirvTarget target{VK_API_VERSION_1_1, state->meshShader ? 0x00010400u : 0x00010300u, state->subgroup.subgroupSize, ShaderRecompiler::BdaAbi::Version, state->capabilities, state->spirvExtensions, false, {limits.maxComputeWorkGroupSize[0], limits.maxComputeWorkGroupSize[1], limits.maxComputeWorkGroupSize[2]}, limits.maxComputeWorkGroupInvocations, limits.maxComputeSharedMemorySize, {}, {}};
target.fragmentShaderBarycentricEnabled = state->fragmentShaderBarycentric;
if (state->meshShader) {
const auto& mesh = state->meshLimits;
target.mesh = ShaderRecompiler::MeshTargetLimits{{mesh.maxMeshWorkGroupSize[0], mesh.maxMeshWorkGroupSize[1], mesh.maxMeshWorkGroupSize[2]}, mesh.maxMeshWorkGroupInvocations, std::min(mesh.maxMeshSharedMemorySize, mesh.maxMeshPayloadAndSharedMemorySize), mesh.maxMeshOutputVertices, mesh.maxMeshOutputPrimitives, mesh.maxMeshOutputComponents, std::min(mesh.maxMeshOutputMemorySize, mesh.maxMeshPayloadAndOutputMemorySize), mesh.meshOutputPerVertexGranularity, mesh.meshOutputPerPrimitiveGranularity};
Expand Down
20 changes: 15 additions & 5 deletions core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ bool readsBuiltin(const std::vector<spv::BuiltIn>& read, spv::BuiltIn builtin) {
return std::find(read.begin(), read.end(), builtin) != read.end();
}

std::vector<std::uint32_t> pixelNoPerspectiveLocations() {
std::vector<std::uint32_t> pixelNoPerspectiveLocations(bool barycentricEnabled) {
auto queue = makeState();
queue.context[0x1b3] = 0x22u;
queue.context[0x1b4] = 0x22u;
Expand All @@ -298,18 +298,27 @@ std::vector<std::uint32_t> pixelNoPerspectiveLocations() {
request.target.vulkanVersion = 0x00401000u;
request.target.spirvVersion = 0x00010300u;
request.target.subgroupSize = 64;
request.target.fragmentShaderBarycentricEnabled = true;
request.target.fragmentShaderBarycentricEnabled = barycentricEnabled;
request.layout.pushConstantSizeBytes = 128;
request.useCache = false;
const auto result = ShaderRecompiler::Recompile(request);
const auto& words = result.spirv.Words();
std::map<std::uint32_t, std::uint32_t> locations;
std::vector<std::uint32_t> noPerspective;
std::uint32_t perVertex = 0;
bool perspectiveBarycentrics = false;
bool linearBarycentrics = false;
for (std::size_t at = 5; at < words.size() && (words[at] >> 16u) != 0; at += words[at] >> 16u) {
if (static_cast<spv::Op>(words[at] & 0xffffu) != spv::OpDecorate) continue;
if (words[at + 2] == spv::DecorationLocation) locations[words[at + 1]] = words[at + 3];
if (words[at + 2] == spv::DecorationNoPerspective) noPerspective.push_back(words[at + 1]);
if (words[at + 2] == spv::DecorationPerVertexKHR) perVertex++;
if (words[at + 2] == spv::DecorationBuiltIn) {
perspectiveBarycentrics |= words[at + 3] == spv::BuiltInBaryCoordKHR;
linearBarycentrics |= words[at + 3] == spv::BuiltInBaryCoordNoPerspKHR;
}
}
if (barycentricEnabled) Require(perVertex == 2u && perspectiveBarycentrics && linearBarycentrics, "explicit interpolation must preserve both parameter vertices and both barycentric inputs");
std::vector<std::uint32_t> result2;
for (const auto id : noPerspective) result2.push_back(locations.count(id) != 0 ? locations.at(id) : 0xffffffffu);
return result2;
Expand Down Expand Up @@ -350,8 +359,9 @@ void PixelInputLayoutTests() {
const auto read = pixelBuiltinsRead(0x106u, 0x106u, source);
Require(readsBuiltin(read, spv::BuiltInBaryCoordKHR) && !readsBuiltin(read, spv::BuiltInFragCoord), "a centroid-layout I/J VGPR does not hold the barycentrics: v" + std::to_string(source));
}
const auto noPerspective = pixelNoPerspectiveLocations();
const auto noPerspective = pixelNoPerspectiveLocations(false);
Require(noPerspective.size() == 1 && noPerspective[0] == 1u, "only the parameter interpolated through the linear pair must be NoPerspective");
Require(pixelNoPerspectiveLocations(true).empty(), "explicit interpolation must not interpolate parameter arrays a second time");
auto read = pixelBuiltinsRead(0x106u, 0x106u, 4u);
Require(readsBuiltin(read, spv::BuiltInFragCoord) && !readsBuiltin(read, spv::BuiltInBaryCoordKHR), "POS_X is not in v4 after the center and centroid pairs");
read = pixelBuiltinsRead(0x326u, 0x326u, 5u);
Expand Down Expand Up @@ -1389,10 +1399,10 @@ void pixelParameterSlotTests() {
const std::array<std::uint32_t, 7> shared{0xc8100000u, 0xc8110001u, 0xc8140500u, 0xc8150501u, 0xf800180fu, 0x05040504u, 0xbf810000u};
pixel = recompilePixel({0x3u, 0x3u}, shared);
inputs = locatedInputs(pixel.spirv.Words());
Require(inputs.size() == 1 && inputs[0].location == 3 && !inputs[0].perVertex && !inputs[0].flat, "inputs reading one slot were not declared once at the slot");
Require(inputs.size() == 1 && inputs[0].location == 3 && inputs[0].perVertex && !inputs[0].flat, "inputs reading one slot were not declared once at the slot");
pixel = recompilePixel({0x404u, 0x0u}, shared);
inputs = locatedInputs(pixel.spirv.Words());
Require(inputs.size() == 2 && inputs[0].location == 0 && !inputs[0].flat && inputs[1].location == 4 && inputs[1].flat, "flat and interpolated inputs of different slots moved");
Require(inputs.size() == 2 && inputs[0].location == 0 && inputs[0].perVertex && inputs[1].location == 4 && inputs[1].perVertex, "flat and interpolated inputs of different slots moved");
pixel = recompilePixel({0x20u, 0x2320u}, shared);
Require(locatedInputs(pixel.spirv.Words()).empty(), "a defaulted input was declared as a parameter");
AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, true);
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ std::vector<std::pair<std::uint32_t, bool>> slotInputs(std::initializer_list<std
void verifyPixelParameterSlots() {
static constexpr std::array<std::uint32_t, 7> shared{0xc8100000u, 0xc8110001u, 0xc8140500u, 0xc8150501u, 0xf800180fu, 0x05040504u, 0xbf810000u};
auto inputs = slotInputs({0x3u, 0x3u}, shared);
require(inputs.size() == 1u && inputs[0].first == 3u && !inputs[0].second, "inputs reading one slot were not declared once at the slot");
require(inputs.size() == 1u && inputs[0].first == 3u && inputs[0].second, "inputs reading one slot were not declared once at the slot");
inputs = slotInputs({0x404u, 0x0u}, shared);
require(inputs.size() == 2u && inputs[0].first == 0u && inputs[1].first == 4u, "inputs of different slots moved");
require(slotInputs({0x20u, 0x2320u}, shared).empty(), "a defaulted input was declared as a parameter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TranslationContext {
TranslationContext(IrProgram& program, IrBlock& block, std::uint32_t vectorLimit);

void TranslateInstruction(const RdnaInstruction& instruction);
void SetPixelInput(const ShaderPixelInputInfo* info) { pixelInput = info; }
void SetPixelInput(const ShaderPixelInputInfo* info, bool barycentricEnabled) { pixelInput = info; fragmentShaderBarycentricEnabled = barycentricEnabled; }
void TranslateEmbeddedFetch(const RdnaInstruction& instruction, std::uint32_t attribute, std::uint32_t componentCount, const ShaderBufferResource& resource);
void AddBranchCondition(const BasicBlock& source, BlockInfo& info);

Expand Down Expand Up @@ -223,7 +223,7 @@ class TranslationContext {
void vReadlaneB32(const RdnaInstruction& inst);
void vWritelaneB32(const RdnaInstruction& inst);
void vPermlane16B32(const RdnaInstruction& inst, bool x16);
void vInterpP1F32();
void vInterpP1F32(const RdnaInstruction& inst);
void vInterpP2F32(const RdnaInstruction& inst);
void vInterpMovF32(const RdnaInstruction& inst);
void eXP(const RdnaInstruction& inst);
Expand All @@ -234,6 +234,7 @@ class TranslationContext {

IrProgram& program;
const ShaderPixelInputInfo* pixelInput = nullptr;
bool fragmentShaderBarycentricEnabled = false;
IrBuilder ir;
IrBlock& block;
IrU1 instructionBranchCondition;
Expand Down
20 changes: 18 additions & 2 deletions core/shader/recompiler/Translation/src/AttributeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,23 @@ ExportFlags TranslationContext::addExportInfo(const RdnaInstruction& inst) {
return ExportFlags{index, inst.programCounter};
}

void TranslationContext::vInterpP1F32() {
void TranslationContext::vInterpP1F32(const RdnaInstruction& inst) {
if (!fragmentShaderBarycentricEnabled) return;
auto& delta = ir.Emit(IrOpcode::GetInterpolationParameter, IrType::U32, {&ir.Constant(inst.source1.value), &ir.Constant(inst.source2.value), &ir.Constant(0u)});
auto& origin = ir.Emit(IrOpcode::GetInterpolationParameter, IrType::U32, {&ir.Constant(inst.source1.value), &ir.Constant(inst.source2.value), &ir.Constant(2u)});
auto& product = ir.Emit(IrOpcode::FPMul32, IrType::F32, {&ir.BitCastF32(delta), readOperand(inst.source0, IrType::F32)});
auto& result = ir.Emit(IrOpcode::FPAdd32, IrType::F32, {&product, &ir.BitCastF32(origin)});
writeOperand(inst.destination, &result);
}

void TranslationContext::vInterpP2F32(const RdnaInstruction& inst) {
if (fragmentShaderBarycentricEnabled) {
auto& delta = ir.Emit(IrOpcode::GetInterpolationParameter, IrType::U32, {&ir.Constant(inst.source1.value), &ir.Constant(inst.source2.value), &ir.Constant(1u)});
auto& product = ir.Emit(IrOpcode::FPMul32, IrType::F32, {&ir.BitCastF32(delta), readOperand(inst.source0, IrType::F32)});
auto& result = ir.Emit(IrOpcode::FPAdd32, IrType::F32, {&product, readOperand(inst.destination, IrType::F32)});
writeOperand(inst.destination, &result);
return;
}
if (pixelInput != nullptr && inst.source0.kind == RdnaOperandKind::VectorRegister && inst.source1.value < 32u) {
const auto readsPair = [&](PixelInput input) {
const auto base = pixelInput->psInputVgpr[static_cast<std::size_t>(input)];
Expand Down Expand Up @@ -146,9 +159,12 @@ void TranslationContext::eXP(const RdnaInstruction& inst) {
}

bool TranslationContext::emitInterpolation(const RdnaInstruction& inst) {
if ((inst.op == RdnaOpcode::VInterpP1F32 || inst.op == RdnaOpcode::VInterpP2F32) && pixelInput != nullptr && pixelInput->InputIsCustom(inst.source1.value)) {
throw std::runtime_error("pixel input " + std::to_string(inst.source1.value) + " passes its vertices through unchanged but is read with v_interp_p1/p2");
}
switch (inst.op) {
case RdnaOpcode::VInterpP1F32:
vInterpP1F32();
vInterpP1F32(inst);
return true;
case RdnaOpcode::VInterpP2F32:
vInterpP2F32(inst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ IrProgram InstructionTranslator::Translate(const RdnaProgram& decoded, const Con
for (const auto& cfgBlock : cfg.blocks) {
const auto typedIndex = blockIndices.at(cfgBlock.id);
TranslationContext context(program, *blocks[typedIndex], vectorLimit);
context.SetPixelInput(options.inputInfo.pixel);
context.SetPixelInput(options.inputInfo.pixel, options.fragmentShaderBarycentricEnabled);
for (std::uint32_t index = cfgBlock.instructionBegin; index < cfgBlock.instructionEnd; index++) {
const auto& instruction = decoded.instructions[index];
if (isCodeTableLoad(cfg, instruction.programCounter)) {
Expand Down
Loading