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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ jobs:
key: linux
save: ${{ github.event_name == 'push' }}
evict-old-files: job
- name: Install lavapipe for the GPU execution tests
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libvulkan1 mesa-vulkan-drivers
- run: cmake -S . -B build $CONFIGURE
- run: cmake --build build
- run: cmake --build build --target libs
- run: ctest --test-dir build --output-on-failure --timeout 120
env:
ANYPS5_REQUIRE_VULKAN: 1

windows:
runs-on: windows-latest
Expand Down
44 changes: 19 additions & 25 deletions core/libs/prx/libSceAgcDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,36 +392,30 @@ target_link_libraries(agc_driver_mesh_tests PRIVATE shader_recompiler_agc_driver
set_target_properties(agc_driver_mesh_tests PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(agc_driver_mesh_tests)

add_test_executable(agc_driver_mix_precision_tests EXCLUDE_FROM_ALL
tests/MixPrecision.cpp
)
target_include_directories(agc_driver_mix_precision_tests PRIVATE
${LIBS_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/core/shader/recompiler
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
)
target_link_libraries(agc_driver_mix_precision_tests PRIVATE libSceAgcDriver SDL2-static libc)
set_target_properties(agc_driver_mix_precision_tests PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(agc_driver_mix_precision_tests)

add_test_executable(agc_driver_sdwa_destination_tests EXCLUDE_FROM_ALL
tests/SdwaDestination.cpp
)
target_include_directories(agc_driver_sdwa_destination_tests PRIVATE
${LIBS_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/core/shader/recompiler
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
)
target_link_libraries(agc_driver_sdwa_destination_tests PRIVATE libSceAgcDriver SDL2-static libc)
set_target_properties(agc_driver_sdwa_destination_tests PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(agc_driver_sdwa_destination_tests)
file(GLOB agcExecutionTestSources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/execution/*.cpp)
set(agcExecutionTests)
foreach(agcExecutionTestSource IN LISTS agcExecutionTestSources)
get_filename_component(agcExecutionTestName ${agcExecutionTestSource} NAME_WE)
string(REGEX REPLACE "([a-z0-9])([A-Z])" "\\1_\\2" agcExecutionTestName "${agcExecutionTestName}")
string(TOLOWER "agc_driver_${agcExecutionTestName}_tests" agcExecutionTest)
add_test_executable(${agcExecutionTest} EXCLUDE_FROM_ALL ${agcExecutionTestSource})
target_include_directories(${agcExecutionTest} PRIVATE
${LIBS_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/core/shader/recompiler
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
)
target_link_libraries(${agcExecutionTest} PRIVATE libSceAgcDriver SDL2-static libc)
set_target_properties(${agcExecutionTest} PROPERTIES CXX_EXTENSIONS OFF)
configure_windows_unwind(${agcExecutionTest})
list(APPEND agcExecutionTests ${agcExecutionTest})
endforeach()

if(BUILD_TESTING)
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests)
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests})
string(REGEX REPLACE "_tests$" "" agcTestName "${agcTest}")
set_target_properties(${agcTest} PROPERTIES EXCLUDE_FROM_ALL OFF)
add_test(NAME ${agcTestName} COMMAND ${agcTest})
set_tests_properties(${agcTestName} PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1")
set_tests_properties(${agcTestName} PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" SKIP_RETURN_CODE 77)
if(WIN32)
set_tests_properties(${agcTestName} PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
Expand Down
149 changes: 149 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/LdsAtomics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#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 <bit>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

namespace {

using AgcDriver::Graphics::Require;
using ShaderRecompiler::ShaderStage;

constexpr std::uint32_t Threads = 32;
constexpr std::uint32_t Inputs = 4;
constexpr std::uint32_t Results = 32;
alignas(256) std::array<std::uint32_t, Threads * Inputs> Input{};
alignas(256) std::array<std::uint32_t, Threads * Results> Output{};

alignas(256) constexpr std::array<std::uint32_t, 168> Code{
0x34020084, 0x34060087, 0x343c0082, 0xe0301000, 0x80000401, 0xe0301004, 0x80000501, 0xe0301008,
0x80000601, 0xbf8c3f70, 0xd8340000, 0x0000041e, 0xd8340080, 0x0000041e, 0xd8340100, 0x0000041e,
0xd8340180, 0x0000041e, 0xd8340200, 0x0000041e, 0xd8340280, 0x0000041e, 0xd8340300, 0x0000041e,
0xd8340380, 0x0000041e, 0xd8340400, 0x0000041e, 0xd8340480, 0x0000041e, 0xd8340500, 0x0000041e,
0xd8340580, 0x0000041e, 0xd8340600, 0x0000041e, 0xd8340680, 0x0000041e, 0xd8340700, 0x0000041e,
0xd8340780, 0x0000041e, 0xd8340800, 0x0000041e, 0xbf8cc07f, 0xd8500000, 0x00000000, 0xd8080000,
0x0000051e, 0xd8880080, 0x1400051e, 0xd80c0100, 0x0000051e, 0xd8100180, 0x0000051e, 0xd8300200,
0x0006051e, 0xd8400280, 0x0006051e, 0xd8440300, 0x0006051e, 0xd8540380, 0x0000051e, 0xd8b00400,
0x1506051e, 0xd8c00480, 0x1606051e, 0xd8c40500, 0x1806051e, 0xd8c80580, 0x1700051e, 0xd8cc0600,
0x1900051e, 0xd8d00680, 0x1a06051e, 0xd9540700, 0x1b00051e, 0xd8480780, 0x0000051e, 0xd84c0800,
0x0000051e, 0xbf8cc07f, 0xd8d80000, 0x2800001e, 0xd8d80080, 0x2900001e, 0xd8d80100, 0x2a00001e,
0xd8d80180, 0x2b00001e, 0xd8d80200, 0x2c00001e, 0xd8d80280, 0x2d00001e, 0xd8d80300, 0x2e00001e,
0xd8d80380, 0x2f00001e, 0xd8d80400, 0x3000001e, 0xd8d80480, 0x3100001e, 0xd8d80500, 0x3200001e,
0xd8d80580, 0x3300001e, 0xd8d80600, 0x3400001e, 0xd8d80680, 0x3500001e, 0xd8d80700, 0x3600001e,
0xd8d80780, 0x3700001e, 0xd8d80800, 0x3800001e, 0xbf8cc07f, 0xe0701000, 0x80012803, 0xe0701004,
0x80012903, 0xe0701008, 0x80012a03, 0xe070100c, 0x80012b03, 0xe0701010, 0x80012c03, 0xe0701014,
0x80012d03, 0xe0701018, 0x80012e03, 0xe070101c, 0x80012f03, 0xe0701020, 0x80013003, 0xe0701024,
0x80013103, 0xe0701028, 0x80013203, 0xe070102c, 0x80013303, 0xe0701030, 0x80013403, 0xe0701034,
0x80013503, 0xe0701038, 0x80013603, 0xe070103c, 0x80013703, 0xe0701040, 0x80013803, 0xe0701044,
0x80011403, 0xe0701048, 0x80011503, 0xe070104c, 0x80011603, 0xe0701050, 0x80011803, 0xe0701054,
0x80011703, 0xe0701058, 0x80011903, 0xe070105c, 0x80011a03, 0xe0701060, 0x80011b03, 0xbf810000,
};

std::uint32_t Bits(float value) { return std::bit_cast<std::uint32_t>(value); }
float Value(std::uint32_t bits) { return std::bit_cast<float>(bits); }
bool Nan(std::uint32_t bits) { return (bits & 0x7fffffffu) > 0x7f800000u; }
bool Denormal(std::uint32_t bits) { return (bits & 0x7f800000u) == 0u && (bits & 0x007fffffu) != 0u; }
std::uint32_t MinMax(std::uint32_t old, std::uint32_t data, bool max) {
if (Nan(old)) return data;
if (Nan(data)) return old;
if (((old | data) & 0x7fffffffu) == 0u) return max ? (old & data) : (old | data);
return (max ? Value(data) > Value(old) : Value(data) < Value(old)) ? data : old;
}
void Fill(std::uint32_t tid, std::uint32_t* words) {
constexpr std::array<std::uint32_t, 8> floats{0x00000000u, 0x80000000u, 0x3f800000u, 0xbf800000u, 0x7fc00000u, 0x7f800000u, 0x40200000u, 0xc0400000u};
const std::uint32_t kind = tid % 4u;
const std::uint32_t seed = tid * 0x9e3779b9u + 0x7f4a7c15u;
if (kind == 0u) { words[0] = seed; words[1] = seed * 0x85ebca6bu; words[2] = seed ^ 0xc2b2ae35u; }
if (kind == 1u) { words[0] = tid % 7u; words[1] = (tid * 3u) % 7u; words[2] = tid % 5u; }
if (kind == 2u) { words[0] = floats[tid % 8u]; words[1] = floats[(tid / 2u + 3u) % 8u]; words[2] = floats[(tid + 5u) % 8u]; }
if (kind == 3u) { words[0] = seed; words[1] = (tid & 4u) != 0u ? seed : seed + 1u; words[2] = seed * 3u; }
}

std::array<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t bytes) {
const auto address = reinterpret_cast<std::uintptr_t>(data);
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), bytes, 0x01016facu};
}

std::string Hex(std::uint32_t value) {
char text[16];
std::snprintf(text, sizeof(text), "0x%08x", value);
return text;
}

void Expect(std::uint32_t tid, std::uint32_t actual, std::uint32_t expected, const char* name) {
Require(actual == expected, std::string("lds atomics: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected));
}

void Run(AgcDriver::VulkanDevice& device) {
for (std::uint32_t tid = 0; tid < Threads; ++tid) Fill(tid, &Input[tid * Inputs]);
Output.fill(0xdeadbeefu);
std::vector<std::uint32_t> userData(8, 0u);
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size() * 4u));
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size() * 4u));
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(Code);
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}, 4096u, {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 std::uint32_t* in = &Input[tid * Inputs];
const std::uint32_t* out = &Output[tid * Results];
const std::uint32_t a = in[0];
const std::uint32_t b = in[1];
const std::uint32_t c = in[2];
const std::uint32_t sum = Nan(Bits(Value(a) + Value(b))) ? 0x7fc00000u : Bits(Value(a) + Value(b));
const std::array<std::uint32_t, 17> memory{
b - a, b - a, a >= b ? 0u : a + 1u, (a == 0u || a > b) ? b : a - 1u,
(a & ~b) | c, a == b ? c : a, Value(a) == Value(b) ? c : a, sum,
(a & ~b) | c, a == b ? c : a, Value(a) == Value(b) ? c : a, MinMax(a, b, false),
MinMax(a, b, true), a >= b ? a - b : a + c, sum, MinMax(a, b, false), MinMax(a, b, true),
};
constexpr std::array<const char*, 17> names{"ds_rsub_u32", "ds_rsub_rtn_u32", "ds_inc_u32", "ds_dec_u32", "ds_mskor_b32", "ds_cmpst_b32", "ds_cmpst_f32", "ds_add_f32",
"ds_mskor_rtn_b32", "ds_cmpst_rtn_b32", "ds_cmpst_rtn_f32", "ds_min_rtn_f32", "ds_max_rtn_f32", "ds_wrap_rtn_b32", "ds_add_rtn_f32", "ds_min_f32", "ds_max_f32"};
constexpr std::uint32_t floatOps = (1u << 6u) | (1u << 7u) | (1u << 10u) | (1u << 11u) | (1u << 12u) | (1u << 14u) | (1u << 15u) | (1u << 16u);
const bool denormal = Denormal(a) || Denormal(b) || Denormal(sum);
for (std::uint32_t j = 0; j < memory.size(); ++j) {
if (denormal && ((floatOps >> j) & 1u) != 0u) continue;
const bool bothNan = Nan(out[j]) && Nan(memory[j]);
Expect(tid, bothNan ? memory[j] : out[j], memory[j], names[j]);
}
for (std::uint32_t j = 17; j < 25; ++j) Expect(tid, out[j], a, "returned value");
}
}

}

int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("lds atomics tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
#include "Recompiler.hpp"
#include "VulkanTestDevice.hpp"
#include <array>
#include <bit>
#include <cmath>
Expand Down Expand Up @@ -134,9 +135,10 @@ void Check() {

int main() {
try {
AgcDriver::VulkanDevice device;
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
FillInput();
Run(device);
Run(*device);
Check();
std::puts("mix precision tests passed");
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
#include "Recompiler.hpp"
#include "VulkanTestDevice.hpp"
#include <array>
#include <bit>
#include <cmath>
Expand Down Expand Up @@ -105,9 +106,10 @@ void Check() {

int main() {
try {
AgcDriver::VulkanDevice device;
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
FillInput();
Run(device);
Run(*device);
Check();
std::puts("sdwa destination tests passed");
return 0;
Expand Down
22 changes: 22 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/VulkanTestDevice.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CORE_LIBS_PRX_LIBSCEAGCDRIVER_TESTS_VULKANTESTDEVICE_HPP
#define CORE_LIBS_PRX_LIBSCEAGCDRIVER_TESTS_VULKANTESTDEVICE_HPP

#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
#include <cstdio>
#include <cstdlib>
#include <exception>
#include <memory>

constexpr int VulkanTestSkipped = 77;

inline std::unique_ptr<AgcDriver::VulkanDevice> OpenVulkanTestDevice() {
try {
return std::make_unique<AgcDriver::VulkanDevice>();
} catch (const std::exception& error) {
if (std::getenv("ANYPS5_REQUIRE_VULKAN") != nullptr) throw;
std::printf("skipped, no usable Vulkan device: %s\n", error.what());
return nullptr;
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ enum class IrOpcode : std::uint16_t {
SharedAtomicAnd32,
SharedAtomicOr32,
SharedAtomicXor32,
SharedAtomicRsub32,
SharedAtomicFAdd32,
SharedAtomicCmpst32,
SharedAtomicCmpstF32,
SharedAtomicMskor32,
SharedAtomicWrap32,
DataAppend,
DataConsume,
SwizzleU32,
Expand Down
16 changes: 14 additions & 2 deletions core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ constexpr std::array<OpcodeMeta, static_cast<std::size_t>(IrOpcode::Count)> Meta
makeMeta("WriteSharedU32x2", Void, U32, U32, U32, U1),
makeMeta("WriteSharedU32x3", Void, U32, U32, U32, U32, U1),
makeMeta("WriteSharedU32x4", Void, U32, U32, U32, U32, U32, U1),
makeMeta("SharedAtomicFMin32", Void, U32, U32, U32, U1),
makeMeta("SharedAtomicFMax32", Void, U32, U32, U32, U1),
makeMeta("SharedAtomicFMin32", U32, U32, U32, U1),
makeMeta("SharedAtomicFMax32", U32, U32, U32, U1),
makeMeta("SharedAtomicSwap32", U32, U32, U32, U1),
makeMeta("SharedAtomicIAdd32", U32, U32, U32, U1),
makeMeta("SharedAtomicISub32", U32, U32, U32, U1),
Expand All @@ -357,6 +357,12 @@ constexpr std::array<OpcodeMeta, static_cast<std::size_t>(IrOpcode::Count)> Meta
makeMeta("SharedAtomicAnd32", U32, U32, U32, U1),
makeMeta("SharedAtomicOr32", U32, U32, U32, U1),
makeMeta("SharedAtomicXor32", U32, U32, U32, U1),
makeMeta("SharedAtomicRsub32", U32, U32, U32, U1),
makeMeta("SharedAtomicFAdd32", U32, U32, U32, U1),
makeMeta("SharedAtomicCmpst32", U32, U32, U32, U32, U1),
makeMeta("SharedAtomicCmpstF32", U32, U32, U32, U32, U1),
makeMeta("SharedAtomicMskor32", U32, U32, U32, U32, U1),
makeMeta("SharedAtomicWrap32", U32, U32, U32, U32, U1),
makeMeta("DataAppend", U32, U32, U1, U32, U32),
makeMeta("DataConsume", U32, U32, U1, U32, U32),
makeMeta("SwizzleU32", U32, U32, U32, U1),
Expand Down Expand Up @@ -501,6 +507,12 @@ SharedAccess SharedAccessOf(IrOpcode opcode) {
case IrOpcode::SharedAtomicAnd32:
case IrOpcode::SharedAtomicOr32:
case IrOpcode::SharedAtomicXor32:
case IrOpcode::SharedAtomicRsub32:
case IrOpcode::SharedAtomicFAdd32:
case IrOpcode::SharedAtomicCmpst32:
case IrOpcode::SharedAtomicCmpstF32:
case IrOpcode::SharedAtomicMskor32:
case IrOpcode::SharedAtomicWrap32:
return SharedAccess::Atomic;
case IrOpcode::DataAppend:
return SharedAccess::Append;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,22 @@ enum class RdnaOpcode : std::uint16_t {
DsWriteB8,
DsWriteB16,
DsWriteB16D16Hi,
DsRsubU32,
DsIncU32,
DsDecU32,
DsAddF32,
DsRsubRtnU32,
DsMinRtnF32,
DsMaxRtnF32,
DsAddRtnF32,
DsMskorB32,
DsCmpstB32,
DsCmpstF32,
DsMskorRtnB32,
DsCmpstRtnB32,
DsCmpstRtnF32,
DsWrapRtnB32,
DsNop,
DsWrite2st64B32,
DsWrite2B64,
DsWrite2st64B64,
Expand Down
Loading
Loading