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

Open
github-bot wants to merge 2 commits from github-bot/gh-2166 into main AGit
Owner

@⁠DadaCap on GitHub · 2026-11-26 01:05 UTC · original
DadaCap:title-texture-partial-mips → main · +263 −55 · 7 files · 2 commits · open

Claimed in the coordination issue as: #1608

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

**@⁠DadaCap** on GitHub · 2026-11-26 01:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2166) `DadaCap:title-texture-partial-mips` → `main` · +263 −55 · 7 files · 2 commits · open Claimed in the coordination issue as: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 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)
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). With LEONIDA_TITLE_PARTIAL_MIPS=1 the readability probe returns the
readable prefix (texture_memory_readable_bytes), first_mip_within the first mip it holds; when the last slot-70 view
starts there or later, those mips are filled and only the T#s of views that start there or later are published. The
others stay on the fallback until a later fill has their mips. A texture not filled, or filled in part, whose pages
came through a map change is marked stale so the next pass fills it.

Off by default: the image still has memory for every mip. LEONIDA_TITLE_PARTIAL_MIPS_MB (2048) bounds the image
memory of the textures filled in part. Unset, the behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:57 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 04:49 UTC · original · edited 2026-11-26 08:51 UTC

I checked the opt-in device path on a physical RTX 4090 (Windows 11, NVIDIA 616.64) at f36d89ebcc27a02d0aad9742a057cf9af488129e. A GPU shader sampled the smaller mips as their pages arrived. Views for larger, unreadable mips continued to sample the fallback, and previously published views stayed valid through two upgrades.

I extended the synthetic d3d12_descriptor_test fixture locally, leaving the runtime at the PR revision. I created four separate slot-70 SRVs of one 512×512 RGBA8_UNORM texture, each selecting exactly one mip, while its backing range was still entirely reserved. Each view initially sampled transparent black. I then committed progressively larger prefixes, wrote a different byte pattern into each mip using the XG layout, and reported only the newly mapped range through title_memory_map::changed. After the normal refresh interval, I submitted an empty command list, waited for its fence and sampled the original four descriptors through the runtime's bindless set. I did not recreate the views.

Readable prefix Partial mips enabled Partial mips disabled
81,920 bytes Mips 2 and 3 returned their colors. Mips 0 and 1 returned the fallback. All four returned the fallback.
344,064 bytes Mips 1, 2 and 3 returned their colors. Mip 0 returned the fallback. All four returned the fallback.
1,392,640 bytes (complete) All four returned their colors. All four returned their colors.

6,144/6,144 RGBA samples matched across eight runs: 64 per view × four views × three updates, repeated with partial mips on/off, staged upload/host image copy, and Vulkan validation on/off. Correction after checking the full process logs: all four validation-enabled runs reached the pixel check with zero validation errors, and each logged one device-destruction message afterward (174–185 Vulkan objects still live). The local test returned immediately after readback. I reran all four validation-enabled configurations on the same runtime revision after fixing the local fixture to retire its images, refresh its descriptor-set handle, and finish normal device cleanup. All 3,072 additional RGBA samples matched. All four processes exited 0 and their complete logs contained no validation messages through device destruction. For the staged runs the test device disabled host image copy. For host copy it enabled the supported feature and set LEONIDA_TITLE_IMAGE_STAGING=0.

This covers pixel readback for a synthetic single-slice 2D texture. Retail visuals and frame timing were outside this test. AI-assisted verification (OpenAI Codex).

**@⁠ecox982745** on GitHub · 2026-11-26 04:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2166#issuecomment-7182935450) · edited 2026-11-26 08:51 UTC I checked the opt-in device path on a physical RTX 4090 (Windows 11, NVIDIA 616.64) at `f36d89ebcc27a02d0aad9742a057cf9af488129e`. A GPU shader sampled the smaller mips as their pages arrived. Views for larger, unreadable mips continued to sample the fallback, and previously published views stayed valid through two upgrades. I extended the synthetic `d3d12_descriptor_test` fixture locally, leaving the runtime at the PR revision. I created four separate slot-70 SRVs of one 512×512 RGBA8_UNORM texture, each selecting exactly one mip, while its backing range was still entirely reserved. Each view initially sampled transparent black. I then committed progressively larger prefixes, wrote a different byte pattern into each mip using the XG layout, and reported only the newly mapped range through `title_memory_map::changed`. After the normal refresh interval, I submitted an empty command list, waited for its fence and sampled the **original four descriptors** through the runtime's bindless set. I did not recreate the views. | Readable prefix | Partial mips enabled | Partial mips disabled | | --- | --- | --- | | 81,920 bytes | Mips 2 and 3 returned their colors. Mips 0 and 1 returned the fallback. | All four returned the fallback. | | 344,064 bytes | Mips 1, 2 and 3 returned their colors. Mip 0 returned the fallback. | All four returned the fallback. | | 1,392,640 bytes (complete) | All four returned their colors. | All four returned their colors. | **6,144/6,144 RGBA samples matched** across eight runs: 64 per view × four views × three updates, repeated with partial mips on/off, staged upload/host image copy, and Vulkan validation on/off. Correction after checking the full process logs: all four validation-enabled runs reached the pixel check with zero validation errors, and each logged one device-destruction message afterward (174–185 Vulkan objects still live). The local test returned immediately after readback. I reran all four validation-enabled configurations on the same runtime revision after fixing the local fixture to retire its images, refresh its descriptor-set handle, and finish normal device cleanup. All 3,072 additional RGBA samples matched. All four processes exited 0 and their complete logs contained no validation messages through device destruction. For the staged runs the test device disabled host image copy. For host copy it enabled the supported feature and set `LEONIDA_TITLE_IMAGE_STAGING=0`. This covers pixel readback for a synthetic single-slice 2D texture. Retail visuals and frame timing were outside this test. AI-assisted verification (OpenAI Codex).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-26 04:53 UTC · original

Thank you for the check on the RTX 4090. The table matches what the change is meant to do: views of the smaller mips pick up their data as their pages arrive, the larger ones stay on the fallback, and the published descriptors stay valid without being recreated. It also covers the host image copy path, which my own runs (RTX 5080, staged uploads) did not exercise separately.

(Reply written with Claude Code.)

**@⁠DadaCap** on GitHub · 2026-11-26 04:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2166#issuecomment-7182992212) Thank you for the check on the RTX 4090. The table matches what the change is meant to do: views of the smaller mips pick up their data as their pages arrive, the larger ones stay on the fallback, and the published descriptors stay valid without being recreated. It also covers the host image copy path, which my own runs (RTX 5080, staged uploads) did not exercise separately. (Reply written with Claude Code.)
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 origin '+refs/pull/2166/head:github-bot/gh-2166'
git switch 'github-bot/gh-2166'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2166'
git switch 'github-bot/gh-2166'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2166'
git switch 'github-bot/gh-2166'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2166'
git switch 'main'
git merge --squash 'github-bot/gh-2166'
git switch 'main'
git merge --ff-only 'github-bot/gh-2166'
git switch 'main'
git merge 'github-bot/gh-2166'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.