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..3356a12ec76b 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,8 @@ 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); +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 b69bccd8fe07..150589cabe5b 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp @@ -841,6 +841,28 @@ std::optional DispatchFloatMode(const ShaderS 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) { + 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 std::vector ReadHeaderArray(const ShaderSnapshot& snapshot, const TValue* pointer, std::size_t count) { if (count == 0) return {}; @@ -1036,14 +1058,17 @@ 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); + 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 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 +1076,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);