d3d12: fill the readable smaller mips of a title texture whose larger ones are not there yet (RT-TITLE-PARTIAL-MIPS) #2166
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2166"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-26T01:05:22Z.
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
mon are a prefix of its footprint:mip_chain_bytes(layout, m)bytes from the base.With
LEONIDA_TITLE_PARTIAL_MIPS=1(off by default):texture_memory_readable_bytes,title_texture_memory.h);first_mip_withinturns that into the first mip held with every smaller one(
xg_xs_layout.h).path and the staged
TitleImageUploadtake a first mip), and only the descriptor keys of views that start thereor later are published. Keys of views that start above stay on the fallback (
PendingImage::first_mip), so noshader 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).the next pass fills it instead of the round-robin sweep many passes later.
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 hasmemory for every mip (a
shortcut:comment says when to make it without the missing ones). The census line gains acount 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.mdnext 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 tooshort for a tail and linear layouts, the first
mip_chain_bytes(t, m)bytes detile every element of mipsm..exactly as the whole texture does; a larger mip needs a longer prefix and mip 0 the whole texture;
first_mip_withinfinds the largest mip a prefix holds; a cube is readable whole or not at all;texture_memory_readable_bytesstops at a guarded first page. The cases do not build without the change (thefunctions are new).
gta6rtand ranxg_xs,d3d12_texture_memory,d3d12_title_va,d3d12_existing_heap,d3d12_descriptor,title_memory_mapandvulkan_title_image_pool(10 CTest entries with their variants): allpass (MSVC, RelWithDebInfo, Ninja). These run with the switch unset; the device path with it set has no unit test.
mainplus this change), retail title, counts only, 420 s each: withLEONIDA_TITLE_PARTIAL_MIPS=1, three runs, no device loss; the figures above are from the third. No run of thisbuild with the switch unset (that path is
main's). The census line needsLEONIDA_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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T04:49:32Z.
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_testfixture 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 throughtitle_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.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).
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-26T04:53:26Z.
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.)
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T19:29:01Z.
Merge test on an 8 GB laptop (profile M), asked by DadaCap. Main
ec91d695cwas merged without conflict, in one tree together with #2020. AI-assisted (Claude Code, Claude Opus 5.5).xg_xs_testexit 0 (519 checks, 0 failures; 280 textures laid out by both models).ec91d695cthe new test does not build:mip_chain_bytesandfirst_mip_withindo not exist there. So it covers the new helpers, not a behaviour change on main.