Shaders: read heap-loaded s_buffer_load raw; SampleLevel outside pixel shaders #1409
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!1409
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1409/head"
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?
@icdmkg2 on GitHub · 2026-11-24 17:47 UTC · original
icdmkg2:fix/shader-heap-buffer-loads-and-compute-sample→main· +107 −5 · 5 files · 2 commits · closed without mergingTwo shader translation fixes found while chasing #1348, and a clearer device-removal message. These don't fix the world-load removal in #1348.
1.
s_buffer_loadon a descriptor read fromResourceDescriptorHeapBefore,
smem()lowered everys_buffer_loadwhose descriptor has no SRV used-resource entry as a constant-buffer read. For a descriptor the shader loads from the resource heap at a computed index, that put a CBV handle on a slot the host fills with a raw buffer view. GBV flagged the mismatch, WARP read nulls, and it can hang a GPU. The hair-strand compute shaders (smh_modify:CS_*Strand*) hit this.Selection rule (
smem()incrates/victory-shader/src/emit/lower.rs). The load is read raw, the same way as an SRV used-resource, when both of these hold:self.used_kind(src)isNone).Source::Loadedwhose scalar load traces, throughself.scalar[load].param, to a root parameter withroot == RootType::ResourceHeap. In practice that iss_load_dwordx4 s[n:n+3], s[heap_base], soffset, with the heap index(base + offset + soffset) >> 5fromheap_index().The rule looks only at where the descriptor was loaded from. It doesn't look at how the shader uses it: read-only and written heap descriptors are treated the same. It relies on the host making the heap's buffer views raw (
descriptor/host.rs). A descriptor that a used-resource entry names as a CBV still takes the CBV path.The read-only-descriptor case in #1354 at
cd9699f, which returned 73 through a CBV and 41 through an explicit raw table SRV, should be a direct control for this rule.2.
image_sampleoutside pixel shadersimage_samplein a compute, vertex or mesh shader emittedSample, which DXIL rejects outside pixel shaders ("features incompatible with the shader stage").CS_DensityShadowBlur_Hfailed validation this way. It now emitsSampleLevelat LOD 0.image_sample_oandimage_sample_boutside pixel shaders now fail as untranslatable instead of emitting invalid DXIL.3. Diagnostics
GetDeviceRemovedReason.shader-info --verboseprints each container's runtime hash: BLAKE3 of the container bytes, sized by the DXBC header at 0x18. Hashes in the logs can then be matched to containers.Testing
cargo clippyis clean, andcargo test -p victory-shaderpasses (120 passed, 1 ignored), rebased onffe310e.CS_DensityShadowBlur_Hnow passes validation.🤖 Generated with Claude Code
https://claude.ai/code/session_01GHAMAwekwWQWP6FsLe2hsw
@MichaelSmithAI on GitHub · 2026-11-24 17:54 UTC · original
We tested the scalar-buffer selection rule from this PR together with #1354 at
cd9699fon an RTX 4090 under Wine/GE. A source-built compute shader used a runtime index to read 41 from raw SRV slot 2 while slot 1 held 99. A named table CBV returned 73. Both wrote the result through a slot inferred to be a raw UAV. All 15 lowering tests passed.The combined lowering keeps #1354’s inferred UAV class on the raw path and adds this PR’s resource-heap origin check for an unnamed read-only descriptor. A separate fixture exercised creation of all three descriptor classes through
HostHeap::make_at. The numerical fixture used matching host bindings. A directly indexed heap CBV without used-resource metadata remains ambiguous. These checks cover shader translation and descriptor creation; we have no title run measuring the effect on #1348.@geiyiliyabumo on GitHub · 2026-11-24 18:10 UTC · original
Independent verification of \
cfc0edf\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:Code audit: routing \RootType::ResourceHeap\ \s_buffer_load\ descriptors through raw SRV (11, 0)\ and lowering non-pixel \image_sample\ to \sampleLevel\ (level 0) looks clean and directly addresses the #1348 hang pattern; adding targeted unit tests for both paths would make regressions easy to catch.
AI-assisted; synthetic tests only, no game files.
@icdmkg2 on GitHub · 2026-11-24 18:37 UTC · original
Thanks both. @geiyiliyabumo, I've added the targeted tests in
de109f1:scalar_loads_from_a_resource_heap_descriptor_are_raw(inlower.rstests): ans_buffer_loadon a descriptors_loaded from aResourceHeaproot parameter, with no used-resource entry, is read raw. As a control, the same load from aTablestays a constant-buffer read. It is counted by a test-onlyheap_raw_loads.compute_image_sample_reads_level_zero(inwaterfall_tests.rs): the indexed waterfall program, withimage_samplein place ofimage_sample_lz. It validates in compute and samples each lane's texture on hardware and WARP.Both fail with the fixes reverted. The second fails with the validator's
Function uses features incompatible with the shader stage (cs). With the fixes: 122 passed, clippy-D warningsclean,xtask policyok.@MichaelSmithAI, agreed on the open case. A heap CBV that is directly indexed, with no used-resource metadata, is read raw under this rule. If the title wrote a CBV into that slot, the host has built a CBV descriptor there, so the two don't match. The rule only looks at where the descriptor came from. One way to settle it would be for the host to record the view kind it built for each heap slot, so the translator, or a debug check, could compare against it. For now I'd treat that as a known limit rather than widen this PR.
Separately, merged with #568, this gets an RX 6750 XT to about 6 minutes in the world (frame 6350). Details are in #508.
@sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: +24 programs over
main, 0 lost.Offline. I merged head
de109f1ontomainffe310e(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: 21,724 onmain, 21,748 with this PR.mainAll 24 are among the programs that #1402 gains. They failed in the validator on
main("Entry function performs some operation that is incompatible with the shader stage").Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 122, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@upipibi on GitHub · 2026-11-24 21:00 UTC · original
In-world evidence for part 1, from a fork that runs
maininto the world: fxceless/victory-gta6, the comment at itss_buffer_loadheap path inlower.rs.BatchCullMeshlets,BatchCullPreSkinnedMeshlets,BatchCullBatchCSMeshlets) read their batch records, mesh headers and instance transforms through heap-picked buffers. Read as constant buffers, the loads gave nothing (validation: "Descriptor Type in Heap: SRV, Register Type: CBV"), so culling passed no meshlet and every indirect mesh draw ran empty. This PR's hair-strand case is the same pattern.image_sampleoutside pixel shaders, asSampleLevelat 0) is the same shortcut the fork took. It overlaps with #1237 (gradients from quad lanes) and #160 (keepssampleand relies on driver compute derivatives), so those three need one choice.Reading only, nothing run. AI-assisted (Claude Code).
@sinan-cmyk on GitHub · 2026-11-24 21:19 UTC · original
Stacked on #1402: no change, and one behaviour contradicts #1015
Result: 0 gained, 0 lost, and no failure reason changes on top of #1402. On
mainthis PR gained 24 programs, and all of them are among #1402's gains.Merging it needs two decisions. There are 5 conflict hunks in
lower.rs,shader.rsandwaterfall_tests.rs:heap_buffer_viewrule runs first, and this PR's heap rule is the fallback (.or(from_heap.then_some(11))).image_sampleoutside pixel shaders: compute programs keep #1402's SM 6.6 derivatives. This PR's level-0 sample then applies only to vertex and mesh programs. Without that split, #1402'scompute_shader_implicit_sample_uses_valver_1_8_and_validatesfails.With those choices,
cargo test --locked -p victory-shader --lib: 139 passed, 0 failed.Method:
victory translate --validate --listonshaders.rpf(1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs), against #1402 at2310409. AI-assisted (Claude Code). No shader names or data are included, per the asset policy.@Marvisak on GitHub · 2026-11-25 00:40 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Its main fix (s_buffer_load through a heap-loaded descriptor read raw) is in main (lower.rs smem
heap_constants); the rest turns non-pixel image_sample into SampleLevel 0, against main's deliberate implicit-LOD samples in compute, with no evidence.If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed