Skip to content

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

Open
Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-title-texture-show-after-upload
Open

Tyrannys wants to merge 3 commits into
ProjectLeonida:mainfrom
Tyrannys:rt-title-texture-show-after-upload

Conversation

@Tyrannys

@Tyrannys Tyrannys commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-TITLE-TEXTURE-SHOW-AFTER-UPLOAD (#1608 (comment))

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 2859d0c (with d3d12,xmem: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN) #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 (e6fa554): 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

…TITLE-TEXTURE-SHOW-AFTER-UPLOAD)

A slot-70 texture the layer makes itself (TitleImageOrigin::streamed) and fills
through the staged upload had its T#s bound in the bindless set from its first
view on. A draw before the first fill (always with LEONIDA_TITLE_FILL_ASYNC=1,
and whenever an inline fill is skipped) sampled an image never written and still
in UNDEFINED layout, and a draw on another queue could overlap the upload's
UNDEFINED -> TRANSFER_DST transition of it.

Such a texture now keeps its T#s pending (they read the fallback at index 0)
until publish_streamed_texture, which runs after the first upload has been
submitted. TitleImageUpload::submit already orders every later submission
behind that upload (an image barrier on its queue, a timeline wait on the
others), so a draw that can see the image sees it uploaded. Memory is still
bound at creation; only the descriptor waits. LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0
restores the old behaviour.

Idea from codec-d/cool_fox docs/findings.md (VICTORY_SHOW_AFTER); idea only,
no code taken.

Test: d3d12_title_show_after_upload (LEONIDA_TITLE_FILL_ASYNC=1 with a new
LEONIDA_TITLE_FILL_DELAY_MS slow fill worker) checks the T# has no bindless
entry before the upload and has one after it. It fails with
LEONIDA_TITLE_SHOW_AFTER_UPLOAD=0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ow-after-upload

# Conflicts:
#	runtime/test/d3d12_existing_heap_test.cpp
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
@Tyrannys

Copy link
Copy Markdown
Contributor Author

Full runtime suite after the main merge (9fa1a8e, 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 2859d0c's d3d12_vulkan_device.cpp built in the same tree, so none come from this PR. AI-assisted (Claude Code).

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread runtime/shims/d3d12_vulkan_device.cpp Outdated
const char* value = std::getenv("LEONIDA_TITLE_SHOW_AFTER_UPLOAD");
return !value || std::strcmp(value, "0");
}();
if (show_after_upload && origin == TitleImageOrigin::streamed && staged_title_ && !deferred_stream_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lixonik, good find. Covered in e6fa554: 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).

… copy

A slot-70 streamed texture that is neither staged nor host-transfer
(a format without host-image transfer, LEONIDA_TITLE_IMAGE_STAGING=0 on a
device without host copies, the retry_host fallback there) also starts
UNDEFINED. It is filled through WriteToSubresource's waited staging copy,
and fill_title_texture already publishes it after the first fill. The
deferral now keys on !host_transfer_ instead of staged_title_, so these
textures read the fallback until that fill too. Host-transfer images are
made GENERAL and filled on the host, and are still shown at once.

New test d3d12_title_show_after_upload_unstaged (LEONIDA_TITLE_IMAGE_STAGING=0,
no host image copy): its T# named the image before the fill with the old
condition (2/2 runs), and is hidden until the fill worker's upload with
the new one (3/3). LEONIDA_TITLE_SHOW_AFTER_UPLOAD is now in the README's
environment table.

From lixonik's review of ubiquitarianism#2267.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants