Skip to content

runtime: bind published typed buffer inputs with 32-bit components - #3386

Open
Not-Saii wants to merge 4 commits into
R0Y00:mainfrom
Not-Saii:runtime/typed-buffer-srv
Open

Not-Saii wants to merge 4 commits into
R0Y00:mainfrom
Not-Saii:runtime/typed-buffer-srv

Conversation

@Not-Saii

@Not-Saii Not-Saii commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3224

Behavior

In the #3224 census, SRV kind typed_buffer_srv is the largest gap between compiling a compute program and publishing its manifest. These are programs that read with buffer_load_format_x to _xyzw (MUBUF, element index only), which the direct compiler reads as a Buffer<uint4>.

  • Manifest (src/direct_compute_cache.cpp): format_compute_runtime_manifest writes srv <register> typed table <parameter> <byte> bytes <n>. n is 4 bytes per component of the widest load on that binding; required_bytes is already the maximum over the binding's loads.
  • Stand-in (src/startup_stubs/d3d12_compute_dispatch.inl): the dispatch path resolves the table entry with the existing indirect_table_buffer range rules and binds a UINT buffer view (R32_UINT to R32G32B32A32_UINT) over it. A UINT view returns the same bits as the guest format unit only for 32-bit UINT, SINT and FLOAT components, so only those are bound:
    • Hardware descriptor: FORMAT 20-22, 62-64, 72-74 or 75-77, stride equal to the element size, identity DST_SEL over the components read, unified FORMAT, structured bounds (OOB_SELECT 0), and no swizzle, index stride or ADD_TID.
    • Slot 18 typed buffer view token: reuses JB2WIN's typed_dword_channels / typed_dword_uint_format from the heap contract (native: read one-channel typed loads through a GPU-selected heap descriptor #3042).
    • All four words zero: a null buffer that reads zeros, as raw inputs already do.
  • Every other shape is refused before a dispatch is recorded, with one reason per check (listed in docs/experiments/compute-typed-buffer-inputs.md). A typed input on an indirect Dispatch is refused, and the in-process X2W_NATIVE_SHADERS route is unchanged.

Not in this PR:

Tests

tests/startup_compute_typed_buffer_srv_check.py (tests/cmake/startup_compute_typed_buffer_srv.cmake) uses the published route: compile_dxil --requests → <key>.txt → slot 14 Dispatch on the stand-in.

  • _controls (no GPU): source-built programs for 1 to 4 components publish srv 0 typed table 1 0 bytes 4n.
  • _warp / _hardware: for each width, a 32-bit FLOAT descriptor of 50 elements.
    • The 384 lanes store what they read, so the words past element 49 must be zero.
    • The 4-component case also reads through a slot 18 R32G32B32A32_FLOAT view token (new consumer mode dispatch-srv-token-typed).
    • Each width also reads through its UINT and SINT FORMATs, and through a descriptor based one element into the buffer (new consumer mode dispatch-records32-input-at-<bytes>); the words read shift by one element.
    • Refusal controls, each with the output untouched: an 8_8_8_8_UNORM FORMAT, a wrong stride, word 1 bit 30, OOB_SELECT 3, a legacy (RESOURCE_LEVEL 0) FORMAT, swapped X/Y DST_SEL, fewer channels than read, a base 4 bytes in (2 or more components), and an R8G8B8A8_UNORM token.
    • Before publication the dispatch reports no translation.

Verification

Commits 89fd41b0, 9a414d17, 4a2720e0 and da4fe59c (review cases) on main d418f70e. Windows 11 build 26300, MSVC x64 Debug, Windows SDK 10.0.26100 DXC, D3D12 debug layer enabled.

.\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev --target compile_dxil d3d12_xs_shim startup_stream_consumer offscreen_check
ctest --preset dev --no-tests=error -V -R "^startup_compute_typed_buffer_srv_(controls|warp|hardware)$"
  • _controls: passed.
  • _hardware, NVIDIA GeForce RTX 4090, driver 32.0.16.1088: passed at da4fe59c. 1, 2, 3 and 4 components read 50 elements and then zeros, the UINT and SINT FORMATs read the same words, a base one element in shifts them, the token reads the same elements, and 5, 8, 8 and 9 refusal controls passed. No debug layer errors.
  • Review mutations (Leyukaka's four; the FORMAT one run per row), each applied alone with the shim rebuilt: each fails _hardware. FirstElement → 0 fails at the shifted base, the dropped whole-element check at the 4-byte base, each FORMAT row at its UINT case, and the dropped word 1 bits at the bit 30 stride.
  • _warp, Microsoft Basic Render Driver 10.0.26100.9818: capability skip (77). WARP reports 4-lane waves and the direct module needs 32.
  • Negative control: with the stand-in's parse of the typed line disabled, the manifest is published but not bound, and _hardware fails at word 0 (expected 8b02a7f1, read c5c5c5c5). With the change restored, it passes.

Regressions on the same build, run with -R "^startup_compute_(dispatch|dispatch_input|dispatch_texture|dispatch_native|half_buffer_uav|root_srv_dispatch)_(warp|hardware)$":

  • Passed: startup_compute_dispatch, _dispatch_input, _dispatch_texture and _root_srv_dispatch on WARP and hardware, and _dispatch_native_hardware.
  • Capability skips on WARP: _dispatch_native_warp and _half_buffer_uav_warp.
  • startup_compute_half_buffer_uav_hardware fails, and not because of this change. Its 1-channel D16 store now compiles to packed_d16_x_uav (since 94d2803f), which format_compute_runtime_manifest does not write (no_manifest ... UAV kind unknown). That kind is SimSalabimse's claim on direct compute: untranslated compute shaders of a start-up run ranked by dispatches, with first refusals on main #3224, and this PR changes only the SRV branch. I read this from the code; I did not run that test at main without this change.
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py      # Checked 156 Markdown files and 678 links.
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py   # no bidirectional controls

AI-assisted.

🤖 Generated with Claude Code

Not-Saii and others added 3 commits November 28, 2026 19:51
format_compute_runtime_manifest writes `srv <i> typed table <param>
<byte> bytes <n>` for a typed_buffer_srv (buffer_load_format_*, read as
Buffer<uint4>), n being the widest load. The stand-in resolves the
title's hardware descriptor or slot 18 typed buffer view token as a
buffer range and binds a UINT view of its 32-bit components; every
other shape is refused with a named reason.

Refs R0Y00#3224

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

Copy link
Copy Markdown
Collaborator

Measured 4a2720e0 on the 878 untranslated requests of the 900 s census in #3224: compile_dxil <dxc dir> <cache> --jobs 8 gfx1013-direct-cs@0 --requests <request dir> <out dir>, built in a local integration of main f2972840 with this PR and 17 other open PRs (none of the others changes the manifest's SRV kinds). Baseline: the same requests on main d418f70e. Compile counts are unchanged (290 compiled, 588 refused); runtime manifests go from 124 to 146.

Of the 112 programs that stopped at SRV kind typed_buffer_srv:

Now Programs Dispatches
manifest published 22 163,511
UAV kind typed_buffer_uav 32 2,001,657
SRV kind comparison_texture_srv 2d 33 155,463
UAV kind indexed_atomic_uav 17 122,577
UAV kind unknown 4 18,843
UAV kind half_scalar_uav 4 14,141

No other program changed manifest state. Whether the 22 bind at Dispatch (the 32-bit FORMAT check) is not measured here; that needs a run.

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

Reviewed 4a2720e0.

Run on a release build of main f2972840 with this PR and 17 other open PRs merged locally, Windows Sandbox, network off, vGPU:

  • startup_compute_typed_buffer_srv_controls passes.
  • startup_compute_typed_buffer_srv_hardware passes on the hardware backend (the Sandbox's only GPU is the NVIDIA GeForce RTX 5080 vGPU). It covers 50 elements and then zeros for 1 to 4 components, the slot 18 token, and 4/6/6/7 refusals.
  • _warp skips (77): WARP has no 32-lane wave.

Test gaps. Each mutation below still passes _hardware:

  1. The input view always starts at element 0. In dispatch-records32 the descriptor addresses the first byte of the placed input buffer, and the slot 18 token view has FirstElement 0. Mutation: src/startup_stubs/d3d12_compute_dispatch.inl:160 view.Buffer.FirstElement = range.offset / element -> 0. Add a dispatch whose descriptor base is 4 * channels bytes into the input buffer, and expect the words shifted by one element.
  2. The whole-element check has no case. Mutation: :155 drop range.offset % element ||. Add, for 2 or more channels, a descriptor base 4 bytes into the input buffer. It should be refused with a typed input range does not start at a whole element and leave the output untouched.
  3. Only the FLOAT codes are dispatched (22, 64, 74, 77). Mutation: :111 case 20: case 21: case 22: return 1; -> case 22: return 1; (the same holds for the 62/72/75 rows). Add dispatches with FORMAT 20 (UINT) and 21 (SINT), expecting the same raw words.
  4. No case sets word 1 bit 30 or 31. Mutation: :145 drop (words[1] >> 30) ||. Add stride field 0x4000 | 4 * channels, which sets bit 30 and keeps the 14-bit stride equal to the element size. It should be refused with a typed input descriptor is swizzled or not bounds-checked by record.

Request changes for the test gaps above.

…bits

Review of R0Y00#3386: four mutations of the typed input view still passed.
The hardware check now also reads each width through its UINT and SINT
FORMATs and through a descriptor based one element into the buffer
(new consumer mode dispatch-records32-input-at-<bytes>), and refuses a
base 4 bytes in (2 or more components) and a stride field with bit 30.

Refs R0Y00#3224

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

The gaps the R0Y00#3386 review found in the typed input check exist for the
typed outputs too. Each stored width now also writes through its UINT
and SINT FORMATs and through a descriptor 8 bytes into the output
buffer (shifted for 1 and 2 components, refused as not element-aligned
for 3 and 4), and a stride field with word 1 bit 30 is refused.

Refs R0Y00#3224

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

Copy link
Copy Markdown
Contributor Author

@Leyukaka Thanks. All four gaps were real, and each now has a case that fails under its mutation. Fixed in da4fe59c, which changes only tests and docs.

  1. Nonzero FirstElement. New consumer mode dispatch-records32-input-at-<bytes> puts the input descriptor's base that many bytes into the buffer. Each width reads once with its base at 4 * channels and expects the words shifted by one element.
    Mutation view.Buffer.FirstElement = range.offset / element → 0: fails, 1 channels, base one element in: word 0 expected 8b06bba2, read 8b02a7f1.

  2. Whole-element check. For 2 or more channels, a base 4 bytes in must be refused with a typed input range does not start at a whole element, leaving the output untouched.
    Mutation that drops range.offset % element ||: fails, {'mode': 'dispatch-records32-input-at-4'}: word 0 expected c5c5c5c5, read 8b02a7f1 (the dispatch reads from element 0 instead of being refused).

  3. Integer FORMATs. Each width also reads through its UINT and SINT codes (20/21, 62/63, 72/73, 75/76) and expects the same words. I ran each row's mutation separately (keep only the FLOAT code); each fails at that width's UINT case:

    • row 1, case 22 only: 1 channels, FORMAT 20: word 0 expected 8b02a7f1, read c5c5c5c5;
    • row 2, case 64 only: 2 channels, FORMAT 62: ...;
    • row 3, case 74 only: 3 channels, FORMAT 72: ...;
    • row 4, case 77 only: 4 channels, FORMAT 75: ....

    All four read the sentinel, because the dispatch was refused.

  4. Word 1 bits 30/31. A stride field of 0x4000 | 4 * channels must be refused with a typed input descriptor is swizzled or not bounds-checked by record.
    Mutation that drops (words[1] >> 30) ||: fails, {'stride': 16388}: word 0 expected c5c5c5c5, read 8b02a7f1.

Each mutation was applied on its own, the shim rebuilt, and startup_compute_typed_buffer_srv_hardware run, then reverted. Without mutations, _controls and _hardware pass on da4fe59c: 1 to 4 components, the UINT/SINT FORMATs, the shifted base, the token, and 5/8/8/9 refusals. The setup was the NVIDIA GeForce RTX 4090, driver 32.0.16.1088, Windows 11 build 26300, Debug, with the debug layer enabled.

#3397 (typed outputs, stacked on this PR) had the same four gaps, so I added the matching cases there: UINT/SINT stores, a base 8 bytes into the output (shifted for 1 and 2 components, refused as not element-aligned for 3 and 4), and word 1 bit 30. Under the same procedure, the output FirstElement → 0, the dropped alignment check, rows 1, 2 and 4, and the bit 30/31 mutation all fail its _hardware check. The row 3 mutation is caught only by this PR's check: the RTX 4090 has no typed UAV store for R32G32B32, so no 3-component store reaches that row.

AI-assisted.

@Not-Saii
Not-Saii requested a review from Leyukaka November 28, 2026 20:28

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

LGTM — clean input-side of typed buffer route.

Adds typed_dword_format_channels and typed_dword_input_view for published srv typed inputs. Manifest formatter emits srv <reg> typed table <param> <byte> bytes <n> lines; dispatch stub resolves table entries, binds UINT views of 32-bit components, and refuses invalid descriptors with precise reasons. Follows the same patterns as #3397 (typed outputs). Test fixture covers 1–4 components with comprehensive refusal controls.

Ready to land.

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

LGTM — clean input-side of typed buffer route.

Adds typed_dword_format_channels and typed_dword_input_view for published srv typed inputs. Manifest formatter emits srv <reg> typed table <param> <byte> bytes <n> lines; dispatch stub resolves table entries, binds UINT views of 32-bit components, and refuses invalid descriptors with precise reasons. Follows the same patterns as #3397 (typed outputs). Test fixture covers 1–4 components with comprehensive refusal controls.

Ready to land.

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.

3 participants