mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
test(agc): isolate shader linking and interpolant preparation checks
This commit is contained in:
@@ -236,9 +236,13 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_test_executable(agc_interpolant_mapping_tests EXCLUDE_FROM_ALL tests/InterpolantMapping.cpp)
|
||||
add_test_executable(agc_interpolant_mapping_tests EXCLUDE_FROM_ALL
|
||||
tests/InterpolantMapping.cpp
|
||||
Shader/src/InterpolantMapping.cpp
|
||||
Shader/src/ShaderUtils.cpp
|
||||
)
|
||||
target_include_directories(agc_interpolant_mapping_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(agc_interpolant_mapping_tests PRIVATE libSceAgc libc)
|
||||
target_link_libraries(agc_interpolant_mapping_tests PRIVATE libSceAgcDriver libc)
|
||||
set_target_properties(agc_interpolant_mapping_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(agc_interpolant_mapping_tests)
|
||||
|
||||
@@ -252,9 +256,15 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_test_executable(guest_shader_link_tests ${LIBS_INCLUDE_DIR}/tests/GuestShaderLink.cpp)
|
||||
add_test_executable(guest_shader_link_tests
|
||||
${LIBS_INCLUDE_DIR}/tests/GuestShaderLink.cpp
|
||||
Shader/src/LinkShaders.cpp
|
||||
Shader/src/PrimState.cpp
|
||||
Shader/src/InterpolantMapping.cpp
|
||||
Shader/src/ShaderUtils.cpp
|
||||
)
|
||||
target_include_directories(guest_shader_link_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_shader_link_tests PRIVATE libSceAgc libc)
|
||||
target_link_libraries(guest_shader_link_tests PRIVATE libSceAgc libSceAgcDriver libc)
|
||||
configure_windows_unwind(guest_shader_link_tests)
|
||||
add_test(NAME guest_shader_link COMMAND guest_shader_link_tests)
|
||||
if(WIN32)
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "prx/libSceAgc/Shader/include/ShaderConstants.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <span>
|
||||
|
||||
extern "C" int APS5_VABI sceAgcCreateInterpolantMapping(ShaderRegister* regs, const Shader* gs, const Shader* ps);
|
||||
extern "C" int APS5_VABI sceAgcUnknownCreateInterpolantMapping(ShaderRegister* regs, const Shader* gs, const Shader* ps);
|
||||
@@ -15,6 +17,10 @@ extern "C" int APS5_VABI sceAgcUnknownCreateInterpolantMapping(ShaderRegister* r
|
||||
namespace {
|
||||
|
||||
using Registers = std::array<ShaderRegister, 32>;
|
||||
const Shader* mappedPixel = nullptr;
|
||||
Registers preparedMapping{};
|
||||
unsigned mappings = 0;
|
||||
unsigned links = 0;
|
||||
|
||||
void check(bool condition, const char* message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
@@ -82,6 +88,7 @@ void testMapping() {
|
||||
|
||||
auto split = filled();
|
||||
check(sceAgcUnknownCreateInterpolantMapping(split.data(), &gs, &ps) == 0, "split f16 mapping failed");
|
||||
check(std::memcmp(split.data(), preparedMapping.data(), sizeof(split)) == 0, "prepared split mapping differs from published registers");
|
||||
for (std::uint32_t i = 0; i < inputs.size(); ++i) {
|
||||
check(split[i].offset == ShaderRegs::SPI_PS_INPUT_CNTL_0 + i, "interpolant register offset changed");
|
||||
}
|
||||
@@ -94,6 +101,7 @@ void testMapping() {
|
||||
|
||||
auto regular = filled();
|
||||
check(sceAgcCreateInterpolantMapping(regular.data(), &gs, &ps) == 0, "mapping failed");
|
||||
check(std::memcmp(regular.data(), preparedMapping.data(), sizeof(regular)) == 0, "prepared mapping differs from published registers");
|
||||
check(regular[3].value == split[3].value && regular[4].value == split[4].value, "mappings differ outside the high f16 half mode");
|
||||
checkIdentity(regular, static_cast<std::uint32_t>(inputs.size()), "unused interpolants are not the identity");
|
||||
}
|
||||
@@ -117,11 +125,24 @@ void testRejections() {
|
||||
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverResolveShaderAbi_nid_postfix(const Shader* shader, std::span<const ShaderRegister> context, std::span<const ShaderRegister> primitive) {
|
||||
check(shader != nullptr && context.size() == preparedMapping.size() && primitive.empty(), "invalid mapping preparation call");
|
||||
mappedPixel = shader;
|
||||
std::copy(context.begin(), context.end(), preparedMapping.begin());
|
||||
++mappings;
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverResolveGraphicsAbi_nid_postfix(const Shader* vertex, const Shader* pixel, std::uint32_t primitiveType) {
|
||||
check(vertex != nullptr && pixel == mappedPixel && primitiveType == 0u, "invalid mapping link call");
|
||||
++links;
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
testIdentity();
|
||||
testMapping();
|
||||
testRejections();
|
||||
check(mappings == 3u && links == 2u, "mapping preparation call count changed");
|
||||
LibcRunShutdown_nid_postfix();
|
||||
std::puts("AGC interpolant mapping tests passed");
|
||||
return 0;
|
||||
|
||||
@@ -5,10 +5,31 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <span>
|
||||
extern "C" int APS5_VABI sceAgcLinkShaders(ShaderRegister*, ShaderRegister*, const void*, const Shader*, const Shader*, std::uint32_t);
|
||||
extern "C" void* APS5_VABI sceAgcGetRegisterDefaults();
|
||||
extern "C" void* APS5_VABI sceAgcGetRegisterDefaults2(std::uint32_t);
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
static unsigned preparations = 0;
|
||||
static unsigned mappings = 0;
|
||||
static unsigned links = 0;
|
||||
static const Shader* mappedPixel = nullptr;
|
||||
|
||||
extern "C" void AgcDriverResolveGraphicsStagesAbi_nid_postfix(std::span<const Shader* const> stages, std::span<const ShaderRegister> context, std::span<const ShaderRegister> primitive) {
|
||||
Require(!stages.empty() && stages[0] != nullptr && context.size() == 2u && primitive.size() == 3u);
|
||||
++preparations;
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverResolveShaderAbi_nid_postfix(const Shader* shader, std::span<const ShaderRegister> context, std::span<const ShaderRegister> primitive) {
|
||||
Require(shader != nullptr && context.size() == 32u && primitive.empty());
|
||||
mappedPixel = shader;
|
||||
++mappings;
|
||||
}
|
||||
|
||||
extern "C" void AgcDriverResolveGraphicsAbi_nid_postfix(const Shader* vertex, const Shader* pixel, std::uint32_t primitiveType) {
|
||||
Require(vertex != nullptr && (pixel == nullptr || pixel == mappedPixel) && (primitiveType == 0u || primitiveType == 2u || primitiveType == 4u));
|
||||
++links;
|
||||
}
|
||||
int main() {
|
||||
using namespace ShaderRegs;
|
||||
auto* defaults = static_cast<unsigned char*>(sceAgcGetRegisterDefaults());
|
||||
@@ -83,4 +104,5 @@ int main() {
|
||||
input.default_value = 2;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == 0);
|
||||
Require(context[2].value == 0x220);
|
||||
Require(preparations == 4u && mappings == 3u && links == 7u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user