Repository navigation
GPU: buffer views past the end of their host copy are null, views running past it are cut - #635
claude-GTA6 wants to merge 7 commits into
Conversation
…ning past it are cut A title buffer view whose first element lies past the end of the host copy it is made on was created as is. That is an invalid call: with the debug layer (VICTORY_D3D12_DEBUG=1) on an RTX 5090 it removed the device (DXGI_ERROR_INVALID_CALL after 'CreateUnorderedAccessView: ... StructureByteStride 16, FirstElement (value = 2706088) must be between 0 and the maximum'); without it the view is undefined. Such views are now left null (once-logged), and views whose last element runs past the copy are cut to fit, in buffer_srv and buffer_uav. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title view whose record count is 0 became a view of NumElements 0, also an invalid call: on an RTX 5090 with the debug layer, continuing from a save removed the device on the start screen (CreateUnorderedAccessView, stride 16, FirstElement in range, NumElements 0). Made null like a view past the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
From a tester working with Claude (AI-assisted); measured on my own machine. Pushed On an RTX 5090 (driver 621.24, Windows 11) with the debug layer, continuing from a save removed the device on the start screen. The last message before the removal was
On |
|
Hardware data point for the
|
Test by Vaximous (Vaximous/VIctory 25d3abd, offered on this PR): makes placed buffer SRVs/UAVs of one and of zero elements and checks the empty slot is null and the device stays. Fails without the check (the slot is kept). Co-Authored-By: Vax <vaximous@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
From a tester working with Claude (AI-assisted); measured on my own machine. @Vaximous thanks, I took your test into this PR as On an RTX 5090 (621.24): the test passes with the check, and fails when I disable the check ( Your note that a run's chance of hitting this depended on the shader cache fits what I saw: it only showed up for me after a save existed, so continuing from it took a different path at world entry. |
descriptor/host.rs: keep both new tests (zero-element buffer views are null; upstream's null UAV dimension tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DenRakEiw
left a comment
There was a problem hiding this comment.
Tested head fb29c17 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP (VICTORY_D3D12_WARP=1):
cargo test -p victory-gpu(RTX 5090): 51 passed, 0 failed, 1 ignored (includesdescriptor::host::tests::buffer_views_of_no_elements_are_null,GetDeviceRemovedReasonclean)VICTORY_D3D12_WARP=1 cargo test -p victory-gpu(WARP): 51 passed, 0 failed, 1 ignoredcargo clippy -p victory-gpu --all-targets: 0 warningscargo xtask policy: ok
Code review looks clean and sound: both buffer_srv and buffer_uav check FirstElement >= capacity against the host shadow buffer's element capacity, clamp NumElements to capacity - FirstElement (guaranteed ≤ u32::MAX since NumElements is u32 and FirstElement < capacity), and reject NumElements == 0 so the caller gets a null descriptor instead of triggering device removal. Approving.
AI-assisted (Gemini 4 Neon).
|
Review of The clamp itself is right, and one detail deserves a comment in the code: Two things I would add before merge:
While writing those, one trap worth a comment: the descriptor word layouts differ between the two view types. A shader resource view's buffer union starts at word 4 — With the guard disabled, all three tests fail, so they pin the behaviour rather than passing vacuously. |
|
From a tester working with Claude (AI-assisted); measured on my own machine. @adamdotpy thanks, both done in
On the word-layout trap: the device test sets the SRV's count at word 6 and the UAV's at word 4, which matches the two layouts you describe (SRV union at word 4, UAV at word 2). On |
…vice buffer_srv and buffer_uav shared the same three checks; cut_to_copy now holds them (start at or past the end: null; past the end: cut; no elements: null) with unit tests of each case, and says why the host copy's 64 KiB padding keeps views into it legal. Suggested by adamdotpy in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Applied as the net diff of upstream PR Marvisak#635 (head fb29c17), 4 commits: fb29c17,cfe7610b,66e9038a,64133ca8.
|
Both suggestions are in and they are better than what I asked for: one One gap is left, and it is the branch I would least like to lose: the device test covers the null side (a view past the copy, I had the same need on your head and wrote that test; it is pushed as Take it, rewrite it or ignore it — it is yours, not a PR on this branch. |
|
Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
Great fix for out-of-bounds / zero-element buffer views — looks ready to merge! |
|
Confirming @Yaekai's find, with where the value comes from and what the worst case actually is.
Two things worth recording about the impact, because they change how urgent it is:
This is pre-existing on One thing that would go with it: the cut side of this code on a real device. My |
|
Tested on an RTX 3070 (Windows 11), diag build, on a branch with #193, #483, #439 and runtime descriptor kind checks stacked. I ported the same check by hand because that branch's
Unit test 🤖 Generated with Claude Code |
|
This is the evidence that settles it. A zero-element unordered buffer view ( |
The first element is the title's own descriptor word; a corrupt one near u64::MAX wrapped when the host copy's offset was added and passed cut_to_copy as a small first element, viewing the wrong part of the copy. Saturating keeps it past the copy, so the view is null; a view that fits cannot saturate (offset / element <= capacity). Found by Yaekai, confirmed by adamdotpy in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
From a tester working with Claude (AI-assisted); measured on my own machine. @Yaekai thanks, and @adamdotpy for the impact analysis: fixed in @XIIYAZ thanks for the hardware data point. A zero-element unordered view removing the device at world entry, then 7 minutes in the world after the fix, is the exact case this PR set out to catch. @adamdotpy on your device test for the cut side: thanks for writing it. The maintainer of this branch will decide on taking it; it's noted. |
|
Verified I also reproduced the wrap itself with a throwaway test on your head (reverted afterwards, tree clean): with That closes the last open item on this branch from my side: the cut is tested without a device, the cut side has a device test offered in |
|
Same crash on an RTX 5080 (driver 616.92), with a case this check doesn't catch: the first element is inside the copy but the view has no elements. The device was removed with |
|
Checked this exact case against the current head Every buffer view path — Evidence run here: So: no code change needed on this branch for the zero-element case; it is covered since |
…null, views running past it are cut Head 5346bfa (claude-GTA6). Conflicts in descriptor/host.rs: our buffer views can be made raw off their elements (raw_window) and refuse a raw start off 16 bytes; the cut runs after both, counting dwords for a view made raw. #635's tests pass make_at no annotation (#568). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79f6e24 to
8e58f53
Compare
…ast it a cut one `cut_to_copy`'s arithmetic is tested without a device; that it is handed the right arguments, and that both functions act on the answer, is not. This goes through `HostHeap::make_at` for both view kinds and checks the slot: null for a view whose first element is past the copy, kept for one whose last element is, with the device alive after each (both are the invalid calls the host removes it for). The two descriptor word layouts differ: a shader resource view's buffer union starts a word later than an unordered access view's, because the 64-bit `FirstElement` aligns it past `Shader4ComponentMapping`. Setting the wrong words leaves `NumElements` 0, which tests the null path twice. Disabling the cut fails both tests. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
|
From a tester working with Claude (AI-assisted); measured on my own machine. Housekeeping: I rewrote this branch's history to fix commit author metadata (a wrong local git identity), so three commit IDs changed. The contents are identical (same tree, same commits):
@adamdotpy: I took your device test as |
|
Verified the new head |
|
From a tester working with Claude (AI-assisted); measured on my own machine. Closing this as superseded by The one behavioural difference: here, a view that starts inside its copy but runs past the end was cut to the part that fits, while Thanks to everyone who tested and reviewed: @adamdotpy (including the device test for the cut), @Vaximous, @Yaekai, @XIIYAZ, @DenRakEiw and SlopComp. |
…vt-440-111a Shaders: f16 cvt via valu16; unused resinfo channels are 0 (Marvisak#440)
…l properties" This reverts commit cd6d934.
Upstream closed Marvisak#635: main's 4051149 makes title buffer views that are empty or run past their host copy null, the cases Marvisak#635 covered.
Upstream superseded Marvisak#635 and Marvisak#568 (reverted just before this merge); Marvisak#189, Marvisak#334, Marvisak#437, Marvisak#542, Marvisak#587 and Marvisak#1529 are still open upstream and are kept. Resolutions: - emit::Options is upstream's struct with Marvisak#189's `wave64` added; TranslateOptions stays as its alias. lower::Parts carries both `options` and upstream's `view_marks`. - Shader cache: upstream's cached refusals and hit flag, keyed by Marvisak#189's Wave64 mode byte as before. - lower.rs: Marvisak#542's 2 GiB bound applies to raw and structured views; title memory (upstream's MEMORY path and root views read as memory) is not bounded again, being checked where it is looked up. Scalar loads take upstream's raw views plus Marvisak#437's UAVs. The descriptor-kind use keeps Marvisak#437's preference for image/vector uses inside upstream's fallback. image() is upstream's (its own a16 bias/compare, gather4_l and _cl grads), replacing Marvisak#437's parallel version. - Marvisak#189: AddH (upstream's f16 wave sum) in apply_wave_op; 16-bit reductions are refused in an emulated 64-lane wave. mask_dword checks Marvisak#189's deferred ballot errors before upstream's mask_number. - Marvisak#334: indirect arguments keep the per-list buffer states (no indirect::done); upstream's single-group clamp dispatch is taken, and its diagnostics readback copies from the read state without barriers. - GPU adapter: upstream still creates its device on the default adapter, so host_adapter() stays. The shader test host keeps the high-performance adapter pick and adds upstream's dedicated-memory requirement. - Marvisak#1529: gameinput.rs as the PR's own merge of main (scripted keys first, then keyboard and mouse); run.rs configures controls and FidelityFX.
From a tester working with Claude (AI-assisted); measured on my own machine.
What
buffer_srv/buffer_uav(descriptor/host.rs) move a title buffer view'sFirstElementonto its host copy but never check it against the copy's size. A view whose first element lies past the end of the copy is an invalid call.Seen
RTX 5090 (driver 621.24), Windows 11 26200, diag build with
VICTORY_D3D12_DEBUG=1, a few minutes into the first mission's world. The debug layer reported the call below, and the device was removed withDXGI_ERROR_INVALID_CALL:Without the debug layer the view is undefined behaviour.
Change
In both functions, after the offset is applied:
With this change the debug layer reported no API errors in the same scene (that run also had other fixes stacked, listed below).
Testing
cargo build --release -p victoryandcargo test --release -p victory-gpuonmain: 43 passed.cargo fmt --checkgives the same warnings on this file as onmain. None are in the new lines.