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
3 changes: 2 additions & 1 deletion docs/experiments/native-compile-dxil-refusals.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
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
images the dimension and `array`; a texture SRV of dimension 1D, 2D, 3D or 2D array has a line, a
cube or multisampled one does not), 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
Expand Down
8 changes: 7 additions & 1 deletion docs/experiments/startup-compute-native-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ ctest --preset dev --no-tests=error -V -R '^(startup_compute_dispatch(_.*)?|star
## Limits

- Compute only. Graphics pipelines are not translated in-process.
- A scalar buffer load, a texture, a sampler and the typed, half and indexed views are refused.
- A scalar buffer load, a texture, a sampler and the typed, half and indexed views are refused. This is the
in-process route. The published-manifest route (`<key>.txt` from `compile_dxil --requests`) binds a
title's 1D, 2D, 2D-array and 3D texture SRV (`srv N tex1d|tex2d|tex2da|tex3d table R B`). For 1D, 2D-array
and 3D the title's view must be described, have the manifest's dimension and fit its texture, otherwise the
Dispatch is refused (on a dimension mismatch the draw path binds a null view instead). "Fits" is
`address_view_fits`: the view format is the storage format or a member of its typeless family, the mip and
slice range lie inside the texture, and ResourceMinLODClamp is 0. Cube texture SRVs are not published.
- One descriptor shape was dispatched: stride 4 and 320 records, for the input and for the output.
- An indirect Dispatch of a natively translated program was not run.
- A captured request starts with a 36-byte prefix of `v_nop` words before `s_inst_prefetch`. The route passes
Expand Down
4 changes: 3 additions & 1 deletion docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,9 @@ The existing dispatch path records the result, and a program is accepted only wi
fixture has run through it: root constants, raw table buffers loaded per lane (`buffer_load_dword`)
and raw table buffers stored to, with their descriptors in 32-byte table records. Anything else (a
scalar buffer load, a texture, a sampler, a typed or indexed view, an instruction the compiler does
not lower) is refused. The first 16 refusals of a process are logged as
not lower) is refused. Programs published as `<key>.txt` also bind 1D, 2D, 2D-array and 3D texture SRVs
(`srv N tex1d|tex2d|tex2da|tex3d table R B`) from the title's described view of that dimension, or are
refused by name; cube texture SRVs are not published. The first 16 refusals of a process are logged as
`compute pipeline <key> not translated natively: <reason>`. A refused key is left to the
published translations, so `-Translate` can run beside it for those pipelines. A direct module declares
wave size 32, so an adapter without 32-lane waves refuses every program by that name. The in-process
Expand Down
12 changes: 9 additions & 3 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,15 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
b.kind == ComputeViewKind::byte_window_srv) {
srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset
<< '\n';
} else if (b.kind == ComputeViewKind::texture_srv && b.image_dimension == 1 && b.array_count == 1) {
srv_lines << "srv " << b.shader_register << " tex2d table " << b.root_parameter << ' ' << b.byte_offset
<< '\n';
} else if (b.kind == ComputeViewKind::texture_srv && b.array_count == 1 &&
(b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 ||
b.image_dimension == 5)) {
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 {
return refuse(view_shape("SRV", b));
}
Expand Down
32 changes: 29 additions & 3 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// buffers (`srv <i> buf table <param> <byte>` and `srv <i> buf root <param>` inputs, `uav <i> table <param> <byte>`
// outputs, or `uav <i> bufhalf table <param> <byte> bytes <stride>` for typed half stores)
// named by hardware buffer descriptors or 64-bit root SRV addresses, and textures
// (`srv <i> tex2d table <param> <byte>` inputs, `uav <i> tex1d/tex2d/tex2da/tex3d float table <param> <byte> channels <n>` outputs) named
// (`srv <i> tex1d|tex2d|tex2da|tex3d table <param> <byte>` inputs, `uav <i> tex1d/tex2d/tex2da/tex3d float table <param> <byte> channels <n>` outputs) named
// by the token of a view the title created (device slots 18 and 19). `smp`, `smpl` and `smpc` lines become static samplers. Entry
// values come from the compute root constants of slots 37 and 39, or from the descriptor a buffer input or output is
// bound from: its stride and word 3 (`stride`, `descword3`), and word 3, the upper half of word 1 and the record
Expand Down Expand Up @@ -38,6 +38,7 @@ struct ComputeTranslation {
bool root = false;
bool atomic_uint_texture = false;
unsigned channels = 4;
D3D12_SRV_DIMENSION srv_dimension = D3D12_SRV_DIMENSION_UNKNOWN;
unsigned half_buffer_bytes = 0;
};
u64 key = 0;
Expand Down Expand Up @@ -176,6 +177,13 @@ const char* load_compute_translation(ComputeTranslation& tr)
if (!std::strcmp(name, "tex3d")) return D3D12_UAV_DIMENSION_TEXTURE3D;
return D3D12_UAV_DIMENSION_UNKNOWN;
};
const auto srv_dimension = [&] {
if (!std::strcmp(name, "tex1d")) return D3D12_SRV_DIMENSION_TEXTURE1D;
if (!std::strcmp(name, "tex2d")) return D3D12_SRV_DIMENSION_TEXTURE2D;
if (!std::strcmp(name, "tex2da")) return D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
if (!std::strcmp(name, "tex3d")) return D3D12_SRV_DIMENSION_TEXTURE3D;
return D3D12_SRV_DIMENSION_UNKNOWN;
};
if (line.empty() || (std::sscanf(line.c_str(), "group %u %u %u%n", &x, &y, &z, &used) == 3 && whole())) continue;
if (std::sscanf(line.c_str(), "ud %u%n", &declared_uds, &used) == 1 && whole()) continue;
if (std::sscanf(line.c_str(), "udsrc %u rootconst %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uds.size())
Expand Down Expand Up @@ -219,8 +227,11 @@ const char* load_compute_translation(ComputeTranslation& tr)
tr.uavs.back().uav_dimension = uav_dimension();
tr.uavs.back().channels = x;
}
else if (std::sscanf(line.c_str(), "srv %u tex2d table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size())
else if (std::sscanf(line.c_str(), "srv %u %15s table %d %d%n", &i, name, &a, &b, &used) == 4 && whole() &&
i == tr.srvs.size() && srv_dimension() != D3D12_SRV_DIMENSION_UNKNOWN) {
tr.srvs.push_back({a, b, true});
tr.srvs.back().srv_dimension = srv_dimension();
}
else if (std::sscanf(line.c_str(), "resheap %u %u%n", &x, &y, &used) == 2 && whole()) {
if (tr.heap_srvs || !x || x > x2w_startup::max_translated_resheap || y != x2w_startup::translated_resheap_space)
return "a resource heap range outside the supported layout";
Expand All @@ -234,7 +245,7 @@ const char* load_compute_translation(ComputeTranslation& tr)
std::sscanf(line.c_str(), "smpc %u %x %x %x %x%n", &i, &x, &y, &z, &w, &used) == 5) && whole() &&
i == tr.samplers.statics.size())
tr.samplers.read_manifest_line(line.c_str());
else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 2D texture"
else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 1D/2D/2D-array/3D texture"
: line.rfind("uav", 0) == 0 ? "an unsupported compute output view"
: line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant or a buffer descriptor word"
: line.rfind("smp", 0) == 0 ? "a sampler that is not a plain static one" : "an unknown manifest line";
Expand Down Expand Up @@ -542,6 +553,21 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch&
if (!known || record.slot != 18) reason = "an input texture entry is not the token of a shader resource view";
else if (!texture || (resource.Flags & D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE))
reason = "an input texture has no desktop texture to sample";
else if (slot.srv_dimension != D3D12_SRV_DIMENSION_TEXTURE2D) {
// 1D, 2D array and 3D: only the title's own described view of that dimension, inside its texture.
const bool one = slot.srv_dimension == D3D12_SRV_DIMENSION_TEXTURE1D;
const bool array = slot.srv_dimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
if (!described)
reason = one ? "an input 1D texture has no recorded view description"
: array ? "an input 2D array texture has no recorded view description"
: "an input 3D texture has no recorded view description";
else if (desc.ViewDimension != slot.srv_dimension)
reason = one ? "an input texture view is not 1D" : array ? "an input texture view is not 2D array"
: "an input texture view is not 3D";
else if (!x2w_startup::address_view_fits(resource, desc))
reason = "an input texture view does not fit its texture";
else if (x2w_startup::packed_target_format(desc.Format)) reason = "an input texture view has a packed format";
}
else if (described ? desc.ViewDimension != D3D12_SRV_DIMENSION_TEXTURE2D
: resource.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || resource.DepthOrArraySize != 1)
reason = "an input texture view is not 2D";
Expand Down
8 changes: 8 additions & 0 deletions tests/cmake/startup_compute_dispatch_texture_dims.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if(EXISTS "${INTAKE_PYTHON}" AND TARGET startup_stream_consumer)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_compute_dispatch_texture_dims_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_dims_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
set_tests_properties(startup_compute_dispatch_texture_dims_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77)
endforeach()
endif()
31 changes: 28 additions & 3 deletions tests/native_compute_manifest_reasons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "native_compute_output.h"

#include <cstdio>
#include <cstring>
#include <functional>
#include <string>

Expand Down Expand Up @@ -58,9 +59,9 @@ int main() {
{"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) {
{"SRV kind texture_srv cube", [](auto &p) {
p.bindings[0].kind = K::texture_srv;
p.bindings[0].image_dimension = 2;
p.bindings[0].image_dimension = 3;
}},
{"SRV kind texture_srv 2d array", [](auto &p) {
p.bindings[0].kind = K::texture_srv;
Expand Down Expand Up @@ -92,6 +93,30 @@ int main() {
ok ? "" : manifest ? "a manifest" : reason.c_str());
failures += !ok;
}
std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + 1);
// A texture SRV is published under the name of its dimension: the line the runtime's reader takes.
const struct {
unsigned image_dimension;
const char *line;
} published[] = {
{0, "srv 0 tex1d table 1 64\n"},
{1, "srv 0 tex2d table 1 64\n"},
{2, "srv 0 tex3d table 1 64\n"},
{5, "srv 0 tex2da table 1 64\n"},
};
for (const auto &c : published) {
auto program = base();
program.bindings[0].kind = K::texture_srv;
program.bindings[0].image_dimension = c.image_dimension;
reason = "unset";
const auto manifest = format_compute_runtime_manifest(program, &reason);
std::string wanted = expected;
wanted.replace(wanted.find("srv 0 buf table 1 64\n"), std::strlen("srv 0 buf table 1 64\n"), c.line);
const bool ok = manifest && *manifest == wanted && reason == "unset";
std::printf("%s publishes %s", ok ? "ok " : "FAIL", c.line);
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) + 1);
return failures ? 1 : 0;
}
Loading
Loading