Skip to content

Shaders: structured access through a root SRV or UAV uses its raw view (stacked on #294) - #709

Closed
itsRevela wants to merge 4 commits into
Marvisak:mainfrom
itsRevela:shaders/structured-root-views
Closed

itsRevela wants to merge 4 commits into
Marvisak:mainfrom
itsRevela:shaders/structured-root-views

Conversation

@itsRevela

Copy link
Copy Markdown
Contributor

Depends on: #294 (root UAVs). This branch is on top of it; only the last two commits are new.

What

An indexed (structured) buffer_load_*, buffer_store_* or buffer_atomic_* through a descriptor built around a root SRV or UAV now goes through the root view's raw handle, at byte index * stride + offset. The stride is the one the title declares for that root parameter (UsedResource::stride).

A root descriptor is a bare address on the host, with no stride of its own. These accesses used to ask handle for a structured view (12 | u), which root descriptors don't have, so they stopped with a typed root view. That message was misleading for them, since none is a typed (format) access.

A new Lower::structured holds the choice for all three access kinds. Structured buffers in tables and heaps are unchanged, as is their stride check.

Why

With the title, in the opening cutscene, compute programs that write through root UAVs declared with strides of 1 to 64 bytes stopped at a typed root view once #294 was in. Each dropped its dispatches.

I measured in a local build with #302, #489, #294 and some local work on addresses passed as root constants (#614), which those programs need first:

  • with this change, 5 of them translate;
  • the run logs no a typed root view failures left;
  • the host accepted all 5 pipelines. The run's other host pipeline refused lines (129 without this change) don't involve them.

Tested

Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088), Rust 1.98.1, on #294's head.

  • New GPU test. emit::valu_tests::structured_access_through_a_root_uav_reaches_index_times_stride declares a root UAV with a stride of 8. It does an indexed store (element 2, offset 4), an indexed atomic add (element 2, offset 0) and an indexed load, then checks the buffer the root UAV binds on the hardware GPU and on WARP. With GPU & shader: full Root SRV extent refresh, safe fallback VAs, and Root UAVs #294's lower.rs, it fails at emit with a typed root view.
  • Crate checks:
    • cargo test -p victory-shader: 72 passed.
    • cargo clippy -p victory-shader --tests: nothing in the changed files.
    • cargo fmt -p victory-shader --check: clean.
    • cargo xtask policy: ok.

AI-assisted (Claude Code). The title runs used my own copy; no game data is in this PR.

🤖 Generated with Claude Code

wbkepler and others added 4 commits November 24, 2026 03:03
…ot UAVs

- Refresh the full remaining Shadow buffer extent for Root SRVs and Root UAVs instead of truncating at 1 MiB (keeping Root CBVs at the 64 KiB D3D12 limit).

- Guard shadow::find/loose against low (<0x10000) and uncommitted addresses, and bind permanently-alive 4 MiB zeroed/sink fallback GPU VAs instead of skipping Set*Root*View when a root view is unset, null, or unmapped.

- Support Root UAVs (u<slot>, space1 RWByteAddressBuffer) end-to-end across victory-shader (descriptor handle, global_store_dword*, s_load_dword* on root descriptors, PSV0/dx.resources metadata, SFI0/ShaderFlags UAVsAtEveryStage=1<<16), shader_cache (VSH2), pipeline::host (deduplicating shared (kind, slot) root views across stages), and draw (binding, gpu_writes write-back, and post-draw/dispatch UAV barriers).

- Add unit, dxil.dll validation, WARP, and host GPU tests covering >1 MiB Root SRV dirty-page refresh, null/unmapped fallback VAs, cross-stage root view deduplication, and Root UAV execution/write-back.
Root SRVs and UAVs took the whole rest of their buffer's host copy, so a
root UAV near the start of a very large backing copy kept and compared
that whole range on every submission. A root view has no size and the
translated shader does not report its range yet, so bound them: root
SRVs refresh at most 4 MiB, root UAVs refresh, snapshot and copy back at
most 2 MiB, constant buffers keep the 64 KiB D3D12 maximum. A cut is
logged once per view kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A root descriptor is a bare address on the host, with no stride of its own: an indexed (structured) load, store or atomic through one reads or writes its raw view at byte index * stride + offset. These stopped with "a typed root view".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech 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.

Verified on Windows 11 MSVC (Rust 1.98.1). \structured_access_through_a_root_uav_reaches_index_times_stride\ passes on both hardware and WARP.

  • Structured accesses (loads, stores, atomics) across root UAVs/SRVs now cleanly compute the effective byte address as \index * stride + offset\ using raw buffer handles (11 | u, 0), properly reflecting that root descriptors are bare host virtual addresses rather than typed descriptors.
  • Resolves \� typed root view\ pipeline creation failures.
  • Fully compliant with asset policy (\cargo xtask policy\ clean).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Heads-up: no longer merges cleanly with current main (7374bfb) — conflict in victory-shader/src/emit/valu_tests.rs. Needs a rebase.

Head's shader crate is green on macOS 26 arm64 / rustc 1.98.1 (cargo test -p victory-shader: 56 passed / 0 failed against its own base; its new coverage is Windows-gated). The structured-access-through-root-SRV/UAV change is mostly GPU-side, so the Windows shader+GPU run is the real check.

@raffclar

Copy link
Copy Markdown
Contributor

#294 has some issues but this branch on top is okay.

@MartinIndra02

Copy link
Copy Markdown

Independent Windows + NVIDIA Ampere verification for e50ed36:

  • Setup: Windows 11 Pro 26200, NVIDIA GeForce RTX 3080 (10 GB, driver 621.24), Ryzen 7 5800X3D, Rust 1.98.1 (x86_64-pc-windows-msvc).
  • cargo test -p victory-shader --lib -- --test-threads=1: 72 passed, 0 failed (including structured_access_through_a_root_uav_reaches_index_times_stride on both hardware D3D12 and WARP).

No game data used. AI-assisted; tests run on my machine.

@erLCoder

Copy link
Copy Markdown

Independent structured root UAV GPU readback on GTX 1660 Ti, NVIDIA 581.42, Windows 10 22H2 build 19045.6466, Ryzen 5 3600, Rust 1.98.1 MSVC and Agility SDK 1.620.2. PR e50ed36 includes #294 dependency 0050ce5. Local SDK exports were added to the test executable; the fixture was restricted to hardware and asserts NVIDIA LUID 00000000:00017c52.

cargo test --offline --locked -p victory-shader --features host --lib structured_access_through_a_root_uav_reaches_index_times_stride -- --nocapture --test-threads=1 — 1 passed, 0 failed, 0 ignored, 71 filtered out. The synthetic dispatch wrote the expected words at index times stride and read them back successfully. The number of recovered title dispatches and effects on lighting remain untested.

Codex prepared the worktree, ran the test and drafted this report.

cybx added a commit to cybx/VIctory that referenced this pull request Nov 24, 2026
…or UAV uses its raw view

A root view is a bare address on the host, with no stride of its own, so
indexed (structured) loads, stores and atomics through one stopped with
"a typed root view". The BVH builder's programs at 0x38220, 0x39f00,
0x45c80 and 0x53fd0 stopped there.

Resolved against Marvisak#650's root view bounds as the msai-pr4 merge (66ac451)
does: buffer() turns an indexed access through a root view into a raw one
at byte index * stride + offset (the stride the title declares; none
stops with "a structured buffer of unknown stride"), and that access must
both lie in the bytes the host binds and come from an index whose byte
does not wrap past 4 GiB. structured() is left with heap views only.

The PR's GPU test runs with the root view's size in user data, as Marvisak#650
needs, over bound sizes that cut element 2 short and an index that wraps.
Machad3x pushed a commit to Machad3x/VIctory that referenced this pull request Nov 24, 2026
…UAV raw view)

Targets the 'emit: a typed root view' group: 41 -> 40 failing containers
in the offline translate (the typed-root-view program now translates);
prerequisite for Marvisak#710.

Conflicts with the V_DYNAMIC stride path in lower.rs: kept V_DYNAMIC (no
stride check) inside the PR's new structured() helper. The new-tree
bounds check from Marvisak#650 only covered the in-element offset, so for a root
view the index*stride is now folded into the byte offset before the
check, and the PR's GPU test passes the view size in root constant 0 as
Marvisak#650 requires. resource::track gained a parameter in Marvisak#294; one test call
updated for it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Machad3x pushed a commit to Machad3x/VIctory that referenced this pull request Nov 24, 2026
…sak#309 on top of Marvisak#233

