From c92135036b2ca19ed60e94eb2381afa81398029d Mon Sep 17 00:00:00 2001 From: Ammar Abdelfattah <241957358+Ammmae0x@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:11:10 +0200 Subject: [PATCH 1/3] compute: publish comparison_texture_srv and smpc manifests Refs #3224, #2935. 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 and the graphics manifest already supported comparison textures and smpc lines; only format_compute_runtime_manifest refused both. - src/direct_compute_cache.cpp: accept comparison_texture_srv alongside texture_srv for a single view of dimension 1D, 2D, 3D or 2D array, emitting the same srv tex line; a cube comparison stays a different kind (cube_comparison_srv) and stays refused by name. A comparison sampler is published as smpc, never smpl: the comparison wins over the LOD limits, as in format_graphics_runtime_manifest and the dispatch reader. The obsolete comparison sampler refusal is gone. - tests/native_compute_manifest_reasons.cpp: publish comparison_texture_srv for all four dimensions, keep the cube-comparison and array refusals, add comparison_texture_srv cube/array refusals, and publish a mixed smp 0, smpl 1, smpc 2 order plus a lone smpc 0. - tests/startup_compute_comparison_srv_check.py: end-to-end coverage for the sampled program (plain + comparison samples of one 2D texture). No-argument controls run on Linux; compile mode publishes through compile_dxil --requests and checks the manifest lines; warp/hardware modes dispatch the published program without X2W_NATIVE_SHADERS and match every volume word against the CPU model, with a wrong-view control (tex3d rewrite refused) and a cube control (DXIL published, no manifest, no translation). Registered in tests/cmake/startup_compute_comparison_srv.cmake and tests/checks/python-linux/comparison-texture-manifest.txt. - Docs: new docs/experiments/compute-comparison-texture-manifest.md, and the stale comparison-sampler refusal notes in docs/experiments.md, docs/experiments/native-compile-dxil-refusals.md and docs/experiments/startup-compute-comparison-sampler.md updated. Linux verification (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 native_compute_manifest_reasons passes 0 of 45 manifest reasons wrong against a verbatim extract of the formatter (the full C++ build needs Windows). 5/5 spot-mutations killed on throwaway copies: revert the comparison_texture_srv branch, emit smp instead of smpc, admit dimension 3, let smpl win over smpc, drop the array_count guard. Windows verification (compile_dxil, native CTest, GPU readback) is pending. --- docs/experiments.md | 4 +- .../compute-comparison-texture-manifest.md | 67 +++++ .../native-compile-dxil-refusals.md | 8 +- .../startup-compute-comparison-sampler.md | 11 +- src/direct_compute_cache.cpp | 14 +- .../comparison-texture-manifest.txt | 1 + .../startup_compute_comparison_srv.cmake | 18 ++ tests/native_compute_manifest_reasons.cpp | 49 +++- tests/startup_compute_comparison_srv_check.py | 269 ++++++++++++++++++ 9 files changed, 426 insertions(+), 15 deletions(-) create mode 100644 docs/experiments/compute-comparison-texture-manifest.md create mode 100644 tests/checks/python-linux/comparison-texture-manifest.txt create mode 100644 tests/cmake/startup_compute_comparison_srv.cmake create mode 100644 tests/startup_compute_comparison_srv_check.py diff --git a/docs/experiments.md b/docs/experiments.md index 3fff98730d..833bfa52f3 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -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 (`.txt` with `stage cs`, and `.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 (`.txt` with `stage cs`, and `.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. @@ -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. diff --git a/docs/experiments/compute-comparison-texture-manifest.md b/docs/experiments/compute-comparison-texture-manifest.md new file mode 100644 index 0000000000..bc6f56bf51 --- /dev/null +++ b/docs/experiments/compute-comparison-texture-manifest.md @@ -0,0 +1,67 @@ +# 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, and a comparison sampler as `smpc`: + +```text +srv table +smpc +``` + +The view is published only as a single view (`array_count == 1`) of dimension +1D, 2D, 3D or 2D array. 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 cube or of an array (`SRV kind comparison_texture_srv cube`, +`SRV kind comparison_texture_srv 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 all four dimensions, keeps 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). + +Windows verification of `native_compute_manifest_reasons`, +`native_compute_manifest_reasons_requests` and +`startup_compute_comparison_srv_(controls|warp|hardware)` is pending. diff --git a/docs/experiments/native-compile-dxil-refusals.md b/docs/experiments/native-compile-dxil-refusals.md index d1b280d3ee..31226bcc58 100644 --- a/docs/experiments/native-compile-dxil-refusals.md +++ b/docs/experiments/native-compile-dxil-refusals.md @@ -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 the same dimensions and 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, 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 `.cs.cso` and no `.txt`, still counts the request as compiled and still removes `.fail`. It prints the reason in that job's report as `no_manifest input=req_.c67 `. It writes no `.fail`, because `.fail` is the retry diff --git a/docs/experiments/startup-compute-comparison-sampler.md b/docs/experiments/startup-compute-comparison-sampler.md index fc1f3ccfbd..507339f3ef 100644 --- a/docs/experiments/startup-compute-comparison-sampler.md +++ b/docs/experiments/startup-compute-comparison-sampler.md @@ -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. @@ -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`). diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 83af0a61b2..a124c73153 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -971,9 +971,14 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh // buffer_load_format_*: read as Buffer; 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 && + } else if ((b.kind == ComputeViewKind::texture_srv || + b.kind == ComputeViewKind::comparison_texture_srv) && + b.array_count == 1 && (b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 || 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. A cube comparison is a different kind + // (cube_comparison_srv) and stays refused by name. const char *tex = b.image_dimension == 0 ? "tex1d" : b.image_dimension == 1 ? "tex2d" : b.image_dimension == 2 ? "tex3d" @@ -1047,10 +1052,11 @@ std::optional 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; } diff --git a/tests/checks/python-linux/comparison-texture-manifest.txt b/tests/checks/python-linux/comparison-texture-manifest.txt new file mode 100644 index 0000000000..1b761ccc1f --- /dev/null +++ b/tests/checks/python-linux/comparison-texture-manifest.txt @@ -0,0 +1 @@ +tests/startup_compute_comparison_srv_check.py diff --git a/tests/cmake/startup_compute_comparison_srv.cmake b/tests/cmake/startup_compute_comparison_srv.cmake new file mode 100644 index 0000000000..d4e6802c57 --- /dev/null +++ b/tests/cmake/startup_compute_comparison_srv.cmake @@ -0,0 +1,18 @@ +# A comparison-sampling compute program published through compile_dxil and dispatched (#3224). +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + add_test(NAME startup_compute_comparison_srv_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_comparison_srv_check.py" compile + "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_comparison_srv_controls PROPERTIES TIMEOUT 60) +endif() +if(TARGET compile_dxil AND TARGET startup_stream_consumer AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_comparison_srv_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_comparison_srv_check.py" + "$" "$" + "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_comparison_srv_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp index 858f61dab5..7a5b28e879 100644 --- a/tests/native_compute_manifest_reasons.cpp +++ b/tests/native_compute_manifest_reasons.cpp @@ -79,6 +79,14 @@ int main() { p.bindings[0].kind = K::cube_comparison_srv; p.bindings[0].image_dimension = 3; }}, + {"SRV kind comparison_texture_srv cube", [](auto &p) { + p.bindings[0].kind = K::comparison_texture_srv; + p.bindings[0].image_dimension = 3; + }}, + {"SRV kind comparison_texture_srv 2d array", [](auto &p) { + p.bindings[0].kind = K::comparison_texture_srv; + p.bindings[0].array_count = 4; + }}, {"SRV kind cube_sample_srv cube array", [](auto &p) { p.bindings[0].kind = K::cube_sample_srv; p.bindings[0].image_dimension = 3; @@ -116,7 +124,6 @@ int main() { for (unsigned r = 1; r < 9; ++r) p.bindings.push_back(view(K::raw_buffer_uav, r, 2, 32 * r)); }}, - {"comparison sampler", [](auto &p) { p.samplers.push_back({{0, 0, 0, 0}, true, true}); }}, {"stride words from a view that is not one raw vector SRV", [](auto &p) { p.stride_srvs = {0}; }}, }; for (const auto &c : cases) { @@ -131,6 +138,7 @@ int main() { } // Texture bindings are published under the dimension names the runtime's reader takes. A cube sample names // `texcubearr`: the program declares a TextureCubeArray (`texcube` stays the draw route's TextureCube). + // A comparison texture shares the plain texture's line: the sampler line below carries the comparison. const struct { unsigned binding; K kind; @@ -141,6 +149,10 @@ int main() { {0, K::texture_srv, 1, "srv 0 tex2d table 1 64\n"}, {0, K::texture_srv, 2, "srv 0 tex3d table 1 64\n"}, {0, K::texture_srv, 5, "srv 0 tex2da table 1 64\n"}, + {0, K::comparison_texture_srv, 0, "srv 0 tex1d table 1 64\n"}, + {0, K::comparison_texture_srv, 1, "srv 0 tex2d table 1 64\n"}, + {0, K::comparison_texture_srv, 2, "srv 0 tex3d table 1 64\n"}, + {0, K::comparison_texture_srv, 5, "srv 0 tex2da table 1 64\n"}, {0, K::cube_sample_srv, 3, "srv 0 texcubearr table 1 64\n"}, {1, K::texture_uav, 0, "uav 0 tex1d float table 1 32 channels 4\n"}, {1, K::texture_uav, 1, "uav 0 tex2d float table 1 32 channels 4\n"}, @@ -194,6 +206,39 @@ int main() { std::printf(" | got: %s\n", manifest ? manifest->c_str() : reason.c_str()); failures += !ok; } - std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + std::size(published) + 3); + // Samplers are published in register order. A comparison sampler is smpc even when it also carries + // LOD limits, never smpl and never smp. + { + auto program = base(); + program.samplers.push_back({{0x10, 0xfff000, 0x4000000, 0}, false, false}); + program.samplers.push_back({{0x11, 0, 0x4000000, 0}, true, false}); + program.samplers.push_back({{0x8001012, 0, 0, 0}, true, true}); + reason = "unset"; + const auto manifest = format_compute_runtime_manifest(program, &reason); + std::string wanted = expected; + wanted.replace(wanted.find("native "), 0, + "smp 0 00000010 00fff000 04000000 00000000\n" + "smpl 1 00000011 00000000 04000000 00000000\n" + "smpc 2 08001012 00000000 00000000 00000000\n"); + const bool ok = manifest && *manifest == wanted && reason == "unset"; + std::printf("%s publishes smp 0, smpl 1, smpc 2 in order\n", ok ? "ok " : "FAIL"); + if (!ok) + std::printf(" | got: %s\n", manifest ? manifest->c_str() : reason.c_str()); + failures += !ok; + } + { + auto program = base(); + program.samplers.push_back({{0x8001012, 0, 0, 0}, false, true}); + reason = "unset"; + const auto manifest = format_compute_runtime_manifest(program, &reason); + std::string wanted = expected; + wanted.replace(wanted.find("native "), 0, "smpc 0 08001012 00000000 00000000 00000000\n"); + const bool ok = manifest && *manifest == wanted && reason == "unset"; + std::printf("%s publishes smpc 0\n", ok ? "ok " : "FAIL"); + if (!ok) + std::printf(" | got: %s\n", manifest ? manifest->c_str() : reason.c_str()); + failures += !ok; + } + std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + std::size(published) + 5); return failures ? 1 : 0; } diff --git a/tests/startup_compute_comparison_srv_check.py b/tests/startup_compute_comparison_srv_check.py new file mode 100644 index 0000000000..983199cd7f --- /dev/null +++ b/tests/startup_compute_comparison_srv_check.py @@ -0,0 +1,269 @@ +"""Publish a comparison-sampling slot 67 program and dispatch it through the stand-in (#3224). + +usage: startup_compute_comparison_srv_check.py + + startup_compute_comparison_srv_check.py compile + startup_compute_comparison_srv_check.py + (no arguments: pure-Python controls for the program encoding and expectations) + +The program is the sampled program of startup_compute_dispatch_native_check.py: four samples of a +two-mip 2x1 R32_FLOAT texture feed a 3D float image store, each through its own constant sampler +(image_sample_lz, two image_sample_l, image_sample_c_lz with LESS). The plain samples bind the +texture as `texture_srv` and the comparison sample binds the same descriptor as +`comparison_texture_srv`, so the published manifest carries two `srv N tex2d` lines for one +descriptor plus `smpl` lines for the first three samplers and an `smpc` line for the fourth: + + srv 0 tex2d table 1 32 + srv 1 tex2d table 1 32 + uav 0 tex3d float table 1 64 channels 4 + smpl 0 00000010 00fff000 04000000 00000000 + smpl 1 00000011 00000000 04000000 00000000 + smpl 2 00000012 00100100 04000000 00000000 + smpc 3 08001012 00000000 00000000 00000000 + +Every sample in this program passes an explicit LOD to the direct translator's sampler_index +(`src/gfx1013_direct_compute.inl`), so the first three samplers are `smpl`; the fourth is a +comparison sampler, so it is `smpc` even though it also carries LOD limits. + +The warp/hardware run dispatches the program through the stand-in without X2W_NATIVE_SHADERS, +so only the published manifest can translate it: + +1. Before publication the Dispatch is refused with "no translation" and the volume is untouched. +2. `compile_dxil --requests` publishes the manifest above; the Dispatch then translates and all + volume words match the CPU model of the four samplers. +3. Wrong-view control: the manifest's `srv 1 tex2d` line rewritten as `tex3d` is refused with + "an input texture view is not 3D" and the volume is untouched; restoring the line dispatches + again with the same readback. +4. Cube control: the same program with the comparison sample's dimension changed to cube + translates (its `.cs.cso` is published) but gets no manifest + (`SRV kind cube_comparison_srv cube`), so its Dispatch is refused with "no translation" and + the volume is untouched. + +The `compile` mode runs steps 2 and 4 without a device. Without 32-lane waves the published +Dispatch is refused by the pipeline-creation capability reason instead and the check exits 77. +Exit 77 also when the adapter is unavailable. +""" +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +import startup_compute_dispatch_native_check as N +import startup_compute_dispatch_texture_check as T +import startup_compute_image_store_check as A +import startup_gfx2hlsl_image_store_3d1d_check as V +from startup_compute_dispatch_check import lines, prepare_case +from startup_compute_translate_check import state_a, write_request +from startup_stream_check import gfx2hlsl as G + +MODE = 'texture-volume-native-sampled' +MANIFEST_VIEW_LINES = ( + 'srv 0 tex2d table 1 32', + 'srv 1 tex2d table 1 32', + 'uav 0 tex3d float table 1 64 channels 4', +) +EXPECTED_SAMPLER_LINES = ( + 'smpl 0 00000010 00fff000 04000000 00000000', + 'smpl 1 00000011 00000000 04000000 00000000', + 'smpl 2 00000012 00100100 04000000 00000000', + 'smpc 3 08001012 00000000 00000000 00000000', +) +CUBE_REASON = 'unsupported startup runtime manifest bindings: SRV kind cube_comparison_srv cube' +CAPABILITY_REFUSALS = ( + 'pipeline creation failed (adapter has no 32-lane waves)', + 'pipeline creation failed (adapter shader model below 6.6)', +) +STATE = state_a(V.group('volume'), A.RSRC2) + + +def cube_program(): + """The sampled program with the comparison sample's dimension changed to cube (dim field 1 -> 3).""" + code = bytearray(N.sampled_program(False)) + decoded = list(G.decode(bytes(code))) + targets = [offset for offset, _, name, _ in decoded if name == 'image_sample_c_lz'] + assert len(targets) == 1, decoded + offset = targets[0] + word0 = struct.unpack_from('> 3) & 7 == 1, 'the comparison sample does not start at dim 2D' + original = bytes(code) + struct.pack_into(' 2, rows + return initial, expected + + +def expected_sampler_lines(): + """The manifest sampler lines derived from the sampled program's sampler words and the tag rule + (comparison -> smpc, explicit LOD -> smpl, else smp); every sample here passes an explicit LOD.""" + tags = ['smpc' if index == 3 else 'smpl' for index in range(len(N.SAMPLERS))] + return ['%s %d %08x %08x %08x %08x' % (tag, index, *words) + for index, (tag, words) in enumerate(zip(tags, N.SAMPLERS))] + + +def assert_manifest_lines(manifest, label): + lines_found = manifest.read_text().splitlines() + for line in MANIFEST_VIEW_LINES + EXPECTED_SAMPLER_LINES: + assert line in lines_found, f'{label}: missing manifest line {line!r} in:\n{manifest.read_text()}' + samplers = [line for line in lines_found if line.startswith(('smp ', 'smpl ', 'smpc '))] + assert samplers == list(EXPECTED_SAMPLER_LINES), f'{label}: sampler lines out of order: {samplers}' + + +def publish(compile_dxil, sdk, cache): + return subprocess.run([compile_dxil, sdk, cache.parent / 'native', 'gfx1013-direct-cs@0', + '--requests', cache, cache], capture_output=True, text=True, timeout=60) + + +def two_srv_root(directory): + path = directory / 'compute_root' + N.write_two_srv_root(path) + return path.read_bytes() + + +def controls(): + code = N.sampled_program(False) # asserts its own body decodes to SAMPLED_PROGRAM + cube = cube_program() + assert cube != code + assert expected_sampler_lines() == list(EXPECTED_SAMPLER_LINES), expected_sampler_lines() + initial, expected = expected_volume() + assert len(initial) == len(expected) == 32 * 8 * 4 * 6 + assert expected != initial + print('comparison SRV controls (sampled program encoding, cube patch, sampler lines, ' + 'volume model) passed') + + +def check_compiler(compile_dxil, sdk): + controls() + with tempfile.TemporaryDirectory() as temporary: + directory = Path(temporary) + for name, code in (('sampled', N.sampled_program(False)), ('cube', cube_program())): + cache = directory / name / 'cache' + cache.mkdir(parents=True) + key = write_request(cache, code, STATE, root=two_srv_root(directory / name)) + result = publish(compile_dxil, sdk, cache) + manifest = cache / f'{key:016x}.txt' + if name == 'sampled': + assert result.returncode == 0 and 'requests=1 compiled=1 refused=0' in result.stdout, ( + result.stdout, result.stderr) + assert manifest.is_file(), result.stdout + assert_manifest_lines(manifest, name) + assert not (cache / f'{key:016x}.cs.hlsl').exists(), 'expected native publication' + print(f'sampled: published as `{MANIFEST_VIEW_LINES[1]}` with an `smpc 3` line') + else: + assert result.returncode == 0 and 'requests=1 compiled=0 refused=1' in result.stdout, ( + result.stdout, result.stderr) + assert f'no_manifest input=req_{key:016x}.c67 {CUBE_REASON}' in result.stdout, result.stdout + assert not manifest.exists() and (cache / f'{key:016x}.cs.cso').read_bytes().startswith(b'DXBC'), ( + result.stdout, result.stderr) + print('cube: translated to DXIL but refused a manifest (`SRV kind cube_comparison_srv cube`)') + + +def check(compile_dxil, consumer, sdk, work, adapter): + cache, env = prepare_case(work, adapter) + env.pop('X2W_NATIVE_SHADERS', None) # Exercise published translations. + env.pop('X2W_NATIVE_SHADERS_ONLY', None) + N.write_two_srv_root(Path(env['X2W_TEST_COMPUTE_ROOT'])) + (work / 'state').write_bytes(STATE) + initial, expected = expected_volume() + layout = '<%dI' % len(initial) + + (work / 'program').write_bytes(N.sampled_program(False)) + got, result = T.run(work, consumer, env, MODE, layout) + assert got == initial, 'a Dispatch without a translation wrote the volume' + assert len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] + key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16) + + published = publish(compile_dxil, sdk, cache) + assert published.returncode == 0 and 'requests=1 compiled=1 refused=0' in published.stdout, ( + published.stdout, published.stderr) + manifest = cache / f'{key:016x}.txt' + assert_manifest_lines(manifest, 'sampled') + + got, result = T.run(work, consumer, env, MODE, layout) + for capability in CAPABILITY_REFUSALS: + if lines(result, f'not translated: {capability}'): + assert got == initial and len(lines(result, f'Dispatch(2, 1, 1) refused: {capability}')) == 1, ( + result.stderr[-3000:]) + print(f'sampled: native DXIL and manifest verified; dispatch skipped ({capability})') + return False + assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] + wrong = [i for i in range(len(got)) if got[i] != expected[i]] + assert not wrong, 'sampled: word %d got=%08x expected=%08x (%d words differ)\n%s' % ( + wrong[0], got[wrong[0]], expected[wrong[0]], len(wrong), result.stderr[-3000:]) + T.clean(result) + + # Wrong-view control: the comparison binding under a 3D dimension is refused, then restored. + original = manifest.read_text() + manifest.write_bytes(original.replace('srv 1 tex2d table 1 32', 'srv 1 tex3d table 1 32').encode()) + got, result = T.run(work, consumer, env, MODE, layout) + refusal = lines(result, 'Dispatch(2, 1, 1) refused:') + assert got == initial and len(refusal) == 1 and refusal[0].endswith('an input texture view is not 3D'), ( + result.stderr[-3000:]) + manifest.write_bytes(original.encode()) + got, result = T.run(work, consumer, env, MODE, layout) + assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] + assert got == expected, 'restoring the manifest did not restore the readback' + T.clean(result) + print(f'sampled: all {len(got)} volume words match the CPU model (wrap, mirror with MAX_LOD, clamp with ' + f'MIN_LOD, LESS comparison); the tex3d view control refuses and the restore dispatches again') + + (work / 'program').write_bytes(cube_program()) + got, result = T.run(work, consumer, env, MODE, layout) + assert got == initial, 'a Dispatch without a translation wrote the volume' + assert len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] + cube_key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16) + refused = publish(compile_dxil, sdk, cache) + assert refused.returncode == 0 and f'no_manifest input=req_{cube_key:016x}.c67 {CUBE_REASON}' in refused.stdout, ( + refused.stdout, refused.stderr) + assert not (cache / f'{cube_key:016x}.txt').exists(), 'the cube comparison got a manifest' + assert (cache / f'{cube_key:016x}.cs.cso').read_bytes().startswith(b'DXBC'), refused.stdout + got, result = T.run(work, consumer, env, MODE, layout) + assert got == initial, 'a Dispatch without a translation wrote the volume' + assert len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] + print('cube: translated to DXIL but refused a manifest, so the Dispatch stays refused with no translation') + return True + + +def main(compile_dxil, consumer, sdk, adapter): + with tempfile.TemporaryDirectory() as temporary: + if not check(compile_dxil, consumer, sdk, Path(temporary), adapter): + print(f'startup_compute_comparison_srv: SKIP on {adapter} (no 32-lane waves or shader model below 6.6)') + return 77 + print(f'startup_compute_comparison_srv: PASS on {adapter}') + return 0 + + +if __name__ == '__main__': + if len(sys.argv) == 1: + controls() + elif len(sys.argv) == 4 and sys.argv[1] == 'compile': + check_compiler(sys.argv[2], sys.argv[3]) + elif len(sys.argv) == 5 and sys.argv[4] in ('warp', 'hardware'): + sys.exit(main(*sys.argv[1:])) + else: + sys.exit(__doc__) From d473b572f6b23dbb07ee8b83572a0c55c6bb735e Mon Sep 17 00:00:00 2001 From: Ammar Abdelfattah <241957358+Ammmae0x@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:16:35 +0200 Subject: [PATCH 2/3] test: expect cube comparison shader to compile in comparison SRV controls compile_dxil --requests compiles the cube comparison shader to .cs.cso (requests=1 compiled=1 refused=0) and emits no_manifest for it, so the controls check wrongly expected requests=1 compiled=0 refused=1. Refs #3224, #2935 --- .../compute-comparison-texture-manifest.md | 18 +++++++++++++++++- tests/startup_compute_comparison_srv_check.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/experiments/compute-comparison-texture-manifest.md b/docs/experiments/compute-comparison-texture-manifest.md index bc6f56bf51..884bf97a1d 100644 --- a/docs/experiments/compute-comparison-texture-manifest.md +++ b/docs/experiments/compute-comparison-texture-manifest.md @@ -64,4 +64,20 @@ dropping the `array_count == 1` guard (both array refusals fail). Windows verification of `native_compute_manifest_reasons`, `native_compute_manifest_reasons_requests` and -`startup_compute_comparison_srv_(controls|warp|hardware)` is pending. +`startup_compute_comparison_srv_(controls|warp|hardware)` on `c9213503` +(NVIDIA GeForce RTX 4050 Laptop GPU, `XBOX2WINDOWS_ADAPTER=NVIDIA`, `dev` +preset): `native_compute_manifest_reasons`, +`native_compute_manifest_reasons_requests`, +`native_graphics_comparison_pso_warp`, +`startup_compute_comparison_srv_hardware` (2.95s — sampled: all 6144 volume +words match the CPU model; the tex3d view control refuses and the restore +dispatches again; cube: translated to DXIL but refused a manifest) and +`startup_compute_dispatch_native_hardware` (8.19s) passed; +`native_comparison_pso_warp`, `startup_compute_comparison_srv_warp` and +`startup_compute_dispatch_native_warp` exited 77 (Win11 WARP `range=4..4`, no +wave32). `startup_compute_comparison_srv_controls` failed 1/7 at +`tests/startup_compute_comparison_srv_check.py:178`: `compile_dxil --requests` +compiles the cube comparison shader to `.cs.cso` (`requests=1 compiled=1 +refused=0`) and emits `no_manifest ...`, so the check wrongly expected +`requests=1 compiled=0 refused=1`. The fix (expect `compiled=1 refused=0`) +awaits a rerun. diff --git a/tests/startup_compute_comparison_srv_check.py b/tests/startup_compute_comparison_srv_check.py index 983199cd7f..646824d133 100644 --- a/tests/startup_compute_comparison_srv_check.py +++ b/tests/startup_compute_comparison_srv_check.py @@ -175,7 +175,7 @@ def check_compiler(compile_dxil, sdk): assert not (cache / f'{key:016x}.cs.hlsl').exists(), 'expected native publication' print(f'sampled: published as `{MANIFEST_VIEW_LINES[1]}` with an `smpc 3` line') else: - assert result.returncode == 0 and 'requests=1 compiled=0 refused=1' in result.stdout, ( + assert result.returncode == 0 and 'requests=1 compiled=1 refused=0' in result.stdout, ( result.stdout, result.stderr) assert f'no_manifest input=req_{key:016x}.c67 {CUBE_REASON}' in result.stdout, result.stdout assert not manifest.exists() and (cache / f'{key:016x}.cs.cso').read_bytes().startswith(b'DXBC'), ( From d99425fb951a21e0396b6d9dcd193eb76adaa6d8 Mon Sep 17 00:00:00 2001 From: Ammar Abdelfattah <241957358+Ammmae0x@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:50:08 +0200 Subject: [PATCH 3/3] compute: publish comparison_texture_srv only for 2D and 2D array The direct translator refuses a compare op unless the dimension is 1, 3 or 5, and dimension 3 is the cube kind, so only tex2d and tex2da can reach the comparison branch of format_compute_runtime_manifest. Restrict it to those two and refuse 1D/3D comparisons by name, like the cube. Refs #3224, #2935 --- .../compute-comparison-texture-manifest.md | 67 +++++++++++-------- .../native-compile-dxil-refusals.md | 4 +- src/direct_compute_cache.cpp | 18 +++-- tests/native_compute_manifest_reasons.cpp | 17 ++++- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/docs/experiments/compute-comparison-texture-manifest.md b/docs/experiments/compute-comparison-texture-manifest.md index 884bf97a1d..d50bbd20ad 100644 --- a/docs/experiments/compute-comparison-texture-manifest.md +++ b/docs/experiments/compute-comparison-texture-manifest.md @@ -11,19 +11,24 @@ manifest publisher refused both. `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, and a comparison sampler as `smpc`: +dimension (2D or 2D array only), and a comparison sampler as `smpc`: ```text -srv table +srv table smpc ``` -The view is published only as a single view (`array_count == 1`) of dimension -1D, 2D, 3D or 2D array. 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 cube or of an array (`SRV kind comparison_texture_srv cube`, -`SRV kind comparison_texture_srv 2d array`). +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 @@ -36,8 +41,9 @@ lines in register order (`smp`, `smpl`, `smpc`). ## Tests - `tests/native_compute_manifest_reasons.cpp` publishes `comparison_texture_srv` - for all four dimensions, keeps the cube-comparison and array refusals, and - publishes a mixed `smp 0, smpl 1, smpc 2` sampler order plus a lone `smpc 0`. + 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 @@ -62,22 +68,29 @@ 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 `c9213503` -(NVIDIA GeForce RTX 4050 Laptop GPU, `XBOX2WINDOWS_ADAPTER=NVIDIA`, `dev` -preset): `native_compute_manifest_reasons`, -`native_compute_manifest_reasons_requests`, -`native_graphics_comparison_pso_warp`, -`startup_compute_comparison_srv_hardware` (2.95s — sampled: all 6144 volume -words match the CPU model; the tex3d view control refuses and the restore -dispatches again; cube: translated to DXIL but refused a manifest) and -`startup_compute_dispatch_native_hardware` (8.19s) passed; -`native_comparison_pso_warp`, `startup_compute_comparison_srv_warp` and -`startup_compute_dispatch_native_warp` exited 77 (Win11 WARP `range=4..4`, no -wave32). `startup_compute_comparison_srv_controls` failed 1/7 at -`tests/startup_compute_comparison_srv_check.py:178`: `compile_dxil --requests` -compiles the cube comparison shader to `.cs.cso` (`requests=1 compiled=1 -refused=0`) and emits `no_manifest ...`, so the check wrongly expected -`requests=1 compiled=0 refused=1`. The fix (expect `compiled=1 refused=0`) -awaits a rerun. +`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 re-verification is pending. diff --git a/docs/experiments/native-compile-dxil-refusals.md b/docs/experiments/native-compile-dxil-refusals.md index 31226bcc58..8e593002bb 100644 --- a/docs/experiments/native-compile-dxil-refusals.md +++ b/docs/experiments/native-compile-dxil-refusals.md @@ -26,8 +26,8 @@ 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 comparison texture SRV of the same dimensions and a cube sample of one cube - (`srv N texcubearr table R B`); a cube comparison, a cube array and a + 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. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index a124c73153..b6618ea956 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -971,20 +971,26 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh // buffer_load_format_*: read as Buffer; 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.kind == ComputeViewKind::comparison_texture_srv) && - b.array_count == 1 && + } 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)) { - // A comparison sample reads its texture through the same kind of view as a plain one; the - // sampler line below carries the comparison. A cube comparison is a different kind - // (cube_comparison_srv) and stays refused by name. const char *tex = b.image_dimension == 0 ? "tex1d" : b.image_dimension == 1 ? "tex2d" : b.image_dimension == 2 ? "tex3d" : "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). diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp index 7a5b28e879..f900d4f35d 100644 --- a/tests/native_compute_manifest_reasons.cpp +++ b/tests/native_compute_manifest_reasons.cpp @@ -83,6 +83,17 @@ int main() { p.bindings[0].kind = K::comparison_texture_srv; p.bindings[0].image_dimension = 3; }}, + {"SRV kind comparison_texture_srv 1d", [](auto &p) { + // The translator refuses a compare op unless the dimension is 1, 3 or 5, and 3 is the + // cube kind, so a 1D comparison never reaches the publisher. + p.bindings[0].kind = K::comparison_texture_srv; + p.bindings[0].image_dimension = 0; + }}, + {"SRV kind comparison_texture_srv 3d", [](auto &p) { + // Likewise a 3D comparison: only 2D and 2D-array comparisons are published. + p.bindings[0].kind = K::comparison_texture_srv; + p.bindings[0].image_dimension = 2; + }}, {"SRV kind comparison_texture_srv 2d array", [](auto &p) { p.bindings[0].kind = K::comparison_texture_srv; p.bindings[0].array_count = 4; @@ -138,7 +149,9 @@ int main() { } // Texture bindings are published under the dimension names the runtime's reader takes. A cube sample names // `texcubearr`: the program declares a TextureCubeArray (`texcube` stays the draw route's TextureCube). - // A comparison texture shares the plain texture's line: the sampler line below carries the comparison. + // A comparison texture shares the plain texture's 2D/2D-array line: the sampler line below carries the + // comparison. A 1D or 3D comparison never reaches the publisher (the translator refuses compare ops + // outside dimensions 1, 3 and 5, and 3 is the cube kind), so those stay refused above. const struct { unsigned binding; K kind; @@ -149,9 +162,7 @@ int main() { {0, K::texture_srv, 1, "srv 0 tex2d table 1 64\n"}, {0, K::texture_srv, 2, "srv 0 tex3d table 1 64\n"}, {0, K::texture_srv, 5, "srv 0 tex2da table 1 64\n"}, - {0, K::comparison_texture_srv, 0, "srv 0 tex1d table 1 64\n"}, {0, K::comparison_texture_srv, 1, "srv 0 tex2d table 1 64\n"}, - {0, K::comparison_texture_srv, 2, "srv 0 tex3d table 1 64\n"}, {0, K::comparison_texture_srv, 5, "srv 0 tex2da table 1 64\n"}, {0, K::cube_sample_srv, 3, "srv 0 texcubearr table 1 64\n"}, {1, K::texture_uav, 0, "uav 0 tex1d float table 1 32 channels 4\n"},