Repository navigation
Shaders: lower buffer cache invalidations as no-ops - #368
Conversation
5fcd645 to
d3c40da
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @Quat3rnion for this change. I tested head Result: 1 passed, 0 failed (61 filtered out). The synthetic lowering test decodes and lowers both |
d3c40da to
42c86c3
Compare
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 42c86c3 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (248 passed, 0 failed; older base). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.
Skipping descriptor tracking for the _inv forms is right, since they read no data through the descriptor. But I'm not sure a plain no-op is safe:
- The new comment says "D3D12 already guarantees UAV coherence across wavefronts and dispatches". Across dispatches, yes. Within one dispatch, writes from one thread group are only guaranteed visible to another group for
globallycoherentUAVs, or after a device-scope memory barrier (DeviceMemoryBarrier, i.e.dx.op.barrierwithUAV_FENCE_GLOBAL). - Console code usually emits
buffer_gl0_inv/buffer_gl1_invexactly in cross-group producer/consumer patterns: after an atomic flag or before re-reading data another workgroup wrote, often in spin-waits (see #452). As a no-op, such a shader translates but can read stale data or spin forever on NVIDIA and AMD PC drivers. The PC L1 is not coherent either.
Suggested change: lower both to a device-scope UAV memory barrier (no group sync) instead of nothing. It is cheap, it gives the visibility guarantee these instructions request, and it still lets the shader translate. Alternatively, mark the UAVs the program touches globallycoherent. A comment-only review for now.
AI-assisted (Claude Code).
buffer_gl0_inv and buffer_gl1_inv name a buffer but read no descriptor, so resource tracking refused them before lowering. Skip descriptor tracking for _inv buffer instructions and lower the pair to nothing, as the existing scalar cache instructions already are. Add a synthetic full-pipeline test.
42c86c3 to
f47ebd8
Compare
…fied together Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053 Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402 (which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were merged by keeping both sides (additions next to each other); a PR was kept only if cargo clippy -p victory-shader --all-targets -- -D warnings still passed with it. No instruction name is handled in two places. Marvisak#98 is not in this version: an offline measurement on a retail dump showed it loses 31 programs that validate on Marvisak#1402. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (381 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
buffer_gl0_inv and buffer_gl1_inv are decoded but were never lowered, so any shader using one was dropped. They only scope an address range: D3D12 already guarantees UAV coherence across wavefronts and dispatches, ordering comes from the s_waitcnt/s_barrier the translator does lower, and our host-visible writeback is driven by command-stream GpuWrite ranges rather than shader cache hints. So the lowering is nothing, and the descriptor those instructions name does not need tracking either - both halves were needed: with only the lowering changed, descriptor tracking refused first. Verified: the test fails with 'a descriptor neither loaded nor built' when either half is reverted.
What
buffer_gl0_invandbuffer_gl1_invwere the only buffer cacheinstructions the translator refused:
resource::trackdemanded a resourcedescriptor even though the instructions carry no data operand, and lowering
had no arm for their names. The host has no console buffer cache to drop,
so this skips descriptor tracking for
_invbuffer instructions and lowersthe pair as no-ops — the same treatment the scalar
s_gl1_invands_dcache_invalready get. A synthetic full-pipeline test covers bothopcodes.
This was one of the refusals listed in PR #163's audit. That PR only prints
a notice when a listed opcode begins to lower, so the two lines become
stale rather than failing.
An AI tool wrote part of this change.
Tested
cargo test --workspacewith PR Build: Linux workspace, contributor setup and CI #112's Linux build fix applied locally (not part of this PR): 165 passed, 0 failed, 3 ignored. One new test runs both opcodes through decoding, resource tracking, structure and lowering.cargo check --target x86_64-pc-windows-gnu --workspace --testspasses. No Windows host here.cargo xtask policypasses (150 files ok). No game files or data from them were added.shaders.rpfwith no reader in the repo, so the test uses synthetic instruction words.Checklist
cargo xtask policypasses. No game files or data from them were added.