Repository navigation
perf(shader): cache BDA ranges in span reads - #14260
kiansaeidnia wants to merge 1 commit into
Conversation
A span read walked the BDA table for every access. Single-wave address-based programs pay that walk on their critical path: in Ghost of Yotei's opening cinematic, 0x807b90a100 spends 94 % of its time in a triangle loop of six runtime-format buffer loads, and the walk was about a third of each load. Each invocation now keeps the last four ranges its span reads found. A read inside one of them translates directly; a miss walks the table with the range-returning lookup and replaces the oldest entry with the range it finds. A kept range ends at the next range's start, so a hit resolves exactly as the walk would. The entries are separate variables indexed by constants, which keeps their local-memory footprint small. APS5_NO_BDA_RANGE_CACHE=1 walks the table for every read, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This pull request is labeled |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
CnRJay
left a comment
There was a problem hiding this comment.
Marked draft, so this is early feedback. The idea is sound for a single-wave loop of dependent loads, where the table walk is on the critical path. The cost lands on every shader with address-based span reads.
1. Local memory per thread is added to every program with a span read. Four (begin, bound, base) entries are 176 bytes per invocation, and the description's own first attempt showed what that costs: 270 MB more VRAM in the frame replay, and about 40 MB for the four-entry version. On NVIDIA that is also register or local-memory pressure for every wave, which lowers occupancy for programs that have many waves resident and do not need the cache. The win quoted is for a program that runs as one wave. Please apply the cache only where it can pay: a span read inside a loop, or a program whose launch is a single wave, and keep the table walk for the rest. Report the register or local-memory change for the largest captured programs from the replay.
2. The hit rate is not shown. Eight loads over five blocks test correctness. What decides the value is how often a real shader's reads hit one of four ranges. Please add hit and miss counters under the existing APS5_NO_BDA_RANGE_CACHE switch and report the ratio for the Yotei program and for two more titles. A 4-entry cache with oldest-replacement thrashes on a loop that cycles through five buffers.
3. Misses cost more than before. Each miss is a walk plus a replace, where before it was a walk. For a program with a low hit rate this is a regression. Show the replay time with the cache on and off for a program with scattered reads.
4. The numbers are on a different tree. The in-game table comes from the Celegans12 fork and the first version of the change, as the open items say. For the evidence to be usable, rerun it on exactly this commit, and on main for at least one title that runs there.
|
There is a correctness issue to address before promoting this cache: a cached guest range can include addresses whose physical translation overflows. I rechecked current head
The local correction bounds the cached extent by physical capacity: This is conservative and retains the existing exclusive-end overflow rule. Requests outside that safe interval miss and take the original checked lookup/fault path. The synthetic regression below performs two reads from an oversized table entry: the first is valid and warms the cache; the second wraps the translated device address. Both the uncached baseline and corrected cache preserve the first result, return zero for the second, and record Overflow, for coherent and noncoherent reads. The uncorrected malformed GPU access was not executed: the defect is established by source reasoning, supported by baseline/corrected regression results, not an observed crash. Fifteen focused BDA/buffer GPU tests passed on the corrected experimental stack with Vulkan required, shader cache disabled and validation enabled; no VUID or missing layer was observed. Current-main integration still needs qualification. Separately, the cache did not establish a repeatable performance win on our stationary five-frame GTA V replay. On Ryzen 9 3900X / RTX 3080 Ti / NVIDIA 610.88 / Windows / GCC 15.2 Release / SPIRV-Tools OFF, using the same archived integrated base
An unchanged run was as fast as the cache variants; clocks were monitored but not locked. One additional cache run needed an extra real memory restore and was excluded from matched timing, retained for correctness. Matched runs had exact three-buffer replay images and no failed/stale registrations, skipped mappings, unfinished submissions, pacing timeouts or synthesised waits; existing packet-wait/prebuild/pending-image warnings remained. This is exploratory replay evidence, not a current-main performance report or live-game speedup. Below are only our bound correction and synthetic regression, not a republication of the PR's implementation. The patch is against our archived integration and needs porting/retesting on the final PR composition. The input tables and expected values are synthetic; no GTA V code, shader, memory, image or log is included. AI-assisted investigation/code, built and checked locally. Physical-capacity correction and synthetic two-read regressiondiff --git a/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp
index 8682643..fe0f7a9 100644
--- a/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp
+++ b/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp
@@ -129,8 +129,11 @@ std::uint32_t DefineBdaLookup(SpirvEmitterState& state, const char* name, bool r
const auto last = binary(spv::OpUGreaterThanEqual, boolean, index, count);
const auto next = BdaLoadAddress(state, binary(spv::OpIAdd, u32, constant(4), binary(spv::OpIMul, u32, Select(state, u32, last, binary(spv::OpISub, u32, index, constant(1)), index), constant(8))));
const auto bound = Select(state, u64, binary(spv::OpLogicalOr, boolean, last, binary(spv::OpULessThan, boolean, finish, next)), finish, next);
+ const auto extent = binary(spv::OpISub, u64, bound, begin);
+ const auto capacity = binary(spv::OpISub, u64, BdaConstant(state, ~std::uint64_t{0}), base);
+ const auto safeBound = binary(spv::OpIAdd, u64, begin, Select(state, u64, binary(spv::OpULessThan, boolean, capacity, extent), capacity, extent));
const auto range = state.module.AllocateId();
- state.module.AddFunction(spv::OpCompositeConstruct, rangeType, range, begin, bound, base);
+ state.module.AddFunction(spv::OpCompositeConstruct, rangeType, range, begin, safeBound, base);
leave(range);
} else {
leave(result);
diff --git a/core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp b/core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp
index b596aae..a7b0c6e 100644
--- a/core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/BdaExecution.cpp
@@ -519,6 +519,27 @@ void RunBdaExecutionTests(const Context& context) {
span(4, -8, 0b0001u, coherent, stops, {0, 0, 0, 0}, Abi::FaultReason::Overflow, 4, 0);
}
}
+ {
+ constexpr std::uint64_t firstGuest = 0x1000;
+ const auto secondGuest = firstGuest - wide.DeviceAddress() + 16u;
+ const Abi::Header header{Abi::Version, 1, sizeof(Abi::Range), 0};
+ const Abi::Range range{firstGuest, std::numeric_limits<std::uint64_t>::max(), wide.DeviceAddress(), Abi::Read, 0};
+ Buffer overflowTable(context, sizeof(header) + sizeof(range), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
+ std::memcpy(overflowTable.Bytes().data(), &header, sizeof(header));
+ std::memcpy(overflowTable.Bytes().data() + sizeof(header), &range, sizeof(range));
+ for (const bool coherent : {false, true}) {
+ std::memset(fault.Bytes().data(), 0, fault.Bytes().size());
+ std::memset(words.Bytes().data(), 0xcd, words.Bytes().size());
+ Pipeline pipeline(context, MakeBdaSpanSequenceTestShader(firstGuest, secondGuest, coherent), {&overflowTable, &fault, &words});
+ pipeline.Run(1);
+ Abi::Fault report{};
+ std::array<std::uint32_t, 2> result{};
+ std::memcpy(&report, fault.Bytes().data(), sizeof(report));
+ std::memcpy(result.data(), words.Bytes().data(), sizeof(result));
+ Require(result[0] == at(0) && result[1] == 0, "a warmed BDA span lookup lost its valid read or failed to reject device-address overflow");
+ Require(report.state == Abi::FaultState::Ready && report.reason == Abi::FaultReason::Overflow && report.address == secondGuest, "a warmed BDA span lookup did not retain device-address overflow reporting");
+ }
+ }
ranges[0].permissions = 0;
run(guest, 8, 0, Abi::FaultReason::Permission);
const auto sequence = [&](std::initializer_list<Abi::FaultReason> reasons, Abi::FaultReason recorded, std::uint32_t otherFaults) {
diff --git a/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp b/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp
index 955969b..59ff8b1 100644
--- a/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/BdaShader.cpp
@@ -87,6 +87,15 @@ std::vector<std::uint32_t> MakeBdaSpanReadTestShader(std::uint64_t address, std:
}, extracted);
}
+std::vector<std::uint32_t> MakeBdaSpanSequenceTestShader(std::uint64_t first, std::uint64_t second, bool coherent) {
+ using namespace ShaderRecompiler;
+ return MakeShader(first, coherent, false, [&](SpirvValueEmitContext& ctx, const IrValue& instruction, std::uint32_t base) {
+ const auto initial = EmitBdaDwordReads(ctx, instruction, base, 0u, 4u);
+ const auto next = EmitBdaDwordReads(ctx, instruction, BdaConstant(ctx.state, second), 0u, 4u);
+ return std::vector<std::uint32_t>{initial[0], next[0]};
+ }, 1u);
+}
+
std::vector<std::uint32_t> MakeBdaDwordWriteTestShader(std::uint64_t address, std::uint32_t dwords, const std::uint32_t* values) {
using namespace ShaderRecompiler;
return MakeShader(address, false, true, [&](SpirvValueEmitContext& ctx, const IrValue& instruction, std::uint32_t base) {
diff --git a/core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp b/core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp
index 31c068d..73fe98e 100644
--- a/core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp
+++ b/core/libs/prx/libSceAgcDriver/tests/BdaShader.hpp
@@ -10,6 +10,7 @@
std::vector<std::uint32_t> MakeBdaTestShader(std::uint64_t address, std::uint32_t bits, std::int64_t offset = 0);
std::vector<std::uint32_t> MakeBdaDwordReadTestShader(std::uint64_t address, std::uint32_t dwords, bool coherent, bool stops);
std::vector<std::uint32_t> MakeBdaSpanReadTestShader(std::uint64_t address, std::uint32_t offset, std::uint32_t extracted, bool coherent, bool stops);
+std::vector<std::uint32_t> MakeBdaSpanSequenceTestShader(std::uint64_t first, std::uint64_t second, bool coherent);
std::vector<std::uint32_t> MakeBdaFaultSequenceTestShader(std::initializer_list<ShaderRecompiler::BdaAbi::FaultReason> reasons);
std::vector<std::uint32_t> MakeBdaDwordWriteTestShader(std::uint64_t address, std::uint32_t dwords, const std::uint32_t* values);
std::vector<std::uint32_t> MakeBdaStoreTestShader(std::uint64_t address, std::uint32_t value, std::uint32_t bits, bool coherent); |
|
Windows data point for this PR, from Ghost of Yōtei 02.002 (PPSA26344) at HOME on an RTX 4070 Ti SUPER (driver 610.88). Setup
Result: GPU busy for the frame (union of both lanes) went from 104.2 / 104.0 / 103.6 ms to 88.9 / 88.7 / 88.4 ms, -14.7 %.
How the columns were counted
Notes
Written by Claude Code, verified by me. |
|
Main-vs-PR captures for this PR, as the perf label asks. Title: Ghost of Yōtei 02.002 (PPSA26344) at the title menu. Machine: Windows, RTX 4070 Ti SUPER (driver 610.88), Ryzen 9 7950X. Result: no change. Frame times and GPU busy time are the same within the run spread. Setup
Results
Frame times and GPU busy time are in ms.
What it shows
Notes on the summary lines
The six
|
| Capture | Commit | Trace | Presents | Window (ms) |
|---|---|---|---|---|
| baseline | 6fe120d | aps5-trace-6fe120d11ba3-34060.json.gz | 187 | 60166.650 |
| candidate | 8630fa9 | aps5-trace-8630fa906d67-37604.json.gz | 186 | 60118.920 |
- Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene.
- Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval.
- A missing top phase is unreported, not zero; its change is unavailable.
- baseline: trace events were dropped; the event trace omits some of the work included in phase totals.
- baseline: source tree is dirty or its state is unknown; the commit alone does not identify the build.
- candidate: trace events were dropped; the event trace omits some of the work included in phase totals.
- candidate: source tree is dirty or its state is unknown; the commit alone does not identify the build.
Frame and GPU times (ms)
| Metric | Baseline | Candidate | Change | Change (%) |
|---|---|---|---|---|
| frame_ms.p50 | 321.824 | 322.310 | +0.486 | +0.151 |
| frame_ms.p90 | 326.495 | 330.087 | +3.592 | +1.100 |
| frame_ms.p99 | 335.027 | 342.600 | +7.573 | +2.260 |
| frame_ms.max | 338.747 | 347.835 | +9.088 | +2.683 |
| mean_frame_ms | 321.747 | 323.220 | +1.473 | +0.458 |
| gpu_busy_ms_per_present | 90.061 | 90.219 | +0.158 | +0.175 |
Top phases (ms per frame)
| Metric | Baseline | Candidate | Change | Change (%) |
|---|---|---|---|---|
| Driver.Dispatch | 164.342 | 167.015 | +2.673 | +1.626 |
| Driver.Packet | 1121.542 | 1133.567 | +12.025 | +1.072 |
| Driver.Packet.dispatch | 212.554 | 215.370 | +2.816 | +1.325 |
| Driver.Packet.draw | 52.194 | 53.563 | +1.369 | +2.623 |
| Driver.Packet.memory_wait | 660.508 | 667.210 | +6.702 | +1.015 |
| Graphics.Draw | 179.558 | 179.887 | +0.329 | +0.183 |
| Graphics.Draw.draw_and_resource_release | 176.793 | 177.120 | +0.327 | +0.185 |
| Resources.Complete | 180.566 | 180.292 | -0.274 | -0.152 |
tools/trace_digest.py aps5-trace-6fe120d11ba3-34060.json.gz (A1)
seconds 240:60 from present 1387: 187 presents, frame p50 321.8 / p90 326.5 / p99 335.0 / max 338.7 ms, GPU busy 90.1 ms per present
NVIDIA GeForce RTX 4070 Ti SUPER, NVIDIA 610.88, Windows 10.0.26300, 1920x1080, commit 6fe120d, dropped: yes
{"commit":"6fe120d11ba3","dirty":null,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":64704,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"02.002.000","resolution":"1920x1080","window":{"spec":"seconds 240:60","first_present":1387,"ms":60166.65},"presents":187,"frame_ms":{"p50":321.824,"p90":326.495,"p99":335.027,"max":338.747},"gpu_busy_ms_per_present":90.061,"worker_busy_pct":{"queue worker 0x0":96.671,"queue worker 0x52":33.967,"queue worker 0x53":31.784,"queue worker 0x20":35.773,"queue worker 0x30":40.473,"queue worker 0x38":45.667,"queue worker 0x48":1.191,"queue worker 0x51":1.31,"queue worker 0x50":62.878},"top_phases_ms_per_frame":{"Driver.Packet":1121.542,"Driver.Packet.memory_wait":660.508,"Driver.Packet.dispatch":212.554,"Resources.Complete":180.566,"Graphics.Draw":179.558,"Graphics.Draw.draw_and_resource_release":176.793,"Driver.Dispatch":164.342,"Driver.Packet.draw":52.194},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":45.794,"events_lost":81364,"totals_full":false}},"trace":"aps5-trace-6fe120d11ba3-34060.json.gz"}Slowest frames (largest slices inside each, inclusive)
- present 1465: 338.7 ms at 24979 ms: Driver.WorkerWait (queue worker 0x48) 335.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 335.1, Driver.WorkerWait (queue worker 0x51) 334.1, Driver.Packet (queue worker 0x0) 323.2
- present 1466: 335.0 ms at 25318 ms: Driver.WorkerWait (queue worker 0x48) 331.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 331.4, Driver.WorkerWait (queue worker 0x51) 330.2, Driver.Packet (queue worker 0x0) 319.3
- present 1487: 334.5 ms at 32103 ms: Driver.WorkerWait (queue worker 0x48) 330.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 330.8, Driver.WorkerWait (queue worker 0x51) 329.9, Driver.Packet (queue worker 0x0) 318.3
- present 1528: 334.3 ms at 45337 ms: Driver.WorkerWait (queue worker 0x51) 330.3, Driver.WorkerWait (queue worker 0x48) 330.3, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 330.3, Driver.Packet (queue worker 0x0) 318.6
- present 1463: 333.0 ms at 24314 ms: Driver.WorkerWait (queue worker 0x48) 329.6, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 329.6, Driver.WorkerWait (queue worker 0x51) 328.7, Driver.Packet (queue worker 0x0) 318.2
Threads (ms per frame)
| thread | busy | wait | untraced | in slices < 20 us | largest |
|---|---|---|---|---|---|
| title | 0.7 (0 %) | 0.0 (0 %) | 321.0 | 0.4 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.3 |
| queue worker 0x0 | 182.6 (57 %) | 58.7 (18 %) | 80.5 | 21.9 | Driver.Packet 233.4, Driver.Suspend 0.0 |
| queue worker 0x52 | 6.9 (2 %) | 313.5 (97 %) | 1.3 | 0.9 | Driver.Packet 107.8, Driver.EndSubmission 1.3 |
| queue worker 0x53 | 1.1 (0 %) | 319.5 (99 %) | 1.2 | 0.2 | Driver.Packet 102.1, Driver.EndSubmission 0.2 |
| queue worker 0x20 | 11.7 (4 %) | 308.8 (96 %) | 1.3 | 1.5 | Driver.Packet 114.9, Driver.EndSubmission 0.0 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| queue worker 0x30 | 15.1 (5 %) | 305.4 (95 %) | 1.2 | 0.8 | Driver.Packet 130.0, Driver.EndSubmission 0.1 |
| queue worker 0x38 | 74.3 (23 %) | 245.9 (76 %) | 1.5 | 3.4 | Driver.Packet 144.7, Driver.EndSubmission 1.8 |
| queue worker 0x48 | 2.3 (1 %) | 317.8 (99 %) | 1.7 | 0.5 | Driver.Packet 3.7, Driver.EndSubmission 0.1 |
| draw committer | 180.7 (56 %) | 5.5 (2 %) | 135.5 | 3.5 | Graphics.Draw 165.4, Recorder.Sync 15.0 |
| presenter | 4.2 (1 %) | 0.5 (0 %) | 317.0 | 0.1 | VideoOut.Flip 4.7, Driver.Present 0.0 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.1 | 0.2 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.5 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 321.2 | 0.2 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| queue worker 0x51 | 4.0 (1 %) | 316.7 (98 %) | 1.0 | 0.3 | Driver.Packet 4.1, Driver.EndSubmission 0.1 |
| queue worker 0x50 | 6.3 (2 %) | 315.2 (98 %) | 0.2 | 1.3 | Driver.Packet 202.2, Vulkan.Dispatch 0.0 |
| gpu | 90.1 (28 %) | 0.0 (0 %) | 231.7 | 0.0 | batch 90.1 |
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1758.8, Driver.WorkerWait.idle_and_completion_poll 1566.4, Driver.Packet 1042.8, Driver.Packet.memory_wait 649.6, Driver.Packet.dispatch 198.6, Driver.WorkerWait.dequeue_order 193.0, Resources.Complete 177.7, Graphics.Draw 175.4, Graphics.Draw.draw_and_resource_release 172.8, Driver.Dispatch 154.4
Longest waits
- Driver.WorkerWait (queue worker 0x48) 335.0 ms at 24993 ms, present 1465
- Driver.WorkerWait (queue worker 0x51) 333.7 ms at 24984 ms, present 1465
- Driver.WorkerWait (queue worker 0x48) 331.2 ms at 24327 ms, present 1463
- Driver.WorkerWait (queue worker 0x48) 331.1 ms at 25332 ms, present 1466
- Driver.WorkerWait (queue worker 0x51) 330.6 ms at 25322 ms, present 1466
- Driver.WorkerWait (queue worker 0x51) 330.0 ms at 45342 ms, present 1528
- Driver.WorkerWait (queue worker 0x51) 330.0 ms at 32107 ms, present 1487
- Driver.WorkerWait (queue worker 0x48) 329.6 ms at 32117 ms, present 1487
- Driver.WorkerWait (queue worker 0x48) 329.1 ms at 45352 ms, present 1528
- Driver.WorkerWait (queue worker 0x51) 329.0 ms at 24318 ms, present 1463
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
- batch 510: 10.3 ms at 1360 ms, present 1391: GPU no ranges; recorded by GpuMutex.wait.label (draw committer) 0.6, Graphics.Draw (draw committer) 0.3, Graphics.Draw.draw_and_resource_release (draw committer) 0.3, Recorder.Submit (draw committer) 0.1
- batch 3473: 9.3 ms at 10285 ms, present 1419: GPU no ranges; recorded by GpuMutex.wait.label (draw committer) 0.2, Graphics.Draw.validate (draw committer) 0.0, GpuMutex.wait.draw (draw committer) 0.0
- batch 16357: 8.6 ms at 49001 ms, present 1539: GPU no ranges; recorded by GpuMutex.wait.label (draw committer) 0.5
- batch 19134: 8.5 ms at 57394 ms, present 1565: GPU no ranges; recorded by no CPU slices
- batch 7222: 8.5 ms at 21587 ms, present 1454: GPU no ranges; recorded by Graphics.Draw (draw committer) 0.6, Graphics.Draw.draw_and_resource_release (draw committer) 0.6
tools/trace_digest.py aps5-trace-8630fa906d67-37604.json.gz (B3)
seconds 240:60 from present 1396: 186 presents, frame p50 322.3 / p90 330.1 / p99 342.6 / max 347.8 ms, GPU busy 90.2 ms per present
NVIDIA GeForce RTX 4070 Ti SUPER, NVIDIA 610.88, Windows 10.0.26300, 1920x1080, commit 8630fa9, dropped: yes
{"commit":"8630fa906d67","dirty":null,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"240:60"},"gpu":"NVIDIA GeForce RTX 4070 Ti SUPER","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 9 7950X 16-Core Processor","cpu_threads":32,"memory_mib":64704,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"02.002.000","resolution":"1920x1080","window":{"spec":"seconds 240:60","first_present":1396,"ms":60118.92},"presents":186,"frame_ms":{"p50":322.31,"p90":330.087,"p99":342.6,"max":347.835},"gpu_busy_ms_per_present":90.219,"worker_busy_pct":{"queue worker 0x0":96.741,"queue worker 0x20":36.335,"queue worker 0x52":34.377,"queue worker 0x53":32.314,"queue worker 0x30":40.941,"queue worker 0x38":45.65,"queue worker 0x48":1.235,"queue worker 0x51":1.298,"queue worker 0x50":62.576},"top_phases_ms_per_frame":{"Driver.Packet":1133.567,"Driver.Packet.memory_wait":667.21,"Driver.Packet.dispatch":215.37,"Resources.Complete":180.292,"Graphics.Draw":179.887,"Graphics.Draw.draw_and_resource_release":177.12,"Driver.Dispatch":167.015,"Driver.Packet.draw":53.563},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":45.875,"events_lost":80491,"totals_full":false}},"trace":"aps5-trace-8630fa906d67-37604.json.gz"}Slowest frames (largest slices inside each, inclusive)
- present 1579: 347.8 ms at 59111 ms: Driver.WorkerWait (queue worker 0x48) 343.6, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 343.6, Driver.WorkerWait (queue worker 0x51) 342.9, Driver.WorkerWait (queue worker 0x53) 237.9
- present 1578: 342.6 ms at 58769 ms: Driver.WorkerWait (queue worker 0x48) 338.9, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 338.9, Driver.WorkerWait (queue worker 0x51) 338.1, Driver.WorkerWait (queue worker 0x53) 227.7
- present 1577: 341.9 ms at 58427 ms: Driver.WorkerWait (queue worker 0x51) 336.5, Driver.WorkerWait (queue worker 0x48) 335.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 335.2, Driver.WorkerWait (queue worker 0x53) 235.4
- present 1494: 339.4 ms at 31559 ms: Driver.WorkerWait (queue worker 0x48) 335.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 335.4, Driver.WorkerWait (queue worker 0x51) 334.8, Driver.Packet (queue worker 0x0) 324.3
- present 1523: 337.2 ms at 40957 ms: Driver.WorkerWait (queue worker 0x51) 332.7, Driver.WorkerWait (queue worker 0x48) 330.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 330.0, Driver.Packet (queue worker 0x0) 321.4
Threads (ms per frame)
| thread | busy | wait | untraced | in slices < 20 us | largest |
|---|---|---|---|---|---|
| title | 0.7 (0 %) | 0.0 (0 %) | 322.5 | 0.4 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.3 |
| queue worker 0x0 | 184.5 (57 %) | 58.5 (18 %) | 80.2 | 22.1 | Driver.Packet 235.3, Driver.Draw.draw_enqueued 0.0 |
| queue worker 0x20 | 11.3 (4 %) | 310.5 (96 %) | 1.4 | 1.4 | Driver.Packet 117.2, Driver.EndSubmission 0.0 |
| queue worker 0x52 | 6.6 (2 %) | 315.3 (98 %) | 1.3 | 0.9 | Driver.Packet 109.5, Driver.EndSubmission 1.5 |
| queue worker 0x53 | 0.8 (0 %) | 321.2 (99 %) | 1.2 | 0.2 | Driver.Packet 104.3, Driver.EndSubmission 0.1 |
| title | 0.5 (0 %) | 0.0 (0 %) | 322.7 | 0.1 | Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.6 | 0.1 | Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.6 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| queue worker 0x30 | 14.6 (5 %) | 307.4 (95 %) | 1.2 | 0.8 | Driver.Packet 132.2, Driver.EndSubmission 0.0 |
| queue worker 0x38 | 75.8 (23 %) | 245.8 (76 %) | 1.5 | 3.5 | Driver.Packet 146.6, Driver.EndSubmission 0.4 |
| queue worker 0x48 | 2.2 (1 %) | 319.2 (99 %) | 1.8 | 0.5 | Driver.Packet 3.8, Driver.EndSubmission 0.2 |
| draw committer | 181.6 (56 %) | 6.2 (2 %) | 135.4 | 3.5 | Graphics.Draw 165.7, Recorder.Sync 15.6 |
| presenter | 4.2 (1 %) | 0.3 (0 %) | 318.6 | 0.1 | VideoOut.Flip 4.6, Driver.Present 0.0 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.7 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.7 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.7 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.6 | 0.1 | Shader.ResolveGraphicsAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.6 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.6 | 0.2 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| title | 0.6 (0 %) | 0.0 (0 %) | 322.7 | 0.1 | Shader.ResolveGraphicsAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.2 |
| queue worker 0x51 | 4.0 (1 %) | 318.2 (98 %) | 1.1 | 0.3 | Driver.Packet 4.1, Driver.EndSubmission 0.1 |
| queue worker 0x50 | 6.0 (2 %) | 317.0 (98 %) | 0.2 | 1.4 | Driver.Packet 202.1, Vulkan.Dispatch 0.0 |
| gpu | 90.2 (28 %) | 0.0 (0 %) | 233.0 | 0.0 | batch 90.2 |
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1760.9, Driver.WorkerWait.idle_and_completion_poll 1568.4, Driver.Packet 1055.1, Driver.Packet.memory_wait 656.8, Driver.Packet.dispatch 201.1, Driver.WorkerWait.dequeue_order 193.1, Resources.Complete 177.6, Graphics.Draw 175.7, Graphics.Draw.draw_and_resource_release 173.1, Driver.Dispatch 156.9
Longest waits
- Driver.WorkerWait (queue worker 0x51) 343.3 ms at 59116 ms, present 1579
- Driver.WorkerWait (queue worker 0x48) 343.2 ms at 59126 ms, present 1579
- Driver.WorkerWait (queue worker 0x48) 339.2 ms at 58783 ms, present 1578
- Driver.WorkerWait (queue worker 0x51) 337.8 ms at 58774 ms, present 1578
- Driver.WorkerWait (queue worker 0x51) 336.9 ms at 58432 ms, present 1577
- Driver.WorkerWait (queue worker 0x51) 335.4 ms at 31564 ms, present 1494
- Driver.WorkerWait (queue worker 0x48) 334.7 ms at 58445 ms, present 1577
- Driver.WorkerWait (queue worker 0x48) 334.6 ms at 31574 ms, present 1494
- Driver.WorkerWait (queue worker 0x51) 333.0 ms at 40962 ms, present 1523
- Driver.WorkerWait (queue worker 0x48) 333.0 ms at 37715 ms, present 1513
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
- batch 16490: 9.7 ms at 49486 ms, present 1549: GPU no ranges; recorded by Driver.Dispatch.lookup_cache (queue worker 0x20) 11.0, Driver.Packet (queue worker 0x20) 2.2, Driver.Packet.dispatch (queue worker 0x20) 2.2, Driver.Dispatch (queue worker 0x20) 1.6
- batch 14440: 9.7 ms at 43357 ms, present 1530: GPU no ranges; recorded by Driver.Packet (queue worker 0x20) 2.1, Driver.Packet.dispatch (queue worker 0x20) 2.1, Driver.Dispatch (queue worker 0x20) 1.2, Vulkan.Dispatch (queue worker 0x20) 0.3
- batch 11534: 9.6 ms at 34579 ms, present 1503: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.1, Graphics.Draw.draw_and_resource_release (draw committer) 0.9, GpuMutex.wait.label (draw committer) 0.3, GpuMutex.wait.draw (draw committer) 0.2
- batch 19726: 9.3 ms at 59233 ms, present 1579: GPU no ranges; recorded by no CPU slices
- batch 2548: 9.0 ms at 7488 ms, present 1419: GPU no ranges; recorded by GpuMutex.wait.draw (draw committer) 0.7, Graphics.Draw (draw committer) 0.2, Graphics.Draw.draw_and_resource_release (draw committer) 0.2, GpuMutex.wait.flush (draw committer) 0.1
Written by Claude Code, verified by me.
|
NVIDIA Linux run with the Khronos validation layer of the current head Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
The pattern is the one from Tested.
The check ( No AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The review covered the changed implementation, its new execution test, and the documentation at head 8630fa906d675132ad2741f997c275edb36434f9; performance results and focused test runs are author-reported, and I did not run checks.
What I ran
No commands or tests were run. I read review/description.md, review/commits.md, review/manifest.json, and review/diff.patch, plus the full text of all four changed files through the pinned reader. The supplied reader was repo_read.py.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Four changed files read |
| Tests | not run | Results in description are author-reported |
| Performance evidence | not verified | Reported captures predate this exact implementation |
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp:393caches the environment-variable decision in a function-localstatic. ChangingAPS5_NO_BDA_RANGE_CACHEafter the first shader compilation will not change behavior for later compilations in that process. This may be fine if runtime switches are intentionally process-start settings, but the new toggle's expected lifetime is not specified in the change description.- The description says the performance tables and replay were measured with earlier code or alongside another change, and says a same-machine
maincomparison and exact-commit captures remain outstanding. Those results therefore do not establish the performance or memory impact of this exact head.
Not verified
I did not execute tests or reproduce performance captures. The test and source files were read; no changed files were excluded according to manifest.json. review/files.json was not available through the reader, so its exclusion list could not be independently checked. I did not verify behavior on physical console hardware or other host platforms.
To get this to a good state
Nothing is required. Optional: clarify whether the environment switch is process-start-only, and provide exact-head performance captures and a matched main comparison when available.
What
Draft: not ready for review yet. The change and the results below are real; the open items are listed at the end of this section.
Address-based (BDA) span reads walk the BDA table (
probe_bda_pointer) on every access. A program that runs as one wave pays every walk on its critical path, because nothing else is resident to hide the latency. In Ghost of Yotei's opening cinematic, the single-wave program 0x807b90a100 spends 94 % of its time in a triangle loop of six runtime-format buffer loads. Shader-clock instrumentation of that loop shows the table walk is about a third of each load (~2,950 of ~8,400 cycles); the data load itself is ~220 cycles.Each invocation now keeps the last four ranges its span reads found, as
(begin, bound, device base)entries.bda_anchor_range, with the same checks as the probe) and replaces the oldest entry with the range it finds.The entries are separate variables indexed only by constants. A first version indexed 16 slots by pc; its dynamically indexed array added 512 bytes of local memory per thread on NVIDIA, and that showed up as 270 MB more VRAM in the frame replay. The four-entry version adds 176 bytes and about 40 MB.
APS5_NO_BDA_RANGE_CACHE=1walks the table for every read, as before.Still to do before this is ready:
main-vs-PR summary from the same machine and scene. Ghost of Yotei only runs on the Celegans12yotei/bestfork, so the in-game numbers below come from that fork, not frommain. I still need a title or homebrew that runs onmainand exercises address-based span reads.BdaSpanReadResultTypeand the stop handling) for a different purpose, masking writes after faults. Whichever lands second needs a rebase.Overlap: the pr-overlap bot could not compare 54 open PRs that conflict with
main, so I reviewed them by hand.docs/dev/ENVIRONMENT.md(rows in the variable table).SpirvEmitterState.hpp, where this PR adds one field (bdaRangeCache). Their additions there are unrelated: fault masking (test(shader): skip faulting wave test on narrow subgroups #6751, fix(shader): mask writes after barrier-safe BDA faults #7392), device image tables and samplers (feat(agc): look up table images at run time through a device image table on the GPU heap (APS5_GPU_PATH) #7642, feat(agc): serve lane-keyed, pointer and runtime image-table columns #10193, feat(agc): resolve table samplers through device image keys #13928, feat(agc): resolve runtime sampler addresses through device image keys #13929), the mesh fallback (feat(agc): run mesh-path draws through a compute pass on devices without mesh shaders #9356, feat(agc): emulate mesh-fallback barycentrics through tessellation #9387), spanned-wave subgroups (perf(shader): let spanned waves run at any host subgroup size where it can be narrower than 32 #8004), stencil export (feat(agc): export stencil operation values through an attachment #10351), MoltenVK image atomics (fix(shader): order an image store before a later image atomic on MoltenVK #10652), f16/f64 modes (perf(shader): keep native f16 conversion NaN results when a startup probe matches RDNA #11351, fix(shader): declare f16 and f64 DenormPreserve together when their modes are shared #11483), and the ARM64 AOT consolidation (feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021).SpirvBdaRead.cpp(see above).Tested
Windows 11 Pro 10.0.26200, RTX 3080 Ti, NVIDIA 616.92.
New
agc_driver_bda_range_cachetest. Eight loads over five guest blocks: A, A again (a hit), then B, C and D (misses), E (evicts A), A (evicts B) and B. It runs on wave32, wave64 and split wave64, with and withoutglc, and also passes withAPS5_NO_BDA_RANGE_CACHE=1.Focused tests on this branch rebased onto
main6fe120d, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(ctest -R "bda_range_cache|bda_span_reads|bda_anchor_reads|bda_device|global_loads|gpu_buffer_format|buffer_format|descriptor_web_faults|buffer_load_store" -V):main: 15/15 passed.VUID-line or a missing-layer message.spirv-val --target-env vulkan1.3passes for the five largest captured Ghost of Yotei programs (on the earlier base).Frame replay (
agc_frame_replay, exact mode) of a captured cinematic frame, alternating runs with the cache off and on. These runs used the first, pc-indexed version; the four-entry version gives 0x807b90a100 122.5 ms in the same replay. Output buffers are byte-identical in every run.Shader-clock cycles of 0x807b90a100 and 0x807b925400 drop 34 % with the first version. With four entries, 1 of 42,846 reads walks the table.
In game, Ghost of Yotei (PPSA26344), on the
yotei/bestfork's runtime (see above). The change build also carried a spanned-ballot change that measured −1 to −6 % on these programs. Warm shader cache,tools/trace_digest.pyofaps5-summary.jsonl:Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code