mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge remote-tracking branch 'upstream/main' into feat/http2-cookie-box
# Conflicts: # docs/dev/TechnicalDebt.md
This commit is contained in:
@@ -28,3 +28,6 @@
|
||||
[submodule "3rdparty/stb"]
|
||||
path = 3rdparty/stb
|
||||
url = https://github.com/nothings/stb.git
|
||||
[submodule "3rdparty/libjpeg-turbo"]
|
||||
path = 3rdparty/libjpeg-turbo
|
||||
url = https://github.com/libjpeg-turbo/libjpeg-turbo.git
|
||||
|
||||
+1
Submodule 3rdparty/libjpeg-turbo added at c85e6b905b
@@ -7,6 +7,7 @@
|
||||
- A silent stub is allowed only when it unblocks a title and only affects the UI; add it to [silent stubs](docs/dev/TechnicalDebt.md#silent-stubs).
|
||||
- Missing imports fail at startup with a clear error; don't replace them with fallbacks that keep running.
|
||||
- Implement the general behaviour of a function, not what one title happens to need.
|
||||
- Don't add replacements for modules that titles ship themselves in `sce_module/`, `sce_modules/` or `prx/`: engine or middleware modules (Cohtml, FMOD, GOG Galaxy) and SDK libraries that only wrap other system libraries (NpCppWebApi over NpWebApi2). The relinker converts and loads the title's own module, and a host library with the same name is left out of `DT_NEEDED`. Only system libraries, which reach the kernel or the hardware, are reimplemented in [core/libs/prx](core/libs/prx).
|
||||
- Avoid non-standard extensions (`__attribute__`, etc.) where standard C++ is enough. Helper symbols that must not become NIDs use the `_nid_no_patch` or `_nid_no_patch_cut` suffix.
|
||||
- The relinker uses only the C++20 standard library.
|
||||
- Third-party code is added as a submodule under `3rdparty/` and built from source, not found on the system.
|
||||
|
||||
@@ -3,10 +3,56 @@ function(add_jpeg_decoder target runtimeTarget)
|
||||
message(FATAL_ERROR "JPEG decoder requires an existing runtime target: ${runtimeTarget}")
|
||||
endif()
|
||||
|
||||
include(ExternalProject)
|
||||
if(NOT TARGET jpeg_turbo_external)
|
||||
set(jpeg_turbo_prefix "${CMAKE_BINARY_DIR}/libjpeg-turbo")
|
||||
if(WIN32)
|
||||
if(MSVC)
|
||||
set(jpeg_turbo_library "${jpeg_turbo_prefix}/lib/turbojpeg-static.lib")
|
||||
else()
|
||||
set(jpeg_turbo_library "${jpeg_turbo_prefix}/lib/libturbojpeg.a")
|
||||
endif()
|
||||
else()
|
||||
set(jpeg_turbo_library "${jpeg_turbo_prefix}/lib/libturbojpeg.a")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY "${jpeg_turbo_prefix}/include")
|
||||
ExternalProject_Add(jpeg_turbo_external
|
||||
SOURCE_DIR "${PROJECT_SOURCE_DIR}/3rdparty/libjpeg-turbo"
|
||||
BINARY_DIR "${CMAKE_BINARY_DIR}/libjpeg-turbo-build"
|
||||
INSTALL_DIR "${jpeg_turbo_prefix}"
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_INSTALL_PREFIX=${jpeg_turbo_prefix}
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DENABLE_STATIC=ON
|
||||
-DENABLE_SHARED=OFF
|
||||
-DWITH_SIMD=OFF
|
||||
-DWITH_TURBOJPEG=ON
|
||||
-DWITH_TOOLS=OFF
|
||||
-DWITH_TESTS=OFF
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
-DCMAKE_C_VISIBILITY_PRESET=hidden
|
||||
-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
|
||||
BUILD_BYPRODUCTS
|
||||
"${jpeg_turbo_library}"
|
||||
)
|
||||
add_library(jpeg_turbo STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(jpeg_turbo PROPERTIES
|
||||
IMPORTED_LOCATION "${jpeg_turbo_library}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/libjpeg-turbo/src;${jpeg_turbo_prefix}/include"
|
||||
)
|
||||
add_dependencies(jpeg_turbo jpeg_turbo_external)
|
||||
endif()
|
||||
|
||||
add_library(${target} STATIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src/Jpeg.cpp)
|
||||
target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include)
|
||||
target_include_directories(${target} SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/stb)
|
||||
target_link_libraries(${target} PRIVATE ${runtimeTarget})
|
||||
target_link_libraries(${target} PRIVATE ${runtimeTarget} jpeg_turbo)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
CXX_EXTENSIONS OFF
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
|
||||
@@ -21,8 +21,14 @@ struct Header {
|
||||
std::uint32_t channels;
|
||||
};
|
||||
|
||||
enum class Sampling {
|
||||
Yuv444,
|
||||
Yuv422,
|
||||
Yuv420,
|
||||
};
|
||||
|
||||
std::vector<std::uint8_t> Encode(std::span<const std::uint8_t> pixels, std::uint32_t width, std::uint32_t height,
|
||||
std::uint32_t channels, int quality);
|
||||
std::uint32_t channels, int quality, Sampling sampling = Sampling::Yuv444);
|
||||
|
||||
std::optional<Header> ParseHeader(std::span<const std::uint8_t> jpeg);
|
||||
|
||||
|
||||
@@ -4,16 +4,12 @@
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
|
||||
#define STB_IMAGE_WRITE_STATIC
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define STBI_WRITE_NO_STDIO
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#define STB_IMAGE_STATIC
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ONLY_JPEG
|
||||
#define STBI_NO_STDIO
|
||||
#include "stb_image.h"
|
||||
#include "turbojpeg.h"
|
||||
|
||||
namespace Decoder::Jpeg {
|
||||
|
||||
@@ -21,16 +17,39 @@ namespace {
|
||||
|
||||
constexpr std::uint32_t MAX_DIMENSION = 0xFFFF;
|
||||
|
||||
void appendBytes(void* context, void* data, int size) {
|
||||
auto* output = static_cast<std::vector<std::uint8_t>*>(context);
|
||||
const auto* bytes = static_cast<const std::uint8_t*>(data);
|
||||
output->insert(output->end(), bytes, bytes + size);
|
||||
class Handle {
|
||||
public:
|
||||
Handle() : handle(tj3Init(TJINIT_COMPRESS)) {
|
||||
if (!handle) throw std::runtime_error("Jpeg::Encode: encoder initialization failed");
|
||||
}
|
||||
~Handle() { tj3Destroy(handle); }
|
||||
Handle(const Handle&) = delete;
|
||||
Handle& operator=(const Handle&) = delete;
|
||||
operator tjhandle() const { return handle; }
|
||||
|
||||
private:
|
||||
tjhandle handle;
|
||||
};
|
||||
|
||||
class Buffer {
|
||||
public:
|
||||
~Buffer() { tj3Free(data); }
|
||||
unsigned char* data = nullptr;
|
||||
};
|
||||
|
||||
int toSubsampling(Sampling sampling) {
|
||||
switch (sampling) {
|
||||
case Sampling::Yuv444: return TJSAMP_444;
|
||||
case Sampling::Yuv422: return TJSAMP_422;
|
||||
case Sampling::Yuv420: return TJSAMP_420;
|
||||
}
|
||||
throw std::invalid_argument("Jpeg::Encode: invalid sampling");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<std::uint8_t> Encode(std::span<const std::uint8_t> pixels, std::uint32_t width, std::uint32_t height,
|
||||
std::uint32_t channels, int quality) {
|
||||
std::uint32_t channels, int quality, Sampling sampling) {
|
||||
if (width == 0 || height == 0 || width > MAX_DIMENSION || height > MAX_DIMENSION) {
|
||||
throw std::invalid_argument("Jpeg::Encode: unsupported image size");
|
||||
}
|
||||
@@ -39,12 +58,18 @@ std::vector<std::uint8_t> Encode(std::span<const std::uint8_t> pixels, std::uint
|
||||
if (pixels.size() < static_cast<std::size_t>(width) * height * channels) {
|
||||
throw std::invalid_argument("Jpeg::Encode: pixel buffer is too small");
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> output;
|
||||
const int written = stbi_write_jpg_to_func(appendBytes, &output, static_cast<int>(width), static_cast<int>(height),
|
||||
static_cast<int>(channels), pixels.data(), quality);
|
||||
if (written == 0) throw std::runtime_error("Jpeg::Encode: encoding failed");
|
||||
return output;
|
||||
const int subsampling = toSubsampling(sampling);
|
||||
Handle handle;
|
||||
if (tj3Set(handle, TJPARAM_QUALITY, quality) < 0 || tj3Set(handle, TJPARAM_SUBSAMP, channels == 1 ? TJSAMP_GRAY : subsampling) < 0) {
|
||||
throw std::runtime_error("Jpeg::Encode: encoder configuration failed");
|
||||
}
|
||||
Buffer buffer;
|
||||
std::size_t size = 0;
|
||||
const int pixelFormat = channels == 1 ? TJPF_GRAY : TJPF_RGB;
|
||||
if (tj3Compress8(handle, pixels.data(), static_cast<int>(width), 0, static_cast<int>(height), pixelFormat, &buffer.data, &size) < 0) {
|
||||
throw std::runtime_error("Jpeg::Encode: encoding failed");
|
||||
}
|
||||
return {buffer.data, buffer.data + size};
|
||||
}
|
||||
|
||||
std::optional<Header> ParseHeader(std::span<const std::uint8_t> jpeg) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
@@ -25,6 +26,25 @@ static int Difference(std::uint8_t left, std::uint8_t right) {
|
||||
return left > right ? left - right : right - left;
|
||||
}
|
||||
|
||||
struct FrameInfo { int components; std::uint8_t sampling; };
|
||||
|
||||
static FrameInfo ReadFrame(const std::vector<std::uint8_t>& jpeg) {
|
||||
std::size_t offset = 2;
|
||||
while (offset + 3 < jpeg.size()) {
|
||||
Require(jpeg[offset++] == 0xFF);
|
||||
while (offset < jpeg.size() && jpeg[offset] == 0xFF) ++offset;
|
||||
Require(offset < jpeg.size());
|
||||
const std::uint8_t marker = jpeg[offset++];
|
||||
if (marker == 0xDA || marker == 0xD9) break;
|
||||
Require(offset + 1 < jpeg.size());
|
||||
const std::size_t length = (static_cast<std::size_t>(jpeg[offset]) << 8) | jpeg[offset + 1];
|
||||
Require(length >= 2 && offset + length <= jpeg.size());
|
||||
if (marker >= 0xC0 && marker <= 0xC3) return {jpeg[offset + 7], jpeg[offset + 9]};
|
||||
offset += length;
|
||||
}
|
||||
std::abort();
|
||||
}
|
||||
|
||||
int main() {
|
||||
constexpr std::uint32_t width = 32;
|
||||
constexpr std::uint32_t height = 24;
|
||||
@@ -41,6 +61,7 @@ int main() {
|
||||
|
||||
const std::vector<std::uint8_t> rgbJpeg = Decoder::Jpeg::Encode(rgb, width, height, 3, 90);
|
||||
Require(IsJpeg(rgbJpeg));
|
||||
Require(ReadFrame(rgbJpeg).components == 3 && ReadFrame(rgbJpeg).sampling == 0x11);
|
||||
const auto rgbImage = Decoder::Jpeg::Decode(rgbJpeg);
|
||||
Require(rgbImage.has_value());
|
||||
Require(rgbImage->width == width && rgbImage->height == height && rgbImage->channels == 3);
|
||||
@@ -55,6 +76,7 @@ int main() {
|
||||
}
|
||||
const std::vector<std::uint8_t> grayJpeg = Decoder::Jpeg::Encode(gray, width, height, 1, 90);
|
||||
Require(IsJpeg(grayJpeg));
|
||||
Require(ReadFrame(grayJpeg).components == 1);
|
||||
const auto grayImage = Decoder::Jpeg::Decode(grayJpeg);
|
||||
Require(grayImage.has_value());
|
||||
Require(grayImage->width == width && grayImage->height == height);
|
||||
@@ -69,6 +91,16 @@ int main() {
|
||||
Require(ThrowsInvalidArgument([&] { Decoder::Jpeg::Encode(rgb, 0x10000, 1, 3, 90); }));
|
||||
Require(ThrowsInvalidArgument([&] { Decoder::Jpeg::Encode(rgb, width, height + 1, 3, 90); }));
|
||||
|
||||
for (const auto [sampling, factor] : {std::pair{Decoder::Jpeg::Sampling::Yuv444, std::uint8_t{0x11}},
|
||||
std::pair{Decoder::Jpeg::Sampling::Yuv422, std::uint8_t{0x21}},
|
||||
std::pair{Decoder::Jpeg::Sampling::Yuv420, std::uint8_t{0x22}}}) {
|
||||
const auto encoded = Decoder::Jpeg::Encode(rgb, 31, 23, 3, 1, sampling);
|
||||
Require(ReadFrame(encoded).components == 3 && ReadFrame(encoded).sampling == factor);
|
||||
const auto highQuality = Decoder::Jpeg::Encode(rgb, 31, 23, 3, 100, sampling);
|
||||
Require(ReadFrame(highQuality).components == 3 && ReadFrame(highQuality).sampling == factor);
|
||||
}
|
||||
Require(ThrowsInvalidArgument([&] { Decoder::Jpeg::Encode(rgb, width, height, 3, 90, static_cast<Decoder::Jpeg::Sampling>(3)); }));
|
||||
|
||||
Require(!Decoder::Jpeg::Decode({}).has_value());
|
||||
const std::vector<std::uint8_t> garbage{1, 2, 3, 4, 5, 6, 7, 8};
|
||||
Require(!Decoder::Jpeg::Decode(garbage).has_value());
|
||||
|
||||
@@ -118,17 +118,6 @@ foreach(LIB_DIR ${LIBS_DIRS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(LIBCOHTML_PATCHED ${PATCHED_DIR}/libcohtml.prx)
|
||||
set(LIBCOHTML_PROSPERO_PATCHED ${PATCHED_DIR}/libcohtml.Prospero.prx)
|
||||
add_custom_command(
|
||||
OUTPUT ${LIBCOHTML_PROSPERO_PATCHED}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${LIBCOHTML_PATCHED}" "${LIBCOHTML_PROSPERO_PATCHED}"
|
||||
DEPENDS ${LIBCOHTML_PATCHED}
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(libcohtml_prospero DEPENDS ${LIBCOHTML_PROSPERO_PATCHED})
|
||||
list(APPEND PATCHED_OUTPUTS ${LIBCOHTML_PROSPERO_PATCHED})
|
||||
|
||||
add_custom_target(libs DEPENDS ${PATCHED_OUTPUTS})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
@@ -170,16 +159,6 @@ if(BUILD_TESTING)
|
||||
add_test(NAME host_thread_local COMMAND host_thread_local_tests)
|
||||
set_tests_properties(host_thread_local PROPERTIES TIMEOUT 15)
|
||||
|
||||
add_test_executable(guest_np_cpp_web_api_intrusive_ptr_tests tests/GuestNpCppWebApiIntrusivePtr.cpp)
|
||||
target_include_directories(guest_np_cpp_web_api_intrusive_ptr_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(guest_np_cpp_web_api_intrusive_ptr_tests PRIVATE libSceNpCppWebApi libc)
|
||||
configure_windows_unwind(guest_np_cpp_web_api_intrusive_ptr_tests)
|
||||
add_test(NAME guest_np_cpp_web_api_intrusive_ptr COMMAND guest_np_cpp_web_api_intrusive_ptr_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_np_cpp_web_api_intrusive_ptr PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceNpCppWebApi>")
|
||||
endif()
|
||||
|
||||
add_test_executable(savedata_core_write_replacement_tests tests/SaveDataWriteReplacement.cpp)
|
||||
target_include_directories(savedata_core_write_replacement_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(savedata_core_write_replacement_tests PRIVATE libSceSaveData)
|
||||
|
||||
+31
-5
@@ -199,13 +199,39 @@ struct FileStat {
|
||||
KernelTimespec st_birthtim;
|
||||
};
|
||||
|
||||
struct ModuleInfo {
|
||||
std::uint64_t size;
|
||||
std::uint64_t info[32];
|
||||
KernelModule handle;
|
||||
std::uint8_t pad[156];
|
||||
struct ModuleSegmentInfo {
|
||||
std::uint64_t address;
|
||||
std::uint32_t size;
|
||||
std::int32_t prot;
|
||||
};
|
||||
|
||||
struct ModuleInfoEx {
|
||||
std::uint64_t st_size;
|
||||
char name[256];
|
||||
KernelModule id;
|
||||
std::uint32_t tls_index;
|
||||
std::uint64_t tls_init_addr;
|
||||
std::uint32_t tls_init_size;
|
||||
std::uint32_t tls_size;
|
||||
std::uint32_t tls_offset;
|
||||
std::uint32_t tls_align;
|
||||
std::uint64_t init_proc_addr;
|
||||
std::uint64_t fini_proc_addr;
|
||||
std::uint64_t reserved1;
|
||||
std::uint64_t reserved2;
|
||||
std::uint64_t eh_frame_hdr_addr;
|
||||
std::uint64_t eh_frame_addr;
|
||||
std::uint32_t eh_frame_hdr_size;
|
||||
std::uint32_t eh_frame_size;
|
||||
ModuleSegmentInfo segments[4];
|
||||
std::uint32_t segment_count;
|
||||
std::uint32_t ref_count;
|
||||
};
|
||||
static_assert(offsetof(ModuleInfoEx, id) == 0x108);
|
||||
static_assert(offsetof(ModuleInfoEx, eh_frame_hdr_addr) == 0x148);
|
||||
static_assert(offsetof(ModuleInfoEx, segments) == 0x160);
|
||||
static_assert(sizeof(ModuleInfoEx) == 0x1A8);
|
||||
|
||||
struct ModuleInfoForUnwind {
|
||||
std::uint64_t st_size;
|
||||
char name[256];
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
#include <cstdint>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
// CD Projekt RED GOG Galaxy wrapper, bundled with the game as
|
||||
// modules/libREDGalaxy64.prx (seen in Cyberpunk 2077 PPSA04029).
|
||||
// Online Galaxy services cannot work under emulation: Init/Shutdown/
|
||||
// ProcessData are accepted and ignored, interface getters return null
|
||||
// (all observed engine call sites null-check the result).
|
||||
// Roles below were reversed from the module's own export bodies:
|
||||
// Init references clientID/clientSecret/configFilePath, Shutdown
|
||||
// releases the facade singletons, ProcessData throttles facade
|
||||
// ProcessData calls, GetErrorString formats Gog/Std exceptions.
|
||||
|
||||
APS5_EXPORT("1icN9EO2WSg", redGalaxy64Init);
|
||||
std::uint64_t APS5_VABI redGalaxy64Init(const void* options) {
|
||||
(void)options;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
APS5_EXPORT("SA7aCTRE5zg", redGalaxy64Shutdown);
|
||||
void APS5_VABI redGalaxy64Shutdown(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
}
|
||||
|
||||
APS5_EXPORT("ZVPOpEqpUvo", redGalaxy64ProcessData);
|
||||
void APS5_VABI redGalaxy64ProcessData(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
}
|
||||
|
||||
APS5_EXPORT("4trn+7BssaY", redGalaxy64GetErrorString);
|
||||
const char* APS5_VABI redGalaxy64GetErrorString(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return "";
|
||||
}
|
||||
|
||||
APS5_EXPORT("DQAUzFVaGl8", redGalaxy64GameServerInit);
|
||||
std::uint64_t APS5_VABI redGalaxy64GameServerInit(const void* options) {
|
||||
(void)options;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
APS5_EXPORT("GKomji4WVHw", redGalaxy64ProcessGameServerData);
|
||||
void APS5_VABI redGalaxy64ProcessGameServerData(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
}
|
||||
|
||||
APS5_EXPORT("36lort-kFp4", redgalaxy_stub_00);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_00(std::uint64_t a0, std::uint64_t a1, std::uint64_t a2) {
|
||||
(void)a0;
|
||||
(void)a1;
|
||||
(void)a2;
|
||||
NotImplemented_nid_no_patch("36lort-kFp4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("NgDLhCc6F7Y", redgalaxy_stub_01);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_01(const void* a0, const char* a1, std::uint64_t a2) {
|
||||
(void)a0;
|
||||
(void)a1;
|
||||
(void)a2;
|
||||
NotImplemented_nid_no_patch("NgDLhCc6F7Y");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("huJ+beHcWBE", redgalaxy_stub_02);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_02(void) {
|
||||
NotImplemented_nid_no_patch("huJ+beHcWBE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("sxiZFliOEDU", redgalaxy_stub_03);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_03(void) {
|
||||
NotImplemented_nid_no_patch("sxiZFliOEDU");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("49Bdn1OOJ90", redgalaxy_stub_04);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_04(void) {
|
||||
NotImplemented_nid_no_patch("49Bdn1OOJ90");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("8ahh9DUqZLY", redgalaxy_stub_05);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_05(void) {
|
||||
NotImplemented_nid_no_patch("8ahh9DUqZLY");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Ard4nEfw5Vs", redgalaxy_stub_06);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_06(void) {
|
||||
NotImplemented_nid_no_patch("Ard4nEfw5Vs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("AzO2fwK+MUs", redgalaxy_stub_07);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_07(void) {
|
||||
NotImplemented_nid_no_patch("AzO2fwK+MUs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("HKIwQPq45o4", redgalaxy_stub_08);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_08(void) {
|
||||
NotImplemented_nid_no_patch("HKIwQPq45o4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("IXRuom5imkM", redgalaxy_stub_09);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_09(void) {
|
||||
NotImplemented_nid_no_patch("IXRuom5imkM");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("LjDqfncevos", redgalaxy_stub_10);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_10(void) {
|
||||
NotImplemented_nid_no_patch("LjDqfncevos");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Onwg0aGsFhM", redgalaxy_stub_11);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_11(void) {
|
||||
NotImplemented_nid_no_patch("Onwg0aGsFhM");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("oSyqfoYcK40", redgalaxy_stub_12);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_12(void) {
|
||||
NotImplemented_nid_no_patch("oSyqfoYcK40");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("qoS0gqW7RxI", redgalaxy_stub_13);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_13(void) {
|
||||
NotImplemented_nid_no_patch("qoS0gqW7RxI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("SOtPNNwajSw", redgalaxy_stub_14);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_14(void) {
|
||||
NotImplemented_nid_no_patch("SOtPNNwajSw");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("udfpd9vbE+w", redgalaxy_stub_15);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_15(void) {
|
||||
NotImplemented_nid_no_patch("udfpd9vbE+w");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("vuGujcpcUEk", redgalaxy_stub_16);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_16(void) {
|
||||
NotImplemented_nid_no_patch("vuGujcpcUEk");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("VXUTdiaHbD4", redgalaxy_stub_17);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_17(void) {
|
||||
NotImplemented_nid_no_patch("VXUTdiaHbD4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("w5-trCio4bQ", redgalaxy_stub_18);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_18(void) {
|
||||
NotImplemented_nid_no_patch("w5-trCio4bQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("YpZjREtZb20", redgalaxy_stub_19);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_19(void) {
|
||||
NotImplemented_nid_no_patch("YpZjREtZb20");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("gPJN5c9XCec", redgalaxy_stub_20);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_20(void) {
|
||||
NotImplemented_nid_no_patch("gPJN5c9XCec");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("z4SpWc89no8", redgalaxy_stub_21);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_21(void) {
|
||||
NotImplemented_nid_no_patch("z4SpWc89no8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("zdzopKdBeU4", redgalaxy_stub_22);
|
||||
std::uint64_t APS5_VABI redgalaxy_stub_22(void) {
|
||||
NotImplemented_nid_no_patch("zdzopKdBeU4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
#include <cstdint>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
APS5_EXPORT("0DsDTr534gc", renoirStub00);
|
||||
uint64_t APS5_VABI renoirStub00(void) {
|
||||
NotImplemented_nid_no_patch("0DsDTr534gc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("2T56HgbPW08", renoirStub01);
|
||||
uint64_t APS5_VABI renoirStub01(void) {
|
||||
NotImplemented_nid_no_patch("2T56HgbPW08");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("3HnCozh8Az8", renoirStub02);
|
||||
uint64_t APS5_VABI renoirStub02(void) {
|
||||
NotImplemented_nid_no_patch("3HnCozh8Az8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("5Ysce+s-CWU", renoirStub03);
|
||||
uint64_t APS5_VABI renoirStub03(void) {
|
||||
NotImplemented_nid_no_patch("5Ysce+s-CWU");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("AdlSqA4lGS8", renoirStub04);
|
||||
uint64_t APS5_VABI renoirStub04(void) {
|
||||
NotImplemented_nid_no_patch("AdlSqA4lGS8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("bC37hk7rHqs", renoirStub05);
|
||||
uint64_t APS5_VABI renoirStub05(void) {
|
||||
NotImplemented_nid_no_patch("bC37hk7rHqs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("dfPK9R6M0qM", renoirStub06);
|
||||
uint64_t APS5_VABI renoirStub06(void) {
|
||||
NotImplemented_nid_no_patch("dfPK9R6M0qM");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("fZiBbVa2ZDU", renoirStub07);
|
||||
uint64_t APS5_VABI renoirStub07(void) {
|
||||
NotImplemented_nid_no_patch("fZiBbVa2ZDU");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("hkWBH8-WfW4", renoirStub08);
|
||||
uint64_t APS5_VABI renoirStub08(void) {
|
||||
NotImplemented_nid_no_patch("hkWBH8-WfW4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("hUxvGdi64Io", renoirStub09);
|
||||
uint64_t APS5_VABI renoirStub09(void) {
|
||||
NotImplemented_nid_no_patch("hUxvGdi64Io");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("NxqsZxGisrA", renoirStub10);
|
||||
uint64_t APS5_VABI renoirStub10(void) {
|
||||
NotImplemented_nid_no_patch("NxqsZxGisrA");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("OgZVIkaNmb0", renoirStub11);
|
||||
uint64_t APS5_VABI renoirStub11(void) {
|
||||
NotImplemented_nid_no_patch("OgZVIkaNmb0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ojLQdRUnVgA", renoirStub12);
|
||||
uint64_t APS5_VABI renoirStub12(void) {
|
||||
NotImplemented_nid_no_patch("ojLQdRUnVgA");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("s0qDfgsAgVg", renoirStub13);
|
||||
uint64_t APS5_VABI renoirStub13(void) {
|
||||
NotImplemented_nid_no_patch("s0qDfgsAgVg");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("sgrd-r1Nw60", renoirStub14);
|
||||
uint64_t APS5_VABI renoirStub14(void) {
|
||||
NotImplemented_nid_no_patch("sgrd-r1Nw60");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("sjTRb8YD7dQ", renoirStub15);
|
||||
uint64_t APS5_VABI renoirStub15(void) {
|
||||
NotImplemented_nid_no_patch("sjTRb8YD7dQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("tG86XGc2VtE", renoirStub16);
|
||||
uint64_t APS5_VABI renoirStub16(void) {
|
||||
NotImplemented_nid_no_patch("tG86XGc2VtE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("umlGxOcNzgc", renoirStub17);
|
||||
uint64_t APS5_VABI renoirStub17(void) {
|
||||
NotImplemented_nid_no_patch("umlGxOcNzgc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("vPxA9OFW0os", renoirStub18);
|
||||
uint64_t APS5_VABI renoirStub18(void) {
|
||||
NotImplemented_nid_no_patch("vPxA9OFW0os");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("X2qEBlOLkNo", renoirStub19);
|
||||
uint64_t APS5_VABI renoirStub19(void) {
|
||||
NotImplemented_nid_no_patch("X2qEBlOLkNo");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ynh4E+BIaqY", renoirStub20);
|
||||
uint64_t APS5_VABI renoirStub20(void) {
|
||||
NotImplemented_nid_no_patch("ynh4E+BIaqY");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("YXe6ABbHZPs", renoirStub21);
|
||||
uint64_t APS5_VABI renoirStub21(void) {
|
||||
NotImplemented_nid_no_patch("YXe6ABbHZPs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("z0jsXZVz75I", renoirStub22);
|
||||
uint64_t APS5_VABI renoirStub22(void) {
|
||||
NotImplemented_nid_no_patch("z0jsXZVz75I");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,6 +69,14 @@ add_test_executable(agc_command_tests EXCLUDE_FROM_ALL tests/Commands.cpp)
|
||||
target_include_directories(agc_command_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(agc_command_tests PRIVATE libSceAgc libc)
|
||||
configure_windows_unwind(agc_command_tests)
|
||||
if(BUILD_TESTING)
|
||||
set_target_properties(agc_command_tests PROPERTIES EXCLUDE_FROM_ALL OFF)
|
||||
add_test(NAME agc_initialization COMMAND agc_command_tests defaults)
|
||||
if(WIN32)
|
||||
set_tests_properties(agc_initialization PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
configure_windows_unwind(libSceAgc)
|
||||
|
||||
add_test_executable(agc_platform_tests EXCLUDE_FROM_ALL tests/Platform.cpp)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "prx/libSceAgc/DcbState/include/Init.hpp"
|
||||
|
||||
#include "prx/libSceAgc/Command/include/Packet.hpp"
|
||||
#include "prx/libSceAgc/Command/include/RegisterDefaults.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include "SceTypes.hpp"
|
||||
@@ -8,11 +9,17 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
APS5_EXPORT("23LRUSvYu1M", sceAgcInit);
|
||||
int APS5_VABI sceAgcInit(std::uint32_t* state, std::uint32_t version) {
|
||||
APS5_EXPORT("23LRUSvYu1M", sceAgcUnknownInitState);
|
||||
int APS5_VABI sceAgcUnknownInitState(std::uint32_t* state, std::uint32_t version) {
|
||||
Agc::Command::CheckAddress(reinterpret_cast<std::uintptr_t>(state), alignof(std::uint32_t), __func__);
|
||||
Agc::Command::Require(version < 14, __func__, "unsupported AGC initialization version");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcInit(std::uint32_t version) {
|
||||
Agc::Command::GetRegisterDefaults(version, false, __func__);
|
||||
Agc::Command::GetRegisterDefaults(version, true, __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbResetQueue(CommandBuffer* buf, std::uint32_t op, std::uint32_t state);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbSetFlip(CommandBuffer* buf, std::uint32_t handle, std::int32_t index, std::uint32_t mode, std::int64_t argument);
|
||||
extern "C" int APS5_VABI sceAgcSuspendPoint();
|
||||
extern "C" int APS5_VABI sceAgcInit(std::uint32_t* state, std::uint32_t version);
|
||||
extern "C" int APS5_VABI sceAgcInit(std::uint32_t version);
|
||||
extern "C" int APS5_VABI sceAgcUnknownInitState(std::uint32_t* state, std::uint32_t version);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbDrawIndexAuto(CommandBuffer* buf, std::uint32_t indexCount, std::uint64_t modifier);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbDrawIndexIndirect(CommandBuffer* buf, std::uint32_t dataOffsetInBytes, std::uint64_t modifier);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbDrawIndexIndirectMulti(CommandBuffer* buf, std::uint32_t dataOffsetInBytes, std::uint32_t countIndirect, std::uint32_t maxCountOrCount, const volatile void* countAddress, std::uint32_t strideInBytes, std::uint64_t modifier);
|
||||
@@ -336,9 +337,13 @@ void testMemory() {
|
||||
|
||||
void testDefaults() {
|
||||
std::uint32_t state = 0x12345678;
|
||||
check(sceAgcInit(&state, 8) == 0 && state == 0x12345678, "AGC initialization failed or modified caller state");
|
||||
expectFailure([] { sceAgcInit(nullptr, 8); });
|
||||
expectFailure([&] { sceAgcInit(&state, 14); });
|
||||
check(sceAgcUnknownInitState(&state, 8) == 0 && state == 0x12345678, "AGC initialization failed or modified caller state");
|
||||
check(sceAgcUnknownInitState(&state, 13) == 0 && state == 0x12345678, "AGC version 13 initialization changed caller state");
|
||||
expectFailure([] { sceAgcUnknownInitState(nullptr, 8); });
|
||||
expectFailure([&] { sceAgcUnknownInitState(&state, 14); });
|
||||
check(sceAgcInit(8) == 0, "AGC version initialization failed");
|
||||
expectFailure([] { sceAgcInit(14); });
|
||||
expectFailure([] { sceAgcInit(0xffffffffu); });
|
||||
for (std::uint32_t version = 0; version < 14; ++version) {
|
||||
for (const bool internal : {false, true}) {
|
||||
auto* first = Agc::Command::GetRegisterDefaults(version, internal, __func__);
|
||||
@@ -351,8 +356,14 @@ void testDefaults() {
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
if (argc == 2 && std::strcmp(argv[1], "defaults") == 0) {
|
||||
testDefaults();
|
||||
LibcRunShutdown_nid_postfix();
|
||||
std::puts("AGC initialization tests passed");
|
||||
return 0;
|
||||
}
|
||||
testPackets();
|
||||
testIndexedIndirectDraws();
|
||||
testMarkers();
|
||||
|
||||
@@ -200,6 +200,20 @@ target_link_libraries(libSceAgcDriver PRIVATE
|
||||
|
||||
set_target_properties(libSceAgcDriver PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(libSceAgcDriver)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(agc_profile_output_tests tests/ProfileOutput.cpp)
|
||||
target_include_directories(agc_profile_output_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(agc_profile_output_tests PRIVATE libc)
|
||||
configure_windows_unwind(agc_profile_output_tests)
|
||||
add_test(NAME agc_profile_output COMMAND agc_profile_output_tests)
|
||||
set_tests_properties(agc_profile_output PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(agc_profile_output PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/Execution/src/GuestMemory.cpp PROPERTIES COMPILE_DEFINITIONS _WIN32_WINNT=0x0602)
|
||||
endif()
|
||||
@@ -214,6 +228,7 @@ add_test_executable(agc_driver_tests EXCLUDE_FROM_ALL
|
||||
|
||||
target_include_directories(agc_driver_tests PRIVATE
|
||||
${LIBS_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/core/shader/recompiler
|
||||
)
|
||||
|
||||
target_link_libraries(agc_driver_tests PRIVATE
|
||||
@@ -675,6 +690,15 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(linear_display_buffer PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(guest_agc_driver_resources_tests ${LIBS_INCLUDE_DIR}/tests/GuestAgcDriverResources.cpp)
|
||||
target_include_directories(guest_agc_driver_resources_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_agc_driver_resources_tests PRIVATE libSceAgcDriver libc)
|
||||
configure_windows_unwind(guest_agc_driver_resources_tests)
|
||||
add_test(NAME guest_agc_driver_resources COMMAND guest_agc_driver_resources_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_agc_driver_resources PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(guest_rendering_wait_tests ${LIBS_INCLUDE_DIR}/tests/GuestRenderingWait.cpp)
|
||||
target_include_directories(guest_rendering_wait_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_rendering_wait_tests PRIVATE libSceAgcDriver libc)
|
||||
@@ -804,6 +828,19 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test_executable(agc_vop1_sdwa_move_decode_tests EXCLUDE_FROM_ALL tests/Vop1SdwaMoveDecode.cpp)
|
||||
target_link_libraries(agc_vop1_sdwa_move_decode_tests PRIVATE shader_recompiler_agc_driver libc)
|
||||
set_target_properties(agc_vop1_sdwa_move_decode_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(agc_vop1_sdwa_move_decode_tests)
|
||||
if(BUILD_TESTING)
|
||||
set_target_properties(agc_vop1_sdwa_move_decode_tests PROPERTIES EXCLUDE_FROM_ALL OFF)
|
||||
add_test(NAME agc_vop1_sdwa_move_decode COMMAND agc_vop1_sdwa_move_decode_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(agc_vop1_sdwa_move_decode PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test_executable(agc_pixel_position_export_tests EXCLUDE_FROM_ALL tests/PixelPositionExport.cpp)
|
||||
target_link_libraries(agc_pixel_position_export_tests PRIVATE shader_recompiler_agc_driver libc)
|
||||
set_target_properties(agc_pixel_position_export_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
@@ -817,3 +854,14 @@ if(BUILD_TESTING)
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(image_msaa_load_tests ${LIBS_INCLUDE_DIR}/tests/ImageMsaaLoad.cpp)
|
||||
target_link_libraries(image_msaa_load_tests PRIVATE shader_recompiler_agc_driver libc)
|
||||
configure_windows_unwind(image_msaa_load_tests)
|
||||
add_test(NAME image_msaa_load COMMAND image_msaa_load_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(image_msaa_load PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -38,6 +38,7 @@ struct ShaderSnapshot {
|
||||
using ShaderRegistry = std::map<std::uint64_t, std::shared_ptr<const ShaderSnapshot>>;
|
||||
|
||||
bool FailureMemo();
|
||||
std::shared_ptr<const ShaderSnapshot> ReadRawComputeShader(std::uint64_t address);
|
||||
|
||||
std::uint64_t NullPixelProgramAddress();
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace AgcDriver {
|
||||
|
||||
class ProfileOutput {
|
||||
public:
|
||||
explicit ProfileOutput(std::function<void(std::string_view)> writer, std::size_t capacity = 4 * 1024 * 1024) : writer(std::move(writer)), capacity(capacity) {
|
||||
if (!this->writer || capacity == 0) throw std::invalid_argument("invalid profile output writer or capacity");
|
||||
worker = std::thread([this] { run(); });
|
||||
}
|
||||
|
||||
~ProfileOutput() {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
stopping = true;
|
||||
}
|
||||
changed.notify_one();
|
||||
worker.join();
|
||||
}
|
||||
|
||||
bool Write(std::string text) {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
if (failure) std::rethrow_exception(failure);
|
||||
if (stopping) throw std::runtime_error("profile output is stopping");
|
||||
if (text.empty()) return true;
|
||||
if (text.size() > capacity - bytes) {
|
||||
++dropped;
|
||||
changed.notify_one();
|
||||
return false;
|
||||
}
|
||||
const auto size = text.size();
|
||||
pending.push_back(std::move(text));
|
||||
bytes += size;
|
||||
}
|
||||
changed.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename... TArgs>
|
||||
void Print(const char* format, TArgs... args) {
|
||||
std::array<char, 2048> local{};
|
||||
const auto size = std::snprintf(local.data(), local.size(), format, args...);
|
||||
if (size < 0) throw std::runtime_error("profile output formatting failed");
|
||||
if (static_cast<std::size_t>(size) < local.size()) {
|
||||
Write(std::string(local.data(), size));
|
||||
} else if (static_cast<std::size_t>(size) > capacity) {
|
||||
std::lock_guard lock(mutex);
|
||||
if (failure) std::rethrow_exception(failure);
|
||||
++dropped;
|
||||
changed.notify_one();
|
||||
} else {
|
||||
std::vector<char> text(static_cast<std::size_t>(size) + 1);
|
||||
if (std::snprintf(text.data(), text.size(), format, args...) != size) throw std::runtime_error("profile output formatting changed");
|
||||
Write(std::string(text.data(), size));
|
||||
}
|
||||
}
|
||||
|
||||
void Flush() {
|
||||
std::unique_lock lock(mutex);
|
||||
idle.wait(lock, [&] { return failure || (pending.empty() && !writing && dropped == 0); });
|
||||
if (failure) std::rethrow_exception(failure);
|
||||
}
|
||||
|
||||
private:
|
||||
void run() noexcept {
|
||||
try {
|
||||
for (;;) {
|
||||
std::string batch;
|
||||
std::size_t consumed = 0;
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
changed.wait(lock, [&] { return stopping || !pending.empty() || dropped != 0; });
|
||||
if (stopping && pending.empty() && dropped == 0) return;
|
||||
while (!pending.empty() && (batch.empty() || batch.size() + pending.front().size() <= 65536)) {
|
||||
consumed += pending.front().size();
|
||||
batch += pending.front();
|
||||
pending.pop_front();
|
||||
}
|
||||
if (dropped != 0) {
|
||||
batch += "[profile-output] dropped " + std::to_string(dropped) + " chunks because the diagnostic writer fell behind\n";
|
||||
dropped = 0;
|
||||
}
|
||||
writing = true;
|
||||
}
|
||||
writer(batch);
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
bytes -= consumed;
|
||||
writing = false;
|
||||
}
|
||||
idle.notify_all();
|
||||
}
|
||||
} catch (...) {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
failure = std::current_exception();
|
||||
writing = false;
|
||||
}
|
||||
idle.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(std::string_view)> writer;
|
||||
const std::size_t capacity;
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
std::condition_variable idle;
|
||||
std::deque<std::string> pending;
|
||||
std::size_t bytes = 0;
|
||||
std::size_t dropped = 0;
|
||||
bool writing = false;
|
||||
bool stopping = false;
|
||||
std::exception_ptr failure;
|
||||
std::thread worker;
|
||||
};
|
||||
|
||||
inline ProfileOutput& ProfileOutput_nid_no_patch() {
|
||||
static ProfileOutput output([](std::string_view text) {
|
||||
if (std::fwrite(text.data(), 1, text.size(), stderr) != text.size() || std::fflush(stderr) != 0)
|
||||
throw std::runtime_error("profile output write failed");
|
||||
});
|
||||
return output;
|
||||
}
|
||||
|
||||
template<typename... TArgs>
|
||||
void ProfilePrint_nid_no_patch(const char* format, TArgs... args) {
|
||||
ProfileOutput_nid_no_patch().Print(format, args...);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Diagnostics.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp"
|
||||
@@ -12,10 +13,13 @@ namespace AgcDriver::DriverDetail {
|
||||
void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet, const Submission& submission, std::uint64_t indirectArguments) {
|
||||
const auto address = (static_cast<std::uint64_t>(readRegister(queue.shader, 0x20c)) << 8u) | (static_cast<std::uint64_t>(readRegister(queue.shader, 0x20d) & 0xffu) << 40u);
|
||||
auto it = submission.shaders->upper_bound(address);
|
||||
require(it != submission.shaders->begin(), "compute program does not belong to a registered shader");
|
||||
--it;
|
||||
const auto& snapshot = *it->second;
|
||||
require(address - snapshot.codeAddress < snapshot.code.size() * sizeof(std::uint32_t), "compute program is outside registered shader code");
|
||||
std::shared_ptr<const ShaderSnapshot> registeredShader;
|
||||
if (it != submission.shaders->begin()) {
|
||||
--it;
|
||||
if (address - it->second->codeAddress < it->second->code.size() * sizeof(std::uint32_t)) registeredShader = it->second;
|
||||
}
|
||||
if (!registeredShader) registeredShader = ReadRawComputeShader(address);
|
||||
const auto& snapshot = *registeredShader;
|
||||
require(snapshot.type == 0, "compute program refers to a non-compute shader");
|
||||
const auto userCount = (readRegister(queue.shader, 0x213) >> 1u) & 0x1fu;
|
||||
std::vector<std::uint32_t> userData;
|
||||
@@ -23,7 +27,8 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
|
||||
userData.push_back(readRegister(queue.shader, 0x240 + i));
|
||||
}
|
||||
auto compute = Graphics::DecodeComputeStageInfo(queue.shader);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 2> memory{{{snapshot.codeAddress, std::as_bytes(std::span(snapshot.code))}, {snapshot.headerAddress, snapshot.header}}};
|
||||
std::vector<ShaderRecompiler::MemoryRegion> memory{{snapshot.codeAddress, std::as_bytes(std::span(snapshot.code))}};
|
||||
if (!snapshot.header.empty()) memory.push_back({snapshot.headerAddress, snapshot.header});
|
||||
|
||||
static const bool unlockedDevice = std::getenv("APS5_NO_UNLOCKED_DEVICE") == nullptr;
|
||||
std::shared_ptr<VulkanDevice> localDevice = unlockedDevice ? device.Load() : nullptr;
|
||||
@@ -174,7 +179,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
|
||||
previous.key = key;
|
||||
}
|
||||
|
||||
if (!stampValidate()) mix(reinterpret_cast<std::uintptr_t>(it->second.get()));
|
||||
if (!stampValidate()) mix(reinterpret_cast<std::uintptr_t>(registeredShader.get()));
|
||||
phaseTiming.Phase(PhaseKey);
|
||||
lookupDispatch(address, submission, key, noDispatchCache, traceCache, profile, memory, phaseTiming, phaseMs, compiledResult, keepVariant, captured, liveWords, dataHit, cached, validated, missedEntry, missedDiffering);
|
||||
if (cached) {
|
||||
@@ -226,7 +231,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
|
||||
}
|
||||
recompileMs += phaseTiming.Elapsed();
|
||||
phaseTiming.Phase(PhaseRecompile);
|
||||
insertDispatch(address, key, noDispatchCache, profile, it->second, forgetAtCapture, memory, shaderMemory, captured, capture, compiledResult, missedEntry, missedDiffering, attachVariant, phaseTiming);
|
||||
insertDispatch(address, key, noDispatchCache, profile, registeredShader, forgetAtCapture, memory, shaderMemory, captured, capture, compiledResult, missedEntry, missedDiffering, attachVariant, phaseTiming);
|
||||
}
|
||||
if (verifyDataHits() && dataHit) verifyDataHit(snapshot, codeOffset, localDevice->Serial(), request, memory, address, *keepVariant, liveWords, *compiledResult);
|
||||
|
||||
@@ -360,7 +365,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
|
||||
pending.ms = phaseMs;
|
||||
pending.tailAt = phaseLap;
|
||||
}
|
||||
if (profile && ++dispatches % 100 == 0) std::fprintf(stderr, "[gpu] %llu dispatches (%llu dispatch cache hits, %llu evictions, %llu recompile cache hits): capture %.1f s, cache key %.1f s, recompile %.1f s, device %.1f s\n", static_cast<unsigned long long>(dispatches), static_cast<unsigned long long>(dispatchCacheHits), static_cast<unsigned long long>(dispatchCacheEvictions), static_cast<unsigned long long>(cacheHits), captureMs / 1000, keyMs / 1000, recompileMs / 1000, deviceMs / 1000);
|
||||
if (profile && ++dispatches % 100 == 0) AgcDriver::ProfilePrint_nid_no_patch( "[gpu] %llu dispatches (%llu dispatch cache hits, %llu evictions, %llu recompile cache hits): capture %.1f s, cache key %.1f s, recompile %.1f s, device %.1f s\n", static_cast<unsigned long long>(dispatches), static_cast<unsigned long long>(dispatchCacheHits), static_cast<unsigned long long>(dispatchCacheEvictions), static_cast<unsigned long long>(cacheHits), captureMs / 1000, keyMs / 1000, recompileMs / 1000, deviceMs / 1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "Optimization/ResourceProgram.hpp"
|
||||
|
||||
@@ -42,7 +43,7 @@ void Driver::classifyDiffering(std::uint64_t program, std::uint64_t key, const D
|
||||
void Driver::reportDispatchCache(EntryCounters& counters) {
|
||||
const auto count = [](std::uint64_t value) { return static_cast<unsigned long long>(value); };
|
||||
const auto validated = counters.lookups - counters.absent;
|
||||
std::fprintf(stderr, "[dispatch-cache] %llu lookups (10 s): %llu no entry, %llu validated by value in %.1f us each: %llu equal, %llu differing, %llu page not mapped, %llu queued label, %llu image being stored, %llu publish generation moved, %llu pending serial moved, %llu forget serial moved (%llu pending images stored first, %llu pending runs synced first, %llu equal entries inserted before a forget; gate retried %llu: %llu equal, %llu moved again); runs per entry %.1f validated / %.1f inserted; %llu misses found the entry replaced meanwhile; %llu inserts (%llu captures not kept: unstable), %llu evictions in total, %zu entries, %llu LRU moves\n", count(counters.lookups), count(counters.absent), count(validated), validated != 0 ? counters.validateUs / static_cast<double>(validated) : 0.0, count(counters.equal), count(counters.differing), count(counters.inaccessible), count(counters.queuedLabel), count(counters.flushingImage), count(counters.publishMoved), count(counters.pendingMoved), count(counters.forgetMoved), count(counters.imagesFlushed), count(counters.runsSynced), count(counters.forgetSinceInsert), count(counters.retriesEqual + counters.retriesMoved), count(counters.retriesEqual), count(counters.retriesMoved), validated != 0 ? static_cast<double>(counters.runsValidated) / static_cast<double>(validated) : 0.0, counters.inserts != 0 ? static_cast<double>(counters.runsInserted) / static_cast<double>(counters.inserts) : 0.0, count(counters.replaced), count(counters.inserts), count(counters.unstable), count(dispatchCacheEvictions), dispatchCache.size(), count(counters.touches));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch-cache] %llu lookups (10 s): %llu no entry, %llu validated by value in %.1f us each: %llu equal, %llu differing, %llu page not mapped, %llu queued label, %llu image being stored, %llu publish generation moved, %llu pending serial moved, %llu forget serial moved (%llu pending images stored first, %llu pending runs synced first, %llu equal entries inserted before a forget; gate retried %llu: %llu equal, %llu moved again); runs per entry %.1f validated / %.1f inserted; %llu misses found the entry replaced meanwhile; %llu inserts (%llu captures not kept: unstable), %llu evictions in total, %zu entries, %llu LRU moves\n", count(counters.lookups), count(counters.absent), count(validated), validated != 0 ? counters.validateUs / static_cast<double>(validated) : 0.0, count(counters.equal), count(counters.differing), count(counters.inaccessible), count(counters.queuedLabel), count(counters.flushingImage), count(counters.publishMoved), count(counters.pendingMoved), count(counters.forgetMoved), count(counters.imagesFlushed), count(counters.runsSynced), count(counters.forgetSinceInsert), count(counters.retriesEqual + counters.retriesMoved), count(counters.retriesEqual), count(counters.retriesMoved), validated != 0 ? static_cast<double>(counters.runsValidated) / static_cast<double>(validated) : 0.0, counters.inserts != 0 ? static_cast<double>(counters.runsInserted) / static_cast<double>(counters.inserts) : 0.0, count(counters.replaced), count(counters.inserts), count(counters.unstable), count(dispatchCacheEvictions), dispatchCache.size(), count(counters.touches));
|
||||
std::vector<std::pair<std::uint64_t, std::uint64_t>> programs(counters.differingByProgram.begin(), counters.differingByProgram.end());
|
||||
std::sort(programs.begin(), programs.end(), [](const auto& a, const auto& b) { return a.second > b.second; });
|
||||
std::string top;
|
||||
@@ -51,21 +52,21 @@ void Driver::reportDispatchCache(EntryCounters& counters) {
|
||||
std::snprintf(text, sizeof(text), " 0x%llx x%llu", static_cast<unsigned long long>(programs[i].first), count(programs[i].second));
|
||||
top += text;
|
||||
}
|
||||
std::fprintf(stderr, "[dispatch-cache] differing by class (10 s, %llu classified): address-only %llu, data-only %llu, walk %llu, mixed %llu (runs changed %llu); matched one of the last 3 value sets %llu; differing words %llu in total (misses with 1 / 2-4 / 5-16 / >16 words: %llu / %llu / %llu / %llu), %zu distinct positions (first %zu, last %zu); top programs by differing:%s\n", count(counters.differingClassified), count(counters.differingAddress), count(counters.differingData), count(counters.differingWalk), count(counters.differingMixed), count(counters.differingRunsChanged), count(counters.differingMatchedPrior), count(counters.differingWords), count(counters.differingWordBuckets[0]), count(counters.differingWordBuckets[1]), count(counters.differingWordBuckets[2]), count(counters.differingWordBuckets[3]), counters.differingPositions.size(), counters.differingPositions.empty() ? std::size_t{0} : counters.differingFirstPosition, counters.differingLastPosition, top.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch-cache] differing by class (10 s, %llu classified): address-only %llu, data-only %llu, walk %llu, mixed %llu (runs changed %llu); matched one of the last 3 value sets %llu; differing words %llu in total (misses with 1 / 2-4 / 5-16 / >16 words: %llu / %llu / %llu / %llu), %zu distinct positions (first %zu, last %zu); top programs by differing:%s\n", count(counters.differingClassified), count(counters.differingAddress), count(counters.differingData), count(counters.differingWalk), count(counters.differingMixed), count(counters.differingRunsChanged), count(counters.differingMatchedPrior), count(counters.differingWords), count(counters.differingWordBuckets[0]), count(counters.differingWordBuckets[1]), count(counters.differingWordBuckets[2]), count(counters.differingWordBuckets[3]), counters.differingPositions.size(), counters.differingPositions.empty() ? std::size_t{0} : counters.differingFirstPosition, counters.differingLastPosition, top.c_str());
|
||||
std::string ranks;
|
||||
for (std::size_t rank = 0; rank < dispatchVariants(); ++rank) {
|
||||
char text[32];
|
||||
std::snprintf(text, sizeof(text), "%s%llu", rank == 0 ? "" : " / ", count(counters.variantHitsByRank[rank]));
|
||||
ranks += text;
|
||||
}
|
||||
std::fprintf(stderr, "[dispatch-cache] variants (10 s, k = %zu): hits by rank 1..k %s; %.2f variants compared per validation; %llu inserted into an entry, %llu evicted beyond k; %.2f variants per entry (%llu over %zu entries, ~%.1f MiB)\n", dispatchVariants(), ranks.c_str(), validated != 0 ? static_cast<double>(counters.variantsCompared) / static_cast<double>(validated) : 0.0, count(counters.variantsInserted), count(counters.variantsEvicted), dispatchCache.empty() ? 0.0 : static_cast<double>(dispatchCacheVariants) / static_cast<double>(dispatchCache.size()), count(dispatchCacheVariants), dispatchCache.size(), static_cast<double>(dispatchCacheVariantBytes) / (1024.0 * 1024.0));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch-cache] variants (10 s, k = %zu): hits by rank 1..k %s; %.2f variants compared per validation; %llu inserted into an entry, %llu evicted beyond k; %.2f variants per entry (%llu over %zu entries, ~%.1f MiB)\n", dispatchVariants(), ranks.c_str(), validated != 0 ? static_cast<double>(counters.variantsCompared) / static_cast<double>(validated) : 0.0, count(counters.variantsInserted), count(counters.variantsEvicted), dispatchCache.empty() ? 0.0 : static_cast<double>(dispatchCacheVariants) / static_cast<double>(dispatchCache.size()), count(dispatchCacheVariants), dispatchCache.size(), static_cast<double>(dispatchCacheVariantBytes) / (1024.0 * 1024.0));
|
||||
std::string dataRanks;
|
||||
for (std::size_t rank = 0; rank < dispatchVariants(); ++rank) {
|
||||
char text[32];
|
||||
std::snprintf(text, sizeof(text), "%s%llu", rank == 0 ? "" : " / ", count(counters.dataHitsByRank[rank]));
|
||||
dataRanks += text;
|
||||
}
|
||||
std::fprintf(stderr, "[dispatch-cache] data hits (10 s): %llu (%llu words refreshed; by rank 1..k %s; %llu data variants missed on pending runs), verified %llu; inserts with data positions %llu of %llu (%.1f positions each), leaves skipped: unmapped %llu, mismatched %llu, aliased %llu\n", count(counters.dataHits), count(counters.dataWordsRefreshed), dataRanks.c_str(), count(dataPendingMisses.exchange(0, std::memory_order_relaxed)), count(counters.dataVerified), count(counters.dataInserts), count(counters.inserts), counters.dataInserts != 0 ? static_cast<double>(counters.dataPositionsInserted) / static_cast<double>(counters.dataInserts) : 0.0, count(counters.dataLeavesUnmapped), count(counters.dataLeavesMismatched), count(counters.dataLeavesAliased));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch-cache] data hits (10 s): %llu (%llu words refreshed; by rank 1..k %s; %llu data variants missed on pending runs), verified %llu; inserts with data positions %llu of %llu (%.1f positions each), leaves skipped: unmapped %llu, mismatched %llu, aliased %llu\n", count(counters.dataHits), count(counters.dataWordsRefreshed), dataRanks.c_str(), count(dataPendingMisses.exchange(0, std::memory_order_relaxed)), count(counters.dataVerified), count(counters.dataInserts), count(counters.inserts), counters.dataInserts != 0 ? static_cast<double>(counters.dataPositionsInserted) / static_cast<double>(counters.dataInserts) : 0.0, count(counters.dataLeavesUnmapped), count(counters.dataLeavesMismatched), count(counters.dataLeavesAliased));
|
||||
counters = EntryCounters{};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Dispatch/DispatchTiming.hpp"
|
||||
|
||||
@@ -25,7 +26,7 @@ void Driver::addDriverPhases(DispatchClass which, const std::array<double, Drive
|
||||
total += line.ms[i];
|
||||
}
|
||||
const double perValidation = line.validations != 0 ? 1000 / static_cast<double>(line.validations) : 0.0;
|
||||
std::fprintf(stderr, "[dispatch] driver phases %s (10 s, %llu dispatches, %llu cache hits), us per dispatch:%s, total %.1f (%.1f ms); validate %.1f us per validation (%llu validations; GPU waits inside it %.1f us per validation apart)\n", DispatchClassNames[cls], static_cast<unsigned long long>(line.dispatches), static_cast<unsigned long long>(line.hits), report.c_str(), total * 1000 / static_cast<double>(line.dispatches), total, line.ms[PhaseValidate] * perValidation, static_cast<unsigned long long>(line.validations), line.ms[PhaseValidateWait] * perValidation);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch] driver phases %s (10 s, %llu dispatches, %llu cache hits), us per dispatch:%s, total %.1f (%.1f ms); validate %.1f us per validation (%llu validations; GPU waits inside it %.1f us per validation apart)\n", DispatchClassNames[cls], static_cast<unsigned long long>(line.dispatches), static_cast<unsigned long long>(line.hits), report.c_str(), total * 1000 / static_cast<double>(line.dispatches), total, line.ms[PhaseValidate] * perValidation, static_cast<unsigned long long>(line.validations), line.ms[PhaseValidateWait] * perValidation);
|
||||
line = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
|
||||
namespace AgcDriver::DriverDetail {
|
||||
@@ -12,8 +13,8 @@ void Driver::reportDrawCache(DrawEntryCounters& counters) {
|
||||
std::snprintf(text, sizeof(text), "%s%llu", rank == 0 ? "" : " / ", count(counters.variantHitsByRank[rank]));
|
||||
ranks += text;
|
||||
}
|
||||
std::fprintf(stderr, "[draw-cache] %llu lookups (10 s): %llu no entry, %llu validated in %.1f us each (key, lookup and every stage): %llu hits (every stage equal; stage hits by variant rank 1..k %s), misses by reason: front stage differing %llu, fragment differing %llu, other stage differing %llu, layout (push offset) %llu, gate %llu, stage count %llu; %llu stage validations (%llu equal, %.2f variants compared each); %llu inserts (%llu variants inserted, %llu evicted beyond k, %llu already present, %llu unstable), %zu entries (%llu variants, ~%.1f MiB), %llu evictions in total, %llu LRU moves; verify: %llu hits captured again, %llu stages differed\n", count(counters.lookups), count(counters.absent), count(validated), validated != 0 ? counters.validateUs / static_cast<double>(validated) : 0.0, count(counters.hits), ranks.c_str(), miss(DrawMiss::FrontDiffering), miss(DrawMiss::FragmentDiffering), miss(DrawMiss::OtherDiffering), miss(DrawMiss::Layout), miss(DrawMiss::Gate), miss(DrawMiss::Stages), count(counters.stageValidations), count(counters.stageEqual), counters.stageValidations != 0 ? static_cast<double>(counters.variantsCompared) / static_cast<double>(counters.stageValidations) : 0.0, count(counters.inserts), count(counters.variantsInserted), count(counters.variantsEvicted), count(counters.present), count(counters.unstable), drawCache.size(), count(drawCacheVariants), static_cast<double>(drawCacheVariantBytes) / (1024.0 * 1024.0), count(drawCacheEvictions), count(counters.touches), count(counters.verifyHits), count(counters.verifyMismatches));
|
||||
std::fprintf(stderr, "[draw-cache] register key (10 s): %llu lookups, %llu hits, key build %.1f us each; decode skipped %llu, partial (state/pixel/programs from the entry) %llu; facade log != table %llu; verify: %llu decodes compared, %llu differed\n", count(counters.registerKeyLookups), count(counters.registerKeyHits), counters.registerKeyLookups != 0 ? counters.keyUs / static_cast<double>(counters.registerKeyLookups) : 0.0, count(counters.decodeSkipped), count(counters.decodePartial), count(counters.facadeMismatches), count(counters.verifyDecodes), count(counters.verifyDecodeMismatches));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[draw-cache] %llu lookups (10 s): %llu no entry, %llu validated in %.1f us each (key, lookup and every stage): %llu hits (every stage equal; stage hits by variant rank 1..k %s), misses by reason: front stage differing %llu, fragment differing %llu, other stage differing %llu, layout (push offset) %llu, gate %llu, stage count %llu; %llu stage validations (%llu equal, %.2f variants compared each); %llu inserts (%llu variants inserted, %llu evicted beyond k, %llu already present, %llu unstable), %zu entries (%llu variants, ~%.1f MiB), %llu evictions in total, %llu LRU moves; verify: %llu hits captured again, %llu stages differed\n", count(counters.lookups), count(counters.absent), count(validated), validated != 0 ? counters.validateUs / static_cast<double>(validated) : 0.0, count(counters.hits), ranks.c_str(), miss(DrawMiss::FrontDiffering), miss(DrawMiss::FragmentDiffering), miss(DrawMiss::OtherDiffering), miss(DrawMiss::Layout), miss(DrawMiss::Gate), miss(DrawMiss::Stages), count(counters.stageValidations), count(counters.stageEqual), counters.stageValidations != 0 ? static_cast<double>(counters.variantsCompared) / static_cast<double>(counters.stageValidations) : 0.0, count(counters.inserts), count(counters.variantsInserted), count(counters.variantsEvicted), count(counters.present), count(counters.unstable), drawCache.size(), count(drawCacheVariants), static_cast<double>(drawCacheVariantBytes) / (1024.0 * 1024.0), count(drawCacheEvictions), count(counters.touches), count(counters.verifyHits), count(counters.verifyMismatches));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[draw-cache] register key (10 s): %llu lookups, %llu hits, key build %.1f us each; decode skipped %llu, partial (state/pixel/programs from the entry) %llu; facade log != table %llu; verify: %llu decodes compared, %llu differed\n", count(counters.registerKeyLookups), count(counters.registerKeyHits), counters.registerKeyLookups != 0 ? counters.keyUs / static_cast<double>(counters.registerKeyLookups) : 0.0, count(counters.decodeSkipped), count(counters.decodePartial), count(counters.facadeMismatches), count(counters.verifyDecodes), count(counters.verifyDecodeMismatches));
|
||||
counters = DrawEntryCounters{};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawTiming.hpp"
|
||||
|
||||
@@ -26,7 +27,7 @@ void Driver::addDrawPhases(const std::array<double, DrawDriverPhaseCount>& ms, b
|
||||
report += text;
|
||||
total += totals.ms[i];
|
||||
}
|
||||
std::fprintf(stderr, "[draw] driver phases (10 s, %llu draw packets, %llu drawn, %llu captures), us per packet:%s, total %.1f (%.1f ms; Graphics::Draw %.1f ms, skipped %.1f ms)\n", static_cast<unsigned long long>(totals.packets), static_cast<unsigned long long>(totals.drawn), static_cast<unsigned long long>(totals.captures), report.c_str(), total * 1000 / static_cast<double>(totals.packets), total, totals.ms[DrawRowGraphics], totals.ms[DrawRowSkipped]);
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[draw] driver phases (10 s, %llu draw packets, %llu drawn, %llu captures), us per packet:%s, total %.1f (%.1f ms; Graphics::Draw %.1f ms, skipped %.1f ms)\n", static_cast<unsigned long long>(totals.packets), static_cast<unsigned long long>(totals.drawn), static_cast<unsigned long long>(totals.captures), report.c_str(), total * 1000 / static_cast<double>(totals.packets), total, totals.ms[DrawRowGraphics], totals.ms[DrawRowSkipped]);
|
||||
totals.ms = {};
|
||||
totals.packets = totals.drawn = totals.captures = 0;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
|
||||
namespace AgcDriver::DriverDetail {
|
||||
@@ -30,7 +31,7 @@ void Driver::reportValidation(ValidateCounters& counters) {
|
||||
if (evidence.streak >= writeEvidenceAfter()) ++eligible;
|
||||
}
|
||||
}
|
||||
std::fprintf(stderr, "[validate] dispatch-cache compares over pending GPU writes (10 s): %llu; missed without the sync %llu, skipped the sync %llu, synced %llu waiting %.0f ms (no dispatch writer %llu, foreign writer %llu, larger range %llu, label %llu, evidence short %llu, writer changed %llu, sampled %llu, image %llu, shadow %llu, off %llu); known-value reads %llu; verify: %llu would-skip compares synced anyway (%.0f ms), %llu mismatches, %llu misses a sync made hits; dwords observed over waits: %llu unchanged, %llu changed (regions not observed: %llu after no GPU wait, %llu not compared); %zu tracked, %zu with a streak\n", count(counters.pending), count(counters.unsyncedMisses), count(counters.skipped), count(counters.syncedNoWriter + counters.syncedForeign + counters.syncedLargeRange + counters.syncedLabel + counters.syncedEvidence + counters.syncedWriterChanged + counters.syncedSample + counters.syncedImage + counters.syncedShadow + counters.syncedOff), counters.syncedWaitMs, count(counters.syncedNoWriter), count(counters.syncedForeign), count(counters.syncedLargeRange), count(counters.syncedLabel), count(counters.syncedEvidence), count(counters.syncedWriterChanged), count(counters.syncedSample), count(counters.syncedImage), count(counters.syncedShadow), count(counters.syncedOff), count(counters.knownValue), count(counters.verified), counters.verifiedWaitMs, count(counters.mismatches), count(counters.verifiedMissesHit), count(observedUnchanged.exchange(0)), count(observedChanged.exchange(0)), count(observationsNoWait.exchange(0)), count(observationsNotReached.exchange(0)), tracked, eligible);
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[validate] dispatch-cache compares over pending GPU writes (10 s): %llu; missed without the sync %llu, skipped the sync %llu, synced %llu waiting %.0f ms (no dispatch writer %llu, foreign writer %llu, larger range %llu, label %llu, evidence short %llu, writer changed %llu, sampled %llu, image %llu, shadow %llu, off %llu); known-value reads %llu; verify: %llu would-skip compares synced anyway (%.0f ms), %llu mismatches, %llu misses a sync made hits; dwords observed over waits: %llu unchanged, %llu changed (regions not observed: %llu after no GPU wait, %llu not compared); %zu tracked, %zu with a streak\n", count(counters.pending), count(counters.unsyncedMisses), count(counters.skipped), count(counters.syncedNoWriter + counters.syncedForeign + counters.syncedLargeRange + counters.syncedLabel + counters.syncedEvidence + counters.syncedWriterChanged + counters.syncedSample + counters.syncedImage + counters.syncedShadow + counters.syncedOff), counters.syncedWaitMs, count(counters.syncedNoWriter), count(counters.syncedForeign), count(counters.syncedLargeRange), count(counters.syncedLabel), count(counters.syncedEvidence), count(counters.syncedWriterChanged), count(counters.syncedSample), count(counters.syncedImage), count(counters.syncedShadow), count(counters.syncedOff), count(counters.knownValue), count(counters.verified), counters.verifiedWaitMs, count(counters.mismatches), count(counters.verifiedMissesHit), count(observedUnchanged.exchange(0)), count(observedChanged.exchange(0)), count(observationsNoWait.exchange(0)), count(observationsNotReached.exchange(0)), tracked, eligible);
|
||||
counters = ValidateCounters{};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "ThreadOwned.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Diagnostics.hpp"
|
||||
@@ -24,7 +25,7 @@ void Driver::timed(double WorkerProfile::*bucket, TWork&& work) {
|
||||
static const bool report = std::getenv("APS5_PROFILE_DRAW") != nullptr;
|
||||
if (report && end - profile.reported > std::chrono::seconds(10)) {
|
||||
profile.reported = end;
|
||||
std::fprintf(stderr, "[gpu] worker at %.0f s: dispatch %.1f s, draw %.1f s, wait %.1f s\n", std::chrono::duration<double>(end - profile.start).count(), profile.dispatchMs / 1000, profile.drawMs / 1000, profile.waitMs / 1000);
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[gpu] worker at %.0f s: dispatch %.1f s, draw %.1f s, wait %.1f s\n", std::chrono::duration<double>(end - profile.start).count(), profile.dispatchMs / 1000, profile.drawMs / 1000, profile.waitMs / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/DeferredLabels.hpp"
|
||||
@@ -98,7 +99,7 @@ void Driver::flushBetweenPackets(std::uint32_t queue, std::uint32_t header, bool
|
||||
lastReport = reportNow;
|
||||
const auto stores = Graphics::Recorder::StoreCounts();
|
||||
const auto failed = [](TrySite site) { return static_cast<unsigned long long>(triesFailed[site].load()); };
|
||||
std::fprintf(stderr, "[labels] batch flushes between packets: %llu at the next packet, %llu by deadline, %llu by size cap (%llu well overdue, waited for the mutex); %llu boundary reaps; record tries skipped (self-locking next) %llu; failed tries: label %llu, flush %llu, reap %llu, poll %llu, idle %llu, capture %llu, poll-record %llu; at the packet's own lock: %llu label groups (%.0f ms), %llu submits (%.0f ms incl. queue 0's reaps), left to it by a failed try: %llu groups, %llu submits; after a capture: %llu groups recorded by a try, %llu packets redone for a queued label over the capture; %llu suspend points; stores: %llu in %llu runs (%llu joined, %llu replaced, %llu WAW barriers, %llu joins refused; %llu runs recorded at submit, %llu in place before a writer or reader); DCC key stores: %llu queued in %llu runs (%llu before a writer, %llu joined a queued range); queued labels: %llu noted (%llu over a recorded entry), %llu same-queue wait hits, %llu groups recorded from a poll loop, %llu from the flush hook (%llu hook accesses, %llu inside a completion skipped)\n", static_cast<unsigned long long>(packetFlushes.load()), static_cast<unsigned long long>(deadlineFlushes.load()), static_cast<unsigned long long>(capFlushes.load()), static_cast<unsigned long long>(overdueLocks.load()), static_cast<unsigned long long>(boundaryReaps.load()), static_cast<unsigned long long>(recordTriesSkipped.load()), failed(TryLabel), failed(TryFlush), failed(TryReap), failed(TryPoll), failed(TryIdle), failed(TryCapture), failed(TryPollRecord), static_cast<unsigned long long>(packetLockRecords.load()), packetLockRecordUs.load() / 1000.0, static_cast<unsigned long long>(packetLockSubmits.load()), packetLockSubmitUs.load() / 1000.0, static_cast<unsigned long long>(packetLockDeferred.load()), static_cast<unsigned long long>(packetSubmitDeferred.load()), static_cast<unsigned long long>(captureTryRecords.load()), static_cast<unsigned long long>(captureRetries.load()), static_cast<unsigned long long>(suspendPoints.load()), static_cast<unsigned long long>(stores.stores), static_cast<unsigned long long>(stores.runs), static_cast<unsigned long long>(stores.joined), static_cast<unsigned long long>(stores.replaced), static_cast<unsigned long long>(stores.wawBarriers), static_cast<unsigned long long>(stores.joinsRefused), static_cast<unsigned long long>(stores.runsAtSubmit), static_cast<unsigned long long>(stores.runsForced), static_cast<unsigned long long>(stores.keyStores), static_cast<unsigned long long>(stores.keyStoreRuns), static_cast<unsigned long long>(stores.keyStoreRunsForWriter), static_cast<unsigned long long>(stores.keyStoresJoined), static_cast<unsigned long long>(stores.queuedNoted), static_cast<unsigned long long>(stores.queuedOverRecorded), static_cast<unsigned long long>(stores.queuedHits), static_cast<unsigned long long>(pollLabelRecords.load()), static_cast<unsigned long long>(hookLabelRecords.load()), static_cast<unsigned long long>(stores.queuedHookRecords), static_cast<unsigned long long>(stores.queuedHookInCompletion));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[labels] batch flushes between packets: %llu at the next packet, %llu by deadline, %llu by size cap (%llu well overdue, waited for the mutex); %llu boundary reaps; record tries skipped (self-locking next) %llu; failed tries: label %llu, flush %llu, reap %llu, poll %llu, idle %llu, capture %llu, poll-record %llu; at the packet's own lock: %llu label groups (%.0f ms), %llu submits (%.0f ms incl. queue 0's reaps), left to it by a failed try: %llu groups, %llu submits; after a capture: %llu groups recorded by a try, %llu packets redone for a queued label over the capture; %llu suspend points; stores: %llu in %llu runs (%llu joined, %llu replaced, %llu WAW barriers, %llu joins refused; %llu runs recorded at submit, %llu in place before a writer or reader); DCC key stores: %llu queued in %llu runs (%llu before a writer, %llu joined a queued range); queued labels: %llu noted (%llu over a recorded entry), %llu same-queue wait hits, %llu groups recorded from a poll loop, %llu from the flush hook (%llu hook accesses, %llu inside a completion skipped)\n", static_cast<unsigned long long>(packetFlushes.load()), static_cast<unsigned long long>(deadlineFlushes.load()), static_cast<unsigned long long>(capFlushes.load()), static_cast<unsigned long long>(overdueLocks.load()), static_cast<unsigned long long>(boundaryReaps.load()), static_cast<unsigned long long>(recordTriesSkipped.load()), failed(TryLabel), failed(TryFlush), failed(TryReap), failed(TryPoll), failed(TryIdle), failed(TryCapture), failed(TryPollRecord), static_cast<unsigned long long>(packetLockRecords.load()), packetLockRecordUs.load() / 1000.0, static_cast<unsigned long long>(packetLockSubmits.load()), packetLockSubmitUs.load() / 1000.0, static_cast<unsigned long long>(packetLockDeferred.load()), static_cast<unsigned long long>(packetSubmitDeferred.load()), static_cast<unsigned long long>(captureTryRecords.load()), static_cast<unsigned long long>(captureRetries.load()), static_cast<unsigned long long>(suspendPoints.load()), static_cast<unsigned long long>(stores.stores), static_cast<unsigned long long>(stores.runs), static_cast<unsigned long long>(stores.joined), static_cast<unsigned long long>(stores.replaced), static_cast<unsigned long long>(stores.wawBarriers), static_cast<unsigned long long>(stores.joinsRefused), static_cast<unsigned long long>(stores.runsAtSubmit), static_cast<unsigned long long>(stores.runsForced), static_cast<unsigned long long>(stores.keyStores), static_cast<unsigned long long>(stores.keyStoreRuns), static_cast<unsigned long long>(stores.keyStoreRunsForWriter), static_cast<unsigned long long>(stores.keyStoresJoined), static_cast<unsigned long long>(stores.queuedNoted), static_cast<unsigned long long>(stores.queuedOverRecorded), static_cast<unsigned long long>(stores.queuedHits), static_cast<unsigned long long>(pollLabelRecords.load()), static_cast<unsigned long long>(hookLabelRecords.load()), static_cast<unsigned long long>(stores.queuedHookRecords), static_cast<unsigned long long>(stores.queuedHookInCompletion));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Packets/PacketTiming.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hpp"
|
||||
@@ -40,9 +41,9 @@ PacketTimer::~PacketTimer() {
|
||||
outcomes += text;
|
||||
}
|
||||
auto& poll = Driver::pollStats();
|
||||
std::fprintf(stderr, "[poll] queue 0x%x (10 s): ticks %llu, table hits %llu, tries %llu / failed %llu, submits %llu, reaps %llu (%llu with work; by reason: behind completion %llu / other %llu), refusals: %s %llu, %s %llu, %s %llu, %s %llu, %s %llu; longest try hold %.1f us, try holds %.1f ms\n", queue, static_cast<unsigned long long>(poll.ticks), static_cast<unsigned long long>(poll.tableHits), static_cast<unsigned long long>(poll.tries), static_cast<unsigned long long>(poll.triesFailed), static_cast<unsigned long long>(poll.submits), static_cast<unsigned long long>(poll.reaps), static_cast<unsigned long long>(poll.reapsWithWork), static_cast<unsigned long long>(poll.reapsBehindCompletion), static_cast<unsigned long long>(poll.reapsOther), LabelRefusalNames[1], static_cast<unsigned long long>(poll.refusals[1]), LabelRefusalNames[2], static_cast<unsigned long long>(poll.refusals[2]), LabelRefusalNames[3], static_cast<unsigned long long>(poll.refusals[3]), LabelRefusalNames[4], static_cast<unsigned long long>(poll.refusals[4]), LabelRefusalNames[5], static_cast<unsigned long long>(poll.refusals[5]), poll.longestTryHoldUs, poll.tryHoldUs / 1000.0);
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[poll] queue 0x%x (10 s): ticks %llu, table hits %llu, tries %llu / failed %llu, submits %llu, reaps %llu (%llu with work; by reason: behind completion %llu / other %llu), refusals: %s %llu, %s %llu, %s %llu, %s %llu, %s %llu; longest try hold %.1f us, try holds %.1f ms\n", queue, static_cast<unsigned long long>(poll.ticks), static_cast<unsigned long long>(poll.tableHits), static_cast<unsigned long long>(poll.tries), static_cast<unsigned long long>(poll.triesFailed), static_cast<unsigned long long>(poll.submits), static_cast<unsigned long long>(poll.reaps), static_cast<unsigned long long>(poll.reapsWithWork), static_cast<unsigned long long>(poll.reapsBehindCompletion), static_cast<unsigned long long>(poll.reapsOther), LabelRefusalNames[1], static_cast<unsigned long long>(poll.refusals[1]), LabelRefusalNames[2], static_cast<unsigned long long>(poll.refusals[2]), LabelRefusalNames[3], static_cast<unsigned long long>(poll.refusals[3]), LabelRefusalNames[4], static_cast<unsigned long long>(poll.refusals[4]), LabelRefusalNames[5], static_cast<unsigned long long>(poll.refusals[5]), poll.longestTryHoldUs, poll.tryHoldUs / 1000.0);
|
||||
poll = PollStats{};
|
||||
std::fprintf(stderr, "[packets] queue 0x%x %llu submissions, time by packet (10 s):%s, flush %.0fms; DISPATCH_DIRECT by outcome:%s; per submission (%llu submitted): validate %.1f us, copy %.1f us, dequeue %.1f us, complete %.1f us; suspend points %llu x %.1f us, %llu skipped (nothing open); end submits %llu made, %llu skipped, %llu notifies skipped; waits satisfied: at entry %llu, from recorder %llu (%llu while polling, same queue %llu, %llu without the GPU mutex, %llu late-trusted), polled %llu (%llu entered without the GPU mutex, %llu entry tries failed; late candidates %llu: refused cpu-store %llu, overwritten %llu, unclosed %llu, queued %llu), timed out %llu; poll submits %llu, poll reaps %llu; epoch bumps: submissions %llu, waits %llu, drains %llu, reaps %llu, packets %llu\n", queue, static_cast<unsigned long long>(profile.submissions), report.c_str(), profile.flushMs, outcomes.c_str(), static_cast<unsigned long long>(submitted), validateUs, copyUs, dequeueUs, completeUs, static_cast<unsigned long long>(suspends), suspendUs, static_cast<unsigned long long>(costs.suspendsSkipped.exchange(0)), static_cast<unsigned long long>(costs.endSubmits.exchange(0)), static_cast<unsigned long long>(costs.endSkipped.exchange(0)), static_cast<unsigned long long>(costs.notifiesSkipped.exchange(0)), static_cast<unsigned long long>(waits.atEntry), static_cast<unsigned long long>(waits.fromRecorder + waits.fromRecorderPolling), static_cast<unsigned long long>(waits.fromRecorderPolling), static_cast<unsigned long long>(waits.fromRecorderSameQueue), static_cast<unsigned long long>(waits.fromRecorderUnlocked), static_cast<unsigned long long>(waits.fromRecorderLate), static_cast<unsigned long long>(waits.polled), static_cast<unsigned long long>(waits.entriesUnlocked), static_cast<unsigned long long>(waits.entryTriesFailed), static_cast<unsigned long long>(late.candidates - lateSeen.candidates), static_cast<unsigned long long>(waits.lateRefusedCpuStore), static_cast<unsigned long long>(late.overwritten - lateSeen.overwritten), static_cast<unsigned long long>(late.unclosed - lateSeen.unclosed), static_cast<unsigned long long>(late.queued - lateSeen.queued), static_cast<unsigned long long>(waits.timedOut), static_cast<unsigned long long>(waits.pollSubmits), static_cast<unsigned long long>(waits.pollReaps), static_cast<unsigned long long>(epochs.submissions), static_cast<unsigned long long>(epochs.waits), static_cast<unsigned long long>(epochs.drains), static_cast<unsigned long long>(epochs.reaps), static_cast<unsigned long long>(epochs.packets));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[packets] queue 0x%x %llu submissions, time by packet (10 s):%s, flush %.0fms; DISPATCH_DIRECT by outcome:%s; per submission (%llu submitted): validate %.1f us, copy %.1f us, dequeue %.1f us, complete %.1f us; suspend points %llu x %.1f us, %llu skipped (nothing open); end submits %llu made, %llu skipped, %llu notifies skipped; waits satisfied: at entry %llu, from recorder %llu (%llu while polling, same queue %llu, %llu without the GPU mutex, %llu late-trusted), polled %llu (%llu entered without the GPU mutex, %llu entry tries failed; late candidates %llu: refused cpu-store %llu, overwritten %llu, unclosed %llu, queued %llu), timed out %llu; poll submits %llu, poll reaps %llu; epoch bumps: submissions %llu, waits %llu, drains %llu, reaps %llu, packets %llu\n", queue, static_cast<unsigned long long>(profile.submissions), report.c_str(), profile.flushMs, outcomes.c_str(), static_cast<unsigned long long>(submitted), validateUs, copyUs, dequeueUs, completeUs, static_cast<unsigned long long>(suspends), suspendUs, static_cast<unsigned long long>(costs.suspendsSkipped.exchange(0)), static_cast<unsigned long long>(costs.endSubmits.exchange(0)), static_cast<unsigned long long>(costs.endSkipped.exchange(0)), static_cast<unsigned long long>(costs.notifiesSkipped.exchange(0)), static_cast<unsigned long long>(waits.atEntry), static_cast<unsigned long long>(waits.fromRecorder + waits.fromRecorderPolling), static_cast<unsigned long long>(waits.fromRecorderPolling), static_cast<unsigned long long>(waits.fromRecorderSameQueue), static_cast<unsigned long long>(waits.fromRecorderUnlocked), static_cast<unsigned long long>(waits.fromRecorderLate), static_cast<unsigned long long>(waits.polled), static_cast<unsigned long long>(waits.entriesUnlocked), static_cast<unsigned long long>(waits.entryTriesFailed), static_cast<unsigned long long>(late.candidates - lateSeen.candidates), static_cast<unsigned long long>(waits.lateRefusedCpuStore), static_cast<unsigned long long>(late.overwritten - lateSeen.overwritten), static_cast<unsigned long long>(late.unclosed - lateSeen.unclosed), static_cast<unsigned long long>(late.queued - lateSeen.queued), static_cast<unsigned long long>(waits.timedOut), static_cast<unsigned long long>(waits.pollSubmits), static_cast<unsigned long long>(waits.pollReaps), static_cast<unsigned long long>(epochs.submissions), static_cast<unsigned long long>(epochs.waits), static_cast<unsigned long long>(epochs.drains), static_cast<unsigned long long>(epochs.reaps), static_cast<unsigned long long>(epochs.packets));
|
||||
lateSeen = late;
|
||||
waits = WaitOutcomes{};
|
||||
epochs = EpochBumps{};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Diagnostics.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Queues/WorkerAffinity.hpp"
|
||||
@@ -150,7 +151,7 @@ void Driver::reportPresents(double waitedMs, std::size_t inFlight) {
|
||||
const auto flips = flipsCounted.load() - previousFlips;
|
||||
const double perFlip = flips != 0 ? 1.0 / static_cast<double>(flips) : 0.0;
|
||||
const auto serial = flipSerial.load();
|
||||
std::fprintf(stderr, "[present] %llu presents over 10 s (%zu may trail on the GPU); %s p50 %.2f ms, p90 %.2f ms, max %.2f ms over %zu; per present: GPU busy %.1f ms, idle gaps %.1f ms (%llu batches without a completion record); per flip: %.1f batches recorded (%.1f unsignaled at the flip); per present: %.1f batches ahead of the blit, %.1f after it; after the flip packet: last submit %.1f ms, blit submit %.1f ms; in-place reads overwritten before execution: %llu of %llu checked\n", static_cast<unsigned long long>(presents), inFlight, inFlight != 0 ? "inflight_wait" : "render_fence_wait", percentile(0.5), percentile(0.9), waits.empty() ? 0.0 : waits.back(), waits.size(), (counts.gpuBusyMs - previous.gpuBusyMs) * perPresent, (counts.gpuGapMs - previous.gpuGapMs) * perPresent, static_cast<unsigned long long>(counts.gpuUnread - previous.gpuUnread), static_cast<double>(serial - windowSerial) * perFlip, static_cast<double>(flipBatchesUnsignaled.load() - previousUnsignaled) * perFlip, static_cast<double>(counts.batchesAheadOfBlit - previous.batchesAheadOfBlit) * perPresent, static_cast<double>(counts.batchesAfterFlip - previous.batchesAfterFlip) * perPresent, (counts.lastSubmitAfterFlipMs - previous.lastSubmitAfterFlipMs) * perPresent, (counts.blitSubmitAfterFlipMs - previous.blitSubmitAfterFlipMs) * perPresent, static_cast<unsigned long long>(counts.readsOverwritten - previous.readsOverwritten), static_cast<unsigned long long>(counts.readsChecked - previous.readsChecked));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[present] %llu presents over 10 s (%zu may trail on the GPU); %s p50 %.2f ms, p90 %.2f ms, max %.2f ms over %zu; per present: GPU busy %.1f ms, idle gaps %.1f ms (%llu batches without a completion record); per flip: %.1f batches recorded (%.1f unsignaled at the flip); per present: %.1f batches ahead of the blit, %.1f after it; after the flip packet: last submit %.1f ms, blit submit %.1f ms; in-place reads overwritten before execution: %llu of %llu checked\n", static_cast<unsigned long long>(presents), inFlight, inFlight != 0 ? "inflight_wait" : "render_fence_wait", percentile(0.5), percentile(0.9), waits.empty() ? 0.0 : waits.back(), waits.size(), (counts.gpuBusyMs - previous.gpuBusyMs) * perPresent, (counts.gpuGapMs - previous.gpuGapMs) * perPresent, static_cast<unsigned long long>(counts.gpuUnread - previous.gpuUnread), static_cast<double>(serial - windowSerial) * perFlip, static_cast<double>(flipBatchesUnsignaled.load() - previousUnsignaled) * perFlip, static_cast<double>(counts.batchesAheadOfBlit - previous.batchesAheadOfBlit) * perPresent, static_cast<double>(counts.batchesAfterFlip - previous.batchesAfterFlip) * perPresent, (counts.lastSubmitAfterFlipMs - previous.lastSubmitAfterFlipMs) * perPresent, (counts.blitSubmitAfterFlipMs - previous.blitSubmitAfterFlipMs) * perPresent, static_cast<unsigned long long>(counts.readsOverwritten - previous.readsOverwritten), static_cast<unsigned long long>(counts.readsChecked - previous.readsChecked));
|
||||
previous = counts;
|
||||
previousFlips = flipsCounted.load();
|
||||
previousUnsignaled = flipBatchesUnsignaled.load();
|
||||
|
||||
@@ -6,10 +6,78 @@
|
||||
#include "Optimization/ResourceProgram.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
#include "RdnaDecoder/RdnaInstructionDecoder.hpp"
|
||||
|
||||
namespace AgcDriver::DriverDetail {
|
||||
|
||||
std::shared_ptr<const ShaderSnapshot> ReadRawComputeShader(std::uint64_t address) {
|
||||
GuestMemory::CheckRange(reinterpret_cast<const void*>(address), sizeof(std::uint32_t), 256);
|
||||
static std::mutex cacheMutex;
|
||||
static std::list<std::shared_ptr<const ShaderSnapshot>> cache;
|
||||
static std::size_t cacheBytes = 0;
|
||||
std::shared_ptr<const ShaderSnapshot> cached;
|
||||
{
|
||||
std::lock_guard lock(cacheMutex);
|
||||
const auto found = std::find_if(cache.begin(), cache.end(), [address](const auto& entry) { return entry->codeAddress == address; });
|
||||
if (found != cache.end()) cached = *found;
|
||||
}
|
||||
if (cached) {
|
||||
const auto code = std::as_bytes(std::span(cached->code));
|
||||
GuestMemory::FlushGpuWrites(address, code.size());
|
||||
if (GuestMemory::CompareMapped(address, code) == GuestMemory::Compare::Equal) {
|
||||
std::lock_guard lock(cacheMutex);
|
||||
const auto found = std::find(cache.begin(), cache.end(), cached);
|
||||
if (found != cache.end()) cache.splice(cache.begin(), cache, found);
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
constexpr std::size_t limit = 1024 * 1024;
|
||||
const auto ranges = GuestMemory::CommittedRanges(address, limit);
|
||||
std::uint64_t end = address;
|
||||
for (const auto& range : ranges) {
|
||||
if (range.first != end) break;
|
||||
end = range.second;
|
||||
}
|
||||
const auto available = static_cast<std::size_t>(end - address) / sizeof(std::uint32_t);
|
||||
ShaderSnapshot snapshot{address, 0, 0, {}, {}};
|
||||
while (snapshot.code.size() < available) {
|
||||
const auto previous = snapshot.code.size();
|
||||
snapshot.code.resize(std::min(available, std::max<std::size_t>(64, previous * 2)));
|
||||
GuestMemory::Read(address + previous * sizeof(std::uint32_t),
|
||||
std::as_writable_bytes(std::span(snapshot.code).subspan(previous)), alignof(std::uint32_t));
|
||||
try {
|
||||
const auto decoded = ShaderRecompiler::RdnaInstructionDecoder{}.Decode(snapshot.code);
|
||||
const auto& last = decoded.instructions.back();
|
||||
snapshot.code.resize(last.programCounter / sizeof(std::uint32_t) + last.wordCount);
|
||||
auto result = std::make_shared<const ShaderSnapshot>(std::move(snapshot));
|
||||
std::lock_guard lock(cacheMutex);
|
||||
const auto found = std::find_if(cache.begin(), cache.end(), [address](const auto& entry) { return entry->codeAddress == address; });
|
||||
if (found != cache.end()) {
|
||||
if ((*found)->code == result->code) {
|
||||
result = *found;
|
||||
cache.splice(cache.begin(), cache, found);
|
||||
return result;
|
||||
}
|
||||
cacheBytes -= (*found)->code.size() * sizeof(std::uint32_t);
|
||||
cache.erase(found);
|
||||
}
|
||||
const auto bytes = result->code.size() * sizeof(std::uint32_t);
|
||||
while (!cache.empty() && (cache.size() >= 64 || cacheBytes + bytes > 8 * 1024 * 1024)) {
|
||||
cacheBytes -= cache.back()->code.size() * sizeof(std::uint32_t);
|
||||
cache.pop_back();
|
||||
}
|
||||
cache.push_front(result);
|
||||
cacheBytes += bytes;
|
||||
return result;
|
||||
} catch (const std::out_of_range&) {
|
||||
if (snapshot.code.size() == available) break;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("AGC driver: raw compute program has no reachable end within mapped code or the size limit");
|
||||
}
|
||||
|
||||
bool FailureMemo() {
|
||||
static const bool memo = std::getenv("APS5_NO_FAILURE_MEMO") == nullptr;
|
||||
return memo;
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Synchronization/SynchronizationStatistics.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
|
||||
@@ -38,7 +39,7 @@ SubmissionCosts& submissionCosts(std::uint32_t queue) {
|
||||
void reportSync() {
|
||||
std::string report;
|
||||
for (const auto& [code, count] : drainCounts) report += " " + (code == 0xffffu ? std::string("flip") : Pm4::Name(code << 8u)) + "=" + std::to_string(count);
|
||||
std::fprintf(stderr, "[sync] %llu device drains by packet:%s (%llu waited without the GPU mutex); %llu labels written on the GPU, %llu deferred behind completions, %llu deferred not imported, %llu no-op, fallbacks: idle %llu, completions %llu, not imported %llu, undecodable %llu; %llu labels queued per worker, recorded in %llu groups, %llu recorded at once; stores: %llu recorded on the GPU, %llu behind completions, %llu on the CPU (idle), %llu synced (drained)\n", static_cast<unsigned long long>(drainTotal), report.c_str(), static_cast<unsigned long long>(unlockedDrains.load()), static_cast<unsigned long long>(gpuLabels.load()), static_cast<unsigned long long>(completionLabels.load()), static_cast<unsigned long long>(notImportedLabels.load()), static_cast<unsigned long long>(noOpLabels.load()), static_cast<unsigned long long>(labelFallbacks[1].load()), static_cast<unsigned long long>(labelFallbacks[2].load()), static_cast<unsigned long long>(labelFallbacks[3].load()), static_cast<unsigned long long>(labelFallbacks[4].load()), static_cast<unsigned long long>(queuedLabels.load()), static_cast<unsigned long long>(labelGroups.load()), static_cast<unsigned long long>(immediateLabels.load()), static_cast<unsigned long long>(storesOnGpu.load()), static_cast<unsigned long long>(storesBehindCompletions.load()), static_cast<unsigned long long>(storesOnCpu.load()), static_cast<unsigned long long>(storesDrained.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[sync] %llu device drains by packet:%s (%llu waited without the GPU mutex); %llu labels written on the GPU, %llu deferred behind completions, %llu deferred not imported, %llu no-op, fallbacks: idle %llu, completions %llu, not imported %llu, undecodable %llu; %llu labels queued per worker, recorded in %llu groups, %llu recorded at once; stores: %llu recorded on the GPU, %llu behind completions, %llu on the CPU (idle), %llu synced (drained)\n", static_cast<unsigned long long>(drainTotal), report.c_str(), static_cast<unsigned long long>(unlockedDrains.load()), static_cast<unsigned long long>(gpuLabels.load()), static_cast<unsigned long long>(completionLabels.load()), static_cast<unsigned long long>(notImportedLabels.load()), static_cast<unsigned long long>(noOpLabels.load()), static_cast<unsigned long long>(labelFallbacks[1].load()), static_cast<unsigned long long>(labelFallbacks[2].load()), static_cast<unsigned long long>(labelFallbacks[3].load()), static_cast<unsigned long long>(labelFallbacks[4].load()), static_cast<unsigned long long>(queuedLabels.load()), static_cast<unsigned long long>(labelGroups.load()), static_cast<unsigned long long>(immediateLabels.load()), static_cast<unsigned long long>(storesOnGpu.load()), static_cast<unsigned long long>(storesBehindCompletions.load()), static_cast<unsigned long long>(storesOnCpu.load()), static_cast<unsigned long long>(storesDrained.load()));
|
||||
}
|
||||
|
||||
void countLabelOutcome(int reason) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
|
||||
#include "ThreadOwned.hpp"
|
||||
#include "prx/libc/include/GuestAllocations.hpp"
|
||||
@@ -292,30 +293,30 @@ public:
|
||||
auto last = state.lastReport.load();
|
||||
if (nowMs - last < 10000 || !state.lastReport.compare_exchange_strong(last, nowMs)) return;
|
||||
const auto totals = FoldMemoryCounters();
|
||||
std::fprintf(stderr, "[guestmem]");
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[guestmem]");
|
||||
for (std::size_t i = 0; i < MemoryCounterCount; ++i) {
|
||||
std::fprintf(stderr, " %s %llu calls %.0f MiB %.1f s", MemoryCounterNames[i], static_cast<unsigned long long>(totals[i][0]), totals[i][1] / 1048576.0, totals[i][2] / 1e9);
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" %s %llu calls %.0f MiB %.1f s", MemoryCounterNames[i], static_cast<unsigned long long>(totals[i][0]), totals[i][1] / 1048576.0, totals[i][2] / 1e9);
|
||||
}
|
||||
std::fprintf(stderr, " collect-memo hits %llu, collect epochs %llu", static_cast<unsigned long long>(collectMemoHits.load()), static_cast<unsigned long long>(collectEpochBumps.load()));
|
||||
std::fprintf(stderr, " collect-dirty %llu tracker waits %llu / %llu", static_cast<unsigned long long>(collectDirty.load()), static_cast<unsigned long long>(trackerWaits.load()), static_cast<unsigned long long>(trackerAcquisitions.load()));
|
||||
std::fprintf(stderr, " | arena 0x%llx+0x%llx image 0x%llx+0x%llx forgets %llu (%.0f MiB)", static_cast<unsigned long long>(PagesBase()), static_cast<unsigned long long>(PagesSize()), static_cast<unsigned long long>(ImagePagesBase()), static_cast<unsigned long long>(ImagePagesSize()), static_cast<unsigned long long>(forgetCalls.load()), forgetBytes.load() / 1048576.0);
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" collect-memo hits %llu, collect epochs %llu", static_cast<unsigned long long>(collectMemoHits.load()), static_cast<unsigned long long>(collectEpochBumps.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" collect-dirty %llu tracker waits %llu / %llu", static_cast<unsigned long long>(collectDirty.load()), static_cast<unsigned long long>(trackerWaits.load()), static_cast<unsigned long long>(trackerAcquisitions.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" | arena 0x%llx+0x%llx image 0x%llx+0x%llx forgets %llu (%.0f MiB)", static_cast<unsigned long long>(PagesBase()), static_cast<unsigned long long>(PagesSize()), static_cast<unsigned long long>(ImagePagesBase()), static_cast<unsigned long long>(ImagePagesSize()), static_cast<unsigned long long>(forgetCalls.load()), forgetBytes.load() / 1048576.0);
|
||||
{
|
||||
std::lock_guard lock(state.callersMutex);
|
||||
std::fprintf(stderr, " | read callers:");
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" | read callers:");
|
||||
for (const auto& [caller, count] : state.callers) {
|
||||
if (count != 0) std::fprintf(stderr, " +0x%llx=%llu", caller, static_cast<unsigned long long>(count));
|
||||
if (count != 0) AgcDriver::ProfilePrint_nid_no_patch(" +0x%llx=%llu", caller, static_cast<unsigned long long>(count));
|
||||
}
|
||||
std::fprintf(stderr, " | write callers:");
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" | write callers:");
|
||||
for (const auto& [caller, count] : state.writeCallers) {
|
||||
if (count != 0) std::fprintf(stderr, " +0x%llx=%llu", caller, static_cast<unsigned long long>(count));
|
||||
if (count != 0) AgcDriver::ProfilePrint_nid_no_patch(" +0x%llx=%llu", caller, static_cast<unsigned long long>(count));
|
||||
}
|
||||
}
|
||||
std::fprintf(stderr, " | read sites:");
|
||||
AgcDriver::ProfilePrint_nid_no_patch(" | read sites:");
|
||||
for (std::size_t site = 0; site < static_cast<std::size_t>(ReadSite::Count); ++site) {
|
||||
const auto count = readSiteSamples[site].load(std::memory_order_relaxed);
|
||||
if (count != 0) std::fprintf(stderr, " %s=%llu", ReadSiteName(static_cast<ReadSite>(site)), static_cast<unsigned long long>(count));
|
||||
if (count != 0) AgcDriver::ProfilePrint_nid_no_patch(" %s=%llu", ReadSiteName(static_cast<ReadSite>(site)), static_cast<unsigned long long>(count));
|
||||
}
|
||||
std::fprintf(stderr, "\n");
|
||||
AgcDriver::ProfilePrint_nid_no_patch("\n");
|
||||
}
|
||||
private:
|
||||
MemoryCounterKind kind;
|
||||
@@ -1504,8 +1505,8 @@ void GpuMutexType::lock() {
|
||||
char counts[160];
|
||||
std::snprintf(counts, sizeof(counts), "; lock() %llu / try %llu / try failed %llu; locked GPU waits %llu / %.0f ms", static_cast<unsigned long long>(stats.acquisitions), static_cast<unsigned long long>(stats.tries), static_cast<unsigned long long>(stats.triesFailed), static_cast<unsigned long long>(stats.lockedGpuWaits), stats.lockedGpuWaitMs);
|
||||
holds += counts;
|
||||
if (stats.tag == 0xffffffffu) std::fprintf(stderr, "[lock] %s waited %.0f ms for the GPU mutex in %llu of %llu acquisitions (%.0f s); by site (acquisitions/waits, waited):%s%s\n", stats.holderColumn == PresenterColumn ? "presenter" : "untagged thread", stats.waitedMs, static_cast<unsigned long long>(stats.waits), static_cast<unsigned long long>(stats.acquisitions), interval, sites.c_str(), holds.c_str());
|
||||
else std::fprintf(stderr, "[lock] queue 0x%x waited %.0f ms for the GPU mutex in %llu of %llu acquisitions (%.0f s); by site (acquisitions/waits, waited):%s%s\n", stats.tag, stats.waitedMs, static_cast<unsigned long long>(stats.waits), static_cast<unsigned long long>(stats.acquisitions), interval, sites.c_str(), holds.c_str());
|
||||
if (stats.tag == 0xffffffffu) AgcDriver::ProfilePrint_nid_no_patch("[lock] %s waited %.0f ms for the GPU mutex in %llu of %llu acquisitions (%.0f s); by site (acquisitions/waits, waited):%s%s\n", stats.holderColumn == PresenterColumn ? "presenter" : "untagged thread", stats.waitedMs, static_cast<unsigned long long>(stats.waits), static_cast<unsigned long long>(stats.acquisitions), interval, sites.c_str(), holds.c_str());
|
||||
else AgcDriver::ProfilePrint_nid_no_patch("[lock] queue 0x%x waited %.0f ms for the GPU mutex in %llu of %llu acquisitions (%.0f s); by site (acquisitions/waits, waited):%s%s\n", stats.tag, stats.waitedMs, static_cast<unsigned long long>(stats.waits), static_cast<unsigned long long>(stats.acquisitions), interval, sites.c_str(), holds.c_str());
|
||||
stats.waitedMs = 0;
|
||||
stats.waits = 0;
|
||||
stats.acquisitions = 0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/ShaderMemory.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
|
||||
#include "Optimization/RequestMemoryView.hpp"
|
||||
@@ -240,7 +241,7 @@ std::shared_ptr<const ShaderRecompiler::ResourceCapture> ShaderMemory::Capture(c
|
||||
const auto specializationNs = ShaderRecompiler::ResourceMaterializer::SpecializationNanoseconds();
|
||||
const auto hookNs = totals.hookWaitNanoseconds.load();
|
||||
const auto walkNs = captureNs > resolveNs + pageNs + wordNs + specializationNs ? captureNs - resolveNs - pageNs - wordNs - specializationNs : 0;
|
||||
std::fprintf(stderr, "[capture] %llu captures: %llu word reads, %llu pages fetched (%llu read word by word over pending GPU writes: %llu words waited %.2f s, %llu read raw on evidence, %llu verified with %llu mismatches, %llu served from known values, %llu hook reads not observed: no GPU wait), capture (plan lookup + materialize) %.1f s, %llu KiB registered code this capture; sub-phases (s, us per capture): source resolve %.2f/%.1f, walk %.2f/%.1f, specialization (every materialize) %.2f/%.1f, page reads %.2f/%.1f, word reads %.2f/%.1f, hook GPU waits inside %.2f/%.1f; source handle memo %llu hits, %llu resolves\n", static_cast<unsigned long long>(totals.captures.load()), static_cast<unsigned long long>(totals.reads.load()), static_cast<unsigned long long>(totals.pages.load()), static_cast<unsigned long long>(totals.pagesWordwise.load()), static_cast<unsigned long long>(totals.wordWaits.load()), totals.wordWaitNanoseconds.load() / 1e9, static_cast<unsigned long long>(totals.wordsRaw.load()), static_cast<unsigned long long>(totals.wordsVerified.load()), static_cast<unsigned long long>(totals.wordMismatches.load()), static_cast<unsigned long long>(totals.wordsKnown.load()), static_cast<unsigned long long>(totals.observationsSkipped.load()), captureNs / 1e9, static_cast<unsigned long long>(initialBytes / 1024), resolveNs / 1e9, resolveNs / captures / 1e3, walkNs / 1e9, walkNs / captures / 1e3, specializationNs / 1e9, specializationNs / captures / 1e3, pageNs / 1e9, pageNs / captures / 1e3, wordNs / 1e9, wordNs / captures / 1e3, hookNs / 1e9, hookNs / captures / 1e3, static_cast<unsigned long long>(totals.handleHits.load()), static_cast<unsigned long long>(totals.handleMisses.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[capture] %llu captures: %llu word reads, %llu pages fetched (%llu read word by word over pending GPU writes: %llu words waited %.2f s, %llu read raw on evidence, %llu verified with %llu mismatches, %llu served from known values, %llu hook reads not observed: no GPU wait), capture (plan lookup + materialize) %.1f s, %llu KiB registered code this capture; sub-phases (s, us per capture): source resolve %.2f/%.1f, walk %.2f/%.1f, specialization (every materialize) %.2f/%.1f, page reads %.2f/%.1f, word reads %.2f/%.1f, hook GPU waits inside %.2f/%.1f; source handle memo %llu hits, %llu resolves\n", static_cast<unsigned long long>(totals.captures.load()), static_cast<unsigned long long>(totals.reads.load()), static_cast<unsigned long long>(totals.pages.load()), static_cast<unsigned long long>(totals.pagesWordwise.load()), static_cast<unsigned long long>(totals.wordWaits.load()), totals.wordWaitNanoseconds.load() / 1e9, static_cast<unsigned long long>(totals.wordsRaw.load()), static_cast<unsigned long long>(totals.wordsVerified.load()), static_cast<unsigned long long>(totals.wordMismatches.load()), static_cast<unsigned long long>(totals.wordsKnown.load()), static_cast<unsigned long long>(totals.observationsSkipped.load()), captureNs / 1e9, static_cast<unsigned long long>(initialBytes / 1024), resolveNs / 1e9, resolveNs / captures / 1e3, walkNs / 1e9, walkNs / captures / 1e3, specializationNs / 1e9, specializationNs / captures / 1e3, pageNs / 1e9, pageNs / captures / 1e3, wordNs / 1e9, wordNs / captures / 1e3, hookNs / 1e9, hookNs / captures / 1e3, static_cast<unsigned long long>(totals.handleHits.load()), static_cast<unsigned long long>(totals.handleMisses.load()));
|
||||
}
|
||||
}
|
||||
return capture;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/CaptureTrace.hpp"
|
||||
#include "BdaAbi.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
|
||||
@@ -1327,7 +1328,7 @@ bool VulkanDevice::FillBuffer(std::uint64_t address, std::size_t bytes, std::spa
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now - lastReport > std::chrono::seconds(10)) {
|
||||
lastReport = now;
|
||||
std::fprintf(stderr, "[fill-sync] fills: %llu synced (%llu with a completion label pending) waited %.0f ms, %llu ordered by barrier, %llu with no pending write; phases ms: decide %.0f record %.0f notes %.0f; %llu uniform, %llu pattern (%llu doubling steps in place; pattern buffers reused %llu, made %llu)\n", static_cast<unsigned long long>(synced), static_cast<unsigned long long>(labelSynced), syncedMs, static_cast<unsigned long long>(ordered), static_cast<unsigned long long>(fills - synced - ordered), decideMs, recordMs, notesMs, static_cast<unsigned long long>(uniformFills), static_cast<unsigned long long>(patternFills), static_cast<unsigned long long>(doublingSteps), static_cast<unsigned long long>(patternBuffersReused), static_cast<unsigned long long>(patternBuffersMade));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[fill-sync] fills: %llu synced (%llu with a completion label pending) waited %.0f ms, %llu ordered by barrier, %llu with no pending write; phases ms: decide %.0f record %.0f notes %.0f; %llu uniform, %llu pattern (%llu doubling steps in place; pattern buffers reused %llu, made %llu)\n", static_cast<unsigned long long>(synced), static_cast<unsigned long long>(labelSynced), syncedMs, static_cast<unsigned long long>(ordered), static_cast<unsigned long long>(fills - synced - ordered), decideMs, recordMs, notesMs, static_cast<unsigned long long>(uniformFills), static_cast<unsigned long long>(patternFills), static_cast<unsigned long long>(doublingSteps), static_cast<unsigned long long>(patternBuffersReused), static_cast<unsigned long long>(patternBuffersMade));
|
||||
}
|
||||
}
|
||||
auto phaseStart = fillStart;
|
||||
@@ -1388,7 +1389,7 @@ bool VulkanDevice::FillBuffer(std::uint64_t address, std::size_t bytes, std::spa
|
||||
if ((covered & VK_ACCESS_TRANSFER_WRITE_BIT) != 0 && Graphics::Recorder::MergeBarriers()) {
|
||||
Graphics::Recorder::CountMerged(CommandClass::Fill);
|
||||
} else {
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
Graphics::Recorder::CountBarriers(CommandClass::Fill);
|
||||
}
|
||||
const auto offset = address - import->base;
|
||||
@@ -1645,7 +1646,7 @@ VulkanDevice::CopyOutcome VulkanDevice::CopyBuffer(std::uint64_t destination, st
|
||||
if ((covered & transferAccess) == transferAccess && Graphics::Recorder::MergeBarriers()) {
|
||||
Graphics::Recorder::CountMerged(CommandClass::Copy);
|
||||
} else {
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, transferAccess);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, transferAccess);
|
||||
Graphics::Recorder::CountBarriers(CommandClass::Copy);
|
||||
}
|
||||
const auto gpuTiming = recorder.BeginGpuTiming(programAddress);
|
||||
@@ -1958,7 +1959,7 @@ bool VulkanDevice::PresentDisplayBuffer(const DisplayBuffer& buffer) {
|
||||
}
|
||||
if (profile && std::chrono::steady_clock::now() - lastReport > std::chrono::seconds(10)) {
|
||||
lastReport = std::chrono::steady_clock::now();
|
||||
std::fprintf(stderr, "[flip] %llu presents from the resident image (%llu refreshed first), through guest memory: %llu not pending, %llu unsuitable; %llu GPU frame dumps\n", static_cast<unsigned long long>(residentPresents), static_cast<unsigned long long>(refreshedPresents), static_cast<unsigned long long>(notPending), static_cast<unsigned long long>(unsuitable), static_cast<unsigned long long>(gpuDumps));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[flip] %llu presents from the resident image (%llu refreshed first), through guest memory: %llu not pending, %llu unsuitable; %llu GPU frame dumps\n", static_cast<unsigned long long>(residentPresents), static_cast<unsigned long long>(refreshedPresents), static_cast<unsigned long long>(notPending), static_cast<unsigned long long>(unsuitable), static_cast<unsigned long long>(gpuDumps));
|
||||
}
|
||||
CaptureTrace::Log("present dump=%d address=%llx width=%u height=%u resident=%d generation=%llu", dumpFrame ? state->nextDumpIndex : -1, static_cast<unsigned long long>(buffer.address), buffer.width, buffer.height, resident != nullptr, static_cast<unsigned long long>(resident ? resident->Generation() : 0));
|
||||
VkClearColorValue uniform{};
|
||||
@@ -2685,7 +2686,7 @@ void reportRecipes() {
|
||||
const auto precheckUs = perHit(counters.precheckNs);
|
||||
const auto proofUs = perHit(counters.proofNs);
|
||||
const auto recordUs = perHit(counters.recordNs);
|
||||
std::fprintf(stderr, "[recipe] %s (10 s): hits %llu; pre-check misses: %s; proofs: %s; rebuilds: %s; presyncs from the recipe %llu (recomputed %llu, waited %llu); data refreshes recorded %llu / skipped by hash %llu (%llu decided by words: data hits); restarts %llu, attaches %llu; us per hit: pre-check %.1f, proof %.1f, record %.1f; verified %llu (object replaced %llu)\n", kind == 0 ? "dispatch" : kind == 1 ? "indirect" : "draw", hits, misses.c_str(), proofs.c_str(), rebuilds.c_str(), take(counters.presyncsFromRecipe), take(counters.presyncsRecomputed), take(counters.presyncWaits), take(counters.dataRefreshed), take(counters.dataSkipped), take(counters.refreshByWords), take(counters.restarts), take(counters.attaches), precheckUs, proofUs, recordUs, take(counters.verified), take(counters.verifyReplaced));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[recipe] %s (10 s): hits %llu; pre-check misses: %s; proofs: %s; rebuilds: %s; presyncs from the recipe %llu (recomputed %llu, waited %llu); data refreshes recorded %llu / skipped by hash %llu (%llu decided by words: data hits); restarts %llu, attaches %llu; us per hit: pre-check %.1f, proof %.1f, record %.1f; verified %llu (object replaced %llu)\n", kind == 0 ? "dispatch" : kind == 1 ? "indirect" : "draw", hits, misses.c_str(), proofs.c_str(), rebuilds.c_str(), take(counters.presyncsFromRecipe), take(counters.presyncsRecomputed), take(counters.presyncWaits), take(counters.dataRefreshed), take(counters.dataSkipped), take(counters.refreshByWords), take(counters.restarts), take(counters.attaches), precheckUs, proofUs, recordUs, take(counters.verified), take(counters.verifyReplaced));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2715,7 +2716,7 @@ struct DispatchTimer {
|
||||
add(which, ms);
|
||||
phaseStart = now;
|
||||
// Slow phases are reported as they finish, so a dispatch that never completes shows where it is.
|
||||
if (ms > 1000) std::fprintf(stderr, "[dispatch] %s took %.0f ms (%zu words, program 0x%llx)\n", DispatchRowName(which), ms, spirvWords, static_cast<unsigned long long>(programAddress));
|
||||
if (ms > 1000) AgcDriver::ProfilePrint_nid_no_patch("[dispatch] %s took %.0f ms (%zu words, program 0x%llx)\n", DispatchRowName(which), ms, spirvWords, static_cast<unsigned long long>(programAddress));
|
||||
}
|
||||
void restart() { phaseStart = std::chrono::steady_clock::now(); }
|
||||
// The call's phases as text, only when wanted: a slow call, or a new [indirect] maximum.
|
||||
@@ -2738,7 +2739,7 @@ struct DispatchTimer {
|
||||
for (std::size_t row = 0; row < DispatchPhaseCount; ++row) {
|
||||
if (d.phaseTotals[row] != 0) report += " " + std::string(DispatchRowName(row)) + "=" + std::to_string(static_cast<long long>(d.phaseTotals[row] / 1000)) + "s";
|
||||
}
|
||||
std::fprintf(stderr, "[dispatch] %llu dispatches, phase totals:%s\n", static_cast<unsigned long long>(d.profiledDispatches), report.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[dispatch] %llu dispatches, phase totals:%s\n", static_cast<unsigned long long>(d.profiledDispatches), report.c_str());
|
||||
}
|
||||
// The call's end: the proc lookups it made, the slow-call report, the [indirect] hold
|
||||
// accounting (`indirectHold`: the call was an indirect dispatch, CPU-resolved or not) and line.
|
||||
@@ -2748,7 +2749,7 @@ struct DispatchTimer {
|
||||
d.procLookups += Graphics::DeviceProcLookups() - lookupsBefore;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const auto totalMs = std::chrono::duration<double, std::milli>(now - start).count();
|
||||
if (totalMs > 100) std::fprintf(stderr, "[dispatch] %s %zu words:%s\n", groupsText, spirvWords, formatCall().c_str());
|
||||
if (totalMs > 100) AgcDriver::ProfilePrint_nid_no_patch("[dispatch] %s %zu words:%s\n", groupsText, spirvWords, formatCall().c_str());
|
||||
if (!indirectHold) return;
|
||||
auto& hold = d.indirectHold;
|
||||
++hold.count;
|
||||
@@ -2767,7 +2768,7 @@ struct DispatchTimer {
|
||||
else std::snprintf(text, sizeof(text), " %s %.0f ms", DispatchRowName(i), hold.phaseMs[i]);
|
||||
report += text;
|
||||
}
|
||||
std::fprintf(stderr, "[indirect] %llu indirect dispatches spent %.0f ms inside the device call (10 s; max %.1f ms:%s), by phase (the 'resources: ...' rows split 'resources'; 'hook waits' overlaps them; 'images: ...' rows are the lookups by outcome, count x ms, inside 'B images'):%s; copied-writer lists scanned per decision: dispatch avg %.1f (max %zu), draw avg %.1f\n", static_cast<unsigned long long>(hold.count), hold.totalMs, hold.maxMs, hold.maxPhases.c_str(), report.c_str(), hold.count != 0 ? static_cast<double>(hold.writersScanned) / hold.count : 0.0, hold.maxWriters, hold.count != 0 ? static_cast<double>(hold.drawWritersScanned) / hold.count : 0.0);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[indirect] %llu indirect dispatches spent %.0f ms inside the device call (10 s; max %.1f ms:%s), by phase (the 'resources: ...' rows split 'resources'; 'hook waits' overlaps them; 'images: ...' rows are the lookups by outcome, count x ms, inside 'B images'):%s; copied-writer lists scanned per decision: dispatch avg %.1f (max %zu), draw avg %.1f\n", static_cast<unsigned long long>(hold.count), hold.totalMs, hold.maxMs, hold.maxPhases.c_str(), report.c_str(), hold.count != 0 ? static_cast<double>(hold.writersScanned) / hold.count : 0.0, hold.maxWriters, hold.count != 0 ? static_cast<double>(hold.drawWritersScanned) / hold.count : 0.0);
|
||||
hold.phaseMs = {};
|
||||
hold.phaseCounts = {};
|
||||
hold.count = 0;
|
||||
@@ -2902,7 +2903,7 @@ std::uint64_t VulkanDevice::presync(std::span<const std::pair<std::uint64_t, std
|
||||
if (profile) {
|
||||
const auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
auto last = counters.lastReport.load();
|
||||
if (nowMs - last >= 10000 && counters.lastReport.compare_exchange_strong(last, nowMs)) std::fprintf(stderr, "[presync] %llu dispatches checked, %llu pre-syncs waited %.0f ms (cumulative)\n", static_cast<unsigned long long>(counters.checked.load()), static_cast<unsigned long long>(counters.presyncs.load()), counters.waitedUs.load() / 1000.0);
|
||||
if (nowMs - last >= 10000 && counters.lastReport.compare_exchange_strong(last, nowMs)) AgcDriver::ProfilePrint_nid_no_patch("[presync] %llu dispatches checked, %llu pre-syncs waited %.0f ms (cumulative)\n", static_cast<unsigned long long>(counters.checked.load()), static_cast<unsigned long long>(counters.presyncs.load()), counters.waitedUs.load() / 1000.0);
|
||||
}
|
||||
return serial;
|
||||
}
|
||||
@@ -3147,7 +3148,7 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
|
||||
// The group counts were stored by earlier recorded work (a dispatch in place, a fill) or the
|
||||
// host; the indirect read follows all of it.
|
||||
const auto timing = recorder.BeginGpuTiming(CommandClass::IndirectArguments);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
|
||||
Graphics::Recorder::CountBarriers(CommandClass::IndirectArguments);
|
||||
recorder.EndGpuTiming(timing, 12);
|
||||
recorder.NotePendingRead(arguments, 12, Graphics::Recorder::ReadKind::Indirect);
|
||||
@@ -3159,7 +3160,7 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
|
||||
Graphics::Recorder::CountMerged(CommandClass::DispatchLeading);
|
||||
} else {
|
||||
const auto timing = recorder.BeginGpuTiming(CommandClass::DispatchLeading);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
|
||||
Graphics::Recorder::CountBarriers(CommandClass::DispatchLeading);
|
||||
recorder.EndGpuTiming(timing);
|
||||
++d.preBarriersRecorded;
|
||||
@@ -3175,7 +3176,7 @@ void VulkanDevice::recordDispatch(RecordedDispatch& record) {
|
||||
recorder.EndGpuTiming(gpuTiming);
|
||||
const auto trailingTiming = recorder.BeginGpuTiming(CommandClass::DispatchTrailing);
|
||||
constexpr VkAccessFlags dispatchedAccess = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_READ_BIT;
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_SHADER_WRITE_BIT, dispatchedAccess);
|
||||
Graphics::RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_SHADER_WRITE_BIT, dispatchedAccess);
|
||||
Graphics::Recorder::CountBarriers(CommandClass::DispatchTrailing);
|
||||
recorder.EndGpuTiming(trailingTiming);
|
||||
recorder.MarkCovered(dispatchedAccess);
|
||||
@@ -3361,8 +3362,8 @@ VulkanDevice::IndirectOutcome VulkanDevice::dispatch(const ShaderRecompiler::Rec
|
||||
}
|
||||
if (profile && std::chrono::steady_clock::now() - d.cacheReport > std::chrono::seconds(10)) {
|
||||
d.cacheReport = std::chrono::steady_clock::now();
|
||||
std::fprintf(stderr, "[rescache] %llu hits, %llu misses, %llu invalidated, %zu entries (dispatch + draw); template hits: %llu refreshed the data buffers (revalidate %.1f ms), %llu had the same words; Find calls %llu, Touch calls %llu\n", static_cast<unsigned long long>(d.cacheHits), static_cast<unsigned long long>(d.cacheMisses), static_cast<unsigned long long>(d.cacheInvalidated), state->resourceCache.Size(), static_cast<unsigned long long>(d.templateRefreshed), d.templateRevalidateMs, static_cast<unsigned long long>(d.templateSameWords), static_cast<unsigned long long>(ResourceCache::Finds()), static_cast<unsigned long long>(ResourceCache::Touches()));
|
||||
std::fprintf(stderr, "[vk] deviceProc lookups inside the device call: %llu (%.2f per dispatch); pre-dispatch barriers recorded %llu, skipped %llu\n", static_cast<unsigned long long>(d.procLookups), d.profiledDispatches != 0 ? static_cast<double>(d.procLookups) / static_cast<double>(d.profiledDispatches) : 0.0, static_cast<unsigned long long>(d.preBarriersRecorded), static_cast<unsigned long long>(d.preBarriersSkipped));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[rescache] %llu hits, %llu misses, %llu invalidated, %zu entries (dispatch + draw); template hits: %llu refreshed the data buffers (revalidate %.1f ms), %llu had the same words; Find calls %llu, Touch calls %llu\n", static_cast<unsigned long long>(d.cacheHits), static_cast<unsigned long long>(d.cacheMisses), static_cast<unsigned long long>(d.cacheInvalidated), state->resourceCache.Size(), static_cast<unsigned long long>(d.templateRefreshed), d.templateRevalidateMs, static_cast<unsigned long long>(d.templateSameWords), static_cast<unsigned long long>(ResourceCache::Finds()), static_cast<unsigned long long>(ResourceCache::Touches()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[vk] deviceProc lookups inside the device call: %llu (%.2f per dispatch); pre-dispatch barriers recorded %llu, skipped %llu\n", static_cast<unsigned long long>(d.procLookups), d.profiledDispatches != 0 ? static_cast<double>(d.procLookups) / static_cast<double>(d.profiledDispatches) : 0.0, static_cast<unsigned long long>(d.preBarriersRecorded), static_cast<unsigned long long>(d.preBarriersSkipped));
|
||||
reportRecipes();
|
||||
}
|
||||
timing.Mark("shader_resources");
|
||||
@@ -3449,9 +3450,9 @@ VulkanDevice::IndirectOutcome VulkanDevice::dispatch(const ShaderRecompiler::Rec
|
||||
lastReport = now;
|
||||
std::vector<std::pair<std::uint64_t, Waits>> hot(byProgram.begin(), byProgram.end());
|
||||
std::sort(hot.begin(), hot.end(), [](const auto& a, const auto& b) { return a.second.ms > b.second.ms; });
|
||||
std::fprintf(stderr, "[address-sync] %llu address-based dispatch syncs waited %.1f s in total; by program (10 s):", static_cast<unsigned long long>(syncs), waitedMs / 1000);
|
||||
for (std::size_t i = 0; i < hot.size() && i < 8; ++i) std::fprintf(stderr, " 0x%llx x%llu %.0fms", static_cast<unsigned long long>(hot[i].first), static_cast<unsigned long long>(hot[i].second.count), hot[i].second.ms);
|
||||
std::fprintf(stderr, "\n");
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[address-sync] %llu address-based dispatch syncs waited %.1f s in total; by program (10 s):", static_cast<unsigned long long>(syncs), waitedMs / 1000);
|
||||
for (std::size_t i = 0; i < hot.size() && i < 8; ++i) AgcDriver::ProfilePrint_nid_no_patch(" 0x%llx x%llu %.0fms", static_cast<unsigned long long>(hot[i].first), static_cast<unsigned long long>(hot[i].second.count), hot[i].second.ms);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("\n");
|
||||
byProgram.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/BufferPool.hpp"
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
@@ -68,7 +69,7 @@ std::optional<BufferAllocation> BufferPool::Take(std::size_t bytes, VkBufferUsag
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now - lastReport > std::chrono::seconds(10)) {
|
||||
lastReport = now;
|
||||
std::fprintf(stderr, "[bufferpool] small: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB); large: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB)%s; device: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB of %llu)\n", static_cast<unsigned long long>(smallTier.hits), static_cast<unsigned long long>(smallTier.misses), static_cast<unsigned long long>(smallTier.evictions), smallTier.slots, smallTier.retainedBytes / 1048576.0, static_cast<unsigned long long>(largeTier.hits), static_cast<unsigned long long>(largeTier.misses), static_cast<unsigned long long>(largeTier.evictions), largeTier.slots, largeTier.retainedBytes / 1048576.0, sharedTiers() ? " (shared)" : "", static_cast<unsigned long long>(deviceTier.hits), static_cast<unsigned long long>(deviceTier.misses), static_cast<unsigned long long>(deviceTier.evictions), deviceTier.slots, deviceTier.retainedBytes / 1048576.0, static_cast<unsigned long long>(deviceTier.budget >> 20u));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[bufferpool] small: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB); large: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB)%s; device: %llu hits, %llu misses, %llu evictions, %zu retained (%.0f MiB of %llu)\n", static_cast<unsigned long long>(smallTier.hits), static_cast<unsigned long long>(smallTier.misses), static_cast<unsigned long long>(smallTier.evictions), smallTier.slots, smallTier.retainedBytes / 1048576.0, static_cast<unsigned long long>(largeTier.hits), static_cast<unsigned long long>(largeTier.misses), static_cast<unsigned long long>(largeTier.evictions), largeTier.slots, largeTier.retainedBytes / 1048576.0, sharedTiers() ? " (shared)" : "", static_cast<unsigned long long>(deviceTier.hits), static_cast<unsigned long long>(deviceTier.misses), static_cast<unsigned long long>(deviceTier.evictions), deviceTier.slots, deviceTier.retainedBytes / 1048576.0, static_cast<unsigned long long>(deviceTier.budget >> 20u));
|
||||
}
|
||||
}
|
||||
auto& tier = tierFor(capacity, properties);
|
||||
|
||||
@@ -1045,7 +1045,7 @@ void recordDrawCommands(const Context& context, VkCommandBuffer commands, const
|
||||
bool recordIndirectArguments(const Context& context, VkCommandBuffer commands, Recorder* recorder, bool recorded, const IndirectRecord& indirect, std::unique_ptr<DeviceBuffer>& scratch, VkBuffer& argumentBuffer, VkDeviceSize& argumentOffset, const std::function<void(std::uint32_t)>& countBarrier) {
|
||||
using Rule = Pm4::DrawParameters::IndirectDraw::Rule;
|
||||
const auto* args = indirect.args;
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT);
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT);
|
||||
countBarrier(1);
|
||||
if (recorded) {
|
||||
// Read in place from the import when the batch runs (a synchronous draw waits for its own).
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp"
|
||||
#include "ThreadOwned.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/BdaResources.hpp"
|
||||
@@ -818,7 +819,7 @@ void reportMirrors() {
|
||||
}
|
||||
heapBytes = state.heapBytes;
|
||||
}
|
||||
std::fprintf(stderr, "[buffers] image mirrors: %zu ranges (%.1f MiB, %zu writable, %zu heap %.1f MiB), %llu address-based builds served, %llu descriptor sub-ranges bound, %llu rebuilds, %llu refreshes: %llu blocks compared, %llu copied, %llu refresh syncs; heap refills %llu, unwatched heaps %llu\n", count, bytes / 1048576.0, writable, heaps, heapBytes / 1048576.0, static_cast<unsigned long long>(state.builds), static_cast<unsigned long long>(state.subranges), static_cast<unsigned long long>(state.rebuilds), static_cast<unsigned long long>(state.refreshes), static_cast<unsigned long long>(state.blocksCompared), static_cast<unsigned long long>(state.blocksCopied), static_cast<unsigned long long>(state.syncs), static_cast<unsigned long long>(state.heapRefills), static_cast<unsigned long long>(state.heapUnwatched));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[buffers] image mirrors: %zu ranges (%.1f MiB, %zu writable, %zu heap %.1f MiB), %llu address-based builds served, %llu descriptor sub-ranges bound, %llu rebuilds, %llu refreshes: %llu blocks compared, %llu copied, %llu refresh syncs; heap refills %llu, unwatched heaps %llu\n", count, bytes / 1048576.0, writable, heaps, heapBytes / 1048576.0, static_cast<unsigned long long>(state.builds), static_cast<unsigned long long>(state.subranges), static_cast<unsigned long long>(state.rebuilds), static_cast<unsigned long long>(state.refreshes), static_cast<unsigned long long>(state.blocksCompared), static_cast<unsigned long long>(state.blocksCopied), static_cast<unsigned long long>(state.syncs), static_cast<unsigned long long>(state.heapRefills), static_cast<unsigned long long>(state.heapUnwatched));
|
||||
}
|
||||
|
||||
// Deferred lease release. The lease an address-based build takes (AcquireRegistered) is dropped by its
|
||||
@@ -962,7 +963,7 @@ void CountLeaseOutcome(bool synced, std::uint64_t batchSerial) {
|
||||
const auto& stats = state.stats;
|
||||
const auto table = BdaResources::TableCacheCounters();
|
||||
const auto& snapshots = Snapshots();
|
||||
std::fprintf(stderr, "[address-sync] leases: %llu released at completion, %llu synced at once; %llu pin-contention waits by guest threads (%llu finished the lease batch, %llu drained the recorder, %llu cache-only drops) %.1f s; BDA table cache %llu hits / %llu misses (%zu tables held); snapshot compares: %llu skipped (live-backed region), %llu made\n", static_cast<unsigned long long>(stats.deferred), static_cast<unsigned long long>(stats.synced), static_cast<unsigned long long>(stats.contentionWaits), static_cast<unsigned long long>(stats.contentionSyncs), static_cast<unsigned long long>(stats.contentionDrains), static_cast<unsigned long long>(stats.cacheDrops), stats.contentionMs / 1000, static_cast<unsigned long long>(table.hits), static_cast<unsigned long long>(table.misses), table.held, static_cast<unsigned long long>(snapshots.skipped.load(std::memory_order_relaxed)), static_cast<unsigned long long>(snapshots.checked.load(std::memory_order_relaxed)));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[address-sync] leases: %llu released at completion, %llu synced at once; %llu pin-contention waits by guest threads (%llu finished the lease batch, %llu drained the recorder, %llu cache-only drops) %.1f s; BDA table cache %llu hits / %llu misses (%zu tables held); snapshot compares: %llu skipped (live-backed region), %llu made\n", static_cast<unsigned long long>(stats.deferred), static_cast<unsigned long long>(stats.synced), static_cast<unsigned long long>(stats.contentionWaits), static_cast<unsigned long long>(stats.contentionSyncs), static_cast<unsigned long long>(stats.contentionDrains), static_cast<unsigned long long>(stats.cacheDrops), stats.contentionMs / 1000, static_cast<unsigned long long>(table.hits), static_cast<unsigned long long>(table.misses), table.held, static_cast<unsigned long long>(snapshots.skipped.load(std::memory_order_relaxed)), static_cast<unsigned long long>(snapshots.checked.load(std::memory_order_relaxed)));
|
||||
}
|
||||
|
||||
LeaseStats LeaseCounters() {
|
||||
@@ -1166,7 +1167,7 @@ void GuestBufferMemory::CountAddressBuild(double snapshotsUs) {
|
||||
const auto delta = [](std::uint64_t now, std::uint64_t before) { return static_cast<unsigned long long>(now - before); };
|
||||
const auto space = AddressSpaceCounters();
|
||||
const auto& spaceSeen = totals.spaceSeen;
|
||||
std::fprintf(stderr, "[address] %llu address-based builds (10 s), us per build: lease %.0f, imports pass %.0f, mirror prepare %.0f, compare %.0f (%.0f blocks, %.1f copied), snapshots %.0f; space hits %llu / rebuilds: generation %llu, epoch %llu, device %llu, waiter drop %llu, first %llu; unpublished %llu, dissolved: overlap %llu, imports %llu%s; [bda-table] hits %llu / misses %llu (space tables %llu), first entry: expired %llu, hash differs low %llu / heap %llu, same hash %llu, none held %llu\n", static_cast<unsigned long long>(totals.builds), per(totals.sums.leaseUs), per(totals.sums.importsUs), per(totals.sums.mirrorsUs), per(totals.sums.compareUs), per(static_cast<double>(totals.sums.blocksCompared)), per(static_cast<double>(totals.sums.blocksCopied)), per(totals.snapshotsUs), delta(space.hits, spaceSeen.hits), delta(space.rebuiltGeneration, spaceSeen.rebuiltGeneration), delta(space.rebuiltEpoch, spaceSeen.rebuiltEpoch), delta(space.rebuiltDevice, spaceSeen.rebuiltDevice), delta(space.rebuiltWaiterDrop, spaceSeen.rebuiltWaiterDrop), delta(space.rebuiltFirst, spaceSeen.rebuiltFirst), delta(space.unpublished, spaceSeen.unpublished), delta(space.dissolvedOverlap, spaceSeen.dissolvedOverlap), delta(space.dissolvedImports, spaceSeen.dissolvedImports), space.enabled ? "" : " (cache off)", delta(table.hits, seen.hits), delta(table.misses, seen.misses), delta(table.spaceTables, seen.spaceTables), delta(table.firstExpired, seen.firstExpired), delta(table.firstDiffersLow, seen.firstDiffersLow), delta(table.firstDiffersHeap, seen.firstDiffersHeap), delta(table.firstSameHash, seen.firstSameHash), delta(table.firstEmpty, seen.firstEmpty));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[address] %llu address-based builds (10 s), us per build: lease %.0f, imports pass %.0f, mirror prepare %.0f, compare %.0f (%.0f blocks, %.1f copied), snapshots %.0f; space hits %llu / rebuilds: generation %llu, epoch %llu, device %llu, waiter drop %llu, first %llu; unpublished %llu, dissolved: overlap %llu, imports %llu%s; [bda-table] hits %llu / misses %llu (space tables %llu), first entry: expired %llu, hash differs low %llu / heap %llu, same hash %llu, none held %llu\n", static_cast<unsigned long long>(totals.builds), per(totals.sums.leaseUs), per(totals.sums.importsUs), per(totals.sums.mirrorsUs), per(totals.sums.compareUs), per(static_cast<double>(totals.sums.blocksCompared)), per(static_cast<double>(totals.sums.blocksCopied)), per(totals.snapshotsUs), delta(space.hits, spaceSeen.hits), delta(space.rebuiltGeneration, spaceSeen.rebuiltGeneration), delta(space.rebuiltEpoch, spaceSeen.rebuiltEpoch), delta(space.rebuiltDevice, spaceSeen.rebuiltDevice), delta(space.rebuiltWaiterDrop, spaceSeen.rebuiltWaiterDrop), delta(space.rebuiltFirst, spaceSeen.rebuiltFirst), delta(space.unpublished, spaceSeen.unpublished), delta(space.dissolvedOverlap, spaceSeen.dissolvedOverlap), delta(space.dissolvedImports, spaceSeen.dissolvedImports), space.enabled ? "" : " (cache off)", delta(table.hits, seen.hits), delta(table.misses, seen.misses), delta(table.spaceTables, seen.spaceTables), delta(table.firstExpired, seen.firstExpired), delta(table.firstDiffersLow, seen.firstDiffersLow), delta(table.firstDiffersHeap, seen.firstDiffersHeap), delta(table.firstSameHash, seen.firstSameHash), delta(table.firstEmpty, seen.firstEmpty));
|
||||
totals.tableSeen = table;
|
||||
totals.spaceSeen = space;
|
||||
totals.builds = 0;
|
||||
@@ -1691,7 +1692,7 @@ void reportStaging() {
|
||||
const auto staged = stats.staged.load();
|
||||
const auto in = stats.stagedInBytes.load();
|
||||
const auto out = stats.stagedOutBytes.load();
|
||||
std::fprintf(stderr, "[buffers] staging: %llu regions staged device-local (%llu with atomics, %llu of reused builds), %.0f KiB copied in, %.0f KiB copied back, %llu without copy-back, %llu shadows refused; last 10 s: %llu regions, %.0f KiB in, %.0f KiB back\n", static_cast<unsigned long long>(staged), static_cast<unsigned long long>(stats.stagedAtomic.load()), static_cast<unsigned long long>(stats.stagedReused.load()), in / 1024.0, out / 1024.0, static_cast<unsigned long long>(stats.stagedLost.load()), static_cast<unsigned long long>(stats.stagingRefused.load()), static_cast<unsigned long long>(staged - lastStaged), (in - lastIn) / 1024.0, (out - lastOut) / 1024.0);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[buffers] staging: %llu regions staged device-local (%llu with atomics, %llu of reused builds), %.0f KiB copied in, %.0f KiB copied back, %llu without copy-back, %llu shadows refused; last 10 s: %llu regions, %.0f KiB in, %.0f KiB back\n", static_cast<unsigned long long>(staged), static_cast<unsigned long long>(stats.stagedAtomic.load()), static_cast<unsigned long long>(stats.stagedReused.load()), in / 1024.0, out / 1024.0, static_cast<unsigned long long>(stats.stagedLost.load()), static_cast<unsigned long long>(stats.stagingRefused.load()), static_cast<unsigned long long>(staged - lastStaged), (in - lastIn) / 1024.0, (out - lastOut) / 1024.0);
|
||||
lastStaged = staged;
|
||||
lastIn = in;
|
||||
lastOut = out;
|
||||
@@ -2028,7 +2029,7 @@ void GuestBufferMemory::UploadFinish(bool addressable) {
|
||||
const auto uploads = uploadsProfiled.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
if (uploads % 2000 == 0) {
|
||||
const auto& copies = Copies();
|
||||
std::fprintf(stderr, "[buffers] %llu uploads: import lookup %.0f ms, buffer allocation %.0f ms, guest read %.0f ms; copies on the GPU: %llu regions (%.0f KiB) copied out of imports, %llu written sub-ranges (%.0f KiB) copied back, %llu staging stores by the CPU at write-back\n", static_cast<unsigned long long>(uploads), importUs.load(std::memory_order_relaxed) / 1000.0, allocateUs.load(std::memory_order_relaxed) / 1000.0, readUs.load(std::memory_order_relaxed) / 1000.0, static_cast<unsigned long long>(copies.gpuCopies.load(std::memory_order_relaxed)), copies.gpuCopyBytes.load(std::memory_order_relaxed) / 1024.0, static_cast<unsigned long long>(copies.gpuCopyBacks.load(std::memory_order_relaxed)), copies.gpuCopyBackBytes.load(std::memory_order_relaxed) / 1024.0, static_cast<unsigned long long>(copies.stagingStores.load(std::memory_order_relaxed)));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[buffers] %llu uploads: import lookup %.0f ms, buffer allocation %.0f ms, guest read %.0f ms; copies on the GPU: %llu regions (%.0f KiB) copied out of imports, %llu written sub-ranges (%.0f KiB) copied back, %llu staging stores by the CPU at write-back\n", static_cast<unsigned long long>(uploads), importUs.load(std::memory_order_relaxed) / 1000.0, allocateUs.load(std::memory_order_relaxed) / 1000.0, readUs.load(std::memory_order_relaxed) / 1000.0, static_cast<unsigned long long>(copies.gpuCopies.load(std::memory_order_relaxed)), copies.gpuCopyBytes.load(std::memory_order_relaxed) / 1024.0, static_cast<unsigned long long>(copies.gpuCopyBacks.load(std::memory_order_relaxed)), copies.gpuCopyBackBytes.load(std::memory_order_relaxed) / 1024.0, static_cast<unsigned long long>(copies.stagingStores.load(std::memory_order_relaxed)));
|
||||
}
|
||||
const auto ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - started).count();
|
||||
if (ms > 50) {
|
||||
@@ -2040,7 +2041,7 @@ void GuestBufferMemory::UploadFinish(bool addressable) {
|
||||
largest = std::max<std::uint64_t>(largest, region.end - region.begin);
|
||||
if (region.buffer != nullptr) copied += region.end - region.begin;
|
||||
}
|
||||
std::fprintf(stderr, "[resources] guest upload of %zu regions, %.1f MiB (largest %.1f MiB, copied %.1f MiB, addressable %d) took %.0f ms to finish\n", regions.size(), total / 1048576.0, largest / 1048576.0, copied / 1048576.0, addressable ? 1 : 0, ms);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[resources] guest upload of %zu regions, %.1f MiB (largest %.1f MiB, copied %.1f MiB, addressable %d) took %.0f ms to finish\n", regions.size(), total / 1048576.0, largest / 1048576.0, copied / 1048576.0, addressable ? 1 : 0, ms);
|
||||
}
|
||||
// Debug aid: APS5_TRACE_BIGBUF lists every copied region of at least 1 MiB.
|
||||
static const bool traceBig = std::getenv("APS5_TRACE_BIGBUF") != nullptr;
|
||||
@@ -2080,9 +2081,9 @@ void GuestBufferMemory::copyRegion(Region& region, bool addressable) {
|
||||
if (++uploads % 1000 == 0) {
|
||||
// 'misaligned in imports' are the ones the GPU did not copy: over APS5_GPU_COPY_MAX_KIB,
|
||||
// sparse, APS5_CPU_COPIES, no recorder, or an import gone by UploadFinish.
|
||||
std::fprintf(stderr, "[buffers] %llu copied regions on the CPU: %llu snapshots (%.0f MiB), %llu misaligned in imports (%.0f MiB), %llu outside imports (%.0f MiB):", static_cast<unsigned long long>(uploads), static_cast<unsigned long long>(snapshotOnly), snapshotBytes / 1048576.0, static_cast<unsigned long long>(misaligned), misalignedBytes / 1048576.0, static_cast<unsigned long long>(noImport), noImportBytes / 1048576.0);
|
||||
for (const auto& [granule, counts] : outside) std::fprintf(stderr, " 0x%llx0000000:%llu/%.0fMiB", static_cast<unsigned long long>(granule), static_cast<unsigned long long>(counts.first), counts.second / 1048576.0);
|
||||
std::fprintf(stderr, "\n");
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[buffers] %llu copied regions on the CPU: %llu snapshots (%.0f MiB), %llu misaligned in imports (%.0f MiB), %llu outside imports (%.0f MiB):", static_cast<unsigned long long>(uploads), static_cast<unsigned long long>(snapshotOnly), snapshotBytes / 1048576.0, static_cast<unsigned long long>(misaligned), misalignedBytes / 1048576.0, static_cast<unsigned long long>(noImport), noImportBytes / 1048576.0);
|
||||
for (const auto& [granule, counts] : outside) AgcDriver::ProfilePrint_nid_no_patch(" 0x%llx0000000:%llu/%.0fMiB", static_cast<unsigned long long>(granule), static_cast<unsigned long long>(counts.first), counts.second / 1048576.0);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("\n");
|
||||
}
|
||||
}
|
||||
const auto allocateStart = std::chrono::steady_clock::now();
|
||||
@@ -2131,7 +2132,7 @@ void GuestBufferMemory::recordGpuCopies(std::span<Region* const> copies, bool ad
|
||||
for (const auto* region : copies) reads.emplace_back(region->begin, region->end);
|
||||
recorder->NoteAccess(Recorder::CommandClass::StagingIn, Recorder::Access{reads, {}, {}, VK_PIPELINE_STAGE_TRANSFER_BIT});
|
||||
}
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
Recorder::CountBarriers(Recorder::CommandClass::StagingIn);
|
||||
bool stagedAny = false;
|
||||
std::uint64_t copiedBytes = 0;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Pipeline.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/VertexInput.hpp"
|
||||
#include <algorithm>
|
||||
@@ -499,7 +500,7 @@ void reportPipelines(PipelineStore& store) {
|
||||
if (now - store.lastReport < std::chrono::seconds(10)) return;
|
||||
store.lastReport = now;
|
||||
const auto lookups = store.hits + store.misses + store.uncached;
|
||||
std::fprintf(stderr, "[pipecache] %llu lookups over 10 s: %llu hits (%.0f%%), %llu misses, %llu private (no variant id), %llu evicted, %zu cached\n", static_cast<unsigned long long>(lookups), static_cast<unsigned long long>(store.hits), lookups != 0 ? 100.0 * static_cast<double>(store.hits) / static_cast<double>(lookups) : 0.0, static_cast<unsigned long long>(store.misses), static_cast<unsigned long long>(store.uncached), static_cast<unsigned long long>(store.evicted), store.entries.size());
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[pipecache] %llu lookups over 10 s: %llu hits (%.0f%%), %llu misses, %llu private (no variant id), %llu evicted, %zu cached\n", static_cast<unsigned long long>(lookups), static_cast<unsigned long long>(store.hits), lookups != 0 ? 100.0 * static_cast<double>(store.hits) / static_cast<double>(lookups) : 0.0, static_cast<unsigned long long>(store.misses), static_cast<unsigned long long>(store.uncached), static_cast<unsigned long long>(store.evicted), store.entries.size());
|
||||
store.hits = store.misses = store.uncached = store.evicted = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/CaptureTrace.hpp"
|
||||
#include "prx/libc/include/HostThreadLocal.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp"
|
||||
@@ -779,7 +780,7 @@ void ReportHookSyncs(HookSyncStats& stats) {
|
||||
std::snprintf(text, sizeof(text), " [0x%x %s %s +0x%llx/+0x%llx/+0x%llx/+0x%llx/+0x%llx/+0x%llx: %llu/%.0fms u%llu/%llu/%llu c%llu s%llu %.0fK/%.0fK]", key.queue, PacketName(key.opcode).c_str(), GuestMemory::ReadSiteName(key.site), key.frames[0], key.frames[1], key.frames[2], key.frames[3], key.frames[4], key.frames[5], count(totals.count), totals.waitedMs, count(k.unchangedOpen), count(k.unchangedPending), count(k.unchangedSignaled), count(k.changed), count(k.stores), totals.rangeBytes / 1024.0 / totals.count, totals.accessBytes / 1024.0 / totals.count);
|
||||
report += text;
|
||||
}
|
||||
std::fprintf(stderr, "%s\n", report.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("%s\n", report.c_str());
|
||||
stats = HookSyncStats{};
|
||||
}
|
||||
|
||||
@@ -900,7 +901,7 @@ void ReportRecordedStoreSyncs(RecordedStoreStats& stats) {
|
||||
std::snprintf(text, sizeof(text), " [0x%x %s %s +0x%llx/+0x%llx/+0x%llx: %llu/%.0fms k%llu y%llu/n%llu c%llu/u%llu d%llu/l%llu]", key.queue, PacketName(key.opcode).c_str(), GuestMemory::ReadSiteName(key.site), key.frames[0], key.frames[1], key.frames[2], count(k.count), k.waitedMs, count(k.skipped), count(k.cpuWrittenYes), count(k.cpuWrittenNo), count(k.changed), count(k.unchanged), count(k.imagesDead), count(k.imagesLive));
|
||||
report += text;
|
||||
}
|
||||
std::fprintf(stderr, "%s\n", report.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("%s\n", report.c_str());
|
||||
stats.byKey.clear();
|
||||
stats.totals = {};
|
||||
}
|
||||
@@ -1433,7 +1434,7 @@ void Recorder::recordKeyStores(bool forWriter) {
|
||||
const auto timing = beginTiming(ClassKey(CommandClass::DccKeyStore));
|
||||
// Ordered behind every earlier recorded read or write of the ranges (the title's DCC clear or
|
||||
// decompress kernel storing keys through a V#), and visible to the work after and to the host.
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT);
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT);
|
||||
const auto fill = context.Resolved(&DeviceFunctions::cmdFillBuffer, "vkCmdFillBuffer");
|
||||
const auto copy = context.Resolved(&DeviceFunctions::cmdCopyBuffer, "vkCmdCopyBuffer");
|
||||
std::uint64_t bytes = 0;
|
||||
@@ -1718,7 +1719,7 @@ void reportBarriers() {
|
||||
std::snprintf(text, sizeof(text), " %s %llu", CommandClassNames[i], static_cast<unsigned long long>(mergedCount));
|
||||
mergedLine += text;
|
||||
}
|
||||
std::fprintf(stderr, "[barriers] %llu recorded (10 s) by class:%s; merged %llu:%s", static_cast<unsigned long long>(total), line.c_str(), static_cast<unsigned long long>(merged), mergedLine.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[barriers] %llu recorded (10 s) by class:%s; merged %llu:%s", static_cast<unsigned long long>(total), line.c_str(), static_cast<unsigned long long>(merged), mergedLine.c_str());
|
||||
if (Recorder::BarrierValidate()) {
|
||||
std::uint64_t emitted = 0, skipped = 0;
|
||||
std::string classes, kinds;
|
||||
@@ -1737,9 +1738,9 @@ void reportBarriers() {
|
||||
std::snprintf(text, sizeof(text), " %s %llu", HazardNames[i], static_cast<unsigned long long>(validateKinds[i].exchange(0, std::memory_order_relaxed)));
|
||||
kinds += text;
|
||||
}
|
||||
std::fprintf(stderr, "; validate: would emit %llu (%s) + %llu batch ends, would skip %llu; emitted/skipped by class:%s", static_cast<unsigned long long>(emitted), kinds.c_str() + 1, static_cast<unsigned long long>(validateBatchEnds.exchange(0, std::memory_order_relaxed)), static_cast<unsigned long long>(skipped), classes.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("; validate: would emit %llu (%s) + %llu batch ends, would skip %llu; emitted/skipped by class:%s", static_cast<unsigned long long>(emitted), kinds.c_str() + 1, static_cast<unsigned long long>(validateBatchEnds.exchange(0, std::memory_order_relaxed)), static_cast<unsigned long long>(skipped), classes.c_str());
|
||||
}
|
||||
std::fputc('\n', stderr);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1970,7 +1971,7 @@ void Recorder::foldSamples(Batch& batch, VkDeviceAddress target) {
|
||||
}
|
||||
done += count;
|
||||
const bool last = done == pendingSamples.size();
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
|
||||
bind(commands, VK_PIPELINE_BIND_POINT_COMPUTE, samplePipeline);
|
||||
struct {
|
||||
VkDeviceAddress counter;
|
||||
@@ -2031,7 +2032,7 @@ bool Recorder::RecordMeshArguments(VkCommandBuffer commands, VkDeviceAddress rec
|
||||
}
|
||||
}
|
||||
if (meshArgumentState < 0) return false;
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
recordBarrier(commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
function(cmdBindPipeline, "vkCmdBindPipeline")(commands, VK_PIPELINE_BIND_POINT_COMPUTE, meshArgumentPipeline);
|
||||
struct {
|
||||
VkDeviceAddress record;
|
||||
@@ -2147,9 +2148,9 @@ void Recorder::readGpuTiming(Batch& batch) {
|
||||
}
|
||||
std::sort(hot.begin(), hot.end(), [](const auto& a, const auto& b) { return a.second.ms > b.second.ms; });
|
||||
// The first field stays the program sum: the measure scripts match on it.
|
||||
std::fprintf(stderr, "[gputime] %.0f ms of GPU time in %llu batches over 10 s (batch %.0f ms first to last command; classes %.0f ms, all ranges %.0f ms, untimed %.0f ms outside every range; %llu presents; %llu ranges dropped at the %u cap); by program:", timingProgramMs, static_cast<unsigned long long>(timingBatches), timingBatchMs, timingClassMs, timingUnionMs, timingBatchMs - timingUnionMs, static_cast<unsigned long long>(presents), static_cast<unsigned long long>(timingDropped.exchange(0, std::memory_order_relaxed)), MaxTimedRanges);
|
||||
for (std::size_t i = 0; i < hot.size() && i < 12; ++i) std::fprintf(stderr, " 0x%llx x%llu %.0fms", static_cast<unsigned long long>(hot[i].first), static_cast<unsigned long long>(hot[i].second.count), hot[i].second.ms);
|
||||
std::fprintf(stderr, "; by class:%s\n", classes.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[gputime] %.0f ms of GPU time in %llu batches over 10 s (batch %.0f ms first to last command; classes %.0f ms, all ranges %.0f ms, untimed %.0f ms outside every range; %llu presents; %llu ranges dropped at the %u cap); by program:", timingProgramMs, static_cast<unsigned long long>(timingBatches), timingBatchMs, timingClassMs, timingUnionMs, timingBatchMs - timingUnionMs, static_cast<unsigned long long>(presents), static_cast<unsigned long long>(timingDropped.exchange(0, std::memory_order_relaxed)), MaxTimedRanges);
|
||||
for (std::size_t i = 0; i < hot.size() && i < 12; ++i) AgcDriver::ProfilePrint_nid_no_patch(" 0x%llx x%llu %.0fms", static_cast<unsigned long long>(hot[i].first), static_cast<unsigned long long>(hot[i].second.count), hot[i].second.ms);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("; by class:%s\n", classes.c_str());
|
||||
timingByKey.clear();
|
||||
timingProgramMs = timingClassMs = timingUnionMs = timingBatchMs = 0;
|
||||
timingBatches = 0;
|
||||
@@ -2996,7 +2997,7 @@ void ReportSyncWaits(SyncWaitStats& stats) {
|
||||
else std::snprintf(text, sizeof(text), " 0x%x %llu", queue, static_cast<unsigned long long>(count));
|
||||
report += text;
|
||||
}
|
||||
std::fprintf(stderr, "%s\n", report.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("%s\n", report.c_str());
|
||||
stats = SyncWaitStats{};
|
||||
}
|
||||
|
||||
@@ -3202,11 +3203,11 @@ void Recorder::finish(std::unique_ptr<Batch> batch, bool wait, int source) {
|
||||
if (now - lastReport > std::chrono::seconds(10)) {
|
||||
lastReport = now;
|
||||
const auto& h = holdCounters;
|
||||
std::fprintf(stderr, "[recorder] %llu syncs waited %.1f s for the GPU in total (sources, count/wait: idle %llu/%.1fs, pending write %llu/%.1fs, recorded store %llu/%.1fs, address-based %llu/%.1fs, other %llu/%.1fs); hook %llu calls, %llu locked; %llu targeted syncs left %llu batches in flight; snapshot %llu rebuilds %.0f ms, %llu notes covered; %llu unlocked timeline waits %.1f s; %llu submissions, %zu label entries, %llu completion labels pending; fence waits by thread (count/wait):%s; top sync sites (source@caller syncs/batches/wait):%s; under holds (cumulative): %llu completions ran %.0f ms (kept objects released %.0f ms), pending-write syncs from completions: %llu skipped, %llu waited %.0f ms; %llu reaps (%llu with work) retired %llu batches in %.0f ms; hook waits unlocked %llu / %.0f ms GPU (pending write %llu / %.0f ms, recorded store %llu / %.0f ms) + %.0f ms relock (%llu found the recorder torn down), locked %llu; deferred releases: on the release thread %llu batches (%llu objects) in %.0f ms, inline %llu batches (%llu objects) in %.0f ms (%llu batches over the queue bound of %zu), queue max %llu batches, %llu pending\n",static_cast<unsigned long long>(waits), waitedMs / 1000, static_cast<unsigned long long>(syncCounts[0]), syncWaitedMs[0] / 1000, static_cast<unsigned long long>(syncCounts[1]), syncWaitedMs[1] / 1000, static_cast<unsigned long long>(syncCounts[2]), syncWaitedMs[2] / 1000, static_cast<unsigned long long>(syncCounts[3]), syncWaitedMs[3] / 1000, static_cast<unsigned long long>(syncCounts[4]), syncWaitedMs[4] / 1000, static_cast<unsigned long long>(hookCalls.load()), static_cast<unsigned long long>(hookLocks.load()), static_cast<unsigned long long>(targetedSyncs.load()), static_cast<unsigned long long>(batchesLeftInFlight.load()), static_cast<unsigned long long>(snapshotRebuilds), snapshotRebuildMs, static_cast<unsigned long long>(snapshotCovered), static_cast<unsigned long long>(unlockedWaits.load()), unlockedWaitedUs.load() / 1e6, static_cast<unsigned long long>(recorder.submissions), recorder.PendingLabels(), static_cast<unsigned long long>(completionLabels.load()), ThreadSyncReport().c_str(), SyncSiteReport().c_str(), static_cast<unsigned long long>(h.completions), h.completionMs, h.keptReleaseMs, static_cast<unsigned long long>(h.completionSyncsSkipped), static_cast<unsigned long long>(h.completionSyncsWaited), h.completionSyncWaitMs, static_cast<unsigned long long>(h.reaps), static_cast<unsigned long long>(h.reapsWithWork), static_cast<unsigned long long>(h.reapBatches), h.reapMs, static_cast<unsigned long long>(h.hookUnlockedWaits), h.hookUnlockedWaitMs, static_cast<unsigned long long>(h.hookUnlockedWaitsBySource[1]), h.hookUnlockedWaitMsBySource[1], static_cast<unsigned long long>(h.hookUnlockedWaitsBySource[2]), h.hookUnlockedWaitMsBySource[2], h.hookRelockMs, static_cast<unsigned long long>(h.hookUnlockedTornDown), static_cast<unsigned long long>(h.hookLockedWaits), static_cast<unsigned long long>(threadReleases.load()), static_cast<unsigned long long>(threadObjects.load()), threadReleaseUs.load() / 1000.0, static_cast<unsigned long long>(inlineReleases.load()), static_cast<unsigned long long>(inlineObjects.load()), inlineReleaseUs.load() / 1000.0, static_cast<unsigned long long>(inlineOverBound.load()), ReleaseQueueBound(), static_cast<unsigned long long>(releaseQueueMax.load()), static_cast<unsigned long long>(deferredPending.load()));
|
||||
std::fprintf(stderr, "[recorder] completion label stores: %llu run, %llu skipped (no CPU write-back overlapped them); %llu counted pending at a write-back; %llu write-backs over a tracked label; %llu write-back completions pending\n", static_cast<unsigned long long>(completionStoresRun.load()), static_cast<unsigned long long>(completionStoresSkipped.load()), static_cast<unsigned long long>(completionLabelsCountedLate.load()), static_cast<unsigned long long>(writeBacksOverLabels.load()), static_cast<unsigned long long>(writeBackCompletions.load()));
|
||||
std::fprintf(stderr, "[recorder] submits %llu, vkQueueSubmit mean %.1f us, max %.1f us\n", static_cast<unsigned long long>(submitCount), submitCount != 0 ? submitUs / static_cast<double>(submitCount) : 0.0, submitMaxUs);
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[recorder] %llu syncs waited %.1f s for the GPU in total (sources, count/wait: idle %llu/%.1fs, pending write %llu/%.1fs, recorded store %llu/%.1fs, address-based %llu/%.1fs, other %llu/%.1fs); hook %llu calls, %llu locked; %llu targeted syncs left %llu batches in flight; snapshot %llu rebuilds %.0f ms, %llu notes covered; %llu unlocked timeline waits %.1f s; %llu submissions, %zu label entries, %llu completion labels pending; fence waits by thread (count/wait):%s; top sync sites (source@caller syncs/batches/wait):%s; under holds (cumulative): %llu completions ran %.0f ms (kept objects released %.0f ms), pending-write syncs from completions: %llu skipped, %llu waited %.0f ms; %llu reaps (%llu with work) retired %llu batches in %.0f ms; hook waits unlocked %llu / %.0f ms GPU (pending write %llu / %.0f ms, recorded store %llu / %.0f ms) + %.0f ms relock (%llu found the recorder torn down), locked %llu; deferred releases: on the release thread %llu batches (%llu objects) in %.0f ms, inline %llu batches (%llu objects) in %.0f ms (%llu batches over the queue bound of %zu), queue max %llu batches, %llu pending\n",static_cast<unsigned long long>(waits), waitedMs / 1000, static_cast<unsigned long long>(syncCounts[0]), syncWaitedMs[0] / 1000, static_cast<unsigned long long>(syncCounts[1]), syncWaitedMs[1] / 1000, static_cast<unsigned long long>(syncCounts[2]), syncWaitedMs[2] / 1000, static_cast<unsigned long long>(syncCounts[3]), syncWaitedMs[3] / 1000, static_cast<unsigned long long>(syncCounts[4]), syncWaitedMs[4] / 1000, static_cast<unsigned long long>(hookCalls.load()), static_cast<unsigned long long>(hookLocks.load()), static_cast<unsigned long long>(targetedSyncs.load()), static_cast<unsigned long long>(batchesLeftInFlight.load()), static_cast<unsigned long long>(snapshotRebuilds), snapshotRebuildMs, static_cast<unsigned long long>(snapshotCovered), static_cast<unsigned long long>(unlockedWaits.load()), unlockedWaitedUs.load() / 1e6, static_cast<unsigned long long>(recorder.submissions), recorder.PendingLabels(), static_cast<unsigned long long>(completionLabels.load()), ThreadSyncReport().c_str(), SyncSiteReport().c_str(), static_cast<unsigned long long>(h.completions), h.completionMs, h.keptReleaseMs, static_cast<unsigned long long>(h.completionSyncsSkipped), static_cast<unsigned long long>(h.completionSyncsWaited), h.completionSyncWaitMs, static_cast<unsigned long long>(h.reaps), static_cast<unsigned long long>(h.reapsWithWork), static_cast<unsigned long long>(h.reapBatches), h.reapMs, static_cast<unsigned long long>(h.hookUnlockedWaits), h.hookUnlockedWaitMs, static_cast<unsigned long long>(h.hookUnlockedWaitsBySource[1]), h.hookUnlockedWaitMsBySource[1], static_cast<unsigned long long>(h.hookUnlockedWaitsBySource[2]), h.hookUnlockedWaitMsBySource[2], h.hookRelockMs, static_cast<unsigned long long>(h.hookUnlockedTornDown), static_cast<unsigned long long>(h.hookLockedWaits), static_cast<unsigned long long>(threadReleases.load()), static_cast<unsigned long long>(threadObjects.load()), threadReleaseUs.load() / 1000.0, static_cast<unsigned long long>(inlineReleases.load()), static_cast<unsigned long long>(inlineObjects.load()), inlineReleaseUs.load() / 1000.0, static_cast<unsigned long long>(inlineOverBound.load()), ReleaseQueueBound(), static_cast<unsigned long long>(releaseQueueMax.load()), static_cast<unsigned long long>(deferredPending.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[recorder] completion label stores: %llu run, %llu skipped (no CPU write-back overlapped them); %llu counted pending at a write-back; %llu write-backs over a tracked label; %llu write-back completions pending\n", static_cast<unsigned long long>(completionStoresRun.load()), static_cast<unsigned long long>(completionStoresSkipped.load()), static_cast<unsigned long long>(completionLabelsCountedLate.load()), static_cast<unsigned long long>(writeBacksOverLabels.load()), static_cast<unsigned long long>(writeBackCompletions.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[recorder] submits %llu, vkQueueSubmit mean %.1f us, max %.1f us\n", static_cast<unsigned long long>(submitCount), submitCount != 0 ? submitUs / static_cast<double>(submitCount) : 0.0, submitMaxUs);
|
||||
const auto reads = Recorder::ReadCounts();
|
||||
std::fprintf(stderr, "[recorder] in-place reads: %llu noted, %llu queries, hits by reader: dispatch element %llu, gpu copy %llu, address-based %llu, indirect %llu, storage upload %llu, copy source %llu; %llu hits on signaled batches ignored\n", static_cast<unsigned long long>(reads.noted), static_cast<unsigned long long>(reads.queries), static_cast<unsigned long long>(reads.hits[0]), static_cast<unsigned long long>(reads.hits[1]), static_cast<unsigned long long>(reads.hits[2]), static_cast<unsigned long long>(reads.hits[3]), static_cast<unsigned long long>(reads.hits[4]), static_cast<unsigned long long>(reads.hits[5]), static_cast<unsigned long long>(reads.staleIgnored));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[recorder] in-place reads: %llu noted, %llu queries, hits by reader: dispatch element %llu, gpu copy %llu, address-based %llu, indirect %llu, storage upload %llu, copy source %llu; %llu hits on signaled batches ignored\n", static_cast<unsigned long long>(reads.noted), static_cast<unsigned long long>(reads.queries), static_cast<unsigned long long>(reads.hits[0]), static_cast<unsigned long long>(reads.hits[1]), static_cast<unsigned long long>(reads.hits[2]), static_cast<unsigned long long>(reads.hits[3]), static_cast<unsigned long long>(reads.hits[4]), static_cast<unsigned long long>(reads.hits[5]), static_cast<unsigned long long>(reads.staleIgnored));
|
||||
}
|
||||
}
|
||||
} report{profile, source, waitStart, *this, signaledAtStart};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/CaptureTrace.hpp"
|
||||
#include "ThreadOwned.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp"
|
||||
@@ -170,7 +171,7 @@ void reportTextureCounters() {
|
||||
auto last = counters.lastReport.load();
|
||||
if (nowMs - last < 10000 || !counters.lastReport.compare_exchange_strong(last, nowMs)) return;
|
||||
const auto count = [](const std::atomic<std::uint64_t>& value) { return static_cast<unsigned long long>(value.load(std::memory_order_relaxed)); };
|
||||
std::fprintf(stderr, "[textures] sampled created: %llu from storage images, %llu snapshots (%llu snapshot reads over recorded writes inside cachedTexture, %llu storage-path fallbacks); stage-A records %llu: %llu fast hits, %llu full lookups; storage images %llu hits, %llu created, %llu own-object refreshes\n", count(counters.fromStorage), count(counters.snapshots), count(counters.pendingReads), count(counters.storageFallbacks), count(counters.records), count(counters.fastHits), count(counters.fastMisses), count(counters.storageHits), count(counters.storageCreated), count(counters.ownRefreshes));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[textures] sampled created: %llu from storage images, %llu snapshots (%llu snapshot reads over recorded writes inside cachedTexture, %llu storage-path fallbacks); stage-A records %llu: %llu fast hits, %llu full lookups; storage images %llu hits, %llu created, %llu own-object refreshes\n", count(counters.fromStorage), count(counters.snapshots), count(counters.pendingReads), count(counters.storageFallbacks), count(counters.records), count(counters.fastHits), count(counters.fastMisses), count(counters.storageHits), count(counters.storageCreated), count(counters.ownRefreshes));
|
||||
}
|
||||
|
||||
// What the sampled-texture lookups on this thread proved their returned objects current against,
|
||||
@@ -836,7 +837,7 @@ struct ThreadBuildProfile {
|
||||
builds = 0;
|
||||
std::string report;
|
||||
for (std::size_t i = 0; i < BuildPhaseCount; ++i) report += " " + std::string(BuildPhaseNames[i]) + "=" + std::to_string(static_cast<long long>(profile.ms[i])) + "ms";
|
||||
std::fprintf(stderr, "[resources] %llu builds, phase totals:%s\n", static_cast<unsigned long long>(profile.builds), report.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[resources] %llu builds, phase totals:%s\n", static_cast<unsigned long long>(profile.builds), report.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -872,7 +873,7 @@ double ShaderResources::phase(BuildPhase which) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const auto ms = std::chrono::duration<double, std::milli>(now - phaseStart).count();
|
||||
addBuildPhase(which, ms);
|
||||
if (ms > 50) std::fprintf(stderr, "[resources] %s took %.0f ms (%zu textures, %zu storage images, %zu buffers, bda %d)\n", BuildPhaseNames[static_cast<std::size_t>(which)], ms, textures.size(), storageTextures.size(), allocations.size(), usesBda ? 1 : 0);
|
||||
if (ms > 50) AgcDriver::ProfilePrint_nid_no_patch("[resources] %s took %.0f ms (%zu textures, %zu storage images, %zu buffers, bda %d)\n", BuildPhaseNames[static_cast<std::size_t>(which)], ms, textures.size(), storageTextures.size(), allocations.size(), usesBda ? 1 : 0);
|
||||
phaseStart = now;
|
||||
return ms;
|
||||
}
|
||||
@@ -1161,7 +1162,7 @@ void ShaderResources::reportDescriptorCaches() const {
|
||||
const auto descriptors = context.descriptorCache != nullptr ? context.descriptorCache->Counters() : DescriptorCache::Stats{};
|
||||
const auto samplerHits = context.samplerCache != nullptr ? context.samplerCache->Hits() : 0;
|
||||
const auto samplerMisses = context.samplerCache != nullptr ? context.samplerCache->Misses() : 0;
|
||||
std::fprintf(stderr, "[descriptors] layouts %llu hits / %llu created, sets %llu from %llu pools, samplers %llu hits / %llu created\n", static_cast<unsigned long long>(descriptors.layoutHits), static_cast<unsigned long long>(descriptors.layoutMisses), static_cast<unsigned long long>(descriptors.sets), static_cast<unsigned long long>(descriptors.pools), static_cast<unsigned long long>(samplerHits), static_cast<unsigned long long>(samplerMisses));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[descriptors] layouts %llu hits / %llu created, sets %llu from %llu pools, samplers %llu hits / %llu created\n", static_cast<unsigned long long>(descriptors.layoutHits), static_cast<unsigned long long>(descriptors.layoutMisses), static_cast<unsigned long long>(descriptors.sets), static_cast<unsigned long long>(descriptors.pools), static_cast<unsigned long long>(samplerHits), static_cast<unsigned long long>(samplerMisses));
|
||||
}
|
||||
|
||||
std::vector<std::uint32_t> ShaderResources::ContentKey(const CompiledShader& shader, bool dataWords, bool movableBuffers) {
|
||||
@@ -1344,7 +1345,7 @@ void countRevalidate(bool fast, bool ok, std::chrono::steady_clock::time_point s
|
||||
const auto reasons = byReason(profile.fastFails, FastFailNames);
|
||||
const auto fullReasons = byReason(profile.fullByReason, FastFailNames);
|
||||
const auto fallbacks = byReason(profile.ownFallbacks, OwnRefreshFallbackNames);
|
||||
std::fprintf(stderr, "[rescache] revalidate %llu calls %.1f ms: fast %llu, full %llu, failed %llu; fast-fail by reason:%s; full walks: T1 refreshed %llu (%llu storage images, %llu view sources, %llu views served by their own pending source, %llu overlaps left by the refresh accepted), full by reason:%s, T1 fallback by reason:%s, proofs verified %llu; fast-fail pending image: own 0 (the query excepts the own object), foreign %llu, snapshot %llu, T1 eligible %llu; keys proven: %llu sampled, %llu storage; epoch gate: %llu registry scans skipped, %llu import loops skipped\n", static_cast<unsigned long long>(profile.calls.load()), profile.nanoseconds.load() / 1e6, static_cast<unsigned long long>(profile.fast.load()), static_cast<unsigned long long>(profile.full.load()), static_cast<unsigned long long>(profile.failed.load()), reasons.c_str(), static_cast<unsigned long long>(profile.ownRefreshed.load()), static_cast<unsigned long long>(profile.ownStorageRefreshes.load()), static_cast<unsigned long long>(profile.ownViewRefreshes.load()), static_cast<unsigned long long>(profile.ownSourceViews.load()), static_cast<unsigned long long>(profile.refreshedOverlaps.load()), fullReasons.c_str(), fallbacks.c_str(), static_cast<unsigned long long>(profile.proofsVerified.load()), static_cast<unsigned long long>(profile.pendingForeign.load()), static_cast<unsigned long long>(profile.pendingSnapshot.load()), static_cast<unsigned long long>(profile.pendingT1Eligible.load()), static_cast<unsigned long long>(profile.keysProven.load()), static_cast<unsigned long long>(profile.storageKeysProven.load()), static_cast<unsigned long long>(profile.serialSkips.load()), static_cast<unsigned long long>(profile.importSkips.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[rescache] revalidate %llu calls %.1f ms: fast %llu, full %llu, failed %llu; fast-fail by reason:%s; full walks: T1 refreshed %llu (%llu storage images, %llu view sources, %llu views served by their own pending source, %llu overlaps left by the refresh accepted), full by reason:%s, T1 fallback by reason:%s, proofs verified %llu; fast-fail pending image: own 0 (the query excepts the own object), foreign %llu, snapshot %llu, T1 eligible %llu; keys proven: %llu sampled, %llu storage; epoch gate: %llu registry scans skipped, %llu import loops skipped\n", static_cast<unsigned long long>(profile.calls.load()), profile.nanoseconds.load() / 1e6, static_cast<unsigned long long>(profile.fast.load()), static_cast<unsigned long long>(profile.full.load()), static_cast<unsigned long long>(profile.failed.load()), reasons.c_str(), static_cast<unsigned long long>(profile.ownRefreshed.load()), static_cast<unsigned long long>(profile.ownStorageRefreshes.load()), static_cast<unsigned long long>(profile.ownViewRefreshes.load()), static_cast<unsigned long long>(profile.ownSourceViews.load()), static_cast<unsigned long long>(profile.refreshedOverlaps.load()), fullReasons.c_str(), fallbacks.c_str(), static_cast<unsigned long long>(profile.proofsVerified.load()), static_cast<unsigned long long>(profile.pendingForeign.load()), static_cast<unsigned long long>(profile.pendingSnapshot.load()), static_cast<unsigned long long>(profile.pendingT1Eligible.load()), static_cast<unsigned long long>(profile.keysProven.load()), static_cast<unsigned long long>(profile.storageKeysProven.load()), static_cast<unsigned long long>(profile.serialSkips.load()), static_cast<unsigned long long>(profile.importSkips.load()));
|
||||
}
|
||||
|
||||
// APS5_NO_EPOCH_REVALIDATE=1: the per-element registry, cache and stamp checks and the per-region
|
||||
@@ -1991,7 +1992,7 @@ void ResourceCache::noteMiss(const Key& key) {
|
||||
}
|
||||
std::snprintf(item, sizeof(item), "; layout %llu, draw target/index %llu, same key %llu (not inserted or evicted), first seen %llu", static_cast<unsigned long long>(churn.layout), static_cast<unsigned long long>(churn.drawWords), static_cast<unsigned long long>(churn.sameKey), static_cast<unsigned long long>(churn.firstSeen));
|
||||
line += item;
|
||||
std::fprintf(stderr, "%s\n", line.c_str());
|
||||
AgcDriver::ProfilePrint_nid_no_patch("%s\n", line.c_str());
|
||||
};
|
||||
report("dispatch", churn.dispatch);
|
||||
report("draws", churn.draws);
|
||||
@@ -2828,7 +2829,7 @@ void ShaderResources::MarkGpuWrites(Recorder& recorder) {
|
||||
if (nowMs - last < 10000 || !counters.lastReport.compare_exchange_strong(last, nowMs)) return;
|
||||
const auto elements = counters.elements.load();
|
||||
const auto readOnly = counters.readOnly.load();
|
||||
std::fprintf(stderr, "[buffers] descriptor elements bound: %llu total, %llu written, %llu read-only; %llu pending-write notes skipped\n", static_cast<unsigned long long>(elements), static_cast<unsigned long long>(elements - readOnly), static_cast<unsigned long long>(readOnly), static_cast<unsigned long long>(counters.notesSkipped.load()));
|
||||
AgcDriver::ProfilePrint_nid_no_patch("[buffers] descriptor elements bound: %llu total, %llu written, %llu read-only; %llu pending-write notes skipped\n", static_cast<unsigned long long>(elements), static_cast<unsigned long long>(elements - readOnly), static_cast<unsigned long long>(readOnly), static_cast<unsigned long long>(counters.notesSkipped.load()));
|
||||
}
|
||||
|
||||
void ShaderResources::WriteBackBuffers() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/CaptureTrace.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Texture.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
@@ -125,7 +126,7 @@ void reportStorageTraffic(StorageTraffic& traffic) {
|
||||
const auto take = [](std::atomic<std::uint64_t>& counter) { return static_cast<unsigned long long>(counter.exchange(0, std::memory_order_relaxed)); };
|
||||
const auto partialUploadCount = take(partialUploads), partialWriteBackCount = take(partialWriteBacks);
|
||||
const auto uploadMiB = take(partialUploadBytes) / 1048576.0, writeBackMiB = take(partialWriteBackBytes) / 1048576.0;
|
||||
std::fprintf(stderr, "[storage] uploads by path (count/MiB, 10 s):%s; %llu write-backs GPU-direct, %llu stored nothing; block units: partial uploads %llu/%.1f, partial write-backs %llu/%.1f, %llu widened to every pending unit, units dropped %llu, superseded %llu, dropped unregistered %llu, kept over a key flip %llu%s, pretest skipped %llu, evicted stale %llu\n", line.c_str(), static_cast<unsigned long long>(traffic.directWriteBacks), take(emptyWriteBacks), partialUploadCount, uploadMiB, partialWriteBackCount, writeBackMiB, take(coalescedWriteBacks), take(unitsDropped), take(unitsSuperseded), take(unregisteredDropped), take(keyFlipKept), ShadowReport().c_str(), take(pretestSkipped), take(staleEvicted));
|
||||
AgcDriver::ProfilePrint_nid_no_patch( "[storage] uploads by path (count/MiB, 10 s):%s; %llu write-backs GPU-direct, %llu stored nothing; block units: partial uploads %llu/%.1f, partial write-backs %llu/%.1f, %llu widened to every pending unit, units dropped %llu, superseded %llu, dropped unregistered %llu, kept over a key flip %llu%s, pretest skipped %llu, evicted stale %llu\n", line.c_str(), static_cast<unsigned long long>(traffic.directWriteBacks), take(emptyWriteBacks), partialUploadCount, uploadMiB, partialWriteBackCount, writeBackMiB, take(coalescedWriteBacks), take(unitsDropped), take(unitsSuperseded), take(unregisteredDropped), take(keyFlipKept), ShadowReport().c_str(), take(pretestSkipped), take(staleEvicted));
|
||||
traffic.writeBacks.clear();
|
||||
traffic.uploadReasons.clear();
|
||||
traffic.directWriteBacks = 0;
|
||||
|
||||
@@ -234,7 +234,7 @@ void recordCopies(const UnitShadow& shadow, const std::vector<SlabCopies>& copie
|
||||
if (recorder != nullptr && (covered & transferAccess) == transferAccess && Recorder::MergeBarriers()) {
|
||||
Recorder::CountMerged(CommandClass::ShadowPublish);
|
||||
} else {
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, transferAccess);
|
||||
RecordMemoryBarrier(context, commands, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_HOST_WRITE_BIT, transferAccess);
|
||||
Recorder::CountBarriers(CommandClass::ShadowPublish);
|
||||
}
|
||||
const auto copyBuffer = context.Resolved(&DeviceFunctions::cmdCopyBuffer, "vkCmdCopyBuffer");
|
||||
|
||||
@@ -43,4 +43,79 @@ int APS5_VABI sceAgcDriverUnregisterResource(uint32_t resource_handle) {
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverRegisterGdsResource(uint32_t* resource_handle, uint32_t owner_handle, uint32_t gds_offset, uint32_t gds_size, const char* name, uint32_t type, uint64_t user_data) {
|
||||
(void)resource_handle;
|
||||
(void)owner_handle;
|
||||
(void)gds_offset;
|
||||
(void)gds_size;
|
||||
(void)name;
|
||||
(void)type;
|
||||
(void)user_data;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverUnregisterAllResourcesForOwner(uint32_t owner_handle) {
|
||||
(void)owner_handle;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverUnregisterWorkloadStream(uint32_t stream_id) {
|
||||
(void)stream_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetDefaultOwner(uint32_t* owner_handle) {
|
||||
(void)owner_handle;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetOwnerName(uint32_t owner_handle, const char** name) {
|
||||
(void)owner_handle;
|
||||
(void)name;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceName(uint32_t resource_handle, const char** name) {
|
||||
(void)resource_handle;
|
||||
(void)name;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceType(uint32_t resource_handle, uint32_t* type) {
|
||||
(void)resource_handle;
|
||||
(void)type;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceUserData(uint32_t resource_handle, uint64_t* user_data) {
|
||||
(void)resource_handle;
|
||||
(void)user_data;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverSetResourceUserData(uint32_t resource_handle, uint64_t user_data) {
|
||||
(void)resource_handle;
|
||||
(void)user_data;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceBaseAddressAndSizeInBytes(uint32_t resource_handle, void** memory, size_t* size) {
|
||||
(void)resource_handle;
|
||||
(void)memory;
|
||||
(void)size;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceShaderGuid(uint32_t resource_handle, void* guid) {
|
||||
(void)resource_handle;
|
||||
(void)guid;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverFindResourcesPublic(const void* callback, void* user_data) {
|
||||
(void)callback;
|
||||
(void)user_data;
|
||||
return SCE_AGC_ERROR_RESOURCE_REGISTRATION_UNAVAILABLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,18 +8,15 @@
|
||||
extern "C" {
|
||||
|
||||
bool APS5_VABI sceAgcDriverIsCaptureInProgress(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool APS5_VABI sceAgcDriverIsTraceInProgress(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool APS5_VABI sceAgcDriverIsSubmitValidationEnabled(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverRequestCaptureStart(const char* path) {
|
||||
|
||||
@@ -5,5 +5,7 @@
|
||||
|
||||
extern "C" int APS5_VABI sceAgcDriverSubmitDcb(const Packet* packet);
|
||||
extern "C" int APS5_VABI sceAgcDriverAgrSubmitDcb(const Packet* packet);
|
||||
extern "C" int APS5_VABI sceAgcDriverSubmitMultiDcbs(std::uint32_t* const* dcbGpuAddrs, const std::uint32_t* dcbSizesInDwords, std::uint32_t count);
|
||||
extern "C" int APS5_VABI sceAgcDriverAgrSubmitMultiDcbs(std::uint32_t* const* dcbGpuAddrs, const std::uint32_t* dcbSizesInDwords, std::uint32_t count);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,18 @@
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
static int SubmitMany(std::uint32_t* const* addresses, const std::uint32_t* sizes, std::uint32_t count) {
|
||||
if (count == 0) return 0;
|
||||
if (!addresses || !sizes) throw std::runtime_error("AGC driver: null multi-DCB arrays");
|
||||
AgcDriver::GuestMemory::CheckRange(addresses, count * sizeof(*addresses), alignof(std::uint32_t*));
|
||||
AgcDriver::GuestMemory::CheckRange(sizes, count * sizeof(*sizes), alignof(std::uint32_t));
|
||||
for (std::uint32_t i = 0; i < count; ++i) {
|
||||
const Packet packet{addresses[i], sizes[i], 0, {}};
|
||||
AgcDriver::Submit(&packet, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
std::uint32_t APS5_VABI sceAgcDriverGetWaitRenderingPacketSizeInDwords() {
|
||||
@@ -33,12 +45,8 @@ int APS5_VABI sceAgcDriverSubmitDcb(const Packet* packet) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverSubmitMultiDcbs(uint32_t* const* dcb_gpu_addrs, const uint32_t* dcb_sizes_in_dwords, uint32_t count) {
|
||||
(void)dcb_gpu_addrs;
|
||||
(void)dcb_sizes_in_dwords;
|
||||
(void)count;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
int APS5_VABI sceAgcDriverSubmitMultiDcbs(std::uint32_t* const* dcbGpuAddrs, const std::uint32_t* dcbSizesInDwords, std::uint32_t count) {
|
||||
return SubmitMany(dcbGpuAddrs, dcbSizesInDwords, count);
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverAgrSubmitDcb(const Packet* packet) {
|
||||
@@ -47,11 +55,7 @@ int APS5_VABI sceAgcDriverAgrSubmitDcb(const Packet* packet) {
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverAgrSubmitMultiDcbs(std::uint32_t* const* dcbGpuAddrs, const std::uint32_t* dcbSizesInDwords, std::uint32_t count) {
|
||||
(void)dcbGpuAddrs;
|
||||
(void)dcbSizesInDwords;
|
||||
(void)count;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return SubmitMany(dcbGpuAddrs, dcbSizesInDwords, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,51 +5,11 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
int APS5_VABI sceAgcDriverFindResourcesPublic() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetDefaultOwner() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetOwnerName() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceBaseAddressAndSizeInBytes() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceName() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceRegistrationMaxNameLength() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceShaderGuid() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceType() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetResourceUserData() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverGetShaderDebuggingStatus() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
@@ -60,31 +20,11 @@ int APS5_VABI sceAgcDriverRegisterDefaultOwner(uint32_t* owner_handle) {
|
||||
return static_cast<int>(0x8A6C9018);
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverRegisterGdsResource() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverSetResourceUserData() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverSetValidationErrorOutputFrequency() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverUnregisterAllResourcesForOwner() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverUnregisterWorkloadStream() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAgcDriverSetSubmitValidationMode() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
void Check(bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
void FormatAndDrain() {
|
||||
std::string written;
|
||||
const std::string longLine(6000, 'x');
|
||||
{
|
||||
AgcDriver::ProfileOutput output([&](std::string_view text) { written += text; });
|
||||
output.Print("%s %.2f %llu\n", "shader", 1.25, 42ull);
|
||||
output.Print("%s\n", longLine.c_str());
|
||||
}
|
||||
Check(written == "shader 1.25 42\n" + longLine + "\n", "formatting or shutdown drain changed the output");
|
||||
}
|
||||
|
||||
void SlowWriter() {
|
||||
std::mutex mutex;
|
||||
std::condition_variable release;
|
||||
bool released = false;
|
||||
std::promise<void> entered;
|
||||
bool first = true;
|
||||
std::string written;
|
||||
AgcDriver::ProfileOutput output([&](std::string_view text) {
|
||||
if (first) {
|
||||
first = false;
|
||||
entered.set_value();
|
||||
std::unique_lock lock(mutex);
|
||||
release.wait(lock, [&] { return released; });
|
||||
}
|
||||
written += text;
|
||||
}, 16);
|
||||
std::future<bool> producer;
|
||||
struct Release {
|
||||
std::mutex& mutex;
|
||||
std::condition_variable& changed;
|
||||
bool& released;
|
||||
~Release() {
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
released = true;
|
||||
}
|
||||
changed.notify_one();
|
||||
}
|
||||
} cleanup{mutex, release, released};
|
||||
Check(output.Write("12345678"), "first write was rejected");
|
||||
Check(entered.get_future().wait_for(std::chrono::seconds(2)) == std::future_status::ready, "writer did not start");
|
||||
producer = std::async(std::launch::async, [&] { return output.Write("abcdefgh"); });
|
||||
Check(producer.wait_for(std::chrono::seconds(2)) == std::future_status::ready, "producer blocked behind the diagnostic writer");
|
||||
Check(producer.get(), "write within the bound was rejected");
|
||||
Check(!output.Write("z"), "queue bound did not include the in-flight output");
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
released = true;
|
||||
}
|
||||
release.notify_one();
|
||||
output.Flush();
|
||||
Check(written.starts_with("12345678abcdefgh"), "accepted chunks changed order");
|
||||
Check(written.find("[profile-output] dropped 1 chunks") != std::string::npos, "bounded overflow was not reported");
|
||||
}
|
||||
|
||||
void ConcurrentWriters() {
|
||||
std::string written;
|
||||
AgcDriver::ProfileOutput output([&](std::string_view text) { written += text; });
|
||||
std::vector<std::thread> producers;
|
||||
for (int thread = 0; thread < 8; ++thread) {
|
||||
producers.emplace_back([&, thread] {
|
||||
for (int item = 0; item < 100; ++item) output.Print("%d:%d\n", thread, item);
|
||||
});
|
||||
}
|
||||
for (auto& producer : producers) producer.join();
|
||||
output.Flush();
|
||||
std::istringstream stream(written);
|
||||
std::vector<std::string> lines;
|
||||
for (std::string line; std::getline(stream, line);) lines.push_back(line);
|
||||
std::sort(lines.begin(), lines.end());
|
||||
Check(lines.size() == 800 && std::adjacent_find(lines.begin(), lines.end()) == lines.end(), "concurrent writes lost or duplicated chunks");
|
||||
for (int thread = 0; thread < 8; ++thread) {
|
||||
for (int item = 0; item < 100; ++item)
|
||||
Check(std::binary_search(lines.begin(), lines.end(), std::to_string(thread) + ":" + std::to_string(item)), "concurrent formatting changed a chunk");
|
||||
}
|
||||
}
|
||||
|
||||
void WriterFailure() {
|
||||
AgcDriver::ProfileOutput output([](std::string_view) { throw std::runtime_error("test writer failure"); });
|
||||
output.Write("test");
|
||||
for (int operation = 0; operation < 2; ++operation) {
|
||||
bool failed = false;
|
||||
try {
|
||||
if (operation == 0) output.Flush();
|
||||
else output.Write("next");
|
||||
} catch (const std::runtime_error& error) {
|
||||
failed = std::string(error.what()) == "test writer failure";
|
||||
}
|
||||
Check(failed, "writer failure was not propagated");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
FormatAndDrain();
|
||||
SlowWriter();
|
||||
ConcurrentWriters();
|
||||
WriterFailure();
|
||||
std::cout << "profile output tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/QueueState.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp"
|
||||
#include "prx/libc/include/Shutdown.hpp"
|
||||
#include "prx/libSceAgcDriver/Submit/include/Dcb.hpp"
|
||||
#include "prx/libSceAgcDriver/Submit/include/Acb.hpp"
|
||||
@@ -7,6 +8,7 @@
|
||||
#include "prx/libSceAgcDriver/Eq/include/Event.hpp"
|
||||
#include "prx/libkernel/Equeue/Equeue.hpp"
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
@@ -15,6 +17,9 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
extern "C" int APS5_VABI sceKernelCreateEqueue(KernelEqueue* eq, const char* name);
|
||||
extern "C" int APS5_VABI sceKernelDeleteEqueue(KernelEqueue eq);
|
||||
@@ -342,6 +347,33 @@ void testWaitFreeSubmissionTheCpuWaitsFor() {
|
||||
AgcDriverWaitIdle_nid_postfix();
|
||||
}
|
||||
|
||||
void testMultiSubmissions() {
|
||||
alignas(64) static volatile std::uint32_t value = 0, done = 0;
|
||||
check(sceAgcDriverSubmitMultiDcbs(nullptr, nullptr, 0) == 0, "empty multi-DCB submit failed");
|
||||
check(sceAgcDriverAgrSubmitMultiDcbs(nullptr, nullptr, 0) == 0, "empty AGR multi-DCB submit failed");
|
||||
std::array<std::uint32_t, 3> invalid{0xc0017600, 0x20c, 0};
|
||||
std::array<std::uint32_t*, 1> invalidAddresses{invalid.data()};
|
||||
std::array<std::uint32_t, 1> invalidSizes{2};
|
||||
expectFailure([&] { sceAgcDriverSubmitMultiDcbs(nullptr, invalidSizes.data(), 1); });
|
||||
expectFailure([&] { sceAgcDriverAgrSubmitMultiDcbs(invalidAddresses.data(), nullptr, 1); });
|
||||
expectFailure([&] { sceAgcDriverSubmitMultiDcbs(invalidAddresses.data(), invalidSizes.data(), 1); });
|
||||
expectFailure([&] { sceAgcDriverAgrSubmitMultiDcbs(invalidAddresses.data(), invalidSizes.data(), 1); });
|
||||
for (bool agr : {false, true}) {
|
||||
value = 0;
|
||||
done = 0;
|
||||
auto first = writeData(&value, 1);
|
||||
auto second = writeData(&value, 2);
|
||||
auto third = writeData(&done, 1);
|
||||
std::array<std::uint32_t*, 3> addresses{first.data(), second.data(), third.data()};
|
||||
std::array<std::uint32_t, 3> sizes{static_cast<std::uint32_t>(first.size()), static_cast<std::uint32_t>(second.size()), static_cast<std::uint32_t>(third.size())};
|
||||
const int result = agr ? sceAgcDriverAgrSubmitMultiDcbs(addresses.data(), sizes.data(), 3) : sceAgcDriverSubmitMultiDcbs(addresses.data(), sizes.data(), 3);
|
||||
check(result == 0, "multi-DCB submit failed");
|
||||
waitFor(&done, 1, "the last DCB of a multi-DCB submit never ran");
|
||||
check(value == 2, "multi-DCB submit did not run its DCBs in order");
|
||||
AgcDriverWaitIdle_nid_postfix();
|
||||
}
|
||||
}
|
||||
|
||||
void testWorkerFailure() {
|
||||
std::array<std::uint32_t, 5> words{0xc0031500, 1, 1, 1, 0x41};
|
||||
Packet packet{words.data(), static_cast<std::uint32_t>(words.size()), 0, {}};
|
||||
@@ -362,6 +394,68 @@ void testWorkerFailure() {
|
||||
|
||||
int main() {
|
||||
try {
|
||||
alignas(256) std::array<std::uint32_t, 64> rawCode{};
|
||||
rawCode.fill(0xbf800000);
|
||||
rawCode[0] = 0xbe8003ff;
|
||||
rawCode[1] = 0xbf810000;
|
||||
rawCode[2] = 0xbf810000;
|
||||
const auto rawAddress = reinterpret_cast<std::uintptr_t>(rawCode.data());
|
||||
const auto literal = AgcDriver::DriverDetail::ReadRawComputeShader(rawAddress);
|
||||
check(literal->code.size() == 3 && literal->header.empty(), "raw compute stopped at an instruction literal");
|
||||
check(AgcDriver::DriverDetail::ReadRawComputeShader(rawAddress) == literal, "unchanged raw compute code lost its snapshot identity");
|
||||
rawCode[0] = 0xbf820002;
|
||||
rawCode[1] = 0xbf810000;
|
||||
rawCode[2] = 0xbf800000;
|
||||
rawCode[3] = 0xbf810000;
|
||||
const auto branched = AgcDriver::DriverDetail::ReadRawComputeShader(rawAddress);
|
||||
check(branched->code.size() == 4 && literal->code[0] == 0xbe8003ff, "raw compute lost branch targets or modified an earlier snapshot");
|
||||
check(branched != literal, "changed raw compute code reused a stale snapshot");
|
||||
std::array<std::shared_ptr<const AgcDriver::DriverDetail::ShaderSnapshot>, 8> concurrent;
|
||||
std::vector<std::thread> readers;
|
||||
for (auto& snapshot : concurrent) readers.emplace_back([&snapshot, rawAddress] {
|
||||
snapshot = AgcDriver::DriverDetail::ReadRawComputeShader(rawAddress);
|
||||
});
|
||||
for (auto& reader : readers) reader.join();
|
||||
for (const auto& snapshot : concurrent) check(snapshot == branched, "concurrent raw compute readers lost snapshot reuse");
|
||||
alignas(256) std::array<std::array<std::uint32_t, 64>, 65> programs{};
|
||||
for (auto& program : programs) program[0] = 0xbf810000;
|
||||
const auto firstAddress = reinterpret_cast<std::uintptr_t>(programs.front().data());
|
||||
readers.clear();
|
||||
for (auto& snapshot : concurrent) readers.emplace_back([&snapshot, firstAddress] {
|
||||
snapshot = AgcDriver::DriverDetail::ReadRawComputeShader(firstAddress);
|
||||
});
|
||||
for (auto& reader : readers) reader.join();
|
||||
for (const auto& snapshot : concurrent) check(snapshot == concurrent.front(), "concurrent raw compute misses duplicated snapshots");
|
||||
const auto evicted = AgcDriver::DriverDetail::ReadRawComputeShader(firstAddress);
|
||||
for (std::size_t i = 1; i < programs.size(); ++i)
|
||||
AgcDriver::DriverDetail::ReadRawComputeShader(reinterpret_cast<std::uintptr_t>(programs[i].data()));
|
||||
check(AgcDriver::DriverDetail::ReadRawComputeShader(firstAddress) != evicted && evicted->code[0] == 0xbf810000,
|
||||
"raw compute cache eviction lost snapshot lifetime or exceeded its entry limit");
|
||||
check(!expectFailure([&] { AgcDriver::DriverDetail::ReadRawComputeShader(rawAddress + 4); }).empty(), "raw compute accepted a misaligned entry");
|
||||
check(!expectFailure([] { AgcDriver::DriverDetail::ReadRawComputeShader(0); }).empty(), "raw compute accepted an unmapped entry");
|
||||
#ifdef _WIN32
|
||||
auto* mapping = static_cast<std::uint32_t*>(VirtualAlloc(nullptr, 8192, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
|
||||
check(mapping != nullptr, "cannot allocate raw compute boundary test");
|
||||
DWORD protection = 0;
|
||||
check(VirtualProtect(mapping + 1024, 4096, PAGE_NOACCESS, &protection) != 0, "cannot protect raw compute boundary");
|
||||
auto* boundedCode = mapping + 1024 - 64;
|
||||
std::fill_n(boundedCode, 64, 0xbf800000u);
|
||||
const auto boundedAddress = reinterpret_cast<std::uintptr_t>(boundedCode);
|
||||
const auto unterminated = expectFailure([&] { AgcDriver::DriverDetail::ReadRawComputeShader(boundedAddress); });
|
||||
boundedCode[63] = 0xbf810000;
|
||||
const auto bounded = AgcDriver::DriverDetail::ReadRawComputeShader(boundedAddress);
|
||||
check(VirtualProtect(mapping + 1024, 4096, PAGE_READWRITE, &protection) != 0, "cannot extend raw compute mapping");
|
||||
boundedCode[63] = 0xbf800000;
|
||||
boundedCode[64] = 0xbf810000;
|
||||
const auto extended = AgcDriver::DriverDetail::ReadRawComputeShader(boundedAddress);
|
||||
check(extended != bounded && extended->code.size() == 65, "raw compute reused code before its end changed");
|
||||
check(VirtualProtect(mapping + 1024, 4096, PAGE_NOACCESS, &protection) != 0, "cannot revoke cached raw compute tail");
|
||||
check(!expectFailure([&] { AgcDriver::DriverDetail::ReadRawComputeShader(boundedAddress); }).empty(), "raw compute reused an inaccessible cached tail");
|
||||
check(VirtualProtect(mapping, 4096, PAGE_NOACCESS, &protection) != 0, "cannot revoke cached raw compute code");
|
||||
check(!expectFailure([&] { AgcDriver::DriverDetail::ReadRawComputeShader(boundedAddress); }).empty(), "raw compute reused inaccessible cached code");
|
||||
check(VirtualFree(mapping, 0, MEM_RELEASE) != 0, "cannot release raw compute boundary test");
|
||||
check(!unterminated.empty() && bounded->code.size() == 64, "raw compute crossed inaccessible memory or missed its last instruction");
|
||||
#endif
|
||||
testEvents();
|
||||
testValidation();
|
||||
testClearState();
|
||||
@@ -375,6 +469,7 @@ int main() {
|
||||
testWaitFreeSubmissionQueue0WaitsOn();
|
||||
testWaitFreeSubmissionBehindHeldOne();
|
||||
testWaitFreeSubmissionTheCpuWaitsFor();
|
||||
testMultiSubmissions();
|
||||
testWorkerFailure();
|
||||
check(expectFailure([] { LibcRunShutdown_nid_postfix(); }).find("required shader register") != std::string::npos, "shutdown lost worker failure");
|
||||
std::puts("AGC driver submit tests passed");
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "RdnaDecoder/RdnaInstructionDecoder.hpp"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace ShaderRecompiler;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::uint32_t MoveSdwa = 0x7e0602f9u;
|
||||
constexpr std::uint32_t SourceVector = 4;
|
||||
constexpr std::uint32_t DestinationVector = 3;
|
||||
|
||||
constexpr std::uint32_t Modifier(std::uint32_t destinationSelector, std::uint32_t unused, std::uint32_t sourceSelector, std::uint32_t signExtend) {
|
||||
return SourceVector | (destinationSelector << 8u) | (unused << 11u) | (sourceSelector << 16u) | (signExtend << 19u);
|
||||
}
|
||||
|
||||
bool Matches(const RdnaInstruction& instruction, std::uint32_t destinationSelector, std::uint32_t unused, std::uint32_t sourceSelector, std::uint32_t signExtend) {
|
||||
return instruction.op == RdnaOpcode::VMovB32 && instruction.wordCount == 2u && instruction.sourceCount == 1u &&
|
||||
instruction.destination.kind == RdnaOperandKind::VectorRegister && instruction.destination.reg == DestinationVector &&
|
||||
instruction.destination.explicitSdwaDst && instruction.destination.sdwaSel == destinationSelector &&
|
||||
instruction.destination.sdwaDstUnused == unused &&
|
||||
instruction.source0.kind == RdnaOperandKind::VectorRegister && instruction.source0.reg == SourceVector &&
|
||||
instruction.source0.sdwaSel == sourceSelector && instruction.source0.sdwaSext == (signExtend != 0u) &&
|
||||
!instruction.source0.negate && !instruction.source0.absolute;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int failures = 0;
|
||||
for (std::uint32_t sourceSelector = 0; sourceSelector < 7u; ++sourceSelector) {
|
||||
for (std::uint32_t signExtend = 0; signExtend < 2u; ++signExtend) {
|
||||
for (std::uint32_t destinationSelector = 0; destinationSelector < 7u; ++destinationSelector) {
|
||||
for (std::uint32_t unused = 0; unused < 3u; ++unused) {
|
||||
const std::array<std::uint32_t, 2> words{MoveSdwa, Modifier(destinationSelector, unused, sourceSelector, signExtend)};
|
||||
try {
|
||||
if (!Matches(DecodeRdnaInstruction(0u, words, 0u), destinationSelector, unused, sourceSelector, signExtend)) {
|
||||
std::fprintf(stderr, "dst_sel %u dst_unused %u src0_sel %u sext %u decodes with the wrong operands\n", destinationSelector, unused, sourceSelector, signExtend);
|
||||
++failures;
|
||||
}
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "dst_sel %u dst_unused %u src0_sel %u sext %u: %s\n", destinationSelector, unused, sourceSelector, signExtend, error.what());
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
struct Rejected {
|
||||
const char* name;
|
||||
std::uint32_t modifier;
|
||||
};
|
||||
constexpr std::array<Rejected, 6> rejected{{
|
||||
{"reserved dst_unused on a byte destination", Modifier(1u, 3u, 0u, 0u)},
|
||||
{"reserved dst_unused on a dword destination", Modifier(6u, 3u, 6u, 0u)},
|
||||
{"reserved dst_sel", Modifier(7u, 0u, 0u, 0u)},
|
||||
{"reserved src0_sel", Modifier(0u, 2u, 7u, 0u)},
|
||||
{"neg on a byte source", Modifier(1u, 2u, 0u, 0u) | (1u << 20u)},
|
||||
{"abs on a word source", Modifier(5u, 2u, 4u, 0u) | (1u << 21u)},
|
||||
}};
|
||||
for (const auto& entry : rejected) {
|
||||
const std::array<std::uint32_t, 2> words{MoveSdwa, entry.modifier};
|
||||
try {
|
||||
static_cast<void>(DecodeRdnaInstruction(0u, words, 0u));
|
||||
std::fprintf(stderr, "%s decodes\n", entry.name);
|
||||
++failures;
|
||||
} catch (const std::invalid_argument&) {
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s: %s\n", entry.name, error.what());
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
#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 = 16;
|
||||
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, 40> Code{
|
||||
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x36100e81, 0x7d8a1080, 0xd56f000a,
|
||||
0x0c1a0b04, 0xd56f000b, 0x5c1a0905, 0xd55f000c, 0x141a0b04, 0xd55f020d, 0x3c1a0b04, 0xd56d8c0e,
|
||||
0x041a0b04, 0xd56d0c0f, 0x0c1a0b04, 0xd56d0c10, 0x1c1a0b06, 0xd56d8c11, 0x141a0b06, 0xd56e8c12,
|
||||
0x04120d04, 0xd56e0c14, 0x0c120d06, 0xd56e0c16, 0x1c120d04, 0xd56e8c18, 0x14120d06, 0xe0781000,
|
||||
0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, 0x80011603, 0xbf810000,
|
||||
};
|
||||
|
||||
constexpr std::uint32_t Rows[32][4] = {
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x00000000u, 0x00800000u, 0x3ec00000u, 0x9ffbf25eu},
|
||||
{0x00800000u, 0x40000000u, 0xb2400000u, 0x6eb48efcu},
|
||||
{0x20000000u, 0xe4380000u, 0xabbe954cu, 0xd080849du},
|
||||
{0x3f800000u, 0x80800000u, 0x64280000u, 0x013367a7u},
|
||||
{0x7f800000u, 0x3f400000u, 0xff800000u, 0xefc44097u},
|
||||
{0xbf400000u, 0xc0780000u, 0x3f800000u, 0xe44de90bu},
|
||||
{0xbf800000u, 0x20000000u, 0x7f800000u, 0x13eab756u},
|
||||
{0xc0200000u, 0x40400000u, 0xbf800000u, 0xe2d60270u},
|
||||
{0x80000000u, 0xff7fffffu, 0x00a80000u, 0xab35a9b1u},
|
||||
{0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u},
|
||||
{0xe57ddac0u, 0x40900000u, 0x00800000u, 0xf93e81a9u},
|
||||
{0x3f000000u, 0x3f400000u, 0x40000000u, 0xf16dbe02u},
|
||||
{0x00000000u, 0x3ff00000u, 0x00000000u, 0x3ff00000u},
|
||||
{0x00000000u, 0xbff00000u, 0x00000000u, 0xbff00000u},
|
||||
{0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u},
|
||||
{0x3f400000u, 0x5f800000u, 0xc0000000u, 0x9c6e0e69u},
|
||||
{0x7f300000u, 0x20000000u, 0x3f300000u, 0xb96bd6afu},
|
||||
{0x80800000u, 0x3f800000u, 0x3f800000u, 0xa545f3c8u},
|
||||
{0xbf800000u, 0x80800000u, 0xbf800000u, 0x215c2862u},
|
||||
{0xff200000u, 0x7f800000u, 0x80800000u, 0xd46cde99u},
|
||||
{0x40000000u, 0x32200000u, 0xff7fffffu, 0x198be250u},
|
||||
{0x40000000u, 0x5f000000u, 0x3f7fffffu, 0x6616ec89u},
|
||||
{0x1f800000u, 0x40680000u, 0xff800000u, 0xfde11576u},
|
||||
{0x3f7fffffu, 0xffc00000u, 0x3ff00000u, 0x03998b2fu},
|
||||
{0x7f7fffffu, 0x62f2a21bu, 0xbfe80000u, 0x7e544d56u},
|
||||
{0x80000000u, 0x36f675ccu, 0x80800000u, 0x6b0d549bu},
|
||||
{0xbff00000u, 0x40000000u, 0x7f7fffffu, 0x1ef68f28u},
|
||||
{0x00000000u, 0x1e200000u, 0x3f000000u, 0xea5b840eu},
|
||||
{0x00000000u, 0x1f800000u, 0x00800000u, 0x729eabeeu},
|
||||
{0x00000000u, 0x3f400000u, 0x80000000u, 0xa8333fe6u},
|
||||
{0x00000000u, 0x46180000u, 0x80800000u, 0x146bbdacu}
|
||||
};
|
||||
constexpr std::uint32_t Expected[32][16] = {
|
||||
{0x00000000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u},
|
||||
{0x3f400000u, 0x3e400000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x3e400000u, 0x3f800000u, 0x00000000u, 0x08800000u, 0x3ec00000u, 0xa7fbf25eu, 0x00000000u, 0x08800000u, 0x00000000u, 0x00000000u},
|
||||
{0xb2c00000u, 0xb1c00000u, 0x81800000u, 0x80000000u, 0x00800000u, 0x01000000u, 0xb1c00000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xb2400000u, 0x6eb48efcu, 0x00800000u, 0x40000000u, 0x00000000u, 0x3ff00000u},
|
||||
{0xa5380000u, 0x24380000u, 0x21000000u, 0x9f800000u, 0x3f800000u, 0x40800000u, 0xcb3e954cu, 0x00000000u, 0x00000000u, 0x00000000u, 0xabbe954cu, 0xd080849du, 0x20000000u, 0xe4380000u, 0x00000000u, 0x00000000u},
|
||||
{0x7f800000u, 0x7f800000u, 0xc0800000u, 0x3f000000u, 0x3f800000u, 0x40000000u, 0x63a80000u, 0x3f800000u, 0x00000000u, 0x00000000u, 0x64280000u, 0x093367a7u, 0x3f800000u, 0x88800000u, 0x64280000u, 0x093367a7u},
|
||||
{0xffc00000u, 0xff800000u, 0xff800000u, 0xff800000u, 0x3f800000u, 0x7f800000u, 0xff800000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xff800000u, 0xefc44097u, 0x7f800000u, 0x47400000u, 0x00000000u, 0x00000000u},
|
||||
{0x20fa0000u, 0x9f740000u, 0xc0400000u, 0x3ec00000u, 0x00000000u, 0xbfc00000u, 0x3f000000u, 0x3f800000u, 0x00000000u, 0x00000000u, 0x3f800000u, 0xe44de90bu, 0xbf400000u, 0xc0780000u, 0x00000000u, 0x00000000u},
|
||||
{0x7f800000u, 0x7f800000u, 0x7f800000u, 0x7f800000u, 0x00000000u, 0xc0000000u, 0x7f800000u, 0x3f800000u, 0xbf800000u, 0x20000000u, 0x7f800000u, 0x13eab756u, 0xbf800000u, 0x20000000u, 0x7f800000u, 0x13eab756u},
|
||||
{0xc1880000u, 0x40500000u, 0xc1200000u, 0xbfa00000u, 0x00000000u, 0xc0a00000u, 0xbf000000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xbf800000u, 0xe2d60270u, 0xc0200000u, 0x40400000u, 0x00000000u, 0x00000000u},
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x01a80000u, 0x00000000u, 0x00000000u, 0x00a80000u, 0xb335a9b1u, 0x80000000u, 0xff7fffffu, 0x00000000u, 0x00000000u},
|
||||
{0x7ff00000u, 0x7ff00000u, 0x7ff00000u, 0x7ff00000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x3ff00000u},
|
||||
{0xc70ecb0cu, 0x460ecb0cu, 0x667ddac0u, 0x64fddac0u, 0x00000000u, 0xff800000u, 0x20000000u, 0x21800000u, 0x00000000u, 0x3ff00000u, 0x00800000u, 0xf93e81a9u, 0xe57ddac0u, 0x48900000u, 0x00000000u, 0x00000000u},
|
||||
{0x40980000u, 0x3f500000u, 0x40000000u, 0x3e800000u, 0x3f000000u, 0x3f800000u, 0x3f800000u, 0x3f800000u, 0x00000000u, 0x3ff00000u, 0x40000000u, 0xf16dbe02u, 0x3f000000u, 0x47400000u, 0x00000000u, 0x00000000u},
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x3ff00000u},
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbff00000u, 0x00000000u, 0xbff00000u, 0x00000000u, 0x00000000u},
|
||||
{0xfff00000u, 0xfff00000u, 0xfff00000u, 0x7ff00000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u},
|
||||
{0x7f800000u, 0xfec00000u, 0xc0400000u, 0xbec00000u, 0x3f400000u, 0x3fc00000u, 0xbf800000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xc0000000u, 0xa46e0e69u, 0x3f400000u, 0x5f800000u, 0x00000000u, 0x00000000u},
|
||||
{0x40300000u, 0xbf300000u, 0x7f800000u, 0x7eb00000u, 0x3f800000u, 0x7f800000u, 0x3eb00000u, 0x3f800000u, 0x7f300000u, 0x20000000u, 0x3f300000u, 0xb96bd6afu, 0x7f300000u, 0x20000000u, 0x00000000u, 0x00000000u},
|
||||
{0x40000000u, 0x3f000000u, 0x01800000u, 0x00000000u, 0x00000000u, 0x81000000u, 0x3f000000u, 0x3f800000u, 0x80800000u, 0x3f800000u, 0x3f800000u, 0xa545f3c8u, 0x80800000u, 0x3f800000u, 0x00000000u, 0x00000000u},
|
||||
{0xc0000000u, 0xbf000000u, 0x40800000u, 0xbf000000u, 0x00000000u, 0xc0000000u, 0xbf000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbf800000u, 0x295c2862u, 0xbf800000u, 0x88800000u, 0xbf800000u, 0x295c2862u},
|
||||
{0xff800000u, 0x7f800000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xff800000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0x80800000u, 0xd46cde99u, 0xff200000u, 0x7f800000u, 0x00000000u, 0x00000000u},
|
||||
{0xff800000u, 0xfeffffffu, 0xc1000000u, 0xbf800000u, 0x3f800000u, 0x40800000u, 0xfeffffffu, 0x00000000u, 0x40000000u, 0x32200000u, 0xff7fffffu, 0x198be250u, 0x40000000u, 0x32200000u, 0xff7fffffu, 0x198be250u},
|
||||
{0x40000000u, 0xbf000000u, 0x41000000u, 0x3f800000u, 0x3f800000u, 0x40800000u, 0x3effffffu, 0x3f800000u, 0x00000000u, 0x3ff00000u, 0x3f7fffffu, 0x6616ec89u, 0x40000000u, 0x5f000000u, 0x00000000u, 0x3ff00000u},
|
||||
{0xff800000u, 0xff800000u, 0xff800000u, 0xff800000u, 0x1f800000u, 0x20000000u, 0xff800000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xff800000u, 0xfde11576u, 0x1f800000u, 0x48680000u, 0x00000000u, 0x00000000u},
|
||||
{0xffc00000u, 0xffc00000u, 0xffc00000u, 0x7fc00000u, 0x3f7fffffu, 0x3fffffffu, 0x3f700000u, 0x3f800000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0x0b998b2fu, 0x3f7fffffu, 0xffc00000u, 0x3ff00000u, 0x0b998b2fu},
|
||||
{0x7f800000u, 0xff800000u, 0xff800000u, 0xfeffffffu, 0x3f800000u, 0x7f800000u, 0xbf680000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0xbfe80000u, 0x7e544d56u, 0x7f7fffffu, 0x62f2a21bu, 0x00000000u, 0x3ff00000u},
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xa0000000u, 0x00000000u, 0x80000000u, 0x3ef675ccu, 0x80800000u, 0x6b0d549bu, 0x80000000u, 0x3ef675ccu, 0x00000000u, 0x3ff00000u},
|
||||
{0x7f800000u, 0x7effffffu, 0x40f00000u, 0x3f700000u, 0x00000000u, 0xc0700000u, 0x7effffffu, 0x3f800000u, 0x00000000u, 0x3ff00000u, 0x7f7fffffu, 0x1ef68f28u, 0xbff00000u, 0x40000000u, 0x7f7fffffu, 0x1ef68f28u},
|
||||
{0x3f800000u, 0x3e800000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x3e800000u, 0x3f800000u, 0x00000000u, 0x26200000u, 0x3f000000u, 0xea5b840eu, 0x00000000u, 0x26200000u, 0x00000000u, 0x00000000u},
|
||||
{0x01000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x20000000u, 0x21800000u, 0x00000000u, 0x27800000u, 0x00800000u, 0x729eabeeu, 0x00000000u, 0x27800000u, 0x00000000u, 0x3ff00000u},
|
||||
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffc00000u, 0xffc00000u, 0x00000000u, 0x00000000u, 0x3f400000u, 0x80000000u, 0xa8333fe6u, 0x00000000u, 0x3f400000u, 0x00000000u, 0x00000000u},
|
||||
{0x81000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xa0000000u, 0x00000000u, 0x00000000u, 0x3ff00000u, 0x80800000u, 0x1c6bbdacu, 0x00000000u, 0x46180000u, 0x80800000u, 0x1c6bbdacu}
|
||||
};
|
||||
constexpr std::uint32_t Checked[32] = {0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xfffcu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu, 0xffffu};
|
||||
constexpr const char* Names[16] = {
|
||||
"v_div_fmas_f32 v10, v4, v5, v6 mul:2",
|
||||
"v_div_fmas_f32 v11, v5, -v4, v6 div:2",
|
||||
"v_div_fixup_f32 v12, v4, v5, v6 mul:4",
|
||||
"v_div_fixup_f32 v13, -v4, |v5|, v6 div:2",
|
||||
"v_div_scale_f32 v14, s12, v4, v5, v6 clamp",
|
||||
"v_div_scale_f32 v15, s12, v4, v5, v6 mul:2",
|
||||
"v_div_scale_f32 v16, s12, v6, v5, v6 div:2",
|
||||
"v_div_scale_f32 v17, s12, v6, v5, v6 clamp mul:4",
|
||||
"v_div_scale_f64 v[18:19], s12, v[4:5], v[6:7], v[4:5] clamp lo",
|
||||
"v_div_scale_f64 v[18:19], s12, v[4:5], v[6:7], v[4:5] clamp hi",
|
||||
"v_div_scale_f64 v[20:21], s12, v[6:7], v[6:7], v[4:5] mul:2 lo",
|
||||
"v_div_scale_f64 v[20:21], s12, v[6:7], v[6:7], v[4:5] mul:2 hi",
|
||||
"v_div_scale_f64 v[22:23], s12, v[4:5], v[6:7], v[4:5] div:2 lo",
|
||||
"v_div_scale_f64 v[22:23], s12, v[4:5], v[6:7], v[4:5] div:2 hi",
|
||||
"v_div_scale_f64 v[24:25], s12, v[6:7], v[6:7], v[4:5] clamp mul:4 lo",
|
||||
"v_div_scale_f64 v[24:25], s12, v[6:7], v[6:7], v[4:5] clamp mul:4 hi",
|
||||
};
|
||||
|
||||
void Fill(std::uint32_t tid, std::uint32_t* words) {
|
||||
std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words);
|
||||
}
|
||||
|
||||
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("division output modifiers: 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}, 0u, {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];
|
||||
for (std::uint32_t i = 0; i < 16; ++i) {
|
||||
if ((Checked[tid] >> i) & 1u) Expect(tid, out[i], Expected[tid][i], Names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
std::puts("division output modifiers tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -165,19 +165,6 @@ void Run(AgcDriver::VulkanDevice& device) {
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void CheckF32OmodRefused(AgcDriver::VulkanDevice& device) {
|
||||
for (const std::uint32_t opcode : {0x15fu, 0x16fu}) {
|
||||
alignas(256) const std::array<std::uint32_t, 3> code{0xd400000au | (opcode << 16u), 0x0c1a0b04u, 0xbf810000u};
|
||||
std::string refusal;
|
||||
try {
|
||||
static_cast<void>(Compile(device, code));
|
||||
} catch (const std::exception& error) {
|
||||
refusal = error.what();
|
||||
}
|
||||
Require(refusal.find("VOP3 source modifiers are not implemented") != std::string::npos, "VOP3 opcode " + Hex(opcode) + " with omod was not refused");
|
||||
}
|
||||
}
|
||||
|
||||
void Check() {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
const std::uint32_t* in = &Input[tid * Inputs];
|
||||
@@ -196,7 +183,6 @@ int main() {
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
CheckF32OmodRefused(*device);
|
||||
std::puts("division result modifiers tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
#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 = 16;
|
||||
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, 62> Code{
|
||||
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x7e140280, 0x7e160280, 0x7e180280,
|
||||
0x7e1a0280, 0x7e1c0280, 0x7e1e0280, 0x7e200280, 0x7e220280, 0x7e240280, 0x7e260280, 0x7e280280,
|
||||
0x7e2a0280, 0x7e2c0280, 0x7e2e0280, 0x7e300280, 0x7e320280, 0xd532800a, 0x02020b04, 0xd532000b,
|
||||
0x0a020b04, 0xd533800c, 0x02020b04, 0xd534800d, 0x1a020b04, 0xd535800e, 0x02020b04, 0xd53a800f,
|
||||
0x02020b04, 0xd5390010, 0x12020b04, 0xd53b8011, 0x02020b04, 0xd53b0012, 0x0a020b04, 0xd5d98013,
|
||||
0x02010104, 0xd5e38014, 0x02010104, 0xd5e40015, 0x0a010104, 0xd7540016, 0x0c1a0b04, 0xd7578017,
|
||||
0x141a0b04, 0xd7510018, 0x1c1a0b04, 0xd74b0019, 0x0c1a0b04, 0xe0781000, 0x80010a03, 0xe0781010,
|
||||
0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, 0x80011603, 0xbf810000,
|
||||
};
|
||||
|
||||
constexpr std::uint32_t Rows[32][4] = {
|
||||
{0x00000000u, 0x0000ec99u, 0x000073abu, 0x0000965eu},
|
||||
{0x0000c000u, 0x000079cbu, 0x0000cb00u, 0x00004400u},
|
||||
{0x000003ffu, 0x0000b555u, 0x0000e3efu, 0x00000ab8u},
|
||||
{0x0000656au, 0x0000a767u, 0x0000a66bu, 0x0000b800u},
|
||||
{0x00003e00u, 0x00000f3eu, 0x0000c000u, 0x00009980u},
|
||||
{0x00003800u, 0x0000fc00u, 0x000003ffu, 0x000084e5u},
|
||||
{0x0000fe00u, 0x00007bffu, 0x00003c01u, 0x00001400u},
|
||||
{0x00006822u, 0x0000fee5u, 0x0000154cu, 0x000050b6u},
|
||||
{0x0000834cu, 0x00004900u, 0x00003800u, 0x00006680u},
|
||||
{0x00008000u, 0x00004000u, 0x0000fe00u, 0x00007bffu},
|
||||
{0x000036a8u, 0x00008001u, 0x00007851u, 0x00000200u},
|
||||
{0x00006b77u, 0x00003bffu, 0x0000c74cu, 0x0000563eu},
|
||||
{0x00004400u, 0x00000002u, 0x0000c20eu, 0x00002274u},
|
||||
{0x0000c200u, 0x0000bc00u, 0x00007c00u, 0x00002d7cu},
|
||||
{0x0000303au, 0x00007e00u, 0x00000400u, 0x00002187u},
|
||||
{0x00000001u, 0x0000fbffu, 0x00004400u, 0x0000001eu},
|
||||
{0x0000b555u, 0x0000cdacu, 0x0000ff76u, 0x000035f1u},
|
||||
{0x00001400u, 0x00009a1du, 0x000019afu, 0x00007e00u},
|
||||
{0x00003c00u, 0x0000c000u, 0x00000001u, 0x0000d48du},
|
||||
{0x0000fc00u, 0x000003ffu, 0x0000b555u, 0x00003e36u},
|
||||
{0x00007bffu, 0x00003c01u, 0x00002091u, 0x00007bd5u},
|
||||
{0x000022bfu, 0x00002ecdu, 0x00004f91u, 0x0000d15bu},
|
||||
{0x0000b9b3u, 0x00003800u, 0x0000f0beu, 0x0000afddu},
|
||||
{0x0000e1d7u, 0x0000fe00u, 0x00007bffu, 0x00003c01u},
|
||||
{0x00008001u, 0x00004153u, 0x00000200u, 0x000041c9u},
|
||||
{0x00003bffu, 0x00007fb2u, 0x00004900u, 0x00003800u},
|
||||
{0x0000119bu, 0x00008000u, 0x00004000u, 0x00009da9u},
|
||||
{0x000047bcu, 0x00007c00u, 0x0000bfbdu, 0x00003555u},
|
||||
{0x00007e00u, 0x00000400u, 0x00003bffu, 0x0000d000u},
|
||||
{0x0000fbffu, 0x000021afu, 0x00000002u, 0x00008000u},
|
||||
{0x00005000u, 0x0000c200u, 0x0000859du, 0x000023edu},
|
||||
{0x0000ec70u, 0x0000b800u, 0x0000b372u, 0x00000400u}
|
||||
};
|
||||
constexpr std::uint32_t Expected[32][16] = {
|
||||
{0x00000000u, 0x0000ec99u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x000073abu, 0x00000000u, 0x0000ec99u, 0x000073abu},
|
||||
{0x00003c00u, 0x000079cbu, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x000079cbu, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x00008001u, 0x00000000u, 0x000079cbu, 0x00000000u, 0x0000cb00u, 0x0000fc00u},
|
||||
{0x00000000u, 0x0000b555u, 0x00003555u, 0x00000000u, 0x00000000u, 0x00000000u, 0x000003ffu, 0x00000000u, 0x00000000u, 0x00003bfeu, 0x00000002u, 0x00000004u, 0x000003ffu, 0x00000000u, 0x0000e3efu, 0x0000e3efu},
|
||||
{0x00003c00u, 0x0000656au, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000656au, 0x00000000u, 0x00000000u, 0x0000396au, 0x00007fffu, 0x0000ffffu, 0x0000656au, 0x00000000u, 0x0000a767u, 0x0000d103u},
|
||||
{0x00003c00u, 0x00003e00u, 0x00003c00u, 0x00000000u, 0x0000116eu, 0x00000f3eu, 0x00003e00u, 0x00003c00u, 0x00007c00u, 0x00003a00u, 0x00007fffu, 0x0000ffffu, 0x00003e00u, 0x00000f3eu, 0x0000c000u, 0x0000bfffu},
|
||||
{0x00000000u, 0x0000fc00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00004000u, 0x00008000u, 0x00003800u, 0x000003ffu, 0x0000fc00u, 0x0000fc00u},
|
||||
{0x00000000u, 0x0000fe00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003c00u, 0x00007bffu, 0x00000000u, 0x0000fe00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00007bffu, 0x00003c00u, 0x00003c01u, 0x0000fe00u},
|
||||
{0x00000000u, 0x0000fee5u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003c00u, 0x00006822u, 0x00000000u, 0x00000000u, 0x00003822u, 0x00007fffu, 0x0000ffffu, 0x00006822u, 0x0000154cu, 0x0000154cu, 0x0000fee5u},
|
||||
{0x00003c00u, 0x00004900u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00004900u, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x0000fffeu, 0x00000000u, 0x00004900u, 0x00003800u, 0x0000834cu, 0x000037feu},
|
||||
{0x00003c00u, 0x00004000u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00004000u, 0x00000000u, 0x00008000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00004000u, 0x00000000u, 0x00008000u, 0x0000fe00u},
|
||||
{0x000036a8u, 0x000036a8u, 0x000036a8u, 0x00000000u, 0x00000000u, 0x00000000u, 0x000036a8u, 0x00000000u, 0x00000000u, 0x00003aa8u, 0x00003540u, 0x00006a80u, 0x00007851u, 0x000036a8u, 0x00008001u, 0x00007851u},
|
||||
{0x00003c00u, 0x00006b77u, 0x00003c00u, 0x00000000u, 0x00003c00u, 0x00003bffu, 0x00006b77u, 0x00003c00u, 0x00007c00u, 0x00003b77u, 0x00007fffu, 0x0000ffffu, 0x00006b77u, 0x00003bffu, 0x0000c74cu, 0x00006b72u},
|
||||
{0x00003c00u, 0x00004400u, 0x00003c00u, 0x00000000u, 0x00000008u, 0x00000002u, 0x00004400u, 0x00003c00u, 0x00004c00u, 0x00003800u, 0x00007fffu, 0x0000ffffu, 0x00004400u, 0x00000002u, 0x0000c20eu, 0x0000c20eu},
|
||||
{0x00000000u, 0x0000c400u, 0x00000000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x0000bc00u, 0x00000000u, 0x00008000u, 0x00000000u, 0x00008001u, 0x00000000u, 0x00007c00u, 0x00000000u, 0x0000c200u, 0x00007c00u},
|
||||
{0x00000000u, 0x00007e00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000303au, 0x0000303au, 0x00003c00u, 0x00007c00u, 0x0000383au, 0x000010e8u, 0x000021d0u, 0x0000303au, 0x00000400u, 0x00000400u, 0x00007e00u},
|
||||
{0x00000000u, 0x0000fbffu, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00000000u, 0x00000000u, 0x00004400u, 0x00000001u, 0x0000fbffu, 0x000043feu},
|
||||
{0x00000000u, 0x0000cdc1u, 0x00003c00u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x0000b555u, 0x00000000u, 0x00008000u, 0x00000000u, 0x0000d558u, 0x00000000u, 0x0000b555u, 0x00000000u, 0x0000cdacu, 0x0000ff76u},
|
||||
{0x00000000u, 0x0000981du, 0x00001c0eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00001400u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00000020u, 0x00000040u, 0x000019afu, 0x00001400u, 0x00009a1du, 0x000019adu},
|
||||
{0x00000000u, 0x0000bc00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00007fffu, 0x0000ffffu, 0x00003c00u, 0x00000001u, 0x0000c000u, 0x0000c000u},
|
||||
{0x00000000u, 0x0000fc00u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x000003ffu, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x00008001u, 0x00000000u, 0x000003ffu, 0x00000000u, 0x0000fc00u, 0x0000fc00u},
|
||||
{0x00003c00u, 0x00007bffu, 0x00003c00u, 0x00000000u, 0x00003c00u, 0x00003c00u, 0x00007bffu, 0x00003c00u, 0x00007c00u, 0x00003bffu, 0x00007fffu, 0x0000ffffu, 0x00007bffu, 0x00003c00u, 0x00002091u, 0x00007c00u},
|
||||
{0x00002fa5u, 0x00002fa5u, 0x00000000u, 0x00002df5u, 0x000015bcu, 0x000022bfu, 0x00002ecdu, 0x00003c00u, 0x00007c00u, 0x00003abfu, 0x000001b0u, 0x0000035fu, 0x00004f91u, 0x00002ecdu, 0x000022bfu, 0x00004f91u},
|
||||
{0x00000000u, 0x0000b2ccu, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x0000a4d1u, 0x00000000u, 0x00003800u, 0x00000000u, 0x0000f0beu, 0x0000f0beu},
|
||||
{0x00000000u, 0x0000fe00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000e1d7u, 0x00000000u, 0x00008000u, 0x00000000u, 0x00008001u, 0x00000000u, 0x00007bffu, 0x00000000u, 0x0000e1d7u, 0x0000fe00u},
|
||||
{0x00003c00u, 0x00004153u, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00004153u, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00004153u, 0x00000200u, 0x00008001u, 0x000001fdu},
|
||||
{0x00000000u, 0x00007fb2u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003bffu, 0x00003bffu, 0x00003c00u, 0x00007c00u, 0x00003bffu, 0x00007fefu, 0x0000ffdfu, 0x00004900u, 0x00003bffu, 0x00003bffu, 0x00007fb2u},
|
||||
{0x0000119bu, 0x0000119bu, 0x0000119bu, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000119bu, 0x00000000u, 0x00000000u, 0x0000399bu, 0x00000016u, 0x0000002du, 0x00004000u, 0x0000119bu, 0x00008000u, 0x00004000u},
|
||||
{0x00003c00u, 0x00007c00u, 0x00000000u, 0x00003c00u, 0x00003c00u, 0x00003c00u, 0x00007c00u, 0x00003c00u, 0x00007c00u, 0x00003bbcu, 0x00007fffu, 0x0000ffffu, 0x00007c00u, 0x00003c00u, 0x0000bfbdu, 0x00007c00u},
|
||||
{0x00000000u, 0x00007e00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000400u, 0x00000400u, 0x00000000u, 0x00007e00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00003bffu, 0x00000400u, 0x00000400u, 0x00007e00u},
|
||||
{0x00000000u, 0x0000fbffu, 0x00000000u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x000021afu, 0x00000000u, 0x0000fc00u, 0x00000000u, 0x00008001u, 0x00000000u, 0x000021afu, 0x00000002u, 0x0000fbffu, 0x0000e1aeu},
|
||||
{0x00003c00u, 0x00004f40u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00005000u, 0x00000000u, 0x00000000u, 0x00003800u, 0x00007fffu, 0x0000ffffu, 0x00005000u, 0x00000000u, 0x0000c200u, 0x0000d600u},
|
||||
{0x00000000u, 0x0000ec70u, 0x00000000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x0000b800u, 0x00000000u, 0x00008000u, 0x00000000u, 0x00008001u, 0x00000000u, 0x0000b372u, 0x00000000u, 0x0000ec70u, 0x00006870u}
|
||||
};
|
||||
constexpr const char* Names[16] = {
|
||||
"v_add_f16 clamp",
|
||||
"v_add_f16 mul:2",
|
||||
"v_sub_f16 clamp",
|
||||
"v_subrev_f16 clamp div:2",
|
||||
"v_mul_f16 clamp",
|
||||
"v_min_f16 clamp",
|
||||
"v_max_f16 mul:4",
|
||||
"v_ldexp_f16 clamp",
|
||||
"v_ldexp_f16 mul:2",
|
||||
"v_frexp_mant_f16 clamp",
|
||||
"v_cvt_norm_i16_f16 clamp",
|
||||
"v_cvt_norm_u16_f16 mul:2",
|
||||
"v_max3_f16 mul:2",
|
||||
"v_med3_f16 clamp mul:4",
|
||||
"v_min3_f16 div:2",
|
||||
"v_fma_f16 mul:2"
|
||||
};
|
||||
|
||||
void Fill(std::uint32_t tid, std::uint32_t* words) {
|
||||
std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words);
|
||||
}
|
||||
|
||||
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("float16 modifiers: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected));
|
||||
}
|
||||
|
||||
bool IsNan(std::uint32_t half) {
|
||||
return (half & 0x7fffu) > 0x7c00u;
|
||||
}
|
||||
|
||||
void ExpectHalf(std::uint32_t tid, std::uint32_t actual, std::uint32_t expected, const char* name) {
|
||||
actual &= 0xffffu;
|
||||
if (IsNan(expected) && IsNan(actual)) return;
|
||||
Expect(tid, actual, expected, name);
|
||||
}
|
||||
|
||||
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}, 0u, {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];
|
||||
for (std::uint32_t i = 0; i < 16; ++i) ExpectHalf(tid, out[i], Expected[tid][i], Names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
std::puts("float16 modifiers tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
#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 = 16;
|
||||
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, 39> Code{
|
||||
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x7e1c0307, 0x7e200307, 0x7e220307,
|
||||
0x7e140307, 0x7e160307, 0x7e180307, 0x7e1a0307, 0x7e1e0307, 0x7e240307, 0xd754800a, 0x041a0b04,
|
||||
0xd751800b, 0x041a0b04, 0xd757800c, 0x041a0b04, 0xd75f800d, 0x041a0b04, 0xd754fa0e, 0x24120d05,
|
||||
0xd751a80f, 0x44160906, 0xd757f410, 0x84120d05, 0xd75fd811, 0x04160906, 0xd75fa212, 0xa4120d05,
|
||||
0xe0781000, 0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, 0x80011203, 0xbf810000,
|
||||
};
|
||||
|
||||
constexpr std::uint32_t Rows[32][4] = {
|
||||
{0x00000400u, 0x3bffb4a2u, 0x7bff7bffu, 0xfd976299u},
|
||||
{0x0001755du, 0x00007c00u, 0x07b7be05u, 0x32b8562au},
|
||||
{0x00017d23u, 0x42007c01u, 0x3c00fc01u, 0xfb47feb7u},
|
||||
{0xbfa8fd5au, 0x00008000u, 0x7d232fe0u, 0x6a55b5f1u},
|
||||
{0x1000d324u, 0xfc00f936u, 0xa88cfc00u, 0x455742adu},
|
||||
{0x87bb3c00u, 0x7c012000u, 0x00000000u, 0x517cded7u},
|
||||
{0xc2d6b555u, 0x2a2fbc00u, 0x3c00fae5u, 0x3726d2dfu},
|
||||
{0x000103ffu, 0x3555b555u, 0x3c14bc00u, 0xf06fead4u},
|
||||
{0x2000fc01u, 0x79817bffu, 0x7bff8001u, 0xe6607650u},
|
||||
{0x84003c00u, 0x5daf6841u, 0x3c00064eu, 0x3d4d4112u},
|
||||
{0x7e00fc00u, 0x7c007e00u, 0x7e00fc00u, 0x90b35b97u},
|
||||
{0x081d4286u, 0xbd763c00u, 0x84004200u, 0x510fb8c3u},
|
||||
{0x8a2b0000u, 0x05170400u, 0x03ffc7e5u, 0x6e83a7f0u},
|
||||
{0xc0007e00u, 0x7d237e00u, 0x7c017c00u, 0x45c0f96bu},
|
||||
{0xb95a7bffu, 0x007d8001u, 0x7c010ccbu, 0xb9c23f62u},
|
||||
{0x00017e00u, 0x1f9d8001u, 0x417698d1u, 0xe7b478feu},
|
||||
{0x048f7edbu, 0x5e8a4fd9u, 0x81b2fe00u, 0x9f542371u},
|
||||
{0x7c00c000u, 0xbc00fc00u, 0x3c000000u, 0x9004ee95u},
|
||||
{0x7e00f5ddu, 0x7e008000u, 0xfc01bc00u, 0x8fd0b012u},
|
||||
{0xb5558284u, 0x1000d1adu, 0xfe003460u, 0x76315f60u},
|
||||
{0x00003c00u, 0xc0008400u, 0x040039f3u, 0x9266fdd2u},
|
||||
{0x0000bc00u, 0x064de034u, 0x74c2fc01u, 0xcbe5dec7u},
|
||||
{0x3c01b555u, 0x42007c00u, 0x7c003555u, 0x36190caau},
|
||||
{0xc000fbffu, 0x3c004200u, 0x7d23c000u, 0xb63ec222u},
|
||||
{0x000000a1u, 0xf41e891eu, 0xbfb23436u, 0x35b2cc39u},
|
||||
{0x0000018fu, 0xb555844du, 0xcaf50000u, 0x1f46ce67u},
|
||||
{0x0000027cu, 0x7e00932bu, 0x35557c01u, 0xeedc6a0cu},
|
||||
{0x000003ffu, 0x0bc83555u, 0x076a4000u, 0x6dde7f88u},
|
||||
{0x000003ffu, 0x7bff2000u, 0xde652493u, 0xc36c95c2u},
|
||||
{0x000003ffu, 0xfbfffc01u, 0x40007d23u, 0x85da3cafu},
|
||||
{0x00000400u, 0x7789e844u, 0x80000001u, 0xa570949du},
|
||||
{0x0000053du, 0x12482000u, 0x8d328bb0u, 0x80525003u}
|
||||
};
|
||||
constexpr std::uint32_t Expected[32][12] = {
|
||||
{0xfd973c00u, 0xfd970000u, 0xfd970400u, 0xfd970000u, 0x3c006299u, 0xfd970000u, 0x00006299u, 0x00006299u, 0xfd970000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x32b83c00u, 0x32b80000u, 0x32b83c00u, 0x32b80000u, 0x07b7562au, 0x32b80000u, 0x07b7562au, 0x3c00562au, 0x32b80000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xfb470000u, 0xfb470000u, 0xfb470000u, 0xfb470000u, 0x3c00feb7u, 0xfb473c00u, 0x0000feb7u, 0x0000feb7u, 0xfb470000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x6a552fe0u, 0x6a550000u, 0x6a550000u, 0x6a550000u, 0x0000b5f1u, 0x6a550000u, 0x0000b5f1u, 0x0000b5f1u, 0x6a550000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x45570000u, 0x45570000u, 0x45570000u, 0x45573c00u, 0x3c0042adu, 0x45570000u, 0x000042adu, 0x000042adu, 0x45570000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x517c3c00u, 0x517c0000u, 0x517c2000u, 0x517c0000u, 0x0000ded7u, 0x517c0000u, 0x0000ded7u, 0x0000ded7u, 0x517c3c00u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x37260000u, 0x37260000u, 0x37260000u, 0x37263555u, 0x3c00d2dfu, 0x37262a2fu, 0x0000d2dfu, 0x3c00d2dfu, 0x37263c00u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xf06f03ffu, 0xf06f0000u, 0xf06f0000u, 0xf06f03ffu, 0x3c00ead4u, 0xf06f0000u, 0x0000ead4u, 0x0000ead4u, 0xf06f0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xe6603c00u, 0xe6600000u, 0xe6600000u, 0xe6600000u, 0x3c007650u, 0xe6603c00u, 0x3c007650u, 0x3c007650u, 0xe6600000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x3d4d3c00u, 0x3d4d064eu, 0x3d4d3c00u, 0x3d4d3c00u, 0x3c004112u, 0x3d4d0000u, 0x3c004112u, 0x00004112u, 0x3d4d3c00u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x90b30000u, 0x90b30000u, 0x90b30000u, 0x90b30000u, 0x00005b97u, 0x90b33c00u, 0x00005b97u, 0x00005b97u, 0x90b30000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x510f3c00u, 0x510f3c00u, 0x510f3c00u, 0x510f3c00u, 0x3c00b8c3u, 0x510f0000u, 0x0000b8c3u, 0x0400b8c3u, 0x510f0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x6e830400u, 0x6e830000u, 0x6e830000u, 0x6e830000u, 0x03ffa7f0u, 0x6e830000u, 0x03ffa7f0u, 0x0000a7f0u, 0x6e830400u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x45c03c00u, 0x45c03c00u, 0x45c03c00u, 0x45c00000u, 0x0000f96bu, 0x45c00000u, 0x0000f96bu, 0x0000f96bu, 0x45c00000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xb9c23c00u, 0xb9c20000u, 0xb9c20ccbu, 0xb9c20000u, 0x00003f62u, 0xb9c20000u, 0x00003f62u, 0x3c003f62u, 0xb9c20001u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xe7b40000u, 0xe7b40000u, 0xe7b40000u, 0xe7b43c00u, 0x3c0078feu, 0xe7b41f9du, 0x000078feu, 0x000078feu, 0xe7b40000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x9f543c00u, 0x9f543c00u, 0x9f543c00u, 0x9f540000u, 0x048f2371u, 0x9f540000u, 0x00002371u, 0x01b22371u, 0x9f540000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x90040000u, 0x90040000u, 0x90040000u, 0x90040000u, 0x3c00ee95u, 0x90040000u, 0x0000ee95u, 0x0000ee95u, 0x90040000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x8fd00000u, 0x8fd00000u, 0x8fd00000u, 0x8fd03c00u, 0x0000b012u, 0x8fd03c00u, 0x0000b012u, 0x0000b012u, 0x8fd00000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x76313460u, 0x76310000u, 0x76310000u, 0x76310000u, 0x00005f60u, 0x76310284u, 0x00005f60u, 0x3c005f60u, 0x76313c00u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x92663c00u, 0x92660000u, 0x926639f3u, 0x92660000u, 0x3c00fdd2u, 0x92660000u, 0x0000fdd2u, 0x0000fdd2u, 0x92660000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xcbe50000u, 0xcbe50000u, 0xcbe50000u, 0xcbe50000u, 0x3c00dec7u, 0xcbe5064du, 0x0000dec7u, 0x0000dec7u, 0xcbe50000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x36193c00u, 0x36190000u, 0x36193555u, 0x36190000u, 0x3c000caau, 0x36193555u, 0x3c000caau, 0x3c000caau, 0x36190000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xb63e3c00u, 0xb63e0000u, 0xb63e0000u, 0xb63e0000u, 0x0000c222u, 0xb63e3c00u, 0x0000c222u, 0x0000c222u, 0xb63e3c00u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x35b23436u, 0x35b20000u, 0x35b200a1u, 0x35b20000u, 0x3c00cc39u, 0x35b20000u, 0x0000cc39u, 0x0000cc39u, 0x35b20000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x1f46018fu, 0x1f460000u, 0x1f460000u, 0x1f460000u, 0x3c00ce67u, 0x1f460000u, 0x0000ce67u, 0x0000ce67u, 0x1f460000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xeedc027cu, 0xeedc0000u, 0xeedc0000u, 0xeedc0000u, 0x35556a0cu, 0xeedc0000u, 0x00006a0cu, 0x00006a0cu, 0xeedc0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x6dde3c00u, 0x6dde03ffu, 0x6dde3555u, 0x6dde03ffu, 0x076a7f88u, 0x6dde0000u, 0x076a7f88u, 0x3c007f88u, 0x6dde0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xc36c2493u, 0xc36c03ffu, 0xc36c2000u, 0xc36c03ffu, 0x3c0095c2u, 0xc36c0000u, 0x000095c2u, 0x3c0095c2u, 0xc36c0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x85da03ffu, 0x85da03ffu, 0x85da03ffu, 0x85da0000u, 0x3c003cafu, 0x85da0000u, 0x00003cafu, 0x00003cafu, 0x85da0000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0xa5700400u, 0xa5700000u, 0xa5700001u, 0xa5700000u, 0x0000949du, 0xa5700000u, 0x0000949du, 0x0000949du, 0xa5700000u, 0x00000000u, 0x00000000u, 0x00000000u},
|
||||
{0x80522000u, 0x80520000u, 0x8052053du, 0x80520000u, 0x0d325003u, 0x80520000u, 0x00005003u, 0x3c005003u, 0x80520000u, 0x00000000u, 0x00000000u, 0x00000000u}
|
||||
};
|
||||
constexpr std::uint32_t Checked[32] = {0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1feu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1afu, 0x1ffu, 0x17fu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1dfu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1ffu, 0x1fbu, 0x1feu, 0x1feu, 0x1fdu, 0x1fdu, 0x1f8u, 0x1fbu, 0x1ffu};
|
||||
constexpr const char* Names[9] = {
|
||||
"v_max3_f16 v10, v4, v5, v6 clamp",
|
||||
"v_min3_f16 v11, v4, v5, v6 clamp",
|
||||
"v_med3_f16 v12, v4, v5, v6 clamp",
|
||||
"v_div_fixup_f16 v13, v4, v5, v6 clamp",
|
||||
"v_max3_f16 v14, -v5, |v6|, v4 op_sel:[1,1,1,1] clamp",
|
||||
"v_min3_f16 v15, v6, -v4, v5 op_sel:[1,0,1,0] clamp",
|
||||
"v_med3_f16 v16, v5, v6, -|v4| op_sel:[0,1,1,1] clamp",
|
||||
"v_div_fixup_f16 v17, v6, v4, v5 op_sel:[1,1,0,1] clamp",
|
||||
"v_div_fixup_f16 v18, -v5, |v6|, -v4 op_sel:[0,0,1,0] clamp",
|
||||
};
|
||||
|
||||
void Fill(std::uint32_t tid, std::uint32_t* words) {
|
||||
std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words);
|
||||
}
|
||||
|
||||
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("float16 ternary clamp: 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}, 0u, {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];
|
||||
for (std::uint32_t i = 0; i < 9; ++i) {
|
||||
if ((Checked[tid] >> i) & 1u) Expect(tid, out[i], Expected[tid][i], Names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
std::puts("float16 ternary clamp tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
#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 <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
constexpr std::uint32_t Width = 64;
|
||||
constexpr std::uint32_t Height = 32;
|
||||
constexpr std::byte Kept{0x40};
|
||||
alignas(256) std::array<std::byte, Width * Height * 4> Pixels{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 6> VertexCode{
|
||||
0xe0382000, 0x80000005, 0xbf8c3f70, 0xf80008cf, 0x03020100, 0xbf810000,
|
||||
};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 7> MaskedPixelCode{
|
||||
0x7e040f00, 0x36060481, 0x7da40680, 0x7e0e02f2, 0xf800180f, 0x07070707, 0xbf810000,
|
||||
};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 4> FullPixelCode{
|
||||
0x7e0e02f2, 0xf800180f, 0x07070707, 0xbf810000,
|
||||
};
|
||||
|
||||
std::array<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t stride, 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) | (stride << 16u), count, 0x01016facu};
|
||||
}
|
||||
|
||||
constexpr std::array<std::array<float, 4>, 3> Triangle{{
|
||||
{-1.0f, -1.0f, 0.5f, 1.0f}, {3.0f, -1.0f, 0.5f, 1.0f}, {-1.0f, 3.0f, 0.5f, 1.0f}
|
||||
}};
|
||||
|
||||
void Draw(AgcDriver::VulkanDevice& device, std::uint32_t waveSize, std::span<const std::uint32_t> pixelCode) {
|
||||
Pixels.fill(Kept);
|
||||
const auto target = device.Target();
|
||||
|
||||
std::vector<std::uint32_t> vertexUserData(4, 0u);
|
||||
const auto vertexBuffer = BufferDescriptor(Triangle.data(), 16u, static_cast<std::uint32_t>(Triangle.size()));
|
||||
std::copy(vertexBuffer.begin(), vertexBuffer.end(), vertexUserData.begin());
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> vertexMemory{{{reinterpret_cast<std::uintptr_t>(VertexCode.data()), std::as_bytes(std::span(VertexCode))}}};
|
||||
ShaderRecompiler::RecompileRequest vertex{
|
||||
{ShaderStage::Vertex, reinterpret_cast<std::uintptr_t>(VertexCode.data()), VertexCode, 0, {}},
|
||||
{waveSize, 0, vertexUserData, std::nullopt, std::nullopt, ShaderRecompiler::ShaderVertexStageInfo{}, vertexMemory},
|
||||
target,
|
||||
{0, 0, 0, 64}
|
||||
};
|
||||
vertex.useCache = false;
|
||||
const auto vertexResult = ShaderRecompiler::Recompile(vertex);
|
||||
const auto vertexPush = static_cast<std::uint32_t>(vertexResult.pushConstants.size());
|
||||
|
||||
ShaderRecompiler::ShaderPixelStageInfo pixel{};
|
||||
pixel.wave32 = waveSize == 32u;
|
||||
pixel.inputAddr = ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionX) | ShaderRecompiler::PixelInputBit(ShaderRecompiler::PixelInput::PositionY);
|
||||
pixel.posX = true;
|
||||
pixel.posY = true;
|
||||
pixel.targetOutputMode[0] = 9;
|
||||
pixel.targetExportMapping.fill(0xe4u);
|
||||
const std::vector<std::uint32_t> pixelUserData(8, 0u);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> pixelMemory{{{reinterpret_cast<std::uintptr_t>(pixelCode.data()), std::as_bytes(pixelCode)}}};
|
||||
ShaderRecompiler::RecompileRequest fragment{
|
||||
{ShaderStage::Fragment, reinterpret_cast<std::uintptr_t>(pixelCode.data()), pixelCode, 0, {}},
|
||||
{waveSize, 0, pixelUserData, std::nullopt, pixel, std::nullopt, pixelMemory},
|
||||
target,
|
||||
{0, 0, vertexPush, 128 - vertexPush}
|
||||
};
|
||||
fragment.useCache = false;
|
||||
const auto pixelResult = ShaderRecompiler::Recompile(fragment);
|
||||
const std::array<AgcDriver::Graphics::CompiledShader, 2> shaders{{
|
||||
{ShaderStage::Vertex, &vertexResult, 0},
|
||||
{ShaderStage::Fragment, &pixelResult, vertexPush}
|
||||
}};
|
||||
|
||||
AgcDriver::Graphics::State state{};
|
||||
state.stages = {AgcDriver::Graphics::ShaderPath::Vertex, 0u, waveSize, waveSize, std::nullopt, std::nullopt};
|
||||
state.color = {reinterpret_cast<std::uintptr_t>(Pixels.data()), {Width, Height}, VK_FORMAT_R8G8B8A8_UNORM, Pixels.size(), 0xe4u};
|
||||
state.colors = {state.color};
|
||||
state.hasColorTarget = true;
|
||||
state.renderExtent = {Width, Height};
|
||||
state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
state.viewport = {0, static_cast<float>(Height), static_cast<float>(Width), -static_cast<float>(Height), 0, 1};
|
||||
state.negativeOneToOne = false;
|
||||
state.scissor = {{0, 0}, {Width, Height}};
|
||||
state.cullMode = VK_CULL_MODE_NONE;
|
||||
state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
state.blend.colorWriteMask = 15;
|
||||
state.blends = {state.blend};
|
||||
state.blendConstants = {};
|
||||
const AgcDriver::Pm4::DrawParameters draw{0, static_cast<std::uint32_t>(Triangle.size()), 0, 1, 0, false};
|
||||
device.Draw(state, draw, shaders);
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void Check(std::uint32_t waveSize, bool masked) {
|
||||
const auto what = "pixel valid mask wave" + std::to_string(waveSize) + (masked ? " odd columns cleared" : " full EXEC");
|
||||
for (std::uint32_t pixel = 0; pixel < Width * Height; ++pixel) {
|
||||
const bool exported = !masked || (pixel % Width) % 2u == 0u;
|
||||
const auto expected = exported ? std::byte{255} : Kept;
|
||||
for (std::uint32_t channel = 0; channel < 4; ++channel) {
|
||||
const auto actual = Pixels[pixel * 4u + channel];
|
||||
Require(actual == expected, what + ": pixel " + std::to_string(pixel) + " channel " + std::to_string(channel) + " is " + std::to_string(static_cast<unsigned>(actual)) + ", expected " + std::to_string(static_cast<unsigned>(expected)) + (exported ? " (exported)" : " (cleared from EXEC before the vm export)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
if (device->Target().subgroupSize < 32u) {
|
||||
std::printf("skipped, subgroup size %u cannot hold a wave32\n", device->Target().subgroupSize);
|
||||
return VulkanTestSkipped;
|
||||
}
|
||||
for (const auto waveSize : {64u, 32u}) {
|
||||
Draw(*device, waveSize, FullPixelCode);
|
||||
Check(waveSize, false);
|
||||
Draw(*device, waveSize, MaskedPixelCode);
|
||||
Check(waveSize, true);
|
||||
}
|
||||
std::puts("pixel valid mask tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
#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 = 16;
|
||||
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, 50> Code{
|
||||
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x76140af9, 0x06000604, 0x7e160307,
|
||||
0x76160af9, 0x00091504, 0x76180af9, 0x09120c04, 0x761a0af9, 0x02230004, 0x7e1c0307, 0x761c0af9,
|
||||
0x0b041104, 0x761e0af9, 0x04050a04, 0x76200af9, 0x05360304, 0x76220af9, 0x0d0d0604, 0x76240af9,
|
||||
0x0c060d04, 0x76260af9, 0x06042504, 0x7e280307, 0x76280af9, 0x05153404, 0x762a0af9, 0x0c262604,
|
||||
0x762c0af9, 0x06062c04, 0x762e0af9, 0x06044604, 0x7e300307, 0x76300af9, 0x0c15f504, 0x76320af9,
|
||||
0x050b0404, 0xe0781000, 0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, 0x80011203, 0xe0781030,
|
||||
0x80011603, 0xbf810000,
|
||||
};
|
||||
|
||||
constexpr std::uint32_t Rows[32][4] = {
|
||||
{0x00000000u, 0x684e9968u, 0xff007c00u, 0x6f931b8au},
|
||||
{0x808003ffu, 0x0004fffcu, 0x00ff8080u, 0x7bff0004u},
|
||||
{0xfff0fff0u, 0x00108000u, 0x7bffbc00u, 0xa45c7559u},
|
||||
{0x7d22fe4du, 0x056329d8u, 0xd7096658u, 0x38008080u},
|
||||
{0x8bb3fddeu, 0x00ff0004u, 0x80800040u, 0xbc0003ffu},
|
||||
{0xfc7a7ca0u, 0x7c007f7fu, 0xef4b2407u, 0xcc04a29cu},
|
||||
{0x7d007d00u, 0x7b6150bfu, 0x6dcc8926u, 0x8000fffcu},
|
||||
{0x7e007e00u, 0x00103c00u, 0x3c00bc00u, 0xb9cb4fcfu},
|
||||
{0x7e097c3cu, 0x7c007d00u, 0x0080fc00u, 0x80808080u},
|
||||
{0x7eedf7dbu, 0x00000080u, 0x7bff3c00u, 0x8000fffcu},
|
||||
{0x7efc7d70u, 0xc2404efau, 0x03ff0000u, 0xf8e9b3fau},
|
||||
{0x7f7f7f7fu, 0x03ff3c00u, 0x0a0a0ef4u, 0x00043800u},
|
||||
{0x925cfc30u, 0xc2c739c1u, 0x7c00ffc0u, 0x3c00fff0u},
|
||||
{0xfcb6fe11u, 0x7bfffffcu, 0xfc000004u, 0x00ff0000u},
|
||||
{0xffc0ffc0u, 0x00400004u, 0x935ed482u, 0xfff07e00u},
|
||||
{0xfffcfffcu, 0x80807bffu, 0x7d000080u, 0x42e04aebu},
|
||||
{0x9308fc92u, 0x800003ffu, 0x8080fffcu, 0x00107d00u},
|
||||
{0x9759fcb4u, 0xea4692e5u, 0xffc04400u, 0xd16a9b24u},
|
||||
{0x9b437c27u, 0x00040001u, 0x00803800u, 0xf26a25eau},
|
||||
{0x9d757cb2u, 0x7d00fc00u, 0xfffc0080u, 0x03ff8000u},
|
||||
{0xa2207fd4u, 0x77acf39bu, 0x00000040u, 0x4321d11au},
|
||||
{0xa9957e8au, 0x784edcbcu, 0xc1986687u, 0x1673526du},
|
||||
{0xab057dadu, 0x03ff0000u, 0xfc00fff0u, 0xa912eb3au},
|
||||
{0xacdffc34u, 0x01c450c4u, 0x00007c00u, 0xff00fff0u},
|
||||
{0xb5317eabu, 0x6d3223e0u, 0xb2c8089au, 0x001000ffu},
|
||||
{0xb8987d0au, 0x3800fff0u, 0x28bc3cd4u, 0x7bfffff0u},
|
||||
{0xbca4fe29u, 0x6af4ea82u, 0x800000ffu, 0x409ee072u},
|
||||
{0xc242ffedu, 0x00107d00u, 0x45a37ba4u, 0x7f7f4400u},
|
||||
{0xc31cfca9u, 0x25115884u, 0xa6568fceu, 0x7d0003ffu},
|
||||
{0xc492fd96u, 0x330fbd35u, 0x00ff7d00u, 0x8248e011u},
|
||||
{0xcabaff3cu, 0x0000fc00u, 0x000400ffu, 0xbc007bffu},
|
||||
{0xcd717c3bu, 0x808000ffu, 0xffc003ffu, 0x6af2aa83u}
|
||||
};
|
||||
constexpr std::uint32_t Expected[32][16] = {
|
||||
{0x00000000u, 0x00001b8au, 0xffff8000u, 0x00000000u, 0x6f93008au, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x6f930000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00001b8au, 0x00000000u},
|
||||
{0x00000010u, 0x7c000004u, 0xffff8040u, 0x00000000u, 0x7bffff04u, 0x00080000u, 0xfe000000u, 0x00008800u, 0x00400000u, 0x00400000u, 0x7bff0800u, 0x00000040u, 0x00000040u, 0x00000040u, 0x00080004u, 0x0000ff80u},
|
||||
{0x00000000u, 0xffff7559u, 0xffff8000u, 0x000000f8u, 0xa45cf059u, 0xfff00000u, 0xf0000000u, 0x0000fff0u, 0xfff00000u, 0x00000000u, 0xa45c0000u, 0x00000000u, 0x00000000u, 0x0000fff0u, 0x00007559u, 0x0000ffffu},
|
||||
{0x00007c00u, 0xfffe8080u, 0xfffffc00u, 0x00000000u, 0x38004d80u, 0x00220000u, 0x4d000000u, 0x00007f22u, 0xfe4d0000u, 0x00000000u, 0x38000000u, 0x00000000u, 0x00000000u, 0x0000fe4du, 0x00008080u, 0x00007c00u},
|
||||
{0x00000af0u, 0xfffd03ffu, 0xffff80b3u, 0x00000000u, 0xbc00deffu, 0xffb30000u, 0xde000000u, 0x0000fc00u, 0xffde0000u, 0x00000000u, 0xbc003c00u, 0x00000000u, 0x00000000u, 0x0000ffdeu, 0x1bb303ffu, 0x0000ff8bu},
|
||||
{0x00007c00u, 0x7c00a29cu, 0xfffffc00u, 0x000000fcu, 0xcc04a09cu, 0x007a0000u, 0xa0000000u, 0x0000fe7au, 0x7ea00000u, 0x00000000u, 0xcc040000u, 0x00000000u, 0x00000000u, 0x00007ea0u, 0x0000a29cu, 0x0000fffcu},
|
||||
{0x00000000u, 0x7c00fffcu, 0xffff8000u, 0x00000000u, 0x800000fcu, 0x00000000u, 0x00000000u, 0x00007f00u, 0x7f000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00007f00u, 0x0000fffcu, 0x00007c00u},
|
||||
{0x00000000u, 0x007e4fcfu, 0xffff8000u, 0x000000e0u, 0xb9cb00cfu, 0x00000000u, 0x00000000u, 0x00007e00u, 0x7e000000u, 0x00000000u, 0xb9cb0000u, 0x00000000u, 0x00000000u, 0x00007e00u, 0x00004fcfu, 0x000037e0u},
|
||||
{0x00007c00u, 0x007c8080u, 0xfffffc00u, 0x0000007eu, 0x80803c80u, 0x00090000u, 0x3c000000u, 0x00007e09u, 0x7e3c0000u, 0x00000000u, 0x80800000u, 0x00000000u, 0x00000000u, 0x00007e3cu, 0x00008080u, 0x00007c00u},
|
||||
{0x00007c00u, 0xfff7fffcu, 0xffff80edu, 0x0000007eu, 0x8000dbfcu, 0xffed0000u, 0xdb000000u, 0x00007eedu, 0xfc000000u, 0x00000000u, 0x80000000u, 0x00003c00u, 0x00000000u, 0x0000fc00u, 0x0000fffcu, 0x0000007eu},
|
||||
{0x00007c00u, 0x7c00b3fau, 0xfffffc00u, 0x00000000u, 0xf8e970fau, 0xfffc0000u, 0x70000000u, 0x00007efcu, 0x7f700000u, 0x00000000u, 0xf8e90000u, 0x00000000u, 0x00000000u, 0x00007f70u, 0x0000b3fau, 0x00000000u},
|
||||
{0x00007c00u, 0x007f3800u, 0xfffffc00u, 0x00000000u, 0x00047f00u, 0x007f0000u, 0x7f000000u, 0x00007f7fu, 0x7f7f0000u, 0x00000000u, 0x00040000u, 0x00000000u, 0x00000000u, 0x00007f7fu, 0x00003800u, 0x00007c00u},
|
||||
{0x00007c00u, 0xfffcfff0u, 0xfffffc00u, 0x00000000u, 0x3c0030f0u, 0x00000000u, 0x30000000u, 0x00008000u, 0xfe300000u, 0x00000000u, 0x3c000000u, 0x00000000u, 0x00000000u, 0x0000fe30u, 0x3c00fff0u, 0x0000ff92u},
|
||||
{0x00000001u, 0xfffe0000u, 0xffff805bu, 0x00000000u, 0x00ff1100u, 0xffb60000u, 0x11000000u, 0x0000feb6u, 0xfe110000u, 0x00000000u, 0x00ff0000u, 0x00000000u, 0x00000000u, 0x0000fe11u, 0x00000000u, 0x0000fffcu},
|
||||
{0x00000a00u, 0xffff7e00u, 0xffff80c0u, 0x00000000u, 0xfff0c000u, 0xffc00000u, 0xc0000000u, 0x0000ffc0u, 0xffc00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u, 0x0000ffc0u, 0x00007e00u, 0x0000ffffu},
|
||||
{0x00007c00u, 0xffff4aebu, 0xfffffc00u, 0x00000000u, 0x42e0fcebu, 0xfffc0000u, 0xfc000000u, 0x0000fffcu, 0xfffc0000u, 0x00000000u, 0x42e00000u, 0x00000000u, 0x00000000u, 0x0000fffcu, 0x00004aebu, 0x0000ffffu},
|
||||
{0x00007c00u, 0xfffc7d00u, 0xffff8040u, 0x00000093u, 0x00109200u, 0x00000000u, 0x92000000u, 0x00008000u, 0xfe920000u, 0x00000000u, 0x00100000u, 0x00000000u, 0x00000000u, 0x0000fe92u, 0x3c007d00u, 0x0000ff93u},
|
||||
{0x00000000u, 0xfffc9b24u, 0xffff8000u, 0x00000000u, 0xd16ab424u, 0x00000000u, 0xb4000000u, 0x00008000u, 0xfeb40000u, 0x00000000u, 0xd16a0000u, 0x00000000u, 0x00000000u, 0x0000feb4u, 0x00009b24u, 0x0000ff97u},
|
||||
{0x0000004eu, 0x00f825eau, 0xffff8043u, 0x000000d8u, 0xf26a27eau, 0x00430000u, 0x27000000u, 0x0000ab43u, 0x7e270000u, 0x00000000u, 0xf26a2b43u, 0x00000000u, 0x00000000u, 0x00007e27u, 0x1f4325eau, 0x0000ff9bu},
|
||||
{0x00000000u, 0x007c8000u, 0xffff8007u, 0x0000009du, 0x03ffb200u, 0x00000000u, 0xb2000000u, 0x0000fc00u, 0x7eb20000u, 0x00000000u, 0x03ff3c00u, 0x00000000u, 0x00000000u, 0x00007eb2u, 0x00008000u, 0x0000ff9du},
|
||||
{0x00000000u, 0x7c00d11au, 0xffff8000u, 0x00000000u, 0x4321d41au, 0x00000000u, 0xd4000000u, 0x0000fc00u, 0x7fd40000u, 0x00000000u, 0x43213c00u, 0x00000000u, 0x00000000u, 0x00007fd4u, 0x0000d11au, 0x0000ffa2u},
|
||||
{0x00000000u, 0x7c00526du, 0xffff8000u, 0x00000000u, 0x16738a6du, 0x00000000u, 0x8a000000u, 0x0000fc00u, 0x7e8a0000u, 0x00000000u, 0x16733c00u, 0x00000000u, 0x00000000u, 0x00007e8au, 0x0000526du, 0x0000ffa9u},
|
||||
{0x000000adu, 0x007deb3au, 0xffff8005u, 0x00000000u, 0xa912ad3au, 0x00050000u, 0xad000000u, 0x0000fc00u, 0x7fad0000u, 0x00000000u, 0xa9123c00u, 0x00000000u, 0x00000000u, 0x00007fadu, 0x2b05eb3au, 0x0000ffabu},
|
||||
{0x00007c00u, 0xfffcfff0u, 0xfffffc00u, 0x00000000u, 0xff0034f0u, 0x00000000u, 0x34000000u, 0x0000fc00u, 0xfe340000u, 0x00000000u, 0xff003c00u, 0x00000000u, 0x00000000u, 0x0000fe34u, 0x3c00fff0u, 0x0000ffacu},
|
||||
{0x00007c00u, 0x7c0000ffu, 0xfffffc00u, 0x00000000u, 0x0010abffu, 0x00000000u, 0xab000000u, 0x0000fc00u, 0x7eab0000u, 0x00000000u, 0x00103c00u, 0x00000000u, 0x00000000u, 0x00007eabu, 0x3c0000ffu, 0x0000ffb5u},
|
||||
{0x00000000u, 0x7c00fff0u, 0xffff804cu, 0x000000b8u, 0x7bff0af0u, 0xff930000u, 0x0a000000u, 0x0000fc00u, 0x7f0a0000u, 0x00000000u, 0x7bff3c00u, 0x00000000u, 0x00000000u, 0x00007f0au, 0x0093fff0u, 0x0000ffb8u},
|
||||
{0x00000000u, 0xfffee072u, 0xffff8000u, 0x00000000u, 0x409e2972u, 0x00000000u, 0x29000000u, 0x0000fc00u, 0xfe290000u, 0x00000000u, 0x409e3c00u, 0x00000000u, 0x00000000u, 0x0000fe29u, 0x0000e072u, 0x0000ffbcu},
|
||||
{0x00007c00u, 0xffff4400u, 0xfffffc00u, 0x00000010u, 0x7f7fed00u, 0x00000000u, 0xed000000u, 0x0000fc00u, 0xffed0000u, 0x00000000u, 0x7f7f3c00u, 0x00000000u, 0x00000000u, 0x0000ffedu, 0x3c004400u, 0x0000ffc2u},
|
||||
{0x00007c00u, 0xfffc03ffu, 0xfffffc00u, 0x00000018u, 0x7d00a9ffu, 0x00000000u, 0xa9000000u, 0x0000fc00u, 0xfea90000u, 0x00000000u, 0x7d003c00u, 0x00000000u, 0x00000000u, 0x0000fea9u, 0x3c0003ffu, 0x0000ffc3u},
|
||||
{0x00000000u, 0xfffde011u, 0xffff8000u, 0x00000020u, 0x82489611u, 0x00000000u, 0x96000000u, 0x0000fc00u, 0xff960000u, 0x00000000u, 0x82483c00u, 0x00000000u, 0x00000000u, 0x0000ff96u, 0x0000e011u, 0x0000ffc4u},
|
||||
{0x00000000u, 0xffff7bffu, 0xffff800cu, 0x000000cau, 0xbc003cffu, 0x00000000u, 0x3c000000u, 0x0000cabau, 0xff3c0000u, 0x00000000u, 0xbc003c00u, 0x00000000u, 0x00000000u, 0x0000ff3cu, 0x00007bffu, 0x0000ffcau},
|
||||
{0x00007c00u, 0x7c00aa83u, 0xffff8071u, 0x00000000u, 0x6af23b83u, 0x00000000u, 0x3b000000u, 0x00008000u, 0x7e3b0000u, 0x00000000u, 0x6af20000u, 0x00000000u, 0x00000000u, 0x00007e3bu, 0x3c00aa83u, 0x0000ffcdu}
|
||||
};
|
||||
constexpr std::uint32_t Checked[32] = {0xffffu, 0x8008u, 0xfff7u, 0x7ffau, 0xfffau, 0xfff0u, 0x7ffdu, 0x7ff5u, 0x7ff0u, 0x7ff2u, 0xfff8u, 0x7ff8u, 0xfffau, 0xfffau, 0xfffau, 0xfffau, 0xfff2u, 0xffffu, 0xfff0u, 0xfff1u, 0xfffdu, 0xfffdu, 0xfff8u, 0xfffau, 0xfff8u, 0xbfd1u, 0xffffu, 0xfff2u, 0xfff2u, 0xfff7u, 0xfff3u, 0xfff8u};
|
||||
constexpr const char* Names[16] = {
|
||||
"BYTE_0/DWORD -> DWORD",
|
||||
"BYTE_1/BYTE_0 -> WORD_1",
|
||||
"BYTE_2/BYTE_1 -> WORD_0",
|
||||
"BYTE_3/BYTE_2 -> BYTE_0",
|
||||
"WORD_0/BYTE_3 -> BYTE_1",
|
||||
"WORD_1/WORD_0 -> BYTE_2",
|
||||
"DWORD/WORD_1 -> BYTE_3",
|
||||
"WORD_1/WORD_1 -> DWORD",
|
||||
"DWORD/WORD_0 -> WORD_1",
|
||||
"WORD_0/DWORD -> WORD_1 clamp",
|
||||
"WORD_1/WORD_1 -> WORD_0 clamp",
|
||||
"DWORD/WORD_0 -> DWORD clamp",
|
||||
"DWORD/DWORD -> WORD_0 clamp",
|
||||
"WORD_0/DWORD -> DWORD mul:2",
|
||||
"WORD_1/WORD_0 -> WORD_1 clamp div:2",
|
||||
"BYTE_3/WORD_1 -> WORD_0",
|
||||
};
|
||||
|
||||
void Fill(std::uint32_t tid, std::uint32_t* words) {
|
||||
std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words);
|
||||
}
|
||||
|
||||
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("sdwa ldexp f16: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected));
|
||||
}
|
||||
|
||||
ShaderRecompiler::RecompileResult Compile(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t> code) {
|
||||
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::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {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 Run(AgcDriver::VulkanDevice& device) {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) Fill(tid, &Input[tid * Inputs]);
|
||||
Output.fill(0xdeadbeefu);
|
||||
const std::span<const std::uint32_t> code(Code);
|
||||
const auto result = Compile(device, code);
|
||||
device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void CheckRefused(AgcDriver::VulkanDevice& device) {
|
||||
struct Refused {
|
||||
std::uint32_t modifier;
|
||||
const char* error;
|
||||
};
|
||||
constexpr std::array<Refused, 5> forms{{
|
||||
{0x04042004u, "VOP2 SDWA clamp with byte selectors is not implemented"},
|
||||
{0x06022504u, "VOP2 SDWA clamp with byte selectors is not implemented"},
|
||||
{0x01062604u, "VOP2 SDWA clamp with byte selectors is not implemented"},
|
||||
{0x10050404u, "VOP2 SDWA source modifiers are not supported"},
|
||||
{0x26060604u, "VOP2 SDWA source modifiers are not supported"},
|
||||
}};
|
||||
for (const auto& form : forms) {
|
||||
alignas(256) const std::array<std::uint32_t, 3> code{0x76140af9u, form.modifier, 0xbf810000u};
|
||||
std::string refusal;
|
||||
try {
|
||||
static_cast<void>(Compile(device, code));
|
||||
} catch (const std::exception& error) {
|
||||
refusal = error.what();
|
||||
}
|
||||
Require(refusal.find(form.error) != std::string::npos, "v_ldexp_f16 SDWA form " + Hex(form.modifier) + " was not refused");
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
for (std::uint32_t i = 0; i < 16; ++i) {
|
||||
if ((Checked[tid] >> i) & 1u) {
|
||||
Expect(tid, out[i], Expected[tid][i], Names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
CheckRefused(*device);
|
||||
std::puts("sdwa ldexp f16 tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
#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 <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
constexpr std::uint32_t Selectors = 7;
|
||||
constexpr std::uint32_t UnusedModes = 3;
|
||||
constexpr std::uint32_t Combinations = Selectors * 2u * Selectors * UnusedModes;
|
||||
constexpr std::uint32_t BroadcastResult = Combinations;
|
||||
constexpr std::uint32_t MaxLanes = 64;
|
||||
constexpr std::uint32_t Inputs = 2;
|
||||
constexpr std::uint32_t Results = Combinations + 1u;
|
||||
constexpr std::uint32_t InputIndexVector = 1;
|
||||
constexpr std::uint32_t OutputIndexVector = 2;
|
||||
constexpr std::uint32_t BroadcastVector = 3;
|
||||
constexpr std::uint32_t SourceVector = 4;
|
||||
constexpr std::uint32_t PreviousVector = 5;
|
||||
constexpr std::uint32_t DataVector = 6;
|
||||
constexpr std::uint32_t ThreadVector = 0;
|
||||
constexpr std::uint32_t ExecLoRegister = 0x7eu;
|
||||
constexpr std::uint32_t ExecHiRegister = 0x7fu;
|
||||
constexpr std::uint32_t InputRegister = 0;
|
||||
constexpr std::uint32_t OutputRegister = 4;
|
||||
constexpr std::uint32_t ConstantZero = 0x80u;
|
||||
constexpr std::uint32_t ConstantOne = 0x81u;
|
||||
constexpr std::uint32_t ConstantAllOnes = 0xc1u;
|
||||
constexpr std::uint32_t Literal = 0xffu;
|
||||
constexpr std::uint32_t Sdwa = 0xf9u;
|
||||
constexpr std::uint32_t VectorSource = 0x100u;
|
||||
constexpr std::uint32_t Endpgm = 0xbf810000u;
|
||||
constexpr std::array<std::uint32_t, 2> BroadcastExec{0xa5a5a5a5u, 0x3c3c3c3cu};
|
||||
|
||||
template <std::uint32_t WaveSize>
|
||||
constexpr std::size_t CodeWords = 15u + (WaveSize == 64u ? 5u : 3u) + Combinations * 5u + 3u;
|
||||
|
||||
constexpr std::array<std::uint32_t, 32> Sources{
|
||||
0x00000000u, 0xffffffffu, 0x80808080u, 0x7f7f7f7fu, 0x000000ffu, 0x0000ff00u, 0x00ff0000u, 0xff000000u,
|
||||
0x00000080u, 0x00008000u, 0x00800000u, 0x80000000u, 0x0000007fu, 0x00007fffu, 0x007fffffu, 0x7fffffffu,
|
||||
0x01020384u, 0x8504f306u, 0x12345678u, 0x9abcdef0u, 0xfedcba98u, 0x76543210u, 0x00ff00ffu, 0xff00ff00u,
|
||||
0x80007fffu, 0x7fff8000u, 0xc3a5815au, 0x5a81a5c3u, 0x0f1e2d3cu, 0xf0e1d2c3u, 0x40c08001u, 0xdeadbeefu,
|
||||
};
|
||||
|
||||
alignas(256) std::array<std::uint32_t, MaxLanes * Inputs> Input{};
|
||||
alignas(256) std::array<std::uint32_t, MaxLanes * Results> Output{};
|
||||
|
||||
constexpr std::uint32_t Sop1(std::uint32_t opcode, std::uint32_t destination, std::uint32_t source) {
|
||||
return 0xbe800000u | (destination << 16u) | (opcode << 8u) | source;
|
||||
}
|
||||
|
||||
constexpr std::uint32_t Vop1(std::uint32_t opcode, std::uint32_t destination, std::uint32_t source) {
|
||||
return 0x7e000000u | (destination << 17u) | (opcode << 9u) | source;
|
||||
}
|
||||
|
||||
constexpr std::uint32_t Vop2(std::uint32_t opcode, std::uint32_t destination, std::uint32_t source0, std::uint32_t source1) {
|
||||
return (opcode << 25u) | (destination << 17u) | (source1 << 9u) | source0;
|
||||
}
|
||||
|
||||
constexpr std::uint32_t SdwaModifier(std::uint32_t source, std::uint32_t destinationSelector, std::uint32_t unused, std::uint32_t sourceSelector, std::uint32_t signExtend) {
|
||||
return source | (destinationSelector << 8u) | (unused << 11u) | (sourceSelector << 16u) | (signExtend << 19u);
|
||||
}
|
||||
|
||||
constexpr std::uint32_t BufferAccess(std::uint32_t data, std::uint32_t index, std::uint32_t descriptor) {
|
||||
return (ConstantZero << 24u) | ((descriptor / 4u) << 16u) | (data << 8u) | index;
|
||||
}
|
||||
|
||||
constexpr std::uint32_t CombinationIndex(std::uint32_t sourceSelector, std::uint32_t signExtend, std::uint32_t destinationSelector, std::uint32_t unused) {
|
||||
return ((sourceSelector * 2u + signExtend) * Selectors + destinationSelector) * UnusedModes + unused;
|
||||
}
|
||||
|
||||
template <std::uint32_t WaveSize>
|
||||
constexpr std::array<std::uint32_t, CodeWords<WaveSize>> BuildCode() {
|
||||
constexpr std::uint32_t sMovB32 = 0x03u;
|
||||
constexpr std::uint32_t sMovB64 = 0x04u;
|
||||
constexpr std::uint32_t vMovB32 = 0x01u;
|
||||
constexpr std::uint32_t vMulU32U24 = 0x0bu;
|
||||
constexpr std::uint32_t vLshlrevB32 = 0x1au;
|
||||
constexpr std::uint32_t bufferLoadDwordIndexed = 0xe0302000u;
|
||||
constexpr std::uint32_t bufferStoreDwordIndexed = 0xe0702000u;
|
||||
constexpr std::uint32_t waitVmcnt = 0xbf8c3f70u;
|
||||
std::array<std::uint32_t, CodeWords<WaveSize>> code{};
|
||||
std::size_t count = 0;
|
||||
code[count++] = Vop2(vLshlrevB32, InputIndexVector, ConstantOne, ThreadVector);
|
||||
code[count++] = Vop2(vMulU32U24, OutputIndexVector, Literal, ThreadVector);
|
||||
code[count++] = Results;
|
||||
code[count++] = bufferLoadDwordIndexed;
|
||||
code[count++] = BufferAccess(SourceVector, InputIndexVector, InputRegister);
|
||||
code[count++] = bufferLoadDwordIndexed | 4u;
|
||||
code[count++] = BufferAccess(PreviousVector, InputIndexVector, InputRegister);
|
||||
code[count++] = waitVmcnt;
|
||||
code[count++] = Vop1(vMovB32, BroadcastVector, VectorSource | SourceVector);
|
||||
code[count++] = Sop1(sMovB32, ExecLoRegister, Literal);
|
||||
code[count++] = BroadcastExec[0];
|
||||
if constexpr (WaveSize == 64u) {
|
||||
code[count++] = Sop1(sMovB32, ExecHiRegister, Literal);
|
||||
code[count++] = BroadcastExec[1];
|
||||
}
|
||||
for (std::uint32_t byte = 1; byte < 4u; ++byte) {
|
||||
code[count++] = Vop1(vMovB32, BroadcastVector, Sdwa);
|
||||
code[count++] = SdwaModifier(BroadcastVector, byte, 2u, 0u, 0u);
|
||||
}
|
||||
code[count++] = WaveSize == 64u ? Sop1(sMovB64, ExecLoRegister, ConstantAllOnes) : Sop1(sMovB32, ExecLoRegister, ConstantAllOnes);
|
||||
for (std::uint32_t sourceSelector = 0; sourceSelector < Selectors; ++sourceSelector) {
|
||||
for (std::uint32_t signExtend = 0; signExtend < 2u; ++signExtend) {
|
||||
for (std::uint32_t destinationSelector = 0; destinationSelector < Selectors; ++destinationSelector) {
|
||||
for (std::uint32_t unused = 0; unused < UnusedModes; ++unused) {
|
||||
code[count++] = Vop1(vMovB32, DataVector, VectorSource | PreviousVector);
|
||||
code[count++] = Vop1(vMovB32, DataVector, Sdwa);
|
||||
code[count++] = SdwaModifier(SourceVector, destinationSelector, unused, sourceSelector, signExtend);
|
||||
code[count++] = bufferStoreDwordIndexed | (CombinationIndex(sourceSelector, signExtend, destinationSelector, unused) * 4u);
|
||||
code[count++] = BufferAccess(DataVector, OutputIndexVector, OutputRegister);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
code[count++] = bufferStoreDwordIndexed | (BroadcastResult * 4u);
|
||||
code[count++] = BufferAccess(BroadcastVector, OutputIndexVector, OutputRegister);
|
||||
code[count++] = Endpgm;
|
||||
return code;
|
||||
}
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, CodeWords<32>> Wave32Code = BuildCode<32>();
|
||||
alignas(256) constexpr std::array<std::uint32_t, CodeWords<64>> Wave64Code = BuildCode<64>();
|
||||
|
||||
std::uint32_t Source(std::uint32_t tid) {
|
||||
return std::rotl(Sources[tid % 32u], static_cast<int>(tid / 32u) * 8);
|
||||
}
|
||||
|
||||
std::uint32_t Previous(std::uint32_t tid) {
|
||||
return 0xabcd1234u ^ (tid * 0x01030507u);
|
||||
}
|
||||
|
||||
bool BroadcastActive(std::uint32_t tid) {
|
||||
return ((BroadcastExec[tid / 32u] >> (tid % 32u)) & 1u) != 0u;
|
||||
}
|
||||
|
||||
void FillInput() {
|
||||
for (std::uint32_t tid = 0; tid < MaxLanes; ++tid) {
|
||||
Input[tid * Inputs] = Source(tid);
|
||||
Input[tid * Inputs + 1u] = Previous(tid);
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t FieldOffset(std::uint32_t selector) {
|
||||
return selector < 4u ? selector * 8u : (selector - 4u) * 16u;
|
||||
}
|
||||
|
||||
std::uint32_t FieldMask(std::uint32_t selector) {
|
||||
return selector < 4u ? 0xffu : 0xffffu;
|
||||
}
|
||||
|
||||
std::uint32_t SignExtendField(std::uint32_t field, std::uint32_t mask) {
|
||||
return (field & ((mask >> 1u) + 1u)) != 0u ? field | ~mask : field;
|
||||
}
|
||||
|
||||
std::uint32_t SelectSource(std::uint32_t value, std::uint32_t selector, bool signExtend) {
|
||||
if (selector == 6u) {
|
||||
return value;
|
||||
}
|
||||
const std::uint32_t field = (value >> FieldOffset(selector)) & FieldMask(selector);
|
||||
return signExtend ? SignExtendField(field, FieldMask(selector)) : field;
|
||||
}
|
||||
|
||||
std::uint32_t PlaceDestination(std::uint32_t result, std::uint32_t selector, std::uint32_t unused, std::uint32_t previous) {
|
||||
if (selector == 6u) {
|
||||
return result;
|
||||
}
|
||||
const std::uint32_t offset = FieldOffset(selector);
|
||||
const std::uint32_t mask = FieldMask(selector);
|
||||
const std::uint32_t field = result & mask;
|
||||
switch (unused) {
|
||||
case 0u: return field << offset;
|
||||
case 1u: return SignExtendField(field, mask) << offset;
|
||||
default: return (previous & ~(mask << offset)) | (field << offset);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Hex(std::uint32_t value) {
|
||||
char text[16];
|
||||
std::snprintf(text, sizeof(text), "0x%08x", value);
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string Describe(std::uint32_t sourceSelector, bool signExtend, std::uint32_t destinationSelector, std::uint32_t unused) {
|
||||
constexpr const char* selectorNames[Selectors] = {"BYTE_0", "BYTE_1", "BYTE_2", "BYTE_3", "WORD_0", "WORD_1", "DWORD"};
|
||||
constexpr const char* unusedNames[UnusedModes] = {"UNUSED_PAD", "UNUSED_SEXT", "UNUSED_PRESERVE"};
|
||||
return std::string("v_mov_b32_sdwa dst_sel:") + selectorNames[destinationSelector] + " dst_unused:" + unusedNames[unused] +
|
||||
" src0_sel:" + selectorNames[sourceSelector] + (signExtend ? " sext" : "");
|
||||
}
|
||||
|
||||
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, std::span<const std::uint32_t> code, std::uint32_t waveSize, const ShaderRecompiler::SpirvTarget& target) {
|
||||
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() + InputRegister);
|
||||
std::copy(output.begin(), output.end(), userData.begin() + OutputRegister);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{waveSize, 1, 1}, 0, {false, false, false}, false, 1};
|
||||
ShaderRecompiler::RecompileRequest request{
|
||||
{ShaderStage::Compute, reinterpret_cast<std::uintptr_t>(code.data()), code, 0, {}},
|
||||
{waveSize, 0, userData, compute, std::nullopt, std::nullopt, memory},
|
||||
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(std::uint32_t waveSize, const char* run, bool masked) {
|
||||
for (std::uint32_t tid = 0; tid < waveSize; ++tid) {
|
||||
const std::uint32_t source = Source(tid);
|
||||
const std::uint32_t previous = Previous(tid);
|
||||
const auto* out = &Output[tid * Results];
|
||||
const auto where = [&](std::uint32_t result) {
|
||||
return std::string("sdwa move selectors ") + run + ": lane " + std::to_string(tid) + " source " + Hex(source) + " previous " + Hex(previous) + " result " + Hex(out[result]);
|
||||
};
|
||||
for (std::uint32_t sourceSelector = 0; sourceSelector < Selectors; ++sourceSelector) {
|
||||
for (std::uint32_t signExtend = 0; signExtend < 2u; ++signExtend) {
|
||||
const std::uint32_t selected = SelectSource(source, sourceSelector, signExtend != 0u);
|
||||
for (std::uint32_t destinationSelector = 0; destinationSelector < Selectors; ++destinationSelector) {
|
||||
for (std::uint32_t unused = 0; unused < UnusedModes; ++unused) {
|
||||
const std::uint32_t index = CombinationIndex(sourceSelector, signExtend, destinationSelector, unused);
|
||||
const std::uint32_t expected = PlaceDestination(selected, destinationSelector, unused, previous);
|
||||
Require(out[index] == expected, where(index) + ", expected " + Hex(expected) + ": " + Describe(sourceSelector, signExtend != 0u, destinationSelector, unused));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!masked) continue;
|
||||
if (BroadcastActive(tid)) {
|
||||
const std::uint32_t broadcast = (source & 0xffu) * 0x01010101u;
|
||||
Require(out[BroadcastResult] == broadcast, where(BroadcastResult) + ", expected " + Hex(broadcast) + ": in-place v_mov_b32_sdwa v3, v3 dst_sel:BYTE_1/2/3 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0 must copy byte 0 into the other bytes");
|
||||
} else {
|
||||
Require(out[BroadcastResult] == source, where(BroadcastResult) + ", expected " + Hex(source) + ": the in-place v_mov_b32_sdwa must not write an inactive lane");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
const bool masked = device->Target().subgroupSize >= 32u;
|
||||
if (!masked) std::printf("EXEC-masked broadcast skipped, subgroup size %u cannot hold a wave32\n", device->Target().subgroupSize);
|
||||
FillInput();
|
||||
Run(*device, Wave32Code, 32, device->Target());
|
||||
Check(32, "wave32", masked);
|
||||
Run(*device, Wave64Code, 64, device->Target());
|
||||
Check(64, "wave64", masked);
|
||||
Run(*device, Wave64Code, 64, device->ComputeTarget(32));
|
||||
Check(64, "wave64 split", masked);
|
||||
std::puts("sdwa move selector tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
add_library(libSceAppContent SHARED EXCLUDE_FROM_ALL Export.cpp)
|
||||
target_include_directories(libSceAppContent PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
configure_windows_unwind(libSceAppContent)
|
||||
|
||||
if(MINGW)
|
||||
foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static)
|
||||
string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_appcontent_tests ${LIBS_INCLUDE_DIR}/tests/GuestAppContent.cpp)
|
||||
target_include_directories(guest_appcontent_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_appcontent_tests PRIVATE libSceAppContent libc)
|
||||
configure_windows_unwind(guest_appcontent_tests)
|
||||
add_test(NAME guest_appcontent COMMAND guest_appcontent_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_appcontent PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceAppContent>")
|
||||
endif()
|
||||
endif()
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
|
||||
static constexpr int SCE_APP_CONTENT_ERROR_PARAMETER = static_cast<int>(0x80D90002);
|
||||
static constexpr int SCE_APP_CONTENT_ERROR_NOT_FOUND = static_cast<int>(0x80D90005);
|
||||
static constexpr uint32_t APPPARAM_ID_SKU_FLAG = 1;
|
||||
static constexpr int32_t SKU_FLAG_FULL = 3;
|
||||
|
||||
@@ -30,16 +31,13 @@ extern "C" {
|
||||
|
||||
int APS5_VABI sceAppContentAddcontMount(uint32_t service_label, const NpUnifiedEntitlementLabel* entitlement_label, AppContentMountPoint* mount_point) {
|
||||
(void)service_label;
|
||||
(void)entitlement_label;
|
||||
(void)mount_point;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
if (!entitlement_label || !mount_point) return SCE_APP_CONTENT_ERROR_PARAMETER;
|
||||
return SCE_APP_CONTENT_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAppContentAddcontUnmount(const AppContentMountPoint* mount_point) {
|
||||
(void)mount_point;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
if (!mount_point) return SCE_APP_CONTENT_ERROR_PARAMETER;
|
||||
return SCE_APP_CONTENT_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
int APS5_VABI sceAppContentAppParamGetInt(uint32_t param_id, int32_t* value) {
|
||||
|
||||
@@ -172,6 +172,12 @@ int APS5_VABI sceHttpSetRecvTimeOut(int id, uint32_t usec) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpSetResponseHeaderMaxSize(int id, uint64_t header_size) {
|
||||
(void)id;
|
||||
(void)header_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpSetRequestContentLength(int request_id, uint64_t content_length) {
|
||||
(void)request_id;
|
||||
(void)content_length;
|
||||
@@ -242,6 +248,11 @@ int APS5_VABI sceHttpReadData(int request_id, void* data, size_t size) {
|
||||
return ERROR_NETWORK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpRedirectCacheFlush(int http_ctx_id) {
|
||||
(void)http_ctx_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpSetChunkedTransferEnabled(int id, int enable) {
|
||||
(void)id;
|
||||
(void)enable;
|
||||
@@ -345,6 +356,11 @@ int APS5_VABI sceHttpsLoadCert(int http_ctx_id, int num, void* ca_list, void* ce
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpsUnloadCert(int http_ctx_id) {
|
||||
(void)http_ctx_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpGetLastErrno(int request_id, int* errno_out) {
|
||||
(void)request_id;
|
||||
if (errno_out == nullptr) {
|
||||
|
||||
@@ -31,8 +31,7 @@ std::set<int32_t> g_openKeyboards;
|
||||
extern "C" {
|
||||
|
||||
int APS5_VABI sceImeClose_nid_postfix(void) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return ErrorNotOpened;
|
||||
}
|
||||
|
||||
int APS5_VABI sceImeGetPanelSize(const Param* param, uint32_t* width, uint32_t* height) {
|
||||
@@ -94,22 +93,19 @@ void APS5_VABI sceImeParamInit(Param* param) {
|
||||
|
||||
int APS5_VABI sceImeSetCaret(const Caret* caret) {
|
||||
(void)caret;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return ErrorNotOpened;
|
||||
}
|
||||
|
||||
int APS5_VABI sceImeSetText(const char16_t* text, uint32_t length) {
|
||||
(void)text;
|
||||
(void)length;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return ErrorNotOpened;
|
||||
}
|
||||
|
||||
int APS5_VABI sceImeSetTextGeometry(TextAreaMode mode, const TextGeometry* geometry) {
|
||||
(void)mode;
|
||||
(void)geometry;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return ErrorNotOpened;
|
||||
}
|
||||
|
||||
int APS5_VABI sceImeUpdate(EventHandler handler) {
|
||||
|
||||
@@ -41,7 +41,6 @@ constexpr std::uint8_t SAMPLING_TYPE_420 = 2;
|
||||
constexpr std::uint32_t MAX_IMAGE_DIMENSION = 0xFFFF;
|
||||
constexpr std::uint32_t MAX_IMAGE_PITCH = 0xFFFFFFF;
|
||||
constexpr std::uint64_t MAX_IMAGE_SIZE = 0x7FFFFFFF;
|
||||
constexpr int SUBSAMPLED_MAX_QUALITY = 90;
|
||||
|
||||
struct Encoder {
|
||||
Encoder* self;
|
||||
@@ -148,9 +147,16 @@ std::vector<std::uint8_t> toPackedPixels(const JpegEncEncodeParam& param, std::u
|
||||
}
|
||||
|
||||
int toQuality(const JpegEncEncodeParam& param) {
|
||||
int quality = 100 - param.compression_ratio * 99 / 255;
|
||||
if (param.sampling_type != SAMPLING_TYPE_FULL) quality = std::min(quality, SUBSAMPLED_MAX_QUALITY);
|
||||
return quality;
|
||||
return 100 - param.compression_ratio * 99 / 255;
|
||||
}
|
||||
|
||||
Decoder::Jpeg::Sampling toSampling(const JpegEncEncodeParam& param) {
|
||||
switch (param.sampling_type) {
|
||||
case SAMPLING_TYPE_FULL: return Decoder::Jpeg::Sampling::Yuv444;
|
||||
case SAMPLING_TYPE_422: return Decoder::Jpeg::Sampling::Yuv422;
|
||||
case SAMPLING_TYPE_420: return Decoder::Jpeg::Sampling::Yuv420;
|
||||
}
|
||||
throw std::invalid_argument("sceJpegEncEncode: invalid sampling type");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -187,7 +193,7 @@ int32_t APS5_VABI sceJpegEncEncode(void* handle, const JpegEncEncodeParam* param
|
||||
|
||||
const std::uint32_t channels = param->pixel_format == PIXEL_FORMAT_Y8 ? 1 : 3;
|
||||
const std::vector<std::uint8_t> pixels = toPackedPixels(*param, channels);
|
||||
const std::vector<std::uint8_t> jpeg = Decoder::Jpeg::Encode(pixels, param->image_width, param->image_height, channels, toQuality(*param));
|
||||
const std::vector<std::uint8_t> jpeg = Decoder::Jpeg::Encode(pixels, param->image_width, param->image_height, channels, toQuality(*param), toSampling(*param));
|
||||
if (jpeg.size() > param->jpeg_size) return SCE_JPEG_ENC_ERROR_INVALID_SIZE;
|
||||
|
||||
std::memcpy(param->jpeg, jpeg.data(), jpeg.size());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
add_library(libSceNgs2.native SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Atrac9.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Custom.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Rack.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Render.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/System.cpp
|
||||
@@ -25,7 +26,7 @@ if(MINGW)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
foreach(ngs2Test IN ITEMS Render Atrac9)
|
||||
foreach(ngs2Test IN ITEMS Render Atrac9 Filter Custom)
|
||||
string(TOLOWER ${ngs2Test} testName)
|
||||
add_test_executable(ngs2_${testName}_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/Ngs2${ngs2Test}.cpp)
|
||||
target_include_directories(ngs2_${testName}_tests PRIVATE ${LIBS_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/3rdparty/LibAtrac9/C/src)
|
||||
|
||||
@@ -18,6 +18,7 @@ static constexpr int SCE_NGS2_ERROR_UNKNOWN_WAVEFORM_FORMAT = static_cast<int>(0
|
||||
static constexpr std::uint32_t SCE_NGS2_RACK_ID_SAMPLER = 0x1000;
|
||||
static constexpr std::uint32_t SCE_NGS2_RACK_ID_SUBMIXER = 0x2000;
|
||||
static constexpr std::uint32_t SCE_NGS2_RACK_ID_MASTERING = 0x3000;
|
||||
static constexpr std::uint32_t SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER = 0x4002;
|
||||
|
||||
static constexpr std::uint32_t SCE_NGS2_WAVEFORM_TYPE_PCM_I16L = 0x12;
|
||||
static constexpr std::uint32_t SCE_NGS2_WAVEFORM_TYPE_PCM_F32L = 0x18;
|
||||
@@ -46,9 +47,16 @@ static constexpr std::uint32_t SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP = 0x10000000;
|
||||
static constexpr std::uint32_t SCE_NGS2_SAMPLER_VOICE_PARAM_ADD_WAVEFORM_BLOCKS = 0x10000001;
|
||||
static constexpr std::uint32_t SCE_NGS2_SAMPLER_VOICE_PARAM_EXIT_LOOP = 0x10000004;
|
||||
static constexpr std::uint32_t SCE_NGS2_SAMPLER_VOICE_PARAM_PITCH = 0x10000005;
|
||||
static constexpr std::uint32_t SCE_NGS2_SAMPLER_VOICE_PARAM_FILTER = 0x1000000a;
|
||||
static constexpr std::uint32_t SCE_NGS2_SUBMIXER_VOICE_PARAM_SETUP = 0x20000000;
|
||||
static constexpr std::uint32_t SCE_NGS2_MASTERING_VOICE_PARAM_SETUP = 0x30000000;
|
||||
static constexpr std::uint32_t SCE_NGS2_MASTERING_VOICE_PARAM_OUTPUT = 0x30000005;
|
||||
static constexpr std::uint32_t SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP = 0x40020000;
|
||||
static constexpr std::uint32_t SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 = 0x40001f00;
|
||||
|
||||
static constexpr std::uint32_t SCE_NGS2_CUSTOM_MAX_MODULES = 24;
|
||||
static constexpr std::uint32_t SCE_NGS2_CUSTOM_MAX_PORTS = 16;
|
||||
static constexpr std::uint32_t SCE_NGS2_CUSTOM_MODULE_ID_USER_FX2 = 0x1f;
|
||||
|
||||
static constexpr std::uint32_t SCE_NGS2_WAVEFORM_BLOCKS_FLAG_CONTINUE = 1;
|
||||
static constexpr std::uint32_t SCE_NGS2_WAVEFORM_BLOCKS_FLAG_RESET = 4;
|
||||
@@ -148,6 +156,104 @@ struct Ngs2MasteringRackOption {
|
||||
std::uint32_t num_peak_meter_blocks;
|
||||
};
|
||||
|
||||
struct Ngs2CustomModuleOption {
|
||||
std::uint32_t size;
|
||||
};
|
||||
|
||||
struct Ngs2UserFx2SetupContext {
|
||||
void* common;
|
||||
void* param;
|
||||
void* work;
|
||||
std::uintptr_t user_data;
|
||||
std::uint32_t max_voices;
|
||||
std::uint32_t voice_index;
|
||||
std::uint64_t reserved[4];
|
||||
};
|
||||
static_assert(sizeof(Ngs2UserFx2SetupContext) == 72);
|
||||
|
||||
using Ngs2UserFx2CleanupContext = Ngs2UserFx2SetupContext;
|
||||
|
||||
struct Ngs2UserFx2ControlContext {
|
||||
const void* data;
|
||||
std::size_t data_size;
|
||||
void* common;
|
||||
void* param;
|
||||
std::uintptr_t user_data;
|
||||
std::uint64_t reserved[4];
|
||||
};
|
||||
static_assert(sizeof(Ngs2UserFx2ControlContext) == 72);
|
||||
|
||||
struct Ngs2UserFx2ProcessContext {
|
||||
float** channel_data;
|
||||
void* common;
|
||||
const void* param;
|
||||
void* work;
|
||||
void* state;
|
||||
std::uintptr_t user_data;
|
||||
std::uint32_t flags;
|
||||
std::uint32_t num_input_channels;
|
||||
std::uint32_t num_output_channels;
|
||||
std::uint32_t num_grain_samples;
|
||||
std::uint32_t sample_rate;
|
||||
std::uint32_t reserved;
|
||||
std::uint64_t reserved2[4];
|
||||
};
|
||||
static_assert(sizeof(Ngs2UserFx2ProcessContext) == 104);
|
||||
|
||||
using Ngs2UserFx2SetupHandler = std::int32_t (APS5_VABI *)(Ngs2UserFx2SetupContext*);
|
||||
using Ngs2UserFx2CleanupHandler = std::int32_t (APS5_VABI *)(Ngs2UserFx2CleanupContext*);
|
||||
using Ngs2UserFx2ControlHandler = std::int32_t (APS5_VABI *)(Ngs2UserFx2ControlContext*);
|
||||
using Ngs2UserFx2ProcessHandler = std::int32_t (APS5_VABI *)(Ngs2UserFx2ProcessContext*);
|
||||
|
||||
struct Ngs2CustomUserFx2ModuleOption {
|
||||
Ngs2CustomModuleOption custom_module_option;
|
||||
Ngs2UserFx2SetupHandler setup_handler;
|
||||
Ngs2UserFx2CleanupHandler cleanup_handler;
|
||||
Ngs2UserFx2ControlHandler control_handler;
|
||||
Ngs2UserFx2ProcessHandler process_handler;
|
||||
std::size_t common_size;
|
||||
std::size_t param_size;
|
||||
std::size_t work_size;
|
||||
std::uintptr_t user_data;
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomUserFx2ModuleOption) == 72);
|
||||
|
||||
struct Ngs2CustomRackModuleInfo {
|
||||
const Ngs2CustomModuleOption* option;
|
||||
std::uint32_t module_id;
|
||||
std::uint32_t source_buffer_id;
|
||||
std::uint32_t extra_buffer_id;
|
||||
std::uint32_t dest_buffer_id;
|
||||
std::uint32_t state_offset;
|
||||
std::uint32_t state_size;
|
||||
std::uint32_t reserved;
|
||||
std::uint32_t reserved2;
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomRackModuleInfo) == 40);
|
||||
|
||||
struct Ngs2CustomRackPortInfo {
|
||||
std::uint32_t source_buffer_id;
|
||||
std::uint32_t reserved;
|
||||
};
|
||||
|
||||
struct Ngs2CustomRackOption {
|
||||
Ngs2RackOption rack_option;
|
||||
std::uint32_t state_size;
|
||||
std::uint32_t num_buffers;
|
||||
std::uint32_t num_modules;
|
||||
std::uint32_t reserved;
|
||||
Ngs2CustomRackModuleInfo module[SCE_NGS2_CUSTOM_MAX_MODULES];
|
||||
Ngs2CustomRackPortInfo port[SCE_NGS2_CUSTOM_MAX_PORTS];
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomRackOption) == 1280);
|
||||
|
||||
struct Ngs2CustomSubmixerRackOption {
|
||||
Ngs2CustomRackOption custom_rack_option;
|
||||
std::uint32_t max_channels;
|
||||
std::uint32_t max_inputs;
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomSubmixerRackOption) == 1288);
|
||||
|
||||
struct Ngs2VoiceParamHeader {
|
||||
std::uint16_t size;
|
||||
std::int16_t next;
|
||||
@@ -254,6 +360,19 @@ struct Ngs2SamplerVoicePitchParam {
|
||||
float ratio;
|
||||
};
|
||||
|
||||
struct Ngs2SamplerVoiceFilterParam {
|
||||
Ngs2VoiceParamHeader header;
|
||||
std::uint32_t index;
|
||||
std::uint32_t location;
|
||||
std::uint32_t type;
|
||||
std::uint64_t channel_mask;
|
||||
float frequency;
|
||||
float q;
|
||||
float level;
|
||||
std::uint32_t reserved[3];
|
||||
};
|
||||
static_assert(sizeof(Ngs2SamplerVoiceFilterParam) == 56);
|
||||
|
||||
struct Ngs2SubmixerVoiceSetupParam {
|
||||
Ngs2VoiceParamHeader header;
|
||||
std::uint32_t num_io_channels;
|
||||
@@ -261,6 +380,22 @@ struct Ngs2SubmixerVoiceSetupParam {
|
||||
};
|
||||
static_assert(sizeof(Ngs2SubmixerVoiceSetupParam) == 16);
|
||||
|
||||
struct Ngs2CustomSubmixerVoiceSetupParam {
|
||||
Ngs2VoiceParamHeader header;
|
||||
std::uint32_t num_input_channels;
|
||||
std::uint32_t num_output_channels;
|
||||
std::uint32_t flags;
|
||||
std::uint32_t reserved;
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomSubmixerVoiceSetupParam) == 24);
|
||||
|
||||
struct Ngs2CustomVoiceUserFx2Param {
|
||||
Ngs2VoiceParamHeader header;
|
||||
const void* data;
|
||||
std::size_t data_size;
|
||||
};
|
||||
static_assert(sizeof(Ngs2CustomVoiceUserFx2Param) == 24);
|
||||
|
||||
struct Ngs2MasteringVoiceSetupParam {
|
||||
Ngs2VoiceParamHeader header;
|
||||
std::uint32_t num_io_channels;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "prx/libc/include/General.hpp"
|
||||
#include "Ngs2Internal.hpp"
|
||||
|
||||
static constexpr std::uint32_t USER_FX2_FLAG_FIRST_PROCESS = 1;
|
||||
static constexpr std::uint32_t USER_FX2_FLAG_PARAM_CHANGED = 2;
|
||||
|
||||
void Ngs2CheckCustomRack(const Ngs2CustomRackOption& option) {
|
||||
if (option.num_buffers != 1) throw std::runtime_error("NGS2: custom racks with " + std::to_string(option.num_buffers) + " buffers are not implemented");
|
||||
if (option.num_modules > SCE_NGS2_CUSTOM_MAX_MODULES || option.rack_option.max_ports > SCE_NGS2_CUSTOM_MAX_PORTS) APS5_INVALID_ARG_EX;
|
||||
for (std::uint32_t m = 0; m < option.num_modules; m++) {
|
||||
const auto& info = option.module[m];
|
||||
if (info.module_id != SCE_NGS2_CUSTOM_MODULE_ID_USER_FX2) throw std::runtime_error("NGS2: custom module id " + Ngs2Hex(info.module_id) + " is not implemented");
|
||||
if (info.option == nullptr || info.option->size != sizeof(Ngs2CustomUserFx2ModuleOption)) APS5_INVALID_ARG_EX;
|
||||
if (info.source_buffer_id != 0 || info.dest_buffer_id != 0) APS5_INVALID_ARG_EX;
|
||||
if (reinterpret_cast<const Ngs2CustomUserFx2ModuleOption*>(info.option)->process_handler == nullptr) APS5_INVALID_ARG_EX;
|
||||
}
|
||||
for (std::uint32_t p = 0; p < option.rack_option.max_ports; p++) {
|
||||
if (option.port[p].source_buffer_id != 0) APS5_INVALID_ARG_EX;
|
||||
}
|
||||
}
|
||||
|
||||
static Ngs2UserFx2SetupContext UserFxContext(Ngs2Rack& rack, std::size_t module, std::uint32_t voiceIndex) {
|
||||
auto& fx = rack.voices[voiceIndex].userFx[module];
|
||||
return {rack.userFxCommon[module].data(), fx.param.data(), fx.work.data(), rack.userFx[module].user_data,
|
||||
static_cast<std::uint32_t>(rack.voices.size()), voiceIndex, {}};
|
||||
}
|
||||
|
||||
void Ngs2SetupUserFx(Ngs2Rack& rack, const Ngs2CustomRackOption& option) {
|
||||
rack.userFx.resize(option.num_modules);
|
||||
rack.userFxCommon.resize(option.num_modules);
|
||||
for (auto& voice : rack.voices) voice.userFx.resize(option.num_modules);
|
||||
for (std::uint32_t m = 0; m < option.num_modules; m++) {
|
||||
const auto& module = *reinterpret_cast<const Ngs2CustomUserFx2ModuleOption*>(option.module[m].option);
|
||||
rack.userFx[m] = module;
|
||||
rack.userFxCommon[m].resize(module.common_size);
|
||||
for (std::uint32_t i = 0; i < rack.voices.size(); i++) {
|
||||
auto& fx = rack.voices[i].userFx[m];
|
||||
fx.param.resize(module.param_size);
|
||||
fx.work.resize(module.work_size);
|
||||
fx.state.resize(option.module[m].state_size);
|
||||
fx.flags = USER_FX2_FLAG_FIRST_PROCESS;
|
||||
if (module.setup_handler == nullptr) continue;
|
||||
auto context = UserFxContext(rack, m, i);
|
||||
const int result = module.setup_handler(&context);
|
||||
if (result != SCE_NGS2_OK) throw std::runtime_error("NGS2: the UserFx2 setup handler failed with " + std::to_string(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ngs2CleanupUserFx(Ngs2Rack& rack) {
|
||||
for (std::uint32_t i = 0; i < rack.voices.size(); i++) {
|
||||
for (std::size_t m = 0; m < rack.userFx.size(); m++) {
|
||||
if (rack.userFx[m].cleanup_handler == nullptr) continue;
|
||||
auto context = UserFxContext(rack, m, i);
|
||||
const int result = rack.userFx[m].cleanup_handler(&context);
|
||||
if (result != SCE_NGS2_OK) throw std::runtime_error("NGS2: the UserFx2 cleanup handler failed with " + std::to_string(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SetupCustomSubmixer(Ngs2Voice& voice, const Ngs2CustomSubmixerVoiceSetupParam& setup) {
|
||||
if (setup.flags != 0) throw std::runtime_error("NGS2: custom submixer setup flags are not implemented");
|
||||
if (setup.num_input_channels != setup.num_output_channels) throw std::runtime_error("NGS2: custom submixer channel conversion is not implemented");
|
||||
if (setup.num_input_channels == 0 || setup.num_input_channels > voice.rack->maxChannels) APS5_INVALID_ARG_EX;
|
||||
voice.channels = setup.num_input_channels;
|
||||
}
|
||||
|
||||
static void SetUserFxParam(Ngs2Voice& voice, std::uint32_t index, const Ngs2CustomVoiceUserFx2Param& param) {
|
||||
if (index >= voice.userFx.size()) APS5_INVALID_ARG_EX;
|
||||
const auto& module = voice.rack->userFx[index];
|
||||
if (module.control_handler != nullptr) throw std::runtime_error("NGS2: the UserFx2 control handler is not implemented");
|
||||
auto& fx = voice.userFx[index];
|
||||
if (param.data_size != fx.param.size() || (param.data == nullptr && param.data_size != 0)) APS5_INVALID_ARG_EX;
|
||||
if (param.data_size != 0) std::memcpy(fx.param.data(), param.data, param.data_size);
|
||||
fx.flags |= USER_FX2_FLAG_PARAM_CHANGED;
|
||||
}
|
||||
|
||||
void Ngs2ApplyCustomParam(Ngs2Voice& voice, const Ngs2VoiceParamHeader& param) {
|
||||
if (voice.rack->rackId != SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) throw std::invalid_argument("NGS2: voice param " + Ngs2Hex(param.id) + " belongs to another rack");
|
||||
if (param.id == SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP) {
|
||||
SetupCustomSubmixer(voice, ParamAs<Ngs2CustomSubmixerVoiceSetupParam>(param));
|
||||
return;
|
||||
}
|
||||
if ((param.id & ~0x1fu) == SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2) {
|
||||
SetUserFxParam(voice, param.id & 0x1f, ParamAs<Ngs2CustomVoiceUserFx2Param>(param));
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("NGS2: voice param " + Ngs2Hex(param.id) + " is not implemented");
|
||||
}
|
||||
|
||||
void Ngs2ProcessUserFx(Ngs2Voice& voice, std::uint32_t grain, std::uint32_t sampleRate) {
|
||||
if (voice.userFx.empty()) return;
|
||||
std::vector<float*> channels(voice.channels);
|
||||
for (std::uint32_t c = 0; c < voice.channels; c++) channels[c] = voice.samples.data() + static_cast<std::size_t>(c) * grain;
|
||||
for (std::size_t m = 0; m < voice.userFx.size(); m++) {
|
||||
auto& fx = voice.userFx[m];
|
||||
const auto& module = voice.rack->userFx[m];
|
||||
Ngs2UserFx2ProcessContext context{channels.data(), voice.rack->userFxCommon[m].data(), fx.param.data(), fx.work.data(), fx.state.data(),
|
||||
module.user_data, fx.flags, voice.channels, voice.channels, grain, sampleRate, 0, {}};
|
||||
const int result = module.process_handler(&context);
|
||||
if (result != SCE_NGS2_OK) throw std::runtime_error("NGS2: the UserFx2 process handler failed with " + std::to_string(result));
|
||||
fx.flags = 0;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -47,12 +48,37 @@ struct Ngs2Atrac9 {
|
||||
|
||||
struct Ngs2Voice;
|
||||
|
||||
struct Ngs2FilterHistory {
|
||||
double x1 = 0.0;
|
||||
double x2 = 0.0;
|
||||
double y1 = 0.0;
|
||||
double y2 = 0.0;
|
||||
};
|
||||
|
||||
struct Ngs2Filter {
|
||||
bool enabled = false;
|
||||
std::uint64_t bypassMask = 0;
|
||||
double b0 = 1.0;
|
||||
double b1 = 0.0;
|
||||
double b2 = 0.0;
|
||||
double a1 = 0.0;
|
||||
double a2 = 0.0;
|
||||
std::vector<Ngs2FilterHistory> history;
|
||||
};
|
||||
|
||||
struct Ngs2Port {
|
||||
Ngs2Voice* dest = nullptr;
|
||||
float volume = 1.0f;
|
||||
std::int32_t matrix = -1;
|
||||
};
|
||||
|
||||
struct Ngs2UserFx2 {
|
||||
std::vector<std::uint8_t> param;
|
||||
std::vector<std::uint8_t> work;
|
||||
std::vector<std::uint8_t> state;
|
||||
std::uint32_t flags = 0;
|
||||
};
|
||||
|
||||
struct Ngs2Voice {
|
||||
Ngs2Rack* rack = nullptr;
|
||||
Ngs2PlayState state = Ngs2PlayState::Empty;
|
||||
@@ -73,7 +99,9 @@ struct Ngs2Voice {
|
||||
std::uint32_t callbackFlags = 0;
|
||||
std::vector<Ngs2Port> ports;
|
||||
std::vector<std::vector<float>> matrices;
|
||||
std::vector<Ngs2Filter> filters;
|
||||
std::uint32_t outputId = 0;
|
||||
std::vector<Ngs2UserFx2> userFx;
|
||||
std::vector<float> samples;
|
||||
bool rendering = false;
|
||||
bool rendered = false;
|
||||
@@ -88,9 +116,12 @@ struct Ngs2Rack {
|
||||
Ngs2System* system = nullptr;
|
||||
std::uint32_t rackId = 0;
|
||||
std::uint32_t maxChannels = 0;
|
||||
std::uint32_t maxFilters = 0;
|
||||
Ngs2ContextBufferInfo bufferInfo{};
|
||||
Ngs2BufferAllocator allocator{};
|
||||
std::vector<Ngs2Voice> voices;
|
||||
std::vector<Ngs2CustomUserFx2ModuleOption> userFx;
|
||||
std::vector<std::vector<std::uint8_t>> userFxCommon;
|
||||
};
|
||||
|
||||
struct Ngs2System {
|
||||
@@ -99,12 +130,20 @@ struct Ngs2System {
|
||||
Ngs2BufferAllocator allocator{};
|
||||
std::uint32_t uid = 0;
|
||||
std::int64_t renderCount = 0;
|
||||
std::uintptr_t userData = 0;
|
||||
std::vector<Ngs2Rack*> racks;
|
||||
};
|
||||
|
||||
std::string Ngs2Hex(std::uint32_t value);
|
||||
std::recursive_mutex& Ngs2Mutex();
|
||||
Ngs2System* Ngs2FindSystem(Ngs2Handle handle);
|
||||
|
||||
template <typename TParam>
|
||||
const TParam& ParamAs(const Ngs2VoiceParamHeader& param) {
|
||||
if (param.size < sizeof(TParam)) throw std::invalid_argument("NGS2: voice param " + Ngs2Hex(param.id) + " is too small");
|
||||
return reinterpret_cast<const TParam&>(param);
|
||||
}
|
||||
|
||||
Ngs2Rack* Ngs2FindRack(Ngs2Handle handle);
|
||||
Ngs2Voice* Ngs2FindVoice(Ngs2Handle handle);
|
||||
void* Ngs2Place(const Ngs2ContextBufferInfo* bufferInfo, std::size_t size, std::size_t alignment);
|
||||
@@ -114,6 +153,11 @@ void Ngs2SetupAtrac9(Ngs2Voice& voice, const Ngs2WaveformFormat& format);
|
||||
std::size_t Ngs2Atrac9BlockBytes(const Ngs2Voice& voice, const Ngs2WaveformBlock& block);
|
||||
void Ngs2RestartAtrac9(Ngs2Voice& voice);
|
||||
const float* Ngs2Atrac9Frame(Ngs2Voice& voice, Ngs2Block& block, std::uint32_t frame);
|
||||
void Ngs2CheckCustomRack(const Ngs2CustomRackOption& option);
|
||||
void Ngs2SetupUserFx(Ngs2Rack& rack, const Ngs2CustomRackOption& option);
|
||||
void Ngs2CleanupUserFx(Ngs2Rack& rack);
|
||||
void Ngs2ApplyCustomParam(Ngs2Voice& voice, const Ngs2VoiceParamHeader& param);
|
||||
void Ngs2ProcessUserFx(Ngs2Voice& voice, std::uint32_t grain, std::uint32_t sampleRate);
|
||||
void Ngs2RenderSystem(Ngs2System& system, const Ngs2RenderBufferInfo* bufferInfo, std::uint32_t numBufferInfo);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@ union RackOptions {
|
||||
Ngs2SamplerRackOption sampler;
|
||||
Ngs2SubmixerRackOption submixer;
|
||||
Ngs2MasteringRackOption mastering;
|
||||
Ngs2CustomSubmixerRackOption customSubmixer;
|
||||
};
|
||||
|
||||
static std::size_t RackOptionSize(std::uint32_t rackId) {
|
||||
@@ -23,11 +24,13 @@ static std::size_t RackOptionSize(std::uint32_t rackId) {
|
||||
case SCE_NGS2_RACK_ID_SAMPLER: return sizeof(Ngs2SamplerRackOption);
|
||||
case SCE_NGS2_RACK_ID_SUBMIXER: return sizeof(Ngs2SubmixerRackOption);
|
||||
case SCE_NGS2_RACK_ID_MASTERING: return sizeof(Ngs2MasteringRackOption);
|
||||
case SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER: return sizeof(Ngs2CustomSubmixerRackOption);
|
||||
default: throw std::runtime_error("NGS2: rack id " + Ngs2Hex(rackId) + " is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
static RackOptions DefaultRackOption(std::uint32_t rackId) {
|
||||
if (rackId == SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) throw std::runtime_error("NGS2: default custom rack options are not implemented");
|
||||
RackOptions options{};
|
||||
auto& common = options.common;
|
||||
common.size = RackOptionSize(rackId);
|
||||
@@ -69,6 +72,7 @@ static RackOptions DefaultRackOption(std::uint32_t rackId) {
|
||||
static std::uint32_t RackMaxChannels(std::uint32_t rackId, const RackOptions& options) {
|
||||
if (rackId == SCE_NGS2_RACK_ID_SUBMIXER) return options.submixer.max_channels;
|
||||
if (rackId == SCE_NGS2_RACK_ID_MASTERING) return options.mastering.max_channels;
|
||||
if (rackId == SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) return options.customSubmixer.max_channels;
|
||||
return NGS2_MAX_CHANNELS;
|
||||
}
|
||||
|
||||
@@ -82,6 +86,7 @@ static RackOptions CheckedRackOption(std::uint32_t rackId, const Ngs2RackOption*
|
||||
if (options.common.max_voices == 0 || maxChannels == 0 || maxChannels > NGS2_MAX_CHANNELS) {
|
||||
throw std::invalid_argument("NGS2: invalid rack voice or channel count");
|
||||
}
|
||||
if (rackId == SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) Ngs2CheckCustomRack(options.customSubmixer.custom_rack_option);
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -93,6 +98,7 @@ static int CreateRack(Ngs2Handle systemHandle, std::uint32_t rackId, const RackO
|
||||
rack->system = system;
|
||||
rack->rackId = rackId;
|
||||
rack->maxChannels = RackMaxChannels(rackId, options);
|
||||
rack->maxFilters = rackId == SCE_NGS2_RACK_ID_SAMPLER ? options.sampler.max_filters : 0;
|
||||
rack->bufferInfo = bufferInfo;
|
||||
rack->allocator = allocator;
|
||||
rack->voices.resize(options.common.max_voices);
|
||||
@@ -101,12 +107,14 @@ static int CreateRack(Ngs2Handle systemHandle, std::uint32_t rackId, const RackO
|
||||
voice.ports.resize(options.common.max_ports);
|
||||
voice.matrices.resize(options.common.max_matrices);
|
||||
}
|
||||
if (rackId == SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) Ngs2SetupUserFx(*rack, options.customSubmixer.custom_rack_option);
|
||||
system->racks.push_back(rack);
|
||||
*handle = reinterpret_cast<Ngs2Handle>(rack);
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int Ngs2DestroyRack(Ngs2Rack& rack, Ngs2ContextBufferInfo* outBufferInfo) {
|
||||
Ngs2CleanupUserFx(rack);
|
||||
auto& racks = rack.system->racks;
|
||||
std::erase(racks, &rack);
|
||||
for (auto* other : racks) {
|
||||
|
||||
@@ -99,7 +99,46 @@ static void ConsumeSamples(Ngs2Voice& voice, std::uint32_t grain, std::uint32_t
|
||||
voice.phase &= PHASE_FRACTION;
|
||||
}
|
||||
voice.hasSamples = written != 0;
|
||||
if (voice.state == Ngs2PlayState::Playing && voice.blocks.empty() && !voice.acceptsBlocks) voice.state = Ngs2PlayState::Empty;
|
||||
}
|
||||
|
||||
static bool Bypasses(const Ngs2Filter& filter, std::uint32_t channel) {
|
||||
return channel < 64 && (filter.bypassMask & (std::uint64_t{1} << channel)) != 0;
|
||||
}
|
||||
|
||||
static bool HasHistory(const Ngs2Filter& filter) {
|
||||
if (!filter.enabled) return false;
|
||||
for (std::uint32_t channel = 0; channel < filter.history.size(); channel++) {
|
||||
const auto& h = filter.history[channel];
|
||||
if (!Bypasses(filter, channel) && (h.x1 != 0.0 || h.x2 != 0.0 || h.y1 != 0.0 || h.y2 != 0.0)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ApplyFilter(Ngs2Voice& voice, Ngs2Filter& filter, std::uint32_t grain) {
|
||||
for (std::uint32_t channel = 0; channel < voice.channels; channel++) {
|
||||
if (Bypasses(filter, channel)) continue;
|
||||
auto& h = filter.history[channel];
|
||||
for (std::uint32_t i = 0; i < grain; i++) {
|
||||
auto& sample = voice.samples[channel * grain + i];
|
||||
const double x = sample;
|
||||
double y = filter.b0 * x + filter.b1 * h.x1 + filter.b2 * h.x2 - filter.a1 * h.y1 - filter.a2 * h.y2;
|
||||
if (std::abs(y) < 1e-20) y = 0.0;
|
||||
h = {x, h.x1, y, h.y1};
|
||||
sample = static_cast<float>(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void RenderSampler(Ngs2Voice& voice, std::uint32_t grain, std::uint32_t systemRate) {
|
||||
ConsumeSamples(voice, grain, systemRate);
|
||||
for (auto& filter : voice.filters) {
|
||||
if (!filter.enabled || (!voice.hasSamples && !HasHistory(filter))) continue;
|
||||
ApplyFilter(voice, filter, grain);
|
||||
voice.hasSamples = true;
|
||||
}
|
||||
if (voice.state == Ngs2PlayState::Playing && voice.blocks.empty() && !voice.acceptsBlocks && std::none_of(voice.filters.begin(), voice.filters.end(), HasHistory)) {
|
||||
voice.state = Ngs2PlayState::Empty;
|
||||
}
|
||||
}
|
||||
|
||||
static void RenderVoice(Ngs2Voice& voice, const std::vector<Ngs2Voice*>& voices, std::uint32_t grain, std::uint32_t systemRate);
|
||||
@@ -135,8 +174,9 @@ static void RenderVoice(Ngs2Voice& voice, const std::vector<Ngs2Voice*>& voices,
|
||||
voice.samples.assign(static_cast<std::size_t>(grain) * voice.channels, 0.0f);
|
||||
voice.hasSamples = false;
|
||||
if (voice.state == Ngs2PlayState::Playing && voice.channels != 0) {
|
||||
if (voice.rack->rackId == SCE_NGS2_RACK_ID_SAMPLER) ConsumeSamples(voice, grain, systemRate);
|
||||
if (voice.rack->rackId == SCE_NGS2_RACK_ID_SAMPLER) RenderSampler(voice, grain, systemRate);
|
||||
else MixInputs(voice, voices, grain, systemRate);
|
||||
if (voice.hasSamples) Ngs2ProcessUserFx(voice, grain, systemRate);
|
||||
}
|
||||
voice.rendering = false;
|
||||
voice.rendered = true;
|
||||
|
||||
@@ -188,6 +188,55 @@ int APS5_VABI sceNgs2SystemSetGrainSamples(uintptr_t system_handle, uint32_t num
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemSetSampleRate(uintptr_t system_handle, uint32_t sample_rate) {
|
||||
std::lock_guard lock(Ngs2Mutex());
|
||||
auto* system = Ngs2FindSystem(system_handle);
|
||||
if (system == nullptr) return SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||
if (sample_rate == 0) APS5_INVALID_ARG_EX;
|
||||
for (const auto* rack : system->racks) {
|
||||
for (const auto& voice : rack->voices) {
|
||||
for (const auto& filter : voice.filters) {
|
||||
if (filter.enabled && sample_rate != system->option.sample_rate) {
|
||||
throw std::runtime_error("NGS2: changing the sample rate under an enabled sampler filter is not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
system->option.sample_rate = sample_rate;
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemSetUserData(uintptr_t system_handle, uintptr_t user_data) {
|
||||
std::lock_guard lock(Ngs2Mutex());
|
||||
auto* system = Ngs2FindSystem(system_handle);
|
||||
if (system == nullptr) return SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||
system->userData = user_data;
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemGetUserData(uintptr_t system_handle, uintptr_t* user_data) {
|
||||
std::lock_guard lock(Ngs2Mutex());
|
||||
const auto* system = Ngs2FindSystem(system_handle);
|
||||
if (system == nullptr) return SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||
if (user_data == nullptr) APS5_INVALID_ARG_EX;
|
||||
*user_data = system->userData;
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemLock(uintptr_t system_handle) {
|
||||
Ngs2Mutex().lock();
|
||||
if (Ngs2FindSystem(system_handle) != nullptr) return SCE_NGS2_OK;
|
||||
Ngs2Mutex().unlock();
|
||||
return SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemUnlock(uintptr_t system_handle) {
|
||||
std::lock_guard lock(Ngs2Mutex());
|
||||
if (Ngs2FindSystem(system_handle) == nullptr) return SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE;
|
||||
Ngs2Mutex().unlock();
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
int APS5_VABI sceNgs2SystemRender(uintptr_t system_handle, const Ngs2RenderBufferInfo* buffer_info, uint32_t num_buffer_info) {
|
||||
std::lock_guard lock(Ngs2Mutex());
|
||||
auto* system = Ngs2FindSystem(system_handle);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <numbers>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@@ -47,6 +48,7 @@ void Ngs2Voice::ResetSetup() {
|
||||
SetEvent(SCE_NGS2_VOICE_EVENT_STOP_IMM);
|
||||
std::fill(ports.begin(), ports.end(), Ngs2Port{});
|
||||
for (auto& matrix : matrices) matrix.clear();
|
||||
filters.clear();
|
||||
channels = 0;
|
||||
sampleRate = 0;
|
||||
waveformType = 0;
|
||||
@@ -67,12 +69,6 @@ const std::uint8_t* Ngs2Voice::WaveformData() const {
|
||||
return block.data + (static_cast<std::size_t>(block.info.num_skip_samples) + block.cursor) * channels * sizeof(std::int16_t);
|
||||
}
|
||||
|
||||
template <typename TParam>
|
||||
static const TParam& ParamAs(const Ngs2VoiceParamHeader& param) {
|
||||
if (param.size < sizeof(TParam)) throw std::invalid_argument("NGS2: voice param " + Ngs2Hex(param.id) + " is too small");
|
||||
return reinterpret_cast<const TParam&>(param);
|
||||
}
|
||||
|
||||
static Ngs2Port& PortAt(Ngs2Voice& voice, std::uint32_t port) {
|
||||
if (port >= voice.ports.size()) throw std::invalid_argument("NGS2: voice port " + std::to_string(port) + " is out of range");
|
||||
return voice.ports[port];
|
||||
@@ -178,6 +174,40 @@ static void AddWaveformBlocks(Ngs2Voice& voice, const Ngs2SamplerVoiceWaveformBl
|
||||
}
|
||||
}
|
||||
|
||||
static void SetFilter(Ngs2Voice& voice, const Ngs2SamplerVoiceFilterParam& param) {
|
||||
if (param.index >= voice.rack->maxFilters) APS5_INVALID_ARG_EX;
|
||||
if (voice.filters.size() <= param.index) voice.filters.resize(param.index + 1);
|
||||
auto& filter = voice.filters[param.index];
|
||||
if (param.type == 0) {
|
||||
filter = {};
|
||||
return;
|
||||
}
|
||||
if (param.location != 1 || param.type != 1) {
|
||||
throw std::runtime_error("NGS2: sampler filter location " + std::to_string(param.location) + " type " + std::to_string(param.type) + " is not implemented");
|
||||
}
|
||||
if (!std::isfinite(param.frequency) || param.frequency < 0.0f || !std::isfinite(param.q) || param.q <= 0.0f || !std::isfinite(param.level) || param.level < 0.0f) {
|
||||
APS5_INVALID_ARG_EX;
|
||||
}
|
||||
const double rate = voice.rack->system->option.sample_rate;
|
||||
filter.enabled = true;
|
||||
filter.bypassMask = param.channel_mask;
|
||||
filter.history.resize(voice.channels);
|
||||
if (param.frequency == 0.0f || param.frequency >= rate * 0.5) {
|
||||
filter.b0 = param.frequency == 0.0f ? 0.0 : param.level;
|
||||
filter.b1 = filter.b2 = filter.a1 = filter.a2 = 0.0;
|
||||
return;
|
||||
}
|
||||
const double omega = 2.0 * std::numbers::pi * param.frequency / rate;
|
||||
const double cosine = std::cos(omega);
|
||||
const double alpha = std::sin(omega) / (2.0 * param.q);
|
||||
const double inverseA0 = 1.0 / (1.0 + alpha);
|
||||
filter.b0 = (1.0 - cosine) * 0.5 * inverseA0 * param.level;
|
||||
filter.b1 = 2.0 * filter.b0;
|
||||
filter.b2 = filter.b0;
|
||||
filter.a1 = -2.0 * cosine * inverseA0;
|
||||
filter.a2 = (1.0 - alpha) * inverseA0;
|
||||
}
|
||||
|
||||
static void ApplySamplerParam(Ngs2Voice& voice, const Ngs2VoiceParamHeader& param) {
|
||||
switch (param.id) {
|
||||
case SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP: SetupSampler(voice, ParamAs<Ngs2SamplerVoiceSetupParam>(param).format); break;
|
||||
@@ -193,6 +223,7 @@ static void ApplySamplerParam(Ngs2Voice& voice, const Ngs2VoiceParamHeader& para
|
||||
voice.pitch = ratio;
|
||||
break;
|
||||
}
|
||||
case SCE_NGS2_SAMPLER_VOICE_PARAM_FILTER: SetFilter(voice, ParamAs<Ngs2SamplerVoiceFilterParam>(param)); break;
|
||||
default: throw std::runtime_error("NGS2: sampler voice param " + Ngs2Hex(param.id) + " is not implemented");
|
||||
}
|
||||
}
|
||||
@@ -209,6 +240,10 @@ static void ApplyParam(Ngs2Voice& voice, const Ngs2VoiceParamHeader& param) {
|
||||
ApplyCommonParam(voice, param);
|
||||
return;
|
||||
}
|
||||
if (rackId == (SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 >> 16) || rackId == SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER) {
|
||||
Ngs2ApplyCustomParam(voice, param);
|
||||
return;
|
||||
}
|
||||
if (rackId != voice.rack->rackId) throw std::invalid_argument("NGS2: voice param " + Ngs2Hex(param.id) + " belongs to another rack");
|
||||
switch (rackId) {
|
||||
case SCE_NGS2_RACK_ID_SAMPLER: ApplySamplerParam(voice, param); return;
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
#include "Ngs2Test.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
struct Calls {
|
||||
std::vector<std::uint32_t> setupVoices;
|
||||
std::vector<std::uint32_t> cleanupVoices;
|
||||
std::vector<std::uint32_t> processFlags;
|
||||
std::vector<int> order;
|
||||
int processResult = SCE_NGS2_OK;
|
||||
};
|
||||
static Calls calls;
|
||||
|
||||
static std::int32_t APS5_VABI Setup(Ngs2UserFx2SetupContext* context) {
|
||||
Require(context->common != nullptr && context->param != nullptr && context->work != nullptr);
|
||||
Require(context->user_data == 0x77 && context->max_voices == 2);
|
||||
std::memset(context->work, 0x5a, 8);
|
||||
*static_cast<float*>(context->param) = 1.0f;
|
||||
*static_cast<float*>(context->common) = 0.25f;
|
||||
calls.setupVoices.push_back(context->voice_index);
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
static std::int32_t APS5_VABI Cleanup(Ngs2UserFx2CleanupContext* context) {
|
||||
Require(context->user_data == 0x77 && context->max_voices == 2 && static_cast<std::uint8_t*>(context->work)[7] == 0x5a);
|
||||
calls.cleanupVoices.push_back(context->voice_index);
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
static std::int32_t APS5_VABI Gain(Ngs2UserFx2ProcessContext* context) {
|
||||
Require(context->user_data == 0x77 && context->num_input_channels == 2 && context->num_output_channels == 2);
|
||||
Require(context->num_grain_samples == Grain && context->sample_rate == 48000 && context->state != nullptr);
|
||||
Require(static_cast<const std::uint8_t*>(context->work)[0] == 0x5a);
|
||||
const float gain = *static_cast<const float*>(context->param);
|
||||
for (std::uint32_t c = 0; c < 2; c++) {
|
||||
for (std::uint32_t i = 0; i < Grain; i++) context->channel_data[c][i] *= gain;
|
||||
}
|
||||
*static_cast<float*>(context->common) = 0.125f;
|
||||
calls.processFlags.push_back(context->flags);
|
||||
calls.order.push_back(0);
|
||||
return calls.processResult;
|
||||
}
|
||||
|
||||
static std::int32_t APS5_VABI Offset(Ngs2UserFx2ProcessContext* context) {
|
||||
const float offset = *static_cast<const float*>(context->common);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) context->channel_data[1][i] += offset;
|
||||
calls.order.push_back(1);
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
static std::int32_t APS5_VABI ControlHandler(Ngs2UserFx2ControlContext*) {
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
static Ngs2CustomUserFx2ModuleOption Module(Ngs2UserFx2ProcessHandler process) {
|
||||
return {{sizeof(Ngs2CustomUserFx2ModuleOption)}, Setup, Cleanup, nullptr, process, sizeof(float), sizeof(float), 8, 0x77};
|
||||
}
|
||||
|
||||
static Ngs2CustomSubmixerRackOption RackOption(const Ngs2CustomUserFx2ModuleOption* modules, std::uint32_t count) {
|
||||
Ngs2CustomSubmixerRackOption option{};
|
||||
auto& common = option.custom_rack_option.rack_option;
|
||||
common.size = sizeof(option);
|
||||
common.max_grain_samples = 512;
|
||||
common.max_voices = 2;
|
||||
common.max_matrices = 1;
|
||||
common.max_ports = 1;
|
||||
option.custom_rack_option.num_buffers = 1;
|
||||
option.custom_rack_option.num_modules = count;
|
||||
for (std::uint32_t m = 0; m < count; m++) {
|
||||
option.custom_rack_option.module[m].option = &modules[m].custom_module_option;
|
||||
option.custom_rack_option.module[m].module_id = SCE_NGS2_CUSTOM_MODULE_ID_USER_FX2;
|
||||
option.custom_rack_option.module[m].state_size = 16;
|
||||
}
|
||||
option.max_channels = 2;
|
||||
option.max_inputs = 1;
|
||||
return option;
|
||||
}
|
||||
|
||||
template <typename TException>
|
||||
static bool CreateThrows(const Ngs2CustomSubmixerRackOption& option) {
|
||||
Ngs2ContextBufferInfo query{};
|
||||
try {
|
||||
sceNgs2RackQueryBufferSize(SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER, &option.custom_rack_option.rack_option, &query);
|
||||
} catch (const TException&) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename TException, typename TParam>
|
||||
static bool ControlThrows(uintptr_t voice, std::uint32_t id, TParam param) {
|
||||
param.header = {static_cast<std::uint16_t>(sizeof(TParam)), 0, id};
|
||||
try {
|
||||
sceNgs2VoiceControl(voice, ¶m.header);
|
||||
} catch (const TException&) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uintptr_t CustomRack(uintptr_t system, const Ngs2CustomSubmixerRackOption& option) {
|
||||
Ngs2ContextBufferInfo query{};
|
||||
Require(sceNgs2RackQueryBufferSize(SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER, &option.custom_rack_option.rack_option, &query) == SCE_NGS2_OK);
|
||||
const auto info = Buffer(query);
|
||||
uintptr_t rack = 0;
|
||||
Require(sceNgs2RackCreate(system, SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER, &option.custom_rack_option.rack_option, &info, &rack) == SCE_NGS2_OK);
|
||||
return rack;
|
||||
}
|
||||
|
||||
static uintptr_t Sampler(uintptr_t system, const std::vector<std::int16_t>& pcm) {
|
||||
const auto voice = Voice(CreateRack(system, SCE_NGS2_RACK_ID_SAMPLER));
|
||||
Control(voice, SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP, Ngs2SamplerVoiceSetupParam{{}, {SCE_NGS2_WAVEFORM_TYPE_PCM_I16L, 2, 48000, 0, 0, 0}});
|
||||
const Ngs2WaveformBlock block{0, pcm.size() * sizeof(std::int16_t), 0, 0, static_cast<std::uint32_t>(pcm.size() / 2), 0, 0};
|
||||
Control(voice, SCE_NGS2_SAMPLER_VOICE_PARAM_ADD_WAVEFORM_BLOCKS, Ngs2SamplerVoiceWaveformBlocksParam{{}, pcm.data(), 0, 1, &block});
|
||||
return voice;
|
||||
}
|
||||
|
||||
static std::vector<float> Render(uintptr_t system) {
|
||||
std::vector<float> out(Grain * 2, -1.0f);
|
||||
const Ngs2RenderBufferInfo info{out.data(), out.size() * sizeof(float), SCE_NGS2_WAVEFORM_TYPE_PCM_F32L, 2};
|
||||
Require(sceNgs2SystemRender(system, &info, 1) == SCE_NGS2_OK);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void TestUserFxChain() {
|
||||
calls = {};
|
||||
const auto system = CreateSystem();
|
||||
const auto master = Mastering(system, 2);
|
||||
const Ngs2CustomUserFx2ModuleOption modules[2] = {Module(Gain), Module(Offset)};
|
||||
const auto rack = CustomRack(system, RackOption(modules, 2));
|
||||
Require(calls.setupVoices == (std::vector<std::uint32_t>{0, 1, 0, 1}));
|
||||
|
||||
const auto custom = Voice(rack);
|
||||
Control(custom, SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP, Ngs2CustomSubmixerVoiceSetupParam{{}, 2, 2, 0, 0});
|
||||
Patch(custom, master);
|
||||
Event(custom, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
|
||||
std::vector<std::int16_t> pcm(Grain * 2 * 8, 16384);
|
||||
const auto sampler = Sampler(system, pcm);
|
||||
Patch(sampler, custom);
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
|
||||
auto out = Render(system);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) Require(out[i * 2] == 0.5f && out[i * 2 + 1] == 0.75f);
|
||||
Require(calls.processFlags == (std::vector<std::uint32_t>{1}) && calls.order == (std::vector<int>{0, 1}));
|
||||
|
||||
const float gain = 0.5f;
|
||||
Control(custom, SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 | 0, Ngs2CustomVoiceUserFx2Param{{}, &gain, sizeof(gain)});
|
||||
out = Render(system);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) Require(out[i * 2] == 0.25f && out[i * 2 + 1] == 0.5f);
|
||||
Require(calls.processFlags == (std::vector<std::uint32_t>{1, 2}));
|
||||
out = Render(system);
|
||||
Require(calls.processFlags == (std::vector<std::uint32_t>{1, 2, 0}));
|
||||
|
||||
Require(ControlThrows<std::invalid_argument>(custom, SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 | 0, Ngs2CustomVoiceUserFx2Param{{}, &gain, sizeof(gain) - 1}));
|
||||
Require(ControlThrows<std::invalid_argument>(custom, SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 | 2, Ngs2CustomVoiceUserFx2Param{{}, &gain, sizeof(gain)}));
|
||||
Require(ControlThrows<std::runtime_error>(custom, SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP, Ngs2CustomSubmixerVoiceSetupParam{{}, 2, 1, 0, 0}));
|
||||
Require(ControlThrows<std::runtime_error>(custom, SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP, Ngs2CustomSubmixerVoiceSetupParam{{}, 2, 2, 1, 0}));
|
||||
Require(ControlThrows<std::invalid_argument>(custom, SCE_NGS2_CUSTOM_SUBMIXER_VOICE_PARAM_SETUP, Ngs2CustomSubmixerVoiceSetupParam{{}, 3, 3, 0, 0}));
|
||||
Require(ControlThrows<std::invalid_argument>(sampler, SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 | 0, Ngs2CustomVoiceUserFx2Param{{}, &gain, sizeof(gain)}));
|
||||
|
||||
calls.processResult = -1;
|
||||
bool failed = false;
|
||||
try {
|
||||
Render(system);
|
||||
} catch (const std::runtime_error&) {
|
||||
failed = true;
|
||||
}
|
||||
Require(failed);
|
||||
calls.processResult = SCE_NGS2_OK;
|
||||
|
||||
Require(sceNgs2RackDestroy(rack, nullptr) == SCE_NGS2_OK);
|
||||
Require(calls.cleanupVoices == (std::vector<std::uint32_t>{0, 0, 1, 1}));
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestRackOptions() {
|
||||
calls = {};
|
||||
const auto system = CreateSystem();
|
||||
const Ngs2CustomUserFx2ModuleOption modules[1] = {Module(Gain)};
|
||||
const auto good = RackOption(modules, 1);
|
||||
Ngs2ContextBufferInfo query{};
|
||||
Require(sceNgs2RackQueryBufferSize(SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER, &good.custom_rack_option.rack_option, &query) == SCE_NGS2_OK);
|
||||
|
||||
auto option = good;
|
||||
option.custom_rack_option.num_buffers = 2;
|
||||
Require(CreateThrows<std::runtime_error>(option));
|
||||
option = good;
|
||||
option.custom_rack_option.module[0].module_id = 0x10;
|
||||
Require(CreateThrows<std::runtime_error>(option));
|
||||
option = good;
|
||||
option.custom_rack_option.module[0].dest_buffer_id = 1;
|
||||
Require(CreateThrows<std::invalid_argument>(option));
|
||||
option = good;
|
||||
option.custom_rack_option.port[0].source_buffer_id = 1;
|
||||
Require(CreateThrows<std::invalid_argument>(option));
|
||||
option = good;
|
||||
option.custom_rack_option.num_modules = SCE_NGS2_CUSTOM_MAX_MODULES + 1;
|
||||
Require(CreateThrows<std::invalid_argument>(option));
|
||||
auto noProcess = Module(nullptr);
|
||||
option = RackOption(&noProcess, 1);
|
||||
Require(CreateThrows<std::invalid_argument>(option));
|
||||
auto badSize = Module(Gain);
|
||||
badSize.custom_module_option.size = 8;
|
||||
option = RackOption(&badSize, 1);
|
||||
Require(CreateThrows<std::invalid_argument>(option));
|
||||
bool failed = false;
|
||||
try {
|
||||
sceNgs2RackQueryBufferSize(SCE_NGS2_RACK_ID_CUSTOM_SUBMIXER, nullptr, &query);
|
||||
} catch (const std::runtime_error&) {
|
||||
failed = true;
|
||||
}
|
||||
Require(failed && calls.setupVoices.empty());
|
||||
|
||||
auto withControl = Module(Gain);
|
||||
withControl.control_handler = ControlHandler;
|
||||
const auto voice = Voice(CustomRack(system, RackOption(&withControl, 1)));
|
||||
const float gain = 0.5f;
|
||||
Require(ControlThrows<std::runtime_error>(voice, SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 | 0, Ngs2CustomVoiceUserFx2Param{{}, &gain, sizeof(gain)}));
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
Require(calls.cleanupVoices == (std::vector<std::uint32_t>{0, 1}));
|
||||
}
|
||||
|
||||
int main() {
|
||||
TestUserFxChain();
|
||||
TestRackOptions();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
#include "Ngs2Test.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <numbers>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
struct Biquad {
|
||||
double b0, b1, b2, a1, a2;
|
||||
double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0;
|
||||
|
||||
Biquad(double frequency, double q, double level, double rate) {
|
||||
const double w = 2.0 * std::numbers::pi * frequency / rate;
|
||||
const double alpha = std::sin(w) / (2.0 * q);
|
||||
const double a0 = 1.0 + alpha;
|
||||
b0 = (1.0 - std::cos(w)) / 2.0 / a0 * level;
|
||||
b1 = (1.0 - std::cos(w)) / a0 * level;
|
||||
b2 = b0;
|
||||
a1 = -2.0 * std::cos(w) / a0;
|
||||
a2 = (1.0 - alpha) / a0;
|
||||
}
|
||||
|
||||
float Next(double x) {
|
||||
const double y = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
|
||||
x2 = x1;
|
||||
x1 = x;
|
||||
y2 = y1;
|
||||
y1 = y;
|
||||
return static_cast<float>(y);
|
||||
}
|
||||
};
|
||||
|
||||
static Ngs2SamplerVoiceFilterParam Filter(std::uint32_t index, std::uint32_t location, std::uint32_t type, std::uint64_t mask, float frequency, float q, float level) {
|
||||
Ngs2SamplerVoiceFilterParam param{};
|
||||
param.header = {sizeof(param), 0, SCE_NGS2_SAMPLER_VOICE_PARAM_FILTER};
|
||||
param.index = index;
|
||||
param.location = location;
|
||||
param.type = type;
|
||||
param.channel_mask = mask;
|
||||
param.frequency = frequency;
|
||||
param.q = q;
|
||||
param.level = level;
|
||||
return param;
|
||||
}
|
||||
|
||||
static void SetFilter(uintptr_t voice, const Ngs2SamplerVoiceFilterParam& param) {
|
||||
Require(sceNgs2VoiceControl(voice, ¶m.header) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static uintptr_t Sampler(uintptr_t system, const std::vector<std::int16_t>& pcm, std::uint32_t channels, std::uint32_t rate) {
|
||||
const auto voice = Voice(CreateRack(system, SCE_NGS2_RACK_ID_SAMPLER));
|
||||
Control(voice, SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP, Ngs2SamplerVoiceSetupParam{{}, {SCE_NGS2_WAVEFORM_TYPE_PCM_I16L, channels, rate, 0, 0, 0}});
|
||||
const auto frames = static_cast<std::uint32_t>(pcm.size() / channels);
|
||||
const Ngs2WaveformBlock block{0, pcm.size() * sizeof(std::int16_t), 0, 0, frames, 0, 0};
|
||||
Control(voice, SCE_NGS2_SAMPLER_VOICE_PARAM_ADD_WAVEFORM_BLOCKS, Ngs2SamplerVoiceWaveformBlocksParam{{}, pcm.data(), 0, 1, &block});
|
||||
return voice;
|
||||
}
|
||||
|
||||
static std::vector<float> RenderGrain(uintptr_t system, std::uint32_t channels) {
|
||||
std::vector<float> out(Grain * channels, -1.0f);
|
||||
const Ngs2RenderBufferInfo info{out.data(), out.size() * sizeof(float), SCE_NGS2_WAVEFORM_TYPE_PCM_F32L, channels};
|
||||
Require(sceNgs2SystemRender(system, &info, 1) == SCE_NGS2_OK);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void TestLowPassAndTail() {
|
||||
const auto system = CreateSystem();
|
||||
const auto master = Mastering(system, 1);
|
||||
std::vector<std::int16_t> pcm(Grain * 2, 0);
|
||||
pcm[0] = 16384;
|
||||
pcm[5] = -8192;
|
||||
const auto sampler = Sampler(system, pcm, 1, 48000);
|
||||
Patch(sampler, master);
|
||||
const auto param = Filter(7, 1, 1, 0, 1000.0f, 0.70710678f, 0.75f);
|
||||
SetFilter(sampler, param);
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
|
||||
Biquad reference(1000.0, static_cast<double>(0.70710678f), 0.75, 48000.0);
|
||||
for (std::uint32_t grain = 0; grain < 4; grain++) {
|
||||
const auto out = RenderGrain(system, 1);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) {
|
||||
const auto frame = grain * Grain + i;
|
||||
const float expected = reference.Next(frame < pcm.size() ? pcm[frame] / 32768.0 : 0.0);
|
||||
Require(std::abs(out[i] - expected) <= 1e-7f);
|
||||
}
|
||||
Require(out[Grain - 1] != 0.0f);
|
||||
Require(Flags(sampler) == (SCE_NGS2_VOICE_STATE_FLAG_INUSE | SCE_NGS2_VOICE_STATE_FLAG_PLAYING));
|
||||
SetFilter(sampler, param);
|
||||
}
|
||||
|
||||
SetFilter(sampler, Filter(7, 0, 0, 0, NAN, 0.0f, -1.0f));
|
||||
for (float sample : RenderGrain(system, 1)) Require(sample == 0.0f);
|
||||
Require(Flags(sampler) == 0);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestBypassMaskAndGain() {
|
||||
const auto system = CreateSystem();
|
||||
const auto master = Mastering(system, 2);
|
||||
std::vector<std::int16_t> pcm;
|
||||
for (std::uint32_t i = 0; i < Grain; i++) {
|
||||
pcm.push_back(static_cast<std::int16_t>(i * 1000));
|
||||
pcm.push_back(static_cast<std::int16_t>(-4000 + i * 700));
|
||||
}
|
||||
const auto sampler = Sampler(system, pcm, 2, 48000);
|
||||
Patch(sampler, master);
|
||||
SetFilter(sampler, Filter(0, 1, 1, 1, 24000.0f, 1.0f, 0.5f));
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
|
||||
auto out = RenderGrain(system, 2);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) {
|
||||
Require(out[i * 2] == pcm[i * 2] / 32768.0f);
|
||||
Require(out[i * 2 + 1] == pcm[i * 2 + 1] / 32768.0f * 0.5f);
|
||||
}
|
||||
Require(Flags(sampler) == (SCE_NGS2_VOICE_STATE_FLAG_INUSE | SCE_NGS2_VOICE_STATE_FLAG_PLAYING));
|
||||
out = RenderGrain(system, 2);
|
||||
for (float sample : out) Require(sample == 0.0f);
|
||||
Require(Flags(sampler) == 0);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestSystemRateAndZeroCutoff() {
|
||||
const auto system = CreateSystem();
|
||||
const auto master = Mastering(system, 1);
|
||||
const std::vector<std::int16_t> pcm(Grain * 2, 8192);
|
||||
const auto sampler = Sampler(system, pcm, 1, 24000);
|
||||
Patch(sampler, master);
|
||||
SetFilter(sampler, Filter(0, 1, 1, 0, 18000.0f, 0.70710678f, 1.0f));
|
||||
SetFilter(sampler, Filter(1, 1, 1, 0, 30000.0f, 0.70710678f, 1.0f));
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
Biquad reference(18000.0, static_cast<double>(0.70710678f), 1.0, 48000.0);
|
||||
const auto out = RenderGrain(system, 1);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) Require(std::abs(out[i] - reference.Next(0.25)) <= 1e-7f);
|
||||
|
||||
SetFilter(sampler, Filter(1, 1, 1, 0, 0.0f, 0.70710678f, 1.0f));
|
||||
for (float sample : RenderGrain(system, 1)) Require(sample == 0.0f);
|
||||
|
||||
Control(sampler, SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP, Ngs2SamplerVoiceSetupParam{{}, {SCE_NGS2_WAVEFORM_TYPE_PCM_I16L, 1, 48000, 0, 0, 0}});
|
||||
const Ngs2WaveformBlock block{0, pcm.size() * sizeof(std::int16_t), 0, 0, static_cast<std::uint32_t>(pcm.size()), 0, 0};
|
||||
Control(sampler, SCE_NGS2_SAMPLER_VOICE_PARAM_ADD_WAVEFORM_BLOCKS, Ngs2SamplerVoiceWaveformBlocksParam{{}, pcm.data(), 0, 1, &block});
|
||||
Patch(sampler, master);
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
for (float sample : RenderGrain(system, 1)) Require(sample == 0.25f);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
template <typename TError>
|
||||
static void RequireRejected(uintptr_t voice, const Ngs2SamplerVoiceFilterParam& param) {
|
||||
bool rejected = false;
|
||||
try {
|
||||
sceNgs2VoiceControl(voice, ¶m.header);
|
||||
} catch (const TError&) {
|
||||
rejected = true;
|
||||
}
|
||||
Require(rejected);
|
||||
}
|
||||
|
||||
static void TestRejectedParams() {
|
||||
const auto system = CreateSystem();
|
||||
const auto sampler = Sampler(system, std::vector<std::int16_t>(Grain, 0), 1, 48000);
|
||||
RequireRejected<std::invalid_argument>(sampler, Filter(8, 1, 1, 0, 1000.0f, 1.0f, 1.0f));
|
||||
RequireRejected<std::runtime_error>(sampler, Filter(0, 0, 1, 0, 1000.0f, 1.0f, 1.0f));
|
||||
RequireRejected<std::runtime_error>(sampler, Filter(0, 1, 2, 0, 1000.0f, 1.0f, 1.0f));
|
||||
RequireRejected<std::invalid_argument>(sampler, Filter(0, 1, 1, 0, NAN, 1.0f, 1.0f));
|
||||
RequireRejected<std::invalid_argument>(sampler, Filter(0, 1, 1, 0, -1.0f, 1.0f, 1.0f));
|
||||
RequireRejected<std::invalid_argument>(sampler, Filter(0, 1, 1, 0, 1000.0f, 0.0f, 1.0f));
|
||||
RequireRejected<std::invalid_argument>(sampler, Filter(0, 1, 1, 0, 1000.0f, 1.0f, -0.5f));
|
||||
auto small = Filter(0, 1, 1, 0, 1000.0f, 1.0f, 1.0f);
|
||||
small.header.size = sizeof(small) - 4;
|
||||
RequireRejected<std::invalid_argument>(sampler, small);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestRateChangeUnderFilter() {
|
||||
const auto system = CreateSystem();
|
||||
const auto sampler = Sampler(system, std::vector<std::int16_t>(Grain, 0), 1, 48000);
|
||||
SetFilter(sampler, Filter(0, 1, 1, 0, 1000.0f, 1.0f, 1.0f));
|
||||
Require(sceNgs2SystemSetSampleRate(system, 48000) == SCE_NGS2_OK);
|
||||
bool rejected = false;
|
||||
try {
|
||||
sceNgs2SystemSetSampleRate(system, 96000);
|
||||
} catch (const std::runtime_error&) {
|
||||
rejected = true;
|
||||
}
|
||||
Require(rejected);
|
||||
SetFilter(sampler, Filter(0, 1, 0, 0, 0.0f, 1.0f, 1.0f));
|
||||
Require(sceNgs2SystemSetSampleRate(system, 96000) == SCE_NGS2_OK);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
int main() {
|
||||
TestLowPassAndTail();
|
||||
TestBypassMaskAndGain();
|
||||
TestSystemRateAndZeroCutoff();
|
||||
TestRejectedParams();
|
||||
TestRateChangeUnderFilter();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "Ngs2Test.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
static uintptr_t Sampler(uintptr_t system, const std::vector<std::int16_t>& pcm, std::uint32_t repeats) {
|
||||
@@ -152,6 +156,71 @@ static std::int32_t APS5_VABI Release(Ngs2ContextBufferInfo* info) {
|
||||
return SCE_NGS2_OK;
|
||||
}
|
||||
|
||||
static void TestSampleRate() {
|
||||
const auto system = CreateSystem();
|
||||
Require(sceNgs2SystemSetSampleRate(0x1234, 96000) == SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE);
|
||||
bool threw = false;
|
||||
try {
|
||||
sceNgs2SystemSetSampleRate(system, 0);
|
||||
} catch (const std::invalid_argument&) {
|
||||
threw = true;
|
||||
}
|
||||
Require(threw);
|
||||
Require(sceNgs2SystemSetSampleRate(system, 96000) == SCE_NGS2_OK);
|
||||
Ngs2SystemInfo info{};
|
||||
Require(sceNgs2SystemGetInfo(system, &info, sizeof(info)) == SCE_NGS2_OK && info.sample_rate == 96000);
|
||||
|
||||
const auto master = Mastering(system, 1);
|
||||
const std::vector<std::int16_t> pcm{0, 1000, 2000, 3000};
|
||||
const auto sampler = Sampler(system, pcm, 1);
|
||||
Patch(sampler, master);
|
||||
Event(sampler, SCE_NGS2_VOICE_EVENT_PLAY);
|
||||
const std::int16_t expected[Grain] = {0, 500, 1000, 1500, 2000, 2500, 3000, 1500};
|
||||
const auto out = RenderI16(system);
|
||||
for (std::uint32_t i = 0; i < Grain; i++) Require(out[i] == expected[i]);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestUserData() {
|
||||
uintptr_t value = 1;
|
||||
Require(sceNgs2SystemSetUserData(0x1234, 5) == SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE);
|
||||
Require(sceNgs2SystemGetUserData(0x1234, &value) == SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE && value == 1);
|
||||
const auto system = CreateSystem();
|
||||
Require(sceNgs2SystemGetUserData(system, &value) == SCE_NGS2_OK && value == 0);
|
||||
Require(sceNgs2SystemSetUserData(system, 0xfedcba9876543210) == SCE_NGS2_OK);
|
||||
Require(sceNgs2SystemGetUserData(system, &value) == SCE_NGS2_OK && value == 0xfedcba9876543210);
|
||||
bool threw = false;
|
||||
try {
|
||||
sceNgs2SystemGetUserData(system, nullptr);
|
||||
} catch (const std::invalid_argument&) {
|
||||
threw = true;
|
||||
}
|
||||
Require(threw);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestLock() {
|
||||
const auto system = CreateSystem();
|
||||
Require(sceNgs2SystemLock(0x1234) == SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE);
|
||||
Require(sceNgs2SystemUnlock(0x1234) == SCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE);
|
||||
Ngs2SystemInfo info{};
|
||||
std::thread free([&] { Require(sceNgs2SystemGetInfo(system, &info, sizeof(info)) == SCE_NGS2_OK); });
|
||||
free.join();
|
||||
|
||||
Require(sceNgs2SystemLock(system) == SCE_NGS2_OK);
|
||||
std::atomic<bool> done = false;
|
||||
std::thread blocked([&] {
|
||||
Require(sceNgs2SystemGetInfo(system, &info, sizeof(info)) == SCE_NGS2_OK);
|
||||
done = true;
|
||||
});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
Require(!done);
|
||||
Require(sceNgs2SystemUnlock(system) == SCE_NGS2_OK);
|
||||
blocked.join();
|
||||
Require(done);
|
||||
Require(sceNgs2SystemDestroy(system, nullptr) == SCE_NGS2_OK);
|
||||
}
|
||||
|
||||
static void TestAllocator() {
|
||||
const Ngs2BufferAllocator allocator{Allocate, Release, 9};
|
||||
uintptr_t system = 0;
|
||||
@@ -171,6 +240,9 @@ int main() {
|
||||
TestPcmBlockEnd();
|
||||
TestPitchAndRepeat();
|
||||
TestSubmixerMatrix();
|
||||
TestSampleRate();
|
||||
TestUserData();
|
||||
TestLock();
|
||||
TestAllocator();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ int APS5_VABI sceNgs2SystemCreateWithAllocator(const Ngs2SystemOption*, const Ng
|
||||
int APS5_VABI sceNgs2SystemDestroy(uintptr_t, Ngs2ContextBufferInfo*);
|
||||
int APS5_VABI sceNgs2SystemGetInfo(uintptr_t, Ngs2SystemInfo*, size_t);
|
||||
int APS5_VABI sceNgs2SystemSetGrainSamples(uintptr_t, uint32_t);
|
||||
int APS5_VABI sceNgs2SystemSetSampleRate(uintptr_t, uint32_t);
|
||||
int APS5_VABI sceNgs2SystemSetUserData(uintptr_t, uintptr_t);
|
||||
int APS5_VABI sceNgs2SystemGetUserData(uintptr_t, uintptr_t*);
|
||||
int APS5_VABI sceNgs2SystemLock(uintptr_t);
|
||||
int APS5_VABI sceNgs2SystemUnlock(uintptr_t);
|
||||
int APS5_VABI sceNgs2SystemRender(uintptr_t, const Ngs2RenderBufferInfo*, uint32_t);
|
||||
int APS5_VABI sceNgs2RackQueryBufferSize(uint32_t, const Ngs2RackOption*, Ngs2ContextBufferInfo*);
|
||||
int APS5_VABI sceNgs2RackCreate(uintptr_t, uint32_t, const Ngs2RackOption*, const Ngs2ContextBufferInfo*, uintptr_t*);
|
||||
@@ -40,7 +45,7 @@ inline void Check(bool value, int line) {
|
||||
|
||||
inline constexpr std::uint32_t Grain = 8;
|
||||
|
||||
inline std::vector<std::uint64_t> buffers[16];
|
||||
inline std::vector<std::uint64_t> buffers[32];
|
||||
inline std::size_t usedBuffers = 0;
|
||||
|
||||
inline Ngs2ContextBufferInfo Buffer(const Ngs2ContextBufferInfo& query) {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
add_library(libSceNpCppWebApi SHARED EXCLUDE_FROM_ALL Export.cpp)
|
||||
target_include_directories(libSceNpCppWebApi PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
configure_windows_unwind(libSceNpCppWebApi)
|
||||
|
||||
if(MINGW)
|
||||
foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static)
|
||||
string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_np_cpp_web_api_string_tests ${LIBS_INCLUDE_DIR}/tests/GuestNpCppWebApiString.cpp)
|
||||
target_include_directories(guest_np_cpp_web_api_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_np_cpp_web_api_string_tests PRIVATE libSceNpCppWebApi libc)
|
||||
configure_windows_unwind(guest_np_cpp_web_api_string_tests)
|
||||
add_test(NAME guest_np_cpp_web_api_string COMMAND guest_np_cpp_web_api_string_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_np_cpp_web_api_string PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include "SceTypes.hpp"
|
||||
@@ -107,6 +108,13 @@ std::int64_t localOffsetSeconds(std::uint64_t utcTick) {
|
||||
return localSeconds - static_cast<std::int64_t>(seconds);
|
||||
}
|
||||
|
||||
constexpr const char* WEEKDAY_NAMES[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
constexpr const char* MONTH_NAMES[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
int localOffsetMinutes(const RtcTick& utc) {
|
||||
return static_cast<int>(localOffsetSeconds(utc.tick) / 60);
|
||||
}
|
||||
|
||||
int addTicks(RtcTick* dst, const RtcTick* src, std::int64_t count, std::int64_t unit) {
|
||||
if (!dst || !src) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
if (src->tick > MAX_TICK) return SCE_RTC_ERROR_INVALID_VALUE;
|
||||
@@ -158,6 +166,97 @@ bool parseZoneSuffix(const char*& cursor, std::int64_t& offsetMinutes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool parseName(const char*& cursor, const char* const* names, int count, int& index) {
|
||||
for (index = 0; index < count; ++index) {
|
||||
if (std::strncmp(cursor, names[index], 3) == 0) {
|
||||
cursor += 3;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool parseWeekday(const char*& cursor) {
|
||||
static constexpr const char* names[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
int index = 0;
|
||||
return parseName(cursor, names, 7, index);
|
||||
}
|
||||
|
||||
bool parseMonth(const char*& cursor, int& month) {
|
||||
static constexpr const char* names[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
if (!parseName(cursor, names, 12, month)) return false;
|
||||
++month;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseClock(const char*& cursor, int& hour, int& minute, int& second) {
|
||||
return parseDigits(cursor, 2, hour) && *cursor++ == ':' && parseDigits(cursor, 2, minute) && *cursor++ == ':' && parseDigits(cursor, 2, second);
|
||||
}
|
||||
|
||||
RtcDateTime makeDateTime(int year, int month, int day, int hour, int minute, int second, std::uint32_t microsecond) {
|
||||
return RtcDateTime{static_cast<std::uint16_t>(year), static_cast<std::uint16_t>(month), static_cast<std::uint16_t>(day),
|
||||
static_cast<std::uint16_t>(hour), static_cast<std::uint16_t>(minute), static_cast<std::uint16_t>(second), microsecond};
|
||||
}
|
||||
|
||||
bool parseIsoDateTime(const char* cursor, RtcDateTime& time, std::int64_t& offsetMinutes) {
|
||||
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
|
||||
if (!parseDigits(cursor, 4, year) || *cursor++ != '-' || !parseDigits(cursor, 2, month) || *cursor++ != '-' || !parseDigits(cursor, 2, day)) return false;
|
||||
if (*cursor != 'T' && *cursor != 't' && *cursor != ' ') return false;
|
||||
++cursor;
|
||||
if (!parseClock(cursor, hour, minute, second)) return false;
|
||||
std::uint32_t microsecond = 0;
|
||||
if (*cursor == '.') {
|
||||
++cursor;
|
||||
std::uint32_t scale = 100000;
|
||||
if (*cursor < '0' || *cursor > '9') return false;
|
||||
for (; *cursor >= '0' && *cursor <= '9'; ++cursor, scale /= 10) microsecond += static_cast<std::uint32_t>(*cursor - '0') * scale;
|
||||
}
|
||||
offsetMinutes = 0;
|
||||
if (*cursor != 0 && !parseZoneSuffix(cursor, offsetMinutes)) return false;
|
||||
if (*cursor != 0) return false;
|
||||
time = makeDateTime(year, month, day, hour, minute, second, microsecond);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseRfc2822DateTime(const char* cursor, RtcDateTime& time, std::int64_t& offsetMinutes) {
|
||||
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
|
||||
if (!parseWeekday(cursor) || *cursor++ != ',' || *cursor++ != ' ' || !parseDigits(cursor, 2, day) || *cursor++ != ' ') return false;
|
||||
if (!parseMonth(cursor, month) || *cursor++ != ' ' || !parseDigits(cursor, 4, year) || *cursor++ != ' ' || !parseClock(cursor, hour, minute, second)) return false;
|
||||
offsetMinutes = 0;
|
||||
if (*cursor == ' ') {
|
||||
++cursor;
|
||||
if (std::strcmp(cursor, "GMT") == 0) {
|
||||
cursor += 3;
|
||||
} else if (*cursor == '+' || *cursor == '-') {
|
||||
const int sign = *cursor++ == '-' ? -1 : 1;
|
||||
int offsetHours = 0, offsetMinute = 0;
|
||||
if (!parseDigits(cursor, 2, offsetHours) || !parseDigits(cursor, 2, offsetMinute)) return false;
|
||||
if (offsetHours > 23 || offsetMinute > 59) return false;
|
||||
offsetMinutes = sign * (offsetHours * 60 + offsetMinute);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (*cursor != 0) return false;
|
||||
time = makeDateTime(year, month, day, hour, minute, second, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseAsctimeDateTime(const char* cursor, RtcDateTime& time, std::int64_t& offsetMinutes) {
|
||||
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
|
||||
if (!parseWeekday(cursor) || *cursor++ != ' ' || !parseMonth(cursor, month) || *cursor++ != ' ') return false;
|
||||
if (*cursor == ' ') {
|
||||
++cursor;
|
||||
if (!parseDigits(cursor, 1, day)) return false;
|
||||
} else if (!parseDigits(cursor, 2, day)) {
|
||||
return false;
|
||||
}
|
||||
if (*cursor++ != ' ' || !parseClock(cursor, hour, minute, second) || *cursor++ != ' ' || !parseDigits(cursor, 4, year) || *cursor != 0) return false;
|
||||
offsetMinutes = 0;
|
||||
time = makeDateTime(year, month, day, hour, minute, second, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -286,6 +385,28 @@ int APS5_VABI sceRtcFormatRFC3339(char* date_time, const RtcTick* utc, int time_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceRtcFormatRFC3339LocalTime(char* date_time, const RtcTick* utc) {
|
||||
if (!date_time || !utc) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
return sceRtcFormatRFC3339(date_time, utc, localOffsetMinutes(*utc));
|
||||
}
|
||||
|
||||
int APS5_VABI sceRtcFormatRFC2822(char* date_time, const RtcTick* utc, int time_zone_minutes) {
|
||||
if (!date_time || !utc) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
if (time_zone_minutes < -1439 || time_zone_minutes > 1439) return SCE_RTC_ERROR_INVALID_VALUE;
|
||||
RtcTick local{};
|
||||
if (const int result = addTicks(&local, utc, time_zone_minutes, TICKS_PER_MINUTE); result != 0) return result;
|
||||
const RtcDateTime time = fromTick(local.tick);
|
||||
const int offset = time_zone_minutes < 0 ? -time_zone_minutes : time_zone_minutes;
|
||||
std::snprintf(date_time, 32, "%s, %02u %s %04u %02u:%02u:%02u %c%02d%02d", WEEKDAY_NAMES[(local.tick / TICKS_PER_DAY + 1) % 7], time.day,
|
||||
MONTH_NAMES[time.month - 1], time.year, time.hour, time.minute, time.second, time_zone_minutes < 0 ? '-' : '+', offset / 60, offset % 60);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceRtcFormatRFC2822LocalTime(char* date_time, const RtcTick* utc) {
|
||||
if (!date_time || !utc) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
return sceRtcFormatRFC2822(date_time, utc, localOffsetMinutes(*utc));
|
||||
}
|
||||
|
||||
int APS5_VABI sceRtcParseRFC3339(RtcTick* utc, const char* date_time) {
|
||||
if (!utc || !date_time) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
const char* cursor = date_time;
|
||||
@@ -313,28 +434,13 @@ int APS5_VABI sceRtcParseRFC3339(RtcTick* utc, const char* date_time) {
|
||||
|
||||
int APS5_VABI sceRtcParseDateTime(RtcTick* utc, const char* date_time) {
|
||||
if (!utc || !date_time) return SCE_RTC_ERROR_INVALID_POINTER;
|
||||
const char* cursor = date_time;
|
||||
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
|
||||
bool ok = parseDigits(cursor, 4, year) && *cursor++ == '-' && parseDigits(cursor, 2, month) && *cursor++ == '-' && parseDigits(cursor, 2, day);
|
||||
ok = ok && (*cursor == 'T' || *cursor == 't' || *cursor == ' ');
|
||||
if (ok) ++cursor;
|
||||
ok = ok && parseDigits(cursor, 2, hour) && *cursor++ == ':' && parseDigits(cursor, 2, minute) && *cursor++ == ':' && parseDigits(cursor, 2, second);
|
||||
std::uint32_t microsecond = 0;
|
||||
if (ok && *cursor == '.') {
|
||||
++cursor;
|
||||
std::uint32_t scale = 100000;
|
||||
ok = *cursor >= '0' && *cursor <= '9';
|
||||
for (; ok && *cursor >= '0' && *cursor <= '9'; ++cursor, scale /= 10) microsecond += static_cast<std::uint32_t>(*cursor - '0') * scale;
|
||||
}
|
||||
RtcDateTime time{};
|
||||
std::int64_t offsetMinutes = 0;
|
||||
if (ok && *cursor != 0) ok = parseZoneSuffix(cursor, offsetMinutes);
|
||||
if (ok && *cursor != 0) ok = false;
|
||||
if (!ok) {
|
||||
if (!parseIsoDateTime(date_time, time, offsetMinutes) && !parseRfc2822DateTime(date_time, time, offsetMinutes)
|
||||
&& !parseAsctimeDateTime(date_time, time, offsetMinutes)) {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return SCE_RTC_ERROR_BAD_PARSE;
|
||||
}
|
||||
const RtcDateTime time{static_cast<std::uint16_t>(year), static_cast<std::uint16_t>(month), static_cast<std::uint16_t>(day),
|
||||
static_cast<std::uint16_t>(hour), static_cast<std::uint16_t>(minute), static_cast<std::uint16_t>(second), microsecond};
|
||||
if (const int result = validate(&time); result != 0) return result;
|
||||
const RtcTick local{toTick(time)};
|
||||
return addTicks(utc, &local, -offsetMinutes, TICKS_PER_MINUTE);
|
||||
|
||||
@@ -38,6 +38,19 @@ if(BUILD_TESTING)
|
||||
add_test(NAME pad_sdl COMMAND pad_sdl_tests)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_video_out_wqhd_detection_tests ${LIBS_INCLUDE_DIR}/tests/GuestVideoOutWqhdDetection.cpp)
|
||||
target_include_directories(guest_video_out_wqhd_detection_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_video_out_wqhd_detection_tests PRIVATE libSceVideoOut libSceAgcDriver libkernel libc)
|
||||
configure_windows_unwind(guest_video_out_wqhd_detection_tests)
|
||||
add_test(NAME guest_video_out_wqhd_detection COMMAND guest_video_out_wqhd_detection_tests)
|
||||
set_tests_properties(guest_video_out_wqhd_detection PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_video_out_wqhd_detection PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_buffer_reuse_tests ${LIBS_INCLUDE_DIR}/tests/GuestBufferReuse.cpp)
|
||||
target_include_directories(guest_buffer_reuse_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
|
||||
@@ -12,6 +12,7 @@ int APS5_VABI sceVideoOutClose(int handle);
|
||||
int APS5_VABI sceVideoOutConfigureOutput(int handle, uint64_t mode, const VideoOutOutputOptions* options, void* reserved_ptr, uint64_t reserved);
|
||||
int APS5_VABI sceVideoOutIsOutputSupported(int handle, uint64_t mode, const VideoOutOutputOptions* options, void* reserved_ptr, uint64_t reserved);
|
||||
int APS5_VABI sceVideoOutInitializeOutputOptions(VideoOutOutputOptions* options);
|
||||
int APS5_VABI sceVideoOutAllowOutputResolutionWqhdDetection(int handle);
|
||||
int APS5_VABI sceVideoOutSetFlipRate(int handle, int rate);
|
||||
int APS5_VABI sceVideoOutSetWindowModeMargins(int handle, int top, int bottom);
|
||||
int APS5_VABI sceVideoOutGetFlipStatus(int handle, VideoOutFlipStatus* status);
|
||||
|
||||
@@ -80,6 +80,15 @@ int APS5_VABI sceVideoOutClose(int handle) try {
|
||||
LibcAwaitExit_nid_postfix();
|
||||
}
|
||||
|
||||
int APS5_VABI sceVideoOutAllowOutputResolutionWqhdDetection(int handle) try {
|
||||
if (!VideoOutDriver::Get().IsOpen(handle)) {
|
||||
throw std::runtime_error(std::string(__func__) + ": VIDEO_OUT_ERROR_INVALID_HANDLE");
|
||||
}
|
||||
return 0;
|
||||
} catch (const ProcessShutdown&) {
|
||||
LibcAwaitExit_nid_postfix();
|
||||
}
|
||||
|
||||
int APS5_VABI sceVideoOutSetFlipRate(int handle, int rate) try {
|
||||
auto cfg = VideoOutDriver::Get().GetConfig(handle);
|
||||
if (cfg == nullptr) {
|
||||
|
||||
@@ -13,9 +13,10 @@ if(BUILD_TESTING)
|
||||
target_include_directories(guest_voice_qos_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_voice_qos_tests PRIVATE libSceVoiceQoS libc)
|
||||
configure_windows_unwind(guest_voice_qos_tests)
|
||||
add_test(NAME guest_voice_qos COMMAND guest_voice_qos_tests)
|
||||
add_test(NAME guest_voice_qos COMMAND guest_voice_qos_tests 0x20000000)
|
||||
add_test(NAME guest_voice_qos_app_type_0x10000000 COMMAND guest_voice_qos_tests 0x10000000)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_voice_qos PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
set_tests_properties(guest_voice_qos guest_voice_qos_app_type_0x10000000 PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceVoiceQoS>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace {
|
||||
|
||||
constexpr std::int32_t VOICE_QOS_APP_TYPE_GAME = 0x20000000;
|
||||
constexpr std::int32_t VOICE_QOS_APP_TYPE_10000000 = 0x10000000;
|
||||
|
||||
std::mutex g_mutex;
|
||||
bool g_initialized = false;
|
||||
@@ -19,7 +20,7 @@ extern "C" {
|
||||
|
||||
int APS5_VABI sceVoiceQoSInit(void* mem_block, uint32_t mem_size, int32_t app_type) {
|
||||
if (!mem_block || mem_size == 0) throw std::invalid_argument("sceVoiceQoSInit: null or empty memory block");
|
||||
if (app_type != VOICE_QOS_APP_TYPE_GAME) throw std::invalid_argument("sceVoiceQoSInit: unsupported app type " + std::to_string(app_type));
|
||||
if (app_type != VOICE_QOS_APP_TYPE_GAME && app_type != VOICE_QOS_APP_TYPE_10000000) throw std::invalid_argument("sceVoiceQoSInit: unsupported app type " + std::to_string(app_type));
|
||||
std::lock_guard lock(g_mutex);
|
||||
if (g_initialized) throw std::runtime_error("sceVoiceQoSInit: already initialized");
|
||||
g_initialized = true;
|
||||
|
||||
@@ -40,7 +40,21 @@ target_include_directories(libc PRIVATE
|
||||
${LIBS_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(libc PRIVATE advapi32)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_access_tests ${LIBS_INCLUDE_DIR}/tests/GuestAccess.cpp)
|
||||
target_include_directories(guest_access_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_access_tests PRIVATE libc)
|
||||
configure_windows_unwind(guest_access_tests)
|
||||
add_test(NAME guest_access COMMAND guest_access_tests)
|
||||
if(WIN32)
|
||||
target_link_libraries(guest_access_tests PRIVATE advapi32)
|
||||
set_tests_properties(guest_access PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(file_position_tests ${LIBS_INCLUDE_DIR}/tests/FilePosition.cpp)
|
||||
target_include_directories(file_position_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(file_position_tests PRIVATE libc)
|
||||
@@ -87,6 +101,16 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_execute_once PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(guest_fiopen_tests ${LIBS_INCLUDE_DIR}/tests/GuestFiopen.cpp)
|
||||
target_include_directories(guest_fiopen_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_fiopen_tests PRIVATE libc)
|
||||
configure_windows_unwind(guest_fiopen_tests)
|
||||
add_test(NAME guest_fiopen COMMAND guest_fiopen_tests)
|
||||
set_tests_properties(guest_fiopen PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_fiopen PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(guest_working_directory_tests ${LIBS_INCLUDE_DIR}/tests/GuestWorkingDirectory.cpp)
|
||||
target_include_directories(guest_working_directory_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_working_directory_tests PRIVATE libc)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <cxxabi.h>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
@@ -41,6 +42,14 @@ int APS5_VABI LibcInternalExtCxaThreadAtexit_nid_postfix(void (*destructor)(void
|
||||
|
||||
const std::error_category* _ZSt17iostream_categoryv_nid_postfix() { return &std::iostream_category(); }
|
||||
|
||||
std::FILE* APS5_VABI _ZSt7_FiopenPKcNSt5_IosbIiE9_OpenmodeEi_nid_postfix(const char* filename, int mode, int protection) {
|
||||
static_cast<void>(filename);
|
||||
static_cast<void>(mode);
|
||||
static_cast<void>(protection);
|
||||
NotImplemented_nid_no_patch("std::_Fiopen");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int APS5_VABI _ZSt13_Execute_onceRSt9once_flagPFiPvS1_PS1_ES1__nid_postfix(
|
||||
int* flag, int (APS5_VABI *callback)(void*, void*, void**), void* arg
|
||||
) {
|
||||
|
||||
@@ -16,6 +16,29 @@ extern "C" {
|
||||
|
||||
[[noreturn]] void APS5_VABI _ZSt11_Xbad_allocv_nid_postfix();
|
||||
|
||||
FileStream* APS5_VABI fdopen_nid_postfix(int descriptor, const char* mode) {
|
||||
if (descriptor < 0) { errno = 9; return nullptr; }
|
||||
if (!mode) { errno = 22; return nullptr; }
|
||||
const char* supported[] = {"r", "w", "a", "rb", "wb", "ab", "r+", "w+", "a+",
|
||||
"rb+", "wb+", "ab+", "r+b", "w+b", "a+b"};
|
||||
bool valid = false;
|
||||
for (const auto* candidate : supported) if (std::strcmp(mode, candidate) == 0) valid = true;
|
||||
if (!valid) { errno = 22; return nullptr; }
|
||||
try {
|
||||
const auto release = [](void* pointer) { ::operator delete(pointer); };
|
||||
std::unique_ptr<void, decltype(release)> storage(::operator new(sizeof(FileStream)), release);
|
||||
#ifdef _WIN32
|
||||
auto* native = ::_fdopen(descriptor, mode);
|
||||
#else
|
||||
auto* native = ::fdopen(descriptor, mode);
|
||||
#endif
|
||||
if (!native) return nullptr;
|
||||
auto* stream = new (storage.get()) FileStream(native, true);
|
||||
storage.release();
|
||||
return stream;
|
||||
} catch (const std::bad_alloc&) { errno = 12; return nullptr; }
|
||||
}
|
||||
|
||||
FileStream* APS5_VABI freopen_nid_postfix(const char* filename, const char* mode, FileStream* stream) {
|
||||
if (!stream || !mode) { errno = 22; return nullptr; }
|
||||
if (!filename) { errno = 45; return nullptr; } // Mode-only reopening is not supported.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "prx/libc/include/General.hpp"
|
||||
#include <cerrno>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@@ -26,6 +29,65 @@ int FilesystemError(const std::error_code& error) {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int APS5_VABI access_nid_postfix(const char* path, int mode) {
|
||||
if (!path) { errno = 14; return -1; }
|
||||
if (mode < 0 || (mode & ~7)) { errno = 22; return -1; }
|
||||
if (!*path) { errno = 2; return -1; }
|
||||
try {
|
||||
const auto resolved = ResolvePath_nid_no_patch(path);
|
||||
#ifdef _WIN32
|
||||
const DWORD attributes = GetFileAttributesW(resolved.c_str());
|
||||
if (attributes == INVALID_FILE_ATTRIBUTES) {
|
||||
errno = FilesystemError(std::error_code(static_cast<int>(GetLastError()), std::system_category()));
|
||||
return -1;
|
||||
}
|
||||
if (mode == 0) return 0;
|
||||
if ((mode & 2) && !(attributes & FILE_ATTRIBUTE_DIRECTORY) && (attributes & FILE_ATTRIBUTE_READONLY)) {
|
||||
errno = 13; return -1;
|
||||
}
|
||||
DWORD size = 0;
|
||||
constexpr auto information = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
|
||||
GetFileSecurityW(resolved.c_str(), information, nullptr, 0, &size);
|
||||
if (!size) { errno = 13; return -1; }
|
||||
std::vector<unsigned char> descriptor(size);
|
||||
if (!GetFileSecurityW(resolved.c_str(), information, descriptor.data(), size, &size)) {
|
||||
errno = 13; return -1;
|
||||
}
|
||||
struct Token {
|
||||
HANDLE value = nullptr;
|
||||
~Token() { if (value) CloseHandle(value); }
|
||||
} source, impersonation;
|
||||
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY | TOKEN_DUPLICATE, TRUE, &source.value)) {
|
||||
if (GetLastError() != ERROR_NO_TOKEN ||
|
||||
!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE, &source.value)) {
|
||||
errno = 13; return -1;
|
||||
}
|
||||
}
|
||||
if (!DuplicateToken(source.value, SecurityImpersonation, &impersonation.value)) { errno = 13; return -1; }
|
||||
DWORD desired = 0;
|
||||
if (mode & 4) desired |= FILE_READ_DATA;
|
||||
if (mode & 2) desired |= FILE_WRITE_DATA;
|
||||
if (mode & 1) desired |= FILE_EXECUTE;
|
||||
GENERIC_MAPPING mapping{FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_GENERIC_EXECUTE, FILE_ALL_ACCESS};
|
||||
PRIVILEGE_SET privileges{};
|
||||
DWORD privilegeSize = sizeof(privileges), granted = 0;
|
||||
BOOL allowed = FALSE;
|
||||
if (!AccessCheck(descriptor.data(), impersonation.value, desired, &mapping,
|
||||
&privileges, &privilegeSize, &granted, &allowed) || !allowed) {
|
||||
errno = 13; return -1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
if (::access(resolved.c_str(), mode) == 0) return 0;
|
||||
errno = FilesystemError(std::error_code(errno, std::generic_category()));
|
||||
return -1;
|
||||
#endif
|
||||
} catch (const std::bad_alloc&) { errno = 12; return -1; }
|
||||
catch (const std::filesystem::filesystem_error& error) {
|
||||
errno = FilesystemError(error.code()); return -1;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int APS5_VABI rename_nid_postfix(const char* from, const char* to) {
|
||||
if (!from || !to) { errno = 14; return -1; }
|
||||
if (!*from || !*to) { errno = 2; return -1; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mutex>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
@@ -9,6 +10,10 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
std::lldiv_t APS5_VABI lldiv_nid_postfix(long long numerator, long long denominator) {
|
||||
return std::lldiv(numerator, denominator);
|
||||
}
|
||||
|
||||
float APS5_VABI fmodf_nid_postfix(float x, float y) { return std::fmod(x, y); }
|
||||
float APS5_VABI asinf_nid_postfix(float x) { return std::asin(x); }
|
||||
float APS5_VABI acosf_nid_postfix(float x) { return std::acos(x); }
|
||||
|
||||
@@ -13,6 +13,8 @@ int APS5_VABI ___mb_cur_max_nid_postfix() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int APS5_VABI _Getmbcurmax_nid_postfix() { return ___mb_cur_max_nid_postfix(); }
|
||||
|
||||
int APS5_VABI mbsinit_nid_postfix(const void*) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -80,4 +80,7 @@ int APS5_VABI setvbuf_nid_postfix(FileStream* stream, char* buffer, int mode, st
|
||||
const int native = mode == 0 ? _IOFBF : mode == 1 ? _IOLBF : _IONBF;
|
||||
return std::setvbuf(GetNativeStream(stream), buffer, native, size);
|
||||
}
|
||||
void APS5_VABI setbuf_nid_postfix(FileStream* stream, char* buffer) {
|
||||
setvbuf_nid_postfix(stream, buffer, buffer ? 0 : 2, buffer ? 1024 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
add_library(libcohtml SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp
|
||||
)
|
||||
target_include_directories(libcohtml PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
set_target_properties(libcohtml PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(libcohtml)
|
||||
@@ -1,16 +0,0 @@
|
||||
# libcohtml — deploy note
|
||||
|
||||
Game `DT_NEEDED` expects exactly: `libcohtml.Prospero.prx`.
|
||||
|
||||
Copy next to the relinked eboot (same directory):
|
||||
|
||||
- `build/core/libs/libs/libcohtml.Prospero.prx` (patched build output, 50 NIDs) — required.
|
||||
- `libgcc_s_seh-1.dll`, `libstdc++-6.dll`, `libwinpthread-1.dll` from `winlibs-gcc15/mingw64/bin` — required on Windows (see [technical debt](../../../../docs/dev/TechnicalDebt.md)).
|
||||
|
||||
Do NOT deploy:
|
||||
|
||||
- `libcohtml.prx` (build intermediate kept for the NID-patch pipeline, wrong `DT_NEEDED` name).
|
||||
- Anything under `build/core/libs/libs/unpatched/` (NIDs not patched).
|
||||
- `libc.prx` / `libkernel.prx` are not runtime imports of this module (no such DLL dependency); the game may need its other modules separately (out of scope).
|
||||
|
||||
Scope: raw-NID stubs only; real Cohtml rendering stays out of scope.
|
||||
@@ -1,307 +0,0 @@
|
||||
#include <cstdint>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
APS5_EXPORT("1fOA53oGwU8", cohtml_stub_00);
|
||||
std::uint64_t APS5_VABI cohtml_stub_00(void) {
|
||||
NotImplemented_nid_no_patch("1fOA53oGwU8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("2vxXHkZlhbw", cohtml_stub_01);
|
||||
std::uint64_t APS5_VABI cohtml_stub_01(void) {
|
||||
NotImplemented_nid_no_patch("2vxXHkZlhbw");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("3rew70M0SmY", cohtml_stub_02);
|
||||
std::uint64_t APS5_VABI cohtml_stub_02(void) {
|
||||
NotImplemented_nid_no_patch("3rew70M0SmY");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("4Le0SBPvnF8", cohtml_stub_03);
|
||||
std::uint64_t APS5_VABI cohtml_stub_03(void) {
|
||||
NotImplemented_nid_no_patch("4Le0SBPvnF8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("53ZTBeo2a54", cohtml_stub_04);
|
||||
std::uint64_t APS5_VABI cohtml_stub_04(void) {
|
||||
NotImplemented_nid_no_patch("53ZTBeo2a54");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("6PaNuQipllM", cohtml_stub_05);
|
||||
std::uint64_t APS5_VABI cohtml_stub_05(void) {
|
||||
NotImplemented_nid_no_patch("6PaNuQipllM");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("7hn5DAs2bLk", cohtml_stub_06);
|
||||
std::uint64_t APS5_VABI cohtml_stub_06(void) {
|
||||
NotImplemented_nid_no_patch("7hn5DAs2bLk");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("8EYWdAM2-R0", cohtml_stub_07);
|
||||
std::uint64_t APS5_VABI cohtml_stub_07(void) {
|
||||
NotImplemented_nid_no_patch("8EYWdAM2-R0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("9bGvfp1zbKo", cohtml_stub_08);
|
||||
std::uint64_t APS5_VABI cohtml_stub_08(void) {
|
||||
NotImplemented_nid_no_patch("9bGvfp1zbKo");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("a4E5dJh0onE", cohtml_stub_09);
|
||||
std::uint64_t APS5_VABI cohtml_stub_09(void) {
|
||||
NotImplemented_nid_no_patch("a4E5dJh0onE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("BhL-ZtSHmB8", cohtml_stub_10);
|
||||
std::uint64_t APS5_VABI cohtml_stub_10(void) {
|
||||
NotImplemented_nid_no_patch("BhL-ZtSHmB8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("blvwzOvsEAA", cohtml_stub_11);
|
||||
std::uint64_t APS5_VABI cohtml_stub_11(void) {
|
||||
NotImplemented_nid_no_patch("blvwzOvsEAA");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("dko-cMqv5yw", cohtml_stub_12);
|
||||
std::uint64_t APS5_VABI cohtml_stub_12(void) {
|
||||
NotImplemented_nid_no_patch("dko-cMqv5yw");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("EG4kqkxLU3Q", cohtml_stub_13);
|
||||
std::uint64_t APS5_VABI cohtml_stub_13(void) {
|
||||
NotImplemented_nid_no_patch("EG4kqkxLU3Q");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("-El4B0xJF2U", cohtml_stub_14);
|
||||
std::uint64_t APS5_VABI cohtml_stub_14(void) {
|
||||
NotImplemented_nid_no_patch("-El4B0xJF2U");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("EMhQNylkSwk", cohtml_stub_15);
|
||||
std::uint64_t APS5_VABI cohtml_stub_15(void) {
|
||||
NotImplemented_nid_no_patch("EMhQNylkSwk");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("-eNSKAypRz0", cohtml_stub_16);
|
||||
std::uint64_t APS5_VABI cohtml_stub_16(void) {
|
||||
NotImplemented_nid_no_patch("-eNSKAypRz0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("FG9VRZfson0", cohtml_stub_17);
|
||||
std::uint64_t APS5_VABI cohtml_stub_17(void) {
|
||||
NotImplemented_nid_no_patch("FG9VRZfson0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("fNvtExaHN4U", cohtml_stub_18);
|
||||
std::uint64_t APS5_VABI cohtml_stub_18(void) {
|
||||
NotImplemented_nid_no_patch("fNvtExaHN4U");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("g10DkPARoa8", cohtml_stub_19);
|
||||
std::uint64_t APS5_VABI cohtml_stub_19(void) {
|
||||
NotImplemented_nid_no_patch("g10DkPARoa8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("gwQczxoDmG0", cohtml_stub_20);
|
||||
std::uint64_t APS5_VABI cohtml_stub_20(void) {
|
||||
NotImplemented_nid_no_patch("gwQczxoDmG0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("HQF4O9D+Di4", cohtml_stub_21);
|
||||
std::uint64_t APS5_VABI cohtml_stub_21(void) {
|
||||
NotImplemented_nid_no_patch("HQF4O9D+Di4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("igt3a6Q0VMc", cohtml_stub_22);
|
||||
std::uint64_t APS5_VABI cohtml_stub_22(void) {
|
||||
NotImplemented_nid_no_patch("igt3a6Q0VMc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("kyApuhEHHxQ", cohtml_stub_23);
|
||||
std::uint64_t APS5_VABI cohtml_stub_23(void) {
|
||||
NotImplemented_nid_no_patch("kyApuhEHHxQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Ljp75QXUi7s", cohtml_stub_24);
|
||||
std::uint64_t APS5_VABI cohtml_stub_24(void) {
|
||||
NotImplemented_nid_no_patch("Ljp75QXUi7s");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("loJ5Ef3MZrs", cohtml_stub_25);
|
||||
std::uint64_t APS5_VABI cohtml_stub_25(void) {
|
||||
NotImplemented_nid_no_patch("loJ5Ef3MZrs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("LWe+u8SHKgU", cohtml_stub_26);
|
||||
std::uint64_t APS5_VABI cohtml_stub_26(void) {
|
||||
NotImplemented_nid_no_patch("LWe+u8SHKgU");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("nhn1ds+I2t4", cohtml_stub_27);
|
||||
std::uint64_t APS5_VABI cohtml_stub_27(void) {
|
||||
NotImplemented_nid_no_patch("nhn1ds+I2t4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("NmVsRWgsKt4", cohtml_stub_28);
|
||||
std::uint64_t APS5_VABI cohtml_stub_28(void) {
|
||||
NotImplemented_nid_no_patch("NmVsRWgsKt4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ONEnhMinebs", cohtml_stub_29);
|
||||
std::uint64_t APS5_VABI cohtml_stub_29(void) {
|
||||
NotImplemented_nid_no_patch("ONEnhMinebs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("PdOmR8dy1fM", cohtml_stub_30);
|
||||
std::uint64_t APS5_VABI cohtml_stub_30(void) {
|
||||
NotImplemented_nid_no_patch("PdOmR8dy1fM");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("PSwGBN5Icv8", cohtml_stub_31);
|
||||
std::uint64_t APS5_VABI cohtml_stub_31(void) {
|
||||
NotImplemented_nid_no_patch("PSwGBN5Icv8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("RalyfwiTt8o", cohtml_stub_32);
|
||||
std::uint64_t APS5_VABI cohtml_stub_32(void) {
|
||||
NotImplemented_nid_no_patch("RalyfwiTt8o");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("t+OHUjVWIwU", cohtml_stub_33);
|
||||
std::uint64_t APS5_VABI cohtml_stub_33(void) {
|
||||
NotImplemented_nid_no_patch("t+OHUjVWIwU");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Ter8YCVZ9tQ", cohtml_stub_34);
|
||||
std::uint64_t APS5_VABI cohtml_stub_34(void) {
|
||||
NotImplemented_nid_no_patch("Ter8YCVZ9tQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("tG3LJfAOH3k", cohtml_stub_35);
|
||||
std::uint64_t APS5_VABI cohtml_stub_35(void) {
|
||||
NotImplemented_nid_no_patch("tG3LJfAOH3k");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ukSFhKPmCTg", cohtml_stub_36);
|
||||
std::uint64_t APS5_VABI cohtml_stub_36(void) {
|
||||
NotImplemented_nid_no_patch("ukSFhKPmCTg");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("V7KGze2XjJc", cohtml_stub_37);
|
||||
std::uint64_t APS5_VABI cohtml_stub_37(void) {
|
||||
NotImplemented_nid_no_patch("V7KGze2XjJc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("vlmAvJqR7mQ", cohtml_stub_38);
|
||||
std::uint64_t APS5_VABI cohtml_stub_38(void) {
|
||||
NotImplemented_nid_no_patch("vlmAvJqR7mQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("VzhxjXDzYSI", cohtml_stub_39);
|
||||
std::uint64_t APS5_VABI cohtml_stub_39(void) {
|
||||
NotImplemented_nid_no_patch("VzhxjXDzYSI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("X3FzDPzpD2Y", cohtml_stub_40);
|
||||
std::uint64_t APS5_VABI cohtml_stub_40(void) {
|
||||
NotImplemented_nid_no_patch("X3FzDPzpD2Y");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("x68HPh+vxsE", cohtml_stub_41);
|
||||
std::uint64_t APS5_VABI cohtml_stub_41(void) {
|
||||
NotImplemented_nid_no_patch("x68HPh+vxsE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("XUe8OAKB-vQ", cohtml_stub_42);
|
||||
std::uint64_t APS5_VABI cohtml_stub_42(void) {
|
||||
NotImplemented_nid_no_patch("XUe8OAKB-vQ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("y6UNQtnr0wY", cohtml_stub_43);
|
||||
std::uint64_t APS5_VABI cohtml_stub_43(void) {
|
||||
NotImplemented_nid_no_patch("y6UNQtnr0wY");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("YoHAXkBV06c", cohtml_stub_44);
|
||||
std::uint64_t APS5_VABI cohtml_stub_44(void) {
|
||||
NotImplemented_nid_no_patch("YoHAXkBV06c");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Z9XFJCfmId4", cohtml_stub_45);
|
||||
std::uint64_t APS5_VABI cohtml_stub_45(void) {
|
||||
NotImplemented_nid_no_patch("Z9XFJCfmId4");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("zEniuuzG2W0", cohtml_stub_46);
|
||||
std::uint64_t APS5_VABI cohtml_stub_46(void) {
|
||||
NotImplemented_nid_no_patch("zEniuuzG2W0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("zH9Z2nK1fmA", cohtml_stub_47);
|
||||
std::uint64_t APS5_VABI cohtml_stub_47(void) {
|
||||
NotImplemented_nid_no_patch("zH9Z2nK1fmA");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ZHGgdWeYTo8", cohtml_stub_48);
|
||||
std::uint64_t APS5_VABI cohtml_stub_48(void) {
|
||||
NotImplemented_nid_no_patch("ZHGgdWeYTo8");
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("ZWftPxZ4E6k", cohtml_stub_49);
|
||||
std::uint64_t APS5_VABI cohtml_stub_49(void) {
|
||||
NotImplemented_nid_no_patch("ZWftPxZ4E6k");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
add_library(libfmod SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp
|
||||
)
|
||||
|
||||
target_include_directories(libfmod PRIVATE
|
||||
${LIBS_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/SDL2/include
|
||||
)
|
||||
target_link_libraries(libfmod PRIVATE libkernel libc SDL2-static)
|
||||
target_compile_options(libfmod PRIVATE -fkeep-inline-functions)
|
||||
configure_windows_unwind(libfmod)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
||||
add_library(libfmodstudio SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp
|
||||
)
|
||||
|
||||
target_include_directories(libfmodstudio PRIVATE
|
||||
${LIBS_INCLUDE_DIR}
|
||||
)
|
||||
target_link_libraries(libfmodstudio PRIVATE libkernel libc)
|
||||
target_compile_options(libfmodstudio PRIVATE -fkeep-inline-functions)
|
||||
configure_windows_unwind(libfmodstudio)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
@@ -26,6 +27,10 @@ constexpr std::int32_t AioProcessing = 2;
|
||||
constexpr std::int32_t AioCompleted = 3;
|
||||
constexpr std::int32_t AioAborted = 4;
|
||||
constexpr std::int32_t AioMaxQueues = 512;
|
||||
constexpr std::int32_t AioRequestNumMax = 128;
|
||||
constexpr std::int32_t AioIdNumMax = 128;
|
||||
constexpr std::uint32_t AioWaitAnd = 1;
|
||||
constexpr std::uint32_t AioWaitOr = 2;
|
||||
|
||||
std::mutex g_mutex;
|
||||
std::array<std::int32_t, AioMaxQueues> g_states{};
|
||||
@@ -100,35 +105,67 @@ std::int64_t NativePwrite(std::int32_t fd, const void* buf, std::size_t nbyte, s
|
||||
#endif
|
||||
}
|
||||
|
||||
int SubmitCommands(KernelAioRwRequest* req, std::int32_t size, bool write, std::int32_t* id) {
|
||||
bool RunRequest(KernelAioRwRequest& req, bool write) {
|
||||
const std::int64_t done = write
|
||||
? NativePwrite(req.fd, req.buf, req.nbyte, req.offset)
|
||||
: NativePread(req.fd, req.buf, req.nbyte, req.offset);
|
||||
if (done < 0) {
|
||||
const int error = errno;
|
||||
req.result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EIO);
|
||||
if (error == EBADF) req.result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EBADF);
|
||||
if (error == EFAULT) req.result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EFAULT);
|
||||
req.result->state = AioAborted;
|
||||
return false;
|
||||
}
|
||||
req.result->return_value = done;
|
||||
req.result->state = AioCompleted;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ValidateRequests(KernelAioRwRequest* req, std::int32_t size, const void* id) {
|
||||
if (req == nullptr || id == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (size <= 0) return SCE_KERNEL_ERROR_EINVAL;
|
||||
for (std::int32_t i = 0; i < size; ++i) {
|
||||
if (req[i].result == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SubmitCommands(KernelAioRwRequest* req, std::int32_t size, bool write, std::int32_t* id) {
|
||||
const int error = ValidateRequests(req, size, id);
|
||||
if (error != 0) return error;
|
||||
const std::int32_t queue = AllocateId();
|
||||
bool aborted = false;
|
||||
for (std::int32_t i = 0; i < size; ++i) {
|
||||
const std::int64_t done = write
|
||||
? NativePwrite(req[i].fd, req[i].buf, req[i].nbyte, req[i].offset)
|
||||
: NativePread(req[i].fd, req[i].buf, req[i].nbyte, req[i].offset);
|
||||
if (done < 0) {
|
||||
const int error = errno;
|
||||
req[i].result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EIO);
|
||||
if (error == EBADF) req[i].result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EBADF);
|
||||
if (error == EFAULT) req[i].result->return_value = static_cast<std::int64_t>(SCE_KERNEL_ERROR_EFAULT);
|
||||
req[i].result->state = AioAborted;
|
||||
aborted = true;
|
||||
} else {
|
||||
req[i].result->return_value = done;
|
||||
req[i].result->state = AioCompleted;
|
||||
}
|
||||
if (!RunRequest(req[i], write)) aborted = true;
|
||||
}
|
||||
SetState(queue, aborted ? AioAborted : AioCompleted);
|
||||
*id = queue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SubmitCommandsMultiple(KernelAioRwRequest* req, std::int32_t size, bool write, std::int32_t* id, const char* name) {
|
||||
const int error = ValidateRequests(req, size, id);
|
||||
if (error != 0) return error;
|
||||
if (size > AioRequestNumMax) throw std::runtime_error(std::string(name) + ": more than 128 requests per batch is not modelled");
|
||||
for (std::int32_t i = 0; i < size; ++i) {
|
||||
const std::int32_t queue = AllocateId();
|
||||
SetState(queue, RunRequest(req[i], write) ? AioCompleted : AioAborted);
|
||||
id[i] = queue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ValidateIds(const std::int32_t* id, std::int32_t num, const void* out, const char* name) {
|
||||
if (id == nullptr || out == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (num < 0) return SCE_KERNEL_ERROR_EINVAL;
|
||||
if (num > AioIdNumMax) throw std::runtime_error(std::string(name) + ": more than 128 ids per batch is not modelled");
|
||||
for (std::int32_t i = 0; i < num; ++i) {
|
||||
if (!ValidId(id[i])) return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -141,6 +178,46 @@ int APS5_VABI sceKernelAioDeleteRequest(int32_t id, int32_t* ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioDeleteRequests(int32_t* id, int32_t num, int32_t* ret) {
|
||||
const int error = ValidateIds(id, num, ret, "sceKernelAioDeleteRequests");
|
||||
if (error != 0) return error;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SetState(id[i], AioAborted);
|
||||
ret[i] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioCancelRequest(int32_t id, int32_t* state) {
|
||||
if (state == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (id == 0) {
|
||||
*state = AioProcessing;
|
||||
return 0;
|
||||
}
|
||||
if (!ValidId(id)) return SCE_KERNEL_ERROR_EINVAL;
|
||||
SetState(id, AioAborted);
|
||||
*state = AioAborted;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioCancelRequests(int32_t* id, int32_t num, int32_t* state) {
|
||||
if (id == nullptr || state == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (num < 0) return SCE_KERNEL_ERROR_EINVAL;
|
||||
if (num > AioIdNumMax) throw std::runtime_error("sceKernelAioCancelRequests: more than 128 ids per batch is not modelled");
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
if (id[i] != 0 && !ValidId(id[i])) return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
if (id[i] == 0) {
|
||||
state[i] = AioProcessing;
|
||||
continue;
|
||||
}
|
||||
SetState(id[i], AioAborted);
|
||||
state[i] = AioAborted;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioInitializeImpl(void* param, int32_t size) {
|
||||
(void)param;
|
||||
(void)size;
|
||||
@@ -161,6 +238,16 @@ int APS5_VABI sceKernelAioSubmitWriteCommands(KernelAioRwRequest* req, int32_t s
|
||||
return SubmitCommands(req, size, true, id);
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioSubmitReadCommandsMultiple(KernelAioRwRequest* req, int32_t size, int32_t prio, int32_t* id) {
|
||||
(void)prio;
|
||||
return SubmitCommandsMultiple(req, size, false, id, "sceKernelAioSubmitReadCommandsMultiple");
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioSubmitWriteCommandsMultiple(KernelAioRwRequest* req, int32_t size, int32_t prio, int32_t* id) {
|
||||
(void)prio;
|
||||
return SubmitCommandsMultiple(req, size, true, id, "sceKernelAioSubmitWriteCommandsMultiple");
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioPollRequest(int32_t id, int32_t* state) {
|
||||
if (state == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (!ValidId(id)) return SCE_KERNEL_ERROR_EINVAL;
|
||||
@@ -169,6 +256,31 @@ int APS5_VABI sceKernelAioPollRequest(int32_t id, int32_t* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioWaitRequests(int32_t* id, int32_t num, int32_t* state, uint32_t mode, uint32_t* usec) {
|
||||
const int error = ValidateIds(id, num, state, "sceKernelAioWaitRequests");
|
||||
if (error != 0) return error;
|
||||
if (mode != AioWaitAnd && mode != AioWaitOr) throw std::runtime_error("sceKernelAioWaitRequests: unsupported wait mode");
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for (;;) {
|
||||
bool allDone = true;
|
||||
bool anyCompleted = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
state[i] = g_states[id[i]];
|
||||
if (state[i] == AioProcessing) allDone = false;
|
||||
if (state[i] == AioCompleted) anyCompleted = true;
|
||||
}
|
||||
}
|
||||
if (allDone || (mode == AioWaitOr && anyCompleted)) return 0;
|
||||
if (usec != nullptr && *usec != 0) {
|
||||
const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count();
|
||||
if (elapsed > static_cast<std::int64_t>(*usec)) return SCE_KERNEL_ERROR_ETIMEDOUT;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelAioWaitRequest(int32_t id, int32_t* state, uint32_t* usec) {
|
||||
if (state == nullptr) return SCE_KERNEL_ERROR_EFAULT;
|
||||
if (!ValidId(id)) return SCE_KERNEL_ERROR_EINVAL;
|
||||
|
||||
@@ -36,6 +36,7 @@ add_library(libkernel SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EventFlag/src/EventFlag.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Module/src/Module.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Module/src/DynamicLoader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Module/src/ModuleInfo.cpp
|
||||
${LIBS_INCLUDE_DIR}/nid/src/NidCompute.cpp
|
||||
${LIBS_INCLUDE_DIR}/nid/src/Sha1.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Aio/src/Aio.cpp
|
||||
@@ -107,6 +108,15 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_dynamic_loader PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
add_test_executable(guest_module_info_tests ${LIBS_INCLUDE_DIR}/tests/GuestModuleInfo.cpp)
|
||||
target_include_directories(guest_module_info_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_module_info_tests PRIVATE libkernel libc)
|
||||
add_dependencies(guest_module_info_tests guest_module_fixture)
|
||||
add_test(NAME guest_module_info COMMAND guest_module_info_tests $<TARGET_FILE_NAME:guest_module_fixture>)
|
||||
set_tests_properties(guest_module_info PROPERTIES
|
||||
WORKING_DIRECTORY "$<TARGET_FILE_DIR:guest_module_fixture>")
|
||||
endif()
|
||||
add_test_executable(guest_filesystem_tests ${LIBS_INCLUDE_DIR}/tests/GuestFilesystem.cpp)
|
||||
target_include_directories(guest_filesystem_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_filesystem_tests PRIVATE libkernel libc)
|
||||
@@ -264,6 +274,16 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_sync_on_address PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_available_cpumask_tests ${LIBS_INCLUDE_DIR}/tests/GuestAvailableCpumask.cpp)
|
||||
target_include_directories(guest_available_cpumask_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_available_cpumask_tests PRIVATE libkernel libc)
|
||||
configure_windows_unwind(guest_available_cpumask_tests)
|
||||
add_test(NAME guest_available_cpumask COMMAND guest_available_cpumask_tests)
|
||||
set_tests_properties(guest_available_cpumask PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_available_cpumask PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_kernel_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestKernelErrors.cpp)
|
||||
target_include_directories(guest_kernel_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_kernel_error_tests PRIVATE libkernel libc)
|
||||
@@ -355,6 +375,10 @@ if(BUILD_TESTING)
|
||||
target_include_directories(guest_directory_entry_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_directory_entry_tests PRIVATE libkernel libc)
|
||||
add_test(NAME guest_directory_entries COMMAND guest_directory_entry_tests)
|
||||
add_test_executable(guest_file_vector_tests ${LIBS_INCLUDE_DIR}/tests/GuestFileVector.cpp)
|
||||
target_include_directories(guest_file_vector_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_file_vector_tests PRIVATE libkernel libc)
|
||||
add_test(NAME guest_file_vector COMMAND guest_file_vector_tests)
|
||||
else()
|
||||
add_test_executable(guest_directory_close_tests ${LIBS_INCLUDE_DIR}/tests/GuestDirectoryClose.cpp)
|
||||
target_include_directories(guest_directory_close_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
|
||||
@@ -516,6 +516,31 @@ void EraseProtections(std::uintptr_t start, std::uintptr_t end) {
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex g_reservationLock;
|
||||
std::map<std::uintptr_t, std::uintptr_t> g_reservations;
|
||||
|
||||
void EraseReservations(const void* addr, size_t len) {
|
||||
const auto start = reinterpret_cast<std::uintptr_t>(addr);
|
||||
const auto end = start + len;
|
||||
std::lock_guard lock(g_reservationLock);
|
||||
auto it = g_reservations.lower_bound(start);
|
||||
if (it != g_reservations.begin() && std::prev(it)->second > start) --it;
|
||||
while (it != g_reservations.end() && it->first < end) {
|
||||
const auto rangeStart = it->first;
|
||||
const auto rangeEnd = it->second;
|
||||
it = g_reservations.erase(it);
|
||||
if (rangeStart < start) g_reservations.emplace(rangeStart, start);
|
||||
if (rangeEnd > end) it = g_reservations.emplace(end, rangeEnd).first;
|
||||
}
|
||||
}
|
||||
|
||||
void RecordReservation(const void* addr, size_t len) {
|
||||
EraseReservations(addr, len);
|
||||
const auto start = reinterpret_cast<std::uintptr_t>(addr);
|
||||
std::lock_guard lock(g_reservationLock);
|
||||
g_reservations.emplace(start, start + len);
|
||||
}
|
||||
|
||||
void RecordProtection(const void* addr, size_t len, int prot) {
|
||||
const auto start = reinterpret_cast<std::uintptr_t>(addr);
|
||||
std::lock_guard lock(g_protectionLock);
|
||||
@@ -548,6 +573,7 @@ int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart,
|
||||
}
|
||||
GuestAllocations::Mutation mutation;
|
||||
if (RemapFixedIntoRegistered(mutation, *addr, len, prot, flags, physStart)) {
|
||||
EraseReservations(*addr, len);
|
||||
RecordProtection(*addr, len, prot);
|
||||
return 0;
|
||||
}
|
||||
@@ -564,6 +590,7 @@ int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart,
|
||||
throw;
|
||||
}
|
||||
*addr = mapped;
|
||||
EraseReservations(mapped, len);
|
||||
RecordProtection(mapped, len, prot);
|
||||
Trace("map direct %p+0x%zx phys=0x%llx prot=0x%x flags=0x%x align=0x%zx", mapped, len, static_cast<unsigned long long>(physStart), prot, flags, alignment);
|
||||
return 0;
|
||||
@@ -574,6 +601,7 @@ int DoMapAnon(void** addr, size_t len, int prot, int flags) {
|
||||
if (len == 0 || (len & (PS5_PAGE_SIZE - 1)) != 0) return SCE_KERNEL_ERROR_EINVAL;
|
||||
GuestAllocations::Mutation mutation;
|
||||
if (RemapFixedIntoRegistered(mutation, *addr, len, prot, flags)) {
|
||||
EraseReservations(*addr, len);
|
||||
RecordProtection(*addr, len, prot);
|
||||
return 0;
|
||||
}
|
||||
@@ -586,6 +614,7 @@ int DoMapAnon(void** addr, size_t len, int prot, int flags) {
|
||||
throw;
|
||||
}
|
||||
*addr = mapped;
|
||||
EraseReservations(mapped, len);
|
||||
RecordProtection(mapped, len, prot);
|
||||
Trace("map anon %p+0x%zx prot=0x%x flags=0x%x", mapped, len, prot, flags);
|
||||
return 0;
|
||||
@@ -636,6 +665,7 @@ int DoMunmap(void* addr, size_t len) {
|
||||
else munmap(pieceAddress, pieceBytes);
|
||||
#endif
|
||||
});
|
||||
EraseReservations(addr, len);
|
||||
RecordProtection(addr, len, -1);
|
||||
return 0;
|
||||
}
|
||||
@@ -647,7 +677,11 @@ int DoReserveVirtual(void** addr, size_t len, int flags, size_t alignment) {
|
||||
const bool fixed = *addr != nullptr && (flags & GuestMapFixedFlag) != 0;
|
||||
if (fixed && mutation.Covers(*addr, len)) {
|
||||
constexpr int GuestMapNoOverwrite = 0x80;
|
||||
if ((flags & GuestMapNoOverwrite) == 0 && RemapFixedIntoRegistered(mutation, *addr, len, 0, GuestMapFixedFlag)) return 0;
|
||||
if ((flags & GuestMapNoOverwrite) == 0 && RemapFixedIntoRegistered(mutation, *addr, len, 0, GuestMapFixedFlag)) {
|
||||
RecordProtection(*addr, len, -1);
|
||||
RecordReservation(*addr, len);
|
||||
return 0;
|
||||
}
|
||||
mutation.RequireAvailable(*addr, len);
|
||||
}
|
||||
if (fixed) mutation.RequireAvailable(*addr, len);
|
||||
@@ -660,6 +694,7 @@ int DoReserveVirtual(void** addr, size_t len, int flags, size_t alignment) {
|
||||
throw;
|
||||
}
|
||||
*addr = mapped;
|
||||
RecordReservation(mapped, len);
|
||||
Trace("reserve %p+0x%zx flags=0x%x align=0x%zx", mapped, len, flags, alignment);
|
||||
return 0;
|
||||
}
|
||||
@@ -686,6 +721,17 @@ void ForgetDirectMemory(int64_t start, size_t len) {
|
||||
Trace("release physical 0x%llx+0x%zx", static_cast<unsigned long long>(first), len);
|
||||
}
|
||||
|
||||
bool GuestReservation(std::uintptr_t addr, std::uintptr_t* start, std::uintptr_t* end) {
|
||||
std::lock_guard lock(g_reservationLock);
|
||||
const auto next = g_reservations.upper_bound(addr);
|
||||
if (next == g_reservations.begin()) return false;
|
||||
const auto containing = std::prev(next);
|
||||
if (addr >= containing->second) return false;
|
||||
*start = containing->first;
|
||||
*end = containing->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GuestProtection(uintptr_t addr, int* prot) {
|
||||
std::lock_guard lock(g_protectionLock);
|
||||
auto next = g_protections.upper_bound(addr);
|
||||
|
||||
@@ -11,6 +11,7 @@ static constexpr size_t PS5_PAGE_SIZE = 0x4000;
|
||||
|
||||
int DirectMemoryAlloc(int64_t searchStart, int64_t searchEnd, size_t len, size_t alignment, int memoryType, int64_t* physOut);
|
||||
void DirectMemoryFree(int64_t start, size_t len);
|
||||
bool DirectMemoryCheckedFree(int64_t start, size_t len);
|
||||
void CreateDirectMemoryBacking(int64_t start, size_t len, int memoryType);
|
||||
bool QueryDirectMapping(std::uintptr_t address, std::uintptr_t* start, std::uintptr_t* end, std::uint64_t* offset, int* memoryType);
|
||||
void ForgetDirectMemory(int64_t start, size_t len);
|
||||
@@ -22,5 +23,6 @@ int DoMprotect(const void* addr, size_t len, int prot);
|
||||
int DoMunmap(void* addr, size_t len);
|
||||
int DoReserveVirtual(void** addr, size_t len, int flags, size_t alignment);
|
||||
bool GuestProtection(uintptr_t addr, int* prot);
|
||||
bool GuestReservation(std::uintptr_t addr, std::uintptr_t* start, std::uintptr_t* end);
|
||||
|
||||
#endif
|
||||
@@ -148,6 +148,18 @@ int APS5_VABI sceKernelDirectMemoryQuery(int64_t offset, int flags, void* info,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelGetDirectMemoryType(int64_t offset, int* memory_type, int64_t* start, int64_t* end) {
|
||||
if (!memory_type || !start || !end) return SCE_KERNEL_ERROR_EINVAL;
|
||||
int64_t blockStart = 0;
|
||||
int64_t blockEnd = 0;
|
||||
int blockType = 0;
|
||||
if (!DirectMemoryFind(offset, false, &blockStart, &blockEnd, &blockType)) return SCE_KERNEL_ERROR_ENOENT;
|
||||
*memory_type = blockType;
|
||||
*start = blockStart;
|
||||
*end = blockEnd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t APS5_VABI sceKernelGetDirectMemorySize(void) {
|
||||
return DIRECT_MEMORY_SIZE;
|
||||
}
|
||||
@@ -212,6 +224,13 @@ int APS5_VABI sceKernelVirtualQuery(const void* addr, int flags, VirtualQueryInf
|
||||
// mapping at or above it: titles walk their mappings and check that a mapping covers a whole
|
||||
// allocation, so the answer must be the registered allocation, not a page.
|
||||
constexpr int findNext = 1;
|
||||
std::uintptr_t reservedStart = 0;
|
||||
std::uintptr_t reservedEnd = 0;
|
||||
if (GuestReservation(address, &reservedStart, &reservedEnd)) {
|
||||
info->start = reservedStart;
|
||||
info->end = reservedEnd;
|
||||
return 0;
|
||||
}
|
||||
const auto lease = GuestAllocations::GuestAllocationsAcquire_nid_postfix();
|
||||
const GuestAllocations::Range* best = nullptr;
|
||||
for (const auto& range : lease) {
|
||||
@@ -284,10 +303,9 @@ int APS5_VABI sceKernelVirtualQuery(const void* addr, int flags, VirtualQueryInf
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int APS5_VABI sceKernelCheckedReleaseDirectMemory(int64_t start, size_t len) {
|
||||
(void)start;
|
||||
(void)len;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
if (start < 0 || (static_cast<uint64_t>(start) & (PS5_PAGE_SIZE - 1)) != 0 || (len & (PS5_PAGE_SIZE - 1)) != 0) return SCE_KERNEL_ERROR_EINVAL;
|
||||
if (len == 0) return 0;
|
||||
return DirectMemoryCheckedFree(start, len) ? 0 : SCE_KERNEL_ERROR_ENOENT;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelMtypeprotect(const void* addr, size_t len, int type, int prot) {
|
||||
|
||||
@@ -32,18 +32,17 @@ struct PhysicalMemoryPool {
|
||||
|
||||
void Free(uint64_t start, size_t len) {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
ForgetDirectMemory(static_cast<int64_t>(start), len);
|
||||
_mark(start, len, false);
|
||||
const uint64_t end = start + len;
|
||||
auto it = _blocks.upper_bound(start);
|
||||
if (it != _blocks.begin() && std::prev(it)->second.end > start) --it;
|
||||
while (it != _blocks.end() && it->first < end) {
|
||||
const uint64_t blockStart = it->first;
|
||||
const Block block = it->second;
|
||||
it = _blocks.erase(it);
|
||||
if (blockStart < start) _blocks[blockStart] = {start, block.type};
|
||||
if (block.end > end) it = _blocks.emplace(end, Block{block.end, block.type}).first;
|
||||
}
|
||||
_free(start, len);
|
||||
}
|
||||
|
||||
bool CheckedFree(uint64_t start, size_t len) {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (start > DIRECT_MEMORY_SIZE || len > DIRECT_MEMORY_SIZE - start) return false;
|
||||
const size_t first = start / PS5_PAGE_SIZE;
|
||||
for (size_t i = 0; i < len / PS5_PAGE_SIZE; ++i)
|
||||
if (!_used[first + i]) return false;
|
||||
_free(start, len);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Find(uint64_t offset, bool findNext, int64_t* start, int64_t* end, int* memoryType) {
|
||||
@@ -70,6 +69,21 @@ struct PhysicalMemoryPool {
|
||||
}
|
||||
|
||||
private:
|
||||
void _free(uint64_t start, size_t len) {
|
||||
ForgetDirectMemory(static_cast<int64_t>(start), len);
|
||||
_mark(start, len, false);
|
||||
const uint64_t end = start + len;
|
||||
auto it = _blocks.upper_bound(start);
|
||||
if (it != _blocks.begin() && std::prev(it)->second.end > start) --it;
|
||||
while (it != _blocks.end() && it->first < end) {
|
||||
const uint64_t blockStart = it->first;
|
||||
const Block block = it->second;
|
||||
it = _blocks.erase(it);
|
||||
if (blockStart < start) _blocks[blockStart] = {start, block.type};
|
||||
if (block.end > end) it = _blocks.emplace(end, Block{block.end, block.type}).first;
|
||||
}
|
||||
}
|
||||
|
||||
bool _isFree(uint64_t offset, size_t len) const {
|
||||
size_t first = offset / PS5_PAGE_SIZE;
|
||||
size_t count = len / PS5_PAGE_SIZE;
|
||||
@@ -103,6 +117,10 @@ void DirectMemoryFree(int64_t start, size_t len) {
|
||||
PhysicalMemoryPool::Instance().Free(static_cast<uint64_t>(start), len);
|
||||
}
|
||||
|
||||
bool DirectMemoryCheckedFree(int64_t start, size_t len) {
|
||||
return PhysicalMemoryPool::Instance().CheckedFree(static_cast<uint64_t>(start), len);
|
||||
}
|
||||
|
||||
bool DirectMemoryFind(int64_t offset, bool findNext, int64_t* start, int64_t* end, int* memoryType) {
|
||||
return PhysicalMemoryPool::Instance().Find(static_cast<uint64_t>(offset), findNext, start, end, memoryType);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user