From 6ef92281fcf193a2632c5cc5b360cf414054e20e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 28 Nov 2026 17:54:39 +0000 Subject: [PATCH 1/3] compute: publish packed_d16_x_uav runtime manifest A one-component D16 buffer_store_format compiles as packed_d16_x_uav but the published route had no manifest line, so dispatch refused the kind as unknown. Emit bufd16x, name the kind, and keep the view on native_buffer_store_view, refusing an element that is not one R16_UINT halfword. Co-authored-by: SimSalabimse --- docs/experiments/packed-d16-x-uav-manifest.md | 44 ++++ src/direct_compute_cache.cpp | 7 +- src/startup_stubs/d3d12_compute_dispatch.inl | 87 ++++++- .../startup_compute_packed_d16_x_uav.txt | 1 + .../startup_compute_packed_d16_x_uav.cmake | 22 ++ .../startup_compute_packed_d16_x_uav_check.py | 214 ++++++++++++++++++ 6 files changed, 368 insertions(+), 7 deletions(-) create mode 100644 docs/experiments/packed-d16-x-uav-manifest.md create mode 100644 tests/checks/python-linux/startup_compute_packed_d16_x_uav.txt create mode 100644 tests/cmake/startup_compute_packed_d16_x_uav.cmake create mode 100644 tests/startup_compute_packed_d16_x_uav_check.py diff --git a/docs/experiments/packed-d16-x-uav-manifest.md b/docs/experiments/packed-d16-x-uav-manifest.md new file mode 100644 index 000000000..6af3ea79f --- /dev/null +++ b/docs/experiments/packed-d16-x-uav-manifest.md @@ -0,0 +1,44 @@ +# Published manifest for a one-component packed D16 buffer store + +A direct compute `buffer_store_format` with the D16 bit and one component is +`packed_d16_x_uav`. It already compiles, and the in-process route already binds it +(`slot.packed_d16_x`, `native_buffer_store_view`). `format_compute_runtime_manifest` +published no line for it, so a program that compiled still had no runtime manifest. +`view_kind_name` also stopped at `float3_texture_uav`, so both `packed_d16_x_uav` and +`indexed_raw_srv` were printed as `unknown`. + +The publisher now emits `uav bufd16x table bytes 2` when +the binding is one register and the payload is two bytes. The dispatch reader accepts +that line next to `bufhalf`. The view is still checked with `native_buffer_store_view`. +A format, stride or flag the check rejects keeps the reason +`formatted D16 write has an incompatible typed buffer UAV`. An `R32_UINT` element is +four bytes, two halfwords, and the store would zero-extend a 16-bit payload across both +of them, so the published route refuses that view as well. + +The source-built fixture is `tests/startup_compute_packed_d16_x_uav_check.py`. It has no +title data. Thirteen lanes write `0x3c00 + lane` at byte 8 of a sentinel buffer; the +reference is that addition, which matches the low half of the program's `v_xor_b32` for +those lanes. The R32_UINT view, a stride other than 2, and a descriptor with the swizzle +flag set must refuse by name and leave the buffer untouched. Before the manifest exists +the dispatch is `no translation`. + +On Linux the reference half of the fixture runs with no compiler and no device: + +```bash +./out/pe-env/bin/python -B tests/startup_compute_packed_d16_x_uav_check.py +``` + +The compile and dispatch halves need Windows, DXC and the stand-in. WARP is the CI +adapter. A hardware adapter is selected the same way as the other `startup_compute_*` +dispatch tests and returns 77 when none is available. + +```powershell +ctest --preset dev --no-tests=error -R '^startup_compute_packed_d16_x_uav_' -V +``` + +A 900 s start-up run of a retail title on the Windows test PC, runtime built from `main` +`aec2e08`, counted 23 shaders and 86,436 untranslated dispatches (5.7% of that run's +untranslated compute dispatches) whose published-route refusal was +`unsupported startup runtime manifest bindings: UAV kind unknown` for this binding. +Those counts are from that run. This note does not include a Windows dispatch result for +the new fixture; that measurement is still to be taken on the Windows test PC. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 79dcc6b3c..2b63b9935 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -893,7 +893,8 @@ static const char *view_kind_name(ComputeViewKind kind) { "heap_stride_srv", "raw_buffer_uav", "typed_buffer_uav", "half_buffer_uav", "root_buffer_srv", "comparison_texture_srv", "half2_texture_uav", "half4_texture_uav", "cube_sample_srv", "cube_comparison_srv", "indexed_atomic_uav", "d16_sample_srv", "byte_window_srv", "heap_buffer_srv", "heap_sampler", - "uint_texture_uav", "float_texture_uav", "float2_texture_uav", "float3_texture_uav"}; + "uint_texture_uav", "float_texture_uav", "float2_texture_uav", "float3_texture_uav", + "packed_d16_x_uav", "indexed_raw_srv"}; const auto index = static_cast(kind); return index < std::size(names) ? names[index] : "unknown"; } @@ -979,6 +980,10 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh (b.required_bytes == 2 || b.required_bytes == 4 || b.required_bytes == 8)) { uav_lines << "uav " << b.shader_register << " bufhalf table " << b.root_parameter << ' ' << b.byte_offset << " bytes " << b.required_bytes << '\n'; + } else if (b.kind == ComputeViewKind::packed_d16_x_uav && b.array_count == 1 && b.required_bytes == 2) { + // One halfword. A wider element (R32_UINT holds two) is not published as this store. + uav_lines << "uav " << b.shader_register << " bufd16x table " << b.root_parameter << ' ' + << b.byte_offset << " bytes " << b.required_bytes << '\n'; } else if (b.kind == ComputeViewKind::uint_texture_uav && b.image_dimension == 1 && b.array_count == 1) { uav_lines << "uav " << b.shader_register << " tex2d uint table " << b.root_parameter << ' ' << b.byte_offset << " channels 1\n"; diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 164cbe9d0..2e6123525 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -2,7 +2,8 @@ // the key of its published request; gfx2hlsl.py --pending answers the request with .txt (`stage cs`) and // .cs.cso. Bound from the compute tables recorded by slot 35 and compute root SRVs recorded by slot 43: raw // buffers (`srv buf table ` and `srv buf root ` inputs, `uav table ` -// outputs, or `uav bufhalf table bytes ` for typed half stores) +// outputs, `uav bufhalf table bytes ` for typed half stores, or +// `uav bufd16x table bytes 2` for a one-component packed D16 store) // 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 @@ -92,6 +93,50 @@ unsigned float_output_channels(DXGI_FORMAT format) } } +// Published `bufd16x` stores one halfword. native_buffer_store_view accepts an R32_UINT element +// (two halfwords, stride widened to 4) and rewrites R16_FLOAT / R16_UINT to R16_UINT. This path +// keeps that check, then refuses anything that is not the rewritten one-halfword view: a 32-bit +// element would store a zero-extended payload over both halfwords. +const char* packed_d16_x_view_refusal(const std::uint32_t* words, UINT64 offset, UINT64 resource_bytes, + D3D12_UNORDERED_ACCESS_VIEW_DESC& out) +{ + D3D12_UNORDERED_ACCESS_VIEW_DESC view{}; + view.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + const unsigned stride_field = words[1] >> 16; + const unsigned stride = stride_field & 0x3fffu; + const unsigned word3 = words[3]; + const unsigned format = (word3 >> 12) & 127u; + const bool unified = (word3 & 0x01000000u) != 0; + unsigned element = 0; + if (unified && format == 13) { + view.Format = DXGI_FORMAT_R16_FLOAT; + element = 2; + } else if (unified && format == 11) { + view.Format = DXGI_FORMAT_R16_UINT; + element = 2; + } else if (unified && format == 20) { + view.Format = DXGI_FORMAT_R32_UINT; + element = 4; + } + // TYPE, reserved, ADD_TID_ENABLE and INDEX_STRIDE, plus SWIZZLE_ENABLE / CACHE_SWIZZLE and OOB_SELECT. + constexpr unsigned word3_flags = 0xcef80000u; + const bool flags = (stride_field & 0xc000u) != 0 || (word3 & word3_flags) != 0 || ((word3 >> 28) & 3u) != 0; + if (flags) + view.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; + if (!element || (word3 & 7u) != 4u || stride != element) + view.Format = DXGI_FORMAT_UNKNOWN; + const unsigned step = element ? element : 1u; + if (offset % step) + return "an output packed D16 buffer is not element-aligned in its resource"; + view.Buffer.FirstElement = static_cast(offset / step); + view.Buffer.NumElements = words[2] ? words[2] : 1u; + const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::packed_d16_x_uav, 0, 0, 0, 2}; + if (!x2w::native_buffer_store_view(binding, view, resource_bytes) || view.Format != DXGI_FORMAT_R16_UINT) + return "formatted D16 write has an incompatible typed buffer UAV"; + out = view; + return nullptr; +} + bool half_buffer_descriptor_matches(const std::uint32_t* words, unsigned bytes) { // gfx10 V# with identity selectors for each stored component and structured @@ -223,6 +268,11 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.uavs.push_back({a, b}); tr.uavs.back().half_buffer_bytes = x; } + else if (std::sscanf(line.c_str(), "uav %u bufd16x table %d %d bytes %u%n", &i, &a, &b, &x, &used) == 4 && + whole() && i == tr.uavs.size() && x == 2) { + tr.uavs.push_back({a, b}); + tr.uavs.back().packed_d16_x = true; + } else if (std::sscanf(line.c_str(), "uav %u tex2d uint table %d %d channels 1%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uavs.size()) { tr.uavs.push_back({a, b, true}); @@ -823,6 +873,13 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& reason = "formatted D16 write has an incompatible typed buffer UAV"; } #endif + if (!reason && slot.packed_d16_x && !slot.half_typed_bytes) { + token.view.Format = desktop_format(token.view.Format); + const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::packed_d16_x_uav, 0, 0, 0, 2}; + if (!x2w::native_buffer_store_view(binding, token.view, token.backing.Width) || + token.view.Format != DXGI_FORMAT_R16_UINT) + reason = "formatted D16 write has an incompatible typed buffer UAV"; + } if (reason && token.placement == Placement::copied_buffer && trace_copied_compute_output(key, token.guest_resource, token.guest_base, token.offset, token.bytes)) { log("x2w-compute-output-watch key=%016llx groups=%u,%u,%u indirect=%u owner=0x%llx gpuva=0x%llx", @@ -852,7 +909,7 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& token.description_bytes, token.offset, token.bytes, reason ? reason : "bound"); } views[i] = {token.resource, token.offset, token.bytes, true}; - if (!reason && slot.half_typed_bytes) { + if (!reason && (slot.half_typed_bytes || slot.packed_d16_x)) { views[i].described = true; views[i].desc.uav = token.view; } @@ -866,9 +923,10 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& const u64 address = words[0] | (u64{words[1] & 0xffff} << 32); const UINT stride = (words[1] >> 16) & 0x3fff; const unsigned half_bytes = slot.half_buffer_bytes; - const unsigned alignment = half_bytes ? half_bytes : D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT; + const bool packed = slot.packed_d16_x && !slot.half_typed_bytes; + const unsigned alignment = half_bytes ? half_bytes : (packed ? 2u : D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT); const u64 bytes = u64{stride ? stride : 1} * words[2]; - const bool sized = words[0] != view_token_magic && bytes && (half_bytes || bytes % 4 == 0) && bytes <= (16u << 20); + const bool sized = words[0] != view_token_magic && bytes && (half_bytes || packed || bytes % 4 == 0) && bytes <= (16u << 20); const auto placed = sized ? placed_buffer_range(self->own().list_device, address, bytes) : PlacedVertexView{}; const ResourceInfo* info = placed.alias ? resource_info(placed.owner) : nullptr; const u64 offset = placed.alias ? address - reinterpret_cast(placed.owner->own().title_memory) : 0; @@ -877,18 +935,23 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& reason = "a half buffer store requires matching format, stride and structured bounds"; else if (!bytes) reason = "an output buffer descriptor has zero records"; else if (!sized) reason = half_bytes ? "an output half buffer range is over 16 MiB" - : "an output buffer range is over 16 MiB or not whole dwords"; + : packed ? "an output packed D16 buffer range is over 16 MiB" + : "an output buffer range is over 16 MiB or not whole dwords"; else if (placed.reject) reason = "an output range crosses the end of a placed buffer"; else if (!placed.owner) reason = "an output is in title memory outside any placed buffer"; else if (!placed.alias) reason = "an output is in a placed buffer that does not alias title memory"; else if (!info || info->initial_state != D3D12_RESOURCE_STATE_COMMON) reason = "an output buffer's resource was not created in the common state"; else if (offset % alignment) reason = half_bytes ? "an output half buffer is not element-aligned in its resource" - : "an output buffer range is not 16-byte aligned in its resource"; + : packed ? "an output packed D16 buffer is not element-aligned in its resource" + : "an output buffer range is not 16-byte aligned in its resource"; else if (!(placed.alias->GetDesc().Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) reason = "an output buffer has no unordered access"; for (std::size_t input = 0; input < inputs && !reason; ++input) if (views[input].resource == placed.alias) reason = "an output buffer is also an input"; + D3D12_UNORDERED_ACCESS_VIEW_DESC packed_desc{}; + if (!reason && packed) + reason = packed_d16_x_view_refusal(words, offset, placed.alias->GetDesc().Width, packed_desc); if (reason && !tr->first_refusal) log("x2w-draw compute raw UAV %016llx table=%d+%d entry=0x%llx words=%08x/%08x/%08x/%08x " "stride=%u bytes=%llu result=%s", key, slot.a, slot.b, entry, words[0], words[1], words[2], words[3], @@ -912,6 +975,18 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& views[i].desc.uav = desc; } } + if (!reason && packed) { + D3D12_FEATURE_DATA_FORMAT_SUPPORT support{packed_desc.Format}; + constexpr UINT required = D3D12_FORMAT_SUPPORT1_BUFFER | D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW; + if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &support, sizeof(support))) || + (support.Support1 & required) != required || + !(support.Support2 & D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE)) { + reason = "an output packed D16 buffer format does not support typed UAV stores"; + } else { + views[i].described = true; + views[i].desc.uav = packed_desc; + } + } std::memcpy(views[i].words, words, sizeof(views[i].words)); } for (UINT r = 0; r < tr->heap_srvs && !reason; ++r) { diff --git a/tests/checks/python-linux/startup_compute_packed_d16_x_uav.txt b/tests/checks/python-linux/startup_compute_packed_d16_x_uav.txt new file mode 100644 index 000000000..97c50ccf6 --- /dev/null +++ b/tests/checks/python-linux/startup_compute_packed_d16_x_uav.txt @@ -0,0 +1 @@ +tests/startup_compute_packed_d16_x_uav_check.py diff --git a/tests/cmake/startup_compute_packed_d16_x_uav.cmake b/tests/cmake/startup_compute_packed_d16_x_uav.cmake new file mode 100644 index 000000000..e9fa0f6cc --- /dev/null +++ b/tests/cmake/startup_compute_packed_d16_x_uav.cmake @@ -0,0 +1,22 @@ +if(EXISTS "${INTAKE_PYTHON}") + add_test(NAME startup_compute_packed_d16_x_uav_reference COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_packed_d16_x_uav_check.py" reference) + set_tests_properties(startup_compute_packed_d16_x_uav_reference PROPERTIES TIMEOUT 60) +endif() +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_packed_d16_x_uav_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_packed_d16_x_uav_check.py" compile + "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_packed_d16_x_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_packed_d16_x_uav_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_packed_d16_x_uav_check.py" + "$" "$" "$" + "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_packed_d16_x_uav_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_compute_packed_d16_x_uav_check.py b/tests/startup_compute_packed_d16_x_uav_check.py new file mode 100644 index 000000000..799ba779f --- /dev/null +++ b/tests/startup_compute_packed_d16_x_uav_check.py @@ -0,0 +1,214 @@ +"""Publish a source-built one-component D16 buffer store and check the written halfwords. + +No game data. The program is a gfx1013 `buffer_store_format` with the D16 bit and one +component (the direct compiler's `packed_d16_x_uav`). `compile_dxil --requests` must +publish `uav 0 bufd16x table 1 32 bytes 2`. The stand-in then dispatches that translation. +The reference halfwords are the low half of `v_xor_b32` of the literal `0xc0003c00` with +the lane id, which for lanes 0..12 is `0x3c00 + lane`. An R32_UINT view (two halfwords +per element), a stride other than 2, and a descriptor with swizzle flags set must refuse +by name. Before publication the dispatch stays `no translation`. + +usage: + startup_compute_packed_d16_x_uav_check.py + reference only (no compiler, no device) + startup_compute_packed_d16_x_uav_check.py compile + startup_compute_packed_d16_x_uav_check.py + +""" + +from pathlib import Path +import struct +import subprocess +import sys + +SENTINEL = 0xc5c5c5c5 +WORDS = 320 +OFFSET = 8 +RECORDS = 13 +STRIDE = 2 +# gfx10 unified BUF_FMT_16_FLOAT is 13; BUF_FMT_32_UINT is 20. RESOURCE_LEVEL is bit 24 +# and 0xfac is identity DST_SEL. A 32-bit element holds two halfwords, so it is not this store. +FLOAT16 = 13 +UINT32 = 20 +WORD3_BASE = 0x01000fac +INCOMPATIBLE = 'formatted D16 write has an incompatible typed buffer UAV' +MODE = 'dispatch-records32-output-offset' +MANIFEST_LINE = f'uav 0 bufd16x table 1 32 bytes {STRIDE}' + + +def vop2(op, dst, src0, src1): + return op << 25 | dst << 17 | src1 << 9 | src0 + + +def scalar(op, dst, a, b): + return 0x80000000 | op << 23 | dst << 16 | b << 8 | a + + +def sop1(op, dst, src): + return 0xbe800000 | dst << 16 | op << 8 | src + + +def program_words(): + # Same index and payload shape as the one-channel half-buffer store. Opcode 0x84 is + # buffer_store_format_d16_x: idxen, v1, v8, s[32:35], offset 0. + store = 0xe0002000 | (0x84 << 18) + return [ + sop1(3, 20, 6), sop1(3, 21, 128), + 0xf408080a, 0xfa000020, + 0xbf8cc07f, + scalar(0x26, 8, 8, 131), + scalar(0x26, 9, 9, 134), + scalar(0, 11, 7, 8), scalar(0, 11, 11, 9), + scalar(0x1e, 11, 11, 133), + vop2(0x25, 8, 11, 0), + vop2(0x1d, 1, 255, 0), 0xc0003c00, + 0x7e0402ff, 0xbc003800, + store, 0x80080108, + 0xbf810000, + ] + + +def program(): + words = program_words() + return struct.pack('<%dI' % len(words), *words) + + +def halfword(lane): + """Low halfword of v1. Lanes below 16 have no bits in common with 0x3c00, so XOR adds.""" + return (0xc0003c00 ^ lane) & 0xffff + + +def word3(fmt): + return WORD3_BASE | (fmt << 12) + + +def expected(): + data = bytearray(struct.pack('<%dI' % WORDS, *([SENTINEL] * WORDS))) + for lane in range(RECORDS): + struct.pack_into('> 18) & 0xff == 0x84, 'opcode is buffer_store_format_d16_x' + assert store & 0x3ffff == 0x2000, 'idxen, offset 0' + assert (store_b >> 8) & 0xff == 1 and (store_b & 0xff) == 8, 'data v1, index v8' + assert ((store_b >> 16) & 31) * 4 == 32, 'descriptor s[32:35]' + assert vop2(0x1d, 1, 255, 0) in words and 0xc0003c00 in words + for lane in range(RECORDS): + assert halfword(lane) == 0x3c00 + lane, lane + image = expected() + raw = struct.pack('<%dI' % WORDS, *image) + for lane in range(RECORDS): + got, = struct.unpack_from('> 12) & 127 == UINT32 + print(f'reference: {RECORDS} halfwords at byte {OFFSET}, guards intact, three negative descriptors differ') + + +def publish(compile_dxil, sdk, cache, key): + result = subprocess.run([compile_dxil, sdk, cache.parent / 'native', 'gfx1013-direct-cs@0', + '--requests', cache, cache], capture_output=True, text=True, timeout=30) + manifest = cache / f'{key}.txt' + assert result.returncode == 0 and manifest.is_file(), (result.returncode, result.stdout, result.stderr) + text = manifest.read_text() + assert MANIFEST_LINE in text.splitlines(), text + assert not (cache / f'{key}.cs.hlsl').exists(), 'expected native publication' + + +def check_compiler(compile_dxil, sdk): + from tempfile import TemporaryDirectory + + from startup_compute_translate_check import state_a, write_request + from startup_gfx2hlsl_compute_check import TGID_X, TGID_Y, TGID_Z, USER7, root_blob + + state = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) + with TemporaryDirectory() as directory: + cache = Path(directory) + key = write_request(cache, program(), state, root=root_blob(table_range=True)) + publish(compile_dxil, sdk, cache, f'{key:016x}') + print('compile: published', MANIFEST_LINE) + + +def check(compile_dxil, consumer, sdk, work, adapter): + from startup_compute_dispatch_check import dispatch, lines, prepare_case + from startup_compute_translate_check import state_a + from startup_gfx2hlsl_compute_check import TGID_X, TGID_Y, TGID_Z, USER7 + + cache, env = prepare_case(work, adapter) + env.pop('X2W_NATIVE_SHADERS', None) + env.pop('X2W_NATIVE_SHADERS_ONLY', None) + state = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) + (work / 'program').write_bytes(program()) + (work / 'state').write_bytes(state) + fields = work / 'fields.bin' + env['X2W_TEST_DISPATCH_FIELDS'] = str(fields) + accepted_word3 = word3(FLOAT16) + untouched = [SENTINEL] * WORDS + + def run(view_stride=STRIDE, records=RECORDS, descriptor_word=accepted_word3, *, probe=False): + fields.write_bytes(struct.pack('<6I', 4, WORDS, 0, view_stride, records, descriptor_word)) + return dispatch(work, consumer, env, MODE, probe=probe) + + got, result = run(probe=True) + check_words(got, untouched, 'before translation') + assert lines(result, 'Dispatch(3, 2, 2) refused: no translation'), result.stderr[-3000:] + [request] = cache.glob('req_*.c67') + key = request.stem.removeprefix('req_') + publish(compile_dxil, sdk, cache, key) + got, result = run() + check_words(got, expected(), 'packed D16 x') + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused:'), result.stderr[-3000:] + assert not [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] + layers = lines(result, 'x2w-d3d12 debug layer: ') + layer = 'enabled' if layers and '0x00000000' in layers[0] else 'unavailable' + print(f'{RECORDS} halfwords at byte {OFFSET} and all guards match on {adapter} (debug layer {layer})') + + for label, options in ( + ('R32_UINT view', {'view_stride': 4, 'descriptor_word': word3(UINT32)}), + ('wrong stride', {'view_stride': STRIDE + 2}), + ('flags set', {'view_stride': STRIDE | 0x8000}), + ): + got, result = run(**options) + check_words(got, untouched, label) + assert len(lines(result, 'Dispatch(3, 2, 2) refused: ' + INCOMPATIBLE)) == 1, (label, result.stderr[-3000:]) + print(f'{label}: refused ({INCOMPATIBLE}), output untouched') + + +def main(compile_dxil, consumer, renderer, sdk, adapter): + from tempfile import TemporaryDirectory + + from native_gather_lod_check import render + + wave = render(renderer, adapter, '--shader-wave32') + assert wave.returncode == 0, wave.stdout + wave.stderr + with TemporaryDirectory() as directory: + check(compile_dxil, consumer, sdk, Path(directory), adapter) + + +if __name__ == '__main__': + if len(sys.argv) == 1 or sys.argv[1] == 'reference': + check_reference() + elif sys.argv[1] == 'compile': + check_compiler(*sys.argv[2:]) + elif len(sys.argv) == 6 and sys.argv[5] in ('warp', 'hardware'): + main(*sys.argv[1:]) + else: + sys.exit(__doc__) From 0430ae1d33a2e94354b2e4a1361e5a67e9ac6f88 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 28 Nov 2026 18:27:23 +0000 Subject: [PATCH 2/3] compute: keep one-component D16 stores on the half-buffer manifest A one-component buffer_store_format was classified as packed_d16_x_uav, so publishing bufd16x replaced the existing bufhalf line. That store stays a half_buffer_uav. bufd16x is emitted only for a packed_d16_x_uav binding. Co-authored-by: SimSalabimse --- docs/experiments/packed-d16-x-uav-manifest.md | 54 +++++++++---------- src/gfx1013_direct_compute.inl | 17 +++--- .../startup_compute_packed_d16_x_uav_check.py | 19 ++++--- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/docs/experiments/packed-d16-x-uav-manifest.md b/docs/experiments/packed-d16-x-uav-manifest.md index 6af3ea79f..341949361 100644 --- a/docs/experiments/packed-d16-x-uav-manifest.md +++ b/docs/experiments/packed-d16-x-uav-manifest.md @@ -1,26 +1,26 @@ -# Published manifest for a one-component packed D16 buffer store - -A direct compute `buffer_store_format` with the D16 bit and one component is -`packed_d16_x_uav`. It already compiles, and the in-process route already binds it -(`slot.packed_d16_x`, `native_buffer_store_view`). `format_compute_runtime_manifest` -published no line for it, so a program that compiled still had no runtime manifest. -`view_kind_name` also stopped at `float3_texture_uav`, so both `packed_d16_x_uav` and -`indexed_raw_srv` were printed as `unknown`. - -The publisher now emits `uav bufd16x table bytes 2` when -the binding is one register and the payload is two bytes. The dispatch reader accepts -that line next to `bufhalf`. The view is still checked with `native_buffer_store_view`. -A format, stride or flag the check rejects keeps the reason -`formatted D16 write has an incompatible typed buffer UAV`. An `R32_UINT` element is -four bytes, two halfwords, and the store would zero-extend a 16-bit payload across both -of them, so the published route refuses that view as well. - -The source-built fixture is `tests/startup_compute_packed_d16_x_uav_check.py`. It has no -title data. Thirteen lanes write `0x3c00 + lane` at byte 8 of a sentinel buffer; the -reference is that addition, which matches the low half of the program's `v_xor_b32` for -those lanes. The R32_UINT view, a stride other than 2, and a descriptor with the swizzle -flag set must refuse by name and leave the buffer untouched. Before the manifest exists -the dispatch is `no translation`. +# Published manifest names for D16 buffer stores + +`view_kind_name` names `packed_d16_x_uav` and `indexed_raw_srv`. A refusal that +mentions either kind prints that name. + +`format_compute_runtime_manifest` emits +`uav bufd16x table bytes 2` only when the binding +kind is `packed_d16_x_uav`, the binding is one register, and the payload is two +bytes. The dispatch reader accepts that line next to `bufhalf` and still checks +the view with `native_buffer_store_view`. A format, stride or flag that check +rejects keeps the reason `formatted D16 write has an incompatible typed buffer UAV`. + +A one-component `buffer_store_format` with the D16 bit is the half-buffer UAV. +It publishes `uav bufhalf table bytes 2`, the same +line the half-buffer fixture already requires. It does not publish `bufd16x`. + +The source-built fixture is `tests/startup_compute_packed_d16_x_uav_check.py`. +It has no title data. It checks that this store's manifest line is the half-buffer +line and not `bufd16x`. Thirteen lanes write `0x3c00 + lane` at byte 8 of a +sentinel buffer. An R32_UINT view, a stride other than 2, and a descriptor with +the swizzle flag set must refuse with +`a half buffer store requires matching format, stride and structured bounds`. +Before the manifest exists the dispatch is `no translation`. On Linux the reference half of the fixture runs with no compiler and no device: @@ -33,12 +33,12 @@ adapter. A hardware adapter is selected the same way as the other `startup_compu dispatch tests and returns 77 when none is available. ```powershell -ctest --preset dev --no-tests=error -R '^startup_compute_packed_d16_x_uav_' -V +ctest --preset dev --no-tests=error -R '^startup_compute_(packed_d16_x_uav_|half_buffer_uav_)' -V ``` A 900 s start-up run of a retail title on the Windows test PC, runtime built from `main` `aec2e08`, counted 23 shaders and 86,436 untranslated dispatches (5.7% of that run's untranslated compute dispatches) whose published-route refusal was -`unsupported startup runtime manifest bindings: UAV kind unknown` for this binding. -Those counts are from that run. This note does not include a Windows dispatch result for -the new fixture; that measurement is still to be taken on the Windows test PC. +`unsupported startup runtime manifest bindings: UAV kind unknown` for a one-component +D16 store. Those counts are from that run. Windows results for this correction are not +in this note. diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index 35f4cbc68..764816b97 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -740,9 +740,10 @@ struct DirectCompute { unsigned n = raw ? widths[i.op & 3] : (i.op & 3) + 1, data = 256 + i.dst; if (i.dst + (half ? (n + 1) / 2 : n) > 256) refuse(i.pc, "direct buffer data overflow"); - const bool packed_x = half && n == 1 && !graphics_input; - auto kind = store ? (raw ? ComputeViewKind::raw_buffer_uav - : packed_x ? ComputeViewKind::packed_d16_x_uav + // A one-component D16 store is the half-buffer UAV. Its published line is + // `bufhalf` with a 2-byte stride. packed_d16_x_uav is a different binding + // and is the only kind that publishes `bufd16x`. + auto kind = store ? (raw ? ComputeViewKind::raw_buffer_uav : half ? ComputeViewKind::half_buffer_uav : ComputeViewKind::typed_buffer_uav) : raw && s.at(((i.b >> 16) & 31) * 4 + 1).type == Symbol::Type::zero_stride_word @@ -819,22 +820,20 @@ struct DirectCompute { if (j < n || !raw) { const unsigned component = (std::min)(j, n - 1); value = read(data + (half ? component / 2 : component)); - if (packed_x) { - value = ir.binary("and", value, "65535"); - } else if (half) { + if (half) { if (component % 2) value = ir.binary("lshr", value, "16"); value = ir.invoke("float", "legacyF16ToF32", 131, {{"i32", value}}, "nounwind readnone"); } } - args.emplace_back(half && !packed_x ? "float" : "i32", value); + args.emplace_back(half ? "float" : "i32", value); } args.emplace_back("i8", to_string(raw ? (1u << n) - 1 : 15)); if (raw) args.emplace_back("i32", "4"); ir.invoke("void", - raw ? "rawBufferStore.i32" - : half && !packed_x ? "bufferStore.f32" + raw ? "rawBufferStore.i32" + : half ? "bufferStore.f32" : "bufferStore.i32", raw ? 140 : 69, args, "nounwind"); if (!graphics_input) diff --git a/tests/startup_compute_packed_d16_x_uav_check.py b/tests/startup_compute_packed_d16_x_uav_check.py index 799ba779f..fd5ed0ddf 100644 --- a/tests/startup_compute_packed_d16_x_uav_check.py +++ b/tests/startup_compute_packed_d16_x_uav_check.py @@ -1,12 +1,14 @@ """Publish a source-built one-component D16 buffer store and check the written halfwords. No game data. The program is a gfx1013 `buffer_store_format` with the D16 bit and one -component (the direct compiler's `packed_d16_x_uav`). `compile_dxil --requests` must -publish `uav 0 bufd16x table 1 32 bytes 2`. The stand-in then dispatches that translation. -The reference halfwords are the low half of `v_xor_b32` of the literal `0xc0003c00` with -the lane id, which for lanes 0..12 is `0x3c00 + lane`. An R32_UINT view (two halfwords -per element), a stride other than 2, and a descriptor with swizzle flags set must refuse -by name. Before publication the dispatch stays `no translation`. +component. That store is the half-buffer UAV, so `compile_dxil --requests` must publish +`uav 0 bufhalf table 1 32 bytes 2` and must not publish `bufd16x`. `bufd16x` is only for +a binding whose kind is `packed_d16_x_uav`. The stand-in then dispatches the half-buffer +translation. The reference halfwords are the low half of `v_xor_b32` of the literal +`0xc0003c00` with the lane id, which for lanes 0..12 is `0x3c00 + lane`. An R32_UINT +view (two halfwords per element), a stride other than 2, and a descriptor with swizzle +flags set must refuse by the half-buffer name. Before publication the dispatch stays +`no translation`. usage: startup_compute_packed_d16_x_uav_check.py @@ -31,9 +33,9 @@ FLOAT16 = 13 UINT32 = 20 WORD3_BASE = 0x01000fac -INCOMPATIBLE = 'formatted D16 write has an incompatible typed buffer UAV' +INCOMPATIBLE = 'a half buffer store requires matching format, stride and structured bounds' MODE = 'dispatch-records32-output-offset' -MANIFEST_LINE = f'uav 0 bufd16x table 1 32 bytes {STRIDE}' +MANIFEST_LINE = f'uav 0 bufhalf table 1 32 bytes {STRIDE}' def vop2(op, dst, src0, src1): @@ -130,6 +132,7 @@ def publish(compile_dxil, sdk, cache, key): assert result.returncode == 0 and manifest.is_file(), (result.returncode, result.stdout, result.stderr) text = manifest.read_text() assert MANIFEST_LINE in text.splitlines(), text + assert not any(line.startswith('uav ') and ' bufd16x ' in line for line in text.splitlines()), text assert not (cache / f'{key}.cs.hlsl').exists(), 'expected native publication' From 32406a357b3313e71acb1b2a98324079b2d22bcf Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 29 Nov 2026 00:34:36 +0000 Subject: [PATCH 3/3] compute: publish the packed_d16_x manifest line A one-component D16 store stays packed_d16_x_uav and keeps the integer store. format_compute_runtime_manifest writes `uav N packed_d16_x table R B`. The reader binds R16_FLOAT and R16_UINT as R16_UINT and leaves R32_UINT as R32_UINT. The one-channel half-buffer fixture, including both MTBUF forms, expects that line. Co-authored-by: SimSalabimse --- .../compute-output-buffer-reasons.md | 6 ++- docs/experiments/packed-d16-x-uav-manifest.md | 50 +++++++++---------- src/direct_compute_cache.cpp | 11 ++-- src/gfx1013_direct_compute.inl | 17 ++++--- src/startup_stubs/d3d12_compute_dispatch.inl | 20 ++++---- tests/native_compute_manifest_reasons.cpp | 21 +++++++- .../startup_compute_half_buffer_uav_check.py | 6 ++- .../startup_compute_packed_d16_x_uav_check.py | 49 ++++++++++++------ 8 files changed, 114 insertions(+), 66 deletions(-) diff --git a/docs/experiments/compute-output-buffer-reasons.md b/docs/experiments/compute-output-buffer-reasons.md index 451998dd1..351b0bac7 100644 --- a/docs/experiments/compute-output-buffer-reasons.md +++ b/docs/experiments/compute-output-buffer-reasons.md @@ -109,7 +109,11 @@ byte 32, as a title copies descriptors. A native slot 67 request with a `half_buffer_uav` now publishes `uav bufhalf table bytes `. The stride selects a typed buffer view of `R16_FLOAT`, `R16G16_FLOAT` or -`R16G16B16A16_FLOAT` for 2, 4 or 8 bytes respectively. The runtime +`R16G16B16A16_FLOAT` for 2, 4 or 8 bytes respectively. A one-component +D16 store is `packed_d16_x_uav` instead: it publishes +`uav packed_d16_x table `, and the runtime +binds `R16_FLOAT` and `R16_UINT` as `R16_UINT` and `R32_UINT` as +`R32_UINT`. The half view requires the matching gfx10 buffer format, identity selects over the written components and structured out-of-bounds mode. It binds the descriptor's record count and element-aligned offset into an aliased diff --git a/docs/experiments/packed-d16-x-uav-manifest.md b/docs/experiments/packed-d16-x-uav-manifest.md index 341949361..582b64309 100644 --- a/docs/experiments/packed-d16-x-uav-manifest.md +++ b/docs/experiments/packed-d16-x-uav-manifest.md @@ -1,26 +1,29 @@ -# Published manifest names for D16 buffer stores +# Published manifest for a one-component packed D16 buffer store -`view_kind_name` names `packed_d16_x_uav` and `indexed_raw_srv`. A refusal that -mentions either kind prints that name. +A direct compute `buffer_store_format` with the D16 bit and one component, +including the same store reached through an MTBUF opcode, is +`packed_d16_x_uav`. The integer store is `value & 65535` then +`bufferStore.i32`. `format_compute_runtime_manifest` publishes -`format_compute_runtime_manifest` emits -`uav bufd16x table bytes 2` only when the binding -kind is `packed_d16_x_uav`, the binding is one register, and the payload is two -bytes. The dispatch reader accepts that line next to `bufhalf` and still checks -the view with `native_buffer_store_view`. A format, stride or flag that check -rejects keeps the reason `formatted D16 write has an incompatible typed buffer UAV`. +`uav packed_d16_x table ` -A one-component `buffer_store_format` with the D16 bit is the half-buffer UAV. -It publishes `uav bufhalf table bytes 2`, the same -line the half-buffer fixture already requires. It does not publish `bufd16x`. +when that binding is one register and the payload is two bytes. +`load_compute_translation` reads the line. The placed buffer view is checked +with `native_buffer_store_view`: `R16_FLOAT` and `R16_UINT` are bound as +`R16_UINT`, and `R32_UINT` stays `R32_UINT` with a 4-byte element. A +descriptor that matches none of those keeps the refusal +`a half buffer store requires matching format, stride and structured bounds`. + +Two- and four-component D16 stores stay `half_buffer_uav` and publish +`bufhalf`. The source-built fixture is `tests/startup_compute_packed_d16_x_uav_check.py`. -It has no title data. It checks that this store's manifest line is the half-buffer -line and not `bufd16x`. Thirteen lanes write `0x3c00 + lane` at byte 8 of a -sentinel buffer. An R32_UINT view, a stride other than 2, and a descriptor with -the swizzle flag set must refuse with -`a half buffer store requires matching format, stride and structured bounds`. -Before the manifest exists the dispatch is `no translation`. +It has no title data. Thirteen lanes write `0x3c00 + lane` at byte 8. An +`R32_UINT` view writes those values zero-extended to dwords. A stride other +than the element size, and a descriptor with the swizzle flag set, must refuse +by the name above and leave the buffer untouched. Before the manifest exists +the dispatch is `no translation`. The one-channel half-buffer fixture, MUBUF +and both MTBUF forms, expects the same manifest line. On Linux the reference half of the fixture runs with no compiler and no device: @@ -28,17 +31,14 @@ On Linux the reference half of the fixture runs with no compiler and no device: ./out/pe-env/bin/python -B tests/startup_compute_packed_d16_x_uav_check.py ``` -The compile and dispatch halves need Windows, DXC and the stand-in. WARP is the CI -adapter. A hardware adapter is selected the same way as the other `startup_compute_*` -dispatch tests and returns 77 when none is available. +The compile and dispatch halves need Windows, DXC and the stand-in. ```powershell -ctest --preset dev --no-tests=error -R '^startup_compute_(packed_d16_x_uav_|half_buffer_uav_)' -V +ctest --preset dev --no-tests=error -R 'native_compute_manifest_reasons|startup_compute_half_buffer_uav.*|native_compile_dxil.*|.*packed_d16.*|.*store_d16_x.*' -V ``` A 900 s start-up run of a retail title on the Windows test PC, runtime built from `main` `aec2e08`, counted 23 shaders and 86,436 untranslated dispatches (5.7% of that run's untranslated compute dispatches) whose published-route refusal was -`unsupported startup runtime manifest bindings: UAV kind unknown` for a one-component -D16 store. Those counts are from that run. Windows results for this correction are not -in this note. +`unsupported startup runtime manifest bindings: UAV kind unknown` for this binding. +Those counts are from that run. Windows results for this manifest line are not in this note. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 2b63b9935..5a64fd3fb 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -893,8 +893,10 @@ static const char *view_kind_name(ComputeViewKind kind) { "heap_stride_srv", "raw_buffer_uav", "typed_buffer_uav", "half_buffer_uav", "root_buffer_srv", "comparison_texture_srv", "half2_texture_uav", "half4_texture_uav", "cube_sample_srv", "cube_comparison_srv", "indexed_atomic_uav", "d16_sample_srv", "byte_window_srv", "heap_buffer_srv", "heap_sampler", - "uint_texture_uav", "float_texture_uav", "float2_texture_uav", "float3_texture_uav", - "packed_d16_x_uav", "indexed_raw_srv"}; + "uint_texture_uav", "float_texture_uav", "float2_texture_uav", "float3_texture_uav", "packed_d16_x_uav", + "indexed_raw_srv"}; + // ponytail: catches a renamed last kind, not one appended after it; extend both together. + static_assert(std::size(names) == static_cast(ComputeViewKind::indexed_raw_srv) + 1); const auto index = static_cast(kind); return index < std::size(names) ? names[index] : "unknown"; } @@ -981,9 +983,8 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh uav_lines << "uav " << b.shader_register << " bufhalf table " << b.root_parameter << ' ' << b.byte_offset << " bytes " << b.required_bytes << '\n'; } else if (b.kind == ComputeViewKind::packed_d16_x_uav && b.array_count == 1 && b.required_bytes == 2) { - // One halfword. A wider element (R32_UINT holds two) is not published as this store. - uav_lines << "uav " << b.shader_register << " bufd16x table " << b.root_parameter << ' ' - << b.byte_offset << " bytes " << b.required_bytes << '\n'; + uav_lines << "uav " << b.shader_register << " packed_d16_x table " << b.root_parameter << ' ' + << b.byte_offset << '\n'; } else if (b.kind == ComputeViewKind::uint_texture_uav && b.image_dimension == 1 && b.array_count == 1) { uav_lines << "uav " << b.shader_register << " tex2d uint table " << b.root_parameter << ' ' << b.byte_offset << " channels 1\n"; diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index 764816b97..35f4cbc68 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -740,10 +740,9 @@ struct DirectCompute { unsigned n = raw ? widths[i.op & 3] : (i.op & 3) + 1, data = 256 + i.dst; if (i.dst + (half ? (n + 1) / 2 : n) > 256) refuse(i.pc, "direct buffer data overflow"); - // A one-component D16 store is the half-buffer UAV. Its published line is - // `bufhalf` with a 2-byte stride. packed_d16_x_uav is a different binding - // and is the only kind that publishes `bufd16x`. - auto kind = store ? (raw ? ComputeViewKind::raw_buffer_uav + const bool packed_x = half && n == 1 && !graphics_input; + auto kind = store ? (raw ? ComputeViewKind::raw_buffer_uav + : packed_x ? ComputeViewKind::packed_d16_x_uav : half ? ComputeViewKind::half_buffer_uav : ComputeViewKind::typed_buffer_uav) : raw && s.at(((i.b >> 16) & 31) * 4 + 1).type == Symbol::Type::zero_stride_word @@ -820,20 +819,22 @@ struct DirectCompute { if (j < n || !raw) { const unsigned component = (std::min)(j, n - 1); value = read(data + (half ? component / 2 : component)); - if (half) { + if (packed_x) { + value = ir.binary("and", value, "65535"); + } else if (half) { if (component % 2) value = ir.binary("lshr", value, "16"); value = ir.invoke("float", "legacyF16ToF32", 131, {{"i32", value}}, "nounwind readnone"); } } - args.emplace_back(half ? "float" : "i32", value); + args.emplace_back(half && !packed_x ? "float" : "i32", value); } args.emplace_back("i8", to_string(raw ? (1u << n) - 1 : 15)); if (raw) args.emplace_back("i32", "4"); ir.invoke("void", - raw ? "rawBufferStore.i32" - : half ? "bufferStore.f32" + raw ? "rawBufferStore.i32" + : half && !packed_x ? "bufferStore.f32" : "bufferStore.i32", raw ? 140 : 69, args, "nounwind"); if (!graphics_input) diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 2e6123525..1164c1591 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -3,7 +3,7 @@ // .cs.cso. Bound from the compute tables recorded by slot 35 and compute root SRVs recorded by slot 43: raw // buffers (`srv buf table ` and `srv buf root ` inputs, `uav table ` // outputs, `uav bufhalf table bytes ` for typed half stores, or -// `uav bufd16x table bytes 2` for a one-component packed D16 store) +// `uav packed_d16_x table ` for a one-component packed D16 store) // 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 @@ -93,10 +93,9 @@ unsigned float_output_channels(DXGI_FORMAT format) } } -// Published `bufd16x` stores one halfword. native_buffer_store_view accepts an R32_UINT element -// (two halfwords, stride widened to 4) and rewrites R16_FLOAT / R16_UINT to R16_UINT. This path -// keeps that check, then refuses anything that is not the rewritten one-halfword view: a 32-bit -// element would store a zero-extended payload over both halfwords. +// Published `packed_d16_x` stores one low halfword. native_buffer_store_view accepts R16_FLOAT and +// R16_UINT (both rewritten to R16_UINT) and R32_UINT (stride widened to 4). A descriptor that is +// none of those keeps the half-buffer refusal the one-channel fixture already checks. const char* packed_d16_x_view_refusal(const std::uint32_t* words, UINT64 offset, UINT64 resource_bytes, D3D12_UNORDERED_ACCESS_VIEW_DESC& out) { @@ -131,8 +130,8 @@ const char* packed_d16_x_view_refusal(const std::uint32_t* words, UINT64 offset, view.Buffer.FirstElement = static_cast(offset / step); view.Buffer.NumElements = words[2] ? words[2] : 1u; const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::packed_d16_x_uav, 0, 0, 0, 2}; - if (!x2w::native_buffer_store_view(binding, view, resource_bytes) || view.Format != DXGI_FORMAT_R16_UINT) - return "formatted D16 write has an incompatible typed buffer UAV"; + if (!x2w::native_buffer_store_view(binding, view, resource_bytes)) + return "a half buffer store requires matching format, stride and structured bounds"; out = view; return nullptr; } @@ -268,8 +267,8 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.uavs.push_back({a, b}); tr.uavs.back().half_buffer_bytes = x; } - else if (std::sscanf(line.c_str(), "uav %u bufd16x table %d %d bytes %u%n", &i, &a, &b, &x, &used) == 4 && - whole() && i == tr.uavs.size() && x == 2) { + else if (std::sscanf(line.c_str(), "uav %u packed_d16_x table %d %d%n", &i, &a, &b, &used) == 3 && + whole() && i == tr.uavs.size()) { tr.uavs.push_back({a, b}); tr.uavs.back().packed_d16_x = true; } @@ -876,8 +875,7 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& if (!reason && slot.packed_d16_x && !slot.half_typed_bytes) { token.view.Format = desktop_format(token.view.Format); const x2w::ComputeViewBinding binding{x2w::ComputeViewKind::packed_d16_x_uav, 0, 0, 0, 2}; - if (!x2w::native_buffer_store_view(binding, token.view, token.backing.Width) || - token.view.Format != DXGI_FORMAT_R16_UINT) + if (!x2w::native_buffer_store_view(binding, token.view, token.backing.Width)) reason = "formatted D16 write has an incompatible typed buffer UAV"; } if (reason && token.placement == Placement::copied_buffer && diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp index 92d7147f1..66366ee26 100644 --- a/tests/native_compute_manifest_reasons.cpp +++ b/tests/native_compute_manifest_reasons.cpp @@ -68,6 +68,10 @@ 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 packed_d16_x_uav", [](auto &p) { + p.bindings[1].kind = K::packed_d16_x_uav; + p.bindings[1].required_bytes = 4; + }}, {"UAV kind texture_uav cube", [](auto &p) { p.bindings[1].kind = K::texture_uav; p.bindings[1].image_dimension = 3; @@ -117,6 +121,21 @@ 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); + { + auto program = base(); + program.bindings[1].kind = K::packed_d16_x_uav; + program.bindings[1].required_bytes = 2; + reason = "unset"; + const auto manifest = format_compute_runtime_manifest(program, &reason); + const char *line = "uav 0 packed_d16_x table 1 32\n"; + std::string wanted = expected; + wanted.replace(wanted.find("uav 0 table 1 32\n"), std::strlen("uav 0 table 1 32\n"), line); + const bool ok = manifest && *manifest == wanted && reason == "unset"; + std::printf("%s publishes %s", ok ? "ok " : "FAIL", 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) + 2); return failures ? 1 : 0; } diff --git a/tests/startup_compute_half_buffer_uav_check.py b/tests/startup_compute_half_buffer_uav_check.py index d5e2e5f75..e2f08d309 100644 --- a/tests/startup_compute_half_buffer_uav_check.py +++ b/tests/startup_compute_half_buffer_uav_check.py @@ -75,7 +75,11 @@ def publish(compile_dxil, sdk, cache, key, stride): manifest = cache / f'{key}.txt' assert result.returncode == 0 and manifest.is_file(), (result.stdout, result.stderr) text = manifest.read_text() - assert f'uav 0 bufhalf table 1 32 bytes {stride}' in text.splitlines(), text + # One component is packed_d16_x_uav. Wider D16 stores stay on the half-buffer line. + line = 'uav 0 packed_d16_x table 1 32' if stride == 2 else f'uav 0 bufhalf table 1 32 bytes {stride}' + assert line in text.splitlines(), text + if stride == 2: + assert f'uav 0 bufhalf table 1 32 bytes {stride}' not in text.splitlines(), text assert not (cache / f'{key}.cs.hlsl').exists(), 'expected native publication' diff --git a/tests/startup_compute_packed_d16_x_uav_check.py b/tests/startup_compute_packed_d16_x_uav_check.py index fd5ed0ddf..b7be3c29d 100644 --- a/tests/startup_compute_packed_d16_x_uav_check.py +++ b/tests/startup_compute_packed_d16_x_uav_check.py @@ -1,14 +1,13 @@ """Publish a source-built one-component D16 buffer store and check the written halfwords. No game data. The program is a gfx1013 `buffer_store_format` with the D16 bit and one -component. That store is the half-buffer UAV, so `compile_dxil --requests` must publish -`uav 0 bufhalf table 1 32 bytes 2` and must not publish `bufd16x`. `bufd16x` is only for -a binding whose kind is `packed_d16_x_uav`. The stand-in then dispatches the half-buffer -translation. The reference halfwords are the low half of `v_xor_b32` of the literal -`0xc0003c00` with the lane id, which for lanes 0..12 is `0x3c00 + lane`. An R32_UINT -view (two halfwords per element), a stride other than 2, and a descriptor with swizzle -flags set must refuse by the half-buffer name. Before publication the dispatch stays -`no translation`. +component (`packed_d16_x_uav`). `compile_dxil --requests` must publish +`uav 0 packed_d16_x table 1 32`. The stand-in binds an R16_FLOAT or R16_UINT view as +R16_UINT and an R32_UINT view as R32_UINT. The reference halfwords are the low half of +`v_xor_b32` of the literal `0xc0003c00` with the lane id, which for lanes 0..12 is +`0x3c00 + lane`. A stride other than the element size, and a descriptor with swizzle +flags set, must refuse with the half-buffer shape reason. Before publication the +dispatch stays `no translation`. usage: startup_compute_packed_d16_x_uav_check.py @@ -29,13 +28,14 @@ RECORDS = 13 STRIDE = 2 # gfx10 unified BUF_FMT_16_FLOAT is 13; BUF_FMT_32_UINT is 20. RESOURCE_LEVEL is bit 24 -# and 0xfac is identity DST_SEL. A 32-bit element holds two halfwords, so it is not this store. +# and 0xfac is identity DST_SEL. R32_UINT keeps a 4-byte element; the stored halfword is +# zero-extended into that dword. FLOAT16 = 13 UINT32 = 20 WORD3_BASE = 0x01000fac INCOMPATIBLE = 'a half buffer store requires matching format, stride and structured bounds' MODE = 'dispatch-records32-output-offset' -MANIFEST_LINE = f'uav 0 bufhalf table 1 32 bytes {STRIDE}' +MANIFEST_LINE = 'uav 0 packed_d16_x table 1 32' def vop2(op, dst, src0, src1): @@ -91,6 +91,13 @@ def expected(): return list(struct.unpack('<%dI' % WORDS, data)) +def expected_r32(): + data = bytearray(struct.pack('<%dI' % WORDS, *([SENTINEL] * WORDS))) + for lane in range(RECORDS): + struct.pack_into('> 12) & 127 == UINT32 - print(f'reference: {RECORDS} halfwords at byte {OFFSET}, guards intact, three negative descriptors differ') + assert expected() != expected_r32() + wide_raw = struct.pack('<%dI' % WORDS, *expected_r32()) + for lane in range(RECORDS): + got, = struct.unpack_from('