GPU: on NVIDIA, structured buffer views are made raw #2462
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2464"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-25T14:02:51Z.
On NVIDIA hosts, a title SRV that holds a structured buffer view is now made as a raw view of the same bytes.
The problem. Scalar and offset-only buffer reads are translated as raw reads:
rawBufferLoadthrough a raw handle, at a byte offset. When the slot holds the title's structured view, D3D12 leaves that read undefined, and NVIDIA took the byte offset as the element.WindNew:CS_CopyLatestWindFieldForRenderingWithSmoothreads its loop counts that way, fromt71(680-byte records, offsets 0 and 0xC4). With other records' data as counts, its loops ran until Windows reset the device. That happened every run, in the opening credits, on Windows 10 with an NVIDIA wave32 card. DRED named that dispatch.The change (
descriptor/host.rs,buffer_srv):VICTORY_RAW_STRUCTURED=0or=1overrides the vendor check.host::host_vendor()reads the device's adapter vendor once, by its LUID.Why not in the shaders. The first version of this PR read such slots both ways in the shader and picked the result by the slot's stride. That made the largest shaders too much for the NVIDIA driver's compiler. I checked with
translate --pipelines, filtered to theCS_RaytracingResolveand skinning mesh shaders:E_OUTOFMEMORY, and their draws dropped in game.This version leaves the shaders unchanged.
Checked on Windows 10 with an NVIDIA card, together with the Agility SDK (#2460), heap-limit (#2461) and UAV-format (#2462) PRs:
victory-gputests are unchanged againstmain.🤖 Generated with Claude Code. The change was written by Claude Code (Claude Opus 5.5) in my session; the commit carries a
Co-Authored-By: Claudeline.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:04:35Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:cargo test -p victory-shader emit::lower::tests: 21/21 passed on RTX 5090, 21/21 passed on WARP.cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:57:30Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — structured scalar loads.Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-25T14:46:07Z.
Heads-up before merging. In a game run, reading table SRVs both ways made the largest shaders (the materials'
CS_RaytracingResolvevariants and some deferred pixel shaders) too big for the NVIDIA driver's compiler: 145 pipelines were refused withE_OUTOFMEMORYand their draws dropped. I have a follow-up commit that looks the slot's stride up once per descriptor and block, and splits constant offsets at translation time. I'll push it oncetranslate --pipelinesconfirms the refusals are gone. Please hold this one until then.upstream-sync referenced this pull request2026-11-25 16:09:31 +00:00
[PR #2464] Pr/structured scalar loadsto [PR #2464] GPU: on NVIDIA, structured buffer views are made rawImported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-25T16:37:24Z.
Update: I've replaced this PR's approach, so the branch was force-pushed.
As I mentioned above, reading table SRVs both ways in the shader made the largest shaders too big for the NVIDIA driver's compiler. A filtered
translate --pipelinesrun on theCS_RaytracingResolveand skinning mesh shaders gave 569 pipelines refused withE_OUTOFMEMORY, against 0 without the shader change.The PR now fixes it on the host instead: on NVIDIA, a structured SRV is made as a raw view of the same bytes. Raw reads then read what they name, reads by element keep their structured handle (which NVIDIA reads right on a raw view), and the shaders are unchanged. Other vendors are unchanged too.
In a game run with it, the opening credits played through into the prologue with no device removal and no loop cap, and no pipelines were refused for lack of memory. Details are in the updated description. The earlier approvals were for the old version, so a fresh look would be appreciated.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:39:39Z.
Automated triage for the maintainers.
Needs work: needs the maintainer's decision, plus one small change. The head is unchanged (
b9dc4b0). steven-seagull27's synthetic readback on an RTX 5080 confirms both the fix and its limit. Through 16-byte-aligned SRV origins, wrong dwords drop from 950/960 to 0/960. Unaligned origins (12, 24, 36 bytes) still misread, becausebuffer_srvindescriptor/host.rskeeps those views structured.On your reply: #2885 is also open and makes structured SRVs and UAVs raw, with aligned copies for unaligned origins. The maintainer should pick one. If #2885 is chosen, this can close in its favour, as you offer. Until then, the earlier points stand:
host_vendor() == 0x10DE. That needs the maintainer's decision.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:52:47Z.
Mechanics check out: gated to
stride > 0so raw/typed views are untouched; guardsbyte % 16 == 0(raw-view alignment) andstride % 4 == 0(socount*stride/4is exact) before converting toR32_TYPELESS+ RAW with dword FirstElement — the fallback stays structured and logs once. Vendor detection viaEnumAdapterByLuidis the right way (not name matching).The hardware rationale is plausible — a byte-offset read through a structured SRV on NVIDIA indexing by element instead would return wrong records, which explains the wind-sim loop-count corruption. WARP already behaving correctly on raw views makes the raw path the safer default on the hosts that get it right.
Note: a structured view whose
first*strideisn't 16-aligned keeps the buggy NVIDIA behaviour — unavoidable without a copy, but worth remembering if a title hits it.Imported from Marvisak/VIctory. Originally posted by moe-miau on 2026-11-25T17:42:10Z.
Tested on an RTX 4070 SUPER (driver 32.0.16.1742, Windows 11 26300), title 1.0.2.1, Series X profile, diag build. 6-minute runs with scripted Enter presses. The stack is
main67e8ae1+ #1906 + #2098 + #2626 (RGBA8 stand-in for formats 86/115) + #2628 (capped view heap). This PR was merged on top; the only conflict was inhost.rs, where both sides add a function in the same place.host adapter vendor vendor=0x10deandstructured buffer views made raw on=true. One view stayed structured:not on 16 bytes byte=168744600 stride=100.buffer_uav, same 16-byte rule). That gave no visible difference in a 6-minute run, so I don't think this PR needs it.WaveSize(64)compute pipelines NVIDIA still refuses here (exposure and lighting), not this PR.AI-assisted (Claude Code); the runs were done on my machine.
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-25T18:07:31Z.
Thanks @kotekompotek for the review, and @moe-miau for the RTX 4070 SUPER run. A black screen at 0.1 fps turning into the world drawing at about 1 fps is a clearer result than mine.
main(13f91ca). The conflict was the one moe-miau saw: both sides add a function at the same place inhost.rs, and both are kept.byte=168744600 stride=100, not on 16 bytes) shows up in my runs too. As kotekompotek says, it keeps the old NVIDIA behaviour, and fixing it would need a copy. I've left it as a logged shortcut.Imported from Marvisak/VIctory. Originally posted by frenziedcoder on 2026-11-25T19:01:31Z.
RTX 5080 (Blackwell), driver 621.40: @moe-miau's stack with this PR draws the world here too, at about 1.5–2.5 fps, and ran the full 10 minutes with no device removal.
Setup: NVIDIA GeForce RTX 5080 16 GB (driver 621.40, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB RAM, Windows 11 Pro 26200. Title 1.0.2.1, Series X profile,
diagbuild with--features diagnostics,VICTORY_D3D12_DRED=1, scriptedEnterfrom 15 s to 280 s. Shader cache and pipeline library made beforehand withtranslate --cache --pipelineson each tree.Tree:
main13f91ca+ #1906 (a554b15) + #2098 (33a65d1) + #2626 (d1dc7ad) + #2628 (46d530a) + this PR (b9dc4b0), merged in that order. Two conflicts, both indescriptor/host.rsand neither in code: #2098's doc comment onwrite_addressagainst #1906's (merged), and #2628's two new tests at the same spot as #1906's (both kept).Runs, one each, 600 s limit:
main13f91ca0x887A0001at 9 sno host texture … format: 115(2560x1440 render target), as in #1952 / #1781main+ #26260x887A0006at 85 s0x80070057) as the world loads, then a hang in the list that was runningWith the stack:
0x80070057(WaveSize(64)on a 32-lane host; @moe-miau had 166), and 8 programs whose draws are dropped because they don't translate.translate --cache --pipelineson this card: 25,752 of 25,985 programs translate (233 refused); of the pack's 28,164 pipelines, 23,112 made and 3,624 already in the library in 770 s with--jobs 12, 397 refused by the host (the same count onmainand on the stack, close to the 394 in #2220).Not tested: more than one run per tree; #2176 / #189 or #2118 on top; Series S profile; release build.
AI use: Claude Code (Claude Opus 5.5) merged the trees, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:31:24Z.
I tested the default vendor gate on this PR and its direct parent with an overlapping-view GPU write/readback on an RTX 5080 (driver 621.40) and built-in WARP. On the RTX, this change fixed every read through the two 16-byte-aligned SRV origins. The three unaligned origins reproduced the parent’s results.
13f91cab9dc4b0Five 12-byte-stride structured UAVs at different origins write into one allocation in separate trials. For each trial five overlapping SRVs read three fields across 32 lanes. With the writer at byte 0 and reader at byte 12, lane 1 of the first field read
0xa170000cinstead of0xa1700006. The unaligned reads diverged even on fields the writer left untouched. WARP reported the raw-view gate off and the RTX reported it on.The test-only commit on this exact PR head is available if you want to compare other adapters. With
VICTORY_RAW_STRUCTUREDunset, run this twice in separate processes, settingVICTORY_D3D12_WARPto0and1respectively.For the merge comparison, the same fixture on #2178 gave 544/2,400 on each adapter. Those mismatches were confined to newly written words read through a different origin. These are synthetic readbacks, independent of the in-game frame-rate runs above.
AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-26T06:12:28Z.
Thanks @steven-seagull27, that's a clean measurement, and it shows exactly this PR's limit. A raw view has to start on 16 bytes, so
buffer_srvonly makes a structured view raw whenfirst * stride % 16 == 0. Views at 12, 24 or 36 bytes stay structured and keep NVIDIA's misread, as your table shows.#2885 goes further: a view off 16 bytes gets its own copy at an aligned start, and the table-bound path is lowered through raw handles too. So it should cover your unaligned origins as well. If the maintainers prefer #2885, this PR can be closed in its favour. Your fixture would be a good check of #2885's unaligned case.
Imported from Marvisak/VIctory. Originally posted by artor410 on 2026-11-28T08:19:13Z.
NVIDIA Ampere check of
b9dc4b0, merged cleanly ontomain63bcca4(treeab6653f). RTX 3070 Ti 8 GB (Ampere, 32-lane waves, heap capped at 1,000,000), driver 610.88, Windows 11, rustc 1.98.1, hardware adapter. Synthetic tests only.a_heap_buffer_read_by_element_takes_the_views_stridea_heap_buffer_read_where_no_buffer_view_is_reads_zerosThe stride test goes through the shader harness, not
buffer_srv, so this PR cannot change its result. Probe:overlap_test::gpu_writes_visible_through_overlapping_viewsfrom #2885 (76a13e1), copied in unchanged as a probe. It writes through one structured view and reads back through views that start at other 12-byte offsets. Views that start on 16 bytes read right, but the 12/24/36-byte starts stay structured and still misread. This is the limit you described. #2885 passes the probe with 0 mismatches.(Claude Code, Claude Opus 5.5.)
Imported from Marvisak/VIctory. Originally posted by hxpeerr on 2026-11-28T21:01:40Z.
#2464 and #2885 each remove the NVIDIA world-load hang on a Blackwell card, each alone on
main. Onmainthe hang is FIND-12's dispatch running a loop to the loop limit.Machine: RTX 5060 Ti 16 GB (Blackwell, 32-lane waves, view heap capped at 1,000,000), driver 621.40, Windows 11 26200, Ryzen 7 9800X3D, stock clocks, title 1.0.2.1, Series X profile. Every run:
diagbuild,VICTORY_D3D12_DRED=1, a fresh copy of the same saves,VICTORY_KEYS=40:Enter,45:Enter,60:Enter,70:Enter,80:Enter(boot into the story), shader cache and pipeline library made per tree withtranslate --cache --pipelineson this driver.Why
mainhangs on this card. Onmain(63bcca4) all five runs ended with0x887A000673-108 s after start, during the opening credits, and DRED stopped at FIND-12's 16x16x16 dispatch (W in #1968) every time. W costs the same in every frame and scales exactly with the loop limit, so one of its loops runs to the limit instead of ending:VICTORY_SHADER_LOOP_LIMITmain+ #3312, which survives themmain+ #3312main+ #3312Video memory does not change it: with
VICTORY_COPIES_IN_VIDEO_MEMORY=1or with #3312's page tables, W alone is still 5,855-5,935 ms. W reads its loop counts with scalar loads, through raw handles, from a structured SRV with a 680-byte stride, which is the misread #2464 describes.Each PR alone on
main, default loop limit, 6-minute runs alternating between the trees (63bcca4+ #2464b9dc4b0,63bcca4+ #288576a13e1; both merge cleanly):mainThe frame rates include the world load. Both trees reach the world in the opening credits in every run, and the captures show the city at night and then the harbour. The pipeline counts from
translate --pipelinesare the same onmainand both trees: 23,128 made, 397 refused by the host.The one difference I see is coverage. With #2464, one view stays structured in every run (
structured buffer view not made raw: not on 16 bytes, stride 100), as steven-seagull27's readback predicts. #2885 reports nothing like it. On this card, over 6 minutes, that view makes no visible difference in stability or frame cost.No game data attached. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-28T21:52:27Z.
Thanks @hxpeerr and @artor410, these two runs pin it down from both sides.
mainlost the device in 5 of 5 runs at the same dispatch, a loop running to the loop limit. With this PR alone, and with #2885 alone, there was no removal in 360 s and the world was reached. That's the same loop that hung here on an RTX 2080 before this change.So my offer stands: both fix the hang, #2885 also covers the unaligned starts, and if the maintainers pick #2885 this can close in its favour.
If this one is kept instead, the commit message still names one of the title's shaders, which the triage flagged under the asset policy. I'll reword it, or it can be squashed with a new message on merge.
AI-assisted (Claude Code).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.