[Ready to merge] Shaders: emulate image_bvh intersect instructions as miss to enable lighting compute shaders #1533
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#1533
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Xvania7 on GitHub · 2026-11-24 18:52 UTC · original
Related to #876, #71, #274.
Problem
In world rendering, rasterized geometry in G-buffer targets is present, but the 2560x1440 RGBA16F accumulation target that TAA and Bloom read stays flat/clear-colored (a few KB as PNG), starving post-processing passes and upscalers of lit scene pixels (as identified by @luisaugustz in #876 and @HenriqueSBueno in #1317).
Root Cause:
The direct lighting, RTGI probe resolve (
CS_RaytracingResolve), and directional shadow passes (rtdirectionalshadows) walk the console's BVH4 structures using RDNA2 MIMG instructions:image_bvh_intersect_ray(opcode0x0e6)image_bvh64_intersect_ray(opcode0x0e7)In upstream
crates/victory-shader/src/emit/lower.rs:image(), these instructions had no lowering match arm and reached_ => return Err(name), failing translation withShaderError::Unsupportedand dropping over 40-77 compute pipelines per frame.Solution
This branch implements an emulation pass for
image_bvh_intersect_rayandimage_bvh64_intersect_rayas a clean miss termination:Fallback as Miss:
crates/victory-shader/src/gfx10/fields.rs: Ensureimage_bvh*allocate 4 dwords for destination vectorvdata.crates/victory-shader/src/emit/lower.rs:image(): Interceptimage_bvh*at the top ofimage(), writing0to all 4 destination VGPRs under the active lane guard.vdata[0] == 0represents a zero child hit mask. The console's traversal loop interprets this as "no bounding box or triangle intersected", cleanly terminating traversal:rtdirectionalshadows): no occluder hit -> surfaces are evaluated as unoccluded/lit (shadow = 1.0).CS_RaytracingResolve): no geometry hit -> falls back to probe/skybox radiance.Descriptor Mapping:
crates/victory-shader/src/emit/lower.rs:descriptor_data(): Treatimage_bvh*descriptors as raw buffer views (kind 11) rather than typed textures, bypassing texture dimension queries on BVH buffers.Verification
crates/victory-shader/src/emit/lower.rs:image_bvh_intersect_ray_lowers_as_missimage_bvh64_intersect_ray_lowers_as_misscargo test -p victory-shader --lib emit::lower: 13 passed, 0 failed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings).cargo xtask policy: 154 files ok.Branch:
feat/bvh-raytracing-fallback(commitda8761c).@luisaugustz on GitHub · 2026-11-24 19:04 UTC · original
A data point from a different stack, to scope this.
Stack: r4tedx
integration/testers(92bc27b) + #638 + #302/#489/#710 + #876, on an RX 9070 XT. There,victory translate --validate --listovershaders.rpfshows no program failing onimage_bvh_intersect_ray/image_bvh64_intersect_ray.I ported this change onto that stack (the two lowering pieces plus the
fields.rsdword count). Before and after:rtdirectionalshadowstrace programs (CS_RTShadowTrace32*,CS_RTDistantShadowTrace32_Tiled, ...) stop one step earlier, in resource tracking, atan address not from a root parameter.| 48) and then read withs_load_dword, which looks like the BVH header. So they never reach the BVH instructions.CS_RaytracingResolvealready translated on that stack.So on
mainthis may well be the first blocker, as described above. On stacks with more of the shader PRs, these programs also need their memory reads by computed address to work.fxceless/victory-gta6(#1528) appears to address both: a directory from title addresses to host copies for raw-address loads, and a full ray/box and ray/triangle emulation instead of a miss.I've kept this change in our stack; it costs nothing. I'll report whether anything lights once the trace programs get past resource tracking.
AI-assisted (Claude Code): measured offline on this machine.
@Xvania7 on GitHub · 2026-11-24 19:11 UTC · original
@luisaugustz Thanks for measuring that against
shaders.rpf— knowingCS_RaytracingResolvealready translates onintegration/testersand thatCS_RTShadowTrace32*/CS_RTDistantShadowTrace32_Tiledstop earlier on thes_load_dwordBVH header read ((desc << 8) | 48) inresource.rsscopes this cleanly.Two updates on
feat/bvh-raytracing-fallback(now cleanly rebased ontoorigin/mainffe310eata10c287, dropping the unrelated FSPX commits that had been stacked underneath):bvh_miss): Returning all zeros was unsafe for real traversal loops because0is notINVALID_NODE(0xFFFFFFFF) for box nodes and yields0 / 0 = NaNon leaves. Lowering now checksnode_lo & 7dynamically and returns[0x7F80_0000, 0x3F80_0000, 0, 0](+inf, 1.0) for leaf nodes (0..=3) and[0xFFFF_FFFF; 4](INVALID_NODE) for box/internal nodes (4..=7).resource::tracknow tolerates dynamically built/loop-carriedimage_bvh*descriptors without scheduling waterfall checks, anddescriptor_data()resolves descriptors used only byimage_bvh*cleanly to zero without allocating a raw buffer handle.Validated with
dxil.dllon the three synthetic BVH tests (101 passed invictory-shadernon-GPU lib tests,clippyandxtask policyclean). On its own this keeps the lightweight miss path without the runtime cost ofaddress_map, and pairs cleanly if a runtime computed-addresss_load/global_loadsolution (like #1198 /victory-gta6) bringsCS_RTShadowTrace*pastresource::track.@HenriqueSBueno on GitHub · 2026-11-24 19:28 UTC · original
A data point that may help scope this. On our stack (RTX 3080, Series S profile,
main+ #189 #89 #211 #282 #493 #530 #587 + local translator changes for spilled user data, wave-uniformv_readfirstlane, raw root UAVs and descriptor-heap reads as data), no shader reportsimage_bvh*as its first refusal: 430 refusals, led by lane-mask classes ("select on an untracked mask" 77, "lane mask … read as data" 68, "cross-lane op in divergent flow" 60). The translator only logs the first refusal per program, so the lighting programs probably stop on those classes first and would reach the BVH instructions next. That fits @luisaugustz's note thatCS_RTShadowTrace32*stops earlier on the BVH header read.So for a lit frame we expect to need both this change and the lane-mask work (H-6.1–H-6.3 in #1317). In a world-frame target dump on our side, the G-buffer targets hold geometry while every 1280x720 lighting/HDR target (DXGI formats 10, 26, 42, 61) is all zero, the same symptom as the flat RGBA16F buffer here.
AI-assisted (Claude Code)
@Xvania7 on GitHub · 2026-11-25 07:44 UTC · original
Thanks @r4tedx for checking against \
940d32f! Confirmed \main\ now includes full BVH intersection lowering (\␀b35b7f\ / \lower/bvh.rs), so this miss fallback is superseded. Closing in favor of \main\ (and #1883 / #2027 for the remaining register-join validation on the 40 RT programs).