Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17258,7 +17258,7 @@ the field layouts rather than assembled.

## Translated compute Dispatch

With a device slot 67 placeholder bound, command-list slot 14 looks up the translation of the pipeline's published request (`<key>.txt` with `stage cs`, and `<key>.cs.cso`) and records it on the desktop list. It binds, from the compute descriptor tables of slot 35: raw buffers named by 16-byte hardware buffer descriptors, and 2D textures named by the token of a view the caller created (device slot 18 for an input, slot 19 for an output the program stores `float4` to). `smp` manifest lines become static samplers, and entry values come from the compute root constants of slots 37 and 39. A buffer input must resolve to a complete GPU-backed range; a buffer output must be a placed buffer that aliases the caller's memory and allows unordered access; a texture view must be 2D, created on the desktop, and for an output have a float or normalized format that is not packed, on a texture that is not also an input of the call. Any other manifest line (other texture kinds, sampler heaps, comparison samplers, root views, entry values that are neither a root constant nor a buffer descriptor word) leaves the pipeline untranslated, and a Dispatch that cannot be bound completely is refused with one logged reason: no Dispatch is recorded and nothing is bound (the upload of an input texture the caller filled in memory may already be recorded; it only syncs content). No view is ever bound null. The entry values live in the compute root-constant store of #1975: a word no slot 37 or 39 call wrote since the compute root was set (slot 33 with another root, or a list reset) has no value and is refused with `an entry value was not set since the compute root`; setting the same root again keeps the words, and the graphics words of slot 40 are separate.
With a device slot 67 placeholder bound, command-list slot 14 looks up the translation of the pipeline's published request (`<key>.txt` with `stage cs`, and `<key>.cs.cso`) and records it on the desktop list. It binds, from the compute descriptor tables of slot 35: raw buffers named by 16-byte hardware buffer descriptors, and 2D textures named by the token of a view the caller created (device slot 18 for an input, slot 19 for an output the program stores `float4` to). `smp` manifest lines become static samplers, and entry values come from the compute root constants of slots 37 and 39. A buffer input must resolve to a complete GPU-backed range; a buffer output must be a placed buffer that aliases the caller's memory and allows unordered access; a texture view must be 2D, created on the desktop, and for an output have a float or normalized format that is not packed, on a texture that is not also an input of the call. Any other manifest line (other texture kinds, sampler heaps, root views, entry values that are neither a root constant nor a buffer descriptor word) leaves the pipeline untranslated, and a Dispatch that cannot be bound completely is refused with one logged reason: no Dispatch is recorded and nothing is bound (the upload of an input texture the caller filled in memory may already be recorded; it only syncs content). No view is ever bound null. The entry values live in the compute root-constant store of #1975: a word no slot 37 or 39 call wrote since the compute root was set (slot 33 with another root, or a list reset) has no value and is refused with `an entry value was not set since the compute root`; setting the same root again keeps the words, and the graphics words of slot 40 are separate.

`tests/startup_compute_dispatch_check.py` drives a source-built gfx1013 program through the stand-in's list on WARP and on a physical adapter (exit 77 without one) and reads the 320 output words back from the aliased memory. Controls in the same run: before the offline translation, without a Dispatch, and with the two descriptors exchanged, every output word must keep its sentinel. The two entry values arrive through slot 37 and slot 39, with other values written through slot 40 in between; `dispatch-same-root` must still give the expected words, and five refused modes must log their reason and keep the sentinels: a missing word, another compute root set and the first set again, a list reset, a compute root that is not the pipeline's, and one buffer named as input and output. `tests/startup_compute_dispatch_texture_check.py` does the same for a program that stores to a 32x8 RGBA16_FLOAT texture (1024 halves read back through CopyTextureRegion; controls: before translation, without a Dispatch, a texture without unordered access) and for the raw buffer program with a level-zero sample of a 1x1 texture XORed into each stored word (control: no view at the table entry). The texture output program is also bound under a manifest edited to declare no entry values.

Expand Down Expand Up @@ -17355,7 +17355,7 @@ ctest --preset dev --no-tests=error -R "^startup_compute_dispatch_entry_" -V

### Static samplers with a LOD clamp

The translator writes a constant sampler of `image_sample`, `_l` or `_lz` whose mip filter is not 0 as an `smpl` line (#2482): a static sampler whose MinLOD and MaxLOD come from the descriptor's word 1. The compute Dispatch now reads `smpl` lines as the draw path does, through the same `TranslatedSamplers::read_manifest_line` and `create_translated_root`; the only difference for compute is that the root signature is set with `SetComputeRootSignature`, and static samplers need nothing else. The run-time sampler heap table (`smpheap`) is still refused, as "a sampler from the sampler heap". An `smpc` line is read since #3075: see [comparison samplers in a published compute manifest](experiments/startup-compute-comparison-sampler.md). Binding the heap table for compute would need the draw path's sampler snapshot (`snapshot_samplers`, `create_sampler_snapshot_heap`) taken from the compute root's sampler heap pointer, the sampler heap set with `SetDescriptorHeaps` and its table set with `SetComputeRootDescriptorTable`.
The translator writes a constant sampler of `image_sample`, `_l` or `_lz` whose mip filter is not 0 as an `smpl` line (#2482): a static sampler whose MinLOD and MaxLOD come from the descriptor's word 1. The compute Dispatch now reads `smpl` lines as the draw path does, through the same `TranslatedSamplers::read_manifest_line` and `create_translated_root`; the only difference for compute is that the root signature is set with `SetComputeRootSignature`, and static samplers need nothing else. The run-time sampler heap table (`smpheap`) is still refused, as "a sampler from the sampler heap". An `smpc` line is read since #3075: see [comparison samplers in a published compute manifest](experiments/startup-compute-comparison-sampler.md). The C++ publisher writes `smpc` lines and `comparison_texture_srv` views since #3224: see [comparison texture SRVs in the compute runtime manifest](experiments/compute-comparison-texture-manifest.md). Binding the heap table for compute would need the draw path's sampler snapshot (`snapshot_samplers`, `create_sampler_snapshot_heap`) taken from the compute root's sampler heap pointer, the sampler heap set with `SetDescriptorHeaps` and its table set with `SetComputeRootDescriptorTable`.

`tests/startup_compute_dispatch_texture_check.py` adds a filtered case: the texture input program with a wrap, linear sampler (`smpl 0 0x0 0xc00000 0x18500000 0x0`) reads a 2x1 RGBA8 texture whose left texel has red 0 and right texel red 1.0, at the left edge. Only a linear filter that wraps reads 0.5 there. On WARP and on a physical adapter, every thread read red 0.5, and the debug layer reported no error. The control is the same program with the manifest's sampler changed to clamp: it reads red 0, which the check refuses. The `smpheap` line refuses with its reason and leaves the output untouched. Without the new `smpl` reading, the Dispatch refuses with "a sampler that is not a plain static one" and the case fails. The texture has one mip, so the LOD clamp itself is not exercised here.

Expand Down
99 changes: 99 additions & 0 deletions docs/experiments/compute-comparison-texture-manifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Comparison texture SRVs in the compute runtime manifest (#3224)

In the refreshed `#3224` census after `#3386` and `#3397` landed, `SRV kind
comparison_texture_srv 2d` was the largest remaining unclaimed `compiled, no
runtime manifest` item (33 shaders / 52,008 dispatches). The dispatch reader
(`src/startup_stubs/d3d12_compute_dispatch.inl`) and the graphics manifest
already supported comparison textures and `smpc` lines; only the compute
manifest publisher refused both.

## Contract

`format_compute_runtime_manifest` (`src/direct_compute_cache.cpp`) publishes
a `comparison_texture_srv` view exactly like a `texture_srv` view of the same
dimension (2D or 2D array only), and a comparison sampler as `smpc`:

```text
srv <register> <tex2d|tex2da> table <parameter> <byte_offset>
smpc <register> <w0> <w1> <w2> <w3>
```

The comparison view is published only as a single view (`array_count == 1`)
of dimension 2D or 2D array. Only those two can reach the publisher: the
translator refuses a compare op unless the dimension is 1, 3 or 5
(`src/gfx1013_direct_compute.inl`), and dimension 3 is the cube kind. A cube
comparison is a different kind (`cube_comparison_srv`) and stays refused by
name as `SRV kind cube_comparison_srv cube`, as does a
`comparison_texture_srv` of dimension 1D, 3D or cube, or of an array
(`SRV kind comparison_texture_srv 1d`, `SRV kind comparison_texture_srv 3d`,
`SRV kind comparison_texture_srv cube`,
`SRV kind comparison_texture_srv 2d array`). A plain `texture_srv` still
publishes all four dimensions (1D, 2D, 3D, 2D array).

A comparison sampler is always `smpc`, never `smpl`: the comparison wins over
the LOD limits, as in `format_graphics_runtime_manifest` and the dispatch
reader. The direct translator binds one descriptor used by both plain and
comparison samples twice (a `texture_srv` binding and a
`comparison_texture_srv` binding, one register each), so a program that mixes
both carries two `srv N tex2d` lines for the same descriptor and its sampler
lines in register order (`smp`, `smpl`, `smpc`).

## Tests

- `tests/native_compute_manifest_reasons.cpp` publishes `comparison_texture_srv`
for 2D and 2D array, keeps the 1D/3D comparison refusals alongside the
cube-comparison and array refusals, and publishes a mixed
`smp 0, smpl 1, smpc 2` sampler order plus a lone `smpc 0`.
- `tests/startup_compute_comparison_srv_check.py` (no arguments: pure-Python
controls) checks the sampled program's encoding, the cube-dimension patch and
the expected sampler lines. Its `compile` mode publishes the sampled program
through `compile_dxil --requests` and checks the manifest lines, and publishes
the cube program to check it translates to DXIL but gets no manifest. Its
warp/hardware modes dispatch the published program through the stand-in
without `X2W_NATIVE_SHADERS` and match every volume word against the CPU
model of the four samplers, with a wrong-view control (the comparison binding
rewritten as `tex3d` is refused as `an input texture view is not 3D`) and the
cube control (no manifest, no translation).

## Verification

Linux (this change, `origin/main` `77d63db8`): `form_coverage_check.py`,
`docs_links_check.py` and `bidi_controls_check.py` pass, `py_compile` passes,
`git diff --check` is clean, the new check's pure-Python controls pass, and the
manifest-reasons unit test passes `0 of 45 manifest reasons wrong` against a
verbatim extract of the formatter (the full C++ build needs Windows). Five
spot-mutations on throwaway copies are all killed: reverting the
`comparison_texture_srv` branch (4 publish cases fail), emitting `smp` instead
of `smpc` (both sampler blocks fail), admitting dimension 3 (both cube refusals
fail), letting `smpl` win over `smpc` (the mixed-order block fails), and
dropping the `array_count == 1` guard (both array refusals fail).

Follow-up (restrict the published comparison view to 2D/2D array): the
manifest-reasons unit test again passes `0 of 45 manifest reasons wrong`
against a verbatim extract of the formatter, and 5/5 new spot-mutations on
throwaway copies are killed: admitting 1D/3D (both new refusals fail),
admitting dimension 3 (the cube refusal fails), dropping 2D array (the tex2da
publish fails), dropping the `array_count == 1` guard (the array refusal
fails), and emitting `smp` instead of `smpc` (both sampler blocks fail).

Windows verification of `native_compute_manifest_reasons`,
`native_compute_manifest_reasons_requests` and
`startup_compute_comparison_srv_(controls|warp|hardware)` on `d473b572`
(NVIDIA GeForce RTX 4050 Laptop GPU 10de:28e1, driver 32.0.15.9186,
`XBOX2WINDOWS_ADAPTER=NVIDIA`): `dev` 5 passed / 2 skipped (5.53s),
`release` 5 passed / 2 skipped (6.16s); the skips are 77 on Win11 WARP
`range=4..4` (`native_comparison_pso_warp`,
`startup_compute_comparison_srv_warp`). `native_compute_manifest_reasons`
reports 0/45 wrong; `startup_compute_comparison_srv_hardware` matches
6144/6144 volume words and its tex3d/cube controls pass;
`startup_compute_dispatch_native_hardware` passes (dev 7.97s, release 8.21s).
The first run on `c9213503` had failed `startup_compute_comparison_srv_controls`
1/7 at `tests/startup_compute_comparison_srv_check.py:178` (the cube shader
compiles to `.cs.cso`, so the check wrongly expected `compiled=0 refused=1`);
`d473b572` fixed that expectation to `compiled=1 refused=0`.

Follow-up cleanup (this change, restricting the published comparison view to
2D/2D array per the review on `d473b572`): Windows verification on `d99425fb`
passed `dev` and `release` (5 passed / 2 skipped each; the skips are 77 on
Win11 WARP `range=4..4`) prior to the merge with `upstream/main` below. The
merge commit itself has not been Windows-verified yet.
8 changes: 5 additions & 3 deletions docs/experiments/native-compile-dxil-refusals.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
more than 32 user data words, a resource or sampler heap view, a view above root parameter 15,
non-contiguous SRV or UAV registers, an SRV or UAV kind with no manifest line (the kind, and for
images the dimension and `array`; a texture SRV of dimension 1D, 2D, 3D or 2D array has a line, as
has a cube sample of one cube (`srv N texcubearr table R B`); a cube comparison, a cube array and a
multisampled one do not, and an `image_load` on a cube is refused earlier by the translator), more than 32 SRVs or 8 UAVs, a comparison sampler, and stride
words from a view that is not one raw vector SRV. No register numbers, offsets or keys.
has a comparison texture SRV of dimension 2D or 2D array and a cube sample of one cube
(`srv N texcubearr table R B`); a 1D or 3D comparison, a cube comparison, a cube array and a
multisampled one do not, and an `image_load` on a cube is refused earlier by the translator), more than 32 SRVs or 8 UAVs, and stride
words from a view that is not one raw vector SRV. A comparison sampler is published as `smpc`,
never as `smpl`. No register numbers, offsets or keys.
- `--requests` still publishes `<key>.cs.cso` and no `<key>.txt`, still counts the request as
compiled and still removes `<key>.fail`. It prints the reason in that job's report as
`no_manifest input=req_<key>.c67 <reason line>`. It writes no `.fail`, because `.fail` is the retry
Expand Down
11 changes: 7 additions & 4 deletions docs/experiments/startup-compute-comparison-sampler.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ An `smpheap` line is still refused with `a sampler from the sampler heap`.
- Only `tools/startup/gfx2hlsl.py` writes `smpc` for a compute program today (`image_sample_c_lz` and
`image_sample_c` with a constant comparison sampler). Before this change the runtime refused that translation
when it loaded the manifest, so such a request could not be dispatched.
- The C++ compiler's publisher is unchanged. `format_compute_runtime_manifest` (`src/direct_compute_cache.cpp`)
returns no manifest for a comparison sampler, so `compile_dxil` publishes no compute `smpc` line.
- The C++ compiler's publisher now writes the same lines. `format_compute_runtime_manifest`
(`src/direct_compute_cache.cpp`) publishes a `comparison_texture_srv` view like a plain texture view and a
comparison sampler as `smpc` (never `smpl`): see
[comparison texture SRVs in the compute runtime manifest](compute-comparison-texture-manifest.md).
- The in-process route (`X2W_NATIVE_SHADERS`, `translate_compute_natively`) is unchanged. It reads no manifest
lines and refuses every sampler, and every view that is not a raw buffer, before it reaches one.

Expand Down Expand Up @@ -84,7 +86,8 @@ AssertionError: smpc LESS: x2w-draw compute e9f1d94c2215f572 Dispatch(3, 2, 2) r

- A bilinear comparison filter, a border address mode, a 2D array and the other six functions. The fixture runs
point, clamp, LESS and GREATER on a 2D texture with one mip.
- A comparison sampler on the in-process route or from the C++ compiler's publisher. Both still stop before the
manifest reader, as listed above.
- A comparison sampler on the in-process route. The C++ compiler's publisher now writes `smpc` lines and
`comparison_texture_srv` views: see
[comparison texture SRVs in the compute runtime manifest](compute-comparison-texture-manifest.md).
- Console behaviour. The comparison is the desktop sampler's. The function mapping is the draw path's
(`decode_sampler` in `src/startup_stubs/translated_sampler_bindings.h`).
18 changes: 15 additions & 3 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,17 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
: "tex2da";
srv_lines << "srv " << b.shader_register << ' ' << tex << " table " << b.root_parameter << ' '
<< b.byte_offset << '\n';
} else if (b.kind == ComputeViewKind::comparison_texture_srv && b.array_count == 1 &&
(b.image_dimension == 1 || b.image_dimension == 5)) {
// A comparison sample reads its texture through the same kind of view as a plain one; the
// sampler line below carries the comparison. Only 2D and 2D-array comparisons can reach
// here: the translator refuses a compare op unless the dimension is 1, 3 or 5
// (src/gfx1013_direct_compute.inl), and dimension 3 is the cube kind
// (cube_comparison_srv), which stays refused by name. A 1D or 3D comparison is refused
// below, like the cube.
srv_lines << "srv " << b.shader_register << ' '
<< (b.image_dimension == 5 ? "tex2da" : "tex2d") << " table " << b.root_parameter << ' '
<< b.byte_offset << '\n';
} else if (b.kind == ComputeViewKind::cube_sample_srv && b.array_count == 1 && b.image_dimension == 3) {
// The program declares a TextureCubeArray (resource kind 9); the runtime binds the title's cube view
// as a one-cube array. `texcube` keeps its draw meaning (TextureCube).
Expand Down Expand Up @@ -1048,10 +1059,11 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh

for (size_t i = 0; i < program.samplers.size(); ++i) {
const auto &s = program.samplers[i];
if (s.comparison)
return refuse("comparison sampler");
// A comparison sampler is its own static sampler (smpc), never an smpl: the comparison wins over
// the LOD limits, as in format_graphics_runtime_manifest and the dispatch reader.
const char *tag = s.comparison ? "smpc" : s.explicit_lod ? "smpl" : "smp";
char line[64];
std::snprintf(line, sizeof(line), "%s %zu %08x %08x %08x %08x\n", s.explicit_lod ? "smpl" : "smp", i,
std::snprintf(line, sizeof(line), "%s %zu %08x %08x %08x %08x\n", tag, i,
s.words[0], s.words[1], s.words[2], s.words[3]);
sampler_lines << line;
}
Expand Down
1 change: 1 addition & 0 deletions tests/checks/python-linux/comparison-texture-manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/startup_compute_comparison_srv_check.py
Loading
Loading