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
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,26 @@ foreach(backend IN ITEMS warp hardware)
ENVIRONMENT "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=0")
endforeach()

# X2W_D3D12_RETIRE_REASONS=1 names why released resources still hold their desktop object (needs RELEASE_RETIRED and
# BUDGET). `off` (no RETIRE_REASONS) and `no-retire` (no RELEASE_RETIRED) are negative controls: the line must stay empty.
add_executable(startup_resource_retire_reasons tests/startup_resource_retire_reasons.cpp)
target_include_directories(startup_resource_retire_reasons PRIVATE src)
target_compile_features(startup_resource_retire_reasons PRIVATE cxx_std_17)
target_link_libraries(startup_resource_retire_reasons PRIVATE d3d12_xs_shim d3d12 dxgi)
foreach(backend IN ITEMS warp hardware)
set(reasons_base "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=0")
add_test(NAME startup_resource_retire_reasons_${backend} COMMAND startup_resource_retire_reasons ${backend})
set_tests_properties(startup_resource_retire_reasons_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${reasons_base};X2W_D3D12_RELEASE_RETIRED=1;X2W_D3D12_RETIRE_REASONS=1")
add_test(NAME startup_resource_retire_reasons_off_${backend} COMMAND startup_resource_retire_reasons ${backend} off)
set_tests_properties(startup_resource_retire_reasons_off_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${reasons_base};X2W_D3D12_RELEASE_RETIRED=1")
add_test(NAME startup_resource_retire_reasons_no_retire_${backend} COMMAND startup_resource_retire_reasons ${backend} no-retire)
set_tests_properties(startup_resource_retire_reasons_no_retire_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${reasons_base};X2W_D3D12_RETIRE_REASONS=1")
endforeach()


add_executable(startup_resource_retire_title tests/startup_resource_retire_title.cpp)
target_include_directories(startup_resource_retire_title PRIVATE src)
target_compile_features(startup_resource_retire_title PRIVATE cxx_std_17)
Expand All @@ -1362,6 +1382,28 @@ foreach(backend IN ITEMS warp hardware)
ENVIRONMENT "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_RESOURCE_INDEX_CHECK=1;X2W_D3D12_DEBUG=0")
endforeach()

# X2W_D3D12_RELEASE_RETIRED_VIEWS=1 frees a released class texture that only tracked slot-18 descriptor slots keep alive by
# replacing those slots with null descriptors. `keep` is the negative control (views switch off, or retire switch off).
add_executable(startup_resource_retire_views tests/startup_resource_retire_views.cpp)
target_include_directories(startup_resource_retire_views PRIVATE src)
target_compile_features(startup_resource_retire_views PRIVATE cxx_std_17)
target_link_libraries(startup_resource_retire_views PRIVATE d3d12_xs_shim d3d12 dxgi d3dcompiler)
foreach(backend IN ITEMS warp hardware)
foreach(debug IN ITEMS 0 1)
set(retire_views_env "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=${debug}")
add_test(NAME startup_resource_retire_views_${backend}_debug${debug} COMMAND startup_resource_retire_views ${backend})
set_tests_properties(startup_resource_retire_views_${backend}_debug${debug} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${retire_views_env};X2W_D3D12_RELEASE_RETIRED=1;X2W_D3D12_RELEASE_RETIRED_VIEWS=1")
endforeach()
set(retire_views_keep "X2W_D3D12_BUDGET=1;X2W_D3D12_PERMISSIVE=1;X2W_D3D12_LIST_NOOP=1;X2W_D3D12_RENDER=1;X2W_D3D12_DEBUG=0")
add_test(NAME startup_resource_retire_views_keep_${backend} COMMAND startup_resource_retire_views ${backend} keep)
set_tests_properties(startup_resource_retire_views_keep_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${retire_views_keep};X2W_D3D12_RELEASE_RETIRED=1")
add_test(NAME startup_resource_retire_views_noretire_${backend} COMMAND startup_resource_retire_views ${backend} keep)
set_tests_properties(startup_resource_retire_views_noretire_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "${retire_views_keep};X2W_D3D12_RELEASE_RETIRED_VIEWS=1")
endforeach()

# GPU writes the dispatch record that the desktop command processor consumes (Refs #1412).
add_executable(startup_compute_binding_trace tests/startup_compute_binding_trace.cpp)
target_compile_features(startup_compute_binding_trace PRIVATE cxx_std_20)
Expand Down
43 changes: 43 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,8 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `X2W_D3D12_QUERY_SLOTS=1` | diagnostic, in render mode: binds command-list slots 28 to 30 to the hypothesised occlusion query methods (see [Occlusion queries](#occlusion-queries)). Unset, the three slots stay no-ops |
| `X2W_D3D12_BUDGET=1` | adds [video memory budget and allocation counts](#d3d12-resource-budget) to the D3D12 heartbeat |
| `X2W_D3D12_RELEASE_RETIRED=1` | opt-in, effective with `X2W_D3D12_RENDER=1` only (the list handlers that record holds exist only there): frees the desktop object of a released committed 2D texture of one narrow class once no recorded list, submission or release-time fence refers to it ([details](#d3d12-resource-budget)). Unset, nothing changes |
| `X2W_D3D12_RELEASE_RETIRED_VIEWS=1` | opt-in, effective only together with `X2W_D3D12_RELEASE_RETIRED=1`: a released class texture that only tracked slot-18 descriptor slots keep alive (the title never overwrites them) is freed once those slots are replaced by null descriptors ([details](#d3d12-resource-budget)). Unset, nothing changes |
| `X2W_D3D12_RETIRE_REASONS=1` | diagnostic only, effective with `X2W_D3D12_RELEASE_RETIRED=1` and `X2W_D3D12_BUDGET=1`: adds one `x2w-retire held:` line to the heartbeat that counts final-released resources whose desktop object is still alive, by reason ([details](#d3d12-resource-budget)). Unset, nothing is recorded |
| `X2W_DRAW_NULL_IDENTITY=1` | null descriptors read as identity values instead of zero |
| `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) |
Expand Down Expand Up @@ -1413,6 +1415,47 @@ unordered-access flag, and live in a default heap without heap flags:
reusing the same title address or desktop pointer does not skip uploads or
resolve a retired wrapper.

`X2W_D3D12_RELEASE_RETIRED_VIEWS=1` (only with `X2W_D3D12_RELEASE_RETIRED=1`) ends the
`view-refs` retention. Once a released class texture's release-time fences have passed,
the drain (a try-lock, never blocking) replaces every tracked slot-18 descriptor slot
that names it, in every heap and so every `CopyDescriptors*` copy, by a null SRV of the
same dimension: the shadow entry and its ref are dropped, the desktop descriptor is
rewritten with `CreateShaderResourceView(nullptr, ...)`, the view records naming the
resource lose it, and the view token in title descriptor memory is cleared when it
still carries that id. A draw that reads the slot afterwards binds a null texture
(zeros). The texture is then freed by the normal rules: lists and submissions that hold
it through `retire_hold` keep the desktop object until the recording is dropped or the
submission's fence passes. No recorded list or submission reads a title heap's SRV
descriptor (translated draws build their own descriptors from the tokens at draw time
and hold what they sample), so the rewrite cannot reach GPU work. A slot that cannot be
rewritten keeps its ref and the texture stays retained. Not covered: a title thread
that writes the same slot at the moment of the drain, and a guest that uses the
resource after its final release (unsupported with the switch, as before).
`startup_resource_retire_views_*` reads the desktop descriptors back through a compute
probe; the `keep` and `noretire` cases are the negative controls.

`X2W_D3D12_RETIRE_REASONS=1` (with `X2W_D3D12_RELEASE_RETIRED=1` and
`X2W_D3D12_BUDGET=1`) adds a diagnostic line to the heartbeat. It counts every
resource whose final guest Release happened and whose desktop object is still
alive, once, by the first cause that applies. Format: `reason=count/bytes(oldest Nf)`,
bytes from the budget ticket, `oldest` in frames since the final Release:
- `view-refs`: a tracked slot 18 descriptor still names it;
`view-refs-in-visible-heap` is the part with a descriptor in a shader-visible heap.
- `list-hold`, `flight`: a closed or recording list, or a submission, holds a
desktop reference.
- `queued-waiting-fence`: queued, the release-time fence of a queue has not passed;
`drain-pending`: ready, the drain has not run yet; `unqueued`: no queue could take its marker.
- `left-class:<view|view-copy|residency|present|hold-missed>`: it was in the class and the first use named left it.
- `never-class:<buffer|dimension|msaa|rt-ds-uav|heap-type|heap-flags|title-memory|aliased|reserved|slot>`: it was
never in the class (`slot`: created by a path that does not classify).
- `other`: none of the above.
`total` is the sum; `unattributed` is the budget's retained count and bytes minus
`total` (backing heaps, upload and readback objects, and anything created outside the wrappers).
Wrappers without a desktop object (tiled address textures) are not counted. A
released resource that only a list or submission keeps alive after its wrapper
let go is matched by its desktop pointer. Without the switches nothing is
recorded and no line is built.

Every other resource (buffers, placed buffers, reserved resources, render/depth/UAV
targets, and slot 127 `__XMemAllocationHooks__` textures) keeps the lifetime
described above. A resource leaves the class for good when a UAV/RTV/DSV view is
Expand Down
4 changes: 2 additions & 2 deletions src/startup_stubs/d3d12_capture.inl
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void note_view(int slot, u64 resource, u64 counter, const void* desc, std::size_
retire_release_view_ref(reinterpret_cast<const void*>(view_records()[prev - 1].resource));
}
} else if (slot == 18 && resource) {
retire_leave_class(reinterpret_cast<const void*>(resource));
retire_leave_class(reinterpret_cast<const void*>(resource), RetireLeft::view);
}
ReleaseSRWLockExclusive(&note_lock);
const std::size_t token_bytes = slot == 22 ? x2w_startup::title_sampler_stride : 32u;
Expand Down Expand Up @@ -367,7 +367,7 @@ void note_copy(u64 dest_title, u64 src_title, u64 dest_desktop, u64 src_desktop,
const std::uint32_t src_id = from[i];
if (src_id && src_id - 1 < view_records().size() &&
view_records()[src_id - 1].slot == 18 && view_materialized()[src_id - 1])
retire_leave_class(reinterpret_cast<const void*>(view_records()[src_id - 1].resource));
retire_leave_class(reinterpret_cast<const void*>(view_records()[src_id - 1].resource), RetireLeft::view_copy);
}
}
ReleaseSRWLockExclusive(&note_lock);
Expand Down
Loading
Loading