d3d12: give a large shader-visible heap no more slots than the heap bitmaps name #632

Merged
NickStallman merged 1 commit from upstream-pr/632 into main 2026-12-01 20:52:14 +00:00
NickStallman commented 2026-12-01 17:57:30 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-01T17:57:30Z.


What goes wrong (shown in a unit test, not in a game run)

Translated programs that index the resource heap record the host heap index of each image view they read, and of each store, in the heap bitmap (tuxbox_dxbc::heap_writes). The bitmap names indices below SLOTS (1,048,575). tb_note_heap_read records a higher index only as bit 0, unknown. In stamp_reads an unknown read only counts toward the "past" total and stamps no texture. Read residency, on by default since e40d8052, keeps a texture only when a read names it, so a texture read only through such an index is never kept, backed or refreshed. An unknown store publishes every writable candidate, which is correct but costly.

Such indices exist when the host's shader-visible heap is larger than the bitmap. create_heap gives a title heap over 1,000,000 descriptors the driver's MaxViewDescriptorHeapSize. vkd3d-proton reports 16,000,000 when it uses VK_EXT_descriptor_heap with a GPU upload heap (resizable BAR). ProjectScarlett asks for 1,245,184 descriptors, so its tables (or the heap itself, where no arena is made) can sit past 1,048,575. On an RX 9070 XT this heap was the 500,128 KiB BAR allocation traced in #292, which is 16,000,000 x 32 bytes plus 128 KiB. NVIDIA reports 1,000,000 and is not affected.

Change

A shader-visible CBV/SRV/UAV heap over 1,000,000 descriptors gets clamp(driver limit, 1,000,000, heap_writes::SLOTS) host slots. The title's tables are paged into them as on NVIDIA. On the hosts above the descriptor heap falls from about 488 MiB to about 32 MiB of BAR memory. TUXBOX_DESCRIPTOR_HEAP_LIMIT still lowers the count. One log line per such heap gives the title's count, the host slots and the driver's limit.

Tests

  • heap_writes::tests::a_read_at_the_last_slot_of_the_largest_host_heap_names_its_view encodes a read at the host heap's last slot the way tb_note_heap_read does, decodes it, and checks that it names that view.
    • Main has no function for the heap size, so a test-only commit (1f8530c2, on fb17e160) copies main's rule into the test. There it fails: a read at host index 15999999 is recorded only as unknown.
    • With this change it passes.
  • resources::tests::* (3): the slot policy.
  • python tuxbox.py check --no-gpu on 50d2a389: 13 passed, 0 failed. The new d3d12 tests were run on their own under GE-Proton11-15's Wine on the commit before this rebase (ae724d44, same change): 4 of 4 heap_writes and 3 of 3 resources tests passed. Full python tuxbox.py check of 50d2a389 (GE-Proton11-15): RTX 5090 (10de:2b85) 211 pass, AMD iGPU (1002:13c0) 210 pass; the one failure on each is lanes-selftest-texture-publication (#625, fails on main too). Neither card here reports the large heap limit, so these show the change breaks nothing; they don't exercise it.

Not run

ProjectScarlett on a card that reports the large limit. No card here does: our AMD iGPU's Mesa 26.0.8 has no VK_EXT_descriptor_heap, and NVIDIA reports 1,000,000. So the missing textures are inferred from the code and the unit test, not observed. On such a card the change should show in three places:

  • the type-4 allocation at device creation (VKD3D_CONFIG=log_memory_budget);
  • read residency's "past" count, which should go to zero;
  • the descriptor table eviction rate, which goes up because the tables are now paged.

Refs #533.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5591406447 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/632). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-01T17:57:30Z. --- **What goes wrong (shown in a unit test, not in a game run)** Translated programs that index the resource heap record the host heap index of each image view they read, and of each store, in the heap bitmap (`tuxbox_dxbc::heap_writes`). The bitmap names indices below `SLOTS` (1,048,575). `tb_note_heap_read` records a higher index only as bit 0, unknown. In `stamp_reads` an unknown read only counts toward the "past" total and stamps no texture. Read residency, on by default since e40d8052, keeps a texture only when a read names it, so a texture read only through such an index is never kept, backed or refreshed. An unknown store publishes every writable candidate, which is correct but costly. Such indices exist when the host's shader-visible heap is larger than the bitmap. `create_heap` gives a title heap over 1,000,000 descriptors the driver's `MaxViewDescriptorHeapSize`. vkd3d-proton reports 16,000,000 when it uses VK_EXT_descriptor_heap with a GPU upload heap (resizable BAR). ProjectScarlett asks for 1,245,184 descriptors, so its tables (or the heap itself, where no arena is made) can sit past 1,048,575. On an RX 9070 XT this heap was the 500,128 KiB BAR allocation traced in #292, which is 16,000,000 x 32 bytes plus 128 KiB. NVIDIA reports 1,000,000 and is not affected. **Change** A shader-visible CBV/SRV/UAV heap over 1,000,000 descriptors gets `clamp(driver limit, 1,000,000, heap_writes::SLOTS)` host slots. The title's tables are paged into them as on NVIDIA. On the hosts above the descriptor heap falls from about 488 MiB to about 32 MiB of BAR memory. `TUXBOX_DESCRIPTOR_HEAP_LIMIT` still lowers the count. One log line per such heap gives the title's count, the host slots and the driver's limit. **Tests** - `heap_writes::tests::a_read_at_the_last_slot_of_the_largest_host_heap_names_its_view` encodes a read at the host heap's last slot the way `tb_note_heap_read` does, decodes it, and checks that it names that view. - Main has no function for the heap size, so a test-only commit (1f8530c2, on fb17e160) copies main's rule into the test. There it fails: `a read at host index 15999999 is recorded only as unknown`. - With this change it passes. - `resources::tests::*` (3): the slot policy. - `python tuxbox.py check --no-gpu` on 50d2a389: 13 passed, 0 failed. The new d3d12 tests were run on their own under GE-Proton11-15's Wine on the commit before this rebase (ae724d44, same change): 4 of 4 heap_writes and 3 of 3 resources tests passed. Full `python tuxbox.py check` of 50d2a389 (GE-Proton11-15): RTX 5090 (`10de:2b85`) 211 pass, AMD iGPU (`1002:13c0`) 210 pass; the one failure on each is `lanes-selftest-texture-publication` (#625, fails on main too). Neither card here reports the large heap limit, so these show the change breaks nothing; they don't exercise it. **Not run** ProjectScarlett on a card that reports the large limit. No card here does: our AMD iGPU's Mesa 26.0.8 has no VK_EXT_descriptor_heap, and NVIDIA reports 1,000,000. So the missing textures are inferred from the code and the unit test, not observed. On such a card the change should show in three places: - the type-4 allocation at device creation (`VKD3D_CONFIG=log_memory_budget`); - read residency's "past" count, which should go to zero; - the `descriptor table eviction` rate, which goes up because the tables are now paged. Refs #533. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
brcly/TuxBox!632
No description provided.