Skip to content
Open
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: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4759,6 +4759,12 @@ 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})
if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME startup_compute_dispatch_texture_native_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter} "$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(startup_compute_dispatch_texture_native_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
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})
Expand Down
9 changes: 5 additions & 4 deletions docs/experiments/startup-compute-native-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ cache and no offline translator, and compares all 320 output words with a CPU re
3. The entry values and views fill the same `ComputeTranslation` a published `<key>.txt` fills. The existing
dispatch path then resolves the table descriptors, sets the resource states and records the Dispatch.

Accepted: root constants, a raw table buffer loaded per lane and a raw table buffer stored to. These are the
bindings the fixture runs. Refused: every other view kind (a scalar buffer load included), a sampler, more than
32 entry values or inputs or 8 outputs, an adapter without 32-lane waves, and whatever the frontend refuses. The
Accepted bindings include root constants, scalar and per-lane raw table buffer inputs, raw buffer outputs,
2D texture inputs, and four-channel float 1D, 2D, 2D array and 3D texture outputs. The stand-in refuses other
view kinds, samplers, more than 32 entry values or inputs or 8 outputs, and adapters that lack wave32 or report
a shader model below 6.6. The
stand-in logs the first 16 refusals of a process with their reason. A refused key is left to a published
translation. The in-process translation is tried once per key and before a published `<key>.txt`.

Expand Down Expand Up @@ -44,7 +45,7 @@ decoder, and the consumer's `dispatch-records32` mode writes the table with the
5. Order: the first program runs again with its published translation in the cache. The log still names the
native translation, and all 320 words match.

Without 32-lane waves, step 1 instead checks that the native translation is refused by that name with every word
Without wave32 or shader model 6.6, step 1 instead checks the named capability refusal with every word
untouched. Step 2 is left out, steps 3 and 4 run, step 5 runs the first program through its published
translation, and the check exits 77.

Expand Down
37 changes: 30 additions & 7 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,20 +943,29 @@ pipelines, and the cache can start empty: the request files the stand-in wrote a
against their key, translated and compiled to DXIL in the process. The compiler's own cache goes to
`<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. 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
The existing dispatch path binds root constants and views in 32-byte table records. Buffer views
include scalar buffer SRVs (`buffer_srv`), per-lane raw buffer SRVs (`raw_vector_srv`), and raw buffer
UAVs. Texture views include 2D SRVs and four-channel float 1D, 2D, 2D array, and 3D UAVs
(`texture_uav` and `half4_texture_uav`). Samplers, typed or indexed buffer views, and instructions
outside the compiler's supported set are refused. 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
published translations, so `-Translate` can run beside it for those pipelines. A direct module requires
shader model 6.6 and wave32. The in-process
translation is tried once per key and before a published `<key>.txt`. It covers compute only; graphics
pipelines still need a published translation.

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 wave32 or shader model 6.6 the cases check the named refusal
and untouched output before the test returns 77.

### Compute pipeline requests

Expand Down Expand Up @@ -3613,3 +3622,17 @@ 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

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.

The native offline fixture compiles 1D, 3D and 3D NSA programs, checks the published DXIL and
manifest, and compares every mip-one word after Dispatch. It also checks that mismatched views,
an invalid 3D W range and an invalid 1D mip leave the output unchanged. An adapter without
wave32 or shader model 6.6 can verify the native manifests before returning a capability skip for Dispatch.
The separate texture dispatch fixture exercises the existing Python-published path.

`ctest --preset dev --no-tests=error -R '^startup_compute_dispatch_texture_(native_)?(warp|hardware)$' -V`
12 changes: 10 additions & 2 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,16 @@ std::optional<std::string> format_compute_runtime_manifest(const NativeComputeSh
uav_lines << "uav " << b.shader_register << " table " << b.root_parameter << ' ' << b.byte_offset
<< '\n';
} else if ((b.kind == ComputeViewKind::texture_uav || b.kind == ComputeViewKind::half4_texture_uav) &&
(b.image_dimension == 1 || b.image_dimension == 5) && b.array_count == 1) {
uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : " 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 std::nullopt;
}
uav_lines << "uav " << b.shader_register << ' ' << tex
<< " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n";
} else {
return std::nullopt;
Expand Down
65 changes: 54 additions & 11 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ bool float_output_format(DXGI_FORMAT format)
std::unordered_map<u64, ComputeTranslation>& compute_translations() { static std::unordered_map<u64, ComputeTranslation> m; return m; }
LONG compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled;

// 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;
}

bool adapter_reports_shader_model_below_6_6()
{
D3D12_FEATURE_DATA_SHADER_MODEL model{D3D_SHADER_MODEL_6_6};
return SUCCEEDED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &model, sizeof(model))) &&
model.HighestShaderModel < D3D_SHADER_MODEL_6_6;
}

// 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 @@ -193,16 +209,25 @@ 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 does not declare a wave size. Report the adapter capability alongside the PSO failure.
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)";
if (adapter_reports_shader_model_below_6_6())
return "pipeline creation failed (adapter shader model below 6.6)";
}
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;
}

// 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 it loads per lane (buffer_load_dword) and raw table buffers it stores to.
// and with no offline translator running. The dispatch path below binds root constants and supported table views.
// 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 All @@ -221,22 +246,40 @@ bool translate_compute_natively(ComputeTranslation& tr)
std::sort(program.bindings.begin(), program.bindings.end(),
[](const auto& a, const auto& b) { return a.shader_register < b.shader_register; });
for (const auto& view : program.bindings) {
// The two kinds a fixture has run through this path: a raw buffer read per lane, and one written.
const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav;
using Kind = x2w::ComputeViewKind;
// Match the float texture and buffer slots in format_compute_runtime_manifest.
const bool texture_output = view.kind == Kind::texture_uav || view.kind == Kind::half4_texture_uav;
const bool output = texture_output || view.kind == Kind::raw_buffer_uav;
const bool texture_input = view.kind == Kind::texture_srv && view.image_dimension == 1;
auto dimension = D3D12_UAV_DIMENSION_UNKNOWN;
if (texture_output) {
switch (view.image_dimension) {
case 0: dimension = D3D12_UAV_DIMENSION_TEXTURE1D; break;
case 1: dimension = D3D12_UAV_DIMENSION_TEXTURE2D; break;
case 2: dimension = D3D12_UAV_DIMENSION_TEXTURE3D; break;
case 5: dimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; break;
}
}
auto& slots = output ? tr.uavs : tr.srvs;
if ((!output && view.kind != x2w::ComputeViewKind::raw_vector_srv) || view.array_count != 1 ||
const bool supported = view.kind == Kind::raw_buffer_uav || view.kind == Kind::raw_vector_srv ||
view.kind == Kind::buffer_srv || texture_input ||
dimension != D3D12_UAV_DIMENSION_UNKNOWN;
if (!supported || 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)});
slots.push_back({static_cast<int>(view.root_parameter), static_cast<int>(view.byte_offset),
texture_input || texture_output});
if (texture_output)
slots.back().uav_dimension = dimension;
}
if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8)
throw std::runtime_error("a sampler, or 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)
// Direct modules use shader model 6.6 with WaveSize(32).
if (adapter_32_lane_waves() != 1)
throw std::runtime_error("the adapter has no 32-lane waves");
if (adapter_reports_shader_model_below_6_6())
throw std::runtime_error("the adapter reports shader model below 6.6");
// Never released: a static destructor would release DXC after its module may have detached.
static x2w::ShaderDxilCompiler* const compiler =
new x2w::ShaderDxilCompiler(x2w::ShaderDxilCompiler::runtime_worker(sdk));
Expand Down
Loading
Loading