Skip to content

startup: opt-in alias binding for table buffer views over aliased placed buffers - #2977

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
lukaslw-lab:runtime/table-srv-alias
Nov 27, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
lukaslw-lab:runtime/table-srv-alias

Conversation

@lukaslw-lab

Copy link
Copy Markdown
Contributor

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): in draw_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-draw frame_copy. Unset, every table buffer view is copied as on main.

Verification

Windows 10 22H2, i7-4790K, RTX 3080 Ti (NVIDIA 32.0.16.1047) and WARP; dev and release; commit 4982e169 on 6ee878d8.

ctest --preset release --no-tests=error -j 1 -R '^(startup_table_alias_.*|startup_frame_copy_.*|startup_copied_vertex_srv_.*|startup_address_buffer_srv_.*|startup_stream_draw_.*|startup_placed_vertex_.*|startup_direct_index_late_write_.*|startup_formatted_view.*)$'
ctest --preset dev     --no-tests=error -j 1 -R '^(startup_table_alias_.*|startup_frame_copy_.*|startup_copied_vertex_srv_.*|startup_address_buffer_srv_.*|startup_stream_draw_.*|startup_placed_vertex_.*|startup_direct_index_late_write_.*|startup_formatted_view.*)$'

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 with X2W_D3D12_TABLE_ALIAS=1 in the environment: 16/16 in all four runs.

  • New startup_table_alias_{warp,hardware} (X2W_TEST_TABLE_ALIAS_WRITE): a 256-byte slot 133 buffer on VirtualAlloc memory, 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.
    • Switch 0: left 40, right 80 (copies). Switch 1: both 120 (alias, read at execution). Both pass on WARP and hardware.
    • Negative control: the same buffer in image memory is placed "not aliased"; the switch-on arm then reads 40 | 80 and fails.
    • The copy arm sets the switch to 0, so it keeps testing the default when the switch is set in the environment.
  • All 1,159 startup_* tests, release, -j 4, on a local build of this change plus local measurement code, with the switch unset and with X2W_D3D12_TABLE_ALIAS=1 in the environment: identical results except the new fixture (its copy arm then inherited the switch; fixed by clearing it, above).
    • 15 tests fail the same way on unmodified main 6ee878d8 on 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.
  • Startup run of the main executable, one build (on top of startup: opt-in release of upload ring chunks at a fenced submit #2949, X2W_D3D12_RING_RELEASE_AT_SUBMIT=1), only this switch differs, two pairs in opposite order (250 s, warm cache, scripted input):
fps, 30 s windows 150–180 s 180–210 s 210–240 s
unset, pair 1 / pair 2 8.9 / 8.6 5.1 / 7.8 3.7 / 4.2
set, pair 1 / pair 2 11.5 / 9.8 8.0 / 11.2 6.6 / 6.1
per run, pair 1 / pair 2 unset set
Translated draws 64,296 / 88,027 97,419 / 100,254
Null bindings, cause buffer 0 / 0 0 / 0
Null bindings per 1,000 load draws (cause token) 53.8 / 46.5 54.0 / 50.8
Process commit peak 18.1 / 17.1 GiB 17.9 / 18.1 GiB
Device removal none none
Visible — no difference seen

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (docs/startup-runtime.md, experiment note)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: the change, tests and this description were written with Claude; I ran the startup comparison.

🤖 Generated with Claude Code

…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>
@Jess-Doit

Copy link
Copy Markdown
Contributor

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

lukaslw-lab and others added 2 commits November 27, 2026 04:31
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>
@lukaslw-lab

Copy link
Copy Markdown
Contributor Author

Thanks @Jess-Doit, all three were real. Fixed in 2730ac9a (after merging main fb955a51).

Case Change Fixture (startup_table_alias_*) Old code
Shared index and table buffer When the table alias is also the draw's live index buffer, both bindings require INDEX_BUFFER plus both shader-resource states shared-index: one placement holds indices 0–2 and the record; debug layer + GPU-based validation, expects 0 errors and the drawn value GPU-based validation ID 942 "Incompatible resource state … Binding Type In Descriptor: SRV" (WARP and RTX 3080 Ti)
Rounded raw SRV The lookup uses the range rounded up to 4 bytes, the size the raw view covers odd-size: 254-byte placement, 127 × 2-byte structured view; must take the copy Device removed (0x887a0001) under the debug layer
No existing heaps The fixture checks D3D12_FEATURE_EXISTING_HEAPS first and returns 77 all cases returned 47
  • New consumer switch X2W_TEST_GPU_VALIDATION=1 (with X2W_TEST_DEBUG_LAYER=1). The plain debug layer does not check descriptor-table resource states: without it, the old code passes shared-index.
  • Errors are read from ID3D12InfoQueue stored messages; the ID3D12InfoQueue1 callback is not available on Windows 10 19045.
  • The default vertex-stream alias path has the same gap when a stream and the live indices share one alias. Not changed here (default behaviour); can follow separately.

Tests on 2730ac9a, Windows 10 19045, RTX 3080 Ti (driver 32.0.16.1047) + WARP, debug layer off except in the two new cases:

ctest --preset P --no-tests=error -j 1 -R '^(startup_table_alias_.*|startup_frame_copy_.*|startup_copied_vertex_srv_.*|startup_address_buffer_srv_.*|startup_stream_draw_.*|startup_placed_vertex_.*|startup_direct_index_late_write_.*|startup_formatted_view.*)$'
preset X2W_D3D12_TABLE_ALIAS unset =1
release 16/16 16/16
dev 16/16 16/16

Startup retest with the fixes, two more off/on pairs (second reversed), same settings as before; added to docs/experiments/startup-table-srv-alias.md:

fps, mean 150–240 s pair 3 pair 4
unset 6.5 5.5
=1 8.8 10.2
  • Translated draws +62 % / +36 %; draw_lock waits 1.0–1.5 → 0.08–0.14 threads; no copy above 64 KiB with the switch.
  • Not-drawn share in the load 47–50 % in all four runs; 0 buffer nulls; no device removal.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_table flag 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.py fixture 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_range lookup are all consistent with existing vertex/index aliasing logic.
  • Docs are thorough: startup-runtime.md entry, 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

  1. 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.

  2. require_state for both shader-resource states — The raw view adds both NON_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.

  3. Rounded range past placement — The doc says a view whose rounded range runs past the placement keeps the copy. The lookup uses raw_bytes already, so placed_buffer_range would show reject=true if it runs past. Correct but not explicit in inline comments.

  4. X2W_TEST_GPU_VALIDATION path — The shared-index test needs X2W_TEST_DEBUG_LAYER=1 set. 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=1 is active, similar to X2W_D3D12_VIEW_CENSUS heartbeat, 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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 50488e1 into R0Y00:main Nov 27, 2026
5 checks passed
@lukaslw-lab
lukaslw-lab deleted the runtime/table-srv-alias branch November 27, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup: a 16 MiB table buffer copy is compared in full on every draw under draw_lock; the late load stalls on it

4 participants