[pr-fix][rendering] darner-gpu: the read-back footprint cache tells a 3D texture from a 2D array #426

Open
qnjk wants to merge 1 commit from qnjk/Darner:texback-key-dimension into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: texback::footprints_of caches the copyable footprints of a texture under a key that leaves the dimension out:

    type FootprintKey = (u64, u32, u16, u16, i32);   // Width, Height, DepthOrArraySize, MipLevels, Format
    

    (crates/darner-gpu/src/texback.rs:402, built at :416). The cached value depends on the dimension: DepthOrArraySize is a depth for a TEXTURE3D and an array size for a TEXTURE2D, so the subresource count at :421-425 (one per mip versus one per mip per layer) differs for the same key. A 64x64x64 volume and a 64-layer 64x64 array of the same format and mip count therefore shared one Arc<Footprints> and one read-back buffer size. Both users of it trust it: record_texture (:511-526) records subresources.len() copies with SubresourceIndex: i, which the other shape does not have, and land (:633-651) pairs footprint i with (i % mips, i / mips) of a layout whose slices is 1 for a 3D texture, so Layout::tile returns Invalid and nothing lands — the title keeps reading whatever the read-back was meant to replace.

  • This change puts the dimension and the sample count into the key through a pure footprint_key() (desc.Dimension.0 as u64, Width, Height, DepthOrArraySize, MipLevels, Format.0, SampleDesc.Count); the sample count is passed to GetCopyableFootprints, so it belongs in the key too. The subresource-count expression moves into subresource_count() so it can be asserted without a device. FootprintKey is private, so its shape is free to change.

How it was tested

  • Tested revision: c7b977a (one commit on f3840d7).
  • Commands and results:
    • cargo test --locked -p darner-gpu --lib — 1757 passed, 0 failed, 81 ignored. (One earlier full-suite run on this tree failed watch::tests::ask_once_by_res_splits_reservations_without_refusals, one of the two pre-existing parallel-suite flakes: three runs of the unmodified f3840d7 tree in the same worktree produced the same class of flake, and both watch tests pass when run alone.)
    • New test texback::tests::the_footprint_cache_tells_apart_textures_that_differ_in_dimension: builds the 2D-array and 3D D3D12_RESOURCE_DESC values, asserts subresource_count is 64 and 1, asserts the two keys differ, and that raising SampleDesc.Count changes the key. No adapter: the key is pure.
    • Fail-before, with only the old five-field key restored:
      the_footprint_cache_tells_apart_textures_that_differ_in_dimension panicked at texback.rs:913:
        assertion `left != right` failed: a 64x64x64 volume and a 64-layer 64x64 array do not have the same footprints
          left: (64, 64, 64, 1, 41)
         right: (64, 64, 64, 1, 41)
      
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings passes.
  • Changes a default: no. A texture whose dimension/sample count match its cached entry gets the same footprints it got before; two shapes that used to collide no longer do.
  • A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim.
  • 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 green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent flakes of #150; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes.
  • Gameplay, when relevant: no gameplay run. The failure needs a 3D texture and a 2D array that collide in the cache, and no visual claim is made.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: footprints_of itself still needs a device and stays untested; the test pins the key and the subresource count, not a real GetCopyableFootprints call, and does not exercise the out-of-range copy/land path downstream. D3D12_TEXTURE_LAYOUT is still not in the key; no caller here creates a 64 KiB-swizzled texture through this cache, so the change was not widened.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the collision needs both shapes present in one session to observe, and no frame-rate or visual claim is made. 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: 555 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: #341 changes crates/darner-gpu/src/texback.rs too — it narrows land's lock scope and says nothing about footprints_of, FootprintKey or the read-back buffer size, so a conflict is possible in land only. Issue #287 asks for a read-back hook, not this cache. No open or closed issue mentions the footprint key.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `texback::footprints_of` caches the copyable footprints of a texture under a key that leaves the dimension out: ```rust type FootprintKey = (u64, u32, u16, u16, i32); // Width, Height, DepthOrArraySize, MipLevels, Format ``` (`crates/darner-gpu/src/texback.rs:402`, built at `:416`). The cached value depends on the dimension: `DepthOrArraySize` is a **depth** for a `TEXTURE3D` and an **array size** for a `TEXTURE2D`, so the subresource count at `:421-425` (one per mip versus one per mip per layer) differs for the same key. A 64x64x64 volume and a 64-layer 64x64 array of the same format and mip count therefore shared one `Arc<Footprints>` and one read-back buffer size. Both users of it trust it: `record_texture` (`:511-526`) records `subresources.len()` copies with `SubresourceIndex: i`, which the other shape does not have, and `land` (`:633-651`) pairs footprint `i` with `(i % mips, i / mips)` of a layout whose `slices` is 1 for a 3D texture, so `Layout::tile` returns `Invalid` and nothing lands — the title keeps reading whatever the read-back was meant to replace. - This change puts the dimension and the sample count into the key through a pure `footprint_key()` (`desc.Dimension.0 as u64, Width, Height, DepthOrArraySize, MipLevels, Format.0, SampleDesc.Count`); the sample count is passed to `GetCopyableFootprints`, so it belongs in the key too. The subresource-count expression moves into `subresource_count()` so it can be asserted without a device. `FootprintKey` is private, so its shape is free to change. ## How it was tested - Tested revision: `c7b977a` (one commit on `f3840d7`). - Commands and results: - `cargo test --locked -p darner-gpu --lib` — 1757 passed, 0 failed, 81 ignored. (One earlier full-suite run on this tree failed `watch::tests::ask_once_by_res_splits_reservations_without_refusals`, one of the two pre-existing parallel-suite flakes: three runs of the *unmodified* `f3840d7` tree in the same worktree produced the same class of flake, and both `watch` tests pass when run alone.) - New test `texback::tests::the_footprint_cache_tells_apart_textures_that_differ_in_dimension`: builds the 2D-array and 3D `D3D12_RESOURCE_DESC` values, asserts `subresource_count` is 64 and 1, asserts the two keys differ, and that raising `SampleDesc.Count` changes the key. No adapter: the key is pure. - Fail-before, with only the old five-field key restored: ``` the_footprint_cache_tells_apart_textures_that_differ_in_dimension panicked at texback.rs:913: assertion `left != right` failed: a 64x64x64 volume and a 64-layer 64x64 array do not have the same footprints left: (64, 64, 64, 1, 41) right: (64, 64, 64, 1, 41) ``` - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings` passes. - Changes a default: no. A texture whose dimension/sample count match its cached entry gets the same footprints it got before; two shapes that used to collide no longer do. - A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim. - 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 green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent flakes of #150; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. - Gameplay, when relevant: no gameplay run. The failure needs a 3D texture and a 2D array that collide in the cache, and no visual claim is made. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: `footprints_of` itself still needs a device and stays untested; the test pins the key and the subresource count, not a real `GetCopyableFootprints` call, and does not exercise the out-of-range copy/`land` path downstream. `D3D12_TEXTURE_LAYOUT` is still not in the key; no caller here creates a 64 KiB-swizzled texture through this cache, so the change was not widened. ## 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 collision needs both shapes present in one session to observe, and no frame-rate or visual claim is made. 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`: 555 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: #341 changes `crates/darner-gpu/src/texback.rs` too — it narrows `land`'s lock scope and says nothing about `footprints_of`, `FootprintKey` or the read-back buffer size, so a conflict is possible in `land` only. Issue #287 asks for a read-back hook, not this cache. No open or closed issue mentions the footprint key. - Replaces or overlaps: none found
A D3D12_RESOURCE_DESC's DepthOrArraySize is a depth for a TEXTURE3D and an
array size for a TEXTURE2D, so a 64x64x64 volume and a 64-layer 64x64 array
of the same format and mip count produced one key: the read-back cache handed
one shape's GetCopyableFootprints list, and therefore one shape's read-back
buffer size, to the other.

Both users of that list trust it. record_texture recorded the wrong number of
copies, with SubresourceIndex values the texture does not have, and land
paired footprint i with (i % mips, i / mips) of a layout whose slices is 1 for
a 3D texture, so Layout::tile returned Invalid and nothing landed: the title
kept reading whatever the read-back was supposed to replace.

Put the dimension and the sample count (also passed to the call) into
FootprintKey through a pure footprint_key(), and move the count into
subresource_count() so it can be pinned without a device. The new test builds
the 2D-array and 3D descriptions, checks their subresource counts are 64 and
1, and checks the two keys differ; with the old five-field tuple it fails on
exactly that assertion. No adapter is needed.
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 'texback-key-dimension:qnjk-texback-key-dimension'
git switch 'qnjk-texback-key-dimension'

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-texback-key-dimension'
git switch 'qnjk-texback-key-dimension'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-texback-key-dimension'
git switch 'qnjk-texback-key-dimension'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-texback-key-dimension'
git switch 'main'
git merge --squash 'qnjk-texback-key-dimension'
git switch 'main'
git merge --ff-only 'qnjk-texback-key-dimension'
git switch 'main'
git merge 'qnjk-texback-key-dimension'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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!426
No description provided.