Brings in three more open upstream PRs, each kept only because the offline
translate over the 48 dumped world shaders improved (41 -> 36 failures): Marvisak#709
structured access through a root SRV/UAV raw view (typed root view), Marvisak#585 select
on an untracked mask (3 programs), Marvisak#309 SGPR spill forwarding (opaque lane mask).

Conflicts with Marvisak#233's wave handling in emit/lower.rs: Marvisak#233's console-lane analysis
(swizzle/DPP in-half vs whole-wave reads) is kept, and its instruction iterator now
skips the spill moves Marvisak#309 marks dead so they cannot make a program look like it
reads lanes or masks; Marvisak#585's mask_cond is added next to Marvisak#233's lane-bit helper.
Two tests call emit() with the new Target argument (Target::ANY).

Workspace tests pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@qntic

qntic commented Nov 24, 2026

Copy link
Copy Markdown

integrated this with the newer main ffe310e. the structured buffer access paths conflict with the stride table changes, so i merged both into a shared implementation.

tested on rx 6600 xt. 359 workspace tests passed after the root uav integration, with both clippy configurations clean.

integration:
https://github.com/qntic/VIctory/tree/exp4/main-stack

giritsu pushed a commit to giritsu/VIctory that referenced this pull request Nov 24, 2026
…n root views (PR Marvisak#294 part 2 + PR Marvisak#709)

Cap Root SRV/UAV refresh and UAV copy-back ranges (0050ce5), and lower
indexed/structured loads, stores, and atomics through root SRVs/UAVs
via raw views at index * stride + offset (398ae78), preserving StrideTable.
giritsu pushed a commit to giritsu/VIctory that referenced this pull request Nov 24, 2026
Ortomanic added a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
A descriptor the code builds around a root UAV's address stopped
translation with "a root UAV or typed root view" (20 of the 52
XboxBvhBuilder.dll compute programs; nothing in shaders.rpf).

- Shaders: a root UAV is a raw RWByteAddressBuffer `u<slot>` in
  ROOT_CBV_SPACE (HostShader::root_uavs, dx.resources and PSV0 entries,
  UAVsAtEveryStage / 64-UAV feature bits). Structured access through a
  root SRV or UAV uses its raw view at byte index * stride + offset. Reads,
  stores and atomics through a root view are checked against the view's
  length from user data (the existing root-bounds scheme): a store or
  atomic outside is dropped, so a garbage offset no longer writes past
  the host copy (the fork saw DEVICE_HUNG from exactly that).
- GPU: root UAV root parameters (D3D12_ROOT_PARAMETER_TYPE_UAV), bound with
  Set*RootUnorderedAccessView to the shadow copy; the range (to the copy's
  end, at most 4 MiB) is refreshed, copied back after the submission
  (gpu_writes) and passed to the shader as the view's length. Shader cache
  format VSH2 (adds the root UAV list).

Shader corpus (shader-lab, host wave32): no outcome or DXIL change in the
phase-by-phase run; emit::translate now emits 20 BVH-builder programs, all
pass dxv and dxil-spirv --validate. 32 BVH programs still fail on other
constructs.

Ported from LooperSalty/victory bffaefd by wrothgaril (upstream Marvisak#294:
root UAV handle, metadata and feature bits), 398ae78 by itsRevela
(upstream Marvisak#709: structured access through a root view's raw view) and
ed28424 (root UAVs bounded rather than raw), adapted to our root-view
bounds (33e446a) instead of one-view tables.
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…sak#709 on Marvisak#1077's root UAVs

Marvisak#709's test used Marvisak#294's Root::Uav; this host binds a zeroed root UAV
(SetComputeRootUnorderedAccessView) and reads it back after the views' UAVs.
Also the fork's track() signature, and stride-0 structured accesses keep the
fork's runtime stride-table view (Marvisak#193/Marvisak#704) after Marvisak#709's structured().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Stacked on #294; main already indexes a descriptor built around a root view by its own stride into the raw root view (emit/lower.rs, 'A descriptor built around a root view has the stride...').

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
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.

9 participants