From 9895ec1cddc4fbb99c658bec624a40595f5fce11 Mon Sep 17 00:00:00 2001 From: Ammar Abdelfattah <241957358+Ammmae0x@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:57:12 +0200 Subject: [PATCH 1/3] runtime: bind indexed atomic UAVs in the direct compute runtime path Publish ComputeViewKind::indexed_atomic_uav in format_compute_runtime_manifest as 'uav atomic table ' for a single 4-byte view, and bind it in the startup dispatch path from a slot-19 token view, with the view's {stride, count} as root constants at b(register + 1), matching NativeComputePipeline. Hardware-descriptor atomics and unsupported token shapes stay refused by name. Refs #3224, #2935 --- .../experiments/compute-indexed-atomic-uav.md | 63 +++++ src/direct_compute_cache.cpp | 7 + src/startup_stubs/d3d12_compute_dispatch.inl | 55 ++++- .../translated_sampler_bindings.h | 15 +- .../startup_compute_indexed_atomic_uav.cmake | 17 ++ tests/native_compute_manifest_reasons.cpp | 26 +- ...tartup_compute_indexed_atomic_uav_check.py | 224 ++++++++++++++++++ 7 files changed, 401 insertions(+), 6 deletions(-) create mode 100644 docs/experiments/compute-indexed-atomic-uav.md create mode 100644 tests/cmake/startup_compute_indexed_atomic_uav.cmake create mode 100644 tests/startup_compute_indexed_atomic_uav_check.py diff --git a/docs/experiments/compute-indexed-atomic-uav.md b/docs/experiments/compute-indexed-atomic-uav.md new file mode 100644 index 0000000000..524f43f498 --- /dev/null +++ b/docs/experiments/compute-indexed-atomic-uav.md @@ -0,0 +1,63 @@ +# Indexed atomic UAVs in the direct compute runtime path + +The direct gfx1013 compute translator lowers an indexed `buffer_atomic_*` +(`idxen`) to an `atomicBinOp`/`atomicCompareExchange` on a raw buffer UAV, +reading the view's `{stride, count}` from the constant buffer at +`b(uav register + 1)` and testing the lane index against the count before +multiplying by the stride. That binding, `ComputeViewKind::indexed_atomic_uav`, +previously had no runtime manifest, so `compile_dxil` reported +`compiled, no runtime manifest: UAV kind indexed_atomic_uav` and the dispatch +path never bound it. + +## Contract + +`format_compute_runtime_manifest` publishes the view only as a single +4-byte view: + +```text +uav atomic table +``` + +Any other shape (a descriptor array, or a `required_bytes` other than 4) +stays refused by name as `UAV kind indexed_atomic_uav`. + +The startup dispatch path (`src/startup_stubs/d3d12_compute_dispatch.inl`) +parses that line and builds a root signature with one extra 32-bit-constants +parameter per indexed atomic UAV, after the view table and in UAV order, +with `ShaderRegister = uav register + 1` and two values — the same layout +`NativeComputePipeline` builds. The in-process native translation classifies +the binding as an output the same way, so a program translated in-process +binds identically. + +Binding is token-only: the output must be a slot-19 token view. At dispatch +time the shared `native_buffer_store_view` check derives `{stride, count}` +from that view — structured views need a stride that is a multiple of 4 and +at most 2048 bytes, raw views need `R32_TYPELESS` with no stride, typed views +need `R32_UINT` or `R32_SINT` — and rewrites it to the raw `R32_TYPELESS` +view the atomic operates on. A view that fails that check is refused as +`an indexed atomic output view has an unsupported stride or range`. An +indexed atomic output bound from a hardware descriptor instead of a token is +refused as `an indexed atomic output needs a slot-19 token view`. Multiple +indexed atomic UAVs each get their own root-constants parameter; the +manifest's existing caps (8 UAVs, 32 user-data words) keep the root +signature inside the root-cost budget. + +## Verification + +`startup_compute_indexed_atomic_uav_controls` publishes the synthetic +program through `compile_dxil` and checks the manifest line, with no +`.cs.hlsl` sidecar. `startup_compute_indexed_atomic_uav_warp` and +`_hardware` dispatch it through the stand-in's command list: every lane +adds 1 to the indexed counter at byte index `4 * lane` over +`Dispatch(3, 2, 2)`, so each addressed dword gains 12. Raw, structured +stride-8 and typed `R32_UINT` token views are checked, each with its own +addressed dwords, plus six token shapes and a hardware descriptor that must +each refuse with their own reason and leave the output untouched, and a +native in-process translation of the same program. The pure-Python controls +(program encoding, table loads, `idxen` atomic, per-shape expectations and +token views) run without Windows. + +```powershell +cmake --build --preset dev --target compile_dxil startup_stream_consumer offscreen_check +ctest --preset dev --no-tests=error -R '^startup_compute_indexed_atomic_uav_(controls|warp|hardware)$' --output-on-failure +``` diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 79dcc6b3c5..57dc9ff4ba 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -987,6 +987,13 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh const char *dimension = b.image_dimension == 2 ? "tex3d" : b.image_dimension == 5 ? "tex2da" : "tex2d"; uav_lines << "uav " << b.shader_register << ' ' << dimension << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels " << channels << '\n'; + } else if (b.kind == ComputeViewKind::indexed_atomic_uav && b.array_count == 1 && + b.required_bytes == 4) { + // One indexed atomic UAV: the runtime binds it from a slot-19 token view and fills the + // {stride, count} root constants the translated program reads at b(register + 1). Any other + // shape stays refused by name below. + uav_lines << "uav " << b.shader_register << " atomic 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.kind == ComputeViewKind::texture_uav && b.image_dimension == 2)) && b.array_count == 1) { diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 164cbe9d0e..90c2037492 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -5,7 +5,9 @@ // outputs, or `uav bufhalf table bytes ` for typed half stores) // named by hardware buffer descriptors or 64-bit root SRV addresses, and textures // (`srv tex1d|tex2d|tex2da|tex3d table ` inputs, `uav tex1d/tex2d/tex2da/tex3d float table channels ` 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 +// by the token of a view the title created (device slots 18 and 19). An indexed buffer atomic +// (`uav atomic table `) is bound only from a slot-19 token view: the view's {stride, count} +// are bound as root constants at b(u + 1), matching the native compute pipeline. `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 // count of an output (`uav_descword3`, `uav_stride`, `uav_numrecords`). Any other manifest line makes the translation @@ -41,6 +43,7 @@ struct ComputeTranslation { bool packed_d16_x = false; unsigned scalar_window = 0; bool atomic_uint_texture = false; + bool atomic = false; // an indexed atomic UAV: {stride, count} root constants at b(u + 1) unsigned channels = 4; D3D12_SRV_DIMENSION srv_dimension = D3D12_SRV_DIMENSION_UNKNOWN; unsigned half_buffer_bytes = 0; @@ -110,8 +113,13 @@ LONG compute_inputs_gpu_copied, compute_inputs_snapshot, compute_inputs_snapshot const char* create_compute_pipeline(ComputeTranslation& tr, const void* code, std::size_t bytes) { // Parameter 0 keeps one constant for a program without entry values: a constants parameter cannot be empty. + // One 32-bit-constants parameter per indexed atomic UAV follows the view table, in UAV order. + std::vector atomic_registers; + for (UINT i = 0; i < tr.uavs.size(); ++i) + if (tr.uavs[i].atomic) atomic_registers.push_back(i); if (FAILED(x2w_startup::create_translated_root(device_of(the_device), static_cast(tr.uds.empty() ? 1 : tr.uds.size()), - static_cast(tr.srvs.size()), tr.samplers, &tr.root, static_cast(tr.uavs.size()), false, tr.heap_srvs))) + static_cast(tr.srvs.size()), tr.samplers, &tr.root, static_cast(tr.uavs.size()), false, tr.heap_srvs, + static_cast(atomic_registers.size()), atomic_registers.data()))) return "root signature creation failed"; D3D12_COMPUTE_PIPELINE_STATE_DESC desc{}; desc.pRootSignature = tr.root.Get(); @@ -218,6 +226,11 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.srvs.push_back({c, d, false, true, a, b, x, y}); else if (std::sscanf(line.c_str(), "uav %u table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uavs.size()) tr.uavs.push_back({a, b}); + else if (std::sscanf(line.c_str(), "uav %u atomic table %d %d%n", &i, &a, &b, &used) == 3 && whole() && + i == tr.uavs.size()) { + tr.uavs.push_back({a, b}); + tr.uavs.back().atomic = true; + } else if (std::sscanf(line.c_str(), "uav %u bufhalf table %d %d bytes %u%n", &i, &a, &b, &x, &used) == 4 && whole() && i == tr.uavs.size() && x2w::native_half_buffer_format(x) != DXGI_FORMAT_UNKNOWN) { tr.uavs.push_back({a, b}); @@ -338,7 +351,9 @@ bool translate_compute_natively(ComputeTranslation& tr) const bool half_typed = packed_x || view.kind == x2w::ComputeViewKind::half_buffer_uav; const bool texture_input = view.kind == x2w::ComputeViewKind::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; + const bool atomic = view.kind == x2w::ComputeViewKind::indexed_atomic_uav; + const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || volume || channels || + atomic; 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()) @@ -348,6 +363,7 @@ bool translate_compute_natively(ComputeTranslation& tr) if (volume) slots.back().uav_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; slots.back().half_typed_bytes = half_typed ? view.required_bytes : 0; slots.back().packed_d16_x = packed_x; + if (atomic) slots.back().atomic = true; if (x2w::accepts_cbv_window(view.kind)) slots.back().scalar_window = view.required_bytes; if (channels) { @@ -568,6 +584,9 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& Wrapper* wrapper; std::uint32_t words[4]; // a buffer's descriptor words as it was bound from, and its stride UINT stride; + // An indexed atomic UAV: the {stride, count} root constants bound at parameter 2 + its UAV index. + UINT atomic_stride = 0, atomic_count = 0; + bool atomic = false; }; static_assert(sizeof(D3D12_SHADER_RESOURCE_VIEW_DESC) >= ViewRecord::srv_desc_bytes); static_assert(sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC) >= ViewRecord::uav_desc_bytes); @@ -839,6 +858,17 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& if (views[input].resource == token.resource) reason = "an output buffer is also an input"; if (!reason && !retain_with_recording(self, x2w_startup::ComPtr(token.resource))) reason = "an output token's backing could not be retained with the recording"; + // An indexed atomic UAV reads its {stride, count} from root constants at b(u + 1). The shared + // store-view check derives them from the token's view and rewrites it to the raw R32 view the + // atomic operates on; any other shape is refused by that check's name. + x2w::IndexedAtomicView atomic_shape{}; + D3D12_UNORDERED_ACCESS_VIEW_DESC atomic_view{}; + if (!reason && slot.atomic) { + const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::indexed_atomic_uav, 0, 0, 0, 4}; + atomic_view = token.view; + if (!x2w::native_buffer_store_view(binding, atomic_view, token.backing.Width, &atomic_shape)) + reason = "an indexed atomic output view has an unsupported stride or range"; + } if (!tr->logged_token_output || (!reason && !tr->logged_bound_token_output)) { tr->logged_token_output = true; if (!reason) tr->logged_bound_token_output = true; @@ -856,8 +886,19 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& views[i].described = true; views[i].desc.uav = token.view; } + if (!reason && slot.atomic) { + views[i].described = true; + views[i].desc.uav = atomic_view; + views[i].atomic = true; + views[i].atomic_stride = atomic_shape.stride; + views[i].atomic_count = atomic_shape.count; + } continue; } + if (slot.atomic) { + reason = "an indexed atomic output needs a slot-19 token view"; + break; + } if (slot.half_typed_bytes) { reason = "formatted D16 write needs the original typed buffer view"; break; @@ -1023,6 +1064,14 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& list->SetComputeRootSignature(tr->root.Get()); if (!tr->uds.empty()) list->SetComputeRoot32BitConstants(0, static_cast(tr->uds.size()), values, 0); if (n) list->SetComputeRootDescriptorTable(1, D3D12_GPU_DESCRIPTOR_HANDLE{draw_heap->GetGPUDescriptorHandleForHeapStart().ptr + u64{first} * draw_heap_increment}); + // Indexed atomic UAVs: one {stride, count} pair per atomic output, at parameter 2 + its UAV index, + // matching the root signature create_compute_pipeline built. + UINT atomic_parameter = 2; + for (std::size_t i = inputs; i < count; ++i) { + if (!views[i].atomic) continue; + const UINT pair[2] = {views[i].atomic_stride, views[i].atomic_count}; + list->SetComputeRoot32BitConstants(atomic_parameter++, 2, pair, 0); + } if (dispatch.signature) { require_state(self, dispatch.argument, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); list->ExecuteIndirect(dispatch.signature, 1, dispatch.argument, dispatch.offset, nullptr, 0); diff --git a/src/startup_stubs/translated_sampler_bindings.h b/src/startup_stubs/translated_sampler_bindings.h index 658d0a5ecf..255765fbb3 100644 --- a/src/startup_stubs/translated_sampler_bindings.h +++ b/src/startup_stubs/translated_sampler_bindings.h @@ -118,11 +118,15 @@ inline std::vector decode_statics(const TranslatedSam inline UINT sampler_root_parameter(UINT views) { return views ? 2u : 1u; } // Parameter 1, when there are views, is one table: SRVs t0.. first, then UAVs u0.., then bounded resheap SRVs (space 2). +// `atomic` names the UAV registers (one per indexed atomic UAV, in UAV order) that each get a 32-bit-constants +// parameter after the view table: the translated program reads the view's {stride, count} from b(register + 1), +// as NativeComputePipeline binds it. The sampler-heap table, when present, follows those parameters. inline HRESULT create_translated_root(ID3D12Device* device, UINT constants, UINT srvs, const TranslatedSamplers& samplers, ID3D12RootSignature** out, UINT uavs = 0, - bool input_assembler = false, UINT heap_srvs = 0) + bool input_assembler = false, UINT heap_srvs = 0, UINT atomic = 0, + const UINT *atomic_registers = nullptr) { - D3D12_ROOT_PARAMETER parameters[3]{}; + D3D12_ROOT_PARAMETER parameters[11]{}; parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; parameters[0].Constants.Num32BitValues = constants; // A compute program's outputs (u0..) follow its resources in the same table; bounded heap SRVs follow in space 2. @@ -139,6 +143,13 @@ inline HRESULT create_translated_root(ID3D12Device* device, UINT constants, UINT const D3D12_DESCRIPTOR_RANGE sampler_range{ D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, translated_sampler_count, 0, translated_sampler_space, 0}; UINT count = sampler_root_parameter(srvs + uavs + heap_srvs); + for (UINT i = 0; i < atomic; ++i) { + auto ¶m = parameters[count++]; + param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; + param.Constants.ShaderRegister = atomic_registers[i] + 1; + param.Constants.RegisterSpace = 0; + param.Constants.Num32BitValues = 2; + } if (samplers.heap) { parameters[count].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; parameters[count].DescriptorTable = {1, &sampler_range}; diff --git a/tests/cmake/startup_compute_indexed_atomic_uav.cmake b/tests/cmake/startup_compute_indexed_atomic_uav.cmake new file mode 100644 index 0000000000..88652b9ee8 --- /dev/null +++ b/tests/cmake/startup_compute_indexed_atomic_uav.cmake @@ -0,0 +1,17 @@ +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + add_test(NAME startup_compute_indexed_atomic_uav_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_indexed_atomic_uav_check.py" compile + "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_indexed_atomic_uav_controls PROPERTIES TIMEOUT 60) +endif() +if(TARGET compile_dxil AND TARGET startup_stream_consumer AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_indexed_atomic_uav_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_indexed_atomic_uav_check.py" + "$" "$" "$" + "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_indexed_atomic_uav_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp index 92d7147f14..96d5b5e24a 100644 --- a/tests/native_compute_manifest_reasons.cpp +++ b/tests/native_compute_manifest_reasons.cpp @@ -68,6 +68,14 @@ int main() { p.bindings[0].array_count = 4; }}, {"UAV kind typed_buffer_uav", [](auto &p) { p.bindings[1].kind = K::typed_buffer_uav; }}, + {"UAV kind indexed_atomic_uav array", [](auto &p) { + p.bindings[1].kind = K::indexed_atomic_uav; + p.bindings[1].array_count = 2; + }}, + {"UAV kind indexed_atomic_uav", [](auto &p) { + p.bindings[1].kind = K::indexed_atomic_uav; + p.bindings[1].required_bytes = 8; + }}, {"UAV kind texture_uav cube", [](auto &p) { p.bindings[1].kind = K::texture_uav; p.bindings[1].image_dimension = 3; @@ -117,6 +125,22 @@ int main() { 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); + // An indexed atomic UAV is published only as a single 4-byte view. + { + auto program = base(); + program.bindings[1].kind = K::indexed_atomic_uav; + program.bindings[1].required_bytes = 4; + reason = "unset"; + const auto manifest = format_compute_runtime_manifest(program, &reason); + std::string wanted = expected; + wanted.replace(wanted.find("uav 0 table 1 32\n"), std::strlen("uav 0 table 1 32\n"), + "uav 0 atomic table 1 32\n"); + const bool ok = manifest && *manifest == wanted && reason == "unset"; + std::printf("%s publishes uav 0 atomic table 1 32\n", ok ? "ok " : "FAIL"); + 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) + 2); return failures ? 1 : 0; } diff --git a/tests/startup_compute_indexed_atomic_uav_check.py b/tests/startup_compute_indexed_atomic_uav_check.py new file mode 100644 index 0000000000..a9c73b413a --- /dev/null +++ b/tests/startup_compute_indexed_atomic_uav_check.py @@ -0,0 +1,224 @@ +"""Publish a synthetic indexed-atomic slot 67 program and check its token-bound output. + +usage: startup_compute_indexed_atomic_uav_check.py + + startup_compute_indexed_atomic_uav_check.py compile + startup_compute_indexed_atomic_uav_check.py + (no arguments: pure-Python controls for the program encoding and expectations) + +The program loads the input descriptor from table byte 0 and the output descriptor from table byte 32 +(the 32-byte record layout the direct compiler reads), then every lane adds 1 to the indexed atomic +counter at byte index 4 * lane. Dispatch(3, 2, 2) runs 12 groups of 32 lanes, so each addressed dword +gains 12. The output is a slot-19 token UAV, bound through the published manifest line +`uav 0 atomic table 1 32`; the dispatch binds the view's {stride, count} as root constants at b1. +Three token shapes are checked, each with its own addressed dwords: + +- raw (stride 1, byte indices): dwords 0-31; +- structured stride 8 (element indices): dwords 0, 8, ..., 248; +- typed R32_UINT (stride 4, element indices): dwords 0, 4, ..., 124. + +Negative controls keep the same published manifest and refuse, each with its own reason and an +untouched output: structured strides 6 and 4096, a raw view with an R32_UINT format, a typed R16_UINT +view, a view whose first element is not 16-byte aligned, a view past the end of its buffer, and the +same output bound from a hardware descriptor instead of a token. A final native run translates the +same program in-process (no published manifest) and checks the same readback. Exit 77 only if the +initial probe cannot use the adapter or required heaps. +""" +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +from native_gather_lod_check import render +from native_scalar_lds_check import sop1 +from startup_compute_buffer_atomics_check import mubuf, v_mov_imm, vop2 +from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_translate_check import state_a, write_request +from startup_gfx2hlsl_compute_check import MASK, SENTINEL, TGID_X, TGID_Y, TGID_Z, USER7, WORDS, root_blob +from startup_stream_check import gfx2hlsl as G + +STATE = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) +GROUPS = 12 # Dispatch(3, 2, 2) +MANIFEST_LINE = 'uav 0 atomic table 1 32' +NATIVE_LINE = 'translated natively: 0 entry values, 0 inputs, 1 outputs' +NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' +ATOMIC_REASON = 'an indexed atomic output view has an unsupported stride or range' +HARDWARE_REASON = 'an indexed atomic output needs a slot-19 token view' + +RAW, R16_UINT, R32_UINT = 39, 57, 42 # DXGI_FORMAT values +STRIDES = {'raw': 1, 'structured': 8, 'typed': 4} + + +def program(): + code = struct.pack('<2I', sop1(3, 10, 6), sop1(3, 11, 128)) + code += bytes.fromhex('050308f4 000000fa 050408f4 200000fa') # s_load_dwordx4 s[12:15], s[16:19] + code += struct.pack(' Date: Sun, 29 Nov 2026 02:05:01 +0200 Subject: [PATCH 2/3] runtime: keep indexed atomic UAV negative views creatable, run warp without wave32 WIN-VERIFY round 1: on hardware, three negative-control UAV descs were invalid for D3D12 CreateUnorderedAccessView on the 1280-byte buffer (a 4096-byte structured stride, a RAW-flagged R32_UINT view, a 1284-byte view), so slot 19 removed the device before the dispatch could refuse them. Keep every negative view creatable: the 4096-stride view now runs on the 16 MiB + 64 KiB committed buffer, the unaligned view uses WORDS - 1 elements, and the two uncreatable shapes stay out (a RAW view needs R32_TYPELESS; a view past the end of its buffer cannot be created). controls() now checks every negative view fits its buffer and that the two uncreatable shapes fail that check. On WARP, the --shader-wave32 gate exited 77, skipping the published raw/structured/typed runs even though only the native translator needs 32-lane waves: main() no longer probes wave32, and native_check() probes it directly so a skip there does not discard the published results. Refs #3224, #2935 --- .../experiments/compute-indexed-atomic-uav.md | 14 +++- ...tartup_compute_indexed_atomic_uav_check.py | 84 ++++++++++++++----- 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/docs/experiments/compute-indexed-atomic-uav.md b/docs/experiments/compute-indexed-atomic-uav.md index 524f43f498..3297de839b 100644 --- a/docs/experiments/compute-indexed-atomic-uav.md +++ b/docs/experiments/compute-indexed-atomic-uav.md @@ -51,11 +51,17 @@ program through `compile_dxil` and checks the manifest line, with no adds 1 to the indexed counter at byte index `4 * lane` over `Dispatch(3, 2, 2)`, so each addressed dword gains 12. Raw, structured stride-8 and typed `R32_UINT` token views are checked, each with its own -addressed dwords, plus six token shapes and a hardware descriptor that must +addressed dwords, plus four token shapes and a hardware descriptor that must each refuse with their own reason and leave the output untouched, and a -native in-process translation of the same program. The pure-Python controls -(program encoding, table loads, `idxen` atomic, per-shape expectations and -token views) run without Windows. +native in-process translation of the same program. Every negative-control +view is creatable in D3D12 on its buffer: the 4096-stride view is created on +the 16 MiB + 64 KiB committed buffer, since a view D3D12 rejects at creation +removes the device in slot 19 before the dispatch can refuse it. The +published path needs no 32-lane waves, so it runs on WARP; only the native +in-process step probes for them and skips when they are absent. The +pure-Python controls (program encoding, table loads, `idxen` atomic, +per-shape expectations, token views, and that every negative view fits its +buffer) run without Windows. ```powershell cmake --build --preset dev --target compile_dxil startup_stream_consumer offscreen_check diff --git a/tests/startup_compute_indexed_atomic_uav_check.py b/tests/startup_compute_indexed_atomic_uav_check.py index a9c73b413a..99bdf6447a 100644 --- a/tests/startup_compute_indexed_atomic_uav_check.py +++ b/tests/startup_compute_indexed_atomic_uav_check.py @@ -18,11 +18,16 @@ - typed R32_UINT (stride 4, element indices): dwords 0, 4, ..., 124. Negative controls keep the same published manifest and refuse, each with its own reason and an -untouched output: structured strides 6 and 4096, a raw view with an R32_UINT format, a typed R16_UINT -view, a view whose first element is not 16-byte aligned, a view past the end of its buffer, and the -same output bound from a hardware descriptor instead of a token. A final native run translates the -same program in-process (no published manifest) and checks the same readback. Exit 77 only if the -initial probe cannot use the adapter or required heaps. +untouched output: structured strides 6 and 4096, a typed R16_UINT view, and a view whose first +element is not 16-byte aligned, plus the same output bound from a hardware descriptor instead of +a token. Every negative view is creatable in D3D12 on its buffer (the 1280-byte output buffer, or +the 16 MiB + 64 KiB committed buffer for the 4096-stride view, which needs more than 1280 bytes): +a view D3D12 itself rejects at creation removes the device in slot 19 before the dispatch can +refuse it, so a RAW-flagged view with a non-R32_TYPELESS format and a view past the end of its +buffer are not exercised here. A final native run translates the same program in-process (no +published manifest) and checks the same readback; it is skipped on adapters without 32-lane +waves, which only the native translator needs. Exit 77 only if the initial probe cannot use the +adapter or required heaps. """ import struct import subprocess @@ -30,7 +35,6 @@ import tempfile from pathlib import Path -from native_gather_lod_check import render from native_scalar_lds_check import sop1 from startup_compute_buffer_atomics_check import mubuf, v_mov_imm, vop2 from startup_compute_dispatch_check import dispatch, lines, prepare_case @@ -72,6 +76,34 @@ def view(first, elements, fmt, stride=0, flags=0): 'typed': view(0, WORDS, R32_UINT, 0, 0), } +LARGE_BYTES = (16 << 20) + (64 << 10) # dispatch-uav-token-large committed buffer + +# (consumer mode, view, expected refusal). Every view must be creatable in D3D12 on its buffer: +# a view D3D12 rejects at creation removes the device in slot 19 before the dispatch can refuse it. +NEGATIVES = ( + ('dispatch-uav-token-raw', view(0, WORDS * 4 // 8, 0, 6, 0), ATOMIC_REASON), + ('dispatch-uav-token-large', view(0, WORDS * 4 // 8, 0, 4096, 0), ATOMIC_REASON), + ('dispatch-uav-token-raw', view(0, WORDS * 2, R16_UINT, 0, 0), ATOMIC_REASON), + ('dispatch-uav-token-raw', view(1, WORDS - 1, R32_UINT, 0, 0), + 'an output UAV interval is not 16-byte aligned in its buffer'), +) + + +def check_view_fits(desc, capacity, label): + """A negative-control view must be creatable in D3D12 on its buffer (offset + bytes <= size).""" + fmt, _, first, elements, stride, _, flags = struct.unpack(' Date: Sun, 29 Nov 2026 02:49:34 +0200 Subject: [PATCH 3/3] startup: restore wave32 probe and correct native entry count in indexed atomic UAV check --- docs/experiments/compute-indexed-atomic-uav.md | 5 +++-- .../startup_compute_indexed_atomic_uav_check.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/experiments/compute-indexed-atomic-uav.md b/docs/experiments/compute-indexed-atomic-uav.md index 3297de839b..11510e6d9f 100644 --- a/docs/experiments/compute-indexed-atomic-uav.md +++ b/docs/experiments/compute-indexed-atomic-uav.md @@ -57,8 +57,9 @@ native in-process translation of the same program. Every negative-control view is creatable in D3D12 on its buffer: the 4096-stride view is created on the 16 MiB + 64 KiB committed buffer, since a view D3D12 rejects at creation removes the device in slot 19 before the dispatch can refuse it. The -published path needs no 32-lane waves, so it runs on WARP; only the native -in-process step probes for them and skips when they are absent. The +published path needs 32-lane waves too: the published DXIL declares +WaveSize(32), so `CreateComputePipelineState` fails on 4-lane WARP, and +the check probes `--shader-wave32` first and exits 77 without them. The pure-Python controls (program encoding, table loads, `idxen` atomic, per-shape expectations, token views, and that every negative view fits its buffer) run without Windows. diff --git a/tests/startup_compute_indexed_atomic_uav_check.py b/tests/startup_compute_indexed_atomic_uav_check.py index 99bdf6447a..285454fcf4 100644 --- a/tests/startup_compute_indexed_atomic_uav_check.py +++ b/tests/startup_compute_indexed_atomic_uav_check.py @@ -25,9 +25,11 @@ a view D3D12 itself rejects at creation removes the device in slot 19 before the dispatch can refuse it, so a RAW-flagged view with a non-R32_TYPELESS format and a view past the end of its buffer are not exercised here. A final native run translates the same program in-process (no -published manifest) and checks the same readback; it is skipped on adapters without 32-lane -waves, which only the native translator needs. Exit 77 only if the initial probe cannot use the -adapter or required heaps. +published manifest) and checks the same readback. The check probes +`--shader-wave32` first and exits 77 on adapters without 32-lane waves: +the published DXIL declares WaveSize(32), so pipeline creation fails +there, and the native translator needs them too. Exit 77 also if the +initial probe cannot use the adapter or required heaps. """ import struct import subprocess @@ -35,6 +37,7 @@ import tempfile from pathlib import Path +from native_gather_lod_check import render from native_scalar_lds_check import sop1 from startup_compute_buffer_atomics_check import mubuf, v_mov_imm, vop2 from startup_compute_dispatch_check import dispatch, lines, prepare_case @@ -45,7 +48,7 @@ STATE = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) GROUPS = 12 # Dispatch(3, 2, 2) MANIFEST_LINE = 'uav 0 atomic table 1 32' -NATIVE_LINE = 'translated natively: 0 entry values, 0 inputs, 1 outputs' +NATIVE_LINE = 'translated natively: 2 entry values, 0 inputs, 1 outputs' NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' ATOMIC_REASON = 'an indexed atomic output view has an unsupported stride or range' HARDWARE_REASON = 'an indexed atomic output needs a slot-19 token view' @@ -226,8 +229,8 @@ def check(compile_dxil, consumer, sdk, work, adapter, shape): def native_check(consumer, renderer, sdk, work, adapter): - # Only the native translator needs 32-lane waves; the published DXIL path runs without them. - # Probe directly so a skip here does not discard the published-path results above. + # main() already probed --shader-wave32, so this re-probe only guards + # a direct call; it cannot skip here after main() has run. wave = subprocess.run([renderer, adapter, '--shader-wave32'], capture_output=True, text=True, timeout=30) if wave.returncode == 77: @@ -250,6 +253,8 @@ def native_check(consumer, renderer, sdk, work, adapter): def main(compile_dxil, consumer, renderer, sdk, adapter): + wave = render(renderer, adapter, '--shader-wave32') + assert wave.returncode == 0, wave.stdout + wave.stderr with tempfile.TemporaryDirectory() as directory: for shape in ('raw', 'structured', 'typed'): check(compile_dxil, consumer, sdk, Path(directory) / shape, adapter, shape)