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
10 changes: 10 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17860,6 +17860,16 @@ needs support for consuming the resulting `srv ... buf root` manifest record.
ctest --test-dir out/build/release --no-tests=error -R "^startup_compute_global_load_(controls|warp|hardware)$" -V
```

## Opt-in lazy materialization of slot-133 read-only textures

With `X2W_D3D12_LAZY_TEXTURES=1` (Refs #2764, #2379, #1199), device slot 133 (`CreatePlacedResourceX`) defers desktop `CreateCommittedResource` for read-only textures (without `ALLOW_RENDER_TARGET`, `ALLOW_DEPTH_STENCIL`, or `ALLOW_UNORDERED_ACCESS`), keeping `Resource::GetDesc` and `slot 18` SRV tracking active via null placeholder descriptors until first real use (`CopyTextureRegion`, `CopyResource`, `ResolveSubresource`, `sampled_address_texture` in translated draws/dispatches, or non-title-backed `Map`). On materialization (under lock order `draw_lock -> lazy_texture_mutex -> note_lock -> retire_lock`), all tracked `slot 18` descriptors in `HeapInfo::shadow` (including `CopyDescriptorsSimple` copies) refresh in place; untouched textures retire their side records cleanly on guest `Release()`.

[`tests/startup_slot133_lazy_textures_check.cpp`](../tests/startup_slot133_lazy_textures_check.cpp) creates 16 `512x512` `R8G8B8A8_UNORM` read-only 2D textures (`16 MiB` total) over pre-committed guest memory, checks `x2w-budget` (`0/0` texture vs `16777216/16` in the `off` control), `PagefileUsage` delta (`20480` B on Microsoft Basic Render Driver and `40960` B on NVIDIA GeForce GTX 1660 SUPER vs `16936960` B and `16973824` B in the `off` controls), pre-materialization null SRV readback (`0`), selective `CopyTextureRegion` materialization (`2/16` with full `1 MiB` byte-for-byte readbacks), in-place SRV refresh sampled by a compute shader in both the original CPU heap and copied shader-visible heap, and clean retirement (`lazy_texture_count == 0`, budget back to `0/0` with `X2W_D3D12_RELEASE_RETIRED=1`). `debug1` cases skipped (`77`) without D3D12 SDK Layers installed on the host. Three fail-first mutants on `startup_slot133_lazy_textures_warp_debug0` failed as expected: skipping `CopyTextureRegion` materialization (`CopyTextureRegion refused: unknown_resource`, `1045504` mismatched bytes), eager materialization at slot 133 (`live=16777216/16`), and skipping SRV refresh (`texel(0,0)[0]=0.00000 expected=0.49020`).

```powershell
ctest --preset dev --no-tests=error -R '^startup_slot133_lazy_textures_' -V
```

## Design B descriptor retention and host commit on a 16 GiB system (#2379)

R0Y00's standing decision on #2379 keeps **design B** (#2679): a materialized descriptor and its copies own the
Expand Down
11 changes: 11 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ ctest --preset dev --no-tests=error -R '^startup_hook_(window|overlap)$' -V
| `X2W_D3D12_QUERY_SLOTS=1` | diagnostic, in render mode: binds command-list slots 28 to 30 to the confirmed `BeginQuery`, `EndQuery` and `ResolveQueryData` methods (see [Occlusion queries](#occlusion-queries)). The bindings remain diagnostic because the forwarding behavior is not a console runtime oracle. 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_LAZY_TEXTURES=1` | opt-in ([#2764](https://github.com/R0Y00/Xbox2Windows/issues/2764), [#2379](https://github.com/R0Y00/Xbox2Windows/issues/2379)): defers desktop `CreateCommittedResource` for read-only textures placed through device slot 133 (`CreatePlacedResourceX`, without `ALLOW_RENDER_TARGET`, `ALLOW_DEPTH_STENCIL` or `ALLOW_UNORDERED_ACCESS`) until first real copy, CPU-real access or translated draw/compute bind; `slot 18` SRVs receive a null placeholder descriptor and refresh in place when the texture materializes ([details](#lazy-slot-133-textures-opt-in)). Unset or `0`, textures commit immediately |
| `X2W_D3D12_RELEASE_RETIRED_VIEWS=1` | legacy diagnostic. Logs that clearing live slots is disabled and enables the existing retirement breakdown when base retirement and budgets are on ([details](#d3d12-resource-budget)) |
| `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_D3D12_VIEW_DEFAULTS=all` or `=off` | `all` is experimental: UAV, RTV and DSV descriptions with `ViewDimension` 0 also get the resource's default view, which drops their requested format and component mapping. `off` skips the measured SRV case too. Unset, only SRVs of typed non-depth textures get the default view ([details](#unknown-and-mismatched-view-dimensions)) |
Expand Down Expand Up @@ -1927,6 +1928,16 @@ FALSE without the switch, like `x2w_d3d12_budget_snapshot`. `startup_resource_re
runs the same steps without the switch. The hardware cases report 77 without a
physical adapter, and the debug-layer cases report 77 where the debug layer is not installed.

### Lazy slot 133 textures (opt-in)

With `X2W_D3D12_LAZY_TEXTURES=1`, read-only textures placed at a title address through device slot 133 (`CreatePlacedResourceX`, without `D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET`, `D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL`, or `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS`) defer their desktop `CreateCommittedResource` and `x2w_budget` ticket until first materialization. Until then:
- `Resource::GetDesc` (slot 10), `view_slot` validation, and capture metadata read the sanitized desktop `D3D12_RESOURCE_DESC` from the side record under `lazy_texture_mutex`, and `ID3D12Object::SetName` returns `S_OK` without materializing.
- `view_slot<18>` (SRV) creates a null `R8G8B8A8_UNORM` placeholder descriptor of the requested dimension and records the view normally in `HeapInfo::shadow` and `title_memory` (`X2WV` token) under `lazy_texture_mutex -> note_lock`.
- First real use (`CopyTextureRegion` subresource side, `CopyResource`, `ResolveSubresource`, `sampled_address_texture` in translated graphics/compute draws, `Resource::Map` without `title_memory`, or `WriteToSubresource`/`ReadFromSubresource`/`GetHeapProperties`) materializes the desktop resource once under `lazy_texture_mutex` (lock order `draw_lock -> lazy_texture_mutex -> note_lock -> retire_lock`), attaches its budget ticket, and refreshes every live tracked `slot 18` descriptor in `HeapInfo::shadow` (including `CopyDescriptors*` copies), revalidating heap membership and `HeapInfo::shadow` slot identity under `note_lock` so concurrent slot overwrites or heap retirement are not clobbered; `dispatch_translated` also records `retire_hold` so in-flight compute uses after final guest `Release()` stay live behind their fence.
- Untouched textures remain at 0 desktop bytes and clean up their side records and `resource_address_index` entries on final guest `Release()` (immediately when no live view remains, or via `drain_retired_resources()` under `X2W_D3D12_RELEASE_RETIRED=1` once tracked `slot 18` descriptor references and release-time fences clear).

Fixture: `startup_slot133_lazy_textures_{warp,hardware}_{debug0,debug1}` plus `noretire` and `off` controls (`tests/startup_slot133_lazy_textures_check.cpp`).

## D3D12 view allocation failure

A new view record goes into three containers: the record vector, the vector of
Expand Down
6 changes: 6 additions & 0 deletions src/startup_stubs/d3d12_capture.inl
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ void note_view(int slot, u64 resource, u64 counter, const void* desc, std::size_
view_census.missed += !ids_full && view_ids().bucket_count() != buckets_before;
}
}
if (slot == 18 && resource && materialized) {
if (Wrapper* res_w = as_wrapper(reinterpret_cast<const void*>(resource)); res_w && res_w->own().kind == resource_kind)
res_w->own().lazy_view_created = true;
}
if (std::uint32_t* slot_ptr = shadow_slot(dest_desktop)) {
const std::uint32_t prev = *slot_ptr;
*slot_ptr = record.id + 1;
Expand Down Expand Up @@ -680,6 +684,8 @@ void object(Wrapper* w)
if (w->own().real) {
header.desktop = static_cast<ID3D12Resource*>(w->own().real)->GetDesc();
if (header.desktop.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) header.gpu = static_cast<ID3D12Resource*>(w->own().real)->GetGPUVirtualAddress();
} else {
lazy_texture_desc(w, header.desktop);
}
chunk("RES ", &header, sizeof(header), nullptr, 0);
} else if (w->own().kind == descriptor_heap_kind) {
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_compute_dispatch.inl
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch&
: sampled_state(self, view.resource) | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
device_of(the_device)->CreateShaderResourceView(view.resource,
view.described ? &view.desc.srv : nullptr, dest);
if (view.wrapper && !view.wrapper->own().tiled_address_srv) retire_hold(self, view.wrapper);
continue;
}
if (i < inputs || i >= count) {
Expand Down
2 changes: 2 additions & 0 deletions src/startup_stubs/d3d12_memory_srv.inl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ Wrapper* publish_tiled_texture(Wrapper* device, u64 address, const D3D12_RESOURC
ID3D12Resource* sampled_address_texture(Wrapper* resource)
{
if (!resource || resource->own().kind != resource_kind) return nullptr;
if (resource->own().lazy_slot133_texture && !resource->own().real)
return materialize_lazy_texture(resource);
if (!resource->own().tiled_address_srv) return static_cast<ID3D12Resource*>(resource->own().real);
std::lock_guard lock(tiled_srv_mutex);
auto& sampled = tiled_srv_textures.at(resource);
Expand Down
Loading
Loading