darner-gpu: a released texture leaves no eviction record behind #609

Open
qnjk wants to merge 1 commit from qnjk/Darner:texres-released-eviction into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the texture-residency cache records why a texture was evicted by its title address (crates/darner-gpu/src/resource/texres.rs), and nothing cleared that record when the texture went. Windows hands the same address out again, so the next texture mapped there started life already "evicted": charged to the eviction budget, skipped by the room line, and treated as a candidate for the tiny-copy path before it had been used once. The cache's own doc says an eviction is supposed to be a statement about a live texture that has not been used lately.

  • This change tells the residency cache that the range is gone from Drop for Resource (one call, three lines) and forgets every record of an address being released in texres. A record that is missed keeps today's behaviour, so the worst case is unchanged.

How it was tested

  • Tested revision: 845e093 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-gpu --lib -- texres — 22 passed, 0 failed.
    • New test texres::tests::a_released_texture_leaves_no_record_behind records an eviction for an address, releases the resource, and asserts the record is gone; a second case asserts a record of a different address survives.
    • Fail-before, with the three-line hook removed:
      a_released_texture_leaves_no_record_behind ... FAILED
      panicked at crates\darner-gpu\src\resource\texres.rs:2131: the released texture's eviction record stayed
      
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings passes.
  • Changes a default: no. It only drops state that the doc says should not outlive the texture.
  • A/B result: not applicable — no default changes and no speed claim; the added work is one lock and a range scan at release time.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. The crate's texres tests pass.
  • Gameplay, when relevant: no gameplay run. The effect is only visible when an address is reused for a new texture, which needs a long session; no visual or frame-rate claim is made.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the fix is at release time only; a texture unmapped without going through Drop (if such a path exists) still leaves its record. The added cost at release was not measured.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the fault needs address reuse and is not visible in a short session. The evidence is the test, which fails on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: 576 files ok).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: crates/darner-gpu/src/resource.rs is changed by 12 open pull requests (the release path itself is one of the most contended places in the tree); this change adds a single three-line call in Drop for Resource and the rest is confined to crates/darner-gpu/src/resource/texres.rs, which no open pull request touches. No open or closed issue mentions the residency eviction record.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the texture-residency cache records **why** a texture was evicted by its title address (`crates/darner-gpu/src/resource/texres.rs`), and nothing cleared that record when the texture went. Windows hands the same address out again, so the next texture mapped there started life already "evicted": charged to the eviction budget, skipped by the room line, and treated as a candidate for the tiny-copy path before it had been used once. The cache's own doc says an eviction is supposed to be a statement about a live texture that has not been used lately. - This change tells the residency cache that the range is gone from `Drop for Resource` (one call, three lines) and forgets every record of an address being released in `texres`. A record that is missed keeps today's behaviour, so the worst case is unchanged. ## How it was tested - Tested revision: `845e093` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-gpu --lib -- texres` — 22 passed, 0 failed. - New test `texres::tests::a_released_texture_leaves_no_record_behind` records an eviction for an address, releases the resource, and asserts the record is gone; a second case asserts a record of a *different* address survives. - Fail-before, with the three-line hook removed: ``` a_released_texture_leaves_no_record_behind ... FAILED panicked at crates\darner-gpu\src\resource\texres.rs:2131: the released texture's eviction record stayed ``` - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings` passes. - Changes a default: no. It only drops state that the doc says should not outlive the texture. - A/B result: not applicable — no default changes and no speed claim; the added work is one lock and a range scan at release time. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. The crate's `texres` tests pass. - Gameplay, when relevant: no gameplay run. The effect is only visible when an address is reused for a new texture, which needs a long session; no visual or frame-rate claim is made. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the fix is at release time only; a texture unmapped without going through `Drop` (if such a path exists) still leaves its record. The added cost at release was not measured. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the fault needs address reuse and is not visible in a short session. The evidence is the test, which fails on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: 576 files ok). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: `crates/darner-gpu/src/resource.rs` is changed by 12 open pull requests (the release path itself is one of the most contended places in the tree); this change adds a single three-line call in `Drop for Resource` and the rest is confined to `crates/darner-gpu/src/resource/texres.rs`, which no open pull request touches. No open or closed issue mentions the residency eviction record. - Replaces or overlaps: none found
The residency cache records why a texture was evicted by its title
address (`texres.rs`), and nothing cleared that record when the texture
went. Windows hands the same address out again, so the next texture at
that address started life already "evicted": it was charged to the
eviction budget, skipped by the room line and treated as a candidate for
the tiny-copy path before it had been used once.

`Drop for Resource` now tells the residency cache the range is gone,
through one call into `texres` that forgets every record of an address
being released. The record is only ever a hint, so the worst case for a
record that is missed is the old behaviour.
Contributor

I exercised a release followed by publication of a prepared residency result at 845e093. The release cleared the record and fast marker before the publication step in both cases. The final state was:

Prepared result State.evicted row restored EVICTED_AT marker restored
Ordinary eviction yes no
Mode 3 small-copy adoption yes yes

The test-only reproducer extracts the existing publication statements into helpers and calls those helpers after the final release on synthetic textures. It fixes the order of the two operations explicitly. The exact test filter is prepared_residency_updates_do_not_reinsert_released_textures in cargo test --locked --offline -p darner-gpu --lib.

This looks like a second half of the same lifetime fix. Checking the live texture identity under STATE before publishing would also cover results that finished preparing before Drop. Mode 3 needs that check at adoption publication as it sets the fast marker there.

I exercised a release followed by publication of a prepared residency result at `845e093`. The release cleared the record and fast marker before the publication step in both cases. The final state was: | Prepared result | `State.evicted` row restored | `EVICTED_AT` marker restored | |---|---|---| | Ordinary eviction | yes | no | | Mode 3 small-copy adoption | yes | yes | The [test-only reproducer](https://git.gtahub.st/tyr0nsur/Darner/commit/b50f9de6504615518dd83a5a6a37517a87b3bcda) extracts the existing publication statements into helpers and calls those helpers after the final release on synthetic textures. It fixes the order of the two operations explicitly. The exact test filter is `prepared_residency_updates_do_not_reinsert_released_textures` in `cargo test --locked --offline -p darner-gpu --lib`. This looks like a second half of the same lifetime fix. Checking the live texture identity under `STATE` before publishing would also cover results that finished preparing before `Drop`. Mode 3 needs that check at adoption publication as it sets the fast marker there.
TrustNo1 changed title from [pr-fix][memory] darner-gpu: a released texture leaves no eviction record behind to darner-gpu: a released texture leaves no eviction record behind 2026-12-06 03:26:19 +00:00
Owner

Test needed — commit 845e0931; what to check:

  • The problem on main: the texture-residency cache records why a texture was evicted by its title address (crates/darner-gpu/src/resource/texres.rs), and nothing cleared that record when the texture went. Windows hands the same address out again, so the next texture mapped there started life already "evicted": charged to the eviction budget, skipped by the room line, and treated as a candidate for the tiny-copy path before it had been used once. The cache's own doc says an eviction is supposed to be a statement about a live texture that has not been used lately.

  • This change tells the residency cache that the range is gone from Drop for Resource (one call, three lines) and forgets every record of an address being released in texres. A record that is missed keeps today's behaviour, so the worst case is unchanged.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `845e0931`; what to check: - The problem on main: the texture-residency cache records **why** a texture was evicted by its title address (`crates/darner-gpu/src/resource/texres.rs`), and nothing cleared that record when the texture went. Windows hands the same address out again, so the next texture mapped there started life already "evicted": charged to the eviction budget, skipped by the room line, and treated as a candidate for the tiny-copy path before it had been used once. The cache's own doc says an eviction is supposed to be a statement about a live texture that has not been used lately. - This change tells the residency cache that the range is gone from `Drop for Resource` (one call, three lines) and forgets every record of an address being released in `texres`. A record that is missed keeps today's behaviour, so the worst case is unchanged. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'texres-released-eviction:qnjk-texres-released-eviction'
git switch 'qnjk-texres-released-eviction'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-texres-released-eviction'
git switch 'qnjk-texres-released-eviction'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-texres-released-eviction'
git switch 'qnjk-texres-released-eviction'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-texres-released-eviction'
git switch 'Main'
git merge --squash 'qnjk-texres-released-eviction'
git switch 'Main'
git merge --ff-only 'qnjk-texres-released-eviction'
git switch 'Main'
git merge 'qnjk-texres-released-eviction'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!609
No description provided.