[PR #2166] d3d12: fill the readable smaller mips of a title texture whose larger ones are not there yet (RT-TITLE-PARTIAL-MIPS) #2170

Open
opened 2026-11-26 21:20:17 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2166
Author: @DadaCap
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: title-texture-partial-mips


📝 Commits (2)

  • a1df171 d3d12: LEONIDA_TITLE_PARTIAL_MIPS fills the readable smaller mips of a title texture whose larger ones are not there
  • f36d89e Merge remote-tracking branch 'origin/main' into title-texture-partial-mips

📊 Changes

7 files changed (+263 additions, -55 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+9 -0)
📝 runtime/README.md (+2 -0)
📝 runtime/shims/d3d12_title_image_upload.h (+5 -4)
📝 runtime/shims/d3d12_vulkan_device.cpp (+156 -41)
📝 runtime/shims/xg_xs_layout.h (+16 -0)
📝 runtime/src/title_texture_memory.h (+16 -10)
📝 runtime/test/xg_xs_test.cpp (+59 -0)

📄 Description

Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7178047182

Depends on: nothing. Conflicts textually with #2021 (TitleImageUpload::write) and #2050 (d3d12_vulkan_device.cpp); whichever lands second rebases. Merges cleanly with #2122.

What and why

A slot-70 texture whose pages are not all readable waits on the fallback until every page is, even when the
smaller mips are already there. The XG layout of a 2D texture of one slice stores its mips from the smallest to
the largest, so the mips from m on are a prefix of its footprint: mip_chain_bytes(layout, m) bytes from the base.

With LEONIDA_TITLE_PARTIAL_MIPS=1 (off by default):

  • The readability probe returns how many bytes from the base are readable (texture_memory_readable_bytes,
    title_texture_memory.h); first_mip_within turns that into the first mip held with every smaller one
    (xg_xs_layout.h).
  • When the last slot-70 view starts at that mip or later, the mips from there on are filled (both the host-copy
    path and the staged TitleImageUpload take a first mip), and only the descriptor keys of views that start there
    or later are published. Keys of views that start above stay on the fallback (PendingImage::first_mip), so no
    shader samples a mip that was not filled. A later fill with more mips publishes them; a filled range is never
    left half old (fill_limit).
  • A texture not filled, or filled in part, whose pages came through a title memory map change is marked stale, so
    the next pass fills it instead of the round-robin sweep many passes later.
  • Arrays, cubes and volumes are filled whole or not at all: their mips are not a prefix.

Unset, the behaviour is the one on main: a texture is readable only when all of it is, and fills start at mip 0.

LEONIDA_TITLE_PARTIAL_MIPS_MB (2048) limits the image memory of the textures filled in part: the image still has
memory for every mip (a shortcut: comment says when to make it without the missing ones). The census line gains a
count of textures filled in part, their image memory and how much of it is filled.

Why off by default: the VRAM cost. In a 420 s game run of this branch with it on, about 3,000 textures were filled in
part at the end (about 7,400 over the run, 11,200 partial fills, about 800 of them later got their larger mips),
holding about 1.5 GB of image memory for about 315 MB of filled mips. That is a fair trade on a 16 GB card, not on an
8 GB one.

README rows for both switches, and a paragraph in docs/d3d12_vulkan.md next to the deferred slot-70 images.

Tested

  • xg_xs_test, new cases: for tiled (64 KiB and 4 KiB blocks, with a mip tail), odd extents, one mip, a chain too
    short for a tail and linear layouts, the first mip_chain_bytes(t, m) bytes detile every element of mips m..
    exactly as the whole texture does; a larger mip needs a longer prefix and mip 0 the whole texture;
    first_mip_within finds the largest mip a prefix holds; a cube is readable whole or not at all;
    texture_memory_readable_bytes stops at a guarded first page. The cases do not build without the change (the
    functions are new).
  • Built gta6rt and ran xg_xs, d3d12_texture_memory, d3d12_title_va, d3d12_existing_heap,
    d3d12_descriptor, title_memory_map and vulkan_title_image_pool (10 CTest entries with their variants): all
    pass (MSVC, RelWithDebInfo, Ninja). These run with the switch unset; the device path with it set has no unit test.
  • Game runs of this branch's own build (main plus this change), retail title, counts only, 420 s each: with
    LEONIDA_TITLE_PARTIAL_MIPS=1, three runs, no device loss; the figures above are from the third. No run of this
    build with the switch unset (that path is main's). The census line needs LEONIDA_FSDRAW_PROBE=1 (or any probe that enables it) to be printed.
    A picture comparison was not made: whether a texture now shows its smaller mips instead of the fallback was not
    checked by eye.

GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (unit tests and the game observation).

AI-assisted: yes (Claude Code).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2166 **Author:** [@DadaCap](https://github.com/DadaCap) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `title-texture-partial-mips` --- ### 📝 Commits (2) - [`a1df171`](https://github.com/ubiquitarianism/leonida/commit/a1df1713d49f06556eeb26b8015cce2841951c5c) d3d12: LEONIDA_TITLE_PARTIAL_MIPS fills the readable smaller mips of a title texture whose larger ones are not there - [`f36d89e`](https://github.com/ubiquitarianism/leonida/commit/f36d89ebcc27a02d0aad9742a057cf9af488129e) Merge remote-tracking branch 'origin/main' into title-texture-partial-mips ### 📊 Changes **7 files changed** (+263 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+9 -0) 📝 `runtime/README.md` (+2 -0) 📝 `runtime/shims/d3d12_title_image_upload.h` (+5 -4) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+156 -41) 📝 `runtime/shims/xg_xs_layout.h` (+16 -0) 📝 `runtime/src/title_texture_memory.h` (+16 -10) 📝 `runtime/test/xg_xs_test.cpp` (+59 -0) </details> ### 📄 Description Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7178047182 Depends on: nothing. Conflicts textually with #2021 (`TitleImageUpload::write`) and #2050 (`d3d12_vulkan_device.cpp`); whichever lands second rebases. Merges cleanly with #2122. ### What and why A slot-70 texture whose pages are not all readable waits on the fallback until every page is, even when the smaller mips are already there. The XG layout of a 2D texture of one slice stores its mips from the smallest to the largest, so the mips from `m` on are a prefix of its footprint: `mip_chain_bytes(layout, m)` bytes from the base. With `LEONIDA_TITLE_PARTIAL_MIPS=1` (off by default): - The readability probe returns how many bytes from the base are readable (`texture_memory_readable_bytes`, `title_texture_memory.h`); `first_mip_within` turns that into the first mip held with every smaller one (`xg_xs_layout.h`). - When the last slot-70 view starts at that mip or later, the mips from there on are filled (both the host-copy path and the staged `TitleImageUpload` take a first mip), and only the descriptor keys of views that start there or later are published. Keys of views that start above stay on the fallback (`PendingImage::first_mip`), so no shader samples a mip that was not filled. A later fill with more mips publishes them; a filled range is never left half old (`fill_limit`). - A texture not filled, or filled in part, whose pages came through a title memory map change is marked stale, so the next pass fills it instead of the round-robin sweep many passes later. - Arrays, cubes and volumes are filled whole or not at all: their mips are not a prefix. Unset, the behaviour is the one on `main`: a texture is readable only when all of it is, and fills start at mip 0. `LEONIDA_TITLE_PARTIAL_MIPS_MB` (2048) limits the image memory of the textures filled in part: the image still has memory for every mip (a `shortcut:` comment says when to make it without the missing ones). The census line gains a count of textures filled in part, their image memory and how much of it is filled. Why off by default: the VRAM cost. In a 420 s game run of this branch with it on, about 3,000 textures were filled in part at the end (about 7,400 over the run, 11,200 partial fills, about 800 of them later got their larger mips), holding about 1.5 GB of image memory for about 315 MB of filled mips. That is a fair trade on a 16 GB card, not on an 8 GB one. README rows for both switches, and a paragraph in `docs/d3d12_vulkan.md` next to the deferred slot-70 images. ### Tested - `xg_xs_test`, new cases: for tiled (64 KiB and 4 KiB blocks, with a mip tail), odd extents, one mip, a chain too short for a tail and linear layouts, the first `mip_chain_bytes(t, m)` bytes detile every element of mips `m..` exactly as the whole texture does; a larger mip needs a longer prefix and mip 0 the whole texture; `first_mip_within` finds the largest mip a prefix holds; a cube is readable whole or not at all; `texture_memory_readable_bytes` stops at a guarded first page. The cases do not build without the change (the functions are new). - Built `gta6rt` and ran `xg_xs`, `d3d12_texture_memory`, `d3d12_title_va`, `d3d12_existing_heap`, `d3d12_descriptor`, `title_memory_map` and `vulkan_title_image_pool` (10 CTest entries with their variants): all pass (MSVC, RelWithDebInfo, Ninja). These run with the switch unset; the device path with it set has no unit test. - Game runs of this branch's own build (`main` plus this change), retail title, counts only, 420 s each: with `LEONIDA_TITLE_PARTIAL_MIPS=1`, three runs, no device loss; the figures above are from the third. No run of this build with the switch unset (that path is `main`'s). The census line needs `LEONIDA_FSDRAW_PROBE=1` (or any probe that enables it) to be printed. A picture comparison was not made: whether a texture now shows its smaller mips instead of the fallback was not checked by eye. GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (unit tests and the game observation). AI-assisted: yes (Claude Code). ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
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
starred/leonida#2170
No description provided.