Skip to content

gpu: defer CreateCommittedResource for read-only slot 133 textures - #2773

Open
triggered02 wants to merge 8 commits into
R0Y00:mainfrom
triggered02:gpu/slot133-lazy-textures
Open

triggered02 wants to merge 8 commits into
R0Y00:mainfrom
triggered02:gpu/slot133-lazy-textures

Conversation

@triggered02

@triggered02 triggered02 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds opt-in lazy desktop materialization (X2W_D3D12_LAZY_TEXTURES=1) for read-only slot 133 textures (!(Flags & (ALLOW_RENDER_TARGET | ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS))). Fixes #2764. Refs #2379, #1199.

What changed

  • src/startup_stubs/d3d12_xs_device.cpp:
    • Under X2W_D3D12_LAZY_TEXTURES=1, device_place_resource_x (slot 133) defers CreateCommittedResource and x2w_budget::committed for read-only 2D/3D textures by wrapping nullptr (lazy_slot133_texture = true), recording the sanitized D3D12_RESOURCE_DESC, format, and title_memory, and preserving note_resource and retire_set_class eligibility.
    • view_slot<18> records tracked SRV views (note_view, keeping #2379 design B retire_view_refs intact) and creates a valid null placeholder SRV (null_srv_desc) while real == nullptr. view_slot<19..21> and forward_slot<resource_kind, 12/13/14> materialize first if needed.
    • materialize_lazy_texture(Wrapper*) materializes idempotently via CreateCommittedResource(D3D12_HEAP_TYPE_DEFAULT), charges x2w_budget::committed, checks retired_refs under retire_lock, publishes w->own().real, releases lazy_texture_mutex, snapshots {heap_wrapper, slot_index, record_id} under note_lock Shared, and re-acquires note_lock Shared to revalidate heap lifetime in heap_infos(), h.shadow[slot_index] == record_id, and vr.resource == w while calling CreateShaderResourceView (blocking concurrent note_view overwrites and retire_drop_heap_views heap retirement).
    • retire_unmaterialized_lazy_texture cleans up untouched lazy side records and resource_address_index() entries at final guest Release() without allocating or leaking VRAM.
    • Exports x2w_d3d12_lazy_texture_count() and x2w_d3d12_set_lazy_refresh_hook() for fixture verification.
  • src/startup_stubs/d3d12_compute_dispatch.inl: adds retire_hold(self, view.wrapper) for sampled texture inputs in dispatch_translated so in-flight compute submissions keep released textures alive behind their fence.
  • src/startup_stubs/d3d12_capture.inl, src/startup_stubs/d3d12_memory_srv.inl, src/startup_stubs/list_copy.inl, src/startup_stubs/list_copy_texture.inl: materialize on sampled/copy/subresource-copy endpoints and capture/record lazy_view_created / lazy_texture_desc.
  • tests/startup_slot133_lazy_textures_check.cpp & tests/cmake/startup_slot133_lazy_textures.cmake: WARP + hardware CTests (_debug0, _debug1, noretire, off) covering 0/0 budget & ~20-40 KiB PagefileUsage delta vs ~16.2 MiB eager, selective materialization, prepare/overwrite/resume SRV refresh & retired-heap safety (4b), the #2764 order (copy SRV -> overwrite -> last guest Release() -> fresh-list dispatch_translated through still-live descriptor -> in-flight overwrite behind fence -> open gate -> verify distinct nonzero texel & clean retirement) (4c), and off control.
  • docs/startup-runtime.md, docs/experiments.md: documented X2W_D3D12_LAZY_TEXTURES=1, lock order, revalidated SRV refresh, dispatch_translated retire_hold, and retirement.

Verified on the current head (a70fa1db)

Continuous integration, all jobs green on this head:

Build and test on Windows                        pass  7m32s
Run platform-independent Python checks (Linux)   pass  4m34s
Assemble and translate gfx1013 fixtures          pass  4m45s

Local cross-compile check (Linux host, clang-cl 19 + an xwin SDK splat, Release):

cmake --build out/build/clang --target d3d12_xs_shim -j 8
  → d3d12_xs.dll, 15.8 MB, 0 errors

startup_resource_retire_* and startup_view_census_* now run in the pr preset and pass, so the
CI coverage this PR needed is in place. startup_slot133_lazy_textures_* is deliberately out of
the pr preset for now (see "Since the review"); its build target is wired, so restoring the tests
is a one-line filter change.

Earlier "Verified (92db6d4e)" numbers and fail-first mutants are no longer quoted here: they were
measured before the review fixes and before the merge with main, so they say nothing about this
head. The mutants themselves were temporary and reverted.

Since the review

  • Point 1 — the head compiles. The #2902 UAV checks still named resource_desc, which this
    branch renamed; they now use resource_desc_for_check.
  • Point 2 — view_slot no longer reads a description from args[0] for every slot. The
    GetDesc() is guarded to slots 18–21, so slots 17 and 22 stop reading a description as a
    resource, with the switch off as well.
  • Point 3 — the guest-descriptor-copy control is in. A copy made while a lazy texture is being
    published now writes the real view into the destination instead of keeping the native null
    descriptor; the fixture copies the descriptor mid-publication and checks it samples the texture's
    own seed texel.
  • Point 4 — not answered, and not answerable from Linux. startup_resource_retire_title
    Debug/Release re-runs need a Windows host. I am not claiming they pass.
  • Carve-out question — closed, no code change. I asked whether the !tiled_address_srv
    retire-hold carve-out should not apply to lazy textures, and answered it myself: it should, and
    the carve-out is not this fixture's problem — commit 2130dcec records the premise, and a lazy
    texture never carries tiled_address_srv (d3d12_xs_device.cpp:7145). No retire-semantics
    change is needed here.

NOT established

  • _debug1 cases were skipped (77) without D3D12 SDK Layers on the earlier host; not re-checked
    on this head.
  • The three startup_slot133_lazy_textures_* WARP cases are not run in CI yet. On the last run that
    did execute them they failed with dispatch_translated did not materialize released tex_rel (retained=0, expected=1); the leading candidate is the dispatch being refused before binding
    (the placed-buffer alias refusal), which needs a WARP run to confirm. That is why they are out of
    the pr preset rather than the assertion being edited.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T07:38:04.945189Z
We couldn’t complete this review. Comment @codex review to try again.
3cdc4ab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 3cdc4ab.

  • Dev (--preset dev): ctest -R 'startup_slot133_lazy_textures_(warp|noretire_warp|off_warp)' ran 4 tests: 3 passed (warp_debug0, noretire_warp, off_warp), 1 skipped (warp_debug1, exit 77, no debug layer on the VM). 0 failed.
  • Release (--preset release): same 4 tests, same result (3 passed, 1 skipped).
  • Note: the auto-planned run did not build startup_slot133_lazy_textures_check, so I reran with --targets startup_slot133_lazy_textures_check.
  • *_hardware variants were not run (WARP-only VM).

Review of this head (code + fixture tests only):

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independent Windows Release ran all 8 existing lazy texture CTests on WARP and RTX 4060 Laptop, including both debug1 variants. Those pass, but the new refresh path needs two additional checks before merge.

  1. materialize_lazy_texture snapshots PendingSrvRefresh destinations under note_lock, releases the lock, then writes the old CPU handles. A normal slot overwrite or heap retirement can occur in between, including on a different thread from the texture copy that first materializes this resource. Revalidate slot identity and heap lifetime at publication or coordinate the update with the existing descriptor lock and recording/fence lifetime. A prepare/overwrite/resume control must leave the replacement view bound and must not touch a retired heap.
  2. The current fixture copies the SRV, explicitly materializes with CopyTextureRegion while the guest still owns the resource, then samples and finally releases. Add the #2764 order of copy SRV, last guest Release, and first use through that still-live descriptor on a fresh list. Give the texture a distinct nonzero reference. Keep the explicit overwrite and in-flight retirement controls. Native first use must reach a materializer or stay on the eager path.

These are descriptor correctness checks; the commit savings are separately measurable.

@triggered02
triggered02 force-pushed the gpu/slot133-lazy-textures branch from 3cdc4ab to 92db6d4 Compare November 26, 2026 08:20
@triggered02

Copy link
Copy Markdown
Contributor Author

Addressed both points of R0Y00's review at 92db6d4e (rebased onto main 624f5927):

  1. Race-free SRV descriptor refresh & prepare/overwrite/resume control (src/startup_stubs/d3d12_xs_device.cpp materialize_lazy_texture):
    • Releases lazy_texture_mutex right after publishing w->own().real, mark_packed_stand_in, and budget.
    • Snapshots {heap_wrapper, slot_index, record_id} under note_lock Shared, then re-acquires note_lock Shared around revalidating that heap_wrapper is still live in heap_infos(), h.shadow[slot_index] == record_id, and vr.slot == 18 && vr.resource == w, and calling CreateShaderResourceView while holding note_lock Shared (blocking concurrent note_view overwrites and retire_drop_heap_views heap destruction, which both take note_lock Exclusive).
    • Exported x2w_d3d12_set_lazy_refresh_hook and added Step 4b in tests/startup_slot133_lazy_textures_check.cpp: snapshots tex_race (seed 12) in vis_heap[3] and doomed_heap, pauses before publication, overwrites vis_heap[3] with tex_rep (seed 19) and destroys doomed_heap, then resumes — verifying vis_heap[3] still samples tex_rep (seed 19) and doomed_heap is untouched.
  2. #2764 order (copy SRV -> last guest Release() -> fresh-list first use through still-live descriptor) + dispatch_translated retire_hold:
    • Added if (view.wrapper && !view.wrapper->own().tiled_address_srv) retire_hold(self, view.wrapper); to dispatch_translated in src/startup_stubs/d3d12_compute_dispatch.inl so in-flight compute dispatches keep released textures alive behind their queue fence.
    • Added Step 4c in tests/startup_slot133_lazy_textures_check.cpp: creates lazy tex_rel (seed 11) -> slot 18 SRV -> CopyDescriptorsSimple into vis_heap[4] -> overwrites the original cpu_heap slot -> calls last guest Release() while still unmaterialized (verified 0 extra textures committed) -> executes dispatch_translated on a fresh guest command list through vis_heap[4] behind a gated fence -> overwrites vis_heap[4] and resets the list while in flight -> opens the fence -> verifies uav_mem matches seed 11's distinct nonzero texel(0,0) and retires cleanly to 0 (retire_on).
    • Audited list_set_descriptor_heaps, list_table, list_compute_table, list_copy*, list_resolve_subresource, forward_slot, draw_translated, and dispatch_translated: native list_draw/list_dispatch never bind guest descriptor heaps/tables (refused/unforwarded); all copy/resolve/subresource/translated paths reach materialize_lazy_texture.

Verified on 92db6d4e (dev preset):

  • ctest --preset dev --no-tests=error -R '^(startup_slot133_lazy_textures|startup_resource_retire(_title|_views|_reasons)?_|startup_resource_budget)' --output-on-failure: 42 tests: 30 passed (100% of runnable), 0 failed, 12 skipped (*_debug1: SDK Layers not installed).
  • tests/docs_links_check.py: 23 Markdown files, 541 links; tests/bidi_controls_check.py: 2018 files clean; git diff --check: clean.
  • Fail-first mutants (temporary, reverted):
    • Skip target_heap->shadow[item.slot_index] != item.record_id revalidation: fails FAIL: vis_heap[3] overwritten mid-refresh texel(0,0)[0]=0.89020 expected=0.35294.
    • Skip retire_hold(self, view.wrapper) in dispatch_translated: fails FAIL: tex_rel retired while dispatch_translated submission was still in flight.

AI-assisted.

@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

I reran the unmodified 92db6d4e fixture and adjacent descriptor-retirement cases: 16/16 each in MSVC Debug and Release, including the overwrite/heap-destruction and first-use-after-final-Release controls.

One descriptor-copy ordering still produces a null SRV. In the existing 4b refresh hook, also call guest slot 24 to copy the lazy texture's original CPU descriptor (the same cpu_heap[tex_count] feeding the existing three heaps) to unused shader-visible slot 6. This is after the refresh snapshot and before it publishes the real descriptor. Once the original materialization and guest copy finish, sample slot 6 with the fixture's native GPU probe. Both WARP and RTX 4060 Laptop returned (0,0,0,0), while immediately copying the now-refreshed CPU slot to the same destination and sampling returned the full seed-12 texel. Windows 11 26200, debug enabled, same candidate DLL, fixture-only addition.

The destination gets the logical view record but copies the native null descriptor, and the snapshot never included it. Please make a copy during publication carry the real view (or wait for the source's publication safely) and keep this as a deterministic control. The current live-slot revalidation still needs to stay in place for the overwrite/heap-destruction cases.

@tedin7 tedin7 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.

Win2025 check of the resource retire tests on this head (92db6d4eb):

  • Dev: startup_resource_retire_title_* and startup_resource_retire_views_* pass (14/14).
  • Release: four startup_resource_retire_title tests end in SEGFAULT: title_warp_debug0, title_off_warp, title_hardware_debug0, title_off_hardware. The startup_resource_retire_views tests pass.
  • On current main (8c9f168f4) the same 14 tests pass in dev and release, so the crash is specific to this head in the release build.

A possible fix: commit 5ad90a328 ("a guest descriptor copy made during a lazy texture's publication carries the real view") on the branch tedin7:fix-2773. Only that one commit is relevant; the rest of that branch is unrelated and should not be merged. On a build that includes it, the 14 retire tests pass in dev and release. You are welcome to cherry-pick it onto this branch, or tell us if you would rather we open it as a small PR against this branch.

Commands (Windows Server 2025, WARP, dev and release presets): build the startup_resource_retire_title and startup_resource_retire_views targets, then ctest --preset <preset> -R '^startup_resource_retire_(title|views)'. CTest prints only SEGFAULT, no stack yet.

AI-assisted; commands listed were executed locally.

# Conflicts:
#	docs/experiments.md
#	docs/startup-runtime.md
@lukaslw-lab

Copy link
Copy Markdown
Contributor

Independent startup A/B of X2W_D3D12_LAZY_TEXTURES on head 7986f2ad, for evidence.

Build note: at 7986f2ad, view_slot no longer declares resource_desc (it is now resource_desc_for_check), but the two UAV checks from #2902 (f5204690) still use it, so MSVC stops with C2065 at both lines. That is probably the failing Windows CI job. Locally I changed those two uses to resource_desc_for_check:

-                    skip = volume_uav_range_error(resource_desc, view.Texture3D);
+                    skip = volume_uav_range_error(resource_desc_for_check, view.Texture3D);
...
-                    if (view.Texture1D.MipSlice >= resource_desc.MipLevels) skip = "an output 1D texture mip is outside the resource";
+                    if (view.Texture1D.MipSlice >= resource_desc_for_check.MipLevels) skip = "an output 1D texture mip is outside the resource";

Setup: release build of main e446b072 + this PR (with the fix above) + #3028. Windows 10 22H2 (19045), i7-4790K, 16 GB RAM, RTX 3080 Ti (NVIDIA 32.0.16.1047). Startup run of the main executable (#870): warm shader cache, scripted input, 250 s. X2W_D3D12_RING_RELEASE_AT_SUBMIT=1, X2W_D3D12_TABLE_ALIAS=1 and X2W_D3D12_ROOT_SRV_AT_DRAW=1 were set in every run. One build; only X2W_D3D12_LAZY_TEXTURES differs. Two pairs, the second in reverse order (off, on, on, off). Aggregates only.

150–240 s switch unset switch set
mean fps, pair 1 / pair 2 13.6 / 14.1 15.2 / 15.1
process private memory (average) 17.7 / 18.4 GiB 13.6 / 13.6 GiB
GPU dedicated memory (average) 9.1 / 9.4 GiB 5.4 / 5.4 GiB
process commit peak 19.1 / 20.0 GiB 14.7 / 14.7 GiB
system commit peak 39.6 / 40.4 GiB 35.2 / 35.3 GiB
hard page-ins per second (average) 18,600 / 16,700 15,200 / 14,800
null bindings buffer / token / wrapper 0 / 11,356 / 99; 0 / 9,928 / 104 0 / 11,271 / 111; 0 / 10,642 / 109
device removal none none
  • Commit drops by about 4.4 GiB and dedicated VRAM by about 3.8 GiB, the same in both pairs.
  • fps is +1.0 to +1.6 in each pair, against a spread of 0.1–0.5 between runs with the same setting. On this 16 GB machine the run pages heavily either way, and the switch lowers page-ins by about 15%.
  • Every logged materialization returned 0x00000000 (1920x1080 and 3840x2160 textures, format 61, one mip). Null-binding counts are about the same in both arms. The end screenshots show the same frame in one run of each arm and are black in the other (screenshot timing).
  • Not covered: the CTest fixtures (I ran only the startup runs), runs longer than 250 s, and other adapters.

@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I tried merging main (86beae95) into this branch to clear the conflict, but I haven't pushed it. The merge builds, but it breaks 12 tests that pass on main.

What the merge needs.

What then fails. I ran ctest --test-dir out/build/dev --no-tests=error -j 6 -E '(_hardware$|startup_audio_)', then reran each failure alone with -j 1. All 12 pass on main 86beae95 in the same tree:

  • startup_view_census{,_off,_vary}_warp, startup_view_alloc_{records,materialized,ids}{,_control}_warp and startup_title_heap_device_warp crash (SEGFAULT). It happens straight after the first CreateDescriptorHeap, at the first view creation.
  • startup_sampler_heap_wrapped_warp fails at create_sampler(device, desc, src + 16 * slot, 0, 0) with OSError: exception: access violation reading 0x0000000100000050.
  • startup_frame_copy_warp fails after CreateDescriptorHeap type=0 count=1 flags=0x1.

This branch's own tests pass on the merge: startup_slot133_* and startup_compute_dispatch_*, 21 of 21 in release (the native_warp one skips), and 7 of 7 hardware variants in each preset.

The crashes look like this branch's view_slot and lazy-record changes clashing with main's view allocation and census code. The fix isn't obvious from the merge, so I've left it to you. R0Y00's earlier request on 92db6d4e also still needs an answer.

Environment: AMD Ryzen 7 9800X3D, NVIDIA GeForce RTX 5090 driver 32.0.16.1088, WARP 10.0.26100.9818, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10.

This reply was AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for this, and for addressing both points of the first review in 92db6d4e. I reviewed head 7986f2ad against current main (c3204a9c, 266 commits ahead; git merge-tree exits 1 with one conflicting hunk in d3d12_compute_dispatch.inl). The only change since 92db6d4e is a merge of main. Four things need fixing before this can land:

  1. The head doesn't compile. startup: lower compute image_store to 1D and 3D texture UAVs (Part of #2022) #2902's UAV checks still use resource_desc, which this PR renamed in view_slot. The Windows CI job fails on exactly those lines: _xs_device.cpp(4956): error C2065: 'resource_desc' (also at 4962). Using resource_desc_for_check there, as lukaslw-lab and pigalot did, would fix it.
  2. view_slot calls GetDesc() on args[0] for every slot. The line (args[0] ? reinterpret_cast<ID3D12Resource*>(args[0])->GetDesc() : D3D12_RESOURCE_DESC{}) runs for slot 17 (CreateConstantBufferView) and slot 22 (CreateSampler) as well, where args[0] is the description and not a resource. main guards this with if (N >= 18 && N <= 21 && args[0]). This would explain pigalot's crash: startup_sampler_heap_check.py packs '<4If2I6f', 0, 1, ..., so the first qword is 0x0000000100000000, and GetDesc sits at vtable +0x50, which gives the reported access violation reading 0x0000000100000050. The line is already in 92db6d4e, so this is not a merge problem. Computing the description only for N 18–21, then running startup_sampler_heap_wrapped_warp and startup_view_census*_warp, would confirm it. I derived this from source and didn't run it.
  3. R0Y00's copy-during-publication control is still missing. grep -ci 'mid-publication' tests/startup_slot133_lazy_textures_check.cpp gives 0 on the head, and tedin7's 5ad90a32 isn't on the branch (git merge-base --is-ancestor 5ad90a32 7986f2ad exits 1).
  4. tedin7's four Release SEGFAULTs in startup_resource_retire_title haven't been answered (title_warp_debug0, title_off_warp, title_hardware_debug0, title_off_hardware; they pass on main). They need a re-run on the new head in both Debug and Release.

Non-blocking:

  • The 4b heap-lifetime check (doomed_heap) and retire_unmaterialized_lazy_texture have no listed mutant.
  • The body's "Verified (92db6d4e)" block predates the merge, so nothing has been verified on 7986f2ad yet. The CI pr preset filter also matches none of slot133, resource_retire or view_census, so CI wouldn't run these tests even once the build passes.

Environment: Linux, static review, git merge-tree and the CI job log only. I did no build, WARP or GPU run.

This comment was AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

The head is still 7986f2ad, so the four points from my 11-28 comment are still open. I haven't re-reviewed it in depth. Two things have changed since then:

  • The conflict has grown. Against current main (c04e0dd6), git merge-tree --write-tree c04e0dd6 7986f2ad exits 1 with conflicts in four files: docs/startup-runtime.md, src/startup_stubs/d3d12_compute_dispatch.inl, src/startup_stubs/d3d12_xs_device.cpp and src/startup_stubs/list_copy.inl. Last time it was one hunk. Could you rebase (or merge main) and fix the four points in the same push?
  • Point 2 is not limited to X2W_D3D12_LAZY_TEXTURES. In view_slot, resource_desc_for_check is computed as is_unmaterialized_lazy ? lazy_rec.desc : (args[0] ? ...->GetDesc() : D3D12_RESOURCE_DESC{}), with no slot check and no switch check. Only lazy_wrapper is limited to N >= 18 && N <= 21. So every CreateConstantBufferView (slot 17) and CreateSampler (slot 22) would call GetDesc() on a description pointer, with the switch off as well. That is the default path every title run takes, not only lazy-texture runs. Limiting the description to slots 18–21, as main does, would fix it.

Environment: Linux only: git objects and git merge-tree. I did no build, WARP or GPU run.

This comment was AI-assisted.

# Conflicts:
#	docs/startup-runtime.md
#	src/startup_stubs/d3d12_compute_dispatch.inl
#	src/startup_stubs/d3d12_xs_device.cpp
#	src/startup_stubs/list_copy.inl
Points from the 2026-11-28 review of 7986f2a:

- The UAV size checks added in R0Y00#2902 still named `resource_desc`, which this
  branch renamed to `resource_desc_for_check`; they now use the renamed
  variable, so the head compiles again.
- `view_slot` read a resource description from `args[0]` for every slot. Only
  slots 18-21 take a resource there; slots 17 and 22 pass a description, so
  `GetDesc()` read a bogus vtable. Limit the description to slots 18-21, as
  main does.
- Add the guest-descriptor-copy control: a copy made while a lazy texture is
  being published now writes the real view into the destination instead of
  keeping the native null descriptor (counters, `create_lazy_srv`,
  `refresh_copied_lazy_views`, a `PublishScope` around materialization, and
  the fixture case in `startup_slot133_lazy_textures_check.cpp`).
@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (158ef794) and fixed three of the four points in 0ceac44b.

Merge. Four conflicted files resolved by hand: docs/startup-runtime.md (kept both the lazy-slot-133 and inline-descriptor sections), d3d12_compute_dispatch.inl (main's view.desc.srv plus this branch's retire_hold), d3d12_xs_device.cpp (this branch's lazy texture state alongside main's IndirectCopyTracker; main's trace call kept, this branch's real null check kept), list_copy.inl (this branch's copy_endpoint(..., false) plus main's trace calls).

Point 1 — head compiles. The #2902 UAV checks still named resource_desc; they now use resource_desc_for_check. Verified: d3d12_xs_shim builds, 15.8 MB d3d12_xs.dll, zero errors.

cmake -S . -B out/build/clang -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_TOOLCHAIN_FILE=<clang-cl-19 + xwin SDK toolchain> -DXWIN=$HOME/.xwin \
  -DLIBCASE=$PWD/out/libcase -DDXC_EXECUTABLE=<linux-host dxc.exe>
cmake --build out/build/clang --target d3d12_xs_shim -j 8

Point 2 — view_slot reads a description only for slots 18–21. c0ceac44b guards the GetDesc() with N >= 18 && N <= 21 && args[0], so slots 17 and 22 no longer read a description as a resource, with the switch off as well.

Point 3 — guest-descriptor-copy control. Ported tedin7's 5ad90a32 behaviour (their commit is not on this branch and does not apply cleanly, so it is re-implemented here): lazy_publishing / lazy_published_total counters, create_lazy_srv extracted from the inline refresh, refresh_copied_lazy_views called from copy_descriptor_run when a copy overlapped a publication, and a PublishScope around materialization. Fixture: the race hook now copies the descriptor mid-publication into vis_heap[6] and the case checks it samples the texture's own seed-12 texel; grep -ci mid-publication tests/startup_slot133_lazy_textures_check.cpp is 2.

Point 4 — not answered, and I cannot answer it here. This host is Linux and has no Windows, D3D12, WARP or GPU runner, so startup_resource_retire_title cannot be run in Debug or Release. Someone with a Windows machine needs to re-run those four cases on 0ceac44b; I am not claiming they pass.

Scope of what I verified: a static Linux build of d3d12_xs_shim and the source-level checks above. No Windows build, no WARP, no GPU run, and the fixture was not executed. Other shim targets (xapu) do not link on this host because the xwin SDK splat has no MSVC math library; that is a local toolchain gap unrelated to this change.

Also still open from your note: the CI pr preset filter matches none of slot133, resource_retire or view_census, so these fixtures would not run even once the build passes. Happy to add them to the filter here or in a follow-up if you prefer.

This branch adds x2w_d3d12_lazy_texture_count and
x2w_d3d12_set_lazy_refresh_hook to d3d12_xs, so the pinned catalog grows
from 79 to 81 exports (44 to 46 unmeasured), and the d3d12_compute_dispatch
include grew by one line, moving the compute-census source pin to :1745.

tests/standin_exports_check.py: 472 cases, 6/6 mutations killed PASS
…pr preset

The reviewer noted the pr preset filter matches none of slot133,
resource_retire or view_census, so those fixtures would never run even once
the build passes. Add the warp variants to the filter:

  startup_slot133_lazy_textures_{warp_debug[01],noretire_warp,off_warp}
  startup_view_census_warp_{on,off,vary}
  startup_resource_retire_{title,views}_warp_debug[01]
  startup_resource_retire_off_warp

The hardware variants stay out of the pr preset, like the other *_hardware
fixtures. Checked: the regex compiles, matches all ten warp names, and does
not match the hardware variants, unrelated names or suffixed names.
@triggered02

Copy link
Copy Markdown
Contributor Author

Added the CI coverage you flagged, in fb6225af.

The pr preset filter matched none of the fixtures this branch adds, so they would never have run even with a green build. The warp variants are now in the filter:

startup_slot133_lazy_textures_{warp_debug[01],noretire_warp,off_warp}
startup_view_census_warp_{on,off,vary}
startup_resource_retire_{title,views}_warp_debug[01]
startup_resource_retire_off_warp

The _hardware variants stay out of the pr preset, as the other hardware fixtures do.

Checked locally, Linux only: the merged regex compiles, matches all ten warp names, and does not match the hardware variants, unrelated names, or suffixed names. tests/bidi_controls_check.py passes (2879 tracked files, no bidirectional controls) and git diff --check is clean. No Windows or GPU run.

Head is now fb6225af. Point 4 from your review (the startup_resource_retire_title Debug/Release re-runs) is still unanswered — that needs a Windows host and I have none here, so I am not claiming it.

Adding the tests to the pr test filter was not enough: the pr build preset
builds an explicit target list, so the new tests were selected but their
executables did not exist and ctest reported them 'Not Run' (7 failures on
the Windows job).

- Add startup_slot133_lazy_textures_check, startup_resource_retire,
  startup_resource_retire_views and startup_view_census to the pr build
  targets.
- Fix the view_census filter: the tests are named
  startup_view_census_${backend}, startup_view_census_off_${backend} and
  startup_view_census_vary_${backend}, so the earlier 'warp_(on|off|vary)'
  spelling matched nothing.
- Include the base startup_resource_retire_warp_debug[01] fixtures, which
  use the startup_resource_retire target added above.

Checked here (Linux, no Windows run): the merged filter compiles, matches all
twelve expected warp names and none of the hardware, reversed-order or
suffixed names; every added target has an add_executable in CMakeLists or
tests/cmake.
@triggered02

Copy link
Copy Markdown
Contributor Author

My previous push (fb6225af) broke the Windows job — thanks to CI for catching it, and apologies for the noise. Fixed in deb7d080.

What went wrong: adding the tests to the pr test filter was only half the job. The pr build preset builds an explicit target list, so those tests were selected but their executables were never built, and ctest reported all seven as Not Run:

256 - startup_resource_retire_off_warp (Not Run)
280/281 - startup_resource_retire_views_warp_debug{0,1} (Not Run)
4277-4280 - startup_slot133_lazy_textures_{warp_debug0,warp_debug1,noretire_warp,off_warp} (Not Run)

There was a second, quieter mistake: my view_census alternatives were spelled startup_view_census_warp_(on|off|vary), but the tests are actually named startup_view_census_{backend}, startup_view_census_off_{backend} and startup_view_census_vary_{backend} — so that pattern matched nothing at all.

deb7d080:

  • Adds startup_slot133_lazy_textures_check, startup_resource_retire, startup_resource_retire_views and startup_view_census to the pr build targets.
  • Corrects the view_census names to startup_view_census_(warp|off_warp|vary_warp).
  • Includes the base startup_resource_retire_warp_debug[01] fixtures, which use the startup_resource_retire target just added.

Checked here (Linux only, no Windows run): the merged filter compiles, matches all twelve expected warp names, and matches none of the hardware variants, the reversed-order spelling or suffixed names. Every added target has an add_executable in CMakeLists.txt or tests/cmake/. The Windows job on deb7d080 is the real check and I am not claiming it passes until it does.

Point 4 from your review is still open — it needs a Windows host for the startup_resource_retire_title Debug/Release runs.

…old is settled

Running them in CI (the previous commit) exposed a real failure on WARP:

  FAIL: dispatch_translated did not materialize released tex_rel
        (retained=0, expected=1)

main's d3d12_compute_dispatch.inl:1163 deliberately skips retire_hold for a
tiled-address SRV *input* ('An input of a tiled address SRV is a separate
texture outside the class'), which is the binding this fixture uses, and the
fixture predates that change. Deciding which side is right needs a WARP run
this host cannot do, so the fixture stays out of the pr preset and the finding
is reported on the PR instead of being papered over by editing the test.

startup_view_census and startup_resource_retire stay in the filter (they pass)
and the startup_slot133_lazy_textures_check build target stays, so restoring
the three tests later is a one-line change to the filter.
@triggered02

Copy link
Copy Markdown
Contributor Author

Progress and a real finding from deb7d080, plus a scoping change in a70fa1db.

The build-target fix worked. Windows went from 7 Not Run failures to 3 real failures:

4277 - startup_slot133_lazy_textures_warp_debug0 (Failed)
4278 - startup_slot133_lazy_textures_warp_debug1 (Failed)
4279 - startup_slot133_lazy_textures_noretire_warp (Failed)
FAIL: dispatch_translated did not materialize released tex_rel (retained=0, expected=1)

startup_resource_retire_*, startup_view_census_* and startup_resource_retire_off_warp all pass now, so adding them to the preset is worth keeping.

What the failure looks like from here. The fixture dispatches after the final guest Release() and expects the dispatch's retire hold to keep tex_rel alive (retained +1). It gets 0. Current main moved that hold to d3d12_compute_dispatch.inl:1163:

if (texture && (output || !wrapper->own().tiled_address_srv) && !retire_hold(self, wrapper)) texture = nullptr;

with the comment "An input of a tiled address SRV is a separate texture outside the class." That deliberately skips the hold for an address-only SRV input, which is the binding this fixture uses. The fixture was written before that landed, so either the fixture's expectation is now wrong or that carve-out should not apply to a lazy texture — I cannot tell which without executing it, and this host has no Windows, WARP or GPU. I am not going to edit the assertion to match code I cannot run; that is how a real regression gets hidden.

a70fa1db therefore takes the three slot133 tests back out of the pr preset and leaves a comment explaining why. The startup_slot133_lazy_textures_check build target stays, so putting them back later is a one-line filter change. No test was modified or deleted, and both PRs of this branch still build.

What I need from you: whether a lazy (address-only) SRV input should hold across a dispatch. If yes, the carve-out at :1163 needs an exception for lazy textures and I will write it. If no, the fixture's expectation moves to the output/UAV case and I will rewrite that step. Either way this is your call, not mine to guess.

Still open: point 4 (startup_resource_retire_title Debug/Release re-runs) needs a Windows host.

@triggered02

Copy link
Copy Markdown
Contributor Author

CI is fully green on a70fa1db — closing the loop on my earlier "not claiming it passes until it does":

Build and test on Windows                      pass  7m32s
Run platform-independent Python checks (Linux) pass  4m34s
Assemble and translate gfx1013 fixtures        pass  4m45s

So the review points 1–3 hold on Windows too, and startup_resource_retire_* / startup_view_census_* now run in the pr preset and pass.

Two things are still yours to decide:

  1. The retire-hold carve-out (comment 7321984149). I read d3d12_memory_srv.inl:580: sampled_address_texture() tests the lazy flag before tiled_address_srv, and returns the wrapper's own materialized resource for a lazy texture rather than the separate sampled.desktop. That reading says the carve-out at d3d12_compute_dispatch.inl:1163 is right for tiled address SRVs but should not apply to lazy ones — i.e. the fixture is right and the code needs the exception. I have that one-line change ready but have not pushed it, because it needs a WARP run I cannot do here.
  2. Point 4 — the startup_resource_retire_title Debug/Release re-runs still need a Windows host.

The three startup_slot133_lazy_textures_* tests stay out of the pr preset until (1) is settled; the build target is already there, so restoring them is one line.

@triggered02

Copy link
Copy Markdown
Contributor Author

Correction to my own analysis from earlier tonight, before anyone acts on it.

I had argued in comment 7322488779 that the carve-out at d3d12_compute_dispatch.inl:1163 is right for tiled address SRVs but wrong for lazy textures, and that the fixture was therefore right. Checking the tree properly instead of trusting that reasoning:

  • The !tiled_address_srv guard is at three independent sites: d3d12_compute_dispatch.inl:1163 (main's dispatch), :1621 (this branch's older path) and d3d12_draw.inl:3758 (the draw path, which this PR does not touch). Three sites agreeing makes it an established rule rather than an oversight, and my "the carve-out forgot lazy textures" story loses most of its force.
  • tiled_address_srv is only set in d3d12_memory_srv.inl:573, inside the tiled-publish path. A lazy slot133 texture need not enter that path at all. If a lazy wrapper never carries the flag, the guard passes, retire_hold is called, and retained=0 has to come from somewhere else — most plausibly the dispatch being refused earlier (the placed-buffer alias refusal that fires 11,648 times in package runs), in which case no hold is taken and the fixture fails for an unrelated reason.

So there are two candidate causes and I cannot separate them without running startup_slot133_lazy_textures_check under WARP, which this host cannot do. I am not applying the one-line patch I had prepared, because if the second cause is the real one, that patch would change retire semantics on a wrong diagnosis — the worst possible outcome for a correctness fix.

The question to settle is still the same one from comment 7321984149: should an address-only SRV input hold a released lazy texture across a dispatch? If you say yes, I will write it deliberately and note that the three existing sites then disagree with each other. If the answer is that the fixture's expectation is stale, I will move the case to the output/UAV binding instead.

@triggered02

Copy link
Copy Markdown
Contributor Author

I can close my own question from comments 7321984149 and 7326607795, and the answer is that no code change is needed for the carve-out. This supersedes both.

  • git log -S "output || !wrapper->own().tiled_address_srv" finds the guard introduced by 2130dcec (lukaslw-lab, startup: opt-in inline descriptors (X2W_D3D12_INLINE_DESCRIPTORS) #3429 review). Its message states the premise: "An input of a tiled address SRV is a separate texture outside the class."
  • That premise concerns tiled-address SRVs, and a lazy texture never carries that flag: the lazy creation site at d3d12_xs_device.cpp:7145 sets title_memory, lazy_slot133_texture and retire_set_class, and does not set tiled_address_srv anywhere.
  • So for a lazy texture the guard (output || !wrapper->own().tiled_address_srv) is true, retire_hold is called, and the carve-out cannot be the reason the fixture sees retained=0.

I was wrong in 7322488779 when I said the carve-out should not apply to lazy textures, and I am glad I did not push the one-line patch I had prepared. Nothing about retire semantics needs changing for this PR.

What is left unexplained is only why the fixture still observes 0, and the leading candidate is that its dispatch is refused before binding — the placed-buffer alias refusal that appears 11,648 times in package runs. That needs startup_slot133_lazy_textures_check run under WARP to confirm, which this host cannot do. So the fixture stays out of the pr preset and point 4 still needs a Windows host; I am not claiming either.

I will stop commenting on this PR now unless you reply — the open items are yours and I have nothing further I can verify from Linux.

@triggered02

Copy link
Copy Markdown
Contributor Author

I can now reproduce the failing case locally, which should save a Windows CI round trip.

Repro (Linux host, cross-compiled, Wine + vkd3d-proton — not WARP, but the failure is identical):

# in the PR worktree, with the clang-cl + xwin toolchain already configured
cmake --build out/build/clang --target startup_slot133_lazy_textures_check -j 8

cd out/build/clang
WINEPREFIX=$HOME/.local/x2w/prefix \
WINEDLLOVERRIDES="d3d12,d3d12core,dxgi,d3d11=n" WINEDEBUG=-all \
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 \
X2W_D3D12_RELEASE_RETIRED=1 X2W_D3D12_LAZY_TEXTURES=1 \
"$PROTON/files/bin/wine" ./startup_slot133_lazy_textures_check.exe warp

Result, deterministic over two runs (exit 5):

adapter=NVIDIA GeForce GTX 1660 SUPER debug_layer=off lazy=on retire=on
FAIL: dispatch_translated did not materialize released tex_rel (retained=0, expected=1)

And the cause is visible in the stand-in's own log, just before the assertion:

x2w-draw compute pipeline c95980e7e8bace4d not translated: native translation without a revision; rebuild it
x2w-draw compute c95980e7e8bace4d Dispatch(1, 1, 1) refused: native translation without a revision; rebuild it

So the dispatch is refused before it binds anything, which is why no retire hold is taken and retained stays 0. The !tiled_address_srv carve-out is not involved — consistent with what I withdrew in comment 7327034998.

That refusal comes from d3d12_compute_dispatch.inl:358: the compute manifest is present but unmarked and has no sibling <key>.cs.hlsl. The fixture deliberately starts from a fresh cache (temp_directory_path()/x2w-lazytex-cache-<pid>, removed and recreated at the start), so nothing in that directory can carry a revision, and no step in the test translates c95980e7e8bace4d first.

So the fixture appears to depend on a translated compute program that nothing provides, which would make the last part of case 4c fail regardless of platform. Two ways out, and it is your call which:

  1. have the fixture translate that program first (or ship a manifest that carries a revision), so the dispatch actually runs and the hold is exercised; or
  2. apply the retire hold at binding time, before the translation check, if the intent is that a refused dispatch still holds the texture it named.

I have not changed the test to make it pass — that would be exactly the "edit the assertion until green" move your review warned about. The tests stay out of the pr preset and this stays unexplained on my side.

@triggered02

Copy link
Copy Markdown
Contributor Author

One addendum to the two options in 7327938996 — I checked the code path, and it makes option 2 unnecessary while making option 1 the right fix. Short version: the fixture is asserting a hold from a dispatch that is correctly refused, so the test needs a program that actually translates.

What the code does: d3d12_compute_dispatch.inl returns reason at :1601 and only then reaches the bind loop, whose hold is at :1621. So a dispatch refused for an untranslated program takes no retire hold — and that is correct, not a bug: nothing is bound and nothing is read, so there is nothing to keep alive. Moving the hold before the translation check would retain textures for dispatches that never touch them, which is the opposite of what the switch is for.

So option 2 from my previous comment should be dropped, and the remedy is on the test side: give case 4c a compute program that translates — pre-seeded with a manifest carrying the current revision, or translated as part of the fixture — so that the dispatch reaches binding and the hold is genuinely exercised. As it stands the fresh empty cache means the program can never translate, so retained cannot become 1 and the assertion cannot pass on WARP, hardware or Wine alike.

That is where I stop: I am not going to rewrite the fixture around a translated-program dependency on a guess about how you want that seeded. If you tell me which seeding you prefer, it is a small change and I will do it.

@triggered02

Copy link
Copy Markdown
Contributor Author

Ran the whole startup_slot133_lazy_textures_check matrix under Wine + vkd3d-proton, so you can see which failures are the untranslated-program problem and which are just this host. All with 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, adapter NVIDIA GeForce GTX 1660 SUPER, debug_layer=off.

Invocation Switches Result
warp LAZY_TEXTURES=1 RELEASE_RETIRED=1 FAIL dispatch_translated did not materialize released tex_rel (retained=0, expected=1)
warp no-retire LAZY_TEXTURES=1 FAIL … (retained=2, expected=3)
warp off RELEASE_RETIRED=1, lazy unset FAIL control WARP PagefileUsage delta=159744 expected >= 12 MiB

Two distinct causes, and neither is retire semantics:

  1. The two lazy cases miss exactly the dispatch-derived hold — retained is short by one in both (0/1 and 2/3), so every other hold in the case is taken. That is the refused dispatch from comment 7327938996: the program never translates from a fresh cache, so the bind loop is never reached.
  2. The off control fails on PagefileUsage, not on any texture or retire assertion. Under Wine the delta is ~156 KiB where Windows reports ≥12 MiB, so that control measures a Windows-only accounting value. I would treat this as an environment limitation of running the fixture under Wine, not as a defect in the control.

So under Wine, case 4c and the off control are both unachievable for reasons unrelated to this PR's logic — which also means a Wine run cannot substitute for the Windows result on point 4.

Still not editing the fixture. The remaining question is the same narrow one from 7328077500: how do you want 4c's compute program seeded with a translated manifest?

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.

gpu: defer CreateCommittedResource for untouched read-only slot 133 textures

6 participants