Skip to content

gpu, docs: keep placed texture views in step with title memory - #62

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:gpu/defer-address-textures
Nov 25, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:gpu/defer-address-textures

Conversation

@PrivacyOnion

@PrivacyOnion PrivacyOnion commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Reworked after review: this PR now holds only the placed-view fixes and the per-origin accounting. The deferral of address textures is out, held until the pool rework is on main, then measured again against it, as suggested.

Placed texture views are the host copies XTP makes for a texture the title placed in its own memory. Today they can outlive or miss changes to that memory, and a race can leave a slot null:

  • A remap or unmap cancels a view still being created, so a creation that finishes late can no longer reinsert a stale entry.
  • Expired views are reaped during normal submissions, instead of only at the next invalidation.
  • A read-only view waits for at least one mapped page.
  • A slot whose view cannot be made now gets a null view, with no second attempt under the descriptor lock.
  • Concurrent mirrors (review point 3). Thread A makes the view and writes the slot. Thread B, which found no texture because A was still making it, then saw another host texture than the slot's, so it took the slot as stale and wrote a null view over the good one. texture_lookup now reports that case apart (PlacedLookup::Building), and only then a slot already made for the same record over a texture keeps it (descriptor/host.rs, mirror). With no mapped page or a failed creation, the slot follows the memory and is made null. A slot not made yet still gets a null view, and is made by the next mirror that finds the texture.
  • A failed rebuild records the alias change, as main did, so it is not retried on every lookup.

The frame report also gives:

  • host texture count and MiB by creation origin (committed, heap offset, address, placed view, external);
  • the placed-view cache counts (cached, retiring, unmapped, invalidated, same address, shared).

On the RTX 5070 (12 GB, driver 32.0.16.1664, 16 GB RAM), main c3da2f9 with #61, first world frames: placed views 15,449 live, 3,753 MiB; address textures 2,073 MiB. On that driver every DEFAULT texture is charged in full to process commit, even created not resident or evicted. A probe of 32 × 64 MiB RGBA8 textures, deltas in MiB:

Case Private Commit total DXGI local
committed, resident +2,052 +2,047 +2,048
committed, CREATE_NOT_RESIDENT +2,052 +2,053 0
after Evict +2,052 +2,065 0
one 2 GiB heap + placed textures +2,052 +2,081 +2,048
reserved (tiled), no tiles mapped 0 −7 0

So the reserved textures of the pool rework should help this host most. The origin counts show how much it takes off each path.

Not in this PR, to come after the pool rework: the deferral and the census of address textures (it shares the deferral's bookkeeping).

Size: +500/−86 over 7 files, of which about half is tests.

Fixes: none
Depends on: none

Area

  • crates/xtp-gpu/src/resource.rs, resource/alias.rs, resource/format.rs: placed-view lifetime, accounting by origin, a test helper
  • crates/xtp-gpu/src/descriptor/host.rs: the concurrent mirror fix and its tests
  • crates/xtp-gpu/src/host.rs, device.rs: reaping during submissions, the report line
  • docs/analysis/vram.md

Tests

  • cargo xtask pr-check passes on my machine. fmt, both clippy passes, policy and conventions ran. The test step was run per crate (below), because the app integration tests launch xtp.exe.
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

Tests on the RTX 5070, on this branch (main c3da2f9):

  • cargo test -p xtp-gpu --lib -- --test-threads=1: 479 passed, 13 ignored.

New tests:

  • a_placed_slot_keeps_its_view_while_another_is_made: a slot made over a placed view keeps it while the view's entry looks as if another thread were still making it. It fails without the fix (the slot kept its view).
  • a_placed_slot_follows_its_memory_when_unmapped: a slot made over a placed view is made null once its memory is decommitted and the remap reported. It fails if every "no texture" keeps the slot.
  • a_read_only_placed_view_waits_for_its_first_mapped_page
  • a_remap_cancels_a_placed_view_still_being_created
  • placed views going with their memory, and placed texture slots following their replacement (existing tests, updated).

Ran on a title: the placed-view part ran in five guarded world sessions of the 1.0.2.1 Xbox Series build (Series S mode, RTX 5070, 16 GB RAM) on 448bb93, together with the deferral. This exact branch was not run on the title.

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:

Written for XTP from XTP's own code. What was read: XTP's logs from the sessions; public Microsoft documentation on process memory counters, DXGI budgets, Evict and WDDM backing stores. xcl and AnyPS5 were not read for this.

AI assistance: AI coding tools wrote this change and its tests, mainly OpenAI Codex.

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/)

