Skip to content
Open
8 changes: 6 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check",
"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"
"native_compute_ir_dump", "native_pixel_ir_dump", "native_store_replay", "native_raw_buffer_view_check",
"startup_slot133_lazy_textures_check",
"startup_resource_retire",
"startup_resource_retire_views",
"startup_view_census"
]
},
{ "name": "release", "configurePreset": "release" },
Expand All @@ -50,7 +54,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|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run)$"
"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|startup_stage_package|startup_compute_packed_d16_x_uav_reference|native_.*_(ir|dxil|controls)|native_direct_mesh|startup_triage_run|startup_view_census_(warp|off_warp|vary_warp)|startup_resource_retire_((title|views)_)?warp_debug[01]|startup_resource_retire_off_warp)$"
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -18297,6 +18297,16 @@ consumes it: see [root buffer SRVs in the compute runtime manifest](experiments/
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
8 changes: 4 additions & 4 deletions docs/experiments/standin-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source itself is unchanged by this change; only tests are added.
covers the catalog builders against the real repository and against
synthetic temporary repository trees, then runs a self-contained
mutation harness over copy-mutations of the source in a temporary
sandbox. There are 470 cases and 6 mutations killed. Every refusal
sandbox. There are 472 cases and 6 mutations killed. Every refusal
pins the exact exception type and message substring, and every
temporary directory is removed in a `finally` block.

Expand All @@ -27,7 +27,7 @@ repeated `xmem.dll` is deduplicated):
| Module | Entries | Statuses | `ordinals_source` |
| --- | ---: | --- | --- |
| `xmem.dll` | 54 | 52 implemented, 2 unmeasured | `src/xmem_shim.def:3` |
| `d3d12_xs.dll` | 79 | 35 implemented, 44 unmeasured | None |
| `d3d12_xs.dll` | 81 | 35 implemented, 46 unmeasured | None |
| `acphal.dll` | 10 | 9 trap, 1 implemented | None |
| `chad.dll` | 5 | 5 trap | None |
| `xapu.dll` | 6 | 5 trap, 1 implemented | None |
Expand Down Expand Up @@ -63,7 +63,7 @@ Spot checks pin the reviewed behavior sources:
implemented with behavior `src/d3d12_xs_iids.cpp:1`;
`D3D12SerializeVersionedRootSignature` is implemented; the direct
export `x2w_d3d12_compute_census` is unmeasured with source
`src/startup_stubs/d3d12_compute_dispatch.inl:1744` (reached through
`src/startup_stubs/d3d12_compute_dispatch.inl:1745` (reached through
an `#include` in the device source).

The absent/unmeasured distinction is pinned both ways: an absent
Expand Down Expand Up @@ -213,7 +213,7 @@ Linux checks with:
/tmp/pe-env/bin/python -B tests/bidi_controls_check.py
```

Observed on Linux at this head: `standin_exports: 470 cases, 6/6
Observed on Linux at this head: `standin_exports: 472 cases, 6/6
mutations killed PASS`, and the form, docs-links and bidi checks
pass.

Expand Down
11 changes: 11 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,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_INLINE_DESCRIPTORS=1` | opt-in: leaves byte +0x18 of the guest device at 0, so the title writes constant buffer views and copies CBV/SRV/UAV descriptors itself instead of calling device slots 17 and 24 (sampler copies still arrive through slot 24); with `X2W_D3D12_RELEASE_RETIRED=1`, a retired resource is then freed once its release fences pass ([details](#d3d12-inline-descriptors)). Unset, nothing changes |
| `X2W_D3D12_NO_VISIBLE_HEAP_MIRROR=1` | negative control only: title view and sampler heaps created shader-visible get no CPU-only mirror. By default every view, sampler and copy the stand-in writes into a shader-visible range goes to the mirror first and is copied from there, and copies and `ClearUnorderedAccessView*` read a visible descriptor from the mirror, because desktop D3D12 reads those only from CPU-only heaps (debug layer message 654; a driver fault on a GTX 1060, #3558). The switch restores the direct read |
| `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)) |
Expand Down Expand Up @@ -2153,6 +2154,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 inline descriptors

The guest device ABI checks byte +0x18 of the device before it writes descriptors itself. The stand-in sets it
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 @@ -771,6 +771,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 @@ -973,6 +977,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 @@ -1618,6 +1618,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 && view.described) { // a typed buffer input
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