From d9fbfc86a372b7e008e55ff46315d97f92279cfd Mon Sep 17 00:00:00 2001 From: c1 Date: Thu, 26 Nov 2026 15:38:40 +0100 Subject: [PATCH 1/3] startup: read translated compute inputs that live only in title memory from a snapshot, and bind unbound inputs as zeros A compute input in a placed buffer that does not alias title memory is a committed default buffer that holds zeros, so the bytes the title wrote exist only in title memory. With X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1 (opt-in) the range (at most 16 MiB) is copied into a dedicated upload pool (128 MiB) so draw and texture uploads cannot starve it. A compute input whose four descriptor words are all zero is an unbound buffer: it reads zeros (16 bytes) instead of refusing the dispatch; an empty range with any non-zero word is still refused. The log names the source of each input and the render totals count GPU copies and snapshots. --- docs/experiments.md | 10 +++++ src/startup_stubs/d3d12_compute_dispatch.inl | 14 +++++- src/startup_stubs/d3d12_draw.inl | 45 +++++++++++++++++-- src/startup_stubs/d3d12_xs_device.cpp | 41 +++++++++++------ tests/startup_compute_dispatch_input_check.py | 22 +++++++++ tests/startup_stream_consumer.cpp | 11 ++++- 6 files changed, 122 insertions(+), 21 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 1fe79025ee..34b581304a 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -192,6 +192,16 @@ The source is a same-device desktop resource with no title shadow, a unique alia or an already covered range. Later overlapping copies invalidate earlier coverage. The recording discards this proof at Close, so another recording needs its own writer. +`X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1` lets a translated compute Dispatch read an input that lies in a placed buffer which does +not alias title memory. That buffer's desktop copy is a committed default buffer that holds zeros, so the bytes the title wrote +exist only in title memory. The input resolves in this order: a validated GPU copy of the current recording (the proof above, +which needs `X2W_TRANSLATED_INDIRECT_COPY_RANGES=1`), else a snapshot of the range (at most 16 MiB) taken from title memory +into the upload ring when the Dispatch is recorded, else the refusal `an input is in a placed buffer that does not alias title +memory`. A guest write after the recording is not seen, and data a GPU pass wrote into such a buffer is not either. The first +use per pipeline key logs `x2w-draw compute input (...) comes from a GPU copy this list made|a snapshot of title +memory`, and the render totals line counts both paths. Off by default; `tools/startup/tester_run.ps1` turns it on +(`-NoTitleInputSnapshot` turns it off). `startup_compute_dispatch_input` covers it with the `dispatch-input-snapshot` case. + The source-built fixture reproduces a 68-byte request shape with source offset `0xbfffa0`. Its compute writer fills the source with contrasting colours. The consumer reads red from the second DWORD in the destination while the title-side green sentinel stays diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 7115c28500..5f635bb788 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -35,6 +35,7 @@ struct ComputeTranslation { const char* unmodelled = nullptr; // why a manifest that exists cannot be used u64 dispatches = 0, translated = 0; // census: Dispatch calls with this key bound, and those recorded const char* first_refusal = nullptr; // reason of the first refused call + bool input_path_logged = false; // the first time a placed input came from a GPU copy or a title snapshot std::uint32_t refusal_words[4] = {}; // the table descriptor that reason was about, if any; a view token's // last word is replaced by its view format | dimension << 16 ~ComputeTranslation() @@ -65,6 +66,7 @@ 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; +LONG compute_inputs_gpu_copied, compute_inputs_snapshot, compute_inputs_snapshot_kib; // inputs by path: this list's GPU copy, a title snapshot // draw_lock held. Returns the reason the translation is unavailable, or null when it is ready or still absent. const char* load_compute_translation(ComputeTranslation& tr) @@ -330,7 +332,17 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& } if (!output) { // Each condition of a complete GPU-backed buffer range has its own reason. - const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20); + const IndirectBufferView view = indirect_table_buffer(self, words, false, &reason, 16u << 20, true); + if (view.source == 1) InterlockedIncrement(&compute_inputs_gpu_copied); + if (view.source == 2) { + InterlockedIncrement(&compute_inputs_snapshot); + InterlockedExchangeAdd(&compute_inputs_snapshot_kib, static_cast((view.bytes + 1023) / 1024)); + } + if (view.source && !tr->input_path_logged) { + tr->input_path_logged = true; + log("x2w-draw compute %016llx input %zu (%s %d %d) comes from %s (%llu bytes)", key, i, slot.heap ? "heap" : "table", slot.a, slot.b, + view.source == 1 ? "a GPU copy this list made" : view.source == 3 ? "zeros for a null descriptor" : "a snapshot of title memory", view.bytes); + } if (view.resource && view.offset % D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) reason = "an input buffer range is not 16-byte aligned in its resource"; if (reason && !tr->first_refusal) // once per key: which input, and where its descriptor was read log("x2w-draw compute %016llx first refused input %zu (%s %d %d), descriptor at 0x%llx", key, i, diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index a67724e605..34fd6d7415 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1940,14 +1940,24 @@ struct IndirectBufferView { u64 offset = 0, bytes = 0; UINT stride = 0; bool upload = false; + int source = 0; // 0 aliased or any other backing, 1 a GPU copy this list made (X2W_TRANSLATED_INDIRECT_COPY_RANGES), 2 a snapshot of title memory, 3 zeros for a null descriptor }; +// X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT=1: a translated compute input in a placed buffer that does not alias title memory +// (a committed default buffer that holds zeros) is read from title memory, snapshotted into the upload ring. +bool title_input_snapshot_enabled() +{ + static const bool enabled = x2w_local::env_on("X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT"); + return enabled; +} + // For indirect draws, bind the complete descriptor range on a known GPU backing. There is no // fallback to copying an unrelated or stale title allocation into the draw upload ring. // why, when given, receives the condition an empty result failed on. IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* words, bool allow_address_alias = false, const char** why = nullptr, - u64 limit = u64{4} << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP) + u64 limit = u64{4} << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP, + bool allow_title_snapshot = false) { const auto refuse = [why](const char* reason) { if (why) *why = reason; @@ -2005,12 +2015,23 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor stride = (words[1] >> 16) & 0x3fff; bytes = u64{stride ? stride : 1} * words[2]; } + // A compute input whose four descriptor words are all zero is an unbound (null) buffer: the hardware reads zeros from + // it, so the dispatch gets 16 bytes of zeros instead of being refused. Any other empty range is still refused. + if (!bytes && allow_title_snapshot && !words[0] && !words[1] && !words[2] && !words[3]) { + u64 zero_offset = 0; + ID3D12Resource* zero_ring = nullptr; + unsigned char* zero_bytes = reserve_upload_ring(16, &zero_offset, &zero_ring); + if (!zero_bytes || !zero_ring) return refuse("a null input could not get its zero bytes"); + std::memset(zero_bytes, 0, 16); + return {zero_ring, zero_offset, 16, 0, true, 3}; + } if (!bytes) return refuse("an input buffer descriptor has zero records"); if (bytes > limit || bytes % 4) return refuse(limit == (16u << 20) ? "an input buffer range is over 16 MiB or not whole dwords" : "an input buffer range exceeds the D3D12 raw SRV limit or is not whole dwords"); ID3D12Resource* native = nullptr; bool upload = false; + int input_source = 0; Wrapper* device = self->own().list_device; if (address) { if (const auto allocation = list_upload_range(self, address, bytes); allocation.resource) { @@ -2031,8 +2052,24 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor owner = placed.owner; native = static_cast(owner->own().real); offset = address - reinterpret_cast(owner->own().title_memory); - if (!placed.alias && (!native || !list_copied_gpu_range(self, native, offset, bytes))) - return refuse("an input is in a placed buffer that does not alias title memory"); + if (!placed.alias) { + if (native && list_copied_gpu_range(self, native, offset, bytes)) { + input_source = 1; // a GPU copy of this list filled the range: the GPU buffer is the truth + } else if (allow_title_snapshot && title_input_snapshot_enabled() && bytes <= (u64{16} << 20)) { + // The buffer is a committed default buffer that holds zeros (it does not alias title memory), so the + // bytes the title wrote are only in title memory: snapshot the range into the upload ring now. A later + // guest write is not seen (as title_backed_source for copies); data a GPU pass wrote into this buffer is not either. + u64 ring_offset = 0; + ID3D12Resource* ring = nullptr; + if (readable_window(address, static_cast(bytes)) < bytes) + return refuse("an input range in title memory is not readable"); + if (!ring_copy(address, static_cast(bytes), &ring_offset, &ring, true) || !ring) + return refuse("an input range could not be copied from title memory"); + return {ring, ring_offset, bytes, stride, true, 2}; + } else { + return refuse("an input is in a placed buffer that does not alias title memory"); + } + } } else if (own_memory) { native = static_cast(owner->own().real); } else if (owner && !owner->own().title_memory) { @@ -2056,7 +2093,7 @@ IndirectBufferView indirect_table_buffer(Wrapper* self, const std::uint32_t* wor const auto desc = native->GetDesc(); if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || (desc.Flags & D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE) || offset > desc.Width || bytes > desc.Width - offset) return refuse("an input range is outside its desktop buffer"); - return {native, offset, bytes, stride, upload}; + return {native, offset, bytes, stride, upload, input_source}; } struct FormattedBufferDescriptor { diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index 57c89ef8ed..c12a0cd542 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -2417,19 +2417,30 @@ ID3D12PipelineState* build_stream_pipeline(const D3D12_PIPELINE_STATE_STREAM_DES // 16 MiB up to 256 MiB in total and stay alive for the process. Exhaustion // refuses new reservations rather than reusing storage without completion. -UploadReservation reserve_upload_ring(std::size_t bytes) +// Title input snapshots use their own pool (128 MiB) so draw and texture uploads +// cannot starve them. +struct UploadPool { + SRWLOCK lock = SRWLOCK_INIT; + std::vector chunks; + std::size_t active = 0; + u64 total_bytes = 0; +}; + +UploadReservation reserve_upload_ring(std::size_t bytes, bool snapshot = false) { constexpr u64 initial_chunk_bytes = u64{16} << 20; - constexpr u64 max_total_bytes = u64{256} << 20; - constexpr u64 max_alloc_bytes = max_total_bytes / 4; + const u64 max_total_bytes = snapshot ? u64{128} << 20 : u64{256} << 20; + const u64 max_alloc_bytes = max_total_bytes / 4; UploadReservation reservation; if (bytes == 0 || bytes > max_alloc_bytes) return reservation; const u64 rounded = (static_cast(bytes) + 511) & ~u64{511}; - static SRWLOCK lock = SRWLOCK_INIT; - static std::vector chunks; - static std::size_t active = 0; - static u64 total_bytes = 0; + static UploadPool pools[2]; + UploadPool& pool = pools[snapshot ? 1 : 0]; + SRWLOCK& lock = pool.lock; + auto& chunks = pool.chunks; + auto& active = pool.active; + auto& total_bytes = pool.total_bytes; AcquireSRWLockExclusive(&lock); if (!chunks.empty()) { @@ -2494,24 +2505,25 @@ UploadReservation reserve_upload_ring(std::size_t bytes) ReleaseSRWLockExclusive(&lock); static LONG refused; if (first_calls(refused, 8)) - log("x2w-draw upload ring reservation refused: no unused capacity"); + log(snapshot ? "x2w-draw snapshot ring reservation refused: no unused capacity" + : "x2w-draw upload ring reservation refused: no unused capacity"); return reservation; } -unsigned char* reserve_upload_ring(std::size_t bytes, u64* offset, ID3D12Resource** resource) +unsigned char* reserve_upload_ring(std::size_t bytes, u64* offset, ID3D12Resource** resource, bool snapshot = false) { if (resource) *resource = nullptr; if (offset) *offset = 0; - const UploadReservation reservation = reserve_upload_ring(bytes); + const UploadReservation reservation = reserve_upload_ring(bytes, snapshot); if (!reservation.mapped) return nullptr; if (offset) *offset = reservation.offset; if (resource) *resource = reservation.resource; return reservation.mapped; } -bool ring_copy(u64 title_address, std::size_t bytes, u64* offset, ID3D12Resource** resource = nullptr) +bool ring_copy(u64 title_address, std::size_t bytes, u64* offset, ID3D12Resource** resource = nullptr, bool snapshot = false) { - auto* dest = reserve_upload_ring(bytes, offset, resource); + auto* dest = reserve_upload_ring(bytes, offset, resource, snapshot); if (!dest) return false; std::memcpy(dest, reinterpret_cast(title_address), bytes); return true; @@ -6798,8 +6810,9 @@ HRESULT __stdcall queue_present(Wrapper* self, UINT planes, const void* plane_pa heap_root_refusals[static_cast(x2w_startup::RealRootDecision::state_not_restorable)], indirect_first_lookups, compute_requests_published, compute_requests_present, compute_requests_failed, compute_blob_pointer_words); if (render_mode() && frame % 300 == 0) { - log("x2w-render compute dispatches: translated %ld, refused %ld, no translation %ld, not modelled %ld", - compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled); + log("x2w-render compute dispatches: translated %ld, refused %ld, no translation %ld, not modelled %ld; placed inputs from a GPU copy %ld, from a title snapshot %ld (%ld KiB)", + compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled, + compute_inputs_gpu_copied, compute_inputs_snapshot, compute_inputs_snapshot_kib); log_compute_census(); } if (render_mode() && frame % 300 == 0) { diff --git a/tests/startup_compute_dispatch_input_check.py b/tests/startup_compute_dispatch_input_check.py index 57b9e88392..6766ece2e2 100644 --- a/tests/startup_compute_dispatch_input_check.py +++ b/tests/startup_compute_dispatch_input_check.py @@ -85,6 +85,28 @@ def main(consumer, dxc, adapter): assert got == expected and len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused: '), result.stderr[-3000:] errors = [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] assert not errors, errors[0] + # Opt-in X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT: an input in a placed buffer that does not alias title memory holds + # its bytes only in title memory (the desktop copy is zeros). Off, it is refused; on, the bytes are snapshotted + # into the upload ring and all 320 words match; with title memory zero (dispatch-input-copied) the dispatch runs + # on zeros: not refused, not the expected words, not untouched. + snapshot_env = dict(env, X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT='1') + got, result = dispatch(directory, consumer, env, 'dispatch-input-snapshot') + assert got == untouched and lines(result, 'refused: ')[0].endswith(CONTROLS[3][1]), result.stderr[-3000:] + got, result = dispatch(directory, consumer, snapshot_env, 'dispatch-input-snapshot') + assert got == expected and len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused: '), result.stderr[-3000:] + assert len(lines(result, 'comes from a snapshot of title memory (1280 bytes)')) == 1, result.stderr[-3000:] + errors = [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] + assert not errors, errors[0] + got, result = dispatch(directory, consumer, snapshot_env, 'dispatch-input-copied') + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused: '), result.stderr[-3000:] + assert got != expected and got != untouched, 'a snapshot of zero title memory must not give the expected words' + # An all-zero descriptor is an unbound buffer: the dispatch runs on zeros instead of being refused (the empty + # control above has a nonzero base and stays refused). + got, result = dispatch(directory, consumer, env, 'dispatch-input-null') + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused: '), result.stderr[-3000:] + assert len(lines(result, 'comes from zeros for a null descriptor (16 bytes)')) == 1, result.stderr[-3000:] + assert got != expected and got != untouched, 'a null input must read zeros, not the expected words' + print(f'{adapter}: title-input snapshot: off refused, on all {C.WORDS} words match, zero title memory runs on zeros') print(f'startup_compute_dispatch_input: PASS on {adapter} (all {C.WORDS} words match, also with the input behind ' f'a memory view token; {len(CONTROLS)} inputs refused, each with its own reason and an untouched output)') diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index eddf880ff0..f3c2a464bb 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -209,6 +209,7 @@ static void* make_committed(void* device, D3D12_HEAP_TYPE type, const D3D12_RESO // Input descriptors the dispatch refuses, one reason each: dispatch-input-empty has zero records (a nonzero base, // word 3 zero), dispatch-input-past ends 16 bytes past the input buffer, dispatch-input-unplaced names memory between // the two buffers, dispatch-input-copied a third buffer placed there at an offset the desktop cannot alias, and +// dispatch-input-null (all four words zero, an unbound buffer) is not refused and reads zeros; // dispatch-input-token writes the token of a texture view where the input descriptor was. // For any mode, X2W_TEST_DISPATCH_IN names 1280 bytes that replace the input words, and X2W_TEST_DISPATCH_FIELDS // names six words that replace, for the input and then the output descriptor, the stride (word 1 bits 16-31), the @@ -248,7 +249,11 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin std::memcpy(descriptors[mode == "dispatch-swapped" ? 1 - i : i], view, sizeof(view)); } const UINT64 between = reinterpret_cast(memory) + 0x8000; - if (mode == "dispatch-input-copied") { + // dispatch-input-snapshot: the input words are written into the memory the third buffer is placed over, so they + // exist only in title memory (the desktop copy of a buffer that does not alias holds zeros); dispatch-input-copied + // leaves that memory zero. + if (mode == "dispatch-input-snapshot") std::memcpy(reinterpret_cast(between), input, sizeof(input)); + if (mode == "dispatch-input-copied" || mode == "dispatch-input-snapshot") { const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, words * sizeof(UINT), 1, 1, 1, DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR}; void* copied = nullptr; @@ -258,9 +263,11 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin if (mode == "dispatch-input-empty") { const UINT view[4] = {0x32c, 0, 0, 0}; std::memcpy(descriptors[0], view, sizeof(view)); + } else if (mode == "dispatch-input-null") { + std::memset(descriptors[0], 0, sizeof(descriptors[0])); // an unbound buffer: all four words zero } else if (mode == "dispatch-input-past") { descriptors[0][2] = words + 4; - } else if (mode == "dispatch-input-unplaced" || mode == "dispatch-input-copied") { + } else if (mode == "dispatch-input-unplaced" || mode == "dispatch-input-copied" || mode == "dispatch-input-snapshot") { descriptors[0][0] = static_cast(between); descriptors[0][1] = static_cast(between >> 32) | 4u << 16; } From 4322d76f155c1878da11b3b3e2dee195b1886bfe Mon Sep 17 00:00:00 2001 From: c1 Date: Thu, 26 Nov 2026 16:09:05 +0100 Subject: [PATCH 2/3] fix: clear the title-input snapshot flag in the baseline runs and correct the launcher doc --- docs/experiments.md | 4 ++-- tests/startup_compute_dispatch_input_check.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 34b581304a..111f27c1d1 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -199,8 +199,8 @@ which needs `X2W_TRANSLATED_INDIRECT_COPY_RANGES=1`), else a snapshot of the ran into the upload ring when the Dispatch is recorded, else the refusal `an input is in a placed buffer that does not alias title memory`. A guest write after the recording is not seen, and data a GPU pass wrote into such a buffer is not either. The first use per pipeline key logs `x2w-draw compute input (...) comes from a GPU copy this list made|a snapshot of title -memory`, and the render totals line counts both paths. Off by default; `tools/startup/tester_run.ps1` turns it on -(`-NoTitleInputSnapshot` turns it off). `startup_compute_dispatch_input` covers it with the `dispatch-input-snapshot` case. +memory`, and the render totals line counts both paths. Off by default. To turn it on for a run, set `$env:X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT = "1"` in the PowerShell session before +starting `tools/startup/run.ps1`, which passes the session's environment on to the run. `startup_compute_dispatch_input` covers it with the `dispatch-input-snapshot` case. The source-built fixture reproduces a 68-byte request shape with source offset `0xbfffa0`. Its compute writer fills the source with contrasting colours. The consumer reads red diff --git a/tests/startup_compute_dispatch_input_check.py b/tests/startup_compute_dispatch_input_check.py index 6766ece2e2..907cc63ff0 100644 --- a/tests/startup_compute_dispatch_input_check.py +++ b/tests/startup_compute_dispatch_input_check.py @@ -43,6 +43,7 @@ def main(consumer, dxc, adapter): with tempfile.TemporaryDirectory() as temporary: directory = Path(temporary) cache, env = prepare(directory) + env.pop('X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT', None) # prepare() copies os.environ: every baseline run starts with the flag off env.update(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' From 73b2d0ff73921cce81188d3e11cda6064ac3de87 Mon Sep 17 00:00:00 2001 From: tedin7 <110300616+tedin7@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:26:27 +0100 Subject: [PATCH 3/3] test: the long snapshot case puts its input where the buffer does not alias title memory, and asserts the snapshot log line --- tests/startup_compute_dispatch_input_check.py | 2 ++ tests/startup_stream_consumer.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/startup_compute_dispatch_input_check.py b/tests/startup_compute_dispatch_input_check.py index b0e263d1e1..041590b605 100644 --- a/tests/startup_compute_dispatch_input_check.py +++ b/tests/startup_compute_dispatch_input_check.py @@ -109,6 +109,8 @@ def main(consumer, dxc, adapter): assert got == expected and not lines(result, 'refused: '), result.stderr[-3000:] assert not lines(result, 'reservation refused'), lines(result, 'reservation refused') assert len(lines(result, 'Dispatch(3, 2, 2) translated')) >= 1, result.stderr[-3000:] + # The input must really come from a snapshot (8 MiB), not be read in place: an empty long case would pass everything above. + assert len(lines(result, 'comes from a snapshot of title memory (8388608 bytes)')) == 1, result.stderr[-3000:] errors = [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] assert not errors, errors[0] # An all-zero descriptor is an unbound buffer: the dispatch runs on zeros instead of being refused (the empty diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index b7c67ab644..0741de4c63 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -215,6 +215,8 @@ static void* make_committed(void* device, D3D12_HEAP_TYPE type, const D3D12_RESO // For any mode, X2W_TEST_DISPATCH_IN names 1280 bytes that replace the input words, and X2W_TEST_DISPATCH_FIELDS // names six words that replace, for the input and then the output descriptor, the stride (word 1 bits 16-31), the // record count (word 2) and word 3, which are otherwise 4, 320 and 0. +// (The long case puts its input at 0x28000, not at a 64 KiB multiple like 0x20000: there the placed buffer would alias title memory +// and the input would be read in place, never snapshotted, which is how an earlier version of this case passed without a snapshot.) // dispatch-input-snapshot-long: dispatch-input-snapshot with an 8 MiB input range (the descriptor declares 2M records; the program // reads the first 320 words) dispatched in 48 frames, 384 MiB of snapshots in all, with the queue completed between frames. The // snapshot pool holds 128 MiB, so every frame after the sixteenth reuses chunks the GPU is done with; a pool that is not recycled @@ -226,7 +228,7 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin constexpr UINT long_records = 2u << 20, long_frames = 48; const bool indirect = mode.rfind("dispatch-indirect-", 0) == 0; const UINT groups = mode == "dispatch-indirect-zero" ? 0u : mode == "dispatch-indirect-2" ? 2u : 5u; - auto* memory = static_cast(VirtualAlloc(nullptr, long_run ? 0x20000 + long_records * sizeof(UINT) : indirect ? 0x30000 : 0x20000, + auto* memory = static_cast(VirtualAlloc(nullptr, long_run ? 0x28000 + long_records * sizeof(UINT) : indirect ? 0x30000 : 0x20000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); if (!memory) return 70; UINT* const buffers[2] = {memory, memory + 0x10000 / sizeof(UINT)}; @@ -256,7 +258,7 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin const UINT view[4] = {static_cast(address), static_cast(address >> 32) | fields[i][0] << 16, fields[i][1], fields[i][2]}; std::memcpy(descriptors[mode == "dispatch-swapped" ? 1 - i : i], view, sizeof(view)); } - const UINT64 between = reinterpret_cast(memory) + (long_run ? 0x20000 : 0x8000); + const UINT64 between = reinterpret_cast(memory) + (long_run ? 0x28000 : 0x8000); // dispatch-input-snapshot: the input words are written into the memory the third buffer is placed over, so they // exist only in title memory (the desktop copy of a buffer that does not alias holds zeros); dispatch-input-copied // leaves that memory zero.