Skip to content
Open
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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,10 @@ foreach(backend IN ITEMS warp hardware)
set_tests_properties(${case}_inline_control PROPERTIES
PASS_REGULAR_EXPRESSION "FAIL: inline-control missed Release left buffer above baseline")
endforeach()
add_test(NAME startup_resource_budget_creators_${backend} COMMAND startup_resource_budget ${backend} creators)
set_tests_properties(startup_resource_budget_creators_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
PASS_REGULAR_EXPRESSION "upload creators passed"
ENVIRONMENT "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=0;X2W_D3D12_LINEAR_BUFFERS=copy")
endforeach()

# X2W_D3D12_RELEASE_RETIRED=1 frees the desktop object of a committed 2D texture only when no recorded list, no submission
Expand Down Expand Up @@ -2503,6 +2507,10 @@ add_executable(upload_reservation_check tests/upload_reservation_check.cpp)
target_include_directories(upload_reservation_check PRIVATE src)
target_compile_features(upload_reservation_check PRIVATE cxx_std_17)
add_test(NAME upload_reservation COMMAND upload_reservation_check)
add_executable(upload_budget_check tests/upload_budget_check.cpp)
target_include_directories(upload_budget_check PRIVATE src)
target_compile_features(upload_budget_check PRIVATE cxx_std_17)
add_test(NAME upload_budget COMMAND upload_budget_check)
# The same slot driven through the stand-in on a desktop device: one refusal line per refused case, and the
# forwarded calls counted by a pipeline-statistics query on the desktop list.
add_executable(startup_list_dispatch_native tests/startup_list_dispatch_native.cpp)
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"xmem_shim_test_controls", "startup_stub_xcrdapi", "startup_stub_xcrdapi_break_window_control",
"xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check",
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check", "existing_heap_shared_buffer_check", "startup_request_publisher_check", "mesh86_typed_vsharp_check", "mesh86_typed_vsharp_wide_format_mut", "mesh86_typed_vsharp_any_map_mut", "mesh86_typed_vsharp_any_swizzle_mut", "mesh86_typed_vsharp_any_tid_mut",
"xmem_page_runs_device_check", "linear_buffer_backing_check", "upload_budget_check", "startup_resource_budget", "existing_heap_shared_buffer_check", "startup_request_publisher_check", "mesh86_typed_vsharp_check", "mesh86_typed_vsharp_wide_format_mut", "mesh86_typed_vsharp_any_map_mut", "mesh86_typed_vsharp_any_swizzle_mut", "mesh86_typed_vsharp_any_tid_mut",
"bcpack_formats_check", "startup_stub_consumer", "startup_inline_retire", "startup_resource_retire_title", "startup_table_lock",
"native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check"
]
Expand All @@ -50,7 +50,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_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|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|existing_heap_shared_buffer(_offset_control)?_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|native_mesh_readfirstlane_warp|startup_triage_run|mesh86_typed_vsharp_[a-z_]+|startup_request_publisher(_inline_control)?)$"
"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_mesh57_runtime(_[a-z]+)?_warp|native_fixed_mesh57_published_pair(_refusal)?_warp|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|existing_heap_shared_buffer(_offset_control)?_warp|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|native_mesh_readfirstlane_warp|upload_budget|startup_resource_budget_creators_warp|startup_triage_run|mesh86_typed_vsharp_[a-z_]+|startup_request_publisher(_inline_control)?)$"
}
}
},
Expand Down
16 changes: 14 additions & 2 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,9 @@ per-kind counter: the highest count for a signature kind, bucket and reason, wit
A line whose reason is not `bucket/code` with a known bucket is ignored.

The GPU Memory Budget section uses complete `x2w-budget` heartbeat lines from
`X2W_D3D12_BUDGET=1`. It counts samples above the local DXGI budget and prints
`X2W_D3D12_BUDGET=1`. A line that also carries the upload creator columns is
still a complete sample. A line with only some of those columns is ignored.
It counts samples above the local DXGI budget and prints
the sample with the highest usage-to-budget ratio, plus the sample with the most
retained texture bytes. Each row keeps the usage, budget and texture counters
from that same heartbeat. Samples with an unavailable or zero local budget
Expand Down Expand Up @@ -2034,7 +2036,17 @@ come from the desktop allocation info for the created description. A slot 133
texture or buffer with committed backing counts in its committed category.
Each opened or created heap uses its desktop heap size once, even when several
placements share it. Placed resource sizes describe the objects occupying
heaps, so adding both columns would count the backing twice.
heaps, so adding both columns would count the backing twice. The `upload`
column stays the total of every upload-heap object. Seven columns next to it
name the creator: `upload_ring` (the draw upload ring and the title-input
snapshot pool), `upload_slot27` (device slots 27 and 127), `upload_slot70`
(the unplaced memory-SRV upload fallback), `upload_slot148` (list upload
pages, including a draw that takes a page from the same allocator),
`upload_linear` (linear-buffer staging), `upload_mesh86` (the Mesh86 texture
slot map) and `upload_other` (every other upload-heap object, including device
slot 76). Those seven add up to `upload` in both the live and the retained
halves. A log from before the split has no creator columns, and `upload` is
the same total.

Final guest release moves a wrapped allocation to the retained column when
the shim still owns the desktop reference. An explicit heap stays live while
Expand Down
3 changes: 2 additions & 1 deletion src/startup_stubs/d3d12_memory_srv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ Wrapper* unplaced_memory_buffer(Wrapper* device, u64 address, u64 span_bytes, co
w->own().backing_budget = backing_budget;
if (backing_budget) backing_budget->begin_use();
} else {
w->own().budget = x2w_budget::committed(desktop, native_resource.Get(), D3D12_HEAP_TYPE_UPLOAD);
w->own().budget = x2w_budget::committed(desktop, native_resource.Get(), D3D12_HEAP_TYPE_UPLOAD,
x2w_budget::upload_slot70);
}

unplaced_buffers.push_back(UnplacedBufferEntry{device, memory.base, page_start, page_span, is_upload, exact, native_resource, w});
Expand Down
23 changes: 19 additions & 4 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,8 @@ __declspec(noinline) u64 create_slot(Wrapper* self, u64 a, u64 b, u64 c, u64 d,
if (SUCCEEDED(child->own().real->QueryInterface(IID_PPV_ARGS(&resource)))) {
if constexpr (N == 27) {
const auto* props = reinterpret_cast<const D3D12_HEAP_PROPERTIES*>(a);
child->own().budget = x2w_budget::committed(device, resource.Get(), props->Type);
child->own().budget = x2w_budget::committed(device, resource.Get(), props->Type,
x2w_budget::upload_slot27);
} else {
child->own().budget = x2w_budget::resource(device, resource.Get(), x2w_budget::placed);
if (auto* heap = as_wrapper(reinterpret_cast<const void*>(a))) {
Expand Down Expand Up @@ -3393,7 +3394,7 @@ UploadReservation reserve_upload_ring(Wrapper* list, std::size_t bytes, bool sna
if (SUCCEEDED(device->CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &buffer,
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&created)))) {
refusal = SnapshotRefusal::map_failed;
auto* budget = x2w_budget::committed(device, created, D3D12_HEAP_TYPE_UPLOAD);
auto* budget = x2w_budget::committed(device, created, D3D12_HEAP_TYPE_UPLOAD, x2w_budget::upload_ring);
if (SUCCEEDED(created->Map(0, nullptr, &base))) {
try {
chunks.push_back(UploadRingChunk{created, static_cast<unsigned char*>(base), chunk_bytes, 0});
Expand Down Expand Up @@ -8488,7 +8489,8 @@ HRESULT create_committed(int slot, Wrapper* self, const D3D12_HEAP_PROPERTIES* p
resource->Release();
return E_OUTOFMEMORY;
}
w->own().budget = x2w_budget::committed(device_of(self), resource, props->Type);
w->own().budget = x2w_budget::committed(device_of(self), resource, props->Type,
slot == 127 ? x2w_budget::upload_slot27 : x2w_budget::upload_other);
w->own().title_memory = title_memory;
retire_set_class(w, *props, flags, copy, title_memory);
note_resource(w, desc, info.SizeInBytes != ~0ull ? info.SizeInBytes : 0);
Expand Down Expand Up @@ -8743,7 +8745,7 @@ void report_budget(ID3D12CommandQueue* queue)
sample(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, local);
sample(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, nonlocal);
const auto counts = x2w_budget::snapshot();
char text[640]{};
char text[2048]{};
std::size_t used = 0;
for (int i = 0; i < x2w_budget::category_count; ++i) {
const auto& active = counts.live[i];
Expand All @@ -8752,6 +8754,13 @@ void report_budget(ID3D12CommandQueue* queue)
active.bytes, active.objects, held.bytes, held.objects);
if (n < 0 || static_cast<std::size_t>(n) >= sizeof(text) - used) break;
used += n;
// The upload total stays where it is. The creator columns that follow it add up to that total.
if (i == x2w_budget::upload) {
const int extra = x2w_budget::append_upload_creator_fields(text + used, sizeof(text) - used,
counts.upload_live, counts.upload_retained);
if (extra < 0) break;
used += static_cast<std::size_t>(extra);
}
}
// System commit and the physical-page pool behind it: a run that ends on a commit limit (error 1455) shows
// whether the pool (sections, slots) or the resources above grew (#1199).
Expand Down Expand Up @@ -9426,6 +9435,12 @@ extern "C" __declspec(dllexport) BOOL x2w_d3d12_budget_snapshot(x2w_budget::Snap
return TRUE;
}

// The slot 86 texture-map upload, without a mesh bind. The budget fixture charges one object this way.
extern "C" __declspec(dllexport) HRESULT x2w_budget_mesh86_upload_for_test(ID3D12Device* device, ID3D12Resource** out)
{
return create_mesh86_map_upload(device, 256, out);
}

// Called by the XG stand-in after it filled texture memory at a title address.
extern "C" __declspec(dllexport) void x2w_d3d12_texture_written(void* base, unsigned long long bytes)
{
Expand Down
3 changes: 2 additions & 1 deletion src/startup_stubs/linear_buffer_backing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,8 @@ class LinearBuffers {
nullptr, IID_PPV_ARGS(&staging->buffer));
staging->bytes = size;
// The pool's staging buffers live for the process: counted as upload memory (X2W_D3D12_BUDGET).
if (SUCCEEDED(hr)) x2w_budget::committed(internal_device_, staging->buffer, D3D12_HEAP_TYPE_UPLOAD);
if (SUCCEEDED(hr)) x2w_budget::committed(internal_device_, staging->buffer, D3D12_HEAP_TYPE_UPLOAD,
x2w_budget::upload_linear);
void* mapped = nullptr;
const D3D12_RANGE none{0, 0};
if (SUCCEEDED(hr)) hr = staging->buffer->Map(0, &none, &mapped);
Expand Down
2 changes: 1 addition & 1 deletion src/startup_stubs/list_upload_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inline HRESULT make_page(ID3D12Device* device, UINT64 bytes, Page& page, UploadF
if (failure) *failure = {"CreateCommittedResource", hr, bytes};
return hr;
}
x2w_budget::committed(device, page.resource.Get(), D3D12_HEAP_TYPE_UPLOAD);
x2w_budget::committed(device, page.resource.Get(), D3D12_HEAP_TYPE_UPLOAD, x2w_budget::upload_slot148);
D3D12_RANGE no_reads{};
void* mapped = nullptr;
hr = page.resource->Map(0, &no_reads, &mapped);
Expand Down
29 changes: 22 additions & 7 deletions src/startup_stubs/mesh86_cache.inl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,24 @@ ID3D12PipelineState* try_cached_mesh86(const D3D12_PIPELINE_STATE_STREAM_DESC& d
}
} // namespace

// The slot 86 texture-map upload. bind_mesh86_texture_map uses it, and the budget fixture calls it
// through x2w_budget_mesh86_upload_for_test.
HRESULT create_mesh86_map_upload(ID3D12Device* device, UINT64 map_bytes, ID3D12Resource** out)
{
if (out) *out = nullptr;
if (!out || !device || !map_bytes) return E_INVALIDARG;
const D3D12_HEAP_PROPERTIES upload{D3D12_HEAP_TYPE_UPLOAD};
const D3D12_RESOURCE_DESC buffer{D3D12_RESOURCE_DIMENSION_BUFFER, 0, map_bytes, 1, 1, 1, DXGI_FORMAT_UNKNOWN,
{1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_NONE};
ID3D12Resource* created = nullptr;
const HRESULT hr = device->CreateCommittedResource(&upload, D3D12_HEAP_FLAG_NONE, &buffer,
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&created));
if (FAILED(hr)) return hr;
x2w_budget::committed(device, created, D3D12_HEAP_TYPE_UPLOAD, x2w_budget::upload_mesh86);
*out = created;
return S_OK;
}

const char* bind_mesh86_texture_map(Wrapper* self, Pass& pass, ID3D12GraphicsCommandList* list) try
{
const auto& pso = pass.indirect_graphics;
Expand Down Expand Up @@ -493,14 +511,11 @@ const char* bind_mesh86_texture_map(Wrapper* self, Pass& pass, ID3D12GraphicsCom
physical.push_back({texture, view});
}
const UINT64 map_bytes = UINT64{records.size()} * sizeof(records.front());
const D3D12_HEAP_PROPERTIES upload{D3D12_HEAP_TYPE_UPLOAD};
const D3D12_RESOURCE_DESC buffer{D3D12_RESOURCE_DIMENSION_BUFFER, 0, map_bytes, 1, 1, 1, DXGI_FORMAT_UNKNOWN,
{1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_NONE};
x2w_startup::ComPtr<ID3D12Resource> map;
if (FAILED(device->CreateCommittedResource(&upload, D3D12_HEAP_FLAG_NONE, &buffer,
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&map))))
ID3D12Resource* created = nullptr;
if (FAILED(create_mesh86_map_upload(device, map_bytes, &created)))
return "slot86 Texture1D slot map allocation failed";
x2w_budget::committed(device, map.Get(), D3D12_HEAP_TYPE_UPLOAD);
x2w_startup::ComPtr<ID3D12Resource> map;
map.Attach(created);
void* mapped = nullptr;
const D3D12_RANGE empty{0, 0};
if (FAILED(map->Map(0, &empty, &mapped))) return "slot86 Texture1D slot map upload failed";
Expand Down
Loading
Loading