Skip to content
Open
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 @@ -137,6 +137,8 @@ class Driver {
static ShaderMemory::PendingWrite QueryPendingSpan(std::uint64_t address, std::size_t bytes, std::span<std::byte> known);
std::shared_ptr<const ShaderRegistry> RegisteredShaders();
static void SetCaptureCheckHook(void (*hook)());
static void SetDrawEntryHook(void (*hook)());
static void NotePendingWaitForTest(std::span<const std::uint32_t> packet);
static void SetDispatchItemHook(void (*hook)(std::span<const Graphics::GuestMemorySnapshot>));

private:
Expand Down Expand Up @@ -367,9 +369,12 @@ class Driver {
std::array<std::uint32_t, 8> words;
std::size_t count;
std::uint64_t received;
bool landed = false;
};
static std::vector<PendingWait>& pendingWaits();
static void notePendingWait(std::span<const std::uint32_t> packet, std::uint32_t queue, std::uint64_t received);
static void notePendingWait(std::span<const std::uint32_t> packet, std::uint64_t received);
static void dropPendingWaits(std::uint64_t awaited, bool satisfiedOnly);
static bool unsatisfiedWaitPending();
void landPendingWaits(std::uint32_t queue);
struct ResolvedDispatch {
std::uint64_t address = 0, key = 0, indirectArguments = 0, forgetAtCapture = 0;
Expand Down Expand Up @@ -427,8 +432,9 @@ class Driver {
void recordQueuedLabelsBeforeRead(std::uint32_t queue);
bool recordQueuedLabelsAfterCapture(std::uint32_t queue, std::span<const ShaderRecompiler::MemoryRegion> regions);
static void runCaptureCheckHook();
static void runDrawEntryHook();
static bool capturedCurrent(std::span<const ShaderRecompiler::MemoryRegion> captured, const ShaderSnapshot& code, const PreparedShaderState::UserDataLink* linking);
static bool capturedMemoryChanged(std::span<const ShaderRecompiler::MemoryRegion> regions, std::span<Graphics::GuestMemorySnapshot> compared = {}, const PreparedShaderState::UserDataLink* linking = nullptr);
static bool capturedMemoryChanged(std::span<const ShaderRecompiler::MemoryRegion> regions, std::span<Graphics::GuestMemorySnapshot> compared, const PreparedShaderState::UserDataLink* linking, bool required);
void noteQueuedLabels(std::uint32_t queue);
void recordQueuedLabelsByTry(std::uint32_t queue, std::atomic<std::uint64_t>& counter);
static void recordQueuedLabelsFromHook();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern std::atomic<std::uint64_t> labelFallbacks[5];

extern std::atomic<std::uint64_t> queuedLabels, labelGroups, immediateLabels;

extern std::atomic<std::uint64_t> packetLockRecords, packetLockSubmits, packetLockDeferred, packetSubmitDeferred, captureTryRecords, captureRetries, captureChangeRetries, suspendPoints;
extern std::atomic<std::uint64_t> packetLockRecords, packetLockSubmits, packetLockDeferred, packetSubmitDeferred, captureTryRecords, captureRetries, captureChangeRetries, captureChecks, captureChecksSkipped, suspendPoints;

extern std::atomic<std::uint64_t> recordTriesSkipped;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ShaderMemory {
static SupplyCounts Supplies();
[[nodiscard]] std::vector<std::shared_ptr<const ShaderRecompiler::SrtGuestWords>> SuppliedBlocks() const;
[[nodiscard]] std::size_t Bytes() const;
[[nodiscard]] bool ServedKnownValues() const { return servedKnown; }
struct VouchCounts {
std::uint64_t calls, blocks, refused, words;
};
Expand Down Expand Up @@ -184,6 +185,7 @@ class ShaderMemory {
std::uint32_t forceSync = 0;
std::uint64_t branchReadsRefused = 0;
bool waitBranches = false;
bool servedKnown = false;
};

// The positions, among a dispatch-cache variant's stored words, of the pure flat-SRT leaves a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ void Driver::dispatchSplitTableCall(QueueState& queue, std::span<const std::uint
}

void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet, const Submission& submission, std::uint64_t indirectArguments) {
const bool behindWait = unsatisfiedWaitPending();
PerformanceTimer timing("Driver.Dispatch");
const auto address = (static_cast<std::uint64_t>(readRegister(queue.shader, 0x20c)) << 8u) | (static_cast<std::uint64_t>(readRegister(queue.shader, 0x20d) & 0xffu) << 40u);
if (SkippedShader(address) || RefusedDispatch(address)) return;
Expand Down Expand Up @@ -570,6 +571,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,

std::shared_ptr<ShaderMemory> shaderMemory;
std::shared_ptr<const PreparedShaderState::UserDataLink> linking;
const auto compareRequired = [&] { return behindWait || snapshot.header.empty() || (shaderMemory != nullptr && shaderMemory->ServedKnownValues()); };
std::vector<ShaderRecompiler::MemoryRegion> captured;

std::vector<std::uint32_t> liveWords;
Expand Down Expand Up @@ -918,7 +920,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
}
if (pipelined) {
runCaptureCheckHook();
if (capturedMemoryChanged(captured, {}, captureLinking)) {
if (capturedMemoryChanged(captured, {}, captureLinking, compareRequired())) {
const RecaptureScope recapture;
dispatch(queue, packet, submission, indirectArguments);
return;
Expand Down Expand Up @@ -1044,7 +1046,7 @@ void Driver::dispatch(QueueState& queue, std::span<const std::uint32_t> packet,
if (!captureChecked) {
captureChecked = true;
runCaptureCheckHook();
if (capturedMemoryChanged(captured, snapshots, captureLinking)) {
if (capturedMemoryChanged(captured, snapshots, captureLinking, compareRequired())) {
gpuLock.unlock();
const RecaptureScope recapture;
dispatch(queue, packet, submission, indirectArguments);
Expand Down
16 changes: 11 additions & 5 deletions core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct DrawTail {
Pm4::DrawParameters drawParameters{};
Pm4::DrawParameters resolvedParameters{};
std::vector<DrawUserPatch> userPatches;
bool behindWait = false;
bool pipelined = false;
bool traceIndirect = false;
std::uint64_t dumpTarget = 0;
Expand Down Expand Up @@ -341,6 +342,8 @@ DrawVerdict Driver::draw(QueueState& queue, std::span<const std::uint32_t> packe
static const bool profile = std::getenv("APS5_PROFILE_DRAW") != nullptr;
auto tailHolder = std::make_shared<DrawTail>();
auto& tail = *tailHolder;
runDrawEntryHook();
tail.behindWait = unsatisfiedWaitPending();
tail.borderColorTable = Graphics::BorderColorTableBase(queue.context, Graphics::GraphicsBorderColorBase);
auto& phaseMs = tail.phaseMs;
auto& captures = tail.captures;
Expand Down Expand Up @@ -881,6 +884,9 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
auto& vertexInfos = tail.vertexInfos;
auto& decodeReads = tail.decodeReads;
auto& shaderMemory = tail.shaderMemory;
const auto compareRequired = [&] {
return tail.behindWait || !tail.userPatches.empty() || (shaderMemory != nullptr && shaderMemory->ServedKnownValues()) || std::any_of(tail.programs->begin(), tail.programs->end(), [](const DrawProgram& program) { return !program.nullPixel && program.binary.header.empty(); });
};
auto& results = tail.results;
auto& compiledStages = tail.compiledStages;
auto& stages = tail.stages;
Expand Down Expand Up @@ -1273,7 +1279,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
drainBeforeInline();
lockForDraw();
runCaptureCheckHook();
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots)) {
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots, nullptr, compareRequired())) {
gpuLock.unlock();
const RecaptureScope recapture;
return draw(*tail.queue, tail.packet, submission, tail.packetOffset, rejected);
Expand Down Expand Up @@ -1415,7 +1421,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
}
if (pipelined && pipelinedIndirect && record == lastDrawable && !gpuLock.owns_lock() && deferredLabels().labels.empty()) {
runCaptureCheckHook();
if (tail.queue != nullptr && capturedMemoryChanged(memory)) {
if (tail.queue != nullptr && capturedMemoryChanged(memory, {}, nullptr, compareRequired())) {
const RecaptureScope recapture;
return draw(*tail.queue, tail.packet, submission, tail.packetOffset, rejected);
}
Expand All @@ -1440,7 +1446,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
lockForDraw();
if (!recordedOne) {
runCaptureCheckHook();
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots)) {
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots, nullptr, compareRequired())) {
gpuLock.unlock();
const RecaptureScope recapture;
return draw(*tail.queue, tail.packet, submission, tail.packetOffset, rejected);
Expand Down Expand Up @@ -1486,7 +1492,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
}
if (pipelined && (!drawParameters.indirect || pipelinedIndirect) && (tail.queue == nullptr || deferredLabels().labels.empty())) {
runCaptureCheckHook();
if (capturedMemoryChanged(memory)) {
if (capturedMemoryChanged(memory, {}, nullptr, compareRequired())) {
const RecaptureScope recapture;
if (tail.queue != nullptr) return draw(*tail.queue, tail.packet, submission, tail.packetOffset, rejected);
restartFinishedDraw(tail);
Expand All @@ -1513,7 +1519,7 @@ DrawVerdict Driver::finishDraw(DrawTail& tail, PerformanceTimer& timing) {
if (drawParameters.indirect) drainBeforeInline();
lockForDraw();
runCaptureCheckHook();
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots)) {
if (tail.queue != nullptr && capturedMemoryChanged(memory, snapshots, nullptr, compareRequired())) {
gpuLock.unlock();
const RecaptureScope recapture;
return draw(*tail.queue, tail.packet, submission, tail.packetOffset, rejected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Driver::flushBetweenPackets(std::uint32_t queue, std::uint32_t header, bool
lastReport = reportNow;
const auto stores = Graphics::Recorder::StoreCounts();
const auto failed = [](TrySite site) { return static_cast<unsigned long long>(triesFailed[site].load()); };
AgcDriver::ProfilePrint_nid_no_patch("[labels] batch flushes between packets: %llu at the next packet, %llu by deadline, %llu by size cap (%llu well overdue, waited for the mutex); %llu boundary reaps; record tries skipped (self-locking next) %llu; failed tries: label %llu, flush %llu, reap %llu, poll %llu, idle %llu, capture %llu, poll-record %llu; at the packet's own lock: %llu label groups (%.0f ms), %llu submits (%.0f ms incl. queue 0's reaps), left to it by a failed try: %llu groups, %llu submits; after a capture: %llu groups recorded by a try, %llu packets redone for a queued label over the capture, %llu for captured memory that changed before recording; %llu suspend points; stores: %llu in %llu runs (%llu joined, %llu replaced, %llu WAW barriers, %llu joins refused; %llu runs recorded at submit, %llu in place before a writer or reader); DCC key stores: %llu queued in %llu runs (%llu before a writer, %llu joined a queued range); queued labels: %llu noted (%llu over a recorded entry), %llu same-queue wait hits, %llu groups recorded from a poll loop, %llu from the flush hook (%llu hook accesses, %llu inside a completion skipped)\n", static_cast<unsigned long long>(packetFlushes.load()), static_cast<unsigned long long>(deadlineFlushes.load()), static_cast<unsigned long long>(capFlushes.load()), static_cast<unsigned long long>(overdueLocks.load()), static_cast<unsigned long long>(boundaryReaps.load()), static_cast<unsigned long long>(recordTriesSkipped.load()), failed(TryLabel), failed(TryFlush), failed(TryReap), failed(TryPoll), failed(TryIdle), failed(TryCapture), failed(TryPollRecord), static_cast<unsigned long long>(packetLockRecords.load()), packetLockRecordUs.load() / 1000.0, static_cast<unsigned long long>(packetLockSubmits.load()), packetLockSubmitUs.load() / 1000.0, static_cast<unsigned long long>(packetLockDeferred.load()), static_cast<unsigned long long>(packetSubmitDeferred.load()), static_cast<unsigned long long>(captureTryRecords.load()), static_cast<unsigned long long>(captureRetries.load()), static_cast<unsigned long long>(captureChangeRetries.load()), static_cast<unsigned long long>(suspendPoints.load()), static_cast<unsigned long long>(stores.stores), static_cast<unsigned long long>(stores.runs), static_cast<unsigned long long>(stores.joined), static_cast<unsigned long long>(stores.replaced), static_cast<unsigned long long>(stores.wawBarriers), static_cast<unsigned long long>(stores.joinsRefused), static_cast<unsigned long long>(stores.runsAtSubmit), static_cast<unsigned long long>(stores.runsForced), static_cast<unsigned long long>(stores.keyStores), static_cast<unsigned long long>(stores.keyStoreRuns), static_cast<unsigned long long>(stores.keyStoreRunsForWriter), static_cast<unsigned long long>(stores.keyStoresJoined), static_cast<unsigned long long>(stores.queuedNoted), static_cast<unsigned long long>(stores.queuedOverRecorded), static_cast<unsigned long long>(stores.queuedHits), static_cast<unsigned long long>(pollLabelRecords.load()), static_cast<unsigned long long>(hookLabelRecords.load()), static_cast<unsigned long long>(stores.queuedHookRecords), static_cast<unsigned long long>(stores.queuedHookInCompletion));
AgcDriver::ProfilePrint_nid_no_patch("[labels] batch flushes between packets: %llu at the next packet, %llu by deadline, %llu by size cap (%llu well overdue, waited for the mutex); %llu boundary reaps; record tries skipped (self-locking next) %llu; failed tries: label %llu, flush %llu, reap %llu, poll %llu, idle %llu, capture %llu, poll-record %llu; at the packet's own lock: %llu label groups (%.0f ms), %llu submits (%.0f ms incl. queue 0's reaps), left to it by a failed try: %llu groups, %llu submits; after a capture: %llu groups recorded by a try, %llu packets redone for a queued label over the capture, %llu for captured memory that changed before recording; capture checks %llu run, %llu skipped (no unlanded wait); %llu suspend points; stores: %llu in %llu runs (%llu joined, %llu replaced, %llu WAW barriers, %llu joins refused; %llu runs recorded at submit, %llu in place before a writer or reader); DCC key stores: %llu queued in %llu runs (%llu before a writer, %llu joined a queued range); queued labels: %llu noted (%llu over a recorded entry), %llu same-queue wait hits, %llu groups recorded from a poll loop, %llu from the flush hook (%llu hook accesses, %llu inside a completion skipped)\n", static_cast<unsigned long long>(packetFlushes.load()), static_cast<unsigned long long>(deadlineFlushes.load()), static_cast<unsigned long long>(capFlushes.load()), static_cast<unsigned long long>(overdueLocks.load()), static_cast<unsigned long long>(boundaryReaps.load()), static_cast<unsigned long long>(recordTriesSkipped.load()), failed(TryLabel), failed(TryFlush), failed(TryReap), failed(TryPoll), failed(TryIdle), failed(TryCapture), failed(TryPollRecord), static_cast<unsigned long long>(packetLockRecords.load()), packetLockRecordUs.load() / 1000.0, static_cast<unsigned long long>(packetLockSubmits.load()), packetLockSubmitUs.load() / 1000.0, static_cast<unsigned long long>(packetLockDeferred.load()), static_cast<unsigned long long>(packetSubmitDeferred.load()), static_cast<unsigned long long>(captureTryRecords.load()), static_cast<unsigned long long>(captureRetries.load()), static_cast<unsigned long long>(captureChangeRetries.load()), static_cast<unsigned long long>(captureChecks.load()), static_cast<unsigned long long>(captureChecksSkipped.load()), static_cast<unsigned long long>(suspendPoints.load()), static_cast<unsigned long long>(stores.stores), static_cast<unsigned long long>(stores.runs), static_cast<unsigned long long>(stores.joined), static_cast<unsigned long long>(stores.replaced), static_cast<unsigned long long>(stores.wawBarriers), static_cast<unsigned long long>(stores.joinsRefused), static_cast<unsigned long long>(stores.runsAtSubmit), static_cast<unsigned long long>(stores.runsForced), static_cast<unsigned long long>(stores.keyStores), static_cast<unsigned long long>(stores.keyStoreRuns), static_cast<unsigned long long>(stores.keyStoreRunsForWriter), static_cast<unsigned long long>(stores.keyStoresJoined), static_cast<unsigned long long>(stores.queuedNoted), static_cast<unsigned long long>(stores.queuedOverRecorded), static_cast<unsigned long long>(stores.queuedHits), static_cast<unsigned long long>(pollLabelRecords.load()), static_cast<unsigned long long>(hookLabelRecords.load()), static_cast<unsigned long long>(stores.queuedHookRecords), static_cast<unsigned long long>(stores.queuedHookInCompletion));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ bool Driver::recordQueuedLabelsAfterCapture(std::uint32_t queue, std::span<const
namespace {

std::atomic<void (*)()> captureCheckHook{nullptr};
std::atomic<void (*)()> drawEntryHook{nullptr};

bool& recapturing() {
static thread_local bool active = false;
Expand All @@ -219,8 +220,21 @@ void Driver::runCaptureCheckHook() {
if (const auto hook = captureCheckHook.load(std::memory_order_acquire)) hook();
}

bool Driver::capturedMemoryChanged(std::span<const ShaderRecompiler::MemoryRegion> regions, std::span<Graphics::GuestMemorySnapshot> compared, const PreparedShaderState::UserDataLink* linking) {
void Driver::SetDrawEntryHook(void (*hook)()) {
drawEntryHook.store(hook, std::memory_order_release);
}

void Driver::runDrawEntryHook() {
if (const auto hook = drawEntryHook.load(std::memory_order_acquire)) hook();
}

bool Driver::capturedMemoryChanged(std::span<const ShaderRecompiler::MemoryRegion> regions, std::span<Graphics::GuestMemorySnapshot> compared, const PreparedShaderState::UserDataLink* linking, bool required) {
if (recapturing()) return false;
if (!required && !unsatisfiedWaitPending()) {
++captureChecksSkipped;
return false;
}
++captureChecks;
const bool mark = compared.size() == regions.size();
std::vector<VouchedRegions> vouched;
if (linking != nullptr && vouchedValidation() && !validateLegacy()) linking->VouchRegions(regions, vouched);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ std::atomic<std::uint64_t> labelFallbacks[5] = {};

std::atomic<std::uint64_t> queuedLabels{0}, labelGroups{0}, immediateLabels{0};

std::atomic<std::uint64_t> packetLockRecords{0}, packetLockSubmits{0}, packetLockDeferred{0}, packetSubmitDeferred{0}, captureTryRecords{0}, captureRetries{0}, captureChangeRetries{0}, suspendPoints{0};
std::atomic<std::uint64_t> packetLockRecords{0}, packetLockSubmits{0}, packetLockDeferred{0}, packetSubmitDeferred{0}, captureTryRecords{0}, captureRetries{0}, captureChangeRetries{0}, captureChecks{0}, captureChecksSkipped{0}, suspendPoints{0};

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

Expand Down
Loading
Loading