Skip to content

Runtime: per-type descriptor slot sizes and heap handles (P0/P1) - #333

Closed
kontaktjakubjagiello wants to merge 1 commit into
ProjectLeonida:mainfrom
kontaktjakubjagiello:feature/d3d12-descriptor-p0
Closed

kontaktjakubjagiello wants to merge 1 commit into
ProjectLeonida:mainfrom
kontaktjakubjagiello:feature/d3d12-descriptor-p0

Conversation

@kontaktjakubjagiello

Copy link
Copy Markdown

Why

GetDescriptorHandleIncrementSize returned one constant for every heap type, a heap had no stride of its own, and
CopyDescriptors/CopyDescriptorsSimple walked handles with that constant. A sampler, RTV/DSV and CBV/SRV/UAV heap
are allowed to diverge, and a CPU handle that leaves its heap could be copied from arbitrary memory.

What

  • runtime/src/descriptor_sizes.h: per-type slot table (T# 32 B, S# 32 B, RTV/DSV 32 B, unknown type 0).
    CreateDescriptorHeap rejects a type with no slot size; GetDescriptorHandleIncrementSize answers per type.
  • DescriptorHeap keeps its own stride, slot count and base, registers in DeviceState, unregisters on destruction.
  • runtime/src/descriptor_handles.h: slot_index, slot_run_bytes, DirtyRange/merge, copy_slots_between.
  • CopyDescriptors/CopyDescriptorsSimple resolve both heaps from the registry, copy with the destination heap's
    stride, clamp to the heap, and mark the copied slots dirty for the bindless scan.

Tests

  • descriptor_increment and descriptor_handles (CPU, no Vulkan, no game data), including a copy between two
    distinct heaps.
  • ctest: 20/20. d3d12_vulkan_device_test and d3d12_com_test pass on an RTX 5080 Laptop (621.14).
  • No game data, no keys, no network.

Follow-up to #230, which kept the single constant; tracked in #156.

P0: GetDescriptorHandleIncrementSize answers per heap type, CreateDescriptorHeap rejects an unknown type, DescriptorHeap keeps its own stride and slot count, and a device-wide heap registry maps a CPU handle back to its heap. P1: CopyDescriptors/CopyDescriptorsSimple resolve both heaps, use the destination heap's stride, clamp to the heap, and mark the copied slots dirty for the bindless scan. CPU tests: descriptor_increment (table, TargetView payload, invalid type) and descriptor_handles (slot math, overflow, dirty ranges, a copy between two heaps). ctest 17/17 and d3d12_vulkan_device_test/d3d12_com_test pass on an RTX 5080.
@CharlyRien

Copy link
Copy Markdown

Tested b9c6b61 (merged on current main 8bd0087) on RTX 3090, driver 616.56, Windows 11: fail. d3d12_descriptor_test, which is already on main and passes there, now fails. ctest 17/17 and run_gpu_tests.py (32/56 passed, 24 skipped) are fine. CI hasn't run on this branch yet, which is why it didn't show up.

line 91: holds(3, 0) && holds(4, 1) && holds(0, 2)

CopyDescriptorsSimple still passes. Only the multi-range CopyDescriptors case fails: destination ranges {3, 4} and {0}, source ranges {0} and {1, 2}.

Cause: in CopyDescriptors (runtime/shims/d3d12_vulkan_device.cpp, around line 590), d_slot and s_slot come from slot_of(destinations[d].ptr) and slot_of(sources[s].ptr). Those are the start of each range, and the position inside it (d_at, s_at) is never added. The first copy (3 ← 0) is right. After it, the source moves to its second range, but the destination stays in range 0 with d_at = 1, and the next copy writes slot 3 again (3 ← 1) instead of slot 4. Using d_slot + d_at and s_slot + s_at (after slot_of) should fix it. The single-range CopyDescriptorsSimple path never has a non-zero offset, which is why it passes.

#334 contains this commit and fails the same line (checked at 542d5f6).

AI-assisted test run and analysis; synthetic tests only, no game files.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested b9c6b61 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: d3d12_descriptor_test fails. It passes on main (8bd0087), so this comes from the PR, not a flake.

  • Clean RelWithDebInfo Ninja build, ctest --test-dir runtime/build --output-on-failure: 17/17 passed.
  • With LEONIDA_VK_VALIDATION=1: d3d12_vulkan_device_test, d3d12_com_test and vk_command_replay_test pass with 0 validation messages. d3d12_descriptor_test exits 1:
    line 91: holds(3, 0) && holds(4, 1) && holds(0, 2)
    

Cause: in CopyDescriptors (runtime/shims/d3d12_vulkan_device.cpp:603), d_slot/s_slot are looked up from the start of the current range, and d_at/s_at are never added. When a range is copied in more than one chunk, the second chunk goes back to the range's first slot. In the test's case (destination ranges {3,4},{0}, source ranges {0},{1,2}) that writes 3←0 and then 3←1, instead of 4←1.

Passing d_slot + d_at / s_slot + s_at to copy_slots_between and mark_dirty(d_slot + d_at, copied) (line 613) fixes it. With that 3-line change applied locally, d3d12_descriptor_test passes and ctest is still green.

No game files used. AI-assisted run (Claude Code).

@kontaktjakubjagiello

Copy link
Copy Markdown
Author

Relevant to this PR: multi-range CopyDescriptors was copying every range at its handle's first slot, so the second pass overwrote the first. Fixed on #335 (b22834d): d_slot+d_at / s_slot+s_at in copy_slots_between and mark_dirty. d3d12_descriptor_test passes on Windows 11.

@MarcPique

Copy link
Copy Markdown

I tested the 16-byte sampler stride called out in #9276 as a local single-variable follow-up to the #9276 runtime check. The Vulkan sampler heap uses 16 bytes per S# for allocation, the reported increment, both descriptor copy paths and sampler writes. The current multi-range copy still advances each individual slot.

  • d3d12_descriptor and d3d12_m2_textured: 2/2 pass on RTX 4090 and 2/2 pass on Ryzen 7800X3D Radeon Graphics, Windows 11 26200 and MSVC 19.44.35228.
  • On the RTX 4090 retail run, the 16-byte build reached its 145 s limit and at least 36,864 successful presents. The two client captures during presents were black, as with the prior 32-byte build. The sampler stride change alone is insufficient to get a visible image on this stack.

agent: yes

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.

5 participants