From 8ab3fa05c8d3e28d3e00ee66820bf8dc2749e28e Mon Sep 17 00:00:00 2001 From: fablevoid <340827264+fable-void@users.noreply.github.com> Date: Wed, 14 Oct 2026 01:40:12 +0000 Subject: [PATCH 1/2] fix(agc): prepare the push-less pixel variant only without fixed push slots Registration prepared every pixel shader twice: for its push slot and once more with no push constants, for pipelines that leave the pixel stage no push room. With fixed push slots (graphics pipeline libraries) every graphics ABI gives the pixel stage its own slot of PipelinePushSlotBytes (StagePushOffset, and the room the ABI resolution computes), so no draw can request the second variant: it was compiled, cached and kept for nothing, and it doubled the pixel work at registration. DriverDetail::RegistrationRequests lists the requests registration prepares. The push-less pixel variant is among them only for a target without fixed push slots; the partial-workgroup compute variant stays. Evidence: a title that registers about 3,100 pixel shaders at load kept 8,840 variants with 3.7 GiB of SPIR-V; its second pixel variants were about 1.3 GiB of that and 97 % byte-identical to the first (count over its shader disk cache). Tested: agc_driver_prepared_shaders gains RegistrationVariants (one pixel request with fixed push slots, two without, two compute requests); it fails without the change. Full ctest passes. Cherry-picked from fable-void's 22e072b3d6; conflict in Execution/include/Driver/Shaders/ShaderRegistry.hpp and Execution/src/Driver/Shaders/ShaderRegistry.cpp resolved to main's InvocationFor/CaptureInvocation declarations, float-mode helpers, library prebuild switch and undrawn resource plan release. --- .../include/Driver/Shaders/ShaderRegistry.hpp | 1 + .../src/Driver/Shaders/ShaderRegistry.cpp | 29 ++++++++++++------- .../tests/execution/PreparedShaders.cpp | 17 +++++++++++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp b/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp index 203940d7c3b6..6c63209a1dcf 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp +++ b/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp @@ -217,6 +217,7 @@ ShaderRecompiler::RectListShaders PreparedRectangle(const ShaderSnapshot& snapsh ShaderRecompiler::RectListShaders DrawRectangle(const ShaderSnapshot& front, const std::shared_ptr& fragment, std::uint64_t vertexId, std::uint64_t fragmentId, const ShaderRecompiler::SpirvTarget& target); std::shared_ptr SourceHandleFor(const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request); +std::vector RegistrationRequests(const ShaderRecompiler::RecompileRequest& request); ShaderRecompiler::PreparedShaderInvocation InvocationFor(const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request); std::shared_ptr CaptureInvocation(ShaderMemory& memory, const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request, ShaderRecompiler::PreparedShaderInvocation& invocation); diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp index b69bccd8fe07..360fcce16f09 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp @@ -839,6 +839,18 @@ std::optional DispatchFloatMode(const ShaderS return DecodeFloatMode(live, snapshot.type); } +std::vector RegistrationRequests(const ShaderRecompiler::RecompileRequest& request) { + std::vector requests{request}; + if (request.context.compute) { + requests.push_back(request); + requests.back().context.compute->partialThreads = {1, 1, 1}; + } else if (request.context.pixel && !request.target.fixedPushSlots) { + requests.push_back(request); + requests.back().layout.pushConstantSizeBytes = 0; + } + return requests; +} + namespace { template @@ -1036,14 +1048,15 @@ void PrebuildStageLibrary(const std::shared_ptr& device, const Gra } std::vector PrepareRegistered(RegisteredPreparation& plan) { - auto& request = *plan.request; + const auto& request = *plan.request; + const auto requests = RegistrationRequests(request); std::vector entries; ShaderRecompiler::ShaderPreparationContext preparation; - const auto append = [&] { + const auto append = [&](const ShaderRecompiler::RecompileRequest& variant) { PerformanceTimer timing("Shader.PrepareArtifact"); - entries.push_back({plan.codeOffset, PrepareShaderWithDiagnostics(request, &preparation)}); + entries.push_back({plan.codeOffset, PrepareShaderWithDiagnostics(variant, &preparation)}); }; - append(); + append(requests.front()); if (plan.prebuildDevice != nullptr && request.target.registrationModules && request.shader.stage == ShaderRecompiler::ShaderStage::Fragment && !LibraryPrebuildDisabled()) { try { PrebuildStageLibrary(plan.prebuildDevice, {Graphics::ShaderPath::Vertex, 0u, 32u, request.context.waveSize, {}, {}}, request.shader.stage, ShaderRecompiler::RegistrationResult(request, *entries.front().handle), request.layout.pushConstantOffsetBytes); @@ -1051,13 +1064,7 @@ std::vector PrepareRegistered(RegisteredPreparation& pla APS5_LOG_OUT("shader library prebuild skipped: %s", error.what()); } } - if (request.context.compute) { - request.context.compute->partialThreads = {1, 1, 1}; - append(); - } else if (request.context.pixel) { - request.layout.pushConstantSizeBytes = 0; - append(); - } + for (std::size_t index = 1; index < requests.size(); ++index) append(requests[index]); if (plan.registration) { for (const auto& entry : entries) { if (entry.handle != nullptr) ShaderRecompiler::ReleaseUndrawnResourcePlan(*entry.handle); diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp index 734a7c68252f..050007eb59e6 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp @@ -104,6 +104,22 @@ void NullPixelAtDraw(AgcDriver::VulkanDevice& device) { Require(AgcDriver::DriverDetail::SourceHandleFor(snapshot, 0, request) == snapshot.prepared->entries.back().handle && snapshot.prepared->entries.size() == 2, "the null pixel program was prepared again for the same draw"); } +void RegistrationVariants() { + std::array code{0xbf810000u}; + std::array users{}; + const auto pixel = AgcDriver::Graphics::DecodePixelStageInfo({}, {}, true); + ShaderRecompiler::RecompileRequest fragment{{ShaderRecompiler::ShaderStage::Fragment, 0x10000u, code, 0, {}}, {32, 0, users, {}, pixel, {}, {}}, {}, {0, 0, 128, 128}}; + fragment.target.fixedPushSlots = true; + Require(AgcDriver::DriverDetail::RegistrationRequests(fragment).size() == 1, "registration prepared a pixel variant without push data for a target whose pipelines give the pixel stage a fixed push slot"); + fragment.target.fixedPushSlots = false; + const auto unfixed = AgcDriver::DriverDetail::RegistrationRequests(fragment); + Require(unfixed.size() == 2 && unfixed[0].layout.pushConstantSizeBytes == 128 && unfixed[1].layout.pushConstantSizeBytes == 0, "registration did not prepare the pixel variant without push data for a target without fixed push slots"); + const ShaderRecompiler::ShaderComputeStageInfo compute{{1, 1, 1}, 0, {false, false, false}, false, 1, {}}; + const ShaderRecompiler::RecompileRequest dispatch{{ShaderRecompiler::ShaderStage::Compute, 0x10000u, code, 0, {}}, {32, 0, users, compute, {}, {}, {}}, {}, {0, 0, 0, 128}}; + const auto partial = AgcDriver::DriverDetail::RegistrationRequests(dispatch); + Require(partial.size() == 2 && partial[1].context.compute->partialThreads == std::array{1, 1, 1}, "registration did not prepare the partial-workgroup compute variant"); +} + void Run(AgcDriver::VulkanDevice& device) { NullPixelAtDraw(device); alignas(256) std::array code{0xbf810000u}; @@ -1306,6 +1322,7 @@ int main(int argc, char** argv) { std::cout << "deferred undecodable shader tests passed\n"; return 0; } + RegistrationVariants(); auto device = OpenVulkanTestDevice(); if (!device) return VulkanTestSkipped; Run(*device); From 7d177f1671bdef6519fdb3e23690fafb1fbcf265 Mon Sep 17 00:00:00 2001 From: Yunus Shaikh <75296019+EagleBearerYS@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:27:14 +0000 Subject: [PATCH 2/2] perf(agc): count the push-less pixel variants registration left out With APS5_PROFILE_DRAW set, the [draw] driver phases line now ends with the number of pixel shaders registered for a target with fixed push slots, each of which no longer prepares its variant without push data. A draw that still asked for that variant would log that it has no artifact prepared at registration. --- .../include/Driver/Shaders/ShaderRegistry.hpp | 1 + .../Execution/src/Driver/Draw/DrawTiming.cpp | 3 ++- .../Execution/src/Driver/Shaders/ShaderRegistry.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp b/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp index 6c63209a1dcf..3356a12ec76b 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp +++ b/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp @@ -218,6 +218,7 @@ ShaderRecompiler::RectListShaders DrawRectangle(const ShaderSnapshot& front, con std::shared_ptr SourceHandleFor(const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request); std::vector RegistrationRequests(const ShaderRecompiler::RecompileRequest& request); +std::uint64_t PushlessPixelVariantsSkipped(); ShaderRecompiler::PreparedShaderInvocation InvocationFor(const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request); std::shared_ptr CaptureInvocation(ShaderMemory& memory, const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request, ShaderRecompiler::PreparedShaderInvocation& invocation); diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawTiming.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawTiming.cpp index bfc4731ce1fc..798875714b77 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawTiming.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawTiming.cpp @@ -1,6 +1,7 @@ #include "prx/libSceAgcDriver/Execution/include/ProfileOutput.hpp" #include "prx/libSceAgcDriver/Execution/include/Driver/Driver.hpp" #include "prx/libSceAgcDriver/Execution/include/Driver/Draw/DrawTiming.hpp" +#include "prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp" namespace AgcDriver::DriverDetail { @@ -27,7 +28,7 @@ void Driver::addDrawPhases(const std::array& ms, b report += text; total += totals.ms[i]; } - 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(totals.packets), static_cast(totals.drawn), static_cast(totals.captures), report.c_str(), total * 1000 / static_cast(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); push-less pixel variants left out at registration %llu (cumulative)\n", static_cast(totals.packets), static_cast(totals.drawn), static_cast(totals.captures), report.c_str(), total * 1000 / static_cast(totals.packets), total, totals.ms[DrawRowGraphics], totals.ms[DrawRowSkipped], static_cast(PushlessPixelVariantsSkipped())); totals.ms = {}; totals.packets = totals.drawn = totals.captures = 0; } diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp index 360fcce16f09..150589cabe5b 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp @@ -839,6 +839,16 @@ std::optional DispatchFloatMode(const ShaderS return DecodeFloatMode(live, snapshot.type); } +namespace { + +std::atomic pushlessPixelVariantsSkipped{0}; + +} + +std::uint64_t PushlessPixelVariantsSkipped() { + return pushlessPixelVariantsSkipped.load(std::memory_order_relaxed); +} + std::vector RegistrationRequests(const ShaderRecompiler::RecompileRequest& request) { std::vector requests{request}; if (request.context.compute) { @@ -1050,6 +1060,8 @@ void PrebuildStageLibrary(const std::shared_ptr& device, const Gra std::vector PrepareRegistered(RegisteredPreparation& plan) { const auto& request = *plan.request; const auto requests = RegistrationRequests(request); + static const bool profile = std::getenv("APS5_PROFILE_DRAW") != nullptr; + if (profile && request.context.pixel && request.target.fixedPushSlots) pushlessPixelVariantsSkipped.fetch_add(1, std::memory_order_relaxed); std::vector entries; ShaderRecompiler::ShaderPreparationContext preparation; const auto append = [&](const ShaderRecompiler::RecompileRequest& variant) {