Shaders: query a buffer's size through a handle of its own #2120
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2122"
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 imjustprism on 2026-11-25T05:31:44Z.
amd's driver 32.0.32029.2010 on an rx 9070 xt faults in its shader compiler
when one buffer handle feeds both a size query whose result is used and a
load. a buffer's size query now always takes a handle of its own, from caches
of its own, so no load shares it. a query nothing reads is dropped by the
writer together with its handle.
rewritten on
13f91ca: with 850b66f's entry-block handle cache the old branchno longer compiled against main, and the size query was back on the loads'
handle. the uses analysis is gone, the writer's liveness does that job now.
rebased again onto
63bcca4(bf526d7). the lowering change is the one from6ff2361, line for line. the five unit tests moved toemit/lower/tests/size_handles.rs, unchanged: with them in lower.rs the file
was 528,047 bytes on the new main, over the 524,288 of cargo xtask policy.
it is 522,494 now.
the new gpu test runs on hardware and warp. with the size query forced back
onto the loads' handle it kills the test process on the 9070 xt at pipeline
creation. translate --cache --pipelines and the title were not run on this
head.
the extra handle is emitted on every host, so this is how far it reaches:
translate --list with VICTORY_EMIT_DUMP, release builds of
13f91caand6ff2361, one run each, dumps compared file by file. 25,752 programs make25,734 files because some share a dump file name. the other 25,068 files are
byte for byte the same, and refusals are the same on both, reason by reason.
the shader cache is keyed by the translator's source, so every program is
translated again once, as after any translator change.
fixes #1783
fixes #1785
refs #2124
refs #2517
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T05:36:46Z.
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
e14ee3d.victory-shader: 250 passed, 3 failed, 3 ignored. The 6 newstride_testspass (a_buffers_size_query_does_not_share_its_handle_with_the_loads,a_buffers_unread_size_shares_the_handle_of_the_loads,a_buffers_size_read_as_its_loads_offset_has_a_handle_of_its_own,an_images_size_read_as_data_shares_the_handle_of_its_sample,a_buffers_base_in_a_scalar_load_is_not_a_read_of_its_size,a_raw_buffer_is_sized_and_read_through_one_descriptor_load). The 3 failures are #1744's NVIDIA failures onmain. Two of them are in the same file,a_heap_buffer_read_by_element_takes_the_views_strideanda_heap_buffer_read_where_no_buffer_view_is_reads_zeros, and they still fail here, so this PR doesn't change them. Same asmainon this hardware.Added 21:33Z: re-run at the current head
6ff2361(base13f91ca), same RTX 3070, driver 616.56, debug,cargo test --locked -p victory-shaderwithheap_direct_texture_reads_mark_their_heap_indexskipped (it crashes the test process on this card onmain, #2571): 272 passed, 3 failed, no SKIPPED lines. The PR's six new tests all pass:a_buffers_size_query_does_not_share_its_handle_with_the_loads,a_buffer_at_a_computed_table_offset_is_sized_through_its_own_handle,a_buffer_sized_at_each_of_its_reloads_has_one_size_handle,a_buffers_unread_size_query_writes_no_handle,an_images_size_read_as_data_shares_the_handle_of_its_sample(lower::tests) andstride_tests::a_raw_buffers_size_beside_its_loads_reads_its_byte_count. The 3 failures are the #1744 NVIDIA ones that fail onmainon this card too (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware).AI-assisted (Claude Code, Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:40:56Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.149 passed / 0 failed / 2 ignored. Buffer size queried through its own handle (+5 tests) — descriptor-handle-based sizing; biggest test addition of this wave.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:46:08Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib a_buffers_— 4 passed, 0 failed (a_buffers_size_query_does_not_share_its_handle_with_the_loads,a_buffers_unread_size_shares_the_handle_of_the_loads, etc.)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean separation of buffer size-query handles when the buffer size is read as data. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fiestorra on 2026-11-25T06:16:31Z.
Verified the "census is unchanged" claim here, and two things I would add before it lands
Measured on this machine (RTX 4090,
32.0.16.2124, release build, local 1.0.2.1 archive, 26,503 containers, validator SDK 10.0.26100dxil.dll1.9):So the claim holds, and it is the right claim for this change — the fix is about what the driver's compiler is handed, not about whether modules validate.
First, the workaround should carry the reason in the code. The description names it precisely — AMD's
32.0.32029.2010on an RX 9070 XT faults when one buffer heap handle feeds both a size query whose result is used and a load — but a reader oflower.rsin six months will see an extra handle and no way to know it is not redundant. A comment naming the driver version, the card and the crash is what stops it being removed by someone tidying up, and this repository has already lost time this week to a missing line of explanation.Second, the number I would want in the description: how many programs' emitted DXIL changes. The extra handle is emitted wherever the pattern occurs, on every host, not only on the one with the faulty compiler — so:
createHandleFromHeapper program" is worth a sentence on cost, because this is the path that runs for every buffer size query in the title.Your
heap_handlescounter under#[cfg(test)]suggests you already have that number — it just is not in the description, and "census unchanged" does not cover it, because a module can validate identically while its code differs.Two smaller things I checked and like:
soffsetcase handled — that is the part that would have been easy to get subtly wrong, and the helper is written so it can be tested on its own;heap_handlesis test-only, so nothing in a release build pays for the instrumentation.What I could not check: the crash itself, since this machine has neither the card nor that driver. The evidence for the fix's purpose is yours, and I am reviewing the shape of it rather than re-running your failure.
No game data is involved: counts, a driver version and code.
Written with an AI assistant.
Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-25T07:30:09Z.
thanks for running the census on the 4090. the reason is already in the code: the rustdoc on the size query in lower.rs names the driver, the card and the fault, and what does and does not trip it. the count was missing, it is in the description now: 333 of 25,678 emitted programs change, about 100 bytes each. the cache is keyed by the translator's source, so it retranslates once like after any translator change.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:31:09Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
e14ee3d8ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:46:39Z.
Automated triage for the maintainers.
Merge candidate. Thanks for answering the request. Head
bf526d7is rebased onto63bcca4with the same lowering as6ff2361.Lower::descriptor_data(crates/victory-shader/src/emit/lower.rs) makes a buffer's size handle throughswap_size_caches, so no load shares it, and image handles stay shared. The five unit tests moved unchanged intoemit/lower/tests/size_handles.rs, which themod size_handles;insidelower.rs's test module points to. That keepslower.rsat 522,494 bytes, under the 524,288-byte policy limit.The RX 9070 XT check I asked for is covered twice. MeMako's independent run at
6ff2361created 25,665 of 25,665 pipelines with noamdxc64.dllfault, and your run on this head passed. Linking #2124 and #2517 as refs rather than fixes is the right call. A structured-buffer case in the GPU test would still be a useful follow-up, but it shouldn't block this.CI: passing.
Generated by Claude Code
upstream-sync referenced this pull request2026-11-25 15:04:06 +00:00
[PR #2122] query a buffer's size through its own handle when the size is readto [PR #2122] query a buffer's size through a handle of its ownupstream-sync referenced this pull request2026-11-26 00:03:14 +00:00
Imported from Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T00:21:42Z.
Independent RX 9070 XT verification at current head
6ff2361(AMD Radeon RX 9070 XT adapter 0, driver32.0.32029.2010, Windows 1110.0.26200x64, SDK10.0.26100.0dxil.dll).Tests & CI checks on
6ff2361:cargo clippy --workspace --all-targets --locked -- -D warnings: passcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passcargo test --workspace --locked: pass (victory-shader: 276 passed, 0 failed, 3 ignored — all 6 new tests pass on RX 9070 XT, WARP, anddxil.dll)Offline pipeline stress test on
6ff2361(release build,translate --validate --pipelines --jobs 8on the 1.0.2.1 shader pack, 26,503 containers, 1,134 s):amdxc64.dll+0x861b9fcrashes.Not run on
6ff2361:translate --cache --pipelineslibrary pre-build or a live title run.Notes before landing on current
main(63bcca4):lower.rs: A dry-run merge of6ff2361withmain(63bcca4) auto-merges cleanly, but growscrates/victory-shader/src/emit/lower.rsfrom520,563B to528,047B, exceedingxtask/src/policy.rs's524,288B limit (repository_passes_policywill fail once rebased/merged). Moving the 5 new unit tests out oflower.rsinto a test submodule (leaving the 6th test instride_tests.rs) would keep it under 512 KiB.stride_tests.rscurrently tests a raw buffer (Stride::Raw); adding a structured-buffer size+load case (e.g., stride 60) would also cover structured buffers, which hit the sameamdxc64.dll+0x861b9ffault on this driver.amdxc64.dll+0x861b9fcrash on RX 9070 XT (32.0.32029.2010) and look like candidates to link alongside #1783 and #1785.No game data, shader names, or screenshots are included, per
docs/asset-policy.md. Hardware runs and dry-run merge were performed by me on my RX 9070 XT; comment drafted with Antigravity.upstream-sync referenced this pull request2026-11-26 06:03:43 +00:00
Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-26T07:09:55Z.
rebased onto
63bcca4, the head isbf526d7now. the five unit tests movedunchanged to emit/lower/tests/size_handles.rs, so lower.rs is 522,494 bytes
and cargo xtask policy passes. the lowering change is the one from
6ff2361,line for line. both clippy runs, cargo test --workspace and the policy check
are green on the new head on an rx 9070 xt.
@MeMako thanks for the pipeline run and for catching the size limit. #2124
and #2517 show the same fault address on the same driver, so the description
names them now, as refs and not fixes: i have not checked that they are this
cause. the gpu test still covers a raw buffer only, no structured one.
[PR #2122] query a buffer's size through a handle of its ownto [PR #2122] Shaders: query a buffer's size through a handle of its ownImported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T12:40:41Z.
Review: APPROVED
Reviewed and verified
bf526d76:swap_size_caches(crates/victory-shader/src/emit/lower.rs:4256-4262, 4404-4426) cleanly separatessize_handlesandsize_entry_handlesfor buffer size queries and restores both caches before propagating errors, while keeping image queries on the access handle. Becausedescriptor_dataconstructsSource::Loaded, queries stay within those two caches rather thanjoin_handles.emit/lower.rsis 522,494 bytes (1,794 bytes under the 524,288-byte limit).Local verification:
xtask policy(192 files ok),cargo clippy -p victory-shader --all-targets -- -D warnings(default &--all-features),emit::lower::tests(38 passed, including all 5size_handlestests), andemit::stride_tests(9 passedonVICTORY_WARP=1;7 passed, 2 failedon RTX 5090 witha_raw_buffers_size_beside_its_loads_reads_its_byte_countpassing and the two pre-existing NVIDIA 1M view-heap-cap failures). Adding a structured-buffer GPU readback later would cover element-count queries too. Approve.Imported from Marvisak/VIctory. Originally posted by JAEdotUK on 2026-11-27T21:21:36Z.
Tested on RDNA 4 with an older driver: Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 25H2 (build 26200.9974), Rust 1.98.1 (from
rust-toolchain.toml), debug build. PR headbf526d7(bf526d765f) on main63bcca4(63bcca43c6). No game data in this comment.The RX 9070 XT results in this thread name driver 32.0.32029.2010. As far as I can tell from the thread, this is the first result for this PR on 32015. (In #1785, Luislariosss saw the same fault on 32015 with an RX 9060 XT, on
70564ae.)New GPU test,
emit::stride_tests::a_raw_buffers_size_beside_its_loads_reads_its_byte_count. I built it withcargo test -p victory-shader --lib --locked --no-run. Each run is one process running the test binary with--exact <test> --test-threads=1. WARP runs setVICTORY_WARP=1.crates/victory-shader/src/emit/lower.rsreplaced by main's copy from63bcca4(no other change), so the size query is back on the loads' handle:0xC0000005. The Windows crash record namesamdxc64.dll32.0.32015.7029 at offset0x85fd0f. This is the offset on this driver; 32029 reports0x861b9f.This matches the description's note that the test kills the process when the size query shares the loads' handle, on a second driver version.
Shader suite,
cargo test -p victory-shader --lib --lockedonbf526d7: 308 passed, 0 failed, 3 ignored.Not tested:
850b66fon 32015. The bisect in #1785 covers 32029.translate --pipelinesor a game run on this head.This testing and comment were produced with Claude Code (Claude Opus 5.5). The hardware runs were on my machine.
Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-27T21:43:42Z.
Vice-Tay has a regression test that can help with the structured-buffer follow-up. Its merged #258 checks the emitted DXIL for separate GetDimensions and load handles, and for separate index clamps when the view limit is 2,097,152. Its optimizer guard keeps the clamps separate after lowering. KingKaom independently reported the clamped pipeline scan passing on RX 9070 XT / 32.0.32029.2010 after the merge.
The existing #2122 hardware fixture already covers raw buffers. When adding the structured-buffer case, a DXIL check with the heap clamp on and off could show whether the two caches preserve the separation after optimization. That gives a focused test before considering any of Vice-Tay's broader optimizer changes. We compared source and reports and haven't run that check on VIctory.
PortBridge compared the public sources with Codex. The implementation and AMD runs are credited to their original authors.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T02:13:21Z.
Field evidence for this fix, from another VIctory-derived tree (read from its threads, not run):
amdxc64.dll+0x861b9f(read0x8), the fault of #2124, right after the pipeline backlog cleared. The reporter rebuilt with avatarmanz/VIctory-7900XTX#357 ported, which gives a raw view's size query a handle of its own on RDNA 4, and played 8.5 minutes in the world without the crash. The fix is merged there as ScarlettPort#93.NonUniformResourceIndexand keeps it out of those passes.VIctory main has no such merging pass that I can find, so this PR's separate caches should hold. Its GPU test, which kills the process when the size query is forced back onto the load's handle, is then the guard if a later optimisation pass starts merging identical handle creations.
AI-assisted (Claude Code, Claude Opus 5.5 read ScarlettPort#73/#93 and this diff).
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.