Shaders: heap indices from data clamped before the root views they index #2558
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2558
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2558"
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?
@RomainKH on GitHub · 2026-11-25 15:45 UTC · original
RomainKH:shader/clamp-view-index→main· +188 −53 · 4 files · 2 commits · openSplit out of #2342 at the maintainer's request (NEW-118 in #1633), on current
main(63bcca4).view_strideandview_addressesread root SRVs at a heap index taken from data: the view-stride table and the view addresses. They do this without clamping the index, asheap_handleandbuffer_guardalready do. Root views have no bounds, so an index past the table reads whatever memory follows it.Change
clamp_view_indexclamps the index toHEAP_VIEWS - 1before both reads.buffer_guardnow uses the same helper; its behaviour is unchanged.address_slots, from #1906: about 1.5 million here, againstHEAP_VIEWS= 2^21), so even a clamped index could read past it. It now hasaddress_slots().max(HEAP_VIEWS)entries, as the view-stride table already coversHEAP_VIEWS(write_stride). The entries past the dynamic slots are cleared when the buffer is made, so they read 0 whatever the new allocation held (brainbudt's review), and nothing writes them after. This is 32 MiB of upload memory instead of about 23.main(fromff47463,54ab406and850b66f) called the Windows-onlyvalidatorwithout acfg, so the shader tests no longer built on Linux or macOS. They now go through avalidatehelper, as doesds_bpermute_wave64_preserves_32_lane_half(added onmainsince,cfg-gated but skipping silently withoutdxil.dll). WhereCIis set (GitHub sets it), that helper fails ifdxil.dlldoes not load instead of skipping, so a green run means the DXIL of these tests was validated. This is the separate first commit.lower.rsis within a few KiB of the repository's 512 KiB limit on a file (xtaskasset policy), and the new test would have pushed it over. So the test lives inemit/lower/tests/descriptors.rs, a child oflower's tests that uses their helpers.lower.rsis 521,225 bytes here.Relation to open PRs:
address_slots(). This PR takesaddress_slots().max(HEAP_VIEWS), and #1906's testview_addresses_cover_tables_made_afreshnow checks the buffer up toHEAP_VIEWS: the entries past the dynamic slots read 0 up to the last one and are not written, and there is none past it. Its old check of a mark past the buffer's end cannot run any more, since 32 MiB fills the allocation. r4tedx worked out this resolution first and is co-author of the commit.Testing
New test
heap_indices_from_data_are_clamped_before_root_view_reads, on synthetic GFX10 code:Without the two clamps it fails (
left: 3, right: 4).cargo test -p xtask(asset policy): passes.macOS arm64, Rust 1.98.1:
cargo test -p victory-shader --locked --libgives 173 passed, 0 failed, 2 ignored. rustfmt reports nothing new on the changed lines.Windows target, type-checked from macOS:
cargo clippy --target x86_64-pc-windows-msvc --workspace --all-targets --locked -- -D warnings, with and without--all-features, is clean. The GPU tests, including the changed #1906 test, run in the Windows CI only.Not run: the GPU tests (no GPU here) and the title.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
@oni-swr on GitHub · 2026-11-25 16:12 UTC · original
Independent verification (software WARP only)
b0fbdcb60ebb311a92a4901321e47ce0e171b174(checked out detached)67e8ae1401df112248aed36d0024483181b718b7; read-onlygit merge-tree --write-tree origin/main <head>merges cleanly (exit 0); GitHub reports MERGEABLE.VICTORY_D3D12_WARP=1withVICTORY_DXILpointing at the Windows SDK 10.0.26100dxil.dll. Default features, no extra test flags.Commands and results
cargo test --locked -p victory-shadercargo test --locked -p victory-gpucargo test --locked -p victory-shader --lib heap_indices_from_dataheap_indices_from_data_are_clamped_before_root_view_reads: 1 passed). WithVICTORY_DXILset the newvalidatehelper really validated the DXIL of the affected tests on Windows. One existing test (normalized_buffer_formats_load_their_ends_exactly) takes about 80 s in a debug build; it is not touched by this PR.Review: Looks correct.
clamp_view_index(unsigned compare toHEAP_VIEWS - 1) now guards the view-stride lookup and both view-address lookups, andbuffer_guardreuses it unchanged. The host address buffer is sized tomax(count, HEAP_VIEWS)slots, so a clamped index stays in bounds (cost: about 32 MiB of upload memory, as the description says). Thevalidatehelper keeps the shader tests building off Windows. The counting test is a reasonable pin. Only the shader and host emit paths were verified here, not behaviour on hardware.Review and verification by Claude Code (Claude Sonnet 5.5), AI-assisted; no game files, dumps, shader names or hashes involved.
@Mericas77 on GitHub · 2026-11-25 17:34 UTC · original
Tested on NVIDIA (the GPU tests weren't run here yet): RTX 4070, driver 621.01, Windows 11, rustc 1.100.0, dxil.dll 1.9.2602.17. Head
b0fbdcbagainstmain67e8ae1. This card has a capped view heap (NVIDIA's 1,000,000-descriptor limit).cargo test -p victory-gpu --lib --locked:main193 passed / 2 failed / 1 ignored, this PR the same. The two failures are the same on both and are the known heap-cap ones (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views"past the dynamic slots"). The larger view-address buffer causes no new failure.cargo test -p victory-shader --lib --locked(with--skip heap_direct_texture_reads_mark_their_heap_index, which crashes the process onmainhere too, #2571):main266 / 3 / 3, this PR 267 / 3 / 3. Same 3 known NVIDIA failures.heap_indices_from_data_are_clamped_before_root_view_reads: passes. Sincevalidate()skips silently whendxil.dlldoesn't load, I re-ran it withCI=1: still passes, so the DXIL really was validated.No game data; the title was not run.
AI-assisted.
@Marvisak on GitHub · 2026-11-25 18:38 UTC · original · edited 2026-11-25 22:15 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-gpu/src/descriptor/host.rsandcrates/victory-shader/src/emit/lower.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
@brainbudt on GitHub · 2026-11-25 21:04 UTC · original
Independently verified
b0fbdcbmerged onto13f91ca. The index clamps and host allocation size look correct, with one issue to address before merge:HostHeap::view_addresses(crates/victory-gpu/src/descriptor/host.rs:546-560): The buffer allocatesmax(count, HEAP_VIEWS)slots (32 MiB) but only initializes thecounttitle slots. D3D12 documents default committed allocations as "almost always" zeroed rather than guaranteed. In an isolated WARP probe with a diagnostic0xA5prefill, the final slot retained all four prefilled words; clearing[made.len(), slots)during initialization made the same probe pass.Verification: Windows MSVC workspace
cargo check --testspassed; Linux x86-64 passed 159victory-shadertests (2 ignored); Windows WARP + Microsoft DXIL Validator1.9.2609.5passed 6/6 focused shader tests and 13/13 host descriptor tests (synthetic fixtures).b0fbdcb60etoeb0dae2fea@RomainKH on GitHub · 2026-11-26 09:52 UTC · original · edited 2026-11-26 10:01 UTC
Rebased onto
main63bcca4(headeb0dae2).@brainbudt: done as you suggested. When the buffer is made, the entries from
address_slots()(title plus dynamic slots, #1906) up toHEAP_VIEWSare cleared with onewrite_bytes. The title and dynamic entries below that were already written.Conflict with #1906: the buffer has
address_slots().max(HEAP_VIEWS)entries.view_addresses_cover_tables_made_afreshnow checks that:16 * HEAP_VIEWSbytes;address_at(end)andaddress_at(HEAP_VIEWS - 1)read 0;note_address(end)writes nothing;HEAP_VIEWS.The old check of a mark past the end could not run any more, since 32 MiB fills the allocation. @r4tedx worked out this resolution first and is co-author of the commit.
ds_bpermute_wave64_preserves_32_lane_half, added onmain, now goes through thevalidatehelper too.Checked from macOS:
victory-shaderlib: 173 passed, 0 failed, 2 ignored;cargo clippy --workspace --all-targets -- -D warnings, with and without--all-features: clean.The GPU tests run in the Windows CI.
Edit: the first push of this rebase failed the CI asset policy, because
lower.rswent past the repository's 512 KiB file limit by 118 bytes. The new test now lives inemit/lower/tests/descriptors.rs(headeb0dae2); see Layout in the description.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.