Skip to content
Open
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,16 @@ foreach(backend IN ITEMS warp hardware)
ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1")
endforeach()

# List slots 14/33/37/39/45: Dispatch and compute root arguments on a console command list.
add_executable(startup_compute_dispatch tests/startup_compute_dispatch.cpp)
target_compile_features(startup_compute_dispatch PRIVATE cxx_std_17)
target_link_libraries(startup_compute_dispatch PRIVATE d3d12_xs_shim d3d12 dxgi d3dcompiler)
foreach(backend IN ITEMS warp hardware)
add_test(NAME startup_compute_dispatch_root_${backend} COMMAND startup_compute_dispatch ${backend})
set_tests_properties(startup_compute_dispatch_root_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1")
endforeach()

add_executable(startup_nv12_draw tests/startup_nv12_draw.cpp tests/desktop_gpu.cpp)
target_compile_features(startup_nv12_draw PRIVATE cxx_std_17)
target_include_directories(startup_nv12_draw PRIVATE src)
Expand Down Expand Up @@ -2499,7 +2509,7 @@ endforeach()
# Negative control: without slot 43 the first forwarded case is refused, and the fixture must report it.
add_test(NAME startup_list_dispatch_native_skip_srv_warp_control COMMAND startup_list_dispatch_native warp skip-srv)
set_tests_properties(startup_list_dispatch_native_skip_srv_warp_control PROPERTIES TIMEOUT 60
PASS_REGULAR_EXPRESSION "bound: expected no Dispatch line, got 1 Dispatch line\\(s\\)[\r\n]+ x2w-render Dispatch\\(2, 3, 1\\) refused: a compute root SRV is not bound")
PASS_REGULAR_EXPRESSION "bound: expected no Dispatch line, got 1 Dispatch line\\(s\\)[\r\n]+ x2w-render Dispatch\\(2, 3, 1\\) refused: a compute root argument is not bound")
target_sources(offscreen_check PRIVATE tests/startup_image_3d.cpp)
target_sources(offscreen_check PRIVATE tests/startup_image_store.cpp)
target_sources(offscreen_check PRIVATE tests/startup_flat_param.cpp)
Expand Down
5 changes: 3 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check",
"bcpack_formats_check", "startup_stub_consumer", "startup_inline_retire", "startup_resource_retire_title", "startup_table_lock",
"native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check"
"native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check", "startup_compute_dispatch", "startup_root_constant_store", "startup_list_dispatch_check",
"startup_list_dispatch_native", "startup_stream_consumer"
]
},
{ "name": "release", "configurePreset": "release" },
Expand All @@ -50,7 +51,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_mesh_title_snapshot_warp|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run)$"
"name": "^(startup_compute_dispatch_root_warp|startup_compute_dispatch_warp|startup_root_constant_store|startup_list_dispatch[a-z_-]*|bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_mesh_title_snapshot_warp|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run)$"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ The control-flow CPU translator supports [source-built string memory transfers](
| Startup compute D16 image store | Write [four packed half-floats](docs/experiments.md#startup-compute-d16-image-store) per active thread and check all three mips. | `ctest --preset dev --no-tests=error -R '^startup_compute_image_store_d16'` |
| Startup explicit-LOD 2D gather | Dispatch and draw [gfx1013 `image_gather4_l`](docs/experiments.md#explicit-lod-2d-gather) across explicit mips, view offsets, clamped edges, and dynamic per-lane LOD against CPU references. | `ctest --preset dev --no-tests=error -R '^startup_compute_gather_l'` |
| Startup compute buffer atomics | Dispatch [gfx1013 32-bit MUBUF raw buffer atomics](docs/experiments.md#startup-compute-raw-buffer-atomics) with thread contention, `glc` old-value returns, `cmpswap` order, and `EXEC` masking. | `ctest --preset dev --no-tests=error -R '^startup_compute_buffer_atomics'` |
| Startup console-list compute bindings | Forward [compute root UAVs and 32-bit root constants](docs/experiments.md#startup-list-dispatch) through the startup runtime and restore them after a shim pass; dispatch and read back the value on WARP and hardware. | `ctest --preset dev --no-tests=error -R '^startup_compute_dispatch_root_' -V` |
| gfx1030 image loads | Lower [typed RGBA32 and packed RGBA8 2D reads](docs/experiments.md#gfx1030-2d-image-loads), including explicit mip levels, with 32-bit or `a16` addresses and nonzero `dmask` values. Compare the UAV readback against a CPU reference. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_mimg_(load|mip|packed)_'` |
| gfx1030 image queries | Lower [2D mip dimensions and level count](docs/experiments.md#gfx1030-2d-image-resource-queries) for `image_get_resinfo`. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_mimg_resinfo_'` |
| gfx1030 MSAA image load | Lower [`image_msaa_load` for 4× `R32_UINT` 2D input](docs/experiments.md#gfx1030-4-sample-image-load). Compare the four samples per pixel and the untouched UAV words against a CPU reference. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_mimg_msaa_'` |
Expand Down
7 changes: 5 additions & 2 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17571,13 +17571,16 @@ ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_bit_alu_(controls|warp

## Startup list Dispatch

Command-list slot 14 (`Dispatch`) is recorded on the desktop list only when the list is open and direct or compute, a desktop compute pipeline and a desktop compute root signature are bound, the compute root declares no static samplers and only root SRV parameters (slot 43), the compute pipeline was built against that same root signature, every root SRV the root declares was set since the root was bound (a rejected or unaligned replacement clears its binding), and every group count is at most 65535. Zero groups on an axis is forwarded and runs nothing. A root with other parameters is refused with `compute root arguments are not forwarded`, a pipeline from another root with `compute pipeline was built against another root signature`, an unset or rejected root SRV with `a compute root SRV is not bound`. Of the compute root arguments, only root SRVs (slot 43) reach the desktop list: slot 35 records descriptor tables without setting them, and slots 37, 39, 41 and 45 have no handler yet, so a dispatch under any other argument would run with it unset. The first 16 refusals in a process are logged as `x2w-render Dispatch(x, y, z) refused: <reason>`.
Command-list slot 14 (`Dispatch`) is recorded on the desktop list only when the list is open and direct or compute, a desktop compute pipeline and a desktop compute root signature are bound, the compute root declares no static samplers and no parameters other than root SRVs (slot 43), root UAVs (slot 45) and 32-bit root constants (slots 37 and 39), the compute pipeline was built against that same root signature, every declared root SRV, root UAV and constant range was set since the root was bound (a rejected or unaligned replacement clears its binding), and every group count is at most 65535. Zero groups on an axis is forwarded and runs nothing. A root that declares a parameter of another kind, such as a root CBV, a descriptor table or a static sampler, is refused with `compute root arguments are not forwarded`, a pipeline from another root with `compute pipeline was built against another root signature`, an unset or rejected root SRV, root UAV or constant range with `a compute root argument is not bound`. Of the compute root arguments, root SRVs (slot 43), 32-bit root constants (slots 37 and 39) and placed buffer root UAVs (slot 45) reach the desktop list; slot 35 records descriptor tables without setting them, and slot 41 has no handler yet. The first 16 refusals in a process are logged as `x2w-render Dispatch(x, y, z) refused: <reason>`.

`tests/startup_compute_dispatch.cpp` drives slots 86, 25, 33, 37, 39, 45 and 14 of the stand-in on WARP and on a hardware adapter (77 without one) with the debug layer. A subrange at byte 256 is written through a placed buffer root UAV and read back as 59 from the 32 root constants, with sentinels at bytes 0, 128 and 384 untouched. A 33-word write to the 32-word parameter is cut to the words both the store and the desktop list keep, and a same-layout root that wrote its own constants and UAV through the list must be replayed by the restore fixture export before the dispatch reads 59. Calls naming a wrong parameter type or index, an unplaced address, a misaligned address or a rejected placed range must not reach the desktop list, and a Dispatch with an unset root UAV or constant range must be refused.

`tests/startup_list_dispatch_check.cpp` checks the decision without a device; its five mutated runs must fail. `tests/startup_list_dispatch_native.cpp` drives slots 86, 25, 33, 43, 148, 14, 9 and 139 of the stand-in on a desktop device, on WARP and on a hardware adapter (77 without one), with the debug layer when it is installed. Each refused case must log exactly one refusal line with the expected reason: a root SRV never set, a rejected or misaligned slot 43 replacement after a valid one, a root changed and changed back without slot 43, a pipeline built against another root, a root with a descriptor table, a root with a static sampler, an unset root SRV with zero groups, more than 65535 groups, a closed list, and a Reset list without new bindings. A forwarded case must log no line. Around each call on an open list the fixture records a pipeline-statistics query on the desktop list: `CSInvocations` must be 4 per group for a forwarded call and 0 for a refused one. The fully bound call is recorded alone and counted first, so a slot 14 that records nothing fails on its count. Each of the three recordings is executed to a fence, and the debug layer must report no error. The shader only declares its root SRV, so this shows that the desktop `Dispatch` is recorded and runs, not what a shader reads through the bound SRV. The `skip_srv` control drops slot 43 from the first forwarded case and must report that case as refused.

```powershell
cmake --build --preset dev --target startup_list_dispatch_check startup_list_dispatch_native
cmake --build --preset dev --target startup_list_dispatch_check startup_list_dispatch_native startup_compute_dispatch
ctest --preset dev --no-tests=error -R "^startup_list_dispatch" -V
ctest --preset dev --no-tests=error -R "^startup_compute_dispatch_root_" -V
```

## Startup translator: explicit-gradient image_sample_d
Expand Down
9 changes: 3 additions & 6 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1686,12 +1686,9 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch&
barrier.UAV.pResource = views[i].resource;
list->ResourceBarrier(1, &barrier);
}
// The translated root replaced the desktop compute root of the title and its arguments.
if (pass.desktop_compute_root) {
list->SetComputeRootSignature(pass.desktop_compute_root.Get());
for (UINT parameter = 0; parameter < pass.desktop_compute_upload_srvs.size(); ++parameter)
if (const auto address = pass.desktop_compute_upload_srvs[parameter]) list->SetComputeRootShaderResourceView(parameter, address);
}
// The translated root replaced the desktop compute root of the title and its arguments; replay every one of
// them (root SRVs, root UAVs and 32-bit constants) so a later native Dispatch does not run with them unset.
restore_compute_root(pass, list);
++tr->translated;
ReleaseSRWLockExclusive(&draw_lock);
static LONG checks; // as translated draws do: the queue's execute drains the rest
Expand Down
43 changes: 33 additions & 10 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,7 @@ ID3D12Resource* validate_indexed_arguments(Wrapper* self, ID3D12GraphicsCommandL
require_state(self, indices, (index_previous & shader_reads) | D3D12_RESOURCE_STATE_INDEX_BUFFER);

// The clamp changes the native compute root and invalidates its arguments.
// In render mode slot 43 is the forwarded compute parameter setter.
// In render mode slots 37, 39, 43 and 45 are the forwarded compute parameter setters.
restore_compute_root(pass_of(self), list);
return scratch.Get();
}
Expand Down Expand Up @@ -4353,16 +4353,18 @@ void __stdcall list_compute_table(Wrapper* self, UINT parameter, u64 gpu_handle)
log("x2w-render compute descriptor table dropped: parameter %u (%u parameters are kept)", parameter,
x2w_startup::ComputeTables::max_parameters);
}
// Keeps the words of a root constants call; a call outside the 16 x 8 words kept is logged and cut or dropped.
static void store_root_constants(x2w_root_constants::Store& store, const char* kind, UINT parameter, UINT count,
const std::uint32_t* data, UINT offset)
// Keeps the words of a root constants call; a call outside the kept words is logged and cut or dropped. Returns the
// number of words from `offset` that the store kept, so the caller forwards exactly the words the store recorded.
static UINT store_root_constants(x2w_root_constants::Store& store, const char* kind, UINT parameter, UINT count,
const std::uint32_t* data, UINT offset, UINT capacity = x2w_root_constants::words_per_parameter)
{
if (!count || !x2w_local::readable(data, std::size_t{count} * 4)) return;
const auto result = store.set(parameter, count, data, offset);
if (!count || !x2w_local::readable(data, std::size_t{count} * 4)) return 0;
const auto result = store.set(parameter, count, data, offset, capacity);
static LONG refused;
if (result != x2w_root_constants::Result::stored && first_calls(refused, 4))
log("x2w-render %s root constants %s: parameter %u, offset %u, count %u (16 parameters of 8 words are kept)", kind,
result == x2w_root_constants::Result::dropped ? "dropped" : "truncated", parameter, offset, count);
log("x2w-render %s root constants %s: parameter %u, offset %u, count %u (%u words are kept)", kind,
result == x2w_root_constants::Result::dropped ? "dropped" : "truncated", parameter, offset, count, capacity);
return result == x2w_root_constants::Result::dropped ? 0 : (std::min)(count, capacity - offset);
}
// List slot 40 (desktop 36 + 4), SetGraphicsRoot32BitConstants(parameter, count, data, offset).
void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, const std::uint32_t* data, UINT offset)
Expand All @@ -4382,12 +4384,33 @@ void __stdcall list_root_constants(Wrapper* self, UINT parameter, UINT count, co
// List slot 37 (desktop 33 + 4), SetComputeRoot32BitConstant(parameter, value, offset).
void __stdcall list_compute_constant(Wrapper* self, UINT parameter, UINT value, UINT offset)
{
store_root_constants(pass_of(self).compute_constants, "compute", parameter, 1, &value, offset);
Pass& pass = pass_of(self);
UINT capacity = x2w_root_constants::words_per_parameter;
const auto* params = pass.compute_params;
const bool valid_param = params && parameter < params->size() &&
(*params)[parameter].type == D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
if (valid_param) {
capacity = (std::min)(x2w_root_constants::max_words_per_parameter, (*params)[parameter].constants_count);
}
const UINT kept = store_root_constants(pass.compute_constants, "compute", parameter, 1, &value, offset, capacity);
if (auto* list = recording(self); list && pass.desktop_compute_root && valid_param && kept)
list->SetComputeRoot32BitConstant(parameter, value, offset);
}
// List slot 39 (desktop 35 + 4), SetComputeRoot32BitConstants(parameter, count, data, offset).
void __stdcall list_compute_constants(Wrapper* self, UINT parameter, UINT count, const std::uint32_t* data, UINT offset)
{
store_root_constants(pass_of(self).compute_constants, "compute", parameter, count, data, offset);
Pass& pass = pass_of(self);
UINT capacity = x2w_root_constants::words_per_parameter;
const auto* params = pass.compute_params;
const bool valid_param = params && parameter < params->size() &&
(*params)[parameter].type == D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
if (valid_param) {
capacity = (std::min)(x2w_root_constants::max_words_per_parameter, (*params)[parameter].constants_count);
}
// Forward exactly the words the store kept, so a dispatch never runs with words one side has and the other does not.
const UINT kept = store_root_constants(pass.compute_constants, "compute", parameter, count, data, offset, capacity);
if (auto* list = recording(self); list && pass.desktop_compute_root && valid_param && kept)
list->SetComputeRoot32BitConstants(parameter, kept, data, offset);
}
// List slot 47 (desktop 43 + 4), IASetIndexBuffer(view).
void __stdcall list_index_buffer(Wrapper* self, const D3D12_INDEX_BUFFER_VIEW* view)
Expand Down
Loading
Loading