Skip to content

Shaders: lower buffer cache invalidations as no-ops - #368

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
Quat3rnion:victory-shader-coverage
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
Quat3rnion:victory-shader-coverage

Conversation

@Quat3rnion

Copy link
Copy Markdown
Contributor

What

buffer_gl0_inv and buffer_gl1_inv were the only buffer cache
instructions the translator refused: resource::track demanded a resource
descriptor 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 _inv buffer instructions and lowers
the pair as no-ops — the same treatment the scalar s_gl1_inv and
s_dcache_inv already get. A synthetic full-pipeline test covers both
opcodes.

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

  • Linux: cargo test --workspace with 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.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here.
  • cargo xtask policy passes (150 files ok). No game files or data from them were added.
  • Not tested: a real title. Shader binaries live in a 393 MB shaders.rpf with no reader in the repo, so the test uses synthetic instruction words.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.

@Quat3rnion
Quat3rnion force-pushed the victory-shader-coverage branch from 5fcd645 to d3c40da Compare November 24, 2026 02:44
muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremygold02

Copy link
Copy Markdown
Contributor

Thanks @Quat3rnion for this change. I tested head d3c40da1c8371648774e11963cd880539e3d8085 with:

cargo test --locked -p victory-shader --lib buffer_cache_invalidations_lower_as_no_ops -- --test-threads=1

Result: 1 passed, 0 failed (61 filtered out). The synthetic lowering test decodes and lowers both buffer_gl0_inv and buffer_gl1_inv through the shader pipeline. This validates translator acceptance and no-op lowering; it does not exercise behavior in a real title or GPU dispatch.

@ghost ghost mentioned this pull request Nov 24, 2026
@Quat3rnion
Quat3rnion force-pushed the victory-shader-coverage branch from d3c40da to 42c86c3 Compare November 24, 2026 07:25

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 globallycoherent UAVs, or after a device-scope memory barrier (DeviceMemoryBarrier, i.e. dx.op.barrier with UAV_FENCE_GLOBAL).
  • Console code usually emits buffer_gl0_inv/buffer_gl1_inv exactly 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.
@Quat3rnion
Quat3rnion force-pushed the victory-shader-coverage branch from 42c86c3 to f47ebd8 Compare November 24, 2026 14:16
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
KainanP pushed a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…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>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
nazmi added a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
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.
@Marvisak
Marvisak merged commit 9ce9976 into Marvisak:main Nov 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants