Skip to content
Closed
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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4967,9 +4967,13 @@ if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_compute_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
unset(texture_native_args)
if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
set(texture_native_args "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
endif()
add_test(NAME startup_compute_dispatch_texture_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
"${DXC_EXECUTABLE}" ${adapter} ${texture_native_args})
add_test(NAME startup_slot67_indirect_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_slot67_indirect_dispatch_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
Expand Down
36 changes: 33 additions & 3 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,14 @@ against their key, translated and compiled to DXIL in the process. The compiler'
`<shader cache>\native`. Nothing is published as `<key>.txt`.

The existing dispatch path records the result, and a program is accepted only with the bindings a
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. A 2D texture can be
fixture has run through it: root constants, scalar buffer SRVs (`buffer_srv`), raw table buffers loaded
per lane (`buffer_load_dword`) and raw table buffers stored to, with their descriptors in 32-byte table
records. Four-channel float 1D, 2D, 2D-array and 3D texture UAVs (`texture_uav` and `half4_texture_uav`)
are bound as outputs. A 2D texture can be
sampled through samplers whose four words are constants: they become static samplers with the
descriptor's MIN_LOD and MAX_LOD, or comparison samplers
([fixture and results](experiments/startup-compute-native-samplers.md)). Anything else (a
scalar buffer load, a sampler read from memory, a typed or indexed view, an instruction the compiler does
sampler read from memory, a typed or indexed view, an instruction the compiler does
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
Expand All @@ -1033,6 +1035,15 @@ pick up a rebuilt output (by the code path; no test covers the reload). Compute
Check with `ctest --preset dev -R '^startup_compute_dispatch_native_(warp|hardware)$' -V`
([`tests/startup_compute_dispatch_native_check.py`](../tests/startup_compute_dispatch_native_check.py);
[route, controls and results](experiments/startup-compute-native-dispatch.md)).
The #2958/#2993 fixture reads back a 3D float store fed by a scalar buffer SRV and a 2D texture SRV.
The consumer creates the views with the adapter's descriptor increment and copies their tokens
into a packed guest table when the increment exceeds 32 bytes. A zero-size W range must translate
natively, be refused at Dispatch, and leave all 6,144 volume words untouched.
Targeted in-process readbacks also check a mip-one 1D float store, a 2D-array float store into
relative slice 1 (physical slice 2), and a packed D16 store into an RGBA16_FLOAT texture with
round-to-nearest-even input conversion. Each case checks every output value, including sentinels
outside the store region. On adapters without 32-lane waves the cases check the named refusal
and untouched output before the test returns 77.

### Compute pipeline requests

Expand Down Expand Up @@ -4083,3 +4094,22 @@ before any desktop copy, leaving a sentinel-filled readback buffer unchanged. On
list refuses boxes with an unaligned right or bottom edge, copies the aligned 4x4 block, and reads back
all eight block bytes with the next byte unchanged. Reproduce the portable and wrapped-list checks with
`ctest --preset dev --no-tests=error -R '^startup_list_copy_texture' -V`.

### Offline compute manifests for 3D and 1D UAVs

The runtime half of #2902 is ported to `cpp-migration`. For offline compute
requests, the C++ formatter emits `uav N tex3d float table P OFF channels 4` and
`uav N tex1d float table P OFF channels 4`. The stand-in validates UAV view
dimensions and mip levels, including the W-slice range within the selected 3D mip.

On an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100), the 3D, 3D NSA and 1D
store cases matched their mip-one words after `compile_dxil` published the translations. The mismatched-view,
3D W-range and 1D mip controls were refused with their sentinels intact.

If a published compute PSO fails to create, the refusal stays `pipeline creation failed`, and the stand-in adds
the adapter's 32-lane wave capability as observed: `(adapter has no 32-lane waves)`, or `(adapter wave capability
query failed)`. The manifest records no wave size, so this does not say the shader needed one. The test knows its
native modules declare `WaveSize(32)`, so the native 3D, 3D NSA and 1D cases skip on WARP only for
`pipeline creation failed (adapter has no 32-lane waves)`. Any other PSO failure fails the test.
On WARP and hardware, the `gfx2hlsl.py` translations of the same programs require successful 3D, 3D NSA and 1D
mip-one readback and check the same mismatched-view, 3D W-range and 1D mip refusals with sentinels intact.
13 changes: 10 additions & 3 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,16 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
uav_lines << "uav " << b.shader_register << ' ' << dimension << " float table " << b.root_parameter
<< ' ' << b.byte_offset << " channels " << channels << '\n';
} else if ((b.kind == ComputeViewKind::texture_uav || b.kind == ComputeViewKind::half4_texture_uav) &&
(b.image_dimension == 1 || b.image_dimension == 5 ||
(b.kind == ComputeViewKind::texture_uav && b.image_dimension == 2)) && b.array_count == 1) {
uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : b.image_dimension == 2 ? " tex3d" : " tex2d")
b.array_count == 1) {
const char *tex;
switch (b.image_dimension) {
case 0: tex = "tex1d"; break;
case 1: tex = "tex2d"; break;
case 2: tex = "tex3d"; break;
case 5: tex = "tex2da"; break;
default: return refuse(view_shape("UAV", b));
}
uav_lines << "uav " << b.shader_register << ' ' << tex
<< " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n";
} else {
return refuse(view_shape("UAV", b));
Expand Down
47 changes: 37 additions & 10 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ std::unordered_map<u64, ComputeTranslation>& compute_translations() { static std
LONG compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled;
LONG compute_inputs_gpu_copied, compute_inputs_snapshot, compute_inputs_snapshot_kib; // inputs by path: this list's GPU copy, a title snapshot

// Whether the adapter runs 32-lane waves: 1 yes, 0 no, -1 the capability query failed.
int adapter_32_lane_waves()
{
D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{};
if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))))
return -1;
return waves.WaveOps && waves.WaveLaneCountMin <= 32 && waves.WaveLaneCountMax >= 32;
}

// The root signature and pipeline of a translation whose entry values and views are filled in. Returns why it is
// unavailable, or null when it is ready.
const char* create_compute_pipeline(ComputeTranslation& tr, const void* code, std::size_t bytes)
Expand Down Expand Up @@ -276,7 +285,16 @@ const char* load_compute_translation(ComputeTranslation& tr)
}
x2w_startup::ComPtr<ID3DBlob> code;
if (!cache_path(path, L"", tr.key, L".cs.cso") || FAILED(D3DReadFileToBlob(path, &code))) return "no compiled program";
if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) return failure;
if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) {
// The manifest carries no wave size, so the failure stays the reason and the adapter's 32-lane wave
// capability is only reported next to it, as observed. It does not say the shader needed that wave size.
if (!std::strcmp(failure, "pipeline creation failed")) {
const int waves = adapter_32_lane_waves();
if (waves < 0) return "pipeline creation failed (adapter wave capability query failed)";
if (!waves) return "pipeline creation failed (adapter has no 32-lane waves)";
}
return failure;
}
log("x2w-draw compute pipeline %016llx translated: %zu entry values, %zu inputs, %zu outputs", tr.key, tr.uds.size(),
tr.srvs.size(), tr.uavs.size());
return nullptr;
Expand All @@ -285,8 +303,9 @@ const char* load_compute_translation(ComputeTranslation& tr)
// X2W_NATIVE_SHADERS=<directory of dxcompiler.dll and dxil.dll>: the first Dispatch of a slot 67 request translates
// it in this process with the C++ compiler (src/gfx1013_compute_native.cpp), before a published <key>.txt is read
// and with no offline translator running. The dispatch path below binds the result, so a program is accepted only
// with root constants, raw table buffers and exact-width typed texture outputs. The constant sampler words the
// compiler resolved become static samplers.
// with root constants, raw table buffers, 2D texture inputs, four-channel float 1D, 2D, 2D-array and 3D texture
// outputs and exact-width typed texture outputs. The constant sampler words the compiler resolved become static
// samplers.
// A refusal is logged and leaves the key to the published translations. draw_lock held. Returns whether tr is ready.
bool translate_compute_natively(ComputeTranslation& tr)
{
Expand Down Expand Up @@ -349,15 +368,25 @@ bool translate_compute_natively(ComputeTranslation& tr)
const bool texture_input = (view.kind == x2w::ComputeViewKind::texture_srv ||
view.kind == x2w::ComputeViewKind::comparison_texture_srv) &&
view.image_dimension == 1;
const bool volume = view.kind == x2w::ComputeViewKind::texture_uav && view.image_dimension == 2;
const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || volume || channels;
// Four-channel float texture outputs, as format_compute_runtime_manifest writes them.
auto float4_dimension = D3D12_UAV_DIMENSION_UNKNOWN;
if (view.kind == x2w::ComputeViewKind::texture_uav || view.kind == x2w::ComputeViewKind::half4_texture_uav) {
switch (view.image_dimension) {
case 0: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE1D; break;
case 1: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE2D; break;
case 2: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; break;
case 5: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; break;
}
}
const bool float4_output = float4_dimension != D3D12_UAV_DIMENSION_UNKNOWN;
const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || float4_output || channels;
auto& slots = output ? tr.uavs : tr.srvs;
if ((!output && !texture_input && view.kind != x2w::ComputeViewKind::raw_vector_srv && !x2w::accepts_cbv_window(view.kind)) || view.array_count != 1 ||
view.root_parameter >= 16 || view.shader_register != slots.size())
throw std::runtime_error("view kind " + std::to_string(static_cast<unsigned>(view.kind)) +
" is not bound for a natively translated program");
slots.push_back({static_cast<int>(view.root_parameter), static_cast<int>(view.byte_offset), volume || texture_input});
if (volume) slots.back().uav_dimension = D3D12_UAV_DIMENSION_TEXTURE3D;
slots.push_back({static_cast<int>(view.root_parameter), static_cast<int>(view.byte_offset), float4_output || texture_input});
if (float4_output) slots.back().uav_dimension = float4_dimension;
// The dispatch path takes an input of any other dimension for a described 1D, 2D-array or 3D view.
if (texture_input) slots.back().srv_dimension = D3D12_SRV_DIMENSION_TEXTURE2D;
slots.back().half_typed_bytes = half_typed ? view.required_bytes : 0;
Expand Down Expand Up @@ -385,9 +414,7 @@ bool translate_compute_natively(ComputeTranslation& tr)
if (tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8)
throw std::runtime_error("more entry values, inputs or outputs than the dispatch path binds");
// A direct module declares wave size 32 (src/dxil_module.h): without it the pipeline cannot be created.
D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{};
if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) ||
!waves.WaveOps || waves.WaveLaneCountMin > 32 || waves.WaveLaneCountMax < 32)
if (adapter_32_lane_waves() != 1)
throw std::runtime_error("the adapter has no 32-lane waves");
// Never released: a static destructor would release DXC after its module may have detached.
static x2w::ShaderDxilCompiler* const compiler =
Expand Down
Loading
Loading