@github-actions github-actions Bot added area/hle touches crates/xtp-hle area/gpu touches crates/xtp-gpu area/docs docs/, Markdown overlap another open PR changes the same files size/L 400 to 999 changed lines labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

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
#49 crates/xtp-gpu/src/descriptor/host.rs
#51 crates/xtp-gpu/src/host.rs

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

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

Thanks for the probe table and the census. The commit numbers are very useful.

Requesting changes:

  1. Resident creation on the title's thread (resource.rs:1544-1549, 1325, 1367). A deferred texture is created with HEAP_FLAG_NONE at its first host use, and that includes the title's own SRV creation. docs/analysis/stall.md measured this kind of call at 0.3–3.6 s per creation, while holding the residency mutex, and main keeps that wait off the title's thread. Could you report first-use creation times from your sessions, or keep the not-resident path?
  2. Pool bypass (resource.rs:1167). Promoted textures never reach the pool. We are reworking the pool right now toward reserved textures whose tiles are mapped on upload and returned on eviction; your own probe shows those cost no commit until mapped. Deferral would route textures around that design.
  3. Concurrent placed views (resource.rs:2243-2244, descriptor/host.rs:1969). While one thread creates a view, a second thread gets None and writes a null descriptor, which can overwrite the good view until the next re-mirror. This affects every host, not only low-memory ones.
  4. Tests choose deferral from the host's RAM (resource.rs:1597-1618), so CI and machines with 32 GiB or more test different paths. Please default to eager under cfg(test).
  5. Title: please name every area, e.g. gpu, hle, docs: ….

Suggestion: the placed-view fixes and the census/per-origin accounting complement the pool rework, and could land soon as their own PR. Hold the deferral until the pool rework is on main, then measure again against it.

The failing gpu-debug-layer job (message 1419 in a draw.rs test) also fails on main and is unrelated to this PR; we are fixing it.

@PrivacyOnion
PrivacyOnion force-pushed the gpu/defer-address-textures branch from a323476 to 878d9ac Compare November 25, 2026 11:29
@PrivacyOnion PrivacyOnion changed the title gpu: defer address textures on low-memory hosts gpu, docs: keep placed texture views in step with title memory Nov 25, 2026
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I followed your suggestion: this PR now holds only the placed-view fixes and the per-origin accounting, rebased on c3da2f9. The deferral is out, held until the pool rework lands, and will be measured again against it.

  1. Resident creation on the title's thread: gone with the deferral. Address textures use main's path again, unchanged. When the deferral comes back I'll report first-use creation times; I don't have them from the earlier sessions.
  2. Pool bypass: gone with the deferral too.
  3. Concurrent placed views: fixed in descriptor/host.rs (mirror). A mirror that finds no texture for a placed view (unmapped, or still being made by another thread) leaves a slot already made for the same record over a texture as it is, instead of writing a null view over it. An unmade slot still gets a null view and is made by the next mirror that finds the texture. The new test a_placed_slot_keeps_its_view_while_another_is_made holds the view's entry in the "being made" state while a second mirror runs. It fails without the fix.
  4. Tests choosing deferral from the host's RAM: no longer applies, since the policy is out of this PR. When the deferral comes back it will default to eager under cfg(test).
  5. Title: now gpu, docs: …. Since the xmem census hook is out, hle is no longer touched.

The census of address textures is out as well: it shares the deferral's bookkeeping, so it will come with it.

@github-actions github-actions Bot removed the area/hle touches crates/xtp-hle label Nov 25, 2026

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

Thanks for the rework. Splitting the PR, fixing the title and dropping the deferral settle points 1, 2, 4 and 5, and the ticket scheme in texture_at_with reads well. The gpu-debug-layer failures (message 1419) are the same three as on main; we're fixing those there.

Two small points:

  1. descriptor/host.rs:1955-1960: Some(None) means "another thread is making it", but also "no mapped page" or "creation failed". So after an unmap, a slot keeps the old mapping's copy instead of following the memory. Could texture_at report "building" separately, so that only that case keeps the slot? A test that unmaps and then mirrors would cover it.
  2. resource.rs:2153, 2195: view.changes is now recorded only on success, so a failed rebuild is retried on every lookup; main recorded it first. On a low-memory host, that could repeat a slow creation on the title's thread.

Happy to approve once these are answered.

Placed texture views (host copies made for a texture the title placed
in its own memory) now follow that memory:

- A remap or unmap cancels a view still being created, so a creation
  that finishes late can no longer reinsert a stale entry.
- Expired views are reaped during normal submissions instead of only
  at the next invalidation.
- A read-only view waits for at least one mapped page.
- A slot whose view cannot be made now gets a null view, with no second
  attempt under the descriptor lock.
- A slot already made over a placed view's texture keeps it when a
  racing mirror finds no texture there because another thread is still
  making one (texture_lookup reports that case apart). Before, that
  mirror wrote a null view over the good one until the slot was made
  again. With no mapped page or a failed creation, the slot still
  follows the memory and is made null.
- A failed rebuild still records the alias change, as before, so it is
  not tried again on every lookup.

The frame report gives host texture count and MiB by creation origin
(committed, heap offset, address, placed view, external) and the
placed-view cache counts.
@PrivacyOnion
PrivacyOnion force-pushed the gpu/defer-address-textures branch from 878d9ac to dfbbd92 Compare November 25, 2026 11:47
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

Thanks, both done in the same commit.

  1. Unmapped memory vs. a view being made. texture_lookup (resource.rs) now returns PlacedLookup::{Ready, Building, Absent}; texture_at is texture_lookup(..).ready(). mirror keeps a slot already made for the record only for Building. With no mapped page or a failed creation (Absent) the slot follows the memory and is made null. New test a_placed_slot_follows_its_memory_when_unmapped: it mirrors a placed view, decommits the memory, reports the remap, and mirrors again. The slot ends up null. It fails with the previous version (the slot kept the old copy). a_placed_slot_keeps_its_view_while_another_is_made still covers the Building case.
  2. view.changes on a failed rebuild. It is recorded again whatever the creation's outcome (resource.rs, after building = 0), so a failed rebuild waits for the next alias change instead of being retried on every lookup.

Tests on the RTX 5070: cargo test -p xtp-gpu --lib -- --test-threads=1 479 passed, 13 ignored; pr-check (fmt, both clippy passes, policy, conventions) passes.

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

Thanks for the quick rework. Both points are settled. texture_lookup now reports Building separately, so only a slot racing its maker keeps its view, and an unmapped or failed view follows the memory; the unmap test covers it. A failed rebuild records view.changes again, as main did.

Optional, in a follow-up: a test showing that a failed rebuild is not retried before the next alias change. Also, the PlacedLookup::Building doc says "the first one", but it is also returned during a rebuild.

The gpu-debug-layer failures are the three known message-1419 tests that also fail on main. We're fixing them there, and I'll merge once that job is green. Approving.

@simnJS
simnJS merged commit 0a66f9f into MiamiGame:main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs docs/, Markdown area/gpu touches crates/xtp-gpu overlap another open PR changes the same files size/L 400 to 999 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants