Repository navigation
startup: opt-in alias binding for table buffer views over aliased placed buffers - #2977
Conversation
…ced buffers
X2W_D3D12_TABLE_ALIAS=1 makes a translated draw bind the alias of a slot 133
placed buffer that aliases title memory for a table buffer view whose whole
range lies in it, as vertex streams and live indices already do, instead of a
per-draw frame copy. The GPU then reads the bytes at execution, not as they
were when the draw was recorded, and the view is not cut at 16 MiB. Unset,
every table buffer view is copied as before.
- d3d12_draw.inl: placement lookup over the uncut range for source 0 views
that are not formatted loads (at most 512 MiB, 16-byte aligned); the alias is
retained with the recording and put in the shader-resource states.
- Tests: new startup_table_alias_{warp,hardware} (X2W_TEST_TABLE_ALIAS_WRITE):
copy arm 40 | 80 with the switch cleared, alias arm 120 | 120.
- Docs: paragraph and switch row in docs/startup-runtime.md, experiment note
docs/experiments/startup-table-srv-alias.md.
Refs R0Y00#2724, R0Y00#2834.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 |
Review of R0Y00#2977: - when the table alias is also the draw's live index buffer, both bindings require INDEX_BUFFER plus the shader-resource states; - the placement lookup uses the range rounded up to whole DWORDs, the size the raw view covers; - the fixture skips (77) without existing heaps. startup_table_alias gains shared-index (debug layer + GPU-based validation, X2W_TEST_GPU_VALIDATION) and odd-size cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @Jess-Doit, all three were real. Fixed in
Tests on
Startup retest with the fixes, two more off/on pairs (second reversed), same settings as before; added to
|
KelboLive
left a comment
There was a problem hiding this comment.
This PR implements excellent opt-in aliasing for table buffer views — a carefully scoped, well-tested perf optimization that matches console semantics.
What works
- Clean, minimal diff (376/-1) with a single environment variable toggle.
- The
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.- The 512 MiB cap, 16 MiB copy cap parity, and
placed_buffer_rangelookup are all consistent with existing vertex/index aliasing logic. - Docs are thorough:
startup-runtime.mdentry, table-row toggle description, and the experiment note with real perf data (fps up ~30-50%, draw_lock waits down ~10x). - The opt-in nature is well-motivated: console behavior (GPU reads at execution time) vs safety (earlier draws in a list see updated values when the title rewrites within a frame). This is the right risk-reward assessment.
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
- Add inline comment near 512 MiB cap explaining the rationale.
- Consider a one-time warning log when
X2W_D3D12_TABLE_ALIAS=1is active, similar toX2W_D3D12_VIEW_CENSUSheartbeat, so users know aliasing mode is on. - Consider noting in the doc the specific behavior when the title rewrites mid-frame (alias makes earlier draws see the new value, matching console semantics).
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 ❤️
R0Y00
left a comment
There was a problem hiding this comment.
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 built startup_stream_consumer d3d12_xs_shim with the Release preset and ran ctest --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.
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