Skip to content

gpu: a released view's resource stays alive in its copy-goes test - #63

Closed
fogydes wants to merge 1 commit into
mainfrom
gpu/released-view-stays-alive-in-test
Closed

fogydes wants to merge 1 commit into
mainfrom
gpu/released-view-stays-alive-in-test

Conversation

@fogydes

@fogydes fogydes commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

What and why

Part of #54. resource::tests::a_released_targets_copy_goes_when_its_memory_is_used_again failed now and then in the parallel run. The cause is in the test, not a production race.

The test makes a placed view (shown), releases its target, then makes a texture at the same address. That puts shown in the process-wide release queue, to be freed 2 s later, and the test then checks assert_ne!(now, shown), a raw pointer compare. Five other tests drain that whole queue with release_waiting(Duration::ZERO). If one runs between the queueing and the compare, shown is freed, and the next resource made by texture_at can get the same heap address, so now == shown and the assert fails. Production only drains after the 2 s grace, so it is unaffected.

The test now takes its own reference on shown and gives it back at the end, so the address can't be reused, and now != shown checks what it was meant to. No sleep or retry.

Area

gpu: the test module of resource.rs only (+11 lines).

Tests

  • cargo xtask pr-check passes on my machine

  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

  • Evidence: a natural failure in run 32 of 40 parallel runs (left != right, both the same pointer). Draining the queue on purpose right before texture_at reproduced it in 1 of 3 runs of the test alone.

  • Parallel XTP_TEST_ADAPTER=warp cargo test -p xtp-gpu --locked --lib: before, this test failed 1 of 40 runs; after, 0 of 40; with the forced drain kept in, 0 of 15.

  • The debug-layer suite passes, and the full WARP pr-check passes.

  • Not fixed here, also seen while looping: draw::tests::textures_the_hashing_budget_left_out_come_first_next failed in 4 of 80 parallel runs. watch::tests::a_view_gone_before_the_index_forgets_it (gpu: two unit tests fail now and then in parallel runs #54) did not fail in those runs; it is being looked at separately.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: Claude Code (Sonnet, as a Hangar worker) found the cause and wrote the fix; Claude Code (Opus 5.5) reviewed it. No external code was copied or translated. I answer for every line.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

🤖 Generated with Claude Code

a_released_targets_copy_goes_when_its_memory_is_used_again compared the
placed view's resource before and after the title's new texture with
assert_ne!(now, shown), a pointer compare of a resource that was queued
for release. The queue (RELEASED) is the process's, and five other tests
drain it with release_waiting(ZERO) at any moment: that frees `shown`
before the check, and the next resource made can get the same heap
address, so the compare failed now and then in the parallel run (#54).

The test takes a reference on `shown` and gives it back at the end, so
the address cannot be reused. No production code changes: the 2 s grace
is only drained early by tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

This pull request now conflicts with its base branch. Please rebase it on main (or merge main into it) and resolve the conflicts; the conflict label goes away by itself once it merges cleanly.

@github-actions github-actions Bot added conflict conflicts with its base branch overlap another open PR changes the same files labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#62 crates/xtp-gpu/src/resource.rs

This comment is kept up to date automatically and removed when the overlap ends.

@github-actions github-actions Bot added area/gpu touches crates/xtp-gpu size/S 10 to 99 changed lines labels Nov 25, 2026
@fogydes

fogydes commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: main has since fixed this test another way (5e920b8: it compares the retained host copy instead of the resource pointer and releases through release_views_at, so address reuse no longer matters). The diagnosis here stands as background for #54.

@fogydes fogydes closed this Nov 25, 2026
@fogydes
fogydes deleted the gpu/released-view-stays-alive-in-test branch November 25, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/gpu touches crates/xtp-gpu conflict conflicts with its base branch overlap another open PR changes the same files size/S 10 to 99 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant