Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
89fd41b
runtime: bind published typed buffer inputs with 32-bit components
Not-Saii Nov 28, 2026
9a414d1
tests: put the typed buffer fixture's output at table byte 32
Not-Saii Nov 28, 2026
4a2720e
docs: note the published typed buffer input contract and measurements
Not-Saii Nov 28, 2026
4598d59
runtime: bind published typed buffer outputs with 32-bit components
Not-Saii Nov 28, 2026
3d93cff
docs: note the published typed buffer output contract and measurements
Not-Saii Nov 28, 2026
da4fe59
tests: cover typed input offsets, integer FORMATs and word 1 swizzle …
Not-Saii Nov 28, 2026
3b5679f
Merge the #3386 review cases into the typed output branch
Not-Saii Nov 28, 2026
3141771
tests: cover typed output offsets, integer FORMATs and word 1 swizzle…
Not-Saii Nov 28, 2026
d2acde2
Merge main into the typed input branch
Not-Saii Nov 29, 2026
a3854d6
runtime: read typed input tokens with token_view and cover the review…
Not-Saii Nov 29, 2026
ef2b55d
Merge the updated typed input branch (with main) into the typed outpu…
Not-Saii Nov 29, 2026
75ceff6
tests: store typed outputs through 2- and 4-component view tokens
Not-Saii Nov 29, 2026
d518ea3
docs: record the typed buffer measurements on main e3f9a64f
Not-Saii Nov 29, 2026
0663f6e
docs: record the typed input measurements on main e3f9a64f
Not-Saii Nov 29, 2026
91beb2e
Merge the typed input measurements into the typed output branch
Not-Saii Nov 29, 2026
4cd38c9
Merge main into the typed input branch
Not-Saii Nov 29, 2026
4932e06
Merge the typed input branch (with main) into the typed output branch
Not-Saii Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions docs/experiments/compute-typed-buffer-inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Published typed buffer inputs (`srv <i> typed`)

Part of #3224. The direct compiler reads `buffer_load_format_x` to `_xyzw` (MUBUF, element index only) as a
`Buffer<uint4>` (`typed_buffer_srv`). `format_compute_runtime_manifest` now publishes it as
`srv <register> typed table <parameter> <byte> bytes <n>`, where `n` is 4 bytes per component of the widest load
of that binding.

The stand-in (`src/startup_stubs/d3d12_compute_dispatch.inl`) resolves the table entry with the existing input
range rules and binds a UINT buffer view of the title's 32-bit components: `R32_UINT` to `R32G32B32A32_UINT`. 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 (gfx10 `BUF_FMT_32*`), stride equal to the
element size, identity DST_SEL over the components read, unified FORMAT (RESOURCE_LEVEL 1), structured bounds
(OOB_SELECT 0), and no swizzle, index stride or ADD_TID.
- **Slot 18 view token:** a typed buffer view with 32-bit channels and the default component mapping, read through
the UINT format of the same width (`typed_dword_channels` / `typed_dword_uint_format` in
`src/startup_stubs/native_buffer_stride.h`). The token is read with `token_view`, so content tokens
(`X2W_D3D12_VIEW_CONTENT_TOKENS=1`) are decoded as the other buffer readers decode them.
- **All four words zero:** a null buffer that reads zeros, as for raw inputs.

Each other shape is refused before a dispatch is recorded, with one of these reasons:

- `a typed input FORMAT is not 32 bits per channel`
- `a typed input stride is not its element size`
- `a typed input DST_SEL is not the identity`
- `a typed input descriptor is swizzled or not bounds-checked by record`
- `a typed input has fewer channels than the program reads`
- `a typed input token is not a typed buffer view with 32-bit channels`
- `a typed input range does not start at a whole element`

The range checks of raw inputs also apply. A typed input on an indirect Dispatch is refused. 8- and 16-bit
formats, UNORM, SNORM and 16-bit FLOAT need a conversion that a UINT view does not do.

This binding is on the manifest route only, which a default run does not take. Since #3449 the launchers set
`X2W_NATIVE_SHADERS_ONLY=1`, and `load_compute_translation` then returns before it reads `<key>.txt`. The
in-process route (`translate_compute_natively`) is unchanged and still refuses `typed_buffer_srv` with
`view kind 1 is not bound for a natively translated program`. The `srv typed` line is bound only in runs with
`X2W_NATIVE_SHADERS_ONLY=0` and `compile_dxil` manifests.

## Test

`tests/startup_compute_typed_buffer_srv_check.py` publishes a source-built program for 1 to 4 components with
`compile_dxil --requests`. It then dispatches it through slot 14 with a 32-bit FLOAT descriptor of 50 elements.
The 384 lanes store what they read, so the lanes past element 49 must read zeros. The 4-component case also reads
through a slot 18 `R32G32B32A32_FLOAT` view token (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 (consumer mode
`dispatch-records32-input-at-<bytes>`), which shifts the words read by one element, and through an all-zero
descriptor (consumer mode `dispatch-records32-input-null`), which reads zeros. Each invalid shape above must be
refused with the output untouched, including a base 4 bytes in for 2 or more components, word 1 bit 30 or 31, and
word 3 INDEX_STRIDE or ADD_TID. Before publication the dispatch reports `no translation`.

`tests/native_compute_manifest_reasons.cpp` checks that a `typed_buffer_srv` wider than 16 bytes or not whole
32-bit components is refused as `SRV kind typed_buffer_srv`. `tests/startup_slot67_indirect_dispatch_check.py`
replaces its manifest line with `srv 0 typed table 1 0 bytes 4` and expects the indirect Dispatch to be refused.

```powershell
ctest --preset dev --no-tests=error -R '^startup_compute_typed_buffer_srv_' -V
```

Measured at `main` `e3f9a64f` plus this change, on Windows 11 build 26300 with the Windows SDK 10.0.26100 DXC,
Debug, with the D3D12 debug layer enabled:

- **NVIDIA GeForce RTX 4090, driver 32.0.16.1088:** passed for 1, 2, 3 and 4 components, the token, the null
descriptor, and 8, 11, 11 and 12 refusal controls. `native_compute_manifest_reasons` and
`startup_slot67_indirect_dispatch_hardware` passed.
- **WARP 10.0.26100.9818:** capability skip (77). WARP reports 4-lane waves and the direct module needs 32.
- **Negative control:** with the runtime's parse of the `typed` line disabled, the published manifest is not
bound and the hardware check reads the sentinel at word 0.

Not measured: how many of the cohort's typed inputs have a 32-bit FORMAT. The census re-measure answers that.

# Published typed buffer outputs (`uav <i> typed`)

`buffer_store_format_x` to `_xyzw` (MUBUF, element index only) is an `RWBuffer<uint4>` (`typed_buffer_uav`) in the
direct compiler. It is published as `uav <register> typed table <parameter> <byte> bytes <n>`, where `n` is 4 bytes
per stored component. One slot has one store width; the compiler refuses mixed widths.

The stand-in binds a UINT typed UAV of the title's 32-bit components whose channel count equals the stored
components:

- **Hardware descriptor:** the output path of the published D16 stores (#3302) with the typed element width. The
descriptor checks of the inputs above (FORMAT, stride, DST_SEL, bounds), the same channel count as the store,
and every output placement reason of #3229 apply.
- **Slot 19 view token:** `native_buffer_store_view` (`src/native_buffer_store_view.h`), the in-process native
route's typed-store contract: a buffer UAV without counter, structure stride or flags, a 32-bit UINT, SINT or
FLOAT format of the stored width, retyped to UINT and inside its buffer.
- **Typed UAV stores** must be supported for the format (`D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE`). R32G32B32
formats have no typed UAV, so a 3-component store is refused on the adapters measured below. One helper checks
this for these outputs and the half-float ones.

The refusal reasons are `a typed output FORMAT is not 32 bits per channel`,
`a typed output stride is not its element size`, `a typed output DST_SEL is not the identity`,
`a typed output descriptor is swizzled or not bounds-checked by record`,
`a typed output FORMAT has another width than the stored components`,
`an output typed buffer range is over 16 MiB`, `an output typed buffer is not element-aligned in its resource`,
`an output typed buffer format does not support typed UAV stores` and
`a typed output token is not a typed buffer UAV of the stored width`.

As for the inputs, this binding is on the manifest route only. A default run (`X2W_NATIVE_SHADERS_ONLY=1`) does
not read the `uav typed` line, and the in-process route still refuses `typed_buffer_uav` with
`view kind 8 is not bound for a natively translated program`.

## Test

`tests/startup_compute_typed_buffer_uav_check.py` publishes a source-built store of 1 to 4 components. Each of the
384 lanes stores words computed from its element index through a 32-bit FLOAT descriptor of 50 elements, so only
those elements change. The 1-component case also stores through the consumer's slot 19 `R32_UINT` token (312
elements from element 4), and a structured token is refused. The 2- and 4-component cases store through a slot 19
token of `R32G32_UINT` or `R32G32B32A32_UINT` 16 bytes into the output (the consumer's view replaced through
`X2W_TEST_DISPATCH_UAV`), and an `R32_UINT` token is refused. Each stored width also writes through its UINT and
SINT FORMATs, and through a descriptor based 8 bytes into the output (`dispatch-records32-output-offset`): 1 and 2
components store shifted by that much, and 3 and 4 components are refused because 8 bytes is not a whole element.
The invalid descriptors above, and word 1 bit 30, are refused with the output untouched, and before publication
the dispatch reports `no translation`. The other word 1 and word 3 bits, and the indirect Dispatch refusal, are
shared with the inputs and covered by their checks.

```powershell
ctest --preset dev --no-tests=error -R '^startup_compute_typed_buffer_uav_' -V
```

Measured on the same machine as above, stacked on the typed input commits:

- **NVIDIA GeForce RTX 4090, driver 32.0.16.1088:** passed. 1, 2 and 4 components stored 50 elements, the
`R32_UINT` token stored 312, the 2- and 4-component tokens stored 50, and 7, 8, 8 and 9 refusal controls passed. The 3-component store was refused with
`an output typed buffer format does not support typed UAV stores`.
- **WARP:** capability skip (77), as above.
- **Negative control:** with the parse of the `uav typed` line disabled, the hardware check reads the sentinel at
word 0.
- **Regressions:** `startup_compute_half_buffer_uav_hardware` and `startup_compute_packed_d16_x_uav_controls` /
`_hardware` also passed on the RTX 4090.
10 changes: 10 additions & 0 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,11 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
if (b.requires_identity_dst_sel)
srv_lines << " identity_dst_sel";
srv_lines << '\n';
} else if (b.kind == ComputeViewKind::typed_buffer_srv && b.array_count == 1 && b.required_bytes &&
b.required_bytes <= 16 && b.required_bytes % 4 == 0) {
// buffer_load_format_*: read as Buffer<uint4>; bytes is the widest load (4 per component).
srv_lines << "srv " << b.shader_register << " typed table " << b.root_parameter << ' ' << b.byte_offset
<< " bytes " << b.required_bytes << '\n';
} else if (b.kind == ComputeViewKind::texture_srv && b.array_count == 1 &&
(b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 ||
b.image_dimension == 5)) {
Expand Down Expand Up @@ -993,6 +998,11 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
(b.required_bytes == 2 || b.required_bytes == 4 || b.required_bytes == 8)) {
uav_lines << "uav " << b.shader_register << " bufhalf table " << b.root_parameter << ' '
<< b.byte_offset << " bytes " << b.required_bytes << '\n';
} else if (b.kind == ComputeViewKind::typed_buffer_uav && b.array_count == 1 && b.required_bytes &&
b.required_bytes <= 16 && b.required_bytes % 4 == 0) {
// buffer_store_format_*: an RWBuffer<uint4>; bytes is the stored width (4 per component).
uav_lines << "uav " << b.shader_register << " typed table " << b.root_parameter << ' ' << b.byte_offset
<< " bytes " << b.required_bytes << '\n';
} else if (b.kind == ComputeViewKind::packed_d16_x_uav && b.array_count == 1 && b.required_bytes == 2) {
uav_lines << "uav " << b.shader_register << " packed_d16_x table " << b.root_parameter << ' '
<< b.byte_offset << '\n';
Expand Down
Loading
Loading