From 3ea1a79f008bffad492ab1432a99e721e1ccaa43 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 05:02:22 +0200 Subject: [PATCH 1/2] compute: name why a compiled program gets no runtime manifest Each refusal in format_compute_runtime_manifest now returns a fixed reason. compile_dxil --requests writes it to .fail beside the published .cs.cso, --watch writes it instead of the reasonless line, --refusals counts it, and triage_run.py reports it as an allowlisted category. Accepted manifests and published files are unchanged. Refs #3224 Co-Authored-By: Claude Opus 5.5 --- .../native-compile-dxil-refusals.md | 20 +++- src/direct_compute_cache.cpp | 67 ++++++++++--- src/direct_compute_cache.h | 4 +- .../native_compute_manifest_reasons.cmake | 15 +++ tests/native_compute_manifest_reasons.cpp | 97 +++++++++++++++++++ .../native_compute_manifest_reasons_check.py | 88 +++++++++++++++++ tests/startup_triage_run_check.py | 10 ++ tools/startup/compile_dxil.cpp | 29 ++++-- tools/startup/triage_run.py | 8 ++ 9 files changed, 314 insertions(+), 24 deletions(-) create mode 100644 tests/cmake/native_compute_manifest_reasons.cmake create mode 100644 tests/native_compute_manifest_reasons.cpp create mode 100644 tests/native_compute_manifest_reasons_check.py diff --git a/docs/experiments/native-compile-dxil-refusals.md b/docs/experiments/native-compile-dxil-refusals.md index 494f62a51d..90722f3371 100644 --- a/docs/experiments/native-compile-dxil-refusals.md +++ b/docs/experiments/native-compile-dxil-refusals.md @@ -18,13 +18,29 @@ - Strips PC offsets and normalizes hex words, byte offsets, and register indices so repeated failures across different instructions or requests aggregate into one row. +3. **Compute programs without a runtime manifest (#3224):** + - A slot-67 compute program that translates but that `format_compute_runtime_manifest` + (`src/direct_compute_cache.cpp`) cannot describe gets one fixed reason, for example + `unsupported startup runtime manifest bindings: SRV kind root_buffer_srv`. The reasons name the + exit: a zero group dimension, root constants above parameter 15 or more than 8 in one parameter, + 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`), 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. + - `--requests` still publishes `.cs.cso` and no `.txt`, and still counts the request as + compiled; it now also writes the reason to `.fail`. `--watch` writes the same line instead of + the former reasonless one, and `--refusals` counts the request under it instead of under + no refusal. `triage_run.py` reports it as `runtime manifest: `. + - With `X2W_SKIP_FAILED=1` / `--skip-failed`, the Python watcher skips such a key when the output + directory is used as a live cache, as it already did after `--watch` wrote its `.fail`. + ## Verification ```powershell .\tools\dev.ps1 cmake --preset release -cmake --build --preset release --target compile_dxil -ctest --preset release --no-tests=error -V -R "^native_compile_dxil_refusals$" +cmake --build --preset release --target compile_dxil native_compute_manifest_reasons +ctest --preset release --no-tests=error -V -R "^(native_compile_dxil_refusals|native_compute_manifest_reasons(_requests)?)$" .\out\pe-env\Scripts\python.exe -B tests/startup_triage_run_check.py ``` diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 3aaba58c17..2c4ad29e47 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -727,18 +727,51 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view return verified(std::move(pair)); } -std::optional format_compute_runtime_manifest(const NativeComputeShader &program) { - if (!program.group[0] || !program.group[1] || !program.group[2]) +static const char *view_kind_name(ComputeViewKind kind) { + static const char *const names[] = { + "buffer_srv", "typed_buffer_srv", "texture_srv", "texture_uav", "raw_vector_srv", "half_scalar_uav", + "heap_stride_srv", "raw_buffer_uav", "typed_buffer_uav", "half_buffer_uav", "root_buffer_srv", + "comparison_texture_srv", "half2_texture_uav", "half4_texture_uav", "cube_sample_srv", "cube_comparison_srv", + "indexed_atomic_uav", "d16_sample_srv", "byte_window_srv", "heap_buffer_srv", "heap_sampler", + "uint_texture_uav", "float_texture_uav", "float2_texture_uav", "float3_texture_uav"}; + const auto index = static_cast(kind); + return index < std::size(names) ? names[index] : "unknown"; +} + +// "SRV kind texture_srv 3d": the binding kind, and for image kinds the ISA dimension and a descriptor array. +static std::string view_shape(const char *type, const ComputeViewBinding &b) { + std::string out = std::string(type) + " kind " + view_kind_name(b.kind); + if (std::string_view(out).find("texture") != std::string_view::npos || + std::string_view(out).find("sample") != std::string_view::npos || + std::string_view(out).find("cube") != std::string_view::npos) { + static const char *const dims[] = {"1d", "2d", "3d", "cube", "1d-array", "2d-array", "2d-msaa", "2d-msaa-array"}; + out += ' '; + out += b.image_dimension < std::size(dims) ? dims[b.image_dimension] : "unknown-dimension"; + } + if (b.array_count != 1) + out += " array"; + return out; +} + +std::optional format_compute_runtime_manifest(const NativeComputeShader &program, std::string *reason) { + auto refuse = [&](std::string why) -> std::optional { + if (reason) + *reason = std::move(why); return std::nullopt; + }; + if (!program.group[0] || !program.group[1] || !program.group[2]) + return refuse("group size has a zero dimension"); unsigned ud_count = 0; for (const auto &block : program.constants) { - if (block.root_parameter >= 16 || block.count > 8) - return std::nullopt; + if (block.root_parameter >= 16) + return refuse("root constants above root parameter 15"); + if (block.count > 8) + return refuse("more than 8 root constants in one root parameter"); ud_count += block.count; } ud_count += static_cast(program.stride_srvs.size()); if (ud_count > 32) - return std::nullopt; + return refuse("more than 32 user data words"); auto sorted = program.bindings; std::sort(sorted.begin(), sorted.end(), [](const auto &a, const auto &b) { @@ -751,11 +784,15 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh unsigned srv_count = 0, uav_count = 0; std::ostringstream srv_lines, uav_lines, sampler_lines; for (const auto &b : sorted) { + if (b.root_parameter == compute_resource_heap) + return refuse("resource heap view"); + if (b.root_parameter == compute_sampler_heap) + return refuse("sampler heap"); if (b.root_parameter >= 16) - return std::nullopt; + return refuse("view above root parameter 15"); if (!compute_uav(b.kind)) { if (b.shader_register != srv_count++) - return std::nullopt; + return refuse("SRV registers not contiguous"); if (b.kind == ComputeViewKind::buffer_srv || b.kind == ComputeViewKind::raw_vector_srv || b.kind == ComputeViewKind::byte_window_srv) { srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset @@ -764,11 +801,11 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh srv_lines << "srv " << b.shader_register << " tex2d table " << b.root_parameter << ' ' << b.byte_offset << '\n'; } else { - return std::nullopt; + return refuse(view_shape("SRV", b)); } } else { if (b.shader_register != uav_count++) - return std::nullopt; + return refuse("UAV registers not contiguous"); if (b.kind == ComputeViewKind::raw_buffer_uav) { uav_lines << "uav " << b.shader_register << " table " << b.root_parameter << ' ' << b.byte_offset << '\n'; @@ -785,17 +822,19 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : " tex2d") << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n"; } else { - return std::nullopt; + return refuse(view_shape("UAV", b)); } } } - if (srv_count > 32 || uav_count > 8) - return std::nullopt; + if (srv_count > 32) + return refuse("more than 32 SRVs"); + if (uav_count > 8) + return refuse("more than 8 UAVs"); for (size_t i = 0; i < program.samplers.size(); ++i) { const auto &s = program.samplers[i]; if (s.comparison) - return std::nullopt; + return refuse("comparison sampler"); char line[64]; std::snprintf(line, sizeof(line), "%s %zu %08x %08x %08x %08x\n", s.explicit_lod ? "smpl" : "smp", i, s.words[0], s.words[1], s.words[2], s.words[3]); @@ -812,7 +851,7 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh for (unsigned srv : program.stride_srvs) { if (srv >= srv_count || sorted[srv].kind != ComputeViewKind::raw_vector_srv || sorted[srv].array_count != 1) - return std::nullopt; + return refuse("stride words from a view that is not one raw vector SRV"); out << "udsrc " << ud_index++ << " stride " << srv << '\n'; } out << srv_lines.str() << uav_lines.str() << sampler_lines.str() diff --git a/src/direct_compute_cache.h b/src/direct_compute_cache.h index f52d82336e..efe29a989c 100644 --- a/src/direct_compute_cache.h +++ b/src/direct_compute_cache.h @@ -15,7 +15,9 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view std::string_view root = {}, std::string_view input_layout = {}, std::string_view pixel_entry = {}, bool write_cache = true, const std::vector &rtv_formats = {}); -std::optional format_compute_runtime_manifest(const NativeComputeShader &program); +// Without a manifest, reason (when given) receives a fixed refusal text: no register numbers, offsets or keys. +std::optional format_compute_runtime_manifest(const NativeComputeShader &program, + std::string *reason = nullptr); // rtv_request: the "rtv1 ..." text of an RTV variant, written as the manifest's last line for the runtime to match. std::optional format_graphics_runtime_manifest(const DirectGraphicsPair &pair, std::string_view rtv_request = {}); diff --git a/tests/cmake/native_compute_manifest_reasons.cmake b/tests/cmake/native_compute_manifest_reasons.cmake new file mode 100644 index 0000000000..a142534f0b --- /dev/null +++ b/tests/cmake/native_compute_manifest_reasons.cmake @@ -0,0 +1,15 @@ +# Named reasons for compute programs that compile but get no runtime manifest (#3224). +# native_compute_manifest_reasons calls the formatter once per reason; the _requests check runs one reachable +# reason through compile_dxil --requests, --refusals, --watch and triage_run.py. +if(TARGET compile_dxil) + add_executable(native_compute_manifest_reasons tests/native_compute_manifest_reasons.cpp) + target_link_libraries(native_compute_manifest_reasons PRIVATE x2w_shader_compiler) + set_property(TARGET native_compute_manifest_reasons PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + add_test(NAME native_compute_manifest_reasons COMMAND native_compute_manifest_reasons) + if(EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll" AND EXISTS "${INTAKE_PYTHON}") + add_test(NAME native_compute_manifest_reasons_requests COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_compute_manifest_reasons_check.py" + "$" "${DXC_BIN_DIR}") + set_tests_properties(native_compute_manifest_reasons_requests PROPERTIES TIMEOUT 60) + endif() +endif() diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp new file mode 100644 index 0000000000..95576a8ef9 --- /dev/null +++ b/tests/native_compute_manifest_reasons.cpp @@ -0,0 +1,97 @@ +// Every refusal of format_compute_runtime_manifest names its reason, and an accepted program's manifest is unchanged. +#include "direct_compute_cache.h" +#include "native_compute_output.h" + +#include +#include +#include + +using namespace x2w; + +static ComputeViewBinding view(ComputeViewKind kind, unsigned reg, unsigned root = 1, unsigned offset = 0) { + ComputeViewBinding b{}; + b.kind = kind; + b.root_parameter = root; + b.byte_offset = offset; + b.shader_register = reg; + return b; +} + +static NativeComputeShader base() { + NativeComputeShader p{}; + p.group = {8, 4, 1}; + p.constants.push_back({0, 0, 2}); + p.bindings.push_back(view(ComputeViewKind::buffer_srv, 0, 1, 64)); + p.bindings.push_back(view(ComputeViewKind::raw_buffer_uav, 0, 1, 32)); + return p; +} + +int main() { + int failures = 0; + std::string reason = "unset"; + const auto accepted = format_compute_runtime_manifest(base(), &reason); + const std::string expected = "x2w-manifest 2\nstage cs\ngroup 8 4 1\nud 2\nudsrc 0 rootconst 0 0\n" + "udsrc 1 rootconst 0 1\nsrv 0 buf table 1 64\nuav 0 table 1 32\nnative " + + std::to_string(native_compute_output_revision) + "\n"; + if (!accepted || *accepted != expected || reason != "unset") { + std::printf("FAIL accepted program: manifest %s, reason \"%s\"\n", accepted ? accepted->c_str() : "(none)", + reason.c_str()); + ++failures; + } + + using K = ComputeViewKind; + const struct { + const char *expected; + std::function change; + } cases[] = { + {"group size has a zero dimension", [](auto &p) { p.group[2] = 0; }}, + {"root constants above root parameter 15", [](auto &p) { p.constants[0].root_parameter = 16; }}, + {"more than 8 root constants in one root parameter", [](auto &p) { p.constants[0].count = 9; }}, + {"more than 32 user data words", [](auto &p) { + p.constants.assign(4, {0, 0, 8}); + p.bindings[0].kind = K::raw_vector_srv; + p.stride_srvs = {0}; + }}, + {"resource heap view", [](auto &p) { p.bindings.push_back(view(K::heap_buffer_srv, 1, compute_resource_heap)); }}, + {"sampler heap", [](auto &p) { p.bindings.push_back(view(K::heap_sampler, 1, compute_sampler_heap)); }}, + {"view above root parameter 15", [](auto &p) { p.bindings[1].root_parameter = 16; }}, + {"SRV registers not contiguous", [](auto &p) { p.bindings[0].shader_register = 1; }}, + {"UAV registers not contiguous", [](auto &p) { p.bindings[1].shader_register = 1; }}, + {"SRV kind root_buffer_srv", [](auto &p) { p.bindings[0].kind = K::root_buffer_srv; }}, + {"SRV kind texture_srv 3d", [](auto &p) { + p.bindings[0].kind = K::texture_srv; + p.bindings[0].image_dimension = 2; + }}, + {"SRV kind texture_srv 2d array", [](auto &p) { + p.bindings[0].kind = K::texture_srv; + p.bindings[0].array_count = 4; + }}, + {"UAV kind typed_buffer_uav", [](auto &p) { p.bindings[1].kind = K::typed_buffer_uav; }}, + {"UAV kind texture_uav cube", [](auto &p) { + p.bindings[1].kind = K::texture_uav; + p.bindings[1].image_dimension = 3; + }}, + {"more than 32 SRVs", [](auto &p) { + for (unsigned r = 1; r < 33; ++r) + p.bindings.push_back(view(K::buffer_srv, r, 1, 64 + 32 * r)); + }}, + {"more than 8 UAVs", [](auto &p) { + 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) { + auto program = base(); + c.change(program); + reason.clear(); + const auto manifest = format_compute_runtime_manifest(program, &reason); + const bool ok = !manifest && reason == c.expected; + std::printf("%s %s%s%s\n", ok ? "ok " : "FAIL", c.expected, ok ? "" : " | got: ", + ok ? "" : manifest ? "a manifest" : reason.c_str()); + failures += !ok; + } + std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + 1); + return failures ? 1 : 0; +} diff --git a/tests/native_compute_manifest_reasons_check.py b/tests/native_compute_manifest_reasons_check.py new file mode 100644 index 0000000000..8c1d9ebd69 --- /dev/null +++ b/tests/native_compute_manifest_reasons_check.py @@ -0,0 +1,88 @@ +"""A compute program that compiles but gets no runtime manifest names the reason (#3224). + +The program reads a root CBV and a root SRV (the raw-root fixture), so it translates to DXIL but the +compute manifest has no line for a root descriptor. A table-bound control still publishes its manifest. + +usage: + native_compute_manifest_reasons_check.py +""" +import json +from pathlib import Path +import shutil +import struct +import subprocess +import sys +import tempfile + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +sys.path.insert(0, str(HERE.parent / "tools" / "startup")) + +import triage_run # noqa: E402 +from native_compute_clear_check import write_request # noqa: E402 +from native_startup_request_cache_check import ( # noqa: E402 + COMPUTE_GROUP, + COMPUTE_RSRC2, + compile_compute_root, + compute_program_words, + put_compute_request, +) +from startup_compute_translate_check import state_a # noqa: E402 + +# s_load_dwordx4 from the root CBV at s[6:7]; copy the root SRV address s[8:9] to s[2:3]; load from it; s_endpgm. +ROOT_CODE = [0xF40C0403, 0xFA000010, 0xBE820408, 0xF40C0601, 0xFA000030, 0xBF810000] +ROOT_SA = struct.pack("<7I", 0, 0, 0, 32 | (1 << 16), 1 | (1 << 20), 0, 10 << 1) +REASON = "unsupported startup runtime manifest bindings: SRV kind root_buffer_srv" + + +def main(argv: list[str]) -> int: + if len(argv) != 2: + raise SystemExit(__doc__) + cli, sdk = Path(argv[0]).resolve(), Path(argv[1]) + with tempfile.TemporaryDirectory() as tmp: + work = Path(tmp) + src = work / "root.hlsl" + src.write_text('#define RS "RootConstants(num32BitConstants=2,b1),CBV(b0),SRV(t0)"', encoding="ascii") + subprocess.run([sdk / "dxc.exe", "-T", "rootsig_1_1", "-E", "RS", "-Fo", work / "root.bin", src], check=True) + requests = work / "requests" + requests.mkdir() + key = write_request(requests, ROOT_CODE, (work / "root.bin").read_bytes(), ROOT_SA).stem[4:] + control = "%016x" % put_compute_request( + requests, compute_program_words(), compile_compute_root(sdk, work), state_a(COMPUTE_GROUP, COMPUTE_RSRC2)) + watched = work / "watched" + shutil.copytree(requests, watched) + + # 1. --requests still publishes the DXIL and nothing else changes; the .fail names the missing manifest. + out = work / "out" + run = subprocess.run([cli, sdk, work / "frontend", "--jobs", "2", "gfx1013-direct-cs@0", "--requests", + requests, out], capture_output=True, text=True) + assert run.returncode == 0 and "requests=2 compiled=2 refused=0" in run.stdout, (run.stdout, run.stderr) + assert (out / f"{key}.cs.cso").read_bytes().startswith(b"DXBC") + assert not (out / f"{key}.txt").exists() + assert (out / f"{key}.fail").read_text(encoding="ascii") == REASON + "\n", (out / f"{key}.fail").read_text() + assert (out / f"{control}.txt").is_file() and not (out / f"{control}.fail").exists() + + # 2. --refusals counts it with the same text. + summary = json.loads(subprocess.run([cli, "--refusals", requests, "--json"], capture_output=True, + text=True, check=True).stdout)["compute"] + assert summary["examined"] == 2 and summary["no_refusal"] == 1 and summary["refused"] == 1, summary + assert summary["reasons"] == [{"reason": REASON, "count": 1}], summary + + # 3. --watch writes the same line, and triage_run.py reports it as a fixed category without the key. + watch = subprocess.run([cli, "--watch", sdk, work / "watch_cache", watched, "--once"], + capture_output=True, text=True) + assert watch.returncode == 0 and f"{key}: refused: {REASON}" in watch.stdout, (watch.stdout, watch.stderr) + assert f"{control}: compiled compute" in watch.stdout, watch.stdout + assert (watched / f"{key}.fail").read_text(encoding="ascii") == REASON + "\n" + logs = work / "logs" + logs.mkdir() + (logs / "stderr.txt").write_text("", encoding="utf-8") + report = triage_run.triage_run(logs, shader_cache=watched) + assert "| 1 | `compute: runtime manifest: SRV kind root_buffer_srv` |" in report, report + assert key not in report and control not in report + print("compute manifest reasons: ok") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/tests/startup_triage_run_check.py b/tests/startup_triage_run_check.py index 9b46c1a7da..494d0f40be 100644 --- a/tests/startup_triage_run_check.py +++ b/tests/startup_triage_run_check.py @@ -59,6 +59,11 @@ def check_aggregation_and_redaction(failures: list[str]) -> None: # A device slot 67 compute request with the same reason is counted in its own class. (cache_dir / "0000000000000004.fail").write_text("image_load_mip tfe\n", encoding="utf-8") (cache_dir / "req_0000000000000004.c67").write_bytes(b"\0" * 4) + # A compute runtime manifest reason is a fixed category; text outside its allowlist is not copied. + for key, line in ((5, "unsupported startup runtime manifest bindings: UAV kind texture_uav cube"), + (6, "unsupported startup runtime manifest bindings: SRV kind /home/alice/x")): + (cache_dir / f"{key:016x}.fail").write_text(line + "\n", encoding="utf-8") + (cache_dir / f"req_{key:016x}.c67").write_bytes(b"\0" * 4) report = triage_run.triage_run(logdir, shader_cache=cache_dir, max_items=16) @@ -77,6 +82,8 @@ def check_aggregation_and_redaction(failures: list[str]) -> None: "| 1 | `persistent_local_storage` | `0x80070005` |", "| 2 | `image_load_mip tfe` |", "| 1 | `compute: image_load_mip tfe` |", + "| 1 | `compute: runtime manifest: UAV kind texture_uav cube` |", + f"| 1 | `compute: {triage_run.OTHER}` |", f"| 1 | `{triage_run.OTHER}` |", ] for snippet in expected_snippets: @@ -503,6 +510,9 @@ def check_every_shader_reason_entry_is_reachable(failures: list[str]) -> None: ("native compute +0x14: unsupported instruction v_add3_u32 0xd76d0002u", "v_* instruction"), ("native compute +0x8: unsupported opcode 0xdeadbeefu", "unsupported opcode"), ("native compute +0x10: unsupported pixel entry VGPR 2", "unsupported pixel entry VGPR"), + ("unsupported startup runtime manifest bindings: SRV kind texture_srv 2d array", + "runtime manifest: SRV kind texture_srv 2d array"), + ("unsupported startup runtime manifest bindings: more than 8 UAVs", "runtime manifest: more than 8 UAVs"), ("native compute +0x1c: unproven resource descriptor s12", "unproven resource descriptor"), ("native compute +0x20: unbound numeric SGPR s0", "unbound numeric SGPR"), ("unknown gfx1013 instruction format at byte 24", "undecodable word"), diff --git a/tools/startup/compile_dxil.cpp b/tools/startup/compile_dxil.cpp index b8a6b80a0f..e038626718 100644 --- a/tools/startup/compile_dxil.cpp +++ b/tools/startup/compile_dxil.cpp @@ -101,7 +101,7 @@ static std::optional compile_one(x2w::ShaderDxilCompiler& compiler, const fs::path& input_path, const fs::path& destination, const fs::path& cache, std::ostream& report, const x2w::NativeComputeShader *linked=nullptr, - bool emit_manifest=false) { + bool emit_manifest=false, std::string *manifest_reason=nullptr) { Clock::time_point start; std::string source; std::optional manifest; @@ -145,7 +145,7 @@ static std::optional compile_one(x2w::ShaderDxilCompiler& compiler, } report<<"global_srv select="<data(), manifest->size()); @@ -1019,9 +1027,16 @@ int wmain(int argc, wchar_t** argv) { std::error_code ignored; fs::remove(manifest_path, ignored); fs::remove(fs::path(stems[i]) += L".cs.hlsl", ignored); // see compile_watch_item - auto manifest = compile_one(compiler, job_profile(i), inputs[i], outputs[i], argv[2], report, nullptr, true); + std::string reason; + auto manifest = compile_one(compiler, job_profile(i), inputs[i], outputs[i], argv[2], report, nullptr, true, &reason); if (manifest) publish_atomic(manifest_path, manifest->data(), manifest->size()); - fs::remove(fs::path(stems[i]) += L".fail", ignored); + // The DXIL stays published; the .fail names why no manifest was. + if (!manifest && !reason.empty()) { + const auto line = format_fail_line(manifest_refusal(reason)); + publish_atomic(fs::path(stems[i]) += L".fail", line.data(), line.size()); + } else { + fs::remove(fs::path(stems[i]) += L".fail", ignored); + } return; } const fs::path manifest_path = fs::path(stems[i]) += L".txt"; diff --git a/tools/startup/triage_run.py b/tools/startup/triage_run.py index 5342725a7e..d516728e8d 100644 --- a/tools/startup/triage_run.py +++ b/tools/startup/triage_run.py @@ -113,6 +113,14 @@ (re.compile(r"native compute \+0x[0-9a-fA-F]+: unbound numeric SGPR\b"), "unbound numeric SGPR"), (re.compile(r"(?:unknown gfx1013 instruction format|truncated or misaligned gfx1013 instruction|" r"reserved FLAT segment) at byte \d+\Z"), "undecodable word"), + # The fixed reasons of format_compute_runtime_manifest (src/direct_compute_cache.cpp); kind names are enum names. + (re.compile(r"unsupported startup runtime manifest bindings: (" + r"(?:SRV|UAV) kind [a-z0-9_]{1,32}(?: [a-z0-9-]{1,20})?(?: array)?|" + r"(?:SRV|UAV) registers not contiguous|group size has a zero dimension|" + r"root constants above root parameter 15|view above root parameter 15|" + r"more than (?:8 root constants in one root parameter|32 user data words|32 SRVs|8 UAVs)|" + r"resource heap view|sampler heap|comparison sampler|" + r"stride words from a view that is not one raw vector SRV)\Z"), r"runtime manifest: \1"), (re.compile(r"graphics request key mismatch\b"), "graphics request key mismatch"), (re.compile(r"compute request key mismatch\b"), "compute request key mismatch"), (re.compile(r"stale pixel input description\b"), "stale pixel input description"), From 50740b7cc76a59b461079de1e61151a71bc1e8c4 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 05:28:41 +0200 Subject: [PATCH 2/2] compute: keep the --requests manifest reason out of .fail A program that compiles but gets no runtime manifest is not a failed request: .fail is the retry marker of both watchers, and with --skip-failed the Python watcher stopped selecting such a key in a live cache (review of #3268). --requests now removes .fail as before and prints the reason in the job report as no_manifest input=... . --watch, which refuses the key, still writes the reason to its .fail. The end-to-end check runs --requests in a live cache beside a genuine refusal and checks both pending_keys selections, plus the --watch case. Refs #3224 Co-Authored-By: Claude Opus 5.5 --- .../native-compile-dxil-refusals.md | 14 ++++---- .../native_compute_manifest_reasons_check.py | 32 ++++++++++++++----- tools/startup/compile_dxil.cpp | 11 +++---- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/docs/experiments/native-compile-dxil-refusals.md b/docs/experiments/native-compile-dxil-refusals.md index 90722f3371..2f5133d110 100644 --- a/docs/experiments/native-compile-dxil-refusals.md +++ b/docs/experiments/native-compile-dxil-refusals.md @@ -27,12 +27,14 @@ non-contiguous SRV or UAV registers, an SRV or UAV kind with no manifest line (the kind, and for images the dimension and `array`), 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. - - `--requests` still publishes `.cs.cso` and no `.txt`, and still counts the request as - compiled; it now also writes the reason to `.fail`. `--watch` writes the same line instead of - the former reasonless one, and `--refusals` counts the request under it instead of under - no refusal. `triage_run.py` reports it as `runtime manifest: `. - - With `X2W_SKIP_FAILED=1` / `--skip-failed`, the Python watcher skips such a key when the output - directory is used as a live cache, as it already did after `--watch` wrote its `.fail`. + - `--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 + marker of both watchers: with `X2W_SKIP_FAILED=1` / `--skip-failed` the Python watcher keeps + selecting such a key in a live cache. + - `--watch`, which refuses the key, writes the same line to `.fail` instead of the former + reasonless one. `--refusals` counts the request under it instead of under no refusal. + `triage_run.py` reports the `.fail` line as `runtime manifest: `. ## Verification diff --git a/tests/native_compute_manifest_reasons_check.py b/tests/native_compute_manifest_reasons_check.py index 8c1d9ebd69..201d0c6bac 100644 --- a/tests/native_compute_manifest_reasons_check.py +++ b/tests/native_compute_manifest_reasons_check.py @@ -2,6 +2,8 @@ The program reads a root CBV and a root SRV (the raw-root fixture), so it translates to DXIL but the compute manifest has no line for a root descriptor. A table-bound control still publishes its manifest. +--requests reports the reason on stdout and leaves no .fail, so watchers keep retrying the key; --watch, +which refuses the key, writes the reason to its .fail. usage: native_compute_manifest_reasons_check.py @@ -18,6 +20,7 @@ sys.path.insert(0, str(HERE)) sys.path.insert(0, str(HERE.parent / "tools" / "startup")) +import gfx2hlsl as G # noqa: E402 import triage_run # noqa: E402 from native_compute_clear_check import write_request # noqa: E402 from native_startup_request_cache_check import ( # noqa: E402 @@ -52,15 +55,26 @@ def main(argv: list[str]) -> int: watched = work / "watched" shutil.copytree(requests, watched) - # 1. --requests still publishes the DXIL and nothing else changes; the .fail names the missing manifest. - out = work / "out" + # 1. --requests in a live cache: the DXIL is published, the reason goes to stdout, and no .fail is left. + # A genuine refusal beside it keeps its .fail. The Python watcher's two selections tell them apart. + live = work / "live" + shutil.copytree(requests, live) + broken = compute_program_words()[:-4] + struct.pack("<2I", 0xFFFFFFFF, 0xBF810000) + refused = "%016x" % put_compute_request( + live, broken, compile_compute_root(sdk, work), state_a(COMPUTE_GROUP, COMPUTE_RSRC2)) + (live / f"{key}.fail").write_text("stale failure\n", encoding="ascii") run = subprocess.run([cli, sdk, work / "frontend", "--jobs", "2", "gfx1013-direct-cs@0", "--requests", - requests, out], capture_output=True, text=True) - assert run.returncode == 0 and "requests=2 compiled=2 refused=0" in run.stdout, (run.stdout, run.stderr) - assert (out / f"{key}.cs.cso").read_bytes().startswith(b"DXBC") - assert not (out / f"{key}.txt").exists() - assert (out / f"{key}.fail").read_text(encoding="ascii") == REASON + "\n", (out / f"{key}.fail").read_text() - assert (out / f"{control}.txt").is_file() and not (out / f"{control}.fail").exists() + live, live], capture_output=True, text=True) + assert run.returncode == 1 and "requests=3 compiled=2 refused=1" in run.stdout, (run.stdout, run.stderr) + retry_all = sorted(int(k, 16) for k in (key, refused)) + assert G.pending_keys(str(live), False) == retry_all, G.pending_keys(str(live), False) + assert G.pending_keys(str(live), True) == [int(key, 16)], G.pending_keys(str(live), True) + assert f"no_manifest input=req_{key}.c67 {REASON}\n" in run.stdout, run.stdout + assert run.stdout.count("no_manifest ") == 1, run.stdout + assert (live / f"{key}.cs.cso").read_bytes().startswith(b"DXBC") + assert not (live / f"{key}.txt").exists() and not (live / f"{key}.fail").exists() + assert (live / f"{control}.txt").is_file() and not (live / f"{control}.fail").exists() + assert (live / f"{refused}.fail").is_file() and not (live / f"{refused}.cs.cso").exists() # 2. --refusals counts it with the same text. summary = json.loads(subprocess.run([cli, "--refusals", requests, "--json"], capture_output=True, @@ -74,6 +88,8 @@ def main(argv: list[str]) -> int: assert watch.returncode == 0 and f"{key}: refused: {REASON}" in watch.stdout, (watch.stdout, watch.stderr) assert f"{control}: compiled compute" in watch.stdout, watch.stdout assert (watched / f"{key}.fail").read_text(encoding="ascii") == REASON + "\n" + # A watcher refusal is a genuine failure: skipped by the repeated pass, retried by the first. + assert G.pending_keys(str(watched), True) == [] and G.pending_keys(str(watched), False) == [int(key, 16)] logs = work / "logs" logs.mkdir() (logs / "stderr.txt").write_text("", encoding="utf-8") diff --git a/tools/startup/compile_dxil.cpp b/tools/startup/compile_dxil.cpp index e038626718..94ee24896c 100644 --- a/tools/startup/compile_dxil.cpp +++ b/tools/startup/compile_dxil.cpp @@ -1030,13 +1030,10 @@ int wmain(int argc, wchar_t** argv) { std::string reason; auto manifest = compile_one(compiler, job_profile(i), inputs[i], outputs[i], argv[2], report, nullptr, true, &reason); if (manifest) publish_atomic(manifest_path, manifest->data(), manifest->size()); - // The DXIL stays published; the .fail names why no manifest was. - if (!manifest && !reason.empty()) { - const auto line = format_fail_line(manifest_refusal(reason)); - publish_atomic(fs::path(stems[i]) += L".fail", line.data(), line.size()); - } else { - fs::remove(fs::path(stems[i]) += L".fail", ignored); - } + // Not a .fail: that file is the watchers' retry marker, and this compile succeeded. + if (!manifest && !reason.empty()) + report << "no_manifest input=" << inputs[i].filename().string() << ' ' << manifest_refusal(reason) << '\n'; + fs::remove(fs::path(stems[i]) += L".fail", ignored); return; } const fs::path manifest_path = fs::path(stems[i]) += L".txt";