mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #372 from DotDebian/feat/shader-s-wakeup
feat(shader): decode s_wakeup as a no-op
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
|
||||
#include "Recompiler.hpp"
|
||||
#include "VulkanTestDevice.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
constexpr std::uint32_t Threads = 64;
|
||||
constexpr std::uint32_t Stride = 4;
|
||||
alignas(256) std::array<std::uint32_t, Threads * Stride> Input{};
|
||||
alignas(256) std::array<std::uint32_t, Threads * Stride> Output{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 12> WaveSleepCode{
|
||||
0x34020082, 0xbf830000, 0xe0302000, 0x80000401, 0xbf8c3f70, 0xbf8e0001,
|
||||
0xbf830000, 0x4a080881, 0xbf830000, 0xe0702000, 0x80010401, 0xbf810000,
|
||||
};
|
||||
|
||||
std::array<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t count) {
|
||||
const auto address = reinterpret_cast<std::uintptr_t>(data);
|
||||
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu) | (4u << 16u), count, 0x01016facu};
|
||||
}
|
||||
|
||||
void Run(AgcDriver::VulkanDevice& device) {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) Input[tid * Stride] = tid * 0x01010101u + 7u;
|
||||
Output.fill(0xdeadbeefu);
|
||||
std::vector<std::uint32_t> userData(8, 0u);
|
||||
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size()));
|
||||
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size()));
|
||||
std::copy(input.begin(), input.end(), userData.begin());
|
||||
std::copy(output.begin(), output.end(), userData.begin() + 4);
|
||||
const std::span<const std::uint32_t> code(WaveSleepCode);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 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;
|
||||
const auto result = ShaderRecompiler::Recompile(request);
|
||||
device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void Check() {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
const auto expected = Input[tid * Stride] + 1u;
|
||||
const auto actual = Output[tid * Stride];
|
||||
Require(actual == expected, "wave sleep: thread " + std::to_string(tid) + " is " + std::to_string(actual) + ", expected " + std::to_string(expected));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
std::puts("wave sleep tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -794,6 +794,7 @@ enum class RdnaOpcode : std::uint16_t {
|
||||
SSendmsg,
|
||||
SSetregB32,
|
||||
SSleep,
|
||||
SWakeup,
|
||||
STrap,
|
||||
STtracedata,
|
||||
SInstPrefetch,
|
||||
|
||||
@@ -189,6 +189,7 @@ RdnaOpcode decodeSoppOpcode(std::uint32_t opcode) {
|
||||
case 0x00u: return RdnaOpcode::SNop;
|
||||
case 0x01u: return RdnaOpcode::SEndpgm;
|
||||
case 0x02u: return RdnaOpcode::SBranch;
|
||||
case 0x03u: return RdnaOpcode::SWakeup;
|
||||
case 0x04u: return RdnaOpcode::SCbranchScc0;
|
||||
case 0x05u: return RdnaOpcode::SCbranchScc1;
|
||||
case 0x06u: return RdnaOpcode::SCbranchVccz;
|
||||
|
||||
@@ -370,6 +370,7 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) {
|
||||
return packB16(inst, true, true);
|
||||
case RdnaOpcode::SNop:
|
||||
case RdnaOpcode::SSleep:
|
||||
case RdnaOpcode::SWakeup:
|
||||
case RdnaOpcode::SSetprio:
|
||||
case RdnaOpcode::STrap:
|
||||
case RdnaOpcode::SClause:
|
||||
|
||||
Reference in New Issue
Block a user