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

Merged
Quat3rnion merged 1 commit from upstream-pr/368 into main 2026-11-25 00:19:57 +00:00
Quat3rnion commented 2026-11-24 02:40:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T02:40:33Z.


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 #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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573393781 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/368). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T02:40:33Z. --- ## 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 #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 - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
jeremygold02 commented 2026-11-24 06:55:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:03:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121664155 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/368#issuecomment-7121664155). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:03:17Z. --- 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.
mercuryVM commented 2026-11-24 09:05:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:13:15Z.

Review: COMMENTED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035736618 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/368#pullrequestreview-6035736618). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:13:15Z. **Review:** COMMENTED --- 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).
upstream-sync closed this pull request 2026-11-25 01:03:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!368
No description provided.