Skip to content

GPU: make a structured buffer view off its host copy's elements a raw view - #206

Closed
AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:structured-view-raw-fallback
Closed

AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:structured-view-raw-fallback

Conversation

@AnoHunted

Copy link
Copy Markdown
Contributor

What

buffer_srv and buffer_uav (crates/victory-gpu/src/descriptor/host.rs) now make a structured buffer view
whose start in its host copy is not on an element as the raw view of the same bytes (R32_TYPELESS, raw flag,
first element and count in dwords), when that start is 16-byte aligned. Views on an element are made as before.
Everything else (typed views, strides that are not a multiple of 4, starts that are not 16-byte aligned) is still
refused with the same log line. The math is in a small raw_window helper, with a unit test and a host GPU test.

Why

A title buffer view is made on the host copy of the innermost title buffer that holds it, with its first element
moved by its offset in that copy (FirstElement += offset / stride). A view of memory inside a bigger title buffer
can start anywhere in it. The log in #16 already has buffer view not on an element of its host copy with
element=32 on the way to the menus: a 32-byte-stride view 16 bytes past an element. D3D12 puts structured
element i at byte i * stride of the resource, so that start cannot be written as a structured view of the copy.
The slot stayed null: shaders read zeros through it and their writes were lost.

Why a raw view and not a host copy of its own starting at the view: such a copy would be a second buffer for the
same memory. Writes through it would not reach readers of the shared copy in the same submission (and the other
way round), and the refresh and copy-back steps only know the shared copy (shadow::find). The raw view is a
view of the shared copy, so readable's refresh and gpu_writes/copy-back keep working unchanged. They use
buffer_range, which gives the same bytes. What a UAV writes lands where every other view of that memory reads,
and goes back to title memory after the submission.

How shaders see it: the emitter declares heap buffer views raw for dword loads and stores, atomics and
typed-format loads without an index, and structured only when the shader indexes them
(victory-shader/src/emit/mod.rs, "Buffer views in the heap"). A raw reader is served exactly. A shader that
indexes the view declares it structured (stride 32) over a raw descriptor. D3D12 leaves that undefined, so it is
marked as a shortcut. On the RTX 5080 and on WARP such reads and writes got the right bytes (probe below, not
part of the PR). AMD is not known.

The 16-byte rule is D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT. It is not optional. In a probe run, a raw SRV or UAV at
byte 4 or 8 of a buffer removed the device (DXGI_ERROR_INVALID_CALL) on both the NVIDIA GPU and WARP. At byte 16
the device stayed up.

#123 is the same rule for the title's own raw views: it refuses one that lands off 16 bytes in its copy. This PR
covers structured views that land off an element. The two touch neighbouring lines in buffer_srv and
buffer_uav and fit together: the views this one makes are always 16-byte aligned.

Tested

Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1; also
WARP (VICTORY_D3D12_WARP=1, diagnostics build).

New tests in descriptor/host.rs:

  • structured_views_off_an_element_are_raw_views_of_the_same_bytes: the raw view covers exactly the structured
    view's bytes, and the cases it must refuse (not 16-byte aligned, stride 6, stride 0, more than u32::MAX
    dwords).
  • structured_views_off_an_element_read_and_write_their_bytes (host GPU): a 1 KiB title buffer of numbered
    dwords. A structured SRV (stride 32, 4 elements) starts at byte 16 and a structured UAV at byte 272, both made
    by buffer_srv/buffer_uav. A cs_5_1 shader (system compiler) copies the SRV into a buffer of ours and
    writes marks through the UAV. It runs through HostList and Host::execute, so the refresh and copy-back steps
    are the real ones. Checks: what it read is title bytes 16..144; after copy-back, title bytes 272..400 hold the
    marks; no other byte changed.
    • The same test on main's code (test only, without the fix): fails. The read gives 32 zeros (the null view), on
      the RTX 5080 and on WARP.
    • Branch: passes on the RTX 5080 and on WARP.

Whole runs, main (d2a4bae) and branch side by side in one job:

  • cargo test --workspace (RTX 5080): main 264 passed, 0 failed, 4 ignored; branch 266 passed, 0 failed,
    4 ignored (the two new tests).
  • cargo test -p victory-gpu --features diagnostics on WARP: main 45 passed, 0 failed, 1 ignored; branch 47
    passed, 0 failed, 1 ignored.
  • cargo clippy -p victory-gpu --all-targets: one warning on both, the same one, in host.rs (not touched
    here).
  • cargo xtask policy: 151 files ok on both.
  • rustfmt --check on descriptor/host.rs: none of the reported spots are lines this change adds (the file
    was not rustfmt-clean before).

Probe (not part of the PR):

  • StructuredBuffer<E>/RWStructuredBuffer<E> with a 32-byte E, over the raw fallback views: right bytes read
    and written, RTX 5080 and WARP.
  • Raw SRV and UAV at byte 4 or 8 removed the device; at byte 16 they did not.
  • The test machine had no D3D12 debug layer installed (0x887A002D), so there was no debug-layer or GPU-based validation check.

Not tested

  • The title. Whether this view's readers index it, and what the menus look like with it filled.
  • AMD and Intel GPUs, especially shaders that index the view (structured declaration over a raw view).
  • SM 6.6 heap-indexed DXIL as the translator emits it (the probe used SM 5.1 descriptor tables).
  • The D3D12 debug layer and GPU-based validation (not installed on the test machine).

AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.

… view

A title buffer view becomes a view of its host copy with the first element
moved by the view's offset in the copy (offset / stride). A structured view
whose start in the copy is not a multiple of its stride (a 32-byte stride,
16 bytes past an element: logged as "buffer view not on an element of its
host copy" on the way to the menus) cannot be expressed there, so its slot
was left null: shaders read zeros through it and their writes were lost.

Such a view is now made as the raw view of the same bytes (R32_TYPELESS,
raw flag, first element and count in dwords) when its start is 16-byte
aligned; the host removes the device for raw views that are not, so other
starts stay refused. It is a view of the same shared host copy, so what
shaders write through it lands where the other views of that memory read,
and is copied back to title memory as before. Translated shaders read heap
buffer views raw unless they index them; one that indexes it declares it
structured, which D3D12 leaves undefined over a raw view (an RTX 5080 and
WARP read and write the right bytes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
…t copy's elements a raw view) into the integration

The SRV's coherency range (PR Marvisak#185) is computed before the view is
rewritten; the 16-byte raw-start check stays on the in-element path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
AntoninMichelq pushed a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 24, 2026
Shader PRs 136, 163, 164, 160, 176, 193, 177, 180, 138, 139, 145, 154,
156, 157, 162, 166, 168, 169, 179, 200, 226 and 25.

Marvisak#193's runtime stride table is combined with the runtime PRs:
- descriptor/host.rs keeps Marvisak#135's retire-on-keep, dynamic pool and
  sampler cap, Marvisak#185's Slots (made + directly indexed SRVs) and Marvisak#206's
  raw fallback for structured views off their host copy's elements. The
  stride table still holds the title view's element stride: a raw view
  made by Marvisak#206 starts at the same byte (raw_window never rounds), so the
  shader's index * stride + offset reads the same bytes.
- Slots Marvisak#193 did not know about now write their stride: a directly
  indexed SRV (Marvisak#185) when its record changes, and make_null_kind's
  typed null views (0).
- draw.rs keeps bind() returning whether it bound (with the stride table
  root SRV set inside it) and the bounded indirect argument copy.
- pipeline/host.rs keeps the per-stage subobject stream; the stride
  table root parameter merges cleanly.
- depth_bounds_test's HostShader gains stride_table: false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
… elements a raw view

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

Copy link
Copy Markdown
Contributor

Thanks @AnoHunted for the structured-view fix. I tested the open PR at head 05981dd53b338ef0dabf30d4b728ccb41b0772d9 with:

cargo test --locked -p victory-gpu --lib structured_views_off_an_element -- --test-threads=1

Result: 2 passed, 0 failed. structured_views_off_an_element_are_raw_views_of_the_same_bytes checks that a view derived from an element exposes the expected raw byte span, and structured_views_off_an_element_read_and_write_their_bytes checks reads and writes through that view. This exercises the CPU-side descriptor/span logic; it does not execute a GPU shader. The tests are in descriptor/host.rs.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…ent become raw views)

AnoHunted's Marvisak#206: a structured buffer view whose start in its host copy
is not on an element, which stayed null, is made as the raw view of the
same bytes where those start on 16 bytes.

Conflict resolution, crates/victory-gpu/src/descriptor/host.rs:
- buffer_srv and buffer_uav: Marvisak#206's three-way choice (on an element,
  raw view of the same bytes, refused) is kept, and Marvisak#123's refusal of a
  raw view that does not start on 16 bytes of the host copy follows it,
  as it followed the old test. Marvisak#206 moved `FirstElement += offset /
  element` into its first arm and `CounterOffsetInBytes = 0` before the
  choice; the copies of those lines on this tree's side are dropped.
- tests: this tree's and Marvisak#206's are all kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
Seven more upstream PRs are in (Marvisak#493, Marvisak#483, Marvisak#206, Marvisak#469, Marvisak#459, Marvisak#454,
Marvisak#579) and the wave64 stack is at Marvisak#439's head 965ce30. Records how each
was combined with what the tree had, that a capped view heap keeps
2^18 dynamic slots and why, Marvisak#189 and Marvisak#578 as left out, and a new
section with testers' reports from the title: the set without the
world-entry hang on three NVIDIA cards and how this tree differs from
it, VICTORY_SKIP_WAVE64 as the switch to try, and Marvisak#136 bisected as
making every frame black.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@SantannaCarlos

Copy link
Copy Markdown
Contributor

Tested on an RTX 4070 (Windows 11, driver 621.01), diag build of d2a4bae + #136 #173 #176 #164 #180 #179 #177 #138 #116 #145 #135 #100 and two local fixes. With this PR both runs stopped early: 3 s into the world, and once during loading, in a pre-skinning simulation compute pass (50 groups) whose structured SRV (336-byte stride) starts off an element of its host copy. Before this PR that view was null; with it, it is a raw view. Without this PR the same stack ran 116 s and 131 s and stopped elsewhere.

My reading, not verified in that pass's DXIL: the translator declares a heap buffer view structured, with the entry's stride, when the shader reads it with an index, so a raw host view may not match that declaration. The raw window may need to depend on how the shader declares the slot. Two runs; details in #71 (comment) (section 6).

@AnoHunted

Copy link
Copy Markdown
Contributor Author

@SantannaCarlos thank you, that's exactly the case this needed. You're right. When the shader indexes the view, the translator declares the slot structured with the entry's stride. The raw fallback then puts a raw descriptor under a structured declaration, which D3D12 leaves undefined. My synthetic probe passed on NVIDIA and WARP, but your 336-byte-stride compute pass shows it isn't safe in the title: it is worse than the null view main leaves there.

I'm turning this into a draft so it isn't merged as is. A correct version needs one of two things:

I'll come back to it on top of that work rather than keep this fallback.

@AnoHunted
AnoHunted marked this pull request as draft November 24, 2026 10:21
@jamesn-xt

Copy link
Copy Markdown
Contributor

Verified head 05981dd in an integrated Windows 11 / RTX 4080 build (NVIDIA 617.42, Ryzen 5 5600, 32 GiB RAM, Rust 1.98.1).

The previous hardware run logged a structured-buffer view offset off its 32-byte element. With this PR in the stack, that warning no longer appeared in the bounded hardware run. Both added raw-window/read-write tests passed on the RTX 4080; diagnostics GPU suite: 66 passed, 1 ignored. All-target/all-feature GPU Clippy, diagnostics build and asset policy passed.

Stack also contains #211, #89, #492, #985 and #1146 on main ffe310e: https://github.com/jamesn-xt/VIctory/tree/test/rtx4080-target-formats (abe05a3). Character loading artwork rendered at 30 fps; mesh/pixel pipelines began binding later, but a 2 GiB free-commit guard stopped the run before a visible world was confirmed. This does not prove this PR alone fixes title rendering, and I have not verified structured declarations over the raw view on other GPU vendors.

No game captures, retail files or raw logs attached.

@ThomasHFWright

Copy link
Copy Markdown

Tested exact head 05981dd53b338ef0dabf30d4b728ccb41b0772d9 on Linux / RTX 5090. This restores previously null buffer inputs in the title path on this setup; the default-loop-limit run still stalls.

Integration: Slaktarn700 proton-fixes 993dff8, #852 handle-cache fix ae7e0be, #454 watchdog diagnostic d2c93fa (local base 436b3dbce181f0e6c940770596fc2a500ed39050), then this PR's exact file delta merged against its parent. Local binding/timestamp probes retained; no other semantic patch added. CachyOS 7.3.6, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 3.2.0 30b0eb9bc12dc9f. Wine with these DLLs, not a Steam Proton runtime test.

Observed bindings: before this PR, compute 72f552f4553fb5f9 had null raw SRVs at inputs expecting structured buffers of stride 176 and, on some dispatches, 336. With the PR, those inputs receive non-null raw SRVs over the shared buffer. No descriptor-record changes were detected between command recording, pre/post heap refresh and timeout in the examined submissions. This samples descriptor records, not all GPU memory contents or transient races.

Tests:

  • Diagnostics GPU suite with Microsoft's native d3dcompiler_47: 58 passed, 0 failed, 1 ignored, including both added tests. Probes enabled.
  • With Wine's built-in compiler: 57 passed, 1 failed, 1 ignored. The added GPU test fails at CreateRootSignature (0x80004005), before dispatch; the native compiler resolves that harness limitation.
  • Full Windows workspace: 347 passed, 2 unchanged Wine harness failures, 7 ignored across 14 executables. Failures are the nested Linux cargo launch and git-based policy invocation from Wine. The extra ignored item is a local opt-in diagnostic test, exercised separately below.
  • All-target/all-feature Clippy with warnings denied and native asset policy pass.
  • Separate synthetic PC-DXC/SM6.6 heap-indexing test on the actual RTX 5090: 20 cases spanning strides 12/16/24/176/336, raw and structured SRVs, null raw SRVs, and raw views starting at byte 16. Both raw and structured handles read the expected bytes in these cases; null views return zero. This does not establish portable D3D12 behavior or validate arbitrary translated shaders/stores.

Runtime: the default-limit run ends after 108.1 s, exit 5. Our bounded fence probe reports submission 5209/completed 5208. The last resolved pre-command marker is 62, preceding a 34x1x1 dispatch of the same 72f552f4553fb5f9; the next marker is absent. Kernel reports Xid 109 / CTX SWITCH TIMEOUT, where the preceding controls reported Xid 13 / MMU Fault. All 983 captured SPIR-V modules validate. Thus restored views are confirmed, but this run does not establish that the GPU stall is fixed. Earlier producer/dataflow errors remain possible; marker instrumentation can alter scheduling.

Prior isolation and shader-exclusion controls: #71 (comment) .

A second controlled run used the same application binary, only adding VICTORY_SHADER_LOOP_LIMIT=32 (confirmed active; the cache keys on this setting). It also failed: 103.1 s, exit 5, submission 4764/completed 4763. Last resolved marker 53 precedes the same shader, now 421x1x1; kernel Xid 13 / MMU Fault. No descriptor-record change detected; all 988 captured SPIR-V modules validate. The global loop cap does not avoid the fault in this test and can truncate shader work; it is not a correctness fix.

All runs were offline and app-muted. No game files, shader code, dumps or captures attached. No controllable visible gameplay confirmed. AI-assisted testing with Codex on the user's hardware.

fornorharry pushed a commit to NitricAcidDev/VIctory-Omega-Fork that referenced this pull request Nov 24, 2026
@Marvisak Marvisak closed this Nov 24, 2026
arnoudstorm pushed a commit to arnoudstorm/VIctory that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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