Skip to content

D3D12.X: forget a released resource in the console heap's resource map - #3032

Open
Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:d3d12x-forget-released-res
Open

Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:d3d12x-forget-released-res

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The console heap's resource map (RES in console_heap.rs) is filled only when XCL_TRACE_FRAME or XCL_DUMP_TARGETS is set, and nothing removed an entry when the resource was released. Later lookups by address could find a released resource and call GetDesc on a dead pointer. res_release now forgets the resource when its last reference goes, next to title_textures::forget.

This revision: rebased onto main b10cc4c6. One conflict, in real.rs's res_release against #2436: forget_resource now runs after #2436's park_recyclable block, still inside n == 0 and before late_release::hold. In the earlier rebase onto 765b2c5b, the conflicts in console_heap.rs and in real.rs's res_release were resolved by keeping both sides.

What is in it

  • crates/xcl/src/hle/d3d12x/console_heap.rs: a public forget_resource and the test a_released_resource_is_forgotten_by_the_resource_map
  • crates/xcl/src/hle/d3d12x/real.rs: the call in res_release when the count reaches 0, and the release test the_last_release_drops_entries_before_the_object_goes extended to check that the last Release removes the resource from the map (RES is pub(super) for it)

Tested

  • RTX 4090, driver 621.40, i9-13900K, Windows 11 Pro 10.0.26300, stable MSVC Rust (rustc 1.100.0 (0ef1bc386 2026-11-09)), debug build for the suite, release builds for the smoke runs.
  • On main b10cc4c6 (head 273cce7a). cargo test --workspace --no-fail-fast -- --test-threads=4 after cargo build --workspace (debug) on 273cce7a: 2607 passed, 2 failed, 49 ignored, 27 SKIPPED. The 2 failures are two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (two test targets), which is intermittent: it passed in two other runs on this head and in one on main b10cc4c6; this diff does not touch the driver cache.
  • SKIPPED (27, as on main): no wave64 (21), per-lane f16/f32 cases refused by the per-lane form (3), no heap windows (2), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Developer Mode is required) (1).
  • The new test fails when forget_resource does not remove the entry (left: Some(..), right: None)
  • The extended release test fails with the forget_resource call in res_release removed ("the released resource is still in the resource map") and passes with it.

Regression run

The same retail title for 60 s on both sides, scripts/smoke.ps1 on clean trees, release builds, XCL_PREPARE=0 and XCL_PRESS_AT=16:A on both sides, RTX 4090 (driver 621.40).

main (6bfb5c51):

xcl-smoke v1
commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 17826 MB

This PR's head (273cce7a):

xcl-smoke v1
commit: 273cce7a519056021acd8a031c0ec88217722239
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1693 (PresentX 1693)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 18486 MB

The PR's run got 105.1 % of main's frames and 103.7 % of its peak commit.

Not tested

  • The fix only changes behaviour with XCL_TRACE_FRAME or XCL_DUMP_TARGETS set; the smoke runs do not set them, so they check for regressions only.
  • AMD, release build.

AI use

  • Claude Code, Claude Opus 5.5: found the bug, wrote the fix, the test and this description, ran the tests and the smoke pair.
  • An earlier revision: Claude Code, Claude Opus 5.5 rebased the commit onto main e429936c and ran the suite and the smoke pair on that head.
  • The previous revision: Claude Code with Claude Opus 5.5 (the main session) did the rebase onto main 765b2c5b and the conflict resolution, ran the suite and the smoke pair through subagents, and updated this description. A Claude Opus 5.5 reviewer agent checked the rebase (range-diff and the conflict resolutions).
  • This revision (onto main b10cc4c6): Claude Code, Claude Opus 5.5: rebased the branch, resolved the conflicts, updated this description; Claude Sonnet 5.5 subagents ran the tests and the smoke runs; a Claude Opus 5.5 reviewer agent checked the rebase (range-diff and the conflict resolution).
  • The review fix on 273cce7a: Claude Code, Claude Opus 5.5 (main session) orchestrated it and updated this description; a Claude Sonnet 5.5 subagent wrote the test change; subagents ran the suite and the smoke pair.

@Pipodi
Pipodi marked this pull request as ready for review November 27, 2026 17:42
@Anon64

Anon64 commented Nov 27, 2026

Copy link
Copy Markdown

RTX 3060 12 GB, retail title, 300 s: no regression. This PR's head 7f463397 against main 2c717a04, one run each, release, warm caches, XCL_ACTIVITY=1 XCL_NETWORK=0, 8 preparation threads, A pressed every 4 s from 20 s.

Both exit 0x0 with no device removals or crashes. Frames: 2 199 against 2 234 on main. Peak commit: 38 171 MB against 38 242 MB. Peak local video memory: 18 924 MB against 18 893 MB. Neither run gets past world load on this card in 300 s, and I didn't measure the resource map's size. This is a regression check only.

Regression run

main:

xcl-smoke v1
commit: 2c717a043c8488938179fca81da4bb9e7913a358
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 2234 (PresentX 2234)
presents per 2 s (last 3): 6 6 5
device removals: 0
crashes: 0
peak commit: 38242 MB

this PR:

xcl-smoke v1
commit: 7f463397dc8ee66914bb185c25fa1e86f926093a
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 2199 (PresentX 2199)
presents per 2 s (last 3): 5 6 5
device removals: 0
crashes: 0
peak commit: 38171 MB

RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200.

AI use: Claude Code (Claude Opus 5.5) built both commits, ran the title and wrote this report.

@Pipodi
Pipodi force-pushed the d3d12x-forget-released-res branch from 7f46339 to bc20fd9 Compare November 28, 2026 06:27
@Pipodi
Pipodi force-pushed the d3d12x-forget-released-res branch from bc20fd9 to ae7e5bc Compare November 28, 2026 22:17
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 28, 2026
@Pipodi
Pipodi force-pushed the d3d12x-forget-released-res branch from ae7e5bc to 1bebee0 Compare November 29, 2026 03:13
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 1bebee0

No open or merged PR makes the same change; #292 cleans up the separate real::resource_at cache of views by address, not console_heap::RES. No problems found in the diff: res_release now drops the dead pointer from the diagnostics-only slot map, and the test checks both entries naming it go while another stays.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 1bebee0
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+32). A released resource is now removed from the console heap's resource map at its true last reference (real.rs ~2519). Before, a later trace or capture could call GetDesc on the freed pointer (bind.rs ~4454, ~4553). Findings: (1) The test doesn't cover the fix. a_released_resource_is_forgotten_by_the_resource_map (console_heap.rs ~2864) calls forget_resource directly; deleting the line in real.rs that matters still passes it. A test that releases through the hook would pin it. (2) Each release scans the whole map (retain, ~1347). That only happens while the map is filled (XCL_TRACE_FRAME, XCL_DUMP_TARGETS, and also XCL_CAPTURE_FRAME, which the description doesn't list), but it can be slow when resources stream (unverified). (3) resource_at can still return a pointer just before another thread forgets it. Late release, on by default, keeps the object alive meanwhile; with XCL_LATE_RELEASE=0 the window is open (unverified). Fine: the hook runs while the object is still alive, so a new resource at the same address can't be confused with it, and the lock is a leaf. #292 cleans a different map. No smoke run: the map is empty unless tracing or capture is on.
performance: no smoke run (the default path doesn't reach this change); not measured. Only reached while the resource map is filled (XCL_TRACE_FRAME, XCL_DUMP_TARGETS, XCL_CAPTURE_FRAME); a default run does nothing new.
verdict: safe to merge (a test that releases through the hook would pin the fix; today's test passes without the real.rs line)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
The console heap's RES map (view slot address -> ID3D12Resource) is filled
by note_resource and nothing removed an entry when the resource was
destroyed. A trace or target dump that later read the slot (GetDesc in
bind.rs) was handed a dead pointer. RES is only filled with
XCL_TRACE_FRAME / XCL_DUMP_TARGETS, so nothing changes without them (one
lock per release when the map was never made).

forget_resource drops every entry naming the resource; res_release calls
it in its n == 0 block next to title_textures::forget. The unit test fails
without the retain (resource_at still returns the dead pointer). The release-hook test
(the_last_release_drops_entries_before_the_object_goes) also fills RES and
checks that res_release forgets the resource at its last reference; it fails
with the real.rs call removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Pipodi
Pipodi force-pushed the d3d12x-forget-released-res branch from 1bebee0 to 273cce7 Compare December 1, 2026 19:13
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@Pipodi

Pipodi commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, you are right: the test called forget_resource directly and passed without the real.rs line.

I extended the_last_release_drops_entries_before_the_object_goes (the existing test that drives res_release on a fake resource): it now puts the resource in console_heap::RES under one view slot (and a live resource under another), checks the entry is still there after the non-last Release, and checks after the last Release that resource_at no longer names the released resource while the other stays. RES became pub(super) for this. With the forget_resource call in res_release removed, the test fails ("the released resource is still in the resource map"); with it, it passes. The direct forget_resource test is kept.

On your point 2: the scan per release only happens while the map exists, and XCL_CAPTURE_FRAME fills it too; I did not measure it. On 3: agreed, no change.

Claude Code (Claude Sonnet 5.5) assisted with the change and this reply.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up review (head 273cce7, since 1bebee0, diff read, not a merge-check):

  • The test did not cover the fix: fixed. the_last_release_drops_entries_before_the_object_goes (real.rs ~11936-11951) now fills RES and releases through res_release, checking the entry stays while another reference is held, is gone after the last Release, and that another resource's entry stays. Without the forget_resource call (~2519) it fails.
  • Each release scans the whole map: still open, acceptable. forget_resource (console_heap.rs ~1347) still runs retain over all of RES on every last release, only while the map is filled. The description says that is only with XCL_TRACE_FRAME / XCL_DUMP_TARGETS, but note_resource (~1320) also fills it under XCL_CAPTURE_FRAME.
  • resource_at can return a pointer just before another thread forgets it: still open, much smaller than before. With XCL_LATE_RELEASE=0 the object is freed right after the forget (real.rs ~2537), so a trace that got the pointer just before can still call GetDesc on it (bind.rs ~4503).

New: none.

Fine: the forget sits in the n == 0 block after #2436's park_recyclable block and before the object goes, so a new resource at the same address cannot lose its entries; the release test runs in its own child process, so its RES keys cannot collide with the unit test using the same addresses.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants