Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,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.
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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_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)$"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,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 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
and block-compressed). A resolve format is exact against a fully typed endpoint and only family-compatible with a
Expand Down Expand Up @@ -1862,6 +1864,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=<n>` | 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=<bmp>` | 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 <i> (not composited)`. Off by default; the baseline capture and `x2w-render presented` read plane 0 either way. The compositor reserves the largest present it can draw (`src/startup_stubs/window_plane_capacity.h`), so an earlier one-plane present does not cap the switch at one plane. See [Presented planes](#presented-planes) |
| `X2W_PRESENT_PLANE=<n>` | 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`; it takes priority over compositing. See [Presented planes](#presented-planes) |
Expand Down
35 changes: 29 additions & 6 deletions src/startup_stubs/list_copy.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
{
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<u64>(from.wrapper->own().title_memory) + offset;
return readable_window(address, static_cast<std::size_t>(bytes)) >= bytes &&
ring_copy(self, address, static_cast<std::size_t>(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)
Expand All @@ -229,19 +243,27 @@ 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) {
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<ID3D12GraphicsCommandList*>(self->own().real)
->CopyBufferRegion(to.resource, destination_offset, from.resource, source_offset, bytes);
static_cast<ID3D12GraphicsCommandList*>(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()) {
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<ID3D12GraphicsCommandList*>(self->own().real);
D3D12_HEAP_PROPERTIES source_properties{};
const bool mesh_record = mesh_xmem_indirect() && bytes == sizeof(D3D12_DISPATCH_MESH_ARGUMENTS) &&
Expand All @@ -252,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);
Expand Down
6 changes: 6 additions & 0 deletions tests/cmake/mesh_title_snapshot.cmake
Original file line number Diff line number Diff line change
@@ -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=$<TARGET_FILE:xmem_shim>;X2W_D3D12_TITLE_COPY_SNAPSHOT=1;X2W_TEST_MESH_TITLE_SNAPSHOT=1")
endforeach()
22 changes: 20 additions & 2 deletions tests/startup_indirect_mesh_lease.inl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct MeshLeaseWriter {
ComPtr<IUnknown> placed, recording, queue;
ComPtr<ID3D12CommandAllocator> allocator;
ComPtr<ID3D12Resource> writer_source;
ComPtr<IUnknown> title_source;
unsigned char* title_source_memory{};
ComPtr<ID3D12Fence> gate, completion;
bool submitted{};

Expand Down Expand Up @@ -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<unsigned char*>(
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<Place>(guest, 133)(guest, title_source_memory + 256, &source_desc, D3D12_RESOURCE_STATE_COMMON,
nullptr, __uuidof(ID3D12Resource),
reinterpret_cast<void**>(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{};
Expand All @@ -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<Copy>(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<Copy>(recording.Get(), 15)(recording.Get(), placed.Get(), record_offset, source,
source_offset, record_bytes);
check(slot<HRESULT (WINAPI*)(IUnknown*)>(recording.Get(), 9)(recording.Get()), "close slot 15 writer");
queue = create_queue(type);
Expand All @@ -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; }
Expand Down
Loading
Loading