Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
12fcf6b
gpu: back slot 133 linear buffers by sharing or a submit-time copy (o…
MasterDomino Nov 25, 2026
180820c
gpu: keep slot 133's default backing where the linear path refuses
MasterDomino Nov 25, 2026
b121bfc
gpu: refresh linear buffers without holding their lock across waits
MasterDomino Nov 25, 2026
96d166b
gpu: note why concurrent linear-buffer publishes only cost a refresh
MasterDomino Nov 25, 2026
959cc3a
gpu: refresh linear buffers on an internal queue that consumers wait for
MasterDomino Nov 25, 2026
e896410
gpu: count linear-buffer backings in the D3D12 budget
MasterDomino Nov 25, 2026
829d394
gpu: defer slot 133 linear buffers to the XMem lease path
MasterDomino Nov 25, 2026
7c75f6e
gpu: stop refreshing a copied linear buffer that a list copy writes
MasterDomino Nov 25, 2026
bfdd583
docs: record linear-buffer budgets, list-copy holds and the lease def…
MasterDomino Nov 25, 2026
e880a3c
gpu: mark a copied linear buffer GPU-written when its copy is submitted
MasterDomino Nov 25, 2026
07c7a19
gpu: order linear-buffer refreshes behind earlier submissions
MasterDomino Nov 25, 2026
8c52d38
gpu: publish linear-buffer uploads in the order their copies execute
MasterDomino Nov 25, 2026
b605d7c
gpu: probe and guard title memory right before staging a linear buffer
MasterDomino Nov 25, 2026
981b519
tests: drive discarded copies, earlier reads and refresh races in lin…
MasterDomino Nov 25, 2026
58971a4
docs: record the linear-buffer submit-time GPU write, producer wait a…
MasterDomino Nov 25, 2026
c6a0c8a
gpu: refuse a linear-buffer submission whose refresh has no safe comp…
MasterDomino Nov 25, 2026
c777de1
docs: record the linear-buffer refusal of a refresh with no safe comp…
MasterDomino Nov 25, 2026
7ecb6cf
Merge main into gpu/linear-buffer-shared-backing
MasterDomino Nov 25, 2026
ee56e73
gpu: order a queue's title waits and user fence values under one lock
MasterDomino Nov 25, 2026
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
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,42 @@ foreach(mutant IN ITEMS skip_refresh skip_copy_back reuse_early)
set_tests_properties(unified_buffer_paths_${mutant}_control PROPERTIES WILL_FAIL TRUE TIMEOUT 90
SKIP_RETURN_CODE 77)
endforeach()
# The production slice (#1914): slot 133's opt-in linear-buffer backing (X2W_D3D12_LINEAR_BUFFERS,
# src/startup_stubs/linear_buffer_backing.h) through the device and queue wrappers of d3d12_xs.dll, over
# XMem pages and a private range: the default, real sharing, forced copying, host sharing refusal, a
# copy without a submit fence (the default backing is kept and the refusal reported), a refresh that
# cannot be staged (the submission runs, the buffer is reported stale) and a one-buffer staging pool
# (a waiting refresh must not block release(), the info export or another queue). Refreshes run on an
# internal copy queue; the copy path also reads on COMPUTE and COPY queues, reads one buffer on two
# queues after one CPU write (both must see it), and follows a title-owned cross-queue fence without
# deadlock. It also counts the backings in the D3D12 budget, keeps a buffer a submitted list copy wrote
# (and refreshes one whose copy was discarded), orders a refresh behind an earlier read on another queue,
# refuses a submission whose refresh would have to wait for a queue behind an unreached title Wait (also
# when that Wait and the submission behind it arrive on two threads), publishes two threads' refreshes in execution order, skips a buffer released and freed mid-refresh, and
# defers XMem placements to the mesh XMem lease path when that is on. Each mutant removes one guarantee in
# the DLL and must fail its case.
add_executable(linear_buffer_backing_check tests/linear_buffer_backing_check.cpp)
target_include_directories(linear_buffer_backing_check PRIVATE tests)
target_compile_features(linear_buffer_backing_check PRIVATE cxx_std_17)
target_link_libraries(linear_buffer_backing_check PRIVATE xmem_shim d3d12_xs_shim d3d12 dxgi d3dcompiler)
foreach(adapter IN ITEMS warp hardware)
foreach(path IN ITEMS default share copy refusal untracked stale contention lease)
add_test(NAME linear_buffer_backing_${path}_${adapter} COMMAND linear_buffer_backing_check ${adapter} ${path})
set_tests_properties(linear_buffer_backing_${path}_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
endforeach()
foreach(control IN ITEMS copy:skip_refresh copy:reuse_early copy:copy_gpu_writes refusal:ignore_feature
copy:refusal_silent contention:hold_lock copy:skip_consumer_wait copy:refresh_gpu_written copy:gpuw_at_record
copy:skip_producer_wait copy:publish_out_of_order copy:copy_after_retire copy:accept_unsafe_refresh
copy:unlocked_title_wait)
string(REPLACE ":" ";" parts "${control}")
list(GET parts 0 path)
list(GET parts 1 mutant)
string(REPLACE "_" "-" flag "${mutant}")
add_test(NAME linear_buffer_backing_${mutant}_control COMMAND linear_buffer_backing_check warp ${path} --mutate ${flag})
set_tests_properties(linear_buffer_backing_${mutant}_control PROPERTIES WILL_FAIL TRUE TIMEOUT 120
SKIP_RETURN_CODE 77)
endforeach()
# The configured range's windows and GPU addresses (src/d3d12_xs_range.h) with a fake device and fake
# windows. The mutated run is the negative control.
add_executable(d3d12_xs_range_check tests/d3d12_xs_range_check.cpp src/d3d12_xs_range.cpp)
Expand Down
90 changes: 90 additions & 0 deletions docs/experiments.md

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions docs/startup-runtime.md

Large diffs are not rendered by default.

197 changes: 167 additions & 30 deletions src/startup_stubs/d3d12_xs_device.cpp

Large diffs are not rendered by default.

1,256 changes: 1,256 additions & 0 deletions src/startup_stubs/linear_buffer_backing.h

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/startup_stubs/linear_buffer_report.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

// What d3d12_xs.dll reports about slot 133's opt-in linear buffers (X2W_D3D12_LINEAR_BUFFERS,
// src/startup_stubs/linear_buffer_backing.h) to fixtures through x2w_d3d12_linear_buffer_info and
// x2w_d3d12_linear_buffer_totals. Plain layouts: the DLL and the fixtures include this file alike.

#include <cstdint>

struct X2wLinearBufferInfo {
std::uint32_t path; // 1 shared, 2 copied, 3 kept the default backing (refusal_hr says why)
std::uint32_t use; // 1 GPU-read, 2 GPU-written
std::int32_t feature_hr; // S_OK supported, DXGI_ERROR_UNSUPPORTED not, other: query failed; S_FALSE not queried
std::int32_t share_hr; // result of the sharing attempt; S_FALSE when not attempted
std::int32_t refusal_hr; // kept default: why the new path could not keep its guarantees; else S_OK
std::uint32_t stale; // copied: 1 while the backing holds an older upload than the title's bytes
std::uint64_t heap_generation; // shared: generation of the opened heap
void* backing; // the desktop ID3D12Resource
std::uint64_t refreshes; // copied: submissions that copied bytes into the backing
std::uint64_t bytes_copied; // copied: bytes copied from title memory into the backing
std::uint64_t last_staging; // copied: id of the staging buffer of the last refresh (0: none)
std::uint64_t last_fence; // copied: internal fence value of the last refresh (0: none)
std::uint64_t refresh_failures; // copied: submissions that ran without this buffer's refresh
std::int32_t last_refresh_hr; // copied: HRESULT of the last failed refresh; S_OK if none
std::uint32_t gpu_written; // copied: 1 once a submitted copy wrote it; it is no longer refreshed
};

struct X2wLinearBufferTotals {
std::uint64_t placements, shared, copied, kept_default;
std::uint64_t feature_queries, heap_opens, heap_open_failures, heap_cache_hits, place_failures;
std::uint64_t submissions, refreshes, bytes_copied, staging_created, staging_reused, unreadable;
std::uint64_t refresh_failures;
std::uint64_t consumer_waits; // submissions made to Wait for a refresh on the internal queue
std::uint64_t gpu_written; // copied buffers that a submitted copy wrote (held from then on)
std::uint64_t producer_waits; // refresh copies made to Wait for a queue's earlier, uncompleted submission
std::uint64_t unsafe_refresh_refusals; // submissions refused: their refresh had no safe completion order
std::uint64_t reordered_publishes; // an older refresh published after a newer one: `uploaded` dropped
std::uint64_t copy_faults; // staging reads of title memory that faulted (caught; that refresh failed)
std::int32_t last_refusal_hr, last_refresh_hr;
};
34 changes: 34 additions & 0 deletions src/startup_stubs/list_copy.inl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ std::unordered_map<Wrapper*, std::vector<ID3D12Resource*>>& pending_gpu_writes()
static std::unordered_map<Wrapper*, std::vector<ID3D12Resource*>> m;
return m;
}
// X2W_D3D12_LINEAR_BUFFERS: the copied linear buffers a recording wrote (list slots 15 and 17), under the same
// rule. A copied buffer stops being refreshed from its title memory only once a recording that writes it is
// submitted; a recording that is discarded leaves it refreshed (linear_buffer_backing.h).
std::unordered_map<Wrapper*, std::vector<ID3D12Resource*>>& pending_linear_writes()
{
static std::unordered_map<Wrapper*, std::vector<ID3D12Resource*>> m;
return m;
}

bool list_wrote(Wrapper* list, ID3D12Resource* resource)
{
Expand All @@ -125,11 +133,13 @@ void discard_list_gpu_writes(Wrapper* self)
{
AcquireSRWLockExclusive(&pending_writes_lock);
pending_gpu_writes().erase(self);
pending_linear_writes().erase(self);
ReleaseSRWLockExclusive(&pending_writes_lock);
}

void commit_list_gpu_writes(Wrapper* self)
{
std::vector<ID3D12Resource*> linear;
AcquireSRWLockShared(&pending_writes_lock);
if (const auto it = pending_gpu_writes().find(self); it != pending_gpu_writes().end()) {
for (ID3D12Resource* resource : it->second) {
Expand All @@ -138,7 +148,10 @@ void commit_list_gpu_writes(Wrapper* self)
state.done = true;
}
}
if (const auto it = pending_linear_writes().find(self); it != pending_linear_writes().end()) linear = it->second;
ReleaseSRWLockShared(&pending_writes_lock);
// After the recording's ExecuteCommandLists, outside the lock (the backing takes its own).
for (ID3D12Resource* resource : linear) linear_buffers().note_gpu_write(resource);
}

// A copy or resolve destination will hold what the GPU wrote once `self` is submitted. A title-backed texture
Expand All @@ -152,6 +165,25 @@ void mark_gpu_written(Wrapper* self, const CopyEndpoint& destination)
ReleaseSRWLockExclusive(&pending_writes_lock);
}

// X2W_D3D12_LINEAR_BUFFERS: a copied linear buffer that a recorded copy writes keeps the GPU's bytes once
// `self` is submitted, and is no longer refreshed from its title memory from then on (linear_buffer_backing.h).
// Until then the write is pending on the recording: Reset or a failed Close drops it with the texture writes.
void note_linear_gpu_write(Wrapper* self, const CopyEndpoint& destination)
{
if (!destination.wrapper || !destination.wrapper->own().title_memory ||
x2w_startup::linear_buffer_mode() == x2w_startup::LinearBufferMode::off)
return;
if (x2w_startup::linear_detail::mutant("gpuw-at-record")) {
// Mutant: the backing changes at recording, so a discarded recording still stops its refreshes.
linear_buffers().note_gpu_write(destination.resource);
return;
}
AcquireSRWLockExclusive(&pending_writes_lock);
auto& writes = pending_linear_writes()[self];
if (std::find(writes.begin(), writes.end(), destination.resource) == writes.end()) writes.push_back(destination.resource);
ReleaseSRWLockExclusive(&pending_writes_lock);
}

// Refusal shared by the three handlers once the descriptions passed, or none.
x2w_startup::CopyRefusal check_roles_and_sync(Wrapper* self, const CopyEndpoint& to, const CopyEndpoint& from, bool sync)
{
Expand Down Expand Up @@ -218,6 +250,7 @@ void __stdcall list_copy_buffer_region(Wrapper* self, u64 destination, u64 desti
note_mesh_xmem_write(self, to.wrapper, destination_offset, bytes, 15, source_kind,
srv_word || mesh_record ? from.resource : nullptr, source_offset);
}
note_linear_gpu_write(self, to);
if (indirect_copy_ranges()) {
const auto* info = to.wrapper ? resource_info(to.wrapper) : nullptr;
note_copy_gpu_range(self, to.resource, destination_offset, bytes, authoritative && info &&
Expand Down Expand Up @@ -247,6 +280,7 @@ void __stdcall list_copy_resource(Wrapper* self, u64 destination, u64 source)
if (to_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) {
note_mesh_xmem_write(self, to.wrapper, 0, to_desc.Width, 17, "buffer");
note_copy_gpu_range(self, to.resource, 0, to_desc.Width, false);
note_linear_gpu_write(self, to);
} else mark_gpu_written(self, to);
InterlockedIncrement(&list_resource_copies);
}
Expand Down
Loading
Loading