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
77 changes: 77 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/CacheControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
#include "Recompiler.hpp"
#include "VulkanTestDevice.hpp"
#include <array>
#include <cstdio>
#include <iostream>
#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, 23> CacheControlCode{
0x34020082, 0xbf930000, 0xbf940001, 0xe0302000, 0x80000401, 0xf4840000, 0x00000000, 0xf4800000,
0x00000000, 0xf47c0000, 0x00000000, 0xe1c80000, 0x00000000, 0xe1c40000, 0x00000000, 0xbfa20000,
0xbf8c3f70, 0xbfa80001, 0x4a080881, 0xbf950001, 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(CacheControlCode);
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, "cache control: 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("cache control 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 @@ -595,6 +595,15 @@ enum class RdnaOpcode : std::uint16_t {
SInstPrefetch,
SClause,
SCbranchCdbg,
SIcacheInv,
SIncperflevel,
SDecperflevel,
SWaitIdle,
SGl1Inv,
SDcacheInv,
SDcacheWb,
BufferGl0Inv,
BufferGl1Inv,
Exp,
VMulHiI32I24,
VMulHiU32U24,
Expand Down
32 changes: 32 additions & 0 deletions core/shader/recompiler/RdnaDecoder/src/RdnaMemoryOpDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,32 @@ std::uint32_t toProgramCounter(std::uint32_t wordIndex) {
return wordIndex * 4u;
}

RdnaOpcode cacheControlOpcode(RdnaInstructionFamily family, std::uint32_t opcode) {
if (family == RdnaInstructionFamily::SMEM) {
switch (opcode) {
case 0x1fu: return RdnaOpcode::SGl1Inv;
case 0x20u: return RdnaOpcode::SDcacheInv;
case 0x21u: return RdnaOpcode::SDcacheWb;
default: return RdnaOpcode::Invalid;
}
}
switch (opcode) {
case 0x71u: return RdnaOpcode::BufferGl0Inv;
case 0x72u: return RdnaOpcode::BufferGl1Inv;
default: return RdnaOpcode::Invalid;
}
}

RdnaInstruction cacheControlInstruction(RdnaInstructionFamily family, RdnaOpcode op, std::uint32_t opcode, std::uint32_t programCounter, std::span<const std::uint32_t> code, std::uint32_t wordIndex) {
RdnaInstruction instruction{};
instruction.programCounter = programCounter;
instruction.family = family;
instruction.opcodeId = opcode;
instruction.op = op;
setRawWords(instruction, code, wordIndex, 2u);
return instruction;
}

}

RdnaInstruction DecodeRdnaSmem(std::uint32_t programCounter, std::span<const std::uint32_t> code, std::uint32_t wordIndex) {
Expand All @@ -371,6 +397,9 @@ RdnaInstruction DecodeRdnaSmem(std::uint32_t programCounter, std::span<const std
const auto sdst = (word0 >> 6u) & 0x7Fu;
const auto sbase = word0 & 0x3Fu;
const auto soffsetCode = (word1 >> 25u) & 0x7Fu;
if (const auto cacheOp = cacheControlOpcode(RdnaInstructionFamily::SMEM, opcode); cacheOp != RdnaOpcode::Invalid) {
return cacheControlInstruction(RdnaInstructionFamily::SMEM, cacheOp, opcode, programCounter, code, wordIndex);
}
const auto& info = lookupOpcode(smemOpcodes, opcode, "SMEM opcode is not supported");

RdnaInstruction instruction{};
Expand Down Expand Up @@ -413,6 +442,9 @@ RdnaInstruction DecodeRdnaMubuf(std::uint32_t programCounter, std::span<const st
const auto vaddr = word1 & 0xFFu;
const auto srsrc = (word1 >> 16u) & 0x1Fu;
const auto soffsetCode = (word1 >> 24u) & 0xFFu;
if (const auto cacheOp = cacheControlOpcode(RdnaInstructionFamily::MUBUF, opcode); cacheOp != RdnaOpcode::Invalid) {
return cacheControlInstruction(RdnaInstructionFamily::MUBUF, cacheOp, opcode, programCounter, code, wordIndex);
}
const auto& info = lookupOpcode(mubufOpcodes, opcode, "MUBUF opcode is not supported");

RdnaInstruction instruction{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,19 @@ RdnaOpcode decodeSoppOpcode(std::uint32_t opcode) {
case 0x0fu: return RdnaOpcode::SSetprio;
case 0x10u: return RdnaOpcode::SSendmsg;
case 0x12u: return RdnaOpcode::STrap;
case 0x13u: return RdnaOpcode::SIcacheInv;
case 0x14u: return RdnaOpcode::SIncperflevel;
case 0x15u: return RdnaOpcode::SDecperflevel;
case 0x16u: return RdnaOpcode::STtracedata;
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1au: return RdnaOpcode::SCbranchCdbg;
case 0x20u: return RdnaOpcode::SInstPrefetch;
case 0x21u: return RdnaOpcode::SClause;
case 0x22u: return RdnaOpcode::SWaitIdle;
case 0x23u: return RdnaOpcode::SWaitcntDepctr;
case 0x28u: return RdnaOpcode::STtracedata;
default: throw std::invalid_argument("unsupported SOPP opcode " + std::to_string(opcode));
}
}
Expand All @@ -199,7 +204,8 @@ bool isSoppWaitOpcode(RdnaOpcode opcode) {
return opcode == RdnaOpcode::SNop || opcode == RdnaOpcode::SWaitcnt || opcode == RdnaOpcode::SWaitcntDepctr ||
opcode == RdnaOpcode::SSleep || opcode == RdnaOpcode::SSetprio || opcode == RdnaOpcode::SSendmsg ||
opcode == RdnaOpcode::STrap || opcode == RdnaOpcode::STtracedata || opcode == RdnaOpcode::SInstPrefetch ||
opcode == RdnaOpcode::SClause || opcode == RdnaOpcode::SCbranchCdbg;
opcode == RdnaOpcode::SClause || opcode == RdnaOpcode::SCbranchCdbg || opcode == RdnaOpcode::SIcacheInv ||
opcode == RdnaOpcode::SIncperflevel || opcode == RdnaOpcode::SDecperflevel || opcode == RdnaOpcode::SWaitIdle;
}

std::uint32_t scalarDestinationDwordCount(RdnaOpcode opcode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ void TranslateMemoryInstruction(IrBuilder& builder, const RdnaInstruction& instr

bool TranslationContext::emitMemory(const RdnaInstruction& inst) {
switch (inst.op) {
case RdnaOpcode::SGl1Inv:
case RdnaOpcode::SDcacheInv:
case RdnaOpcode::SDcacheWb:
case RdnaOpcode::BufferGl0Inv:
case RdnaOpcode::BufferGl1Inv:
emitControlNop();
return true;

case RdnaOpcode::SLoadDword:
case RdnaOpcode::SLoadDwordx2:
case RdnaOpcode::SLoadDwordx4:
Expand Down
4 changes: 4 additions & 0 deletions core/shader/recompiler/Translation/src/ScalarInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,13 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) {
case RdnaOpcode::SSetprio:
case RdnaOpcode::STrap:
case RdnaOpcode::SClause:
case RdnaOpcode::SIcacheInv:
case RdnaOpcode::SIncperflevel:
case RdnaOpcode::SDecperflevel:
emitControlNop();
return true;
case RdnaOpcode::SWaitcntDepctr:
case RdnaOpcode::SWaitIdle:
emitWaitcnt();
return true;
case RdnaOpcode::SBarrier:
Expand Down
Loading