startup: opt-in alias binding for table buffer views over aliased placed buffers #2977
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2977"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-27T01:02:11Z.
Change
Fixes #2976 (a 16 MiB table buffer copy is compared in full on every draw under
draw_lock). Refs #2724, #2834.X2W_D3D12_TABLE_ALIAS=1(opt-in, render mode): indraw_translated, a table buffer view whose whole range lies in a slot 133 placed buffer that aliases title memory binds that alias, as vertex streams and live indices already do, instead of a per-drawframe_copy. Unset, every table buffer view is copied as onmain.d3d12_draw.inl, view loop,source 0, not a formatted load, range ≤ 512 MiB:placed_buffer_rangeover the range before the 16 MiB copy cap; for one livealiased_bufferplacement and a 16-byte-aligned offset:retain_with_recording,require_state(non-pixel and pixel shader resource), raw view over the full range, counted as a bound buffer. Anything else keeps the copy.frame copy ... refreshed).docs/startup-runtime.md;docs/experiments/startup-table-srv-alias.md.Verification
Windows 10 22H2, i7-4790K, RTX 3080 Ti (NVIDIA 32.0.16.1047) and WARP; dev and release; commit
4982e169on6ee878d8.16 tests per preset (
startup_{stream_draw,formatted_view_draw,address_buffer_srv,copied_vertex_srv,table_alias,direct_index_late_write,frame_copy,placed_vertex}_{warp,hardware}), each run with the switch unset and withX2W_D3D12_TABLE_ALIAS=1in the environment: 16/16 in all four runs.startup_table_alias_{warp,hardware}(X2W_TEST_TABLE_ALIAS_WRITE): a 256-byte slot 133 buffer onVirtualAllocmemory, a slot 18 raw view at table entry 0. The title writes 40, draws the left half, writes 80, draws the right half, and writes 120 after recording.0: left 40, right 80 (copies). Switch1: both 120 (alias, read at execution). Both pass on WARP and hardware.0, so it keeps testing the default when the switch is set in the environment.startup_*tests, release,-j 4, on a local build of this change plus local measurement code, with the switch unset and withX2W_D3D12_TABLE_ALIAS=1in the environment: identical results except the new fixture (its copy arm then inherited the switch; fixed by clearing it, above).main6ee878d8on this host, with and without the switch, so they are not from this change:startup_audio_timeline_cli_check,startup_list_resubmit_nodebug{,_untracked}_hardware(SegFault),startup_image_get_lod_view_warp,startup_image_load_d16_warp,startup_gfx2hlsl_f16_alu_draw_warp,startup_gfx2hlsl_f32_sdwa_warp,startup_compute_dispatch_texture_warp,startup_d16_srv_warp,startup_pixel_uav_{warp,hardware},startup_compute_dispatch_array{,_d16}_warp,startup_gfx2hlsl_pixel_first_lane_warp,startup_gfx2hlsl_wave_reduce_warp.X2W_D3D12_RING_RELEASE_AT_SUBMIT=1), only this switch differs, two pairs in opposite order (250 s, warm cache, scripted input):buffertoken)Checklist
docs/startup-runtime.md, experiment note)AI-assisted: the change, tests and this description were written with Claude; I ran the startup comparison.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-27T01:25:39Z.
I found three cases to cover before merging. A shared index and table buffer needs both read-state flags at the draw. The alias range also needs to cover the rounded raw SRV, and the fixture should skip when existing heaps are unavailable. Ready for more review
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-27T04:11:27Z.
Thanks @Jess-Doit, all three were real. Fixed in
2730ac9a(after mergingmainfb955a51).startup_table_alias_*)INDEX_BUFFERplus both shader-resource statesshared-index: one placement holds indices 0–2 and the record; debug layer + GPU-based validation, expects 0 errors and the drawn valueodd-size: 254-byte placement, 127 × 2-byte structured view; must take the copy0x887a0001) under the debug layerD3D12_FEATURE_EXISTING_HEAPSfirst and returns 77X2W_TEST_GPU_VALIDATION=1(withX2W_TEST_DEBUG_LAYER=1). The plain debug layer does not check descriptor-table resource states: without it, the old code passesshared-index.ID3D12InfoQueuestored messages; theID3D12InfoQueue1callback is not available on Windows 10 19045.Tests on
2730ac9a, Windows 10 19045, RTX 3080 Ti (driver 32.0.16.1047) + WARP, debug layer off except in the two new cases:X2W_D3D12_TABLE_ALIASunset=1Startup retest with the fixes, two more off/on pairs (second reversed), same settings as before; added to
docs/experiments/startup-table-srv-alias.md:=1draw_lockwaits 1.0–1.5 → 0.08–0.14 threads; no copy above 64 KiB with the switch.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T04:22:22Z.
Review: COMMENTED
This PR implements excellent opt-in aliasing for table buffer views — a carefully scoped, well-tested perf optimization that matches console semantics.
What works
index_read_as_tableflag correctly handles the case where the same aliased buffer serves as both live index buffer and table SRV; the dual-state requirement propagates to the index-buffer path so neither binding leaves the other in a wrong state.startup_table_alias_check.pyfixture is a strong positive test: write-draw-write-draw-write recording pattern clearly distinguishes copy (first two values) from alias (third value). The negative control (buffer in image memory, placed "not aliased") is exactly the right kind of failure case.placed_buffer_rangelookup are all consistent with existing vertex/index aliasing logic.startup-runtime.mdentry, table-row toggle description, and the experiment note with real perf data (fps up ~30-50%, draw_lock waits down ~10x).Issues
512 MiB cap rationale — The
raw_bytes <= (512u << 20)cap prevents very large placement lookups. Consider adding an inline comment explaining this is performance protection against theoretically large views.require_statefor both shader-resource states — The raw view adds bothNON_PIXEL_SHADER_RESOURCE | PIXEL_SHADER_RESOURCE. Fine in practice (likely already in one of these states) but could add unnecessary transitions for pixel-only shaders. Low impact.Rounded range past placement — The doc says a view whose rounded range runs past the placement keeps the copy. The lookup uses
raw_bytesalready, soplaced_buffer_rangewould showreject=trueif it runs past. Correct but not explicit in inline comments.X2W_TEST_GPU_VALIDATIONpath — Theshared-indextest needsX2W_TEST_DEBUG_LAYER=1set. The fixture doesn't auto-enable it, which is correct (it reports if active). Worth keeping in mind when the test is run.Recommendations
X2W_D3D12_TABLE_ALIAS=1is active, similar toX2W_D3D12_VIEW_CENSUSheartbeat, so users know aliasing mode is on.Overall: strong PR. The opt-in default, thorough testing with negative controls, and real startup perf data make this a well-executed change.
Reviewed with ❤️
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T04:32:51Z.
Review: APPROVED
Reviewed
2730ac9aded12d2aa4e5b44db80d3e3d11d0f99c. The shared index/table alias retains index and both shader-read states, and alias admission covers the rounded raw view with the normal copy path available on decline. On Windows 11 build 26200.9974 I builtstartup_stream_consumer d3d12_xs_shimwith the Release preset and ranctest --preset release --no-tests=error --output-on-failure -R '^startup_(table_alias|frame_copy|address_buffer_srv|direct_index_late_write|stream_draw)_(warp|hardware)$'. All ten fixtures passed on WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656). The table-alias debug-layer checks reported zero errors. This review verifies source-built fixtures; the original-executable performance run was reported by the author. Required Windows CI passed.