From 3d8b94a4f06f964d1ca73b7a55d899f420b27114 Mon Sep 17 00:00:00 2001 From: Stuart Russell Date: Thu, 5 Nov 2026 13:50:36 +0000 Subject: [PATCH 1/2] fix(agc): discard primitives when the shader exports no position SPI_SHADER_POS_FORMAT entry 0 is SPI_SHADER_ZERO: no position reaches the clipper, so the draw rasterizes nothing. The pipeline, draw and journal keys and the vertex-position validation already carry State::rasterizerDiscard, but the decode required a four-component position and never set it. Set it from the register, and mix and compare it in the draw lookup key and sameDecode so a discarded draw does not share a cached decode. --- .../Execution/src/Driver/Draw/DrawLookup.cpp | 1 + .../src/Driver/Draw/DrawRegisterKey.cpp | 2 +- .../prx/libSceAgcDriver/Graphics/src/State.cpp | 7 ++++++- .../prx/libSceAgcDriver/tests/Graphics.cpp | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp index c61e3112c581..f294b0255e34 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cpp @@ -33,6 +33,7 @@ void Driver::lookupDraw(const Submission& submission, const std::shared_ptr> (4u * slot)) & 0xfu) == 0) continue; diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index ec7b24e9a482..5c6f133af07c 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -432,6 +432,24 @@ void stateTests() { Require(state.color.address == reinterpret_cast(colorMemory.data()) && state.color.bytes == colorMemory.size(), "render-target address or size changed"); Require(state.viewport.y == 4 && state.viewport.height == -4, "negative viewport height was lost"); Require(state.color.format == VK_FORMAT_R8G8B8A8_UNORM, "RGBA format changed"); + Require(!state.rasterizerDiscard, "a four-component position export discarded rasterization"); + queue.context[0x1b3] = 2; + queue.context[0x1b4] = 2; + queue.context[0x1c3] = 0; + state = AgcDriver::Graphics::DecodeState(queue); + Require(state.rasterizerDiscard, "a disabled position export did not discard rasterization"); + Require(AgcDriver::Graphics::DrawRejection(queue, false).empty(), "a draw without a position export was rejected"); + queue.context[0x1c3] = 0x44; + Require(!AgcDriver::Graphics::DecodeState(queue).rasterizerDiscard, "an auxiliary position export discarded rasterization"); + queue.context[0x1c3] = 1; + expectFailure([&] { AgcDriver::Graphics::DecodeState(queue); }, "position export format 1"); + queue.context[0x1c3] = 2; + expectFailure([&] { AgcDriver::Graphics::DecodeState(queue); }, "position export format 2"); + queue.context[0x1c3] = 3; + expectFailure([&] { AgcDriver::Graphics::DecodeState(queue); }, "position export format 3"); + queue = makeState(); + queue.context[0x1c3] = 0; + Require(AgcDriver::Graphics::CanonicalPipelineState(AgcDriver::Graphics::DecodeState(queue)).rasterizerDiscard, "the canonical state dropped the rasterizer discard"); queue.userConfig[0x24b] = 1; queue.context[0x1b3] = 2; queue.context[0x1b4] = 2; From 695ba80a7d03afe244d6743140da175aabeacd01 Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Fri, 6 Nov 2026 03:03:15 +1300 Subject: [PATCH 2/2] fix(agc): accept a vertex shader without a position export when the draw discards The vertex position check in ShaderValidation exempted only evaluation and geometry shaders from a discarded draw, so a vertex shader without a position export was still rejected after SPI_SHADER_POS_FORMAT entry 0 set the discard. Adds a validator test with a position-less vertex shader and a debt row for the unmeasured hardware behaviour. --- .../Graphics/src/ShaderValidation.cpp | 2 +- core/libs/prx/libSceAgcDriver/tests/Graphics.cpp | 12 +++++++++++- docs/dev/debt/libSceAgcDriver.md | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp index aea5f0387147..9f01667e4b40 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp @@ -650,7 +650,7 @@ Module Inspect(const CompiledShader& compiled, const State& state, const VkPhysi if (mesh) Require(module.primitiveIndices == state.stages.mesh->outputPrimitiveSize, "mesh shader does not export primitive indices"); if (fragment) Require(module.primitiveInputs == 0 || !primitiveLocations.empty(), "per-primitive pixel inputs need the barycentric emulation layout"); if (fragment) Require(!module.meshCapability || module.primitiveInputs != 0, "a pixel shader declares mesh shading without a per-primitive input"); - if (stage == Stage::Vertex || mesh || ((evaluation || geometry) && !state.rasterizerDiscard)) Require(module.position, "vertex shader does not export position"); + if (mesh || ((stage == Stage::Vertex || evaluation || geometry) && !state.rasterizerDiscard)) Require(module.position, "vertex shader does not export position"); return module; } diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index 5c6f133af07c..3f87c2888a47 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -8223,6 +8223,7 @@ struct ModuleShape { bool layerOutput = false; bool terminateInvocation = false; bool omitTerminateExtension = false; + bool noPosition = false; }; void emit(std::vector& out, spv::Op op, std::initializer_list operands) { @@ -8372,7 +8373,7 @@ std::vector makeModule(const ModuleShape& shape) { emit(declarations, spv::OpVariable, {inputPointer, input, spv::StorageClassInput}); emit(annotations, spv::OpDecorate, {input, spv::DecorationLocation, 0}); } - if (shape.fragment) emit(annotations, spv::OpDecorate, {output, spv::DecorationLocation, 0}); + if (shape.fragment || shape.noPosition) emit(annotations, spv::OpDecorate, {output, spv::DecorationLocation, 0}); else emit(annotations, spv::OpDecorate, {output, spv::DecorationBuiltIn, spv::BuiltInPosition}); if (shape.push) { const auto length = id(); @@ -9347,6 +9348,15 @@ void barycentricEmulationTests() { expectFailure([&] { ValidateShaders(shaders, state, subgroup, false, false, false, true); }, "triangle primitives"); state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; ValidateShaders(shaders, state, subgroup, false, false, false, true); + RecompileResult withoutPosition; + withoutPosition.spirv = makeModule({.noPosition = true}); + RecompileResult plainPixel; + plainPixel.spirv = makeModule({.fragment = true}); + const std::array withoutPositionShaders{{{ShaderStage::Vertex, &withoutPosition, 0}, {ShaderStage::Fragment, &plainPixel, 0}}}; + expectFailure([&] { ValidateShaders(withoutPositionShaders, state, subgroup, false, false, false, true); }, "vertex shader does not export position"); + auto discarded = state; + discarded.rasterizerDiscard = true; + ValidateShaders(withoutPositionShaders, discarded, subgroup, false, false, false, true); const auto plain = compile(interpolates, false); const std::array plainShaders{{{ShaderStage::Vertex, &vertex, 0}, {ShaderStage::Geometry, &geometry, 0}, {ShaderStage::Fragment, &plain, 0}}}; expectFailure([&] { ValidateShaders(plainShaders, state, subgroup, false, false, false, true); }, "only for emulated barycentrics"); diff --git a/docs/dev/debt/libSceAgcDriver.md b/docs/dev/debt/libSceAgcDriver.md index dd36b4331379..65f347169de8 100644 --- a/docs/dev/debt/libSceAgcDriver.md +++ b/docs/dev/debt/libSceAgcDriver.md @@ -403,6 +403,8 @@ - [Device-lost fault attribution](../../../core/libs/prx/libSceAgcDriver/Execution/include/DeviceFault.hpp) (libSceAgcDriver): a device loss prints the faulting VA with its guest snapshot (owner or neighbours), a bracket window (last completed, in flight, first not started, last 8 tokens) and draw/dispatch tokens (serial, program, variant, desc). Find returns the entry by value (acquire-load, copy, acquire-reload); Claim clears the slot first so a reused token misses instead of aliasing (reuse test). Draws emit their token through the NV checkpoint backend (emission test); serial falls back to the checkpoint marker. Queues report separately with role and queue id; live resources copy under a mutex. Needs APS5_GPU_CHECKPOINTS; the marker buffer stays AMD-only, NVIDIA is draw-only. Cannot name T# or pending write-back. Vendor dump via APS5_DUMP_DEVICE_FAULT where supported. Opened for PPSA01342 (#10634): second-world load faults a write with no checkpoint reached. - [sceAgcSdmaClose, sceAgcSdmaConstFill, sceAgcSdmaCopyLinear, sceAgcSdmaCopyTiledBC, sceAgcSdmaCopyTiledGen2, sceAgcSdmaCopyWindowBC, sceAgcSdmaCopyWindowGen2, sceAgcSdmaFlush, sceAgcSdmaOpen, sceAgcSdmaSetTileModesBC](../../../core/libs/prx/libSceAgcDriver/Export.cpp) (libSceAgcDriver) - names and NIDs are present in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceAgcDriver.c) and the [verified NID name database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv); they are declared without parameters and throw through `NotImplemented_nid_no_patch`. The sibling [libSceSdma](../../../core/libs/prx/libSceSdma/Export.cpp) exports the same operations under different `sceSdma*` NIDs, but the driver-level prototypes, handle layout and behavior are unknown; this is not an ABI claim. +- [SPI_SHADER_POS_FORMAT without a position export](../../../core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp) (libSceAgcDriver) - a `POS0` entry of 0 (`SPI_SHADER_ZERO`) is decoded as a draw that rasterizes nothing and sets `rasterizerDiscardEnable`. That follows the register name; no console measurement shows the hardware discards the primitives rather than faulting or rasterizing an undefined position, and Mesa only programs `POS0` as four components. Other `POS0` formats than 0 and 4 stop the title. + ### Opt-in draw paths - [Draw finisher](../../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cpp) (`APS5_DRAW_PIPELINE`) - opt-in. The Linux main-image page table it adds matches what Windows already does by default.