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
22 changes: 20 additions & 2 deletions docs/experiments/native-compile-dxil-refusals.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,31 @@
- 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 `<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
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 `<key>.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: <reason>`.

## 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
```

Expand Down
67 changes: 53 additions & 14 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,51 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
return verified(std::move(pair));
}

std::optional<std::string> 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<size_t>(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<std::string> format_compute_runtime_manifest(const NativeComputeShader &program, std::string *reason) {
auto refuse = [&](std::string why) -> std::optional<std::string> {
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<unsigned>(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) {
Expand All @@ -751,11 +784,15 @@ std::optional<std::string> 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
Expand All @@ -764,11 +801,11 @@ std::optional<std::string> 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';
Expand All @@ -785,17 +822,19 @@ std::optional<std::string> 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]);
Expand All @@ -812,7 +851,7 @@ std::optional<std::string> 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()
Expand Down
4 changes: 3 additions & 1 deletion src/direct_compute_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned> &rtv_formats = {});
std::optional<std::string> 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<std::string> 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<std::string> format_graphics_runtime_manifest(const DirectGraphicsPair &pair,
std::string_view rtv_request = {});
Expand Down
15 changes: 15 additions & 0 deletions tests/cmake/native_compute_manifest_reasons.cmake
Original file line number Diff line number Diff line change
@@ -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$<$<CONFIG:Debug>: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"
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_compute_manifest_reasons_requests PROPERTIES TIMEOUT 60)
endif()
endif()
97 changes: 97 additions & 0 deletions tests/native_compute_manifest_reasons.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdio>
#include <functional>
#include <string>

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<void(NativeComputeShader &)> 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;
}
Loading
Loading