mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(agc): compose basic shader linkage register blocks
This commit is contained in:
@@ -104,6 +104,15 @@ endforeach()
|
||||
add_custom_target(libs DEPENDS ${PATCHED_OUTPUTS})
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_executable(guest_shader_link_tests tests/GuestShaderLink.cpp)
|
||||
target_include_directories(guest_shader_link_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(guest_shader_link_tests PRIVATE libSceAgc libc)
|
||||
configure_windows_unwind(guest_shader_link_tests)
|
||||
add_test(NAME guest_shader_link COMMAND guest_shader_link_tests)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_shader_link PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_executable(guest_system_exit_tests tests/GuestSystemExit.cpp)
|
||||
target_include_directories(guest_system_exit_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(guest_system_exit_tests PRIVATE libSceSystemService libc)
|
||||
|
||||
@@ -43,6 +43,7 @@ add_library(libSceAgc SHARED EXCLUDE_FROM_ALL
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Predication/src/Predication.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Shader/src/CreateShader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Shader/src/InterpolantMapping.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Shader/src/LinkShaders.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Shader/src/PrimState.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Shader/src/ShaderUtils.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "SceShaders.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include "prx/libSceAgc/Shader/include/ShaderConstants.hpp"
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
extern "C" int APS5_VABI sceAgcCreatePrimState(ShaderRegister*, ShaderRegister*, const Shader*, const Shader*, std::uint32_t);
|
||||
extern "C" int APS5_VABI sceAgcCreateInterpolantMapping(ShaderRegister*, const Shader*, const Shader*);
|
||||
|
||||
extern "C" int APS5_VABI sceAgcLinkShaders(ShaderRegister* context, ShaderRegister* primitive,
|
||||
const void* reserved, const Shader* vertex, const Shader* pixel, std::uint32_t primitiveType) {
|
||||
using namespace ShaderRegs;
|
||||
if (!context || !primitive || reserved || !vertex ||
|
||||
vertex->type != static_cast<std::uint8_t>(ShaderBinaryType::Gs) ||
|
||||
(vertex->num_output_semantics && !vertex->output_semantics) ||
|
||||
(pixel && (pixel->type != static_cast<std::uint8_t>(ShaderBinaryType::Ps) ||
|
||||
pixel->num_input_semantics > 32 ||
|
||||
(pixel->num_input_semantics && !pixel->input_semantics))))
|
||||
return GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM;
|
||||
|
||||
// The simple vertex/pixel pipeline combines two primitive context registers
|
||||
// and 32 interpolant registers. Publish only after both helpers succeed.
|
||||
std::array<ShaderRegister, 34> contextValues{};
|
||||
std::array<ShaderRegister, 3> primitiveValues{};
|
||||
try {
|
||||
sceAgcCreatePrimState(contextValues.data(), primitiveValues.data(), nullptr, vertex, primitiveType);
|
||||
sceAgcCreateInterpolantMapping(contextValues.data() + 2, vertex, pixel);
|
||||
} catch (const std::runtime_error&) {
|
||||
return GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM;
|
||||
}
|
||||
std::copy(contextValues.begin(), contextValues.end(), context);
|
||||
std::copy(primitiveValues.begin(), primitiveValues.end(), primitive);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "SceShaders.hpp"
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include "prx/libSceAgc/Shader/include/ShaderConstants.hpp"
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
extern "C" int APS5_VABI sceAgcLinkShaders(ShaderRegister*, ShaderRegister*, const void*, const Shader*, const Shader*, std::uint32_t);
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
int main() {
|
||||
using namespace ShaderRegs;
|
||||
ShaderSpecialRegs special{};
|
||||
special.vgt_shader_stages_en = {VGT_SHADER_STAGES_EN, VGT_SHADER_STAGES_NGG_BIT};
|
||||
special.vgt_gs_out_prim_type = {VGT_GS_OUT_PRIM_TYPE, 0};
|
||||
special.ge_cntl = {GE_CNTL, 0x123};
|
||||
special.ge_user_vgpr_en = {GE_USER_VGPR_EN, 7};
|
||||
Shader vertex{};
|
||||
vertex.type = static_cast<std::uint8_t>(ShaderBinaryType::Gs);
|
||||
vertex.specials = &special;
|
||||
Shader pixel{};
|
||||
pixel.type = static_cast<std::uint8_t>(ShaderBinaryType::Ps);
|
||||
std::array<ShaderRegister, 35> context{};
|
||||
std::array<ShaderRegister, 4> primitive{};
|
||||
context.back() = {0xdeadbeef, 0xcafebabe};
|
||||
primitive.back() = context.back();
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == 0);
|
||||
Require(context[0].offset == VGT_SHADER_STAGES_EN && context[0].value == VGT_SHADER_STAGES_NGG_BIT);
|
||||
Require(context[1].offset == VGT_GS_OUT_PRIM_TYPE && context[1].value == 2);
|
||||
for (unsigned i = 0; i < 32; ++i)
|
||||
Require(context[i + 2].offset == SPI_PS_INPUT_CNTL_0 + i && context[i + 2].value == i);
|
||||
Require(primitive[0].offset == GE_CNTL && primitive[0].value == 0x123);
|
||||
Require(primitive[1].offset == GE_USER_VGPR_EN && primitive[1].value == 7);
|
||||
Require(primitive[2].offset == VGT_PRIMITIVE_TYPE && primitive[2].value == 4);
|
||||
Require(context.back().value == 0xcafebabe && primitive.back().value == 0xcafebabe);
|
||||
const auto savedContext = context;
|
||||
const auto savedPrimitive = primitive;
|
||||
pixel.num_input_semantics = 33;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM);
|
||||
Require(std::memcmp(context.data(), savedContext.data(), sizeof(context)) == 0);
|
||||
Require(std::memcmp(primitive.data(), savedPrimitive.data(), sizeof(primitive)) == 0);
|
||||
pixel.num_input_semantics = 0;
|
||||
special.ge_cntl.offset = 0;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == GRAPHICS5_ERROR_INVALID_SHADER_PROGRAM);
|
||||
Require(std::memcmp(context.data(), savedContext.data(), sizeof(context)) == 0);
|
||||
special.ge_cntl.offset = GE_CNTL;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, nullptr, 2) == 0);
|
||||
Require(context[1].value == 1 && primitive[2].value == 2);
|
||||
ShaderSemantic output{};
|
||||
output.semantic = 9;
|
||||
output.hardware_mapping = 5;
|
||||
vertex.output_semantics = &output;
|
||||
vertex.num_output_semantics = 1;
|
||||
ShaderSemantic input{};
|
||||
input.semantic = 9;
|
||||
input.is_flat_shaded = 1;
|
||||
pixel.input_semantics = &input;
|
||||
pixel.num_input_semantics = 1;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == 0);
|
||||
Require(context[2].offset == SPI_PS_INPUT_CNTL_0 && context[2].value == (5 | 0x400));
|
||||
input.semantic = 10;
|
||||
input.default_value = 2;
|
||||
Require(sceAgcLinkShaders(context.data(), primitive.data(), nullptr, &vertex, &pixel, 4) == 0);
|
||||
Require(context[2].value == 0x220);
|
||||
}
|
||||
@@ -426,3 +426,25 @@ shutdown test. All twenty-four tests pass and the libraries rebuild.
|
||||
The unchanged game resolves freopen and _Exit. Startup now stops at
|
||||
`MqAdbRMdNz4` (`sceAgcLinkShaders`), moving the next investigation into shader
|
||||
linking. No guest entry-point execution or rendered frame has been observed.
|
||||
|
||||
## Follow-up: basic shader linking
|
||||
|
||||
Added sceAgcLinkShaders for the basic vertex/pixel pipeline by composing the
|
||||
existing primitive-state and interpolant-mapping implementations. It produces
|
||||
34 context-register records and three user-configuration records, matching the
|
||||
buffer sizes consumed by the native ps5link-sdk gpu_cube example. The context
|
||||
layout combines two primitive-state records with 32 interpolant records; this
|
||||
composition is inferred from the existing helpers and native caller, not from
|
||||
a captured hardware result. No homebrew rendering code was copied into the library.
|
||||
|
||||
Inputs are validated and results are staged before touching caller outputs.
|
||||
Tests check triangle/line primitive values, identity interpolants, semantic
|
||||
matching, flat shading, missing-semantic defaults, buffer boundaries, and
|
||||
unchanged outputs on invalid input. Reserved/non-basic pipeline inputs are
|
||||
rejected. All twenty-five tests pass; comparison against real console register
|
||||
output and end-to-end rendering remains outstanding.
|
||||
|
||||
The unchanged game resolves sceAgcLinkShaders and stops at `Wi82ArQtAwg`
|
||||
(`sceAgcGetRegisterDefaults`). The project already has a versioned defaults
|
||||
implementation; the legacy entry point still needs its contract verified.
|
||||
Guest entry-point execution and rendered output remain unverified.
|
||||
|
||||
Reference in New Issue
Block a user