Skip to content

native: carry byte-window formatted loads and typed heap loads to main - #3409

Open
JB2WIN wants to merge 9 commits into
R0Y00:mainfrom
JB2WIN:native/main-typed-heap-port
Open

JB2WIN wants to merge 9 commits into
R0Y00:mainfrom
JB2WIN:native/main-typed-heap-port

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Brings the two cpp-migration features to main: #3034 (formatted loads through a byte-address rewritten descriptor, as RonLogic's #3232) and #3042 (one-channel typed loads through a GPU-selected heap slot). Takes over #3232 under the 2-hour rule (no activity since 12:39 UTC, see the comment there). RonLogic's commits are kept as they are.

This is the first step toward #3063 on main. Its bucket, "direct resource-heap load requires the selected GPU slot and its view type", is the largest in #3224 (330 shaders, 4.67 M dispatches in Leyukaka's 900 s run).

Changes on top of #3232

  • Merge of main 8ecd30f. indirect_table_buffer gained alignment as its sixth parameter on main, so the compute input call passes D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT before true, slot.requires_identity_dst_sel (Leyukaka's point 1 on Carry formatted buffer loads through byte-address windows to main #3232). Every other caller was checked against the new signature. formatted_byte_load uses a byte window the caller already bound (main's graphics path) and otherwise selects byte_window_srv from the zero-stride rewrite.
  • Cherry-pick of native: read one-channel typed loads through a GPU-selected heap descriptor #3042. heap_typed_srv goes after indexed_raw_srv (kinds are serialized by value, so appending keeps existing caches valid). The typed_dword cache identity sits in main's cached_compute_ir. Test section 12 sits next to main's sections 10 and 11.
  • Three negative cases: a typed heap load with offen, an immediate offset or a nonzero soffset is refused by the decoder ("formatted load requires zero or a single linear index"). Doc updated (typed_dword contract, 160 assertions).

Leyukaka's point 2 on #3232 (the pixel-shader MTBUF path has no test) is not covered here.

Tests

Windows 11 26200, RTX 3080 (32.0.16.2124), WARP, dev preset, -j1:

  • ^(native_.*|startup_compute_.*|compute_manifest.*|direct_compute.*)$: all pass except startup_compute_dispatch_output_{warp,hardware} and startup_compute_half_buffer_uav_{controls,hardware}. Those four fail the same way on main without this PR (see shader: lower direct MTBUF packed half stores #3353). WARP wave32 cases skip with 77.
  • native_global_srv_heap_replay_hardware: 160 assertions pass. With the src/, tools/ and fixture changes of the native: read one-channel typed loads through a GPU-selected heap descriptor #3042 commit reverted, it fails at "record typed select 3".
  • startup_compute_mtbuf_window_{controls,hardware} (identity and swapped X/Y, writable alias, CBV token) pass after the merge.

Refs #3232, #3042, #3034, #3023, #3224.

AI-assisted.

🤖 Generated with Claude Code

JB2WIN and others added 8 commits November 28, 2026 08:03
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)
Conflicts resolved:
- indirect_table_buffer: main added `alignment` as the sixth parameter, so the
  compute input call now passes D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT before
  `true, slot.requires_identity_dst_sel` and keeps main's scalar-window fallback.
- formatted_byte_load: a byte window the caller already bound (main's graphics
  path) is used as is; otherwise the zero-stride rewrite selects byte_window_srv.
- native_mtbuf_check.py: main's scalar operand 137 with the byte-window prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00#3042)

Accept the one-channel typed heap-view contract in the direct compute compiler and offline replay. Exercise typed slot selection, cache reuse, and malformed metadata refusals with source-built fixtures.

Refs R0Y00#3023.

(cherry picked from commit a0f6773)
The typed heap load reads the idxen element index only. offen, an immediate
offset and a nonzero soffset are already refused by the decoder ("formatted
load requires zero or a single linear index"); three negative cases pin that.
The doc now lists the typed_dword contract and the current assertion count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SimSalabimse

Copy link
Copy Markdown
Contributor

Hardware test on the Windows test PC (RTX 4070 Ti, Windows 11) at head d4d9af41:

  • cmake --build --preset dev: build exit 0
  • ctest --preset dev -j 1 -R '^(native_.*|startup_compute_.*|compute_manifest.*|direct_compute.*)$' -E 'startup_audio_(output|pacing|provider)': 515/519 passed

The 4 failures are startup_compute_dispatch_output_warp, startup_compute_dispatch_output_hardware, startup_compute_half_buffer_uav_controls and startup_compute_half_buffer_uav_hardware. They are the same ones that fail on main without this PR (#3353). No other failures, timeouts or not-run tests.

AI-Assisted

@JB2WIN

JB2WIN commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that matches my run: the same four failures, which also fail on main without this PR (#3353, fixed by #3389).

AI-assisted.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes at d4d9af41. Read from the diff only, not built here.

Blocking: the in-process path drops the DST_SEL check. translate_compute_natively (src/startup_stubs/d3d12_compute_dispatch.inl, slot loop) accepts byte_window_srv through accepts_cbv_window and pushes the slot without copying view.requires_identity_dst_sel, so record_translated_dispatch calls indirect_table_buffer(..., false). That path is tried before the published manifest. On main this program was refused at translation. With this PR and X2W_NATIVE_SHADERS set, a V# with swapped DST_SEL, a slot 18 SRV with a non-default mapping or a slot 17 CBV token binds without a check (the three checks in d3d12_draw.inl are all gated on that flag). The same drop applies when the pack returns a prepared program, not only on live translation. I could not find what the doc line "The in-process path falls through to that manifest for a byte window" refers to. startup_compute_mtbuf_window_check.py removes X2W_NATIVE_SHADERS, so this path is not tested. Suggested fix: set slots.back().requires_identity_dst_sel = view.requires_identity_dst_sel; and run the swapped case once with the variable set.

One-line mutations the tests do not catch:

  • src/startup_stubs/native_global_srv.h, global_srv_contract: view.dword_channels != 1 -> !view.dword_channels. There is no dword 3 2 case.
  • Same line: removing view.stride != 4 || or !view.bytes || view.bytes % 4 ||. No stride or size negative exists.
  • src/startup_stubs/d3d12_draw.inl: (words[3] & 0xfffu) != 0xfacu -> (words[3] & 0x3fu) != 0x2cu. Only an X/Y swap is tested, and the test load is _xy.

Checked and correct: 0xfac is identity DST_SEL. The decoder refuses typed heap loads with op > 3 (so no d16), offen, an immediate offset or a nonzero soffset. heap_typed_srv is appended last and the cache decode bound covers it. compute_heap_binding includes it, so the pipeline treats it as heap-indexed. The revision hash covers direct_compute_cache.cpp, so cached bindings in the old format do not decode under the new layout. git merge-tree against main 212d4b5f is clean.

Scope: the startup runtime still passes HeapViewContract::none (translate_compute hardcodes it at gfx1013_compute_native.cpp:2048; compile_dxil line 858 for runtime requests). So "direct resource-heap load requires the selected GPU slot and its view type" still refuses every runtime request. typed_dword applies only to compile_dxil with a .views file. In the runtime, the only change is that compute MTBUF loads through a table byte window are no longer refused with "non-contiguous resource descriptor".

The only build file is tests/cmake/startup_compute_mtbuf_window.cmake (add_test only). It is picked up by the existing glob, and CMakeLists.txt is unchanged.

…he contract checks

Review of R0Y00#3409 (Leyukaka):
- translate_compute_natively pushed a byte-window slot without
  requires_identity_dst_sel, so with X2W_NATIVE_SHADERS a swapped DST_SEL, a
  non-default slot 18 mapping or a slot 17 CBV token bound without the check.
  The slot now carries the flag. startup_compute_mtbuf_window runs the identity
  and swapped cases on the in-process route too; without the fix the swapped
  case writes the output.
- A Z/W swap with identity X/Y is refused too (catches a check of the low
  DST_SEL fields only).
- global_srv_contract: a two-channel dword line, stride 8, an odd byte count
  and a zero byte count each refuse on their own.
- Doc: the in-process sentence now says what the code does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JB2WIN added a commit to JB2WIN/Xbox2Windows that referenced this pull request Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all addressed in 30de88b6:

  • In-process DST_SEL: translate_compute_natively now copies requires_identity_dst_sel into the slot. startup_compute_mtbuf_window runs the identity and swapped X/Y cases a second time with X2W_NATIVE_SHADERS and X2W_NATIVE_SHADERS_ONLY set. With that line reverted, the swapped case writes the output (word 0 reads 01234567, not the sentinel). The doc sentence about the in-process route now says what the code does.

  • Mutations:

    • a Z/W swap with identity X/Y (0x0103edec) must refuse on the published route;
    • global_srv_contract gets dword 3 2, stride 8, an odd byte count and a zero byte count as compile refusals.

    I ran each of your four one-line mutations locally, and each now fails its test.

  • Scope: agreed, the runtime still passes no contract, so for a title run this only changes the MTBUF table byte window. The PR body says it is translator side only. cpp-migration: pass captured heap view types into the in-runtime native compute route (#2958) #3023 has the measurement for the runtime side.

native_global_srv_heap_replay_hardware, startup_compute_mtbuf_window_*, native_mtbuf_* and native_direct_container*: 6/6 pass on an RTX 3080 (32.0.16.2124). The WARP wave32 cases skip with 77. #3415 has the same fix merged in (242 assertions on that branch).

AI-assisted.

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.

4 participants