d3d12: show a staged slot-70 texture only after its first upload (RT-TITLE-TEXTURE-SHOW-AFTER-UPLOAD) #2267

Closed
leonida/mandy
Tyrannys wants to merge 0 commits from rt-title-texture-show-after-upload into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

Tyrannys commented 2026-11-26 11:50:57 +00:00

Claimed in the coordination issue as: RT-TITLE-TEXTURE-SHOW-AFTER-UPLOAD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185889059)

What and why

A slot-70 texture the layer makes itself (make_title_texture, TitleImageOrigin::streamed) and fills through the staged upload (TitleImageUpload, no host image copy for it) had its T#s bound in the bindless set from its first view on (register_bound_texture at creation, tracker layout UNDEFINED). Its first upload runs later:

  • always with LEONIDA_TITLE_FILL_ASYNC=1: the view queues the fill for the worker and writes the descriptor at once;
  • in the default inline mode whenever the first fill is skipped (pages not readable at that moment, a guarded copy that fails, write_staged_title_image timing out on pending present work).

In that window a shader sampling the T# reads an image that was never written and is still UNDEFINED, and a draw on another queue can run while the upload's UNDEFINED -> TRANSFER_DST barrier rewrites it (TitleImageUpload::submit makes only later submissions on other queues wait for it). Reading an uninitialised image with compression metadata is the kind of thing that can fault on some GPUs.

Fix: such a texture keeps its T#s pending (pending_image_keys; they read the fallback at index 0, as a pending_stream texture's already do) until publish_streamed_texture, which fill_title_texture and the fill worker's fill_unlocked call right after the first upload has been submitted. The upload already orders every later submission behind it (image barrier on its own queue, timeline-semaphore wait on the others), so any draw that can see the image sees it uploaded. Memory is still bound at creation; only the descriptor waits. No CPU or device waits are added. LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0 restores the old behaviour for A/B runs.

Not changed: placed (slot-133) staged images and host-copy images (those are zero-filled in GENERAL at creation).

Idea from codec-d/cool_fox docs/findings.md ("a slot showed it before its upload had run", VICTORY_SHOW_AFTER), idea only, no code taken.

Overlap note: #2240 (RT-TITLE-TEXTURE-MAP-GEN) also touches the TitleTexture path (title_texture_readable) and adds a case to d3d12_existing_heap_test.cpp. The logic does not overlap (this PR changes Resource::create_texture and the fill worker); the test file may need a trivial merge in main().

Tested

  • After merging upstream/main 2859d0c9b (with #2240): the new test still passes with the fix and fails with LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0 (line 1564, !shown_early); title_memory_map, d3d12_existing_heap, d3d12_host_prefix, d3d12_mapped_plane_async, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch pass. Full suite not rerun after the merge.
  • New d3d12_title_show_after_upload (d3d12_existing_heap_test --title-show-after-upload): on a device without host image copies, with LEONIDA_TITLE_FILL_ASYNC=1 and a new test knob LEONIDA_TITLE_FILL_DELAY_MS=500 (slow fill worker), writes a slot-70 view of readable synthetic pages and checks the T# has no bindless entry before the upload and has one after it. Passes with the fix; fails with LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0 (the old behaviour: "the T# names the image before its upload"). Also passes with LEONIDA_VK_VALIDATION=1 (no validation errors; the Khronos layer reports objects still alive at vkDestroyDevice in this mode, with or without the fix, because the retired test texture is released by the 3 s retirement sweep, after the test ends).
    Synchronization validation cannot see a bindless read of an UNDEFINED image, so the test checks the ordering through the bindless table instead.
  • d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch, d3d12_host_prefix, d3d12_mapped_plane_async: pass.
  • Full runtime suite: ctest -j 4 while a boot ran on the same GPU: 472 of 478 passed. 4 of the 6 failures were timeouts/flakes under that load and pass when rerun alone (xs_proxy_mock, d3d12_queue_wait_timeout, d3d12_queue_list_type, d3d12_sparse_queue_family_contract). xbox_present (present VkResult -11) and d3d12_set_descriptor_heaps (line 353, recorded_commands) fail the same way with upstream/main's d3d12_vulkan_device.cpp built in the same tree, so they are not from this change.
  • No game data; synthetic pages only.

Update after lixonik's review (e6fa5544f): the deferral also covers streamed textures that are neither staged nor host-transfer, which are filled through WriteToSubresource's waited staging copy and also start UNDEFINED. New test d3d12_title_show_after_upload_unstaged (LEONIDA_TITLE_IMAGE_STAGING=0, no host image copy) fails with the old condition (2/2 runs) and passes with the change (3/3). LEONIDA_TITLE_SHOW_AFTER_UPLOAD is now in runtime/README.md.

GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 (profile M: RTX 4070 SUPER 12 GB desktop)

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

Claimed in the coordination issue as: `RT-TITLE-TEXTURE-SHOW-AFTER-UPLOAD` (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185889059) ### What and why A slot-70 texture the layer makes itself (`make_title_texture`, `TitleImageOrigin::streamed`) and fills through the staged upload (`TitleImageUpload`, no host image copy for it) had its T#s bound in the bindless set from its first view on (`register_bound_texture` at creation, tracker layout `UNDEFINED`). Its first upload runs later: - always with `LEONIDA_TITLE_FILL_ASYNC=1`: the view queues the fill for the worker and writes the descriptor at once; - in the default inline mode whenever the first fill is skipped (pages not readable at that moment, a guarded copy that fails, `write_staged_title_image` timing out on pending present work). In that window a shader sampling the T# reads an image that was never written and is still `UNDEFINED`, and a draw on another queue can run while the upload's `UNDEFINED -> TRANSFER_DST` barrier rewrites it (`TitleImageUpload::submit` makes only *later* submissions on other queues wait for it). Reading an uninitialised image with compression metadata is the kind of thing that can fault on some GPUs. Fix: such a texture keeps its T#s pending (`pending_image_keys`; they read the fallback at index 0, as a `pending_stream` texture's already do) until `publish_streamed_texture`, which `fill_title_texture` and the fill worker's `fill_unlocked` call right after the first upload has been submitted. The upload already orders every later submission behind it (image barrier on its own queue, timeline-semaphore wait on the others), so any draw that can see the image sees it uploaded. Memory is still bound at creation; only the descriptor waits. No CPU or device waits are added. `LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0` restores the old behaviour for A/B runs. Not changed: placed (slot-133) staged images and host-copy images (those are zero-filled in `GENERAL` at creation). Idea from codec-d/cool_fox `docs/findings.md` ("a slot showed it before its upload had run", `VICTORY_SHOW_AFTER`), idea only, no code taken. Overlap note: #2240 (RT-TITLE-TEXTURE-MAP-GEN) also touches the TitleTexture path (`title_texture_readable`) and adds a case to `d3d12_existing_heap_test.cpp`. The logic does not overlap (this PR changes `Resource::create_texture` and the fill worker); the test file may need a trivial merge in `main()`. ### Tested - After merging `upstream/main` 2859d0c9b (with #2240): the new test still passes with the fix and fails with `LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0` (line 1564, `!shown_early`); `title_memory_map`, `d3d12_existing_heap`, `d3d12_host_prefix`, `d3d12_mapped_plane_async`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch` pass. Full suite not rerun after the merge. - New `d3d12_title_show_after_upload` (`d3d12_existing_heap_test --title-show-after-upload`): on a device without host image copies, with `LEONIDA_TITLE_FILL_ASYNC=1` and a new test knob `LEONIDA_TITLE_FILL_DELAY_MS=500` (slow fill worker), writes a slot-70 view of readable synthetic pages and checks the T# has no bindless entry before the upload and has one after it. Passes with the fix; **fails** with `LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0` (the old behaviour: "the T# names the image before its upload"). Also passes with `LEONIDA_VK_VALIDATION=1` (no validation errors; the Khronos layer reports objects still alive at `vkDestroyDevice` in this mode, with or without the fix, because the retired test texture is released by the 3 s retirement sweep, after the test ends). Synchronization validation cannot see a bindless read of an `UNDEFINED` image, so the test checks the ordering through the bindless table instead. - `d3d12_existing_heap`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`, `d3d12_host_prefix`, `d3d12_mapped_plane_async`: pass. - Full runtime suite: `ctest -j 4` while a boot ran on the same GPU: 472 of 478 passed. 4 of the 6 failures were timeouts/flakes under that load and pass when rerun alone (`xs_proxy_mock`, `d3d12_queue_wait_timeout`, `d3d12_queue_list_type`, `d3d12_sparse_queue_family_contract`). `xbox_present` (present VkResult -11) and `d3d12_set_descriptor_heaps` (line 353, `recorded_commands`) fail the same way with `upstream/main`'s `d3d12_vulkan_device.cpp` built in the same tree, so they are not from this change. - No game data; synthetic pages only. Update after lixonik's review (e6fa5544f): the deferral also covers streamed textures that are neither staged nor host-transfer, which are filled through `WriteToSubresource`'s waited staging copy and also start `UNDEFINED`. New test `d3d12_title_show_after_upload_unstaged` (`LEONIDA_TITLE_IMAGE_STAGING=0`, no host image copy) fails with the old condition (2/2 runs) and passes with the change (3/3). `LEONIDA_TITLE_SHOW_AFTER_UPLOAD` is now in `runtime/README.md`. GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 (profile M: RTX 4070 SUPER 12 GB desktop) 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. - [ ] 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)
Tyrannys commented 2026-11-27 12:15:52 +00:00

Full runtime suite after the main merge (9fa1a8ee9, RTX 4070 SUPER, profile M): 490 of 492 pass; the 2 failures (xbox_present: present VkResult -11, d3d12_set_descriptor_heaps: line 353 recorded_commands) fail identically with plain main 2859d0c9b's d3d12_vulkan_device.cpp built in the same tree, so none come from this PR. AI-assisted (Claude Code).

Full runtime suite after the main merge (9fa1a8ee9, RTX 4070 SUPER, profile M): 490 of 492 pass; the 2 failures (`xbox_present`: present VkResult -11, `d3d12_set_descriptor_heaps`: line 353 `recorded_commands`) fail identically with plain main 2859d0c9b's `d3d12_vulkan_device.cpp` built in the same tree, so none come from this PR. AI-assisted (Claude Code).
lixonik reviewed 2026-11-27 15:48:24 +00:00
lixonik left a comment
No description provided.
Reviewed and locally tested at `9fa1a8ee9` (merged cleanly onto `main` `ec91d695c`). ### Verification - Environment: Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341; `VK_LAYER_KHRONOS_validation` not installed locally). - `ctest`: `d3d12_title_show_after_upload`, `d3d12_existing_heap`, and `d3d12_mapped_plane_async` all passed (3/3). - `scripts/check_no_game_data.py` and `git diff --check`: clean. ### Review notes - The deferral hooks cleanly into the existing `pending_image_keys` / `publish_streamed_texture()` flow: placing the check after the `mem-probe` block preserves diagnostics, changing the final return to `deferred_stream_ && deferred_bytes_ ? S_OK : register_bound_texture()` ensures already-backed streamed images still register in `VulkanContext` before `upload_staged_title()`, both `fill_unlocked()` and `fill_title_texture()` publish on the first successful fill (`t.owned && !t.fills`), and `~Resource()` cleans up `pending_image_keys` if retired early. - Left one non-blocking inline note about non-`staged_title_` / non-`host_transfer_` `streamed` images that also start in `VK_IMAGE_LAYOUT_UNDEFINED`. AI-assisted. **`runtime/shims/d3d12_vulkan_device.cpp` line 9290:** > Non-blocking edge case: a `TitleImageOrigin::streamed` texture can also start in `VK_IMAGE_LAYOUT_UNDEFINED` when both `host_transfer_` and `staged_title_` are `false` -- e.g., `rgb96` formats, a color format on a host-image-copy-capable GPU that lacks `VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT`, `LEONIDA_TITLE_IMAGE_STAGING=0`, or a `retry_host()` fallback when `host_image_copy` is unavailable. Those images are filled via `upload_title_subresource()` in `fill_title_texture()` (which already calls `publish_streamed_texture()` when `t.owned && !t.fills`), so checking `!host_transfer_` instead of `staged_title_` would cover them too if desired. > > Also, adding `LEONIDA_TITLE_SHOW_AFTER_UPLOAD` to the env-var table in `runtime/README.md` would keep the docs in sync.
Tyrannys reviewed 2026-11-27 16:15:31 +00:00
Tyrannys left a comment
No description provided.
**`runtime/shims/d3d12_vulkan_device.cpp` line 9290:** > Thanks @lixonik, good find. Covered in e6fa5544f: the deferral now keys on `!host_transfer_` instead of `staged_title_`. Those textures are filled through `WriteToSubresource`'s staging copy, which is submitted and waited for, and `fill_title_texture` / the fill worker already call `publish_streamed_texture()` after the first fill, so they are shown once filled, like the staged ones. Host-transfer images start in `GENERAL` and are filled on the host, so they are still shown at once. > > New test `d3d12_title_show_after_upload_unstaged` (`LEONIDA_TITLE_IMAGE_STAGING=0` on a device without host image copy, so the texture is neither staged nor host-copied): > - with the old condition, the T# names the image before its fill (2/2 runs); > - with the change, it is hidden until the fill worker's upload, then shown (3/3 runs). > > One case from the list can't reach this path: a 96-bit (`R32G32B32_FLOAT`) slot-70 view is a null view, because the XG model lacks the format, so no streamed texture is made for it. > > `LEONIDA_TITLE_SHOW_AFTER_UPLOAD` is now in the README env table too. RTX 4070 SUPER, 621.01, Windows 11: 12/12 related tests pass (`existing_heap|title_texture|placed|mapped_plane|show_after`). AI-assisted (Claude Code).
lixonik approved these changes 2026-11-27 20:09:26 +00:00
lixonik left a comment

Re-reviewed e6fa5544f and tested on RTX 5070:

  • Keying deferral on !host_transfer_ instead of staged_title_ cleanly covers streamed slot-70 textures that start UNDEFINED and fill through WriteToSubresource's waited staging copy (formats without host-image transfer, LEONIDA_TITLE_IMAGE_STAGING=0, or retry_host fallback), while host-transfer images remain shown immediately. LEONIDA_TITLE_SHOW_AFTER_UPLOAD is also documented in runtime/README.md.
  • Tested on NVIDIA GeForce RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341, MSVC 19.44; VK_LAYER_KHRONOS_validation not installed locally):
    • d3d12_title_show_after_upload: passed (0.73 s).
    • d3d12_title_show_after_upload_unstaged: passed (0.69 s).

Looks good to merge.

AI-assisted (Antigravity, Gemini).

Re-reviewed `e6fa5544f` and tested on RTX 5070: - Keying deferral on `!host_transfer_` instead of `staged_title_` cleanly covers streamed slot-70 textures that start `UNDEFINED` and fill through `WriteToSubresource`'s waited staging copy (formats without host-image transfer, `LEONIDA_TITLE_IMAGE_STAGING=0`, or `retry_host` fallback), while host-transfer images remain shown immediately. `LEONIDA_TITLE_SHOW_AFTER_UPLOAD` is also documented in `runtime/README.md`. - Tested on NVIDIA GeForce RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341, MSVC 19.44; `VK_LAYER_KHRONOS_validation` not installed locally): - `d3d12_title_show_after_upload`: passed (0.73 s). - `d3d12_title_show_after_upload_unstaged`: passed (0.69 s). Looks good to merge. AI-assisted (Antigravity, Gemini).
zmasi commented 2026-11-28 23:57:15 +00:00

#2267 | head e6fa5544f9a3c2c28f38e1175eabba903342be7d (merged cleanly with main ba8b77b390b278cfb05510a4fc2922fb0fb9a11c — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_title_show_after_upload|d3d12_title_show_after_upload_unstaged|d3d12_host_prefix|d3d12_mapped_plane_async)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red (LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0): both d3d12_title_show_after_upload and d3d12_title_show_after_upload_unstaged fail at line 1574: !shown_early (the T# names the image before its upload) | green on PR+main (with 1 doc-test CI note): 4/4 CTests (d3d12_title_show_after_upload, d3d12_title_show_after_upload_unstaged, d3d12_host_prefix, d3d12_mapped_plane_async) pass in 2.72 s on RTX 3090 (0 vk.validation_errors(); expected vkDestroyDevice 3 s retirement-sweep notice noted in PR body), and check_no_game_data.py (0 violations), test_docs_encoding.py, and test_docs_repo_paths.py pass — CI note: python -m unittest tests/test_docs_env_vars.py fails test_every_variable_is_named_in_a_document because the new test knob LEONIDA_TITLE_FILL_DELAY_MS (runtime/shims/d3d12_vulkan_device.cpp) is not yet mentioned in .md docs (e.g. runtime/README.md or docs/d3d12_vulkan.md) or TEST_ONLY in tests/test_docs_env_vars.py | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2267 | head e6fa5544f9a3c2c28f38e1175eabba903342be7d (merged cleanly with main ba8b77b390b278cfb05510a4fc2922fb0fb9a11c — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_title_show_after_upload|d3d12_title_show_after_upload_unstaged|d3d12_host_prefix|d3d12_mapped_plane_async)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red (`LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0`): both `d3d12_title_show_after_upload` and `d3d12_title_show_after_upload_unstaged` fail at `line 1574: !shown_early` (`the T# names the image before its upload`) | green on PR+main (with 1 doc-test CI note): `4/4` CTests (`d3d12_title_show_after_upload`, `d3d12_title_show_after_upload_unstaged`, `d3d12_host_prefix`, `d3d12_mapped_plane_async`) pass in `2.72 s` on RTX 3090 (`0` `vk.validation_errors()`; expected `vkDestroyDevice` 3 s retirement-sweep notice noted in PR body), and `check_no_game_data.py` (`0` violations), `test_docs_encoding.py`, and `test_docs_repo_paths.py` pass — **CI note**: `python -m unittest tests/test_docs_env_vars.py` fails `test_every_variable_is_named_in_a_document` because the new test knob `LEONIDA_TITLE_FILL_DELAY_MS` (`runtime/shims/d3d12_vulkan_device.cpp`) is not yet mentioned in `.md` docs (e.g. `runtime/README.md` or `docs/d3d12_vulkan.md`) or `TEST_ONLY` in `tests/test_docs_env_vars.py` | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 reviewed 2026-11-29 04:27:38 +00:00
timbot103 left a comment
No description provided.
Static audit of `e6fa5544f` against the patch base and the supplied `main` snapshot. No builds, tests, or GPU runs. - **[MAJOR] `runtime/shims/d3d12_vulkan_device.cpp:9293`** — The unstaged fallback still publishes early if the source pages are unreadable on the first view. With host image copy unavailable and `LEONIDA_TITLE_IMAGE_STAGING=0`, the default image deferral chooses `pending_stream`. The branch at line 9190 only inserts a pending key for that origin when host transfer or dedicated title staging is available, and the new guard only covers `streamed`. This leaves a bindless SRV for an `UNDEFINED` image while the fill is skipped. Please use the existing `stream` predicate here and add a case that starts with uncommitted pages, commits them, and verifies that the original T# becomes visible after the fill. - **[MINOR] `runtime/shims/d3d12_vulkan_device.cpp:16027`** — `LEONIDA_TITLE_FILL_DELAY_MS` is a runtime string literal with no tracked Markdown entry, so `tests/test_docs_env_vars.py` will flag it in CI. Please document the default and test purpose in `runtime/README.md`. - **[MINOR] `runtime/test/d3d12_existing_heap_test.cpp:1534`** — A device without bindless support reports a pass before either test checks visibility. Also, the staged case inherits the staging setting and can fall back to the waited copy path. Please report a CTest skip when prerequisites are missing and verify each mode exercised its intended upload path. - **[MINOR] `runtime/test/d3d12_existing_heap_test.cpp:1567`** — The 500 ms delay lets the worker finish first if the test thread is delayed, so the early assertion can fail with correct publication. A test-controlled gate before upload would make both visibility assertions deterministic. On the paths that enter deferral, failed fills leave the keys pending. The patch base publishes after the full upload succeeds, and the supplied `main` snapshot also gates partial-chain publication by the view's first mip. The descriptor lock protects key rebinding, and the staged uploader orders later submissions on the upload queue and on other queues. RTV, DSV, UAV, and resource-handle CopyDest operations use explicit resources. The new CTests are inside the Windows test block. AI-assisted.
aslan2142 commented 2026-12-01 16:43:21 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.