d3d12_xs, tombox-xshader: bind 64-bit GPU-VA global memory through a 64-window TbGlobal table #336
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!336
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-336"
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?
@GDAgent on GitHub · 2026-11-23 20:25 UTC · original
GDAgent:feat/d3d12-tbglobal-windows→main· +1111 −96 · 12 files · 2 commits · openLibrary / area:
d3d12_xs(global_bind.rs,device_wrap.rs,gpu_va.rs,cmdlist_x.rs),tombox-xshader(global_abi.rs,hlsl/global.rs,hlsl.rs)Exports changed (exports.txt rows): none
Builds on #283 (
gpu_vaforgets destroyed resources). The window table is filled from thegpu_vabuffer map, so without #283 a destroyed buffer can end up in a descriptor (that is the crash #283 fixes). This branch is stacked on #283's commit; review only the second commit (git diff 71cec92..); I will rebase ontomainonce #283 lands.Source of the behaviour: RDNA2 flat/global memory instructions and the BVH intersect instructions address memory by 64-bit GPU VA. The console runtime relies on that; the PC runtime has no such addressing. Seen with the console xdxr runtime (compute shader
07edd3df1713c3c0, seedocs/BLOCKERS.md) and with the ray-tracing state objects of The Matrix Awakens (Xbox Series X build), native Windows 11 on an RDNA2 GPU (gfx1032); not run under Proton.What
Until now such shaders were refused (
global_bind::refusal: "d3d12_xs does not bind yet"). With this change they can run whenTOMBOX_GLOBAL_BIND=1is set; without it nothing changes (same refusal, no heap growth, no root-signature change). The translator already emitted aTbGlobalwindow table (space4000003, 2 windows), but nothing created the table or filled it.tombox-xshader:TbGlobalhas 64 windows. One descriptor table (1 root DWORD):CBV(b0)with the window base/size/writable flag, 64 raw SRVs (t0..t63, read-only buffers), 64 raw UAVs (u0..u63, buffers created withALLOW_UNORDERED_ACCESS) and the fault record (u64). A read uses the SRV when the window is not writable, so upload and read-only buffers work without a UAV; stores to a read-only window are counted as faults.tb_msin.z) instead of a fixed unrolled pair, and indexes the arrays withNonUniformResourceIndexon SM 6+.image_bvh*_intersect_rayreads the BVH throughTbGlobaland no longer also needs the separateTbGmemwindow (needs_gmemis false then). The traversal code is unchanged; only its loads go throughtb_bvh_load1/3/4. A BVH-only shader keeps theTbGmempath byte for byte.d3d12_xs:global_bindappends the table to every non-local root signature that has a spare root DWORD (re-serialized through the host serializer), grows every shader-visibleCBV_SRV_UAVheap by a ring of 8 tables (1040 descriptors) so the table lives in the heap the title already set, and onSetComputeRootSignature/SetGraphicsRootSignaturewrites the window CBV and descriptors for up to 64 buffers from thegpu_vamap (UAV-capable buffers first, then read-only ones, address order within each group) and binds the table. All of this is opt-in: it runs only whenTOMBOX_GLOBAL_BINDis set to a value other than0.gpu_varemembers which buffers allow UAV access and exposes a snapshot of the tracked buffers.CreateRootSignaturehook (GDS parameter, TbGlobal table, centroid binding, console part stripping) was only installed together with the descriptor-trace hooks (TOMBOX_RTCAP), so in a normal run no root signature got the table and compute PSOs that read global memory failed withE_INVALIDARG("CBV b0 in space 4000003 not bound by the root signature"). The hook is now installed on its own when TbGlobal binding is on (and, as before, withTOMBOX_RTCAPor the pass-capture tables); the descriptor-trace hooks stay behindTOMBOX_RTCAP. With the switch off, the hook is installed exactly when it was before.DATA_VOLATILE | DATA_STATIC_WHILE_SET_AT_EXECUTE), so the patch silently fell back to the unpatched blob. The ranges are nowDESCRIPTORS_VOLATILE | DATA_VOLATILEand the serializer's message is logged on failure.Limits (by design in this change)
u32::MAXbytes of a buffer.Tests
cargo test -p tombox-xshader --test opcodes bvh: 1 passedcargo test -p tombox-xshader --lib global_abi: 1 passedcargo test -p tombox-xshader --test exec exec_mem::global(WARP andTOMBOX_EXEC_HW=1): 4 passed on WARP and 4 passed on the RDNA2 GPU. They run a shader against a window table with one read-only SRV window, one writable UAV window and the fault record (63 further windows are null descriptors), including a store into the read-only window that must fault and leave its data unchanged, route flat/global/scratch instructions and check narrow loads at the end of a window. The tests were updated for the 64-window table and the SRV/UAV split.cargo test -p tombox-xshader --test exec exec_mem::bvh(WARP andTOMBOX_EXEC_HW=1): 1 passed on WARP and 1 passed on the RDNA2 GPU. Unchanged tests; they check that the BVH-only path still gives the same results after the helper was split.opcodestest: a shader with a flat load andimage_bvh64_intersect_raytranslates withneeds_globaland withoutneeds_gmem, and reads the BVH throughtb_gmem_load.d3d12_xsunit tests (global_bind): the append plan uses 1 root DWORD and respects the DWORD limit and local root signatures, the ranges use valid volatile flags, patching goes through the host serializer (round trip), heap growth only touches shader-visibleCBV_SRV_UAVheaps, window selection puts explicit windows first, then UAV-capable, then read-only buffers, without duplicates, and the switch is opt-in (unset, empty and0are off). 7 passed (and the 10gpu_vatests from #283 pass with the extra field).TOMBOX_REMOVED_EXIT_MS=off cargo test -p d3d12_xs --lib -- --test-threads=1: 672 passed, 4 failed, 71 ignored. The 4 failures are the ones that fail onmainhere too:alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement,placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap,title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes,xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs(needs the console DLL).dred::tests::report_is_one_shot_and_needs_an_armed_devicepasses when run withoutTOMBOX_REMOVED_EXIT_MS.Not verified
Not verified in a title. The Matrix Awakens was run with this table on (with a local test branch that contained this change plus an unsubmitted ray-tracing runtime: root signatures were patched and the backing buffers and heap ring were created without a device error), but those runs never got as far as a dispatch that reads global memory, so no title shader has read data through a window yet.
The xdxr device tests need console DLLs and were not run, so it is not known whether
07edd3df1713c3c0and its siblings now run.Opt-in on purpose: with
TOMBOX_GLOBAL_BIND=1every shader-visible heap grows by 1040 descriptors and every non-local root signature with a spare DWORD gets one more root parameter, in every title, and the real-device root-signature hook (which also applies the GDS and centroid patches) is installed withoutTOMBOX_RTCAP. No title run compared that before and after, so it should become the default only once a title confirms it.The unit tests run with the switch forced on (
enabled()is true undercfg(test)); the off path is covered by the parse test and by the unchanged refusal.The fault record is written but not read.
Tests pass
No game or console files and no binaries included
No fake success; anything not possible is left
missingwith a note@omonkeyz on GitHub · 2026-11-25 13:51 UTC · original
Thanks for the large piece of work. Two problems block it: (1) the TbGlobal tables and window CBs are written on the CPU at record time into a global ring of 8 with volatile descriptors and no fence, so any list with more than 8 root-signature binds before it executes overwrites data earlier commands still read on the GPU; each bind needs its own slots until the list's fence completes (per-list linear allocation, recycled on completion). (2) In bind_now, the branch that skips binding when the title heap lacks the tail returns false only while once(8) is true; afterwards it binds a GPU handle from the unbound fallback heap. Please also drop
71cec92(already on main as #283) and the inline comments.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.