Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ ShaderRecompiler::RectListShaders PreparedRectangle(const ShaderSnapshot& snapsh
ShaderRecompiler::RectListShaders DrawRectangle(const ShaderSnapshot& front, const std::shared_ptr<const ShaderSnapshot>& fragment, std::uint64_t vertexId, std::uint64_t fragmentId, const ShaderRecompiler::SpirvTarget& target);

std::shared_ptr<const ShaderRecompiler::SourceHandle> SourceHandleFor(const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request);
std::vector<ShaderRecompiler::RecompileRequest> 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<const ShaderRecompiler::ResourceCapture> CaptureInvocation(ShaderMemory& memory, const ShaderSnapshot& snapshot, std::size_t codeOffset, const ShaderRecompiler::RecompileRequest& request, ShaderRecompiler::PreparedShaderInvocation& invocation);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -27,7 +28,7 @@ void Driver::addDrawPhases(const std::array<double, DrawDriverPhaseCount>& 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<unsigned long long>(totals.packets), static_cast<unsigned long long>(totals.drawn), static_cast<unsigned long long>(totals.captures), report.c_str(), total * 1000 / static_cast<double>(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<unsigned long long>(totals.packets), static_cast<unsigned long long>(totals.drawn), static_cast<unsigned long long>(totals.captures), report.c_str(), total * 1000 / static_cast<double>(totals.packets), total, totals.ms[DrawRowGraphics], totals.ms[DrawRowSkipped], static_cast<unsigned long long>(PushlessPixelVariantsSkipped()));
totals.ms = {};
totals.packets = totals.drawn = totals.captures = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,28 @@ std::optional<ShaderRecompiler::ShaderFloatMode> DispatchFloatMode(const ShaderS

namespace {

std::atomic<std::uint64_t> pushlessPixelVariantsSkipped{0};

}

std::uint64_t PushlessPixelVariantsSkipped() {
return pushlessPixelVariantsSkipped.load(std::memory_order_relaxed);
}

std::vector<ShaderRecompiler::RecompileRequest> RegistrationRequests(const ShaderRecompiler::RecompileRequest& request) {
std::vector<ShaderRecompiler::RecompileRequest> 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<typename TValue>
std::vector<TValue> ReadHeaderArray(const ShaderSnapshot& snapshot, const TValue* pointer, std::size_t count) {
if (count == 0) return {};
Expand Down Expand Up @@ -1036,28 +1058,25 @@ void PrebuildStageLibrary(const std::shared_ptr<VulkanDevice>& device, const Gra
}

std::vector<PreparedShaders::Entry> 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<PreparedShaders::Entry> 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);
} catch (const std::exception& error) {
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);
Expand Down
17 changes: 17 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint32_t, 1> code{0xbf810000u};
std::array<std::uint32_t, 4> 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<std::uint32_t, 3>{1, 1, 1}, "registration did not prepare the partial-workgroup compute variant");
}

void Run(AgcDriver::VulkanDevice& device) {
NullPixelAtDraw(device);
alignas(256) std::array<std::uint32_t, 1> code{0xbf810000u};
Expand Down Expand Up @@ -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);
Expand Down
Loading