From fb53abdab966dcec8dbc3c0c6dcdc1d802fc7e84 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 01:57:48 +0100 Subject: [PATCH 1/5] runtime: bind 3D and 1D texture UAVs and write them in the C++ compute manifest (#2974) The stand-in's manifest reader and Dispatch path took only 2D and 2D array output textures, so a compute program storing to a 3D or 1D image could not run on cpp-migration. The runtime half of #2902 (open on main) is taken here unchanged: `uav N tex3d|tex1d float table P OFF channels C` lines, TEXTURE3D/TEXTURE1D UAV views from the title's view record, and the mip and W range checks, also for slot 19. For the offline route, format_compute_runtime_manifest now writes those lines for 3D and 1D texture UAVs, so compile_dxil publishes a manifest the runtime accepts. AI-assisted. --- CMakeLists.txt | 6 +- docs/startup-runtime.md | 12 ++ src/direct_compute_cache.cpp | 12 +- src/startup_stubs/d3d12_compute_dispatch.inl | 56 +++++++-- src/startup_stubs/d3d12_xs_device.cpp | 20 +++- .../startup_compute_dispatch_texture_check.py | 106 +++++++++++++++++- tests/startup_stream_consumer.cpp | 39 +++++-- 7 files changed, 217 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 216c036147..8a2fc251a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4745,9 +4745,13 @@ if(EXISTS "${INTAKE_PYTHON}") add_test(NAME startup_compute_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_check.py" "$" "${DXC_EXECUTABLE}" ${adapter}) + unset(texture_native_args) + if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + set(texture_native_args "$" "${DXC_BIN_DIR}") + endif() add_test(NAME startup_compute_dispatch_texture_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$" - "${DXC_EXECUTABLE}" ${adapter}) + "${DXC_EXECUTABLE}" ${adapter} ${texture_native_args}) add_test(NAME startup_slot67_indirect_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_slot67_indirect_dispatch_check.py" "$" "${DXC_EXECUTABLE}" ${adapter}) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index a97fd2607d..0f25147508 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3537,3 +3537,15 @@ before any desktop copy, leaving a sentinel-filled readback buffer unchanged. On list refuses boxes with an unaligned right or bottom edge, copies the aligned 4x4 block, and reads back all eight block bytes with the next byte unchanged. Reproduce the portable and wrapped-list checks with `ctest --preset dev --no-tests=error -R '^startup_list_copy_texture' -V`. + +### Offline compute manifests for 3D and 1D UAVs + +The runtime half of #2902 is ported to `cpp-migration`. For offline compute +requests, the C++ formatter emits `uav N tex3d float table P OFF channels 4` and +`uav N tex1d float table P OFF channels 4`. The stand-in validates UAV view +dimensions and mip levels, including the W-slice range within the selected 3D mip. + +Results: on an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100) the 3D, 3D NSA and 1D +store cases matched their mip-one words after `compile_dxil` published the request, and the mismatched view, 3D W +range and 1D mip controls were refused with the sentinels intact; on WARP the PSO was refused, so only the manifests were checked there. Writing a 3D UAV as +`tex2d`, or dropping the W range check, each fail it. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 9c93af1221..27a86952fe 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -729,8 +729,16 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh uav_lines << "uav " << b.shader_register << " table " << b.root_parameter << ' ' << b.byte_offset << '\n'; } else if ((b.kind == ComputeViewKind::texture_uav || b.kind == ComputeViewKind::half4_texture_uav) && - (b.image_dimension == 1 || b.image_dimension == 5) && b.array_count == 1) { - uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : " tex2d") + b.array_count == 1) { + const char *tex; + switch (b.image_dimension) { + case 0: tex = "tex1d"; break; + case 1: tex = "tex2d"; break; + case 2: tex = "tex3d"; break; + case 5: tex = "tex2da"; break; + default: return std::nullopt; + } + uav_lines << "uav " << b.shader_register << ' ' << tex << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n"; } else { return std::nullopt; diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 6e0be0f75a..b41b23ee70 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -1,8 +1,8 @@ // Translated compute programs at Dispatch (list slot 14). A device slot 67 pipeline is a placeholder that keeps // 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: raw buffers (`srv buf table ` -// inputs, `uav table ` outputs) named by hardware buffer descriptors, and 2D textures -// (`srv tex2d table ` inputs, `uav tex2d/tex2da float table channels 4` outputs) named +// inputs, `uav table ` outputs) named by hardware buffer descriptors, and textures +// (`srv tex2d table ` inputs, `uav tex1d/tex2d/tex2da/tex3d float table channels 4` outputs) named // by the token of a view the title created (device slots 18 and 19). `smp` 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 @@ -11,6 +11,15 @@ // binds nothing (the upload of an input texture the title filled in memory may already be recorded: it only // syncs content). +const char* volume_uav_range_error(const D3D12_RESOURCE_DESC& resource, const D3D12_TEX3D_UAV& view) +{ + if (view.MipSlice >= resource.MipLevels) return "an output 3D texture mip is outside the resource"; + const UINT depth = (std::max)(1u, UINT{resource.DepthOrArraySize} >> (std::min)(view.MipSlice, 15u)); + if (view.FirstWSlice >= depth || !view.WSize || (view.WSize != ~0u && view.WSize > depth - view.FirstWSlice)) + return "an output 3D texture W range is outside the mip"; + return nullptr; +} + struct ComputeTranslation { // Root parameter and byte offset (views), or parameter and word (entry values). A heap view names the root // constant (parameter and word) that indexes its 32-byte record in the list's view heap, or, with word_param @@ -23,7 +32,7 @@ struct ComputeTranslation { int word_param = -1, word_byte = 0; std::uint32_t at = 0, times = 0; Source source = root_constant; - bool array = false; + D3D12_UAV_DIMENSION uav_dimension = D3D12_UAV_DIMENSION_UNKNOWN; }; u64 key = 0; int state = 0; // 0 not loaded, 1 ready, 2 unavailable @@ -120,6 +129,13 @@ const char* load_compute_translation(ComputeTranslation& tr) if (!std::strcmp(name, names[s])) return static_cast(s + 1); return ComputeTranslation::root_constant; }; + const auto uav_dimension = [&] { + if (!std::strcmp(name, "tex1d")) return D3D12_UAV_DIMENSION_TEXTURE1D; + if (!std::strcmp(name, "tex2d")) return D3D12_UAV_DIMENSION_TEXTURE2D; + if (!std::strcmp(name, "tex2da")) return D3D12_UAV_DIMENSION_TEXTURE2DARRAY; + if (!std::strcmp(name, "tex3d")) return D3D12_UAV_DIMENSION_TEXTURE3D; + return D3D12_UAV_DIMENSION_UNKNOWN; + }; if (line.empty() || (std::sscanf(line.c_str(), "group %u %u %u%n", &x, &y, &z, &used) == 3 && whole())) continue; if (std::sscanf(line.c_str(), "ud %u%n", &declared_uds, &used) == 1 && whole()) continue; if (std::sscanf(line.c_str(), "udsrc %u rootconst %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uds.size()) @@ -140,13 +156,10 @@ 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 tex2d float table %d %d channels 4%n", &i, &a, &b, &used) == 3 && whole() && - i == tr.uavs.size()) - tr.uavs.push_back({a, b, true}); - else if (std::sscanf(line.c_str(), "uav %u tex2da float table %d %d channels 4%n", &i, &a, &b, &used) == 3 && whole() && - i == tr.uavs.size()) { + else if (std::sscanf(line.c_str(), "uav %u %15s float table %d %d channels 4%n", &i, name, &a, &b, &used) == 4 && whole() && + i == tr.uavs.size() && uav_dimension() != D3D12_UAV_DIMENSION_UNKNOWN) { tr.uavs.push_back({a, b, true}); - tr.uavs.back().array = true; + tr.uavs.back().uav_dimension = uav_dimension(); } else if (std::sscanf(line.c_str(), "srv %u tex2d table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size()) tr.srvs.push_back({a, b, true}); @@ -159,7 +172,7 @@ const char* load_compute_translation(ComputeTranslation& tr) i == tr.samplers.statics.size()) tr.samplers.read_manifest_line(line.c_str()); else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 2D texture" - : line.rfind("uav", 0) == 0 ? "an output that is not a raw table buffer or a 2D/2D-array float texture" + : line.rfind("uav", 0) == 0 ? "an output that is not a raw table buffer or a 1D/2D/2D-array/3D float texture" : line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant or a buffer descriptor word" : line.rfind("smp", 0) == 0 ? "a sampler that is not a plain static one" : "an unknown manifest line"; } @@ -379,9 +392,28 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& const DXGI_FORMAT format = desc.Format ? desc.Format : resource.Format; words[3] = static_cast(format) | static_cast(desc.ViewDimension) << 16; if (!known || record.slot != 19) reason = "an output texture entry is not the token of an unordered access view"; - else if (!created || !texture || !(resource.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) + else if (slot.uav_dimension == D3D12_UAV_DIMENSION_TEXTURE3D && + texture && (resource.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) { + const auto& view = desc.Texture3D; + if (!described || desc.ViewDimension != slot.uav_dimension || resource.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D) + reason = "an output texture view or resource is not 3D"; + else { + // Slot 19 can retain a rejected range as an unmaterialized view. + reason = volume_uav_range_error(resource, view); + if (!reason && !created) reason = "an output texture view was not created on the desktop"; + } + } else if (slot.uav_dimension == D3D12_UAV_DIMENSION_TEXTURE1D && + texture && (resource.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) { + // Checked before `created`, as for 3D: slot 19 records a 1D view with an out-of-range mip as refused. + if (!described || desc.ViewDimension != slot.uav_dimension || resource.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE1D) + reason = "an output texture view or resource is not 1D"; + else if (desc.Texture1D.MipSlice >= resource.MipLevels) + reason = "an output 1D texture mip is outside the resource"; + else if (!created) + reason = "an output texture view was not created on the desktop"; + } else if (!created || !texture || !(resource.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) reason = "an output texture view was not created on the desktop"; - else if (slot.array) { + else if (slot.uav_dimension == D3D12_UAV_DIMENSION_TEXTURE2DARRAY) { // The layer in HLSL is relative to FirstArraySlice: retain the caller's complete view. const auto& a = desc.Texture2DArray; if (!described || desc.ViewDimension != D3D12_UAV_DIMENSION_TEXTURE2DARRAY) diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 680d176faf..0a45e217c4 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -4547,14 +4547,14 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d) }; const char* skip = nullptr; bool default_view = false; - bool uav_denied = false; // a UAV of a resource without unordered access: recorded as not created, as before #2649 + bool record_refused_uav = false; if (N == 17) skip = "constant buffer view (title GPU address)"; if (N >= 18 && N <= 21 && args[0]) { const UINT flags = reinterpret_cast(args[0])->GetDesc().Flags; if (N == 18 && (flags & D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE)) skip = "resource denies shader resource views"; if (N == 19 && !(flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)) { skip = "resource lacks unordered access"; - uav_denied = true; + record_refused_uav = true; } if (N == 20 && !(flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)) skip = "resource lacks render target"; if (N == 21 && !(flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) skip = "resource lacks depth stencil"; @@ -4589,6 +4589,20 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d) if (first_calls(mismatched, 6)) log("x2w-d3d12 Device::slot%d view dimension %u needs resource dimension %u, resource has %u", N, view_dimension, x2w_view_dimension::needed(N, view_dimension), dimension); + } else if constexpr (N == 19) { + if (view_dimension == D3D12_UAV_DIMENSION_TEXTURE3D && + x2w_local::readable(reinterpret_cast(described), sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC))) { + D3D12_UNORDERED_ACCESS_VIEW_DESC view{}; + std::memcpy(&view, reinterpret_cast(described), sizeof(view)); + skip = volume_uav_range_error(resource_desc, view.Texture3D); + record_refused_uav = skip != nullptr; + } else if (view_dimension == D3D12_UAV_DIMENSION_TEXTURE1D && + x2w_local::readable(reinterpret_cast(described), sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC))) { + D3D12_UNORDERED_ACCESS_VIEW_DESC view{}; + std::memcpy(&view, reinterpret_cast(described), sizeof(view)); + if (view.Texture1D.MipSlice >= resource_desc.MipLevels) skip = "an output 1D texture mip is outside the resource"; + record_refused_uav = skip != nullptr; + } } } } @@ -4607,7 +4621,7 @@ __declspec(noinline) u64 view_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d) } else if constexpr (N == 19) { // A translated compute Dispatch tells this refusal from a descriptor that holds no view by the record. // A refused creation leaves a descriptor that still holds a live view as it is. - if (uav_denied && !descriptor_has_live_view(args[D], title_dest)) record_view(false); + if (record_refused_uav && !descriptor_has_live_view(args[D], title_dest)) record_view(false); } }; if (skip) { diff --git a/tests/startup_compute_dispatch_texture_check.py b/tests/startup_compute_dispatch_texture_check.py index fd09c48dec..9d00f6d274 100644 --- a/tests/startup_compute_dispatch_texture_check.py +++ b/tests/startup_compute_dispatch_texture_check.py @@ -1,6 +1,6 @@ -"""Translated compute programs with 2D texture views, dispatched through the stand-in's command list (slot 14). +"""Translated compute programs with texture views, dispatched through the stand-in's command list (slot 14). -usage: startup_compute_dispatch_texture_check.py +usage: startup_compute_dispatch_texture_check.py [ ] Texture output: the consumer creates the image store program of startup_compute_image_store_d16_check.py as a device slot 67 pipeline, fills a 32x8 RGBA16_FLOAT texture with sentinel halves, creates an unordered access view of @@ -13,6 +13,8 @@ 4. texture-store-denied (a texture without unordered access, whose view the stand-in does not create): refused with one logged reason, every half keeps its sentinel. A fifth run binds the same program under a manifest edited to declare no entry values. +With compile_dxil, the 1D and 3D float texture cases check offline request publication, mip-one readback, +mismatched views, an invalid 3D W range, and an invalid 1D mip. Texture input: case A of startup_gfx2hlsl_compute_check.py with a level-zero sample of a 2D texture XORed into the stored word (a static sampler, a texture view at table byte 64). The consumer adds a 1x1 RGBA8 texture whose red @@ -148,6 +150,99 @@ def store(directory, consumer, dxc, env): f'untouched before translation, without a Dispatch and for a refused view; debug layer: {layer}') +STORE_FORMS = { + 'volume': '101f20f002080400', + 'volume-nsa': '121f20f00208040003050000', + 'line': '001f20f000080200', +} +STORE_VALUES = (0x3f400000, 0x3e800000, 0x40810000, 0xbf810001) +STORE_RSRC2 = (10 << 1) | C.TGID_X | C.TGID_Y | C.tidig(2) + + +def store_group(form): + return (4, 1, 1) if form == 'line' else (4, 2, 1) + + +def store_program(form): + prefix = bytes.fromhex('07038cbe80038dbe') # s[12:13] = table pointer in s7, zero extended + if form == 'line': + address = bytes.fromhex( + '000046d70a040104' # v0 = group X * 4 + thread X, before the load overwrites s10 + '06020cf4400000fa' # s_load_dwordx8 s[8:15], s[12:13], 0x40 + ) + else: + address = bytes.fromhex( + '06040cf4400000fa' # s_load_dwordx8 s[16:23], s[12:13], 0x40 + '020046d70a040104' # v2 = group X * 4 + thread X + '030046d70b020504' # v3 = group Y * 2 + thread Y + ) + address += bytes.fromhex('81020a7e' if form == 'volume-nsa' else '8102087e') # relative Z = 1 + values = b''.join(struct.pack('<2I', 0x7e0002ff | (8 + i) << 17, word) + for i, word in enumerate(STORE_VALUES)) + return prefix + address + bytes.fromhex('7fc08cbf') + values + bytes.fromhex(STORE_FORMS[form] + '000081bf') + + +def store_3d1d(directory, consumer, compiler, sdk, env, adapter, form): + cache, base = prepare(directory) + env = dict(base, **env) + env.pop('X2W_NATIVE_SHADERS', None) + root = directory / 'compute_root' + # The helper's final RTS0 range is replaced with UAV(u0, offset=2). Each guest record is 32 bytes. + root.write_bytes(C.root_blob(3, table_range=True)[:-24] + struct.pack('<6I', 1, 1, 0, 0, 0, 2)) + env['X2W_TEST_COMPUTE_ROOT'] = str(root) + group = store_group(form) + (directory / 'program').write_bytes(store_program(form)) + (directory / 'data').write_bytes(DATA) + (directory / 'state').write_bytes(state_a(group, STORE_RSRC2)) + + volume = form != 'line' + mode = 'texture-volume' if volume else 'texture-line' + width, height, depth = 32, 8 if volume else 1, 6 if volume else 1 + plane_words = width * height * 4 + initial = [0xbf000000 | (z << 12) | i for z in range(depth) for i in range(plane_words)] + expected = initial.copy() + for y in range(group[1]): + # The 3D view starts at W slice 1 and the shader writes relative Z = 1. + start = (2 * plane_words if volume else 0) + y * width * 4 + expected[start:start + 32] = STORE_VALUES * 8 + layout = '<%dI' % len(initial) + got, result = run(directory, consumer, env, mode, layout) + assert got == initial and len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] + key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16) + compiled = subprocess.run([compiler, sdk, directory / 'frontend', 'gfx1013-direct-cs@0', '--requests', cache, cache], + capture_output=True, text=True) + assert compiled.returncode == 0 and 'requests=1 compiled=1 refused=0' in compiled.stdout, ( + compiled.stdout, compiled.stderr) + assert (cache / f'{key:016x}.cs.cso').read_bytes().startswith(b'DXBC') + manifest = (cache / f'{key:016x}.txt').read_text().splitlines() + dim = '3d' if volume else '1d' + assert f'uav 0 tex{dim} float table 1 64 channels 4' in manifest, manifest + + got, result = run(directory, consumer, env, mode, layout) + # Older WARP builds refuse the direct compiler's WaveSize(32) PSO. + if adapter == 'warp' and lines(result, 'not translated: pipeline creation failed'): + assert got == initial and len(lines(result, 'Dispatch(2, 1, 1) refused: pipeline creation failed')) == 1, ( + result.stderr[-3000:]) + print(f'{form}: manifest verified; WARP refused PSO creation, skipping dispatch and view checks') + return + assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] + assert got == expected, (form, sum(a != b for a, b in zip(got, expected, strict=True))) + clean(result) + + mismatch = [0xbf000000 | i for i in range(32 * 8 * 4)] + cases = [('texture-array-2d', mismatch, f'an output texture view or resource is not {dim.upper()}')] + if volume: + cases.append(('texture-volume-bad-w', initial, 'an output 3D texture W range is outside the mip')) + else: + cases.append(('texture-line-bad-mip', initial, 'an output 1D texture mip is outside the resource')) + for bad_mode, untouched, reason in cases: + got, result = run(directory, consumer, env, bad_mode, '<%dI' % len(untouched)) + refusal = lines(result, 'Dispatch(2, 1, 1) refused:') + assert len(refusal) == 1 and refusal[0].endswith(reason), result.stderr[-3000:] + assert got == untouched and not lines(result, 'Dispatch(2, 1, 1) translated') + print(f'{form}: {len(expected)} mip-one words match; incompatible views refused with sentinels intact') + + # v_xor_b32 v5, v5, v12: the assembled `v_xor_b32 v5, v5, v6` of case A with its second source register changed # (not assembled by llvm-mc here; the translation below is checked to read it as written). XOR = 'v_xor_b32 v5, v5, v12' @@ -263,18 +358,21 @@ def reds(got): f'program with a clamp sampler reads 0; comparison and heap samplers refused; debug layer: {layer}') -def main(consumer, dxc, adapter): +def main(consumer, dxc, adapter, compiler=None, sdk=None): env = dict(X2W_D3D12_LIST_NOOP='1', X2W_D3D12_DEBUG='1') # guest lists; debug-layer messages go to the log if adapter == 'hardware': env['X2W_TEST_DISPATCH_HARDWARE'] = '1' with tempfile.TemporaryDirectory() as temporary: store(Path(temporary) / 'store', consumer, dxc, env) + if compiler is not None: + for form in STORE_FORMS: + store_3d1d(Path(temporary) / form, consumer, compiler, sdk, env, adapter, form) sample(Path(temporary) / 'sample', consumer, dxc, env) filtered(Path(temporary) / 'filtered', consumer, dxc, env) print(f'startup_compute_dispatch_texture: PASS on {adapter}') if __name__ == '__main__': - if len(sys.argv) != 4 or sys.argv[3] not in ('warp', 'hardware'): + if len(sys.argv) not in (4, 6) or sys.argv[3] not in ('warp', 'hardware'): sys.exit(__doc__) main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 2419156f9b..40e27f1c5d 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -407,9 +407,14 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin // handle, which keeps the first view; texture-store-self also creates a shader resource view of the texture at table byte 0. static int texture_slot67(void* device, const std::string& mode) { - constexpr UINT width = 32, height = 8; - const bool fp32 = mode == "texture-array" || mode == "texture-array-2d"; - const UINT layers = mode == "texture-array" || mode == "texture-array-d16" ? 6 : 1; + constexpr UINT width = 32; + const bool volume = mode == "texture-volume" || mode == "texture-volume-bad-w"; + const bool line = mode == "texture-line" || mode == "texture-line-bad-mip"; + const UINT mip = volume || line ? 1 : 0; + const UINT height = line ? 1 : 8; + const bool fp32 = volume || line || mode == "texture-array" || mode == "texture-array-2d"; + const UINT layers = volume || mode == "texture-array" || mode == "texture-array-d16" ? 6 : 1; + const UINT subresources = volume ? 1 : layers; const UINT pitch = width * (fp32 ? 16 : 8), slice_bytes = pitch * height, bytes = slice_bytes * layers; const auto word = [](const void* value) { return reinterpret_cast(value); }; const auto make = [&](D3D12_HEAP_TYPE type, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES state) { @@ -417,7 +422,10 @@ static int texture_slot67(void* device, const std::string& mode) }; const DXGI_FORMAT format = fp32 ? DXGI_FORMAT_R32G32B32A32_FLOAT : mode == "texture-store-uint" ? DXGI_FORMAT_R16G16B16A16_UINT : DXGI_FORMAT_R16G16B16A16_FLOAT; - const D3D12_RESOURCE_DESC texture_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, width, height, static_cast(layers), 1, format, + const auto dimension = volume ? D3D12_RESOURCE_DIMENSION_TEXTURE3D : line ? D3D12_RESOURCE_DIMENSION_TEXTURE1D : + D3D12_RESOURCE_DIMENSION_TEXTURE2D; + const D3D12_RESOURCE_DESC texture_desc{dimension, 0, width << mip, line ? 1 : height << mip, + static_cast(volume ? layers << mip : layers), static_cast(mip + 1), format, {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, mode == "texture-store-denied" ? D3D12_RESOURCE_FLAG_NONE : D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS}; const D3D12_RESOURCE_DESC buffer_desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, bytes, 1, 1, 1, DXGI_FORMAT_UNKNOWN, {1, 0}, @@ -450,7 +458,14 @@ static int texture_slot67(void* device, const std::string& mode) const StreamWord cpu = invoke(heap, 9), gpu = invoke(heap, 10); if (!cpu || !gpu) return 73; D3D12_UNORDERED_ACCESS_VIEW_DESC view{format, D3D12_UAV_DIMENSION_TEXTURE2D}; - if (layers > 1) { + if (volume) { + view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; + // At mip 1 the depth is six. The bad count fits only if the binder uses the base mip's depth. + view.Texture3D = {mip, 1, mode == "texture-volume-bad-w" ? layers : ~0u}; + } else if (line) { + view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D; + view.Texture1D.MipSlice = mode == "texture-line-bad-mip" ? mip + 1 : mip; // bad-mip: one past the last mip + } else if (layers > 1) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; view.Texture2DArray = {0, 1, 4, 0}; // four selected slices, with untouched neighbors on both sides } @@ -478,15 +493,15 @@ static int texture_slot67(void* device, const std::string& mode) if (mode == "texture-store-self") invoke(device, 18, word(texture), word(&read), cpu); D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; D3D12_TEXTURE_COPY_LOCATION source{static_cast(upload), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; - source.PlacedFootprint = {0, {format, width, height, 1, pitch}}; + source.PlacedFootprint = {0, {format, width, height, volume ? layers : 1, pitch}}; D3D12_TEXTURE_COPY_LOCATION result = source; result.pResource = static_cast(readback); const UINT constants[3] = {1, 2, 3}; if (FAILED(static_cast(invoke(list, 139, word(allocator))))) return 74; invoke(list, 32, 1, word(&heap)); - for (UINT layer = 0; layer < layers; ++layer) { - image.SubresourceIndex = layer; - source.PlacedFootprint.Offset = UINT64{layer} * slice_bytes; + for (UINT subresource = 0; subresource < subresources; ++subresource) { + image.SubresourceIndex = subresource + mip; + source.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; invoke(list, 16, word(&image), 0, 0, 0, word(&source), 0); } invoke(list, 25, word(slot67_pipeline)); @@ -494,9 +509,9 @@ static int texture_slot67(void* device, const std::string& mode) invoke(list, 39, 0, 3, word(constants), 0); invoke(list, 35, 1, gpu); if (mode != "texture-store-none") invoke(list, 14, 2, 1, 1); - for (UINT layer = 0; layer < layers; ++layer) { - image.SubresourceIndex = layer; - result.PlacedFootprint.Offset = UINT64{layer} * slice_bytes; + for (UINT subresource = 0; subresource < subresources; ++subresource) { + image.SubresourceIndex = subresource + mip; + result.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; invoke(list, 16, word(&result), 0, 0, 0, word(&image), 0); } if (FAILED(static_cast(invoke(list, 9)))) return 75; From 76d2b9d03f5ffae538650279303301382d1b0085 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 02:41:47 +0100 Subject: [PATCH 2/5] runtime: name missing 32-lane waves after a PSO failure; portable 3D/1D UAV fixture After a published compute translation fails PSO creation, the stand-in checks the adapter's wave capabilities (the same OPTIONS1 test the native route uses) and logs "pipeline creation failed: the adapter has no 32-lane waves" when they rule out a WaveSize(32) module. The texture check skips the native 3D/1D dispatch cases on WARP only for that reason; any other PSO failure fails it. Portable 3D and 1D cases compile a cs_6_0 store with dxc and a hand-written manifest, so the binding path is checked on WARP and hardware independently of the C++ compiler. AI-assisted. --- docs/startup-runtime.md | 13 +++-- src/startup_stubs/d3d12_compute_dispatch.inl | 18 +++++-- .../startup_compute_dispatch_texture_check.py | 50 ++++++++++++++----- 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 0f25147508..97bdd628b3 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3545,7 +3545,12 @@ requests, the C++ formatter emits `uav N tex3d float table P OFF channels 4` and `uav N tex1d float table P OFF channels 4`. The stand-in validates UAV view dimensions and mip levels, including the W-slice range within the selected 3D mip. -Results: on an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100) the 3D, 3D NSA and 1D -store cases matched their mip-one words after `compile_dxil` published the request, and the mismatched view, 3D W -range and 1D mip controls were refused with the sentinels intact; on WARP the PSO was refused, so only the manifests were checked there. Writing a 3D UAV as -`tex2d`, or dropping the W range check, each fail it. +On an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100), the 3D, 3D NSA and 1D +store cases matched their mip-one words after `compile_dxil` published the translations. The mismatched-view, +3D W-range and 1D mip controls were refused with their sentinels intact. + +If a published compute PSO fails to create, the stand-in checks the adapter's wave capabilities. The native +3D, 3D NSA and 1D cases report a WARP skip only for `pipeline creation failed: the adapter has no 32-lane waves`. +Other PSO failures fail the test. On WARP and hardware, portable `cs_6_0` fixtures publish a hand-written +manifest and bytecode under the original guest program's request key. These cases require successful 3D and 1D +mip-one readback and check the same mismatched-view, 3D W-range and 1D mip refusals with sentinels intact. diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index b41b23ee70..70963205d7 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -75,6 +75,13 @@ bool float_output_format(DXGI_FORMAT format) std::unordered_map& compute_translations() { static std::unordered_map m; return m; } LONG compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled; +bool has_32_lane_waves() +{ + D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; + return SUCCEEDED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) && + waves.WaveOps && waves.WaveLaneCountMin <= 32 && waves.WaveLaneCountMax >= 32; +} + // The root signature and pipeline of a translation whose entry values and views are filled in. Returns why it is // unavailable, or null when it is ready. const char* create_compute_pipeline(ComputeTranslation& tr, const void* code, std::size_t bytes) @@ -186,7 +193,12 @@ const char* load_compute_translation(ComputeTranslation& tr) } x2w_startup::ComPtr code; if (!cache_path(path, L"", tr.key, L".cs.cso") || FAILED(D3DReadFileToBlob(path, &code))) return "no compiled program"; - if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) return failure; + if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) { + // The manifest carries no wave size. Check adapter capabilities only after PSO creation fails. + if (!std::strcmp(failure, "pipeline creation failed") && !has_32_lane_waves()) + return "pipeline creation failed: the adapter has no 32-lane waves"; + return failure; + } log("x2w-draw compute pipeline %016llx translated: %zu entry values, %zu inputs, %zu outputs", tr.key, tr.uds.size(), tr.srvs.size(), tr.uavs.size()); return nullptr; @@ -226,9 +238,7 @@ bool translate_compute_natively(ComputeTranslation& tr) if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) throw std::runtime_error("a sampler, or more entry values, inputs or outputs than the dispatch path binds"); // A direct module declares wave size 32 (src/dxil_module.h): without it the pipeline cannot be created. - D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; - if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) || - !waves.WaveOps || waves.WaveLaneCountMin > 32 || waves.WaveLaneCountMax < 32) + if (!has_32_lane_waves()) throw std::runtime_error("the adapter has no 32-lane waves"); // Never released: a static destructor would release DXC after its module may have detached. static x2w::ShaderDxilCompiler* const compiler = diff --git a/tests/startup_compute_dispatch_texture_check.py b/tests/startup_compute_dispatch_texture_check.py index 9d00f6d274..cfe4fbad1b 100644 --- a/tests/startup_compute_dispatch_texture_check.py +++ b/tests/startup_compute_dispatch_texture_check.py @@ -13,8 +13,8 @@ 4. texture-store-denied (a texture without unordered access, whose view the stand-in does not create): refused with one logged reason, every half keeps its sentinel. A fifth run binds the same program under a manifest edited to declare no entry values. -With compile_dxil, the 1D and 3D float texture cases check offline request publication, mip-one readback, -mismatched views, an invalid 3D W range, and an invalid 1D mip. +Portable 1D and 3D float texture cases check offline request publication, mip-one readback, mismatched views, +an invalid 3D W range, and an invalid 1D mip. With compile_dxil, the native translations check the same path. Texture input: case A of startup_gfx2hlsl_compute_check.py with a level-zero sample of a 2D texture XORed into the stored word (a static sampler, a texture view at table byte 64). The consumer adds a 1x1 RGBA8 texture whose red @@ -157,6 +157,7 @@ def store(directory, consumer, dxc, env): } STORE_VALUES = (0x3f400000, 0x3e800000, 0x40810000, 0xbf810001) STORE_RSRC2 = (10 << 1) | C.TGID_X | C.TGID_Y | C.tidig(2) +NO_WAVES = 'pipeline creation failed: the adapter has no 32-lane waves' def store_group(form): @@ -182,7 +183,24 @@ def store_program(form): return prefix + address + bytes.fromhex('7fc08cbf') + values + bytes.fromhex(STORE_FORMS[form] + '000081bf') -def store_3d1d(directory, consumer, compiler, sdk, env, adapter, form): +def publish_portable_store(cache, dxc, key, dim, group): + name = f'{key:016x}' + source = cache / f'{name}.hlsl' + coord = 'uint3(id.xy, 1)' if dim == '3d' else 'id.x' + threads = ', '.join(map(str, group)) + values = ', '.join(f'0x{word:08x}u' for word in STORE_VALUES) + source.write_text(f'RWTexture{dim.upper()} outputTexture : register(u0);\n' + f'[numthreads({threads})]\n' + 'void main(uint3 id : SV_DispatchThreadID) {\n' + f' outputTexture[{coord}] = asfloat(uint4({values}));\n' + '}\n', encoding='ascii') + subprocess.run([dxc, '-T', 'cs_6_0', '-E', 'main', '-Fo', cache / f'{name}.cs.cso', source], check=True) + (cache / f'{name}.txt').write_text( + f'x2w-manifest 2\nstage cs\ngroup {group[0]} {group[1]} {group[2]}\nud 0\n' + f'uav 0 tex{dim} float table 1 64 channels 4\n', encoding='ascii') + + +def store_3d1d(directory, consumer, dxc, env, adapter, form, compiler=None, sdk=None): cache, base = prepare(directory) env = dict(base, **env) env.pop('X2W_NATIVE_SHADERS', None) @@ -209,21 +227,24 @@ def store_3d1d(directory, consumer, compiler, sdk, env, adapter, form): got, result = run(directory, consumer, env, mode, layout) assert got == initial and len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16) - compiled = subprocess.run([compiler, sdk, directory / 'frontend', 'gfx1013-direct-cs@0', '--requests', cache, cache], - capture_output=True, text=True) - assert compiled.returncode == 0 and 'requests=1 compiled=1 refused=0' in compiled.stdout, ( - compiled.stdout, compiled.stderr) + dim = '3d' if volume else '1d' + if compiler is None: + publish_portable_store(cache, dxc, key, dim, group) + else: + compiled = subprocess.run([compiler, sdk, directory / 'frontend', 'gfx1013-direct-cs@0', '--requests', + cache, cache], capture_output=True, text=True) + assert compiled.returncode == 0 and 'requests=1 compiled=1 refused=0' in compiled.stdout, ( + compiled.stdout, compiled.stderr) assert (cache / f'{key:016x}.cs.cso').read_bytes().startswith(b'DXBC') manifest = (cache / f'{key:016x}.txt').read_text().splitlines() - dim = '3d' if volume else '1d' assert f'uav 0 tex{dim} float table 1 64 channels 4' in manifest, manifest got, result = run(directory, consumer, env, mode, layout) # Older WARP builds refuse the direct compiler's WaveSize(32) PSO. - if adapter == 'warp' and lines(result, 'not translated: pipeline creation failed'): - assert got == initial and len(lines(result, 'Dispatch(2, 1, 1) refused: pipeline creation failed')) == 1, ( + if compiler is not None and adapter == 'warp' and lines(result, f'not translated: {NO_WAVES}'): + assert got == initial and len(lines(result, f'Dispatch(2, 1, 1) refused: {NO_WAVES}')) == 1, ( result.stderr[-3000:]) - print(f'{form}: manifest verified; WARP refused PSO creation, skipping dispatch and view checks') + print(f'{form}: native 3D/1D dispatch cases skipped on WARP: the adapter has no 32-lane waves') return assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] assert got == expected, (form, sum(a != b for a, b in zip(got, expected, strict=True))) @@ -240,7 +261,8 @@ def store_3d1d(directory, consumer, compiler, sdk, env, adapter, form): refusal = lines(result, 'Dispatch(2, 1, 1) refused:') assert len(refusal) == 1 and refusal[0].endswith(reason), result.stderr[-3000:] assert got == untouched and not lines(result, 'Dispatch(2, 1, 1) translated') - print(f'{form}: {len(expected)} mip-one words match; incompatible views refused with sentinels intact') + fixture = 'portable' if compiler is None else 'native' + print(f'{fixture} {form}: {len(expected)} mip-one words match; incompatible views refused with sentinels intact') # v_xor_b32 v5, v5, v12: the assembled `v_xor_b32 v5, v5, v6` of case A with its second source register changed @@ -364,9 +386,11 @@ def main(consumer, dxc, adapter, compiler=None, sdk=None): env['X2W_TEST_DISPATCH_HARDWARE'] = '1' with tempfile.TemporaryDirectory() as temporary: store(Path(temporary) / 'store', consumer, dxc, env) + for form in ('volume', 'line'): + store_3d1d(Path(temporary) / f'portable-{form}', consumer, dxc, env, adapter, form) if compiler is not None: for form in STORE_FORMS: - store_3d1d(Path(temporary) / form, consumer, compiler, sdk, env, adapter, form) + store_3d1d(Path(temporary) / form, consumer, dxc, env, adapter, form, compiler, sdk) sample(Path(temporary) / 'sample', consumer, dxc, env) filtered(Path(temporary) / 'filtered', consumer, dxc, env) print(f'startup_compute_dispatch_texture: PASS on {adapter}') From e18549cafe7f9412b896fd43cf261fdc6750498a Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 03:12:59 +0100 Subject: [PATCH 3/5] runtime: keep the PSO failure as the reason and report the wave capability beside it A failed published compute PSO stays "pipeline creation failed". The stand-in adds the adapter's 32-lane wave capability as observed: "(adapter has no 32-lane waves)" or "(adapter wave capability query failed)". The manifest records no wave size, so the runtime does not claim the shader needed one. Only the texture check, whose native modules declare WaveSize(32), skips its native cases on WARP for the no-waves observation. AI-assisted. --- docs/startup-runtime.md | 9 ++++++--- src/startup_stubs/d3d12_compute_dispatch.inl | 20 ++++++++++++------- .../startup_compute_dispatch_texture_check.py | 4 +++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 97bdd628b3..ba42d07a4f 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3549,8 +3549,11 @@ On an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100), store cases matched their mip-one words after `compile_dxil` published the translations. The mismatched-view, 3D W-range and 1D mip controls were refused with their sentinels intact. -If a published compute PSO fails to create, the stand-in checks the adapter's wave capabilities. The native -3D, 3D NSA and 1D cases report a WARP skip only for `pipeline creation failed: the adapter has no 32-lane waves`. -Other PSO failures fail the test. On WARP and hardware, portable `cs_6_0` fixtures publish a hand-written +If a published compute PSO fails to create, the refusal stays `pipeline creation failed`, and the stand-in adds +the adapter's 32-lane wave capability as observed: `(adapter has no 32-lane waves)`, or `(adapter wave capability +query failed)`. The manifest records no wave size, so this does not say the shader needed one. The test knows its +native modules declare `WaveSize(32)`, so the native 3D, 3D NSA and 1D cases skip on WARP only for +`pipeline creation failed (adapter has no 32-lane waves)`. Any other PSO failure fails the test. +On WARP and hardware, portable `cs_6_0` fixtures publish a hand-written manifest and bytecode under the original guest program's request key. These cases require successful 3D and 1D mip-one readback and check the same mismatched-view, 3D W-range and 1D mip refusals with sentinels intact. diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 70963205d7..01502fa1b2 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -75,11 +75,13 @@ bool float_output_format(DXGI_FORMAT format) std::unordered_map& compute_translations() { static std::unordered_map m; return m; } LONG compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled; -bool has_32_lane_waves() +// Whether the adapter runs 32-lane waves: 1 yes, 0 no, -1 the capability query failed. +int adapter_32_lane_waves() { D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; - return SUCCEEDED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) && - waves.WaveOps && waves.WaveLaneCountMin <= 32 && waves.WaveLaneCountMax >= 32; + if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves)))) + return -1; + return waves.WaveOps && waves.WaveLaneCountMin <= 32 && waves.WaveLaneCountMax >= 32; } // The root signature and pipeline of a translation whose entry values and views are filled in. Returns why it is @@ -194,9 +196,13 @@ const char* load_compute_translation(ComputeTranslation& tr) x2w_startup::ComPtr code; if (!cache_path(path, L"", tr.key, L".cs.cso") || FAILED(D3DReadFileToBlob(path, &code))) return "no compiled program"; if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) { - // The manifest carries no wave size. Check adapter capabilities only after PSO creation fails. - if (!std::strcmp(failure, "pipeline creation failed") && !has_32_lane_waves()) - return "pipeline creation failed: the adapter has no 32-lane waves"; + // The manifest carries no wave size, so the failure stays the reason and the adapter's 32-lane wave + // capability is only reported next to it, as observed. It does not say the shader needed that wave size. + if (!std::strcmp(failure, "pipeline creation failed")) { + const int waves = adapter_32_lane_waves(); + if (waves < 0) return "pipeline creation failed (adapter wave capability query failed)"; + if (!waves) return "pipeline creation failed (adapter has no 32-lane waves)"; + } return failure; } log("x2w-draw compute pipeline %016llx translated: %zu entry values, %zu inputs, %zu outputs", tr.key, tr.uds.size(), @@ -238,7 +244,7 @@ bool translate_compute_natively(ComputeTranslation& tr) if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) throw std::runtime_error("a sampler, or more entry values, inputs or outputs than the dispatch path binds"); // A direct module declares wave size 32 (src/dxil_module.h): without it the pipeline cannot be created. - if (!has_32_lane_waves()) + if (adapter_32_lane_waves() != 1) throw std::runtime_error("the adapter has no 32-lane waves"); // Never released: a static destructor would release DXC after its module may have detached. static x2w::ShaderDxilCompiler* const compiler = diff --git a/tests/startup_compute_dispatch_texture_check.py b/tests/startup_compute_dispatch_texture_check.py index cfe4fbad1b..c98c4ad4fb 100644 --- a/tests/startup_compute_dispatch_texture_check.py +++ b/tests/startup_compute_dispatch_texture_check.py @@ -157,7 +157,9 @@ def store(directory, consumer, dxc, env): } STORE_VALUES = (0x3f400000, 0x3e800000, 0x40810000, 0xbf810001) STORE_RSRC2 = (10 << 1) | C.TGID_X | C.TGID_Y | C.tidig(2) -NO_WAVES = 'pipeline creation failed: the adapter has no 32-lane waves' +# The runtime reports the adapter capability next to the PSO failure; only this test knows its native +# modules declare WaveSize(32), so only here does that observation explain the failure. +NO_WAVES = 'pipeline creation failed (adapter has no 32-lane waves)' def store_group(form): From 917c124dfa3ee0c6ce735286ffc1617dec851b01 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 04:25:15 +0100 Subject: [PATCH 4/5] runtime: bind table buffers, 2D texture inputs and texture outputs on the in-process compute route translate_compute_natively (X2W_NATIVE_SHADERS) bound only raw_vector_srv and raw_buffer_uav. It now also fills the ComputeTranslation slots the manifest reader fills for buffer_srv (srv buf table), texture_srv with a 2D image (srv tex2d table) and texture_uav/half4_texture_uav with a 1D, 2D, 2D array or 3D image (uav tex1d/tex2d/tex2da/tex3d float table channels 4), with the same kind and image-dimension rules as format_compute_runtime_manifest. Samplers and other kinds stay refused. The native check gains a case where a scalar buffer read and a 2D image load feed a 3D image store, compared with a CPU reference; the same program with a sample instead of the load must be refused with the volume untouched. AI-assisted. --- docs/startup-runtime.md | 10 +-- src/startup_stubs/d3d12_compute_dispatch.inl | 29 +++++-- .../startup_compute_dispatch_native_check.py | 81 ++++++++++++++++++- tests/startup_stream_consumer.cpp | 33 +++++++- 4 files changed, 137 insertions(+), 16 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index ba42d07a4f..d1e4631dc6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -908,11 +908,11 @@ pipelines, and the cache can start empty: the request files the stand-in wrote a against their key, translated and compiled to DXIL in the process. The compiler's own cache goes to `\native`. Nothing is published as `.txt`. -The existing dispatch path records the result, and a program is accepted only with the bindings a -fixture has run through it: root constants, raw table buffers loaded per lane (`buffer_load_dword`) -and raw table buffers stored to, with their descriptors in 32-byte table records. Anything else (a -scalar buffer load, a texture, a sampler, a typed or indexed view, an instruction the compiler does -not lower) is refused. The first 16 refusals of a process are logged as +The existing dispatch path binds root constants and views in 32-byte table records. Buffer views +include scalar buffer SRVs (`buffer_srv`), per-lane raw buffer SRVs (`raw_vector_srv`), and raw buffer +UAVs. Texture views include 2D SRVs and four-channel float 1D, 2D, 2D array, and 3D UAVs +(`texture_uav` and `half4_texture_uav`). Samplers, typed or indexed buffer views, and instructions +outside the compiler's supported set are refused. The first 16 refusals of a process are logged as `compute pipeline not translated natively: `. A refused key is left to the published translations, so `-Translate` can run beside it for those pipelines. A direct module declares wave size 32, so an adapter without 32-lane waves refuses every program by that name. The in-process diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 01502fa1b2..ae6f2568ca 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -212,8 +212,7 @@ const char* load_compute_translation(ComputeTranslation& tr) // X2W_NATIVE_SHADERS=: the first Dispatch of a slot 67 request translates // it in this process with the C++ compiler (src/gfx1013_compute_native.cpp), before a published .txt is read -// and with no offline translator running. The dispatch path below binds the result, so a program is accepted only -// with root constants, raw table buffers it loads per lane (buffer_load_dword) and raw table buffers it stores to. +// and with no offline translator running. The dispatch path below binds root constants and supported table views. // A refusal is logged and leaves the key to the published translations. draw_lock held. Returns whether tr is ready. bool translate_compute_natively(ComputeTranslation& tr) { @@ -232,14 +231,32 @@ bool translate_compute_natively(ComputeTranslation& tr) std::sort(program.bindings.begin(), program.bindings.end(), [](const auto& a, const auto& b) { return a.shader_register < b.shader_register; }); for (const auto& view : program.bindings) { - // The two kinds a fixture has run through this path: a raw buffer read per lane, and one written. - const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav; + using Kind = x2w::ComputeViewKind; + // Match the float texture and buffer slots in format_compute_runtime_manifest. + const bool texture_output = view.kind == Kind::texture_uav || view.kind == Kind::half4_texture_uav; + const bool output = texture_output || view.kind == Kind::raw_buffer_uav; + const bool texture_input = view.kind == Kind::texture_srv && view.image_dimension == 1; + auto dimension = D3D12_UAV_DIMENSION_UNKNOWN; + if (texture_output) { + switch (view.image_dimension) { + case 0: dimension = D3D12_UAV_DIMENSION_TEXTURE1D; break; + case 1: dimension = D3D12_UAV_DIMENSION_TEXTURE2D; break; + case 2: dimension = D3D12_UAV_DIMENSION_TEXTURE3D; break; + case 5: dimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; break; + } + } auto& slots = output ? tr.uavs : tr.srvs; - if ((!output && view.kind != x2w::ComputeViewKind::raw_vector_srv) || view.array_count != 1 || + const bool supported = view.kind == Kind::raw_buffer_uav || view.kind == Kind::raw_vector_srv || + view.kind == Kind::buffer_srv || texture_input || + dimension != D3D12_UAV_DIMENSION_UNKNOWN; + if (!supported || view.array_count != 1 || view.root_parameter >= 16 || view.shader_register != slots.size()) throw std::runtime_error("view kind " + std::to_string(static_cast(view.kind)) + " is not bound for a natively translated program"); - slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset)}); + slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset), + texture_input || texture_output}); + if (texture_output) + slots.back().uav_dimension = dimension; } if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) throw std::runtime_error("a sampler, or more entry values, inputs or outputs than the dispatch path binds"); diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 2a0809e72a..9fe9339c3e 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -18,26 +18,31 @@ dispatches case A through the published translation. All 320 words match. 4. Order: the first program runs again, now with a published translation in the cache. The native translation is still the one used, and all 320 words match. +5. Table views: a scalar buffer read and a 2D image load feed a 3D image store. Replacing the load with a sample + adds a sampler and must leave the volume untouched. -A direct compute module declares wave size 32. On an adapter without 32-lane waves, step 1 instead checks that the -native translation is refused by that name with the output untouched, steps 2 and 3 run as written, step 4 runs the -first program through its published translation, and the check exits 77. Exit 77 also when the adapter is not -available. +A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1 and 5 check that the +native translation is refused by that name with the output untouched. The sampler control and steps 2 and 3 run as +written, step 4 uses the published translation, and the check exits 77. Exit 77 also when the adapter is unavailable. """ import os from pathlib import Path +import struct import subprocess import sys import tempfile import startup_gfx2hlsl_compute_check as C +import startup_compute_dispatch_texture_check as T from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_translate_check import state_a from startup_stream_check import gfx2hlsl as G LOAD_X8 = bytes.fromhex('05030cf4' '000000fa') LOADS_X4 = bytes.fromhex('050308f4' '000000fa' '050408f4' '200000fa') RECORD_LOADS = ['s_load_dwordx4 s[12:15], s[10:11], 0x0', 's_load_dwordx4 s[16:19], s[10:11], 0x20'] NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' +SAMPLER_REFUSAL = 'not translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path binds' def mismatch(got, expected, result): @@ -46,6 +51,73 @@ def mismatch(got, expected, result): wrong[0], got[wrong[0]], expected[wrong[0]], len(wrong), result.stderr[-3000:]) +def table_program(sample): + # Keep the volume fixture's table pointer, UAV descriptor, coordinates, and final store. + wait = bytes.fromhex('7fc08cbf') + prologue, _, tail = T.store_program('volume').partition(wait) + loads = bytes.fromhex( + '060808f4000000fa' # s_load_dwordx4 s[32:35], s[12:13], 0x0 + '06060cf4200000fa' # s_load_dwordx8 s[24:31], s[12:13], 0x20 + ) + values = bytes.fromhex( + '100920f4000000fa' # s_buffer_load_dword s36, s[32:35], 0x0 + ) + wait + bytes.fromhex( + '2402107e' # v_mov_b32 v8, s36 + '80020c7e' # v_mov_b32 v6, 0 + '80020e7e' # v_mov_b32 v7, 0 + ) + if sample: + image = bytes.fromhex( + '8004a8be8004aabe' # s_mov_b64 s[40:41], 0; s_mov_b64 s[42:43], 0 + '08019cf006094601' # image_sample_lz v9, v[6:7], s[24:31], s[40:43], dmask:1, 2D + ) + else: + image = bytes.fromhex('080100f006090600') # image_load v9, v[6:7], s[24:31], dmask:1, 2D + # The new reads replace the first two literal moves (two dwords each). + return prologue + loads + wait + values + image + bytes.fromhex('700f8cbf') + tail[16:] + + +def table_views(directory, consumer, dxc_dir, adapter, no_waves): + cache, env = prepare_case(directory, adapter) + env['X2W_NATIVE_SHADERS'] = dxc_dir + root = Path(env['X2W_TEST_COMPUTE_ROOT']) + # Two SRVs in records 0 and 1, followed by one UAV in record 2. + blob = bytearray(C.root_blob(3, table_range=True)[:-24]) + blob.extend(struct.pack('<12I', 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2)) + payload = 44 # DXBC header, part offset, and RTS0 part header + struct.pack_into('(invoke(device, 36, 0, 0, word(&__uuidof(ID3D12Fence)), word(&fence))))) return 72; const StreamWord cpu = invoke(heap, 9), gpu = invoke(heap, 10); if (!cpu || !gpu) return 73; + void* input_texture = nullptr; + if (native_inputs) { + // A hardware buffer descriptor in record 0 and a 2D SRV token in record 1. + auto* input = static_cast(VirtualAlloc(nullptr, 0x10000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + if (!input) return 70; + input[0] = 0x3f200000u; // 0.625f, not a value the store fixture writes + void* placed = nullptr; + const D3D12_RESOURCE_DESC input_buffer{D3D12_RESOURCE_DIMENSION_BUFFER, 0, sizeof(UINT), 1, 1, 1, + DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR}; + if (FAILED(static_cast(invoke(device, 133, word(input), word(&input_buffer), D3D12_RESOURCE_STATE_COMMON, + 0, word(&__uuidof(ID3D12Resource)), word(&placed))))) return 71; + const auto address = reinterpret_cast(input); + const UINT descriptor[4] = {static_cast(address), static_cast(address >> 32) | (4u << 16), 1, 0}; + std::memcpy(reinterpret_cast(cpu), descriptor, sizeof(descriptor)); + const D3D12_RESOURCE_DESC input_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 1, 1, 1, 1, format, {1, 0}}; + input_texture = make(D3D12_HEAP_TYPE_DEFAULT, input_desc, D3D12_RESOURCE_STATE_COMMON); + if (!input_texture) return 71; + D3D12_SHADER_RESOURCE_VIEW_DESC input_view{format, D3D12_SRV_DIMENSION_TEXTURE2D, + D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + input_view.Texture2D.MipLevels = 1; + invoke(device, 18, word(input_texture), word(&input_view), cpu + 32); + } D3D12_UNORDERED_ACCESS_VIEW_DESC view{format, D3D12_UAV_DIMENSION_TEXTURE2D}; if (volume) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; @@ -499,6 +522,14 @@ static int texture_slot67(void* device, const std::string& mode) const UINT constants[3] = {1, 2, 3}; if (FAILED(static_cast(invoke(list, 139, word(allocator))))) return 74; invoke(list, 32, 1, word(&heap)); + if (input_texture) { + D3D12_TEXTURE_COPY_LOCATION input_image{static_cast(input_texture), + D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + D3D12_TEXTURE_COPY_LOCATION input_source{static_cast(upload), + D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + input_source.PlacedFootprint = {0, {format, 1, 1, 1, pitch}}; + invoke(list, 16, word(&input_image), 0, 0, 0, word(&input_source), 0); + } for (UINT subresource = 0; subresource < subresources; ++subresource) { image.SubresourceIndex = subresource + mip; source.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; From a5d118336bc18f44eb5d2bc8ae8f253bebd5bd91 Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:26:56 +0100 Subject: [PATCH 5/5] tests: use the adapter's descriptor increment in the native input fixture; add zero-W, 1D, 2D-array and half4 native cases The texture-volume-native-inputs mode created its SRV and UAV at fixed 32-byte offsets, which is mid-descriptor on adapters with a wider CBV/SRV/UAV increment (64 bytes on WARP). It now queries the increment (device slot 15) for the creation handles. On a wider heap the 32-byte tokens are copied into a packed table at the guest byte offsets the program reads, and that table's base is bound. The native check gains a Texture3D.WSize = 0 control (translated natively, Dispatch refused, output untouched) and in-process readbacks for a 1D float output, a 2D-array output on a non-zero layer and a half4 (D16) output, each against a CPU reference. AI-assisted. --- docs/startup-runtime.md | 9 +++ .../startup_compute_dispatch_native_check.py | 76 +++++++++++++++++-- tests/startup_stream_consumer.cpp | 39 +++++++--- 3 files changed, 109 insertions(+), 15 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index d1e4631dc6..a4ea643454 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -922,6 +922,15 @@ pipelines still need a published translation. Check with `ctest --preset dev -R '^startup_compute_dispatch_native_(warp|hardware)$' -V` ([`tests/startup_compute_dispatch_native_check.py`](../tests/startup_compute_dispatch_native_check.py); [route, controls and results](experiments/startup-compute-native-dispatch.md)). +The #2958/#2993 fixture reads back a 3D float store fed by a scalar buffer SRV and a 2D texture SRV. +The consumer creates the views with the adapter's descriptor increment and copies their tokens +into a packed guest table when the increment exceeds 32 bytes. A zero-size W range must translate +natively, be refused at Dispatch, and leave all 6,144 volume words untouched. +Targeted in-process readbacks also check a mip-one 1D float store, a 2D-array float store into +relative slice 1 (physical slice 2), and a packed D16 store into an RGBA16_FLOAT texture with +round-to-nearest-even input conversion. Each case checks every output value, including sentinels +outside the store region. On adapters without 32-lane waves the cases check the named refusal +and untouched output before the test returns 77. ### Compute pipeline requests diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 9fe9339c3e..69c27f7fa1 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -19,9 +19,10 @@ 4. Order: the first program runs again, now with a published translation in the cache. The native translation is still the one used, and all 320 words match. 5. Table views: a scalar buffer read and a 2D image load feed a 3D image store. Replacing the load with a sample - adds a sampler and must leave the volume untouched. + adds a sampler and must leave the volume untouched. A zero-size UAV W range also leaves it untouched. +6. Texture outputs: 1D float, 2D-array float, and 2D packed D16 stores match CPU references. -A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1 and 5 check that the +A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1, 5 and 6 check that the native translation is refused by that name with the output untouched. The sampler control and steps 2 and 3 run as written, step 4 uses the published translation, and the check exits 77. Exit 77 also when the adapter is unavailable. """ @@ -34,6 +35,8 @@ import startup_gfx2hlsl_compute_check as C import startup_compute_dispatch_texture_check as T +import startup_compute_image_store_check as A +import startup_compute_image_store_d16_check as D from startup_compute_dispatch_check import dispatch, lines, prepare_case from startup_compute_translate_check import state_a from startup_stream_check import gfx2hlsl as G @@ -43,6 +46,8 @@ RECORD_LOADS = ['s_load_dwordx4 s[12:15], s[10:11], 0x0', 's_load_dwordx4 s[16:19], s[10:11], 0x20'] NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' SAMPLER_REFUSAL = 'not translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path binds' +TEXTURE_DISPATCH = 'Dispatch(2, 1, 1)' +ZERO_W_REFUSAL = 'an output 3D texture W range is outside the mip' def mismatch(got, expected, result): @@ -99,9 +104,12 @@ def table_views(directory, consumer, dxc_dir, adapter, no_waves): start = 2 * plane + y * 32 * 4 # view FirstWSlice 1, shader Z 1 expected[start:start + 32] = (0x3f200000, initial[0], *T.STORE_VALUES[2:]) * 8 - for sample in (False, True): + for mode, sample, zero_w in ( + ('texture-volume-native-inputs', False, False), + ('texture-volume-native-inputs', True, False), + ('texture-volume-native-zero-w', False, True)): (directory / 'program').write_bytes(table_program(sample)) - got, result = T.run(directory, consumer, env, 'texture-volume-native-inputs', '<%dI' % len(initial)) + got, result = T.run(directory, consumer, env, mode, '<%dI' % len(initial)) if sample or no_waves: reason = SAMPLER_REFUSAL if sample else NO_WAVES assert len(lines(result, reason)) == 1, result.stderr[-3000:] @@ -109,13 +117,70 @@ def table_views(directory, consumer, dxc_dir, adapter, no_waves): assert got == initial, 'a refused Dispatch wrote the volume' else: assert len(lines(result, 'translated natively: 3 entry values, 2 inputs, 1 outputs')) == 1, result.stderr[-3000:] + if zero_w: + refusal = lines(result, f'{TEXTURE_DISPATCH} refused:') + assert len(refusal) == 1 and refusal[0].endswith(ZERO_W_REFUSAL), result.stderr[-3000:] + assert not lines(result, f'{TEXTURE_DISPATCH} translated'), result.stderr[-3000:] + assert got == initial, 'the zero WSize Dispatch changed the volume' + continue assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] assert got == expected, 'native table views changed %d unexpected words\n%s' % ( sum(a != b for a, b in zip(got, expected)), result.stderr[-3000:]) T.clean(result) assert all(p.name.startswith('req_') or p.name == 'native' for p in cache.iterdir()) if not no_waves: - print('native table views: all volume words match the CPU reference, and a sampler is refused') + print('native table views: volume words match, and the sampler and zero WSize controls leave them untouched') + + +def half4_program(f32_words): + moves = b''.join(struct.pack('<2I', 0x7e0002ff | reg << 17, bits) + for reg, bits in enumerate(f32_words, 10)) + # v_cvt_f16_f32 vN, vN, followed by v_pack_b32_f16 v[14:15] from pairs in v[10:13]. + converts = b''.join(struct.pack('(memory)[i] = static_cast(0x5000 + i); } invoke(upload, 9, 0, 0); + constexpr StreamWord record_bytes = 32; + const StreamWord increment = invoke(device, 15, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + // On wider heaps, reserve a separate region for the shader's packed guest table. + const UINT table_slot = increment == record_bytes ? 0 : 4; const struct { D3D12_DESCRIPTOR_HEAP_DESC desc; UINT64 backing, bytes; - } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 4, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; + } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, table_slot + 4, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; void *heap = nullptr, *queue = nullptr, *allocator = nullptr, *list = nullptr, *fence = nullptr; const D3D12_COMMAND_QUEUE_DESC queue_desc{}; const UINT list_desc[]{D3D12_COMMAND_LIST_TYPE_DIRECT, 2, 1, 0}; @@ -457,7 +462,9 @@ static int texture_slot67(void* device, const std::string& mode) FAILED(static_cast(invoke(device, 73, word(list_desc), word(allocator), 0, word(&__uuidof(ID3D12GraphicsCommandList)), word(&list)))) || FAILED(static_cast(invoke(device, 36, 0, 0, word(&__uuidof(ID3D12Fence)), word(&fence))))) return 72; const StreamWord cpu = invoke(heap, 9), gpu = invoke(heap, 10); - if (!cpu || !gpu) return 73; + if (!cpu || !gpu || increment < record_bytes) return 73; + const StreamWord table_cpu = cpu + table_slot * increment; + const StreamWord uav_handle = cpu + 2 * increment; void* input_texture = nullptr; if (native_inputs) { // A hardware buffer descriptor in record 0 and a 2D SRV token in record 1. @@ -471,20 +478,21 @@ static int texture_slot67(void* device, const std::string& mode) 0, word(&__uuidof(ID3D12Resource)), word(&placed))))) return 71; const auto address = reinterpret_cast(input); const UINT descriptor[4] = {static_cast(address), static_cast(address >> 32) | (4u << 16), 1, 0}; - std::memcpy(reinterpret_cast(cpu), descriptor, sizeof(descriptor)); + std::memcpy(reinterpret_cast(table_cpu), descriptor, sizeof(descriptor)); const D3D12_RESOURCE_DESC input_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 1, 1, 1, 1, format, {1, 0}}; input_texture = make(D3D12_HEAP_TYPE_DEFAULT, input_desc, D3D12_RESOURCE_STATE_COMMON); if (!input_texture) return 71; D3D12_SHADER_RESOURCE_VIEW_DESC input_view{format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; input_view.Texture2D.MipLevels = 1; - invoke(device, 18, word(input_texture), word(&input_view), cpu + 32); + invoke(device, 18, word(input_texture), word(&input_view), cpu + 1 * increment); } D3D12_UNORDERED_ACCESS_VIEW_DESC view{format, D3D12_UAV_DIMENSION_TEXTURE2D}; if (volume) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; // At mip 1 the depth is six. The bad count fits only if the binder uses the base mip's depth. view.Texture3D = {mip, 1, mode == "texture-volume-bad-w" ? layers : ~0u}; + if (zero_w) view.Texture3D.WSize = 0; } else if (line) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D; view.Texture1D.MipSlice = mode == "texture-line-bad-mip" ? mip + 1 : mip; // bad-mip: one past the last mip @@ -492,28 +500,39 @@ static int texture_slot67(void* device, const std::string& mode) view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; view.Texture2DArray = {0, 1, 4, 0}; // four selected slices, with untouched neighbors on both sides } - if (mode != "texture-store-copied") invoke(device, 19, word(texture), 0, word(&view), cpu + 64); + if (mode != "texture-store-copied") invoke(device, 19, word(texture), 0, word(&view), uav_handle); if (mode == "texture-store-copied") { // The view is created at another handle and its token copied into this slot by memcpy, as a title does; a // refused creation at this slot then keeps that copied token. invoke(device, 19, word(texture), 0, word(&view), cpu); - std::memcpy(reinterpret_cast(cpu + 64), reinterpret_cast(cpu), 32); + std::memcpy(reinterpret_cast(uav_handle), reinterpret_cast(cpu), record_bytes); D3D12_RESOURCE_DESC plain = texture_desc; plain.Flags = D3D12_RESOURCE_FLAG_NONE; void* const other = make(D3D12_HEAP_TYPE_DEFAULT, plain, D3D12_RESOURCE_STATE_COMMON); if (!other) return 79; - invoke(device, 19, word(other), 0, word(&view), cpu + 64); + invoke(device, 19, word(other), 0, word(&view), uav_handle); } else if (mode == "texture-store-occupied") { // A second creation at the same handle, over a texture without unordered access, is refused and leaves the first view. D3D12_RESOURCE_DESC plain = texture_desc; plain.Flags = D3D12_RESOURCE_FLAG_NONE; void* const other = make(D3D12_HEAP_TYPE_DEFAULT, plain, D3D12_RESOURCE_STATE_COMMON); if (!other) return 79; - invoke(device, 19, word(other), 0, word(&view), cpu + 64); + invoke(device, 19, word(other), 0, word(&view), uav_handle); } D3D12_SHADER_RESOURCE_VIEW_DESC read{format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; read.Texture2D.MipLevels = 1; if (mode == "texture-store-self") invoke(device, 18, word(texture), word(&read), cpu); + if (table_slot) { + // Creation writes 32-byte tokens at the stride-aligned CPU handles. The translated + // Dispatch reads them at literal guest byte offsets 0, 32 and 64 from the bound table. + const auto copy_token = [&](UINT slot) { + std::memcpy(reinterpret_cast(table_cpu + slot * record_bytes), + reinterpret_cast(cpu + slot * increment), record_bytes); + }; + if (native_inputs) copy_token(1); + if (mode == "texture-store-self") copy_token(0); + copy_token(2); + } D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; D3D12_TEXTURE_COPY_LOCATION source{static_cast(upload), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; source.PlacedFootprint = {0, {format, width, height, volume ? layers : 1, pitch}}; @@ -538,7 +557,7 @@ static int texture_slot67(void* device, const std::string& mode) invoke(list, 25, word(slot67_pipeline)); invoke(list, 33, word(slot67_root)); invoke(list, 39, 0, 3, word(constants), 0); - invoke(list, 35, 1, gpu); + invoke(list, 35, 1, gpu + table_slot * increment); if (mode != "texture-store-none") invoke(list, 14, 2, 1, 1); for (UINT subresource = 0; subresource < subresources; ++subresource) { image.SubresourceIndex = subresource + mip;