mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #522 from adriadam10/fix/dpp16-no-form
fix(shader): refuse DPP16 on opcodes with no DPP form
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
|
||||
#include "Recompiler.hpp"
|
||||
#include "VulkanTestDevice.hpp"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
struct NoFormOpcode {
|
||||
bool vop2;
|
||||
std::uint32_t opcode;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
constexpr std::array<NoFormOpcode, 23> NoFormOpcodes{{
|
||||
{false, 0x02u, "v_readfirstlane_b32"}, {false, 0x03u, "v_cvt_i32_f64"}, {false, 0x04u, "v_cvt_f64_i32"},
|
||||
{false, 0x0fu, "v_cvt_f32_f64"}, {false, 0x10u, "v_cvt_f64_f32"}, {false, 0x15u, "v_cvt_u32_f64"},
|
||||
{false, 0x16u, "v_cvt_f64_u32"}, {false, 0x17u, "v_trunc_f64"}, {false, 0x18u, "v_ceil_f64"},
|
||||
{false, 0x19u, "v_rndne_f64"}, {false, 0x1au, "v_floor_f64"}, {false, 0x3cu, "v_frexp_exp_i32_f64"},
|
||||
{false, 0x3du, "v_frexp_mant_f64"}, {false, 0x3eu, "v_fract_f64"}, {false, 0x65u, "v_swap_b32"},
|
||||
{false, 0x68u, "v_swaprel_b32"}, {true, 0x06u, "v_mac_legacy_f32"}, {true, 0x20u, "v_madmk_f32"},
|
||||
{true, 0x21u, "v_madak_f32"}, {true, 0x2cu, "v_fmamk_f32"}, {true, 0x2du, "v_fmaak_f32"},
|
||||
{true, 0x37u, "v_fmamk_f16"}, {true, 0x38u, "v_fmaak_f16"},
|
||||
}};
|
||||
|
||||
std::string Hex(std::uint32_t value) {
|
||||
char text[16];
|
||||
std::snprintf(text, sizeof(text), "0x%08x", value);
|
||||
return text;
|
||||
}
|
||||
|
||||
auto Compile(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t> code) {
|
||||
std::vector<std::uint32_t> userData(8, 0u);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{32, 1, 1}, 0, {false, false, false}, false, 1};
|
||||
ShaderRecompiler::RecompileRequest request{
|
||||
{ShaderStage::Compute, reinterpret_cast<std::uintptr_t>(code.data()), code, 0, {}},
|
||||
{32, 0, userData, compute, std::nullopt, std::nullopt, memory},
|
||||
device.Target(),
|
||||
{0, 0, 0, 128}
|
||||
};
|
||||
request.useCache = false;
|
||||
return ShaderRecompiler::Recompile(request);
|
||||
}
|
||||
|
||||
void CheckRefused(AgcDriver::VulkanDevice& device, std::uint32_t word0, std::uint32_t word1, const std::string& reason, const std::string& what) {
|
||||
alignas(256) const std::array<std::uint32_t, 4> code{word0, word1, 0x3c003c00u, 0xbf810000u};
|
||||
std::string refusal;
|
||||
try {
|
||||
static_cast<void>(Compile(device, code));
|
||||
} catch (const std::exception& error) {
|
||||
refusal = error.what();
|
||||
}
|
||||
Require(refusal.find(reason) != std::string::npos, what + " " + Hex(word0) + " was not refused");
|
||||
}
|
||||
|
||||
void CheckAccepted(AgcDriver::VulkanDevice& device, std::uint32_t word0, std::uint32_t word1) {
|
||||
alignas(256) const std::array<std::uint32_t, 3> code{word0, word1, 0xbf810000u};
|
||||
static_cast<void>(Compile(device, code));
|
||||
}
|
||||
|
||||
std::uint32_t Encode(const NoFormOpcode& op, std::uint32_t form) {
|
||||
return op.vop2 ? (op.opcode << 25u) | (10u << 17u) | (5u << 9u) | form : 0x7e000000u | (10u << 17u) | (op.opcode << 9u) | form;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
constexpr std::uint32_t Dpp16 = 0xff00b104u;
|
||||
constexpr std::uint32_t Dpp8 = 0x00fac604u;
|
||||
for (const auto& op : NoFormOpcodes) {
|
||||
const std::string name = op.name;
|
||||
CheckRefused(*device, Encode(op, 0xfau), Dpp16, "DPP modifier is not supported for opcode", name + " with DPP16");
|
||||
CheckRefused(*device, Encode(op, 0xe9u), Dpp8, "DPP8 modifier is not supported for opcode", name + " with DPP8");
|
||||
CheckRefused(*device, Encode(op, 0xeau), Dpp8, "DPP8 modifier is not supported for opcode", name + " with DPP8 fi:1");
|
||||
}
|
||||
CheckAccepted(*device, 0x7e1402fau, Dpp16);
|
||||
CheckAccepted(*device, 0x4a140afau, Dpp16);
|
||||
std::puts("dpp no form tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -701,7 +701,7 @@ bool isPermlaneOpcode(RdnaOpcode opcode) {
|
||||
return opcode == RdnaOpcode::VPermlane16B32 || opcode == RdnaOpcode::VPermlanex16B32;
|
||||
}
|
||||
|
||||
bool acceptsDpp8(RdnaOpcode opcode) {
|
||||
bool hasDppForm(RdnaOpcode opcode) {
|
||||
switch (opcode) {
|
||||
case RdnaOpcode::VReadfirstlaneB32:
|
||||
case RdnaOpcode::VCvtI32F64:
|
||||
@@ -724,12 +724,19 @@ bool acceptsDpp8(RdnaOpcode opcode) {
|
||||
case RdnaOpcode::VMadakF32:
|
||||
case RdnaOpcode::VFmamkF16:
|
||||
case RdnaOpcode::VFmaakF16:
|
||||
return false;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool acceptsDpp8(RdnaOpcode opcode) {
|
||||
switch (opcode) {
|
||||
case RdnaOpcode::VPkFmacF16:
|
||||
case RdnaOpcode::VMovrelsB32:
|
||||
case RdnaOpcode::VMovrelsdB32:
|
||||
case RdnaOpcode::VMovrelsd2B32:
|
||||
return false;
|
||||
default: return true;
|
||||
default: return hasDppForm(opcode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1219,12 +1226,12 @@ void decodeVop1Dpp(std::uint32_t programCounter, std::span<const std::uint32_t>
|
||||
? DecodeRdnaScalarDestination(vdst, programCounter)
|
||||
: DecodeRdnaVectorGpr(vdst);
|
||||
instruction.source0 = DecodeRdnaScalarSource(src0 + 256u, programCounter);
|
||||
if (form == 250u) {
|
||||
if (form == 250u && hasDppForm(instruction.op)) {
|
||||
applyDppModifier(instruction.source0, modifier);
|
||||
} else if (acceptsDpp8(instruction.op)) {
|
||||
} else if (form != 250u && acceptsDpp8(instruction.op)) {
|
||||
applyDpp8Modifier(instruction.source0, modifier, form == 234u);
|
||||
} else {
|
||||
throw std::invalid_argument("DPP8 modifier is not supported for opcode");
|
||||
throw std::invalid_argument(form == 250u ? "DPP modifier is not supported for opcode" : "DPP8 modifier is not supported for opcode");
|
||||
}
|
||||
instruction.sourceCount = 1;
|
||||
|
||||
@@ -1418,14 +1425,14 @@ void decodeVop2Dpp(std::uint32_t programCounter, std::span<const std::uint32_t>
|
||||
instruction.destination = DecodeRdnaVectorGpr(vdst);
|
||||
instruction.source1 = DecodeRdnaVectorGpr(vsrc1);
|
||||
instruction.source0 = DecodeRdnaScalarSource(src0 + 256u, programCounter);
|
||||
if (form == 250u) {
|
||||
if (form == 250u && hasDppForm(instruction.op)) {
|
||||
applyDppModifier(instruction.source0, modifier);
|
||||
instruction.source1.negate = ((modifier >> 22u) & 0x1u) != 0u;
|
||||
instruction.source1.absolute = ((modifier >> 23u) & 0x1u) != 0u;
|
||||
} else if (acceptsDpp8(instruction.op)) {
|
||||
} else if (form != 250u && acceptsDpp8(instruction.op)) {
|
||||
applyDpp8Modifier(instruction.source0, modifier, form == 234u);
|
||||
} else {
|
||||
throw std::invalid_argument("DPP8 modifier is not supported for opcode");
|
||||
throw std::invalid_argument(form == 250u ? "DPP modifier is not supported for opcode" : "DPP8 modifier is not supported for opcode");
|
||||
}
|
||||
const bool packedFmac = instruction.op == RdnaOpcode::VPkFmacF16;
|
||||
if (packedFmac) {
|
||||
|
||||
Reference in New Issue
Block a user