Skip to content

gpu: slot 133 texture replacement for #2773 - #3347

Open
romn4rch wants to merge 4 commits into
R0Y00:mainfrom
romn4rch:copilot/pr-2773-review-9bab5832
Open

romn4rch wants to merge 4 commits into
R0Y00:mainfrom
romn4rch:copilot/pr-2773-review-9bab5832

Conversation

@romn4rch

@romn4rch romn4rch commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

This is the replacement review PR for #2773, synchronized with upstream main at 24fcd0b5742abb2fcaba8066093d70829df956a3. The merge exposed a fixture-only mismatch: current main requires a native compiler-revision marker on synthetic compute manifests, so the slot-133 fixture now writes x2w::native_compute_output_revision. No slot-133 runtime behavior was changed to accommodate the test.

The original PR remains open and overlaps this revision. Please keep only one and mark #2773 as superseded if this replacement is selected; this PR does not close it.

Validation

  • cmake --build out\build\release --target startup_slot133_lazy_textures_check startup_stream_consumer d3d12_xs_shim — passed in Release.
  • ctest --test-dir out\build\release --no-tests=error -R '^(startup_resource_retire_title_(warp_debug0|off_warp|hardware_debug0|off_hardware)|startup_resource_retire_views_(warp_debug0|keep_warp|noretire_warp)|startup_slot133_lazy_textures_(warp_debug0|hardware_debug0|noretire_warp|off_warp)|startup_view_census_(warp|off_warp|vary_warp)|startup_view_alloc_(records|materialized|ids)(_control)?_warp|startup_title_heap_device_warp)$' --output-on-failure — 21/21 passed, including all slot-133 cases and the reported Release retirement cases.
  • $env:X2W_D3D12_PERMISSIVE='1'; $env:X2W_D3D12_DEBUG='1'; python -B tests\startup_sampler_heap_check.py wrapped out\build\release\d3d12_xs.dll warp — passed; descriptor-token copies matched.
  • $env:X2W_FXC='C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\fxc.exe'; python -B tests\startup_frame_copy_check.py out\build\release\startup_stream_consumer.exe warp — passed; 32 pixels exact, one refresh for changed contents and none for unchanged contents.
  • Hardware: startup_slot133_lazy_textures_hardware_debug0 and both resource-retirement hardware cases passed on NVIDIA GeForce RTX 3050 6GB Laptop GPU, driver 32.0.16.2140, Windows 10 Pro 26H2 build 26300.10075, debug layer off; tested commit 02182842cc3d0c7b5ebaec9c46077d9b6dfe8f23.
  • GitHub Actions run 46140793329 completed successfully: Windows, Linux Python, and gfx1013 fixture jobs passed; the opt-in /O2 job was skipped.

triggered02 and others added 4 commits November 26, 2026 13:48
# Conflicts:
#	docs/experiments.md
#	docs/startup-runtime.md
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@romn4rch romn4rch changed the title gpu: slot 133 texture review follow-up gpu: slot 133 texture replacement for #2773 Nov 28, 2026

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean opt-in lazy materialization of slot-133 read-only textures.

  • Defers desktop CreateCommittedResource until first copy, CPU-map, or translated draw bind.
  • Null placeholder SRV descriptors refresh in place on materialization, including CopyDescriptorsSimple copies.
  • Untouched textures retire cleanly at guest Release(); in-flight computes stay live via retire_hold.
  • Lock ordering (draw_lock -> lazy_texture_mutex -> note_lock -> retire_lock) and publication hook handle descriptor race windows.
  • Test fixture covers budget delta, selective materialization, SRV refresh with copies, prepare/overwrite/resume race, and Release-before-first-use dispatch_translated path.
  • Documentation updated in experiments.md and startup-runtime.md.

The approach is consistent with existing slot-133 and retired-resource patterns.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean opt-in lazy materialization of slot-133 read-only textures.

  • Defers desktop CreateCommittedResource until first copy, CPU-map, or translated draw bind.
  • Null placeholder SRV descriptors refresh in place on materialization, including CopyDescriptorsSimple copies.
  • Untouched textures retire cleanly at guest Release(); in-flight computes stay live via retire_hold.
  • Lock ordering (draw_lock -> lazy_texture_mutex -> note_lock -> retire_lock) and publication hook handle descriptor race windows.
  • Test fixture covers budget delta, selective materialization, SRV refresh with copies, prepare/overwrite/resume race, and Release-before-first-use dispatch_translated path.
  • Documentation updated in experiments.md and startup-runtime.md.

The approach is consistent with existing slot-133 and retired-resource patterns.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested on 0218284. Evidence: reading the diff, the head blobs and main 212d4b5, plus git merge-tree. Nothing was built or run; the race and the surviving mutations below are found by reading, not reproduced.

Blocking:

  • The Write/ReadFromSubresource/GetHeapProperties trigger is unreachable. forward_slot materializes under if constexpr (N == 12 || N == 13 || N == 14) (d3d12_xs_device.cpp:762-763), but build_tables installs resource slots 8-11 only (:8133-8136; :8137-8138 "Desktop Resource 12-14 ... are not installed until a call site confirms them") and enable_object forwards 3-6 (:7985-7988). docs/startup-runtime.md lists these three calls as materialization triggers. Fix: remove the branch and the doc entry, or install the slots with a test.
  • The CBV view record shrinks from 16 to 12 bytes (:5180 N == 17 ? 12; main :5267 N == 17 ? 16). It came in with 9bab583, is not in #2773 (7986f2a), is not gated by the switch and is not mentioned in the PR body. note_view hashes the stored bytes, so slot-17 views that differ only in bytes 12-15 now share one id, and every slot-17 record reports desc_bytes 12. The new fixture creates no slot-17 view. Fix: move it to its own PR with a test, or drop it.
  • resource_map materializes only when the resource has no guest memory pointer yet (:4878-4880), and the lazy path sets that pointer to the placement address (:5868). For a non-null address, Map returns that address and never materializes, same as the eager path (:5910). Both docs list Map as a trigger. Fix: drop it from the trigger lists, or say it applies to no slot-133 texture.

Refresh ordering (read from the code):

  • view_slot writes the desktop descriptor at :5383 and updates the shadow afterwards, in record_view -> note_view (:5389). materialize_lazy_texture runs its refresh after releasing lazy_texture_mutex (:6156), checks shadow[slot] == record_id under note_lock shared and writes T's SRV (:6190-6211). If another thread's desktop write for view X lands before that check and its note_view after it, the slot holds T while its record names X. The comment at :6188-6189 does not cover this, because the desktop write is outside note_lock.
  • copy_descriptor_run has the same window: CopyDescriptorsSimple at :5489, note_copy at :5490. refresh_copied_lazy_views then repairs the slot only if the copied record names a lazy texture (:5459-5461).
  • The 4b hook runs complete slot-24 and slot-18 calls (desktop write and shadow update) between the snapshot and the refresh, so it does not exercise this ordering.
  • Fix: do the desktop write and the shadow update under one lock in both paths, or have the refresh take a lock the writers hold across both steps.

Applies with the switch off; the off control returns after the creation checks (test :491-520) and reaches none of it:

  • forward_slot returns 0, S_OK, DXGI_ERROR_NOT_FOUND or E_FAIL for any wrapper with a null real (:760-771), on slots 3-6 of every kind. main dereferences it (:765).
  • record_translated_dispatch calls retire_hold for every non-tiled sampled input (d3d12_compute_dispatch.inl:798), which changes X2W_D3D12_RELEASE_RETIRED=1 for textures that are not lazy.
  • device_residency drops null entries and returns S_OK when none remain (:1417-1420).
  • Fix: gate these on the switch, or extend the off control to run them.

Error reporting: the eager path returns the CreateCommittedResource failure (:5902); the lazy path returns S_OK for any description (:5879-5880) and the failure shows only at first use. Worth a line in the docs.

Tests:

  • The pull_request job runs cmake --build --preset pr and ctest --preset pr (windows.yml:489-493). Neither the pr targets nor its test filter in CMakePresets.json include startup_slot133_lazy_textures_*, so run 46140793329 did not build or run the fixture. docs/experiments.md reports the debug1 cases skipped (77). Fix: add the target and the WARP cases to the pr preset.
  • The fixture uses one 2D R8G8B8A8_UNORM texture shape, 1 mip, with a described TEXTURE2D SRV. By reading, these changes would not fail it:
    • any edit to the resource-dimension branches of lazy_null_srv_desc (:5118-5137), reached only without a described dimension;
    • the packed-format lazy branch in view_slot (:5306-5308);
    • the UNKNOWN-dimension and short-record paths of create_lazy_srv (:5422-5433);
    • reverting the CBV change.

Rebase: git merge-tree --write-tree origin/main reports two conflicts, both with main's trace_compute_output_use lines: list_copy_buffer_region in list_copy.inl and resource_unmap in d3d12_xs_device.cpp. #2773 is still open at 7986f2a, an ancestor of this head.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of head 02182842 against main c04e0dd6. I read the diff, the head and main blobs and the git merge-tree result. Nothing was built or run.

This needs a rebase. git merge-tree --write-tree origin/main 02182842 exits 1 with conflicts in docs/startup-runtime.md, src/startup_stubs/d3d12_xs_device.cpp and src/startup_stubs/list_copy.inl. The docs conflict is new since the changes request. #3429 (X2W_D3D12_INLINE_DESCRIPTORS, opt-in) added its table row and section at the same place. #3429 also brings two semantic overlaps that git does not flag:

SHOULD

  1. retire_hold changed meaning on main. In 2130dcec (startup: opt-in inline descriptors (X2W_D3D12_INLINE_DESCRIPTORS) #3429 review) it returns bool. A null own().real now means the drain has claimed the object: it logs reads found their texture already freed; bound null and returns false, and the draw and compute callers bind null (if (texture && ... && !retire_hold(self, wrapper)) texture = nullptr;). A lazy slot-133 texture also has a null real until it materializes. The auto-merged d3d12_compute_dispatch.inl keeps both main's checked hold on the sampled-texture path and this PR's unchecked retire_hold(self, view.wrapper) in record_translated_dispatch. After the rebase, keep one hold per site, and make sure every hold of a lazy texture runs after materialize_lazy_texture. Otherwise a not-yet-used texture is bound null and reported as freed. A fixture case with X2W_D3D12_RELEASE_RETIRED=1, where the first use is a translated dispatch, would show it.
  2. The lazy-view refresh depends on slot 24, which X2W_D3D12_INLINE_DESCRIPTORS=1 turns off for CBV/SRV/UAV heaps. main's switch row says the title then "copies CBV/SRV/UAV descriptors itself instead of calling device slots 17 and 24". This PR refreshes copied placeholders only inside copy_descriptor_run, which is reached from device slots 23 and 24. A copy the title makes itself never reaches refresh_copied_lazy_views. Please state whether X2W_D3D12_LAZY_TEXTURES=1 may be combined with it. Then either refuse the combination at startup, or add a fixture case with both switches set.

MUST
3. Rebase onto current main, resolving the three conflicts and the two overlaps above.

I won't repeat the blocking points of the open changes request on this head, or the duplicate with #2773. Both still apply.

Held: conflicting, with a standing changes request.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants