From b97a694d2f9517f5aa5f51c975901706479785be Mon Sep 17 00:00:00 2001 From: Kawiu <110430638+Kawiu@users.noreply.github.com> Date: Sun, 29 Nov 2026 19:23:57 +0100 Subject: [PATCH 1/4] runtime: forward CopyBufferRegion from a title-backed buffer through a snapshot Opt-in X2W_D3D12_TITLE_COPY_SNAPSHOT=1. A copy of up to 64 KiB whose source has no desktop copy is read from title memory at record time instead of being skipped as title_backed_source. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- CMakeLists.txt | 3 +++ docs/startup-runtime.md | 5 +++- src/startup_stubs/list_copy.inl | 25 ++++++++++++++++---- tests/startup_list_copy.cpp | 41 ++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b2889d414..86096d9d71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1797,6 +1797,9 @@ foreach(backend IN ITEMS warp hardware) add_test(NAME startup_list_copy_${backend} COMMAND startup_list_copy ${backend}) set_tests_properties(startup_list_copy_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1") + add_test(NAME startup_list_copy_title_snapshot_${backend} COMMAND startup_list_copy ${backend}) + set_tests_properties(startup_list_copy_title_snapshot_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=1;X2W_D3D12_TITLE_COPY_SNAPSHOT=1") endforeach() # Validation of the whole-resource copies (src/startup_stubs/list_copy.h); the mutated runs are negative controls. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 040ae3e4b2..75a6ccf312 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -741,7 +741,9 @@ desktop would reject is counted, logged (first six) and not forwarded, with the `range_overflow`, `heap_direction` (an upload buffer as a destination, a readback buffer as a source), `initial_state` (a placed buffer that does not start in COMMON) or `title_backed_source` (a title-backed default-heap buffer or an upload buffer, which have no desktop copy the list can refresh without rewriting bytes an earlier submission may -still read). A source the title maps at its own memory must be current: a texture takes the draw path's upload and is refused +still read). With `X2W_D3D12_TITLE_COPY_SNAPSHOT=1`, `CopyBufferRegion` of up to 64 KiB from such a buffer reads its +title memory at record time into the upload ring instead; CPU writes after recording and GPU writes into the source are not +seen. A source the title maps at its own memory must be current: a texture takes the draw path's upload and is refused when that upload cannot stage it (unreadable or unsupported memory), and an aliased placed buffer is already current. A copy or resolve destination with title memory is marked GPU-written when its list is submitted (on its own list at once), so a later draw does not upload the stale title memory over the result; a list discarded by Reset or a failed Close marks nothing. CopyResource accepts formats of one DXGI family (colour, depth, 8/16/32-bit and block-compressed). A resolve format is exact against a fully typed endpoint and only family-compatible with a @@ -1767,6 +1769,7 @@ ctest --preset dev --no-tests=error -R '^startup_hook_(window|overlap)$' -V | `X2W_D3D12_TABLE_ALIAS=1` | opt-in, render mode: a translated draw's table buffer view whose whole range lies in a slot 133 placed buffer that aliases title memory binds that alias instead of a per-draw frame copy, so the GPU reads the bytes at execution and the view is not cut at 16 MiB (`startup_table_alias_*`). Unset, every table buffer view is copied as before. See [Copies of title memory within a frame](#copies-of-title-memory-within-a-frame) | | `X2W_DEPTH_STATE=1` | translated draws of slot 57 pipelines take their depth-stencil state and stencil reference from state block A instead of the desktop default (depth and stencil off); a refused block keeps the default. Off by default, then nothing changes: see [Shortcuts that are known to be wrong](#shortcuts-that-are-known-to-be-wrong) | | `X2W_PRESENT_SIGNATURE_EVERY=` | in render mode, samples a coarse signature of the presented picture every `n` presents from the start, without a script request (`0` off). Unset, sampling starts, every 4 presents, only once a script with a `wait` asks for it: see [Waiting for the presented picture](#waiting-for-the-presented-picture) | +| `X2W_D3D12_TITLE_COPY_SNAPSHOT=1` | opt-in, in render mode: `CopyBufferRegion` of up to 64 KiB from a title-backed buffer that has no desktop copy (otherwise skipped as `title_backed_source`) reads that memory at record time; later CPU writes and GPU writes into the source are not seen | | `X2W_D3D12_DUMP_SURFACE=` | writes the last presented surface | | `X2W_PRESENT_COMPOSITE=1` | experimental, in render mode: the output window composites every presented plane, bottom to top, instead of showing plane 0 alone, and the highest plane above plane 0 is sampled as `x2w-render raw plane (not composited)`. Off by default; the baseline capture and `x2w-render presented` read plane 0 either way. See [Presented planes](#presented-planes) | | `X2W_PRESENT_PLANE=` | diagnostic, in render mode: the output window shows plane `n` of each present alone (plane 0 when `n` is past the count), with or without `X2W_PRESENT_COMPOSITE`. See [Presented planes](#presented-planes) | diff --git a/src/startup_stubs/list_copy.inl b/src/startup_stubs/list_copy.inl index a755eec820..e98a289b44 100644 --- a/src/startup_stubs/list_copy.inl +++ b/src/startup_stubs/list_copy.inl @@ -211,6 +211,20 @@ bool copy_source_authoritative(Wrapper* self, const CopyEndpoint& from, u64 offs return placed.alias || list_copied_gpu_range(self, from.resource, offset, bytes); } +// X2W_D3D12_TITLE_COPY_SNAPSHOT=1: a buffer source with no desktop copy the list can refresh is read from its +// title memory at record time into the upload ring, for copies of up to 64 KiB (constant updates). Bytes a GPU +// wrote into the source are not in title memory and are not seen. +bool title_copy_snapshot(Wrapper* self, const CopyEndpoint& from, u64 offset, u64 bytes, ID3D12Resource** ring, + u64* ring_offset) +{ + static const bool enabled = x2w_local::env_on("X2W_D3D12_TITLE_COPY_SNAPSHOT"); + if (!enabled || !from.wrapper || !from.wrapper->own().title_memory || bytes > (u64{64} << 10)) return false; + if (from.resource->GetDesc().Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const u64 address = reinterpret_cast(from.wrapper->own().title_memory) + offset; + return readable_window(address, static_cast(bytes)) >= bytes && + ring_copy(self, address, static_cast(bytes), ring_offset, ring, true) && *ring; +} + // List slot 15, CopyBufferRegion(destination, destination offset, source, source offset, bytes). void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 destination_offset, u64 source, u64 source_offset, u64 bytes) @@ -229,13 +243,16 @@ void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 desti if (refusal == x2w_startup::CopyRefusal::none) refusal = check_endpoint_roles(to, from); const bool authoritative = refusal == x2w_startup::CopyRefusal::none && indirect_copy_ranges() && copy_source_authoritative(self, from, source_offset, bytes); - if (refusal == x2w_startup::CopyRefusal::none && !authoritative && !sync_title_source(self, from)) + ID3D12Resource* snapshot = nullptr; + u64 snapshot_offset = 0; + if (refusal == x2w_startup::CopyRefusal::none && !authoritative && !sync_title_source(self, from) && + !title_copy_snapshot(self, from, source_offset, bytes, &snapshot, &snapshot_offset)) refusal = x2w_startup::CopyRefusal::title_backed_source; if (refusal != x2w_startup::CopyRefusal::none) return refuse_copy("CopyBufferRegion", refusal); - require_copy_state(self, from.resource, D3D12_RESOURCE_STATE_COPY_SOURCE); + if (!snapshot) require_copy_state(self, from.resource, D3D12_RESOURCE_STATE_COPY_SOURCE); require_copy_state(self, to.resource, D3D12_RESOURCE_STATE_COPY_DEST); - static_cast(self->own().real) - ->CopyBufferRegion(to.resource, destination_offset, from.resource, source_offset, bytes); + static_cast(self->own().real)->CopyBufferRegion( + to.resource, destination_offset, snapshot ? snapshot : from.resource, snapshot ? snapshot_offset : source_offset, bytes); trace_compute_output_use(self, OutputUse::copy_read_recorded, "copy-read-recorded", from.wrapper, 0, source_offset, bytes); trace_compute_output_use(self, OutputUse::copy_write_recorded, "copy-write-recorded", to.wrapper, 0, destination_offset, bytes); if (mesh_xmem_tracking()) { diff --git a/tests/startup_list_copy.cpp b/tests/startup_list_copy.cpp index bf5d0676a1..7d54af4898 100644 --- a/tests/startup_list_copy.cpp +++ b/tests/startup_list_copy.cpp @@ -16,7 +16,9 @@ // buffer and a copy out of a readback buffer // 7. a title-backed texture copied to a texture: the destination holds its texels; one whose memory cannot // be read is refused and the destination stays empty -// 8. after Close, the same calls change no counter +// 7b. CopyBufferRegion from a title-backed buffer placed off a 64 KiB boundary (no desktop alias): refused by +// default; with X2W_D3D12_TITLE_COPY_SNAPSHOT=1 the destination holds the title bytes of record time. A source +// whose pages are gone, or a range over 64 KiB, is refused either way// 8. after Close, the same calls change no counter // 9. a copy into a title-backed texture, discarded by Close and Reset unsubmitted: a later copy out of that // texture still reads its own memory // @@ -338,8 +340,45 @@ int main(int argc, char** argv) invoke(list, 17, arg(dest_gone.Get()), arg(title_gone)); if (!step("8b CopyResource from an unreadable title-backed texture", {0, 0, 0, 1}, seen)) return 34; + // A title buffer that does not alias title memory has no desktop copy of its bytes. + char snapshot_value[4]{}; + const bool snapshot_on = GetEnvironmentVariableA("X2W_D3D12_TITLE_COPY_SNAPSHOT", snapshot_value, sizeof(snapshot_value)) && + snapshot_value[0] == '1'; + constexpr std::size_t block_bytes = 0x40000; + auto* const buffer_memory = static_cast(VirtualAlloc(nullptr, block_bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + auto* const lost_memory = static_cast(VirtualAlloc(nullptr, title_bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + if (!buffer_memory || !lost_memory) return 50; + std::memcpy(buffer_memory + 256, pattern.data(), pattern.size()); + const D3D12_RESOURCE_DESC large_desc = buffer(0x20000), small_desc = buffer(256); + void *title_buffer = nullptr, *title_lost = nullptr; + ComPtr from_title, from_lost, large_out; + heap.Type = D3D12_HEAP_TYPE_DEFAULT; + if (!create(small_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, from_title) || + !create(small_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, from_lost) || + !create(large_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, large_out) || + !ok(invoke(device, 133, arg(buffer_memory + 256), arg(&large_desc), D3D12_RESOURCE_STATE_COMMON, 0, + arg(&__uuidof(ID3D12Resource)), arg(&title_buffer))) || !title_buffer || + !ok(invoke(device, 133, arg(lost_memory + 256), arg(&small_desc), D3D12_RESOURCE_STATE_COMMON, 0, + arg(&__uuidof(ID3D12Resource)), arg(&title_lost))) || !title_lost) + return 51; + VirtualFree(lost_memory, title_bytes, MEM_DECOMMIT); + const Counts copied_or_refused = snapshot_on ? Counts{1, 0, 0, 0} : Counts{0, 0, 0, 1}; + invoke(list, 15, arg(from_title.Get()), 0, arg(title_buffer), 0, 256); + if (!step("8c CopyBufferRegion from an unaliased title buffer", copied_or_refused, seen)) return 52; + std::memset(buffer_memory + 256, 0xee, 256); // the snapshot holds the bytes of record time + invoke(list, 15, arg(from_lost.Get()), 0, arg(title_lost), 0, 256); + if (!step("8d CopyBufferRegion from an unreadable title buffer", {0, 0, 0, 1}, seen)) return 53; + invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 0, 0x10004); + if (!step("8e CopyBufferRegion over 64 KiB from a title buffer", {0, 0, 0, 1}, seen)) return 54; + invoke(list, 9); if (!probe.submit(list)) return 19; + std::vector title_out; + if (!probe.bytes(from_title.Get(), 256, title_out)) return 55; + const std::vector wanted = snapshot_on ? std::vector(pattern.begin(), pattern.end()) + : std::vector(256, 0); + std::printf("title buffer copy (snapshot %s): %s\n", snapshot_on ? "on" : "off", title_out == wanted ? "exact" : "differs"); + if (title_out != wanted) return 56; invoke(list, 17, arg(copy_b.Get()), arg(empty_d.Get())); invoke(list, 19, arg(resolved_r.Get()), 0, arg(msaa_m.Get()), 0, DXGI_FORMAT_R8G8B8A8_UNORM); invoke(list, 15, arg(buffer_y.Get()), 0, arg(buffer_x.Get()), 0, 16); From 113a764f459ac3a4ecf76b4ec636e210fb54c08f Mon Sep 17 00:00:00 2001 From: Kawiu <110430638+Kawiu@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:02:50 +0100 Subject: [PATCH 2/4] test: pin the 64 KiB cap of the title copy snapshot Fix the line break in the header comment of startup_list_copy. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- tests/startup_list_copy.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/startup_list_copy.cpp b/tests/startup_list_copy.cpp index 7d54af4898..ab2334c627 100644 --- a/tests/startup_list_copy.cpp +++ b/tests/startup_list_copy.cpp @@ -18,7 +18,9 @@ // be read is refused and the destination stays empty // 7b. CopyBufferRegion from a title-backed buffer placed off a 64 KiB boundary (no desktop alias): refused by // default; with X2W_D3D12_TITLE_COPY_SNAPSHOT=1 the destination holds the title bytes of record time. A source -// whose pages are gone, or a range over 64 KiB, is refused either way// 8. after Close, the same calls change no counter +// whose pages are gone, or a range over 64 KiB, is refused either way; with the switch on exactly +// 64 KiB is still copied +// 8. after Close, the same calls change no counter // 9. a copy into a title-backed texture, discarded by Close and Reset unsubmitted: a later copy out of that // texture still reads its own memory // @@ -368,8 +370,10 @@ int main(int argc, char** argv) std::memset(buffer_memory + 256, 0xee, 256); // the snapshot holds the bytes of record time invoke(list, 15, arg(from_lost.Get()), 0, arg(title_lost), 0, 256); if (!step("8d CopyBufferRegion from an unreadable title buffer", {0, 0, 0, 1}, seen)) return 53; + invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 0, 0x10000); + if (!step("8e CopyBufferRegion of 64 KiB from a title buffer", copied_or_refused, seen)) return 57; invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 0, 0x10004); - if (!step("8e CopyBufferRegion over 64 KiB from a title buffer", {0, 0, 0, 1}, seen)) return 54; + if (!step("8f CopyBufferRegion over 64 KiB from a title buffer", {0, 0, 0, 1}, seen)) return 54; invoke(list, 9); if (!probe.submit(list)) return 19; From 577a17fd2d29f99be350202094497e98a97e2407 Mon Sep 17 00:00:00 2001 From: Kawiu <110430638+Kawiu@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:36:21 +0100 Subject: [PATCH 3/4] runtime: preserve title snapshots in mesh handoff Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- CMakePresets.json | 4 ++-- docs/startup-runtime.md | 2 +- src/startup_stubs/list_copy.inl | 12 +++++++++--- tests/startup_list_copy.cpp | 8 ++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index e332a968f3..f418555af5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,7 +26,7 @@ "name": "pr", "configurePreset": "dev", "targets": [ - "d3d12_sdk_check", "era_heap_check", "xmem_shim", "offscreen_check", + "d3d12_sdk_check", "era_heap_check", "xmem_shim", "offscreen_check", "startup_list_copy", "startup_list_copy_check", "cpu_fuzz_lifted", "cpu_fuzz_lifted_o2", "pe_map", "intake_candidate", "archive_gpu_reader", "archive_codec_gpu", "archive_texture_gpu_lifted", "startup_launch_probe", "compile_dxil", "startup_indirect_dispatch", "startup_indirect_draw_indexed", "startup_present_readback_check", @@ -49,7 +49,7 @@ "displayName": "Windows pull request smoke tests", "filter": { "include": { - "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$" + "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$" } } }, diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 42ad0ee6b1..0c43bfaeb6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -796,7 +796,7 @@ desktop would reject is counted, logged (first six) and not forwarded, with the `initial_state` (a placed buffer that does not start in COMMON) or `title_backed_source` (a title-backed default-heap buffer or an upload buffer, which have no desktop copy the list can refresh without rewriting bytes an earlier submission may still read). With `X2W_D3D12_TITLE_COPY_SNAPSHOT=1`, `CopyBufferRegion` of up to 64 KiB from such a buffer reads its -title memory at record time into the upload ring instead; CPU writes after recording and GPU writes into the source are not +title memory at record time into the snapshot pool instead; CPU writes after recording and GPU writes into the source are not seen. A source the title maps at its own memory must be current: a texture takes the draw path's upload and is refused when that upload cannot stage it (unreadable or unsupported memory), and an aliased placed buffer is already current. A copy or resolve destination with title memory is marked GPU-written when its list is submitted (on its own list at once), so a later draw does not upload the stale title memory over the result; a list discarded by Reset or a failed Close marks nothing. CopyResource accepts formats of one DXGI family (colour, depth, 8/16/32-bit diff --git a/src/startup_stubs/list_copy.inl b/src/startup_stubs/list_copy.inl index a883256950..6d3ac77b6e 100644 --- a/src/startup_stubs/list_copy.inl +++ b/src/startup_stubs/list_copy.inl @@ -212,7 +212,7 @@ bool copy_source_authoritative(Wrapper* self, const CopyEndpoint& from, u64 offs } // X2W_D3D12_TITLE_COPY_SNAPSHOT=1: a buffer source with no desktop copy the list can refresh is read from its -// title memory at record time into the upload ring, for copies of up to 64 KiB (constant updates). Bytes a GPU +// title memory at record time into the snapshot pool, for copies of up to 64 KiB (constant updates). Bytes a GPU // wrote into the source are not in title memory and are not seen. bool title_copy_snapshot(Wrapper* self, const CopyEndpoint& from, u64 offset, u64 bytes, ID3D12Resource** ring, u64* ring_offset) @@ -249,6 +249,11 @@ void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 desti !title_copy_snapshot(self, from, source_offset, bytes, &snapshot, &snapshot_offset)) refusal = x2w_startup::CopyRefusal::title_backed_source; if (refusal != x2w_startup::CopyRefusal::none) return refuse_copy("CopyBufferRegion", refusal); + if (snapshot) { + static LONG snapshot_copies = 0; + if (InterlockedIncrement(&snapshot_copies) <= 10) + log("x2w-render CopyBufferRegion used a title snapshot (%llu bytes)", bytes); + } if (!snapshot) require_copy_state(self, from.resource, D3D12_RESOURCE_STATE_COPY_SOURCE); require_copy_state(self, to.resource, D3D12_RESOURCE_STATE_COPY_DEST); static_cast(self->own().real)->CopyBufferRegion( @@ -258,7 +263,7 @@ void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 desti if (mesh_xmem_tracking()) { D3D12_HEAP_TYPE source_heap; const bool upload = fixed_heap(from.resource, source_heap) && source_heap == D3D12_HEAP_TYPE_UPLOAD; - const bool srv_word = mesh_xmem_handoff() && bytes == sizeof(UINT) && upload; + const bool srv_word = mesh_xmem_handoff() && bytes == sizeof(UINT) && (upload || snapshot); auto* list = static_cast(self->own().real); D3D12_HEAP_PROPERTIES source_properties{}; const bool mesh_record = mesh_xmem_indirect() && bytes == sizeof(D3D12_DISPATCH_MESH_ARGUMENTS) && @@ -269,7 +274,8 @@ void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 desti const char* source_kind = upload ? "upload" : mesh_record ? "default-uav" : (from_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) ? "uav-capable-buffer" : "buffer"; note_mesh_xmem_write(self, to.wrapper, destination_offset, bytes, 15, source_kind, - srv_word || mesh_record ? from.resource : nullptr, source_offset); + srv_word || mesh_record ? (snapshot ? snapshot : from.resource) : nullptr, + snapshot ? snapshot_offset : source_offset); } if (to.wrapper) diag_placed_copy(to.resource); if (to.wrapper && indirect_cross_list_copy()) indirect_copy_tracker().record(self, to.resource, destination_offset, bytes); diff --git a/tests/startup_list_copy.cpp b/tests/startup_list_copy.cpp index ab2334c627..99c7f58d38 100644 --- a/tests/startup_list_copy.cpp +++ b/tests/startup_list_copy.cpp @@ -372,6 +372,9 @@ int main(int argc, char** argv) if (!step("8d CopyBufferRegion from an unreadable title buffer", {0, 0, 0, 1}, seen)) return 53; invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 0, 0x10000); if (!step("8e CopyBufferRegion of 64 KiB from a title buffer", copied_or_refused, seen)) return 57; + std::memcpy(buffer_memory + 256 + 12, pattern.data(), 256); + invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 12, 256); + if (!step("8g CopyBufferRegion from a title buffer with a source offset", copied_or_refused, seen)) return 58; invoke(list, 15, arg(large_out.Get()), 0, arg(title_buffer), 0, 0x10004); if (!step("8f CopyBufferRegion over 64 KiB from a title buffer", {0, 0, 0, 1}, seen)) return 54; @@ -383,6 +386,11 @@ int main(int argc, char** argv) : std::vector(256, 0); std::printf("title buffer copy (snapshot %s): %s\n", snapshot_on ? "on" : "off", title_out == wanted ? "exact" : "differs"); if (title_out != wanted) return 56; + std::vector offset_out; + if (!probe.bytes(large_out.Get(), 256, offset_out)) return 59; + const std::vector offset_wanted = snapshot_on ? std::vector(pattern.begin(), pattern.begin() + 256) + : std::vector(256, 0); + if (offset_out != offset_wanted) return 60; invoke(list, 17, arg(copy_b.Get()), arg(empty_d.Get())); invoke(list, 19, arg(resolved_r.Get()), 0, arg(msaa_m.Get()), 0, DXGI_FORMAT_R8G8B8A8_UNORM); invoke(list, 15, arg(buffer_y.Get()), 0, arg(buffer_x.Get()), 0, 16); From c308f362676f991da968463be1532135daead576 Mon Sep 17 00:00:00 2001 From: Kawiu <110430638+Kawiu@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:48:43 +0100 Subject: [PATCH 4/4] test: cover title snapshots in mesh handoff Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- CMakePresets.json | 2 +- tests/cmake/mesh_title_snapshot.cmake | 6 ++++++ tests/startup_indirect_mesh_lease.inl | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/cmake/mesh_title_snapshot.cmake diff --git a/CMakePresets.json b/CMakePresets.json index f418555af5..c761de7cbc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -49,7 +49,7 @@ "displayName": "Windows pull request smoke tests", "filter": { "include": { - "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$" + "name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_mesh57_real_shape|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(control_)?warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_indirect_mesh_cache_heap(_wide)?_warp|runtime_mesh86_cache_cli_check|startup_shader_cache_key|startup_present_readback|startup_present_planes(_control)?|startup_present_composite_(warp|overlay_removed_control_warp)|startup_mesh_title_snapshot_warp|startup_list_copy_(warp|title_snapshot_warp|validation(_[a-z_]+_control)?)|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference)$" } } }, diff --git a/tests/cmake/mesh_title_snapshot.cmake b/tests/cmake/mesh_title_snapshot.cmake new file mode 100644 index 0000000000..c75956f011 --- /dev/null +++ b/tests/cmake/mesh_title_snapshot.cmake @@ -0,0 +1,6 @@ +foreach(backend IN ITEMS warp hardware) + add_test(NAME startup_mesh_title_snapshot_${backend} + COMMAND startup_indirect_draw_indexed ${backend} mesh-lease-writer) + set_tests_properties(startup_mesh_title_snapshot_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77 + ENVIRONMENT "X2W_MESH86_FIXTURE_XMEM=$;X2W_D3D12_TITLE_COPY_SNAPSHOT=1;X2W_TEST_MESH_TITLE_SNAPSHOT=1") +endforeach() diff --git a/tests/startup_indirect_mesh_lease.inl b/tests/startup_indirect_mesh_lease.inl index de5d8846c1..0c4baaa5ed 100644 --- a/tests/startup_indirect_mesh_lease.inl +++ b/tests/startup_indirect_mesh_lease.inl @@ -29,6 +29,8 @@ struct MeshLeaseWriter { ComPtr placed, recording, queue; ComPtr allocator; ComPtr writer_source; + ComPtr title_source; + unsigned char* title_source_memory{}; ComPtr gate, completion; bool submitted{}; @@ -117,6 +119,19 @@ struct MeshLeaseWriter { list->Dispatch(1, 1, 1); } transition(list.Get(), writer_source.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON); + } else if (GetEnvironmentVariableA("X2W_TEST_MESH_TITLE_SNAPSHOT", nullptr, 0)) { + title_source_memory = static_cast( + VirtualAlloc(nullptr, page, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + check(title_source_memory ? S_OK : E_FAIL, "allocate title snapshot source"); + std::memcpy(title_source_memory + 256 + sizeof(UINT), &red, sizeof(red)); + const D3D12_RESOURCE_DESC source_desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, 256, + 1, 1, 1, DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, + D3D12_RESOURCE_FLAG_NONE}; + using Place = HRESULT (WINAPI*)(IUnknown*, void*, const D3D12_RESOURCE_DESC*, UINT, const void*, REFIID, void**); + check(slot(guest, 133)(guest, title_source_memory + 256, &source_desc, D3D12_RESOURCE_STATE_COMMON, + nullptr, __uuidof(ID3D12Resource), + reinterpret_cast(title_source.GetAddressOf())), + "create unaliased title snapshot source"); } else { writer_source = make_buffer(device, sizeof(red), D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ); const D3D12_RANGE empty{}; @@ -126,8 +141,9 @@ struct MeshLeaseWriter { writer_source->Unmap(0, nullptr); } using Copy = void (WINAPI*)(IUnknown*, IUnknown*, UINT64, IUnknown*, UINT64, UINT64); - const UINT64 source_offset = writer && !mirror_owner ? argument_offset : 0; - slot(recording.Get(), 15)(recording.Get(), placed.Get(), record_offset, writer_source.Get(), + const UINT64 source_offset = title_source ? sizeof(UINT) : writer && !mirror_owner ? argument_offset : 0; + IUnknown* source = title_source ? title_source.Get() : writer_source.Get(); + slot(recording.Get(), 15)(recording.Get(), placed.Get(), record_offset, source, source_offset, record_bytes); check(slot(recording.Get(), 9)(recording.Get()), "close slot 15 writer"); queue = create_queue(type); @@ -141,6 +157,8 @@ struct MeshLeaseWriter { gate->Signal(1); mesh_fence_reached(completion.Get(), 5000); } + title_source.Reset(); + if (title_source_memory) VirtualFree(title_source_memory, 0, MEM_RELEASE); } UINT64 address() const { return mirror + record_offset; }