Skip to content

Carry formatted buffer loads through byte-address windows to main - #3232

Open
RonLogic wants to merge 5 commits into
R0Y00:mainfrom
RonLogic:shader/main-mtbuf-byte-window
Open

RonLogic wants to merge 5 commits into
R0Y00:mainfrom
RonLogic:shader/main-mtbuf-byte-window

Conversation

@RonLogic

Copy link
Copy Markdown
Contributor

Change

Carries JB2WIN’s merged #3034 from cpp-migration to main, preserving the original author and commit reference. Refs #3023 and #3063.

The direct Compute frontend uses the byte-window SRV for an MTBUF load through a rewritten buffer descriptor. The current main heap replay generator runs the existing raw cases and the new formatted-load cases. This is the first prerequisite for the typed-heap carry from #3042.

Verification

Tested 6fb2316c over 7fcde81f on Windows 11 build 26300.10075, DXC 1.9.2602.17, RTX 4070 driver 32.0.16.2124 and WARP.

cmake --build --preset release --target compile_dxil native_store_replay native_global_srv_heap_replay
ctest --preset release --no-tests=error -R '^(native_mtbuf_hardware|native_global_srv_heap_replay_(hardware|warp)|native_direct_container)$' -V
  • Stock Debug and Release each had three passes and one in-box WARP wave32 skip, with zero failures.
  • The same four entries passed in Release with Agility 1.620.2 and WARP 1.0.22.
  • The table fixture matched all 54 result words and the guards. Heap slots 0 and 1 matched distinct readbacks, and deliberately using slot 1 as slot 0’s reference failed at word 0.
  • The new container fixture reproduces non-contiguous resource descriptor on clean main at 7fcde81f. On this branch the complete window compiles and the missing byte-count control still refuses.
  • The branch merges cleanly against current main b1e92256, native: bind a single directly indexed heap flag as a descriptor table #3221 and Compute descriptor stride SCC from bound buffer metadata #3227. The docs link check passed.

Evidence

The MIT-licensed, source-built fixtures and their limitations are documented in the heap replay experiment. The changes cover compiler and replay behavior. The live heap contract is tracked in #3023.

I used Codex to prepare the carry and ran verification locally.

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

I independently reproduced this at 6fb2316 merged over main 86beae9 (tree 93bdcd0f1f75b9a201b16f9d6bc1fdf4673773e5). Debug and Release /O2 each gave three passes (MTBUF, direct container, RTX 4060 Laptop heap replay) and one inbox WARP wave32 capability skip (77). Windows 11 26200.9974, NVIDIA driver 32.0.16.1656, WARP 10.0.26100.9818.

The remaining gap is the ordinary table manifest route. The new lowering accepts an MTBUF byte window without proving its DST_SEL, emits a generic srv buf table line for it, and the runtime reads and bounds that view without checking the identity contract described by the new documentation. The replay inputs all use identity. Please make the boundary explicit in code. Either keep this carry on the explicit offline replay route, or check the required identity before the runtime uses the generated table manifest and add a source-built table dispatch with a non-identity refusal/control. The existing byte-count and cross-slot controls should stay.

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^(native_mtbuf_hardware|native_global_srv_heap_replay_(hardware|warp)|native_direct_container)$'

Copy link
Copy Markdown

The data-path distinction in shadPS4 #5753 would make a good extra reference test for this port: use two SRV views selected by opposite branches, one raw and one formatted, and check the same underlying dword across the selection. That separates typed conversion from byte-window selection without requiring either implementation to use the other's code.

formatted_byte_load asked resource() for raw_vector_srv even when the
descriptor was the byte-address rewrite (stride cleared in word 1), so a
tbuffer_load_format_* through such a window was refused with
"non-contiguous resource descriptor", for a table descriptor and for a
GPU-selected heap descriptor under the raw_buffer contract. It now picks
byte_window_srv by the same rule as the raw MUBUF load. Conversion, the
getDimensions element bound and the raw loads are unchanged.

Tests:
- native_global_srv_heap_replay_check.py: a 32_UINT tbuffer load through
  the heap window is recorded, compiled and replayed for selections 0
  and 1, with the cross-slot mismatch control; the loop guard refuses
  it; an 8_8_8_8_UNORM load through the window compiles.
- native_mtbuf_check.py: the 11-format value check also runs through a
  byte window of its table SRV (native_store_replay accepts the window
  binding as the same raw view).
- native_direct_container_check.py: compute table windows with both
  formats compile; without the byte-count product they are refused.

Refs R0Y00#3023

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e67f101)
@RonLogic
RonLogic force-pushed the shader/main-mtbuf-byte-window branch from 6fb2316 to 587fc6d Compare November 28, 2026 06:07

Copy link
Copy Markdown
Contributor Author

Rebased to 587fc6d2 on main 9e32722b. The only conflict was in the heap experiment note. Both the original #3034 measurements and the newer offset-add measurements are retained, and JB2WIN remains the patch author.

I rebuilt offscreen_check, native_store_replay, native_global_srv_heap_replay, and compile_dxil in all three configurations. The affected CTest selection included both heap replay adapters, MTBUF, direct containers, and native_heap_offset_add. Stock Debug and Release each had four passes and the expected in-box WARP wave32 skip. Full Agility 1.620.2 plus app-local WARP 1.0.22 passed 5/5. The table replay checked all 54 words and guards, and the heap replay retained both the cross-slot mismatch control and the new offset-add cases. The tested commit merged cleanly into newer main 6a1968a1.

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

I checked the rebased diff at 587fc6d2. It still lowers a zero-stride MTBUF source as byte_window_srv, and the published srv buf table route reaches indirect_table_buffer, which sizes the range from words 0–2 without checking DST_SEL in word 3. No runtime binding or manifest discriminator was added in the rebase. The prior request about the ordinary table route still applies. The offline and identity-fixture results are useful and can be retained in either approach.

Copy link
Copy Markdown
Contributor Author

Addressed the published table-route finding in 80952189. The MTBUF byte-window binding now carries its identity requirement through cache serialization and emits srv 0 buf table 1 0 identity_dst_sel. Dispatch checks the hardware descriptor's DST_SEL or the buffer SRV token's D3D12 component mapping before binding its raw range.

I reproduced the original issue at 587fc6d2: the old generic manifest recorded a Dispatch with swapped X/Y selectors on both RTX 4070 and WARP 1.0.22, and the readback still had the identity order. The new fixture compares all 320 words through the ordinary slot 67/14 route. Five complete pairs match, the partial pair at the 44-byte edge and six later pairs return zero, and all guards match. Both the hardware descriptor and SRV token pass with identity and refuse with swapped X/Y before writing output. Cold and warm manifests match.

cmake --build <build> --target offscreen_check compile_dxil native_store_replay native_global_srv_heap_replay startup_stream_consumer d3d12_xs_shim
ctest --test-dir <build> --no-tests=error -R '^(startup_compute_(mtbuf_window|dispatch_(entry|input))_(warp|hardware)|native_(mtbuf_hardware|direct_container|global_srv_heap_replay_(warp|hardware)|heap_offset_add))$' -j 2 -V

Stock Debug and Release each had nine passes and two in-box WARP wave32 capability skips. Agility 1.620.2 with app-local WARP 1.0.22 passed 11/11. The original 54-word, byte-count and cross-slot controls are included.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the quick follow-up. I did a static review of 80952189 (no build, Wine or GPU run). It looks mergeable with the notes below, but it still needs R0Y00's re-review: the latest review is the COMMENTED one on 587fc6d2, and reviewDecision is still CHANGES_REQUESTED.

  • The requested table-route change is in. There is an identity_dst_sel manifest marker, and a runtime check runs before binding: (words[3] & 0xfffu) != 0xfacu for the hardware descriptor and Shader4ComponentMapping != D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING for the slot 18 token. startup_compute_mtbuf_window_check.py refuses swapped X/Y for both forms (SWAPPED_XY = 0x0103efa5, mapping='swapped'). The byte-count and cross-slot controls are still there.
  • Merge: git merge-tree --write-tree c3204a9c 80952189 gives rc=0. The 8 newer commits on main touch 6 of the same files, and I found no interaction. No positional initializer shifts.
  • CI passes, but ctest --preset pr ran 73 tests. grep -c on the Windows log returns 0 for native_mtbuf, native_global_srv_heap, native_direct_container and startup_compute_mtbuf_window, so only local Windows runs cover the affected tests.
  • No new DXIL op: getDimensions 72 and rawBufferLoad 139 are reused. DST_SEL 0xfac/0xfa5 and the default mapping 0x1688 check out. docs_links_check.py on the merged tree prints Checked 148 Markdown files and 671 links.

SHOULD

  1. Two new refusals have no test. git grep -F over tests/ finds neither "a writable MTBUF byte window has no verified view contract" nor "an MTBUF byte window requires a buffer SRV". If the first were removed, the binding would become raw_buffer_uav, whose manifest line has no marker, and the suite would stay green. Two cases would cover them: a compile-only refusal in native_direct_container_check.py, and a CBV-token (slot 17) run in startup_compute_mtbuf_window_check.py.

NIT
2. Pre-existing: an MTBUF load outside a byte window binds as raw_vector_srv with no DST_SEL check, yet the header comment edited in gfx1013_compute_mtbuf.inl says "Only the runtime-checked identity raw SRV is used". Either reword it or pass the flag for every MTBUF resource.
3. native-global-srv-heap-replay.md: after the new table-route bullets, the next bullet still ends with "none of this reaches a title run (#3023)". That should be limited to the heap route.
4. The PR body still says it was tested on 6fb2316c and doesn't mention the runtime/manifest change. It should be updated before a squash merge.

This comment was AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the work here. This branch no longer merges with current main (c6f23813): git merge-tree --write-tree origin/main 80952189 exits 1 with a conflict in src/direct_compute_cache.cpp.

Could you merge or rebase current main into the branch, resolve that conflict, and re-run the tests this PR adds, so reviewers can look at the refreshed head?

This comment was AI-assisted.

Copy link
Copy Markdown
Contributor Author

Thanks for pointing out the two gaps in the test coverage. Both controls are now in 5399a2d8, tested at the refreshed head 1b3ee66181c59ea4c8cbfa7f4b4cf3ef15175f6b on main 052abe6f.

  • A source-built request aliases the MTBUF byte-window read and raw store to the same table record. It refuses with a writable MTBUF byte window has no verified view contract before producing either DXIL or a manifest. The older 587fc6d2 hit a later, generic non-contiguous resource descriptor refusal on this fixture.
  • A real slot-17 CBV token in the same published table refuses with an MTBUF byte window requires a buffer SRV and preserves all 320 guard words on RTX 4070 and WARP. Dropping just identity_dst_sel from the generated manifest let the same view dispatch on both adapters and change the first 24 words.

The original identity, swapped X/Y, byte-count and selected-heap cases still pass. Debug and Release each passed 12/12 with Agility 1.620.2 and app-local WARP 1.0.22 on Windows 26300.10075. The RTX 4070 used driver 32.0.16.2124. The refreshed branch merges cleanly with main and #3305.

cmake --build <build> --target offscreen_check compile_dxil native_store_replay native_global_srv_heap_replay startup_stream_consumer d3d12_xs_shim
ctest --test-dir <build> --no-tests=error -j 1 -V -R '^(startup_compute_(mtbuf_window_(controls|warp|hardware)|dispatch_(entry|input)_(warp|hardware))|native_(mtbuf_hardware|direct_container|global_srv_heap_replay_(warp|hardware)|heap_offset_add))$'

@R0Y00 the published route now has controls for both additional cases and is ready for another review. I used Codex to prepare the tests and ran the verification locally.

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.

5 participants