d3d12: check sparse buffer memory_types before sharing the tile arena #2405

Open
github-bot wants to merge 1 commit from github-bot/gh-2405 into main AGit
Owner

@⁠pepefroge on GitHub · 2026-11-26 21:26 UTC · original
pepefroge:fix/intel-sparse-buffer-heap → main · +2 −2 · 1 files · 1 commits · open

Summary

Fixes D3D12→Vulkan sparse buffer tile mappings failing with ID3D12CommandQueue::UpdateTileMappings: invalid mapping or sparse residency unavailable on Intel Arc (reported in #725).

Root Cause

  • DeviceState::tiles_share_arena() (runtime/shims/d3d12_vulkan_device.cpp:3536) only checks whether arena.memory_type overlaps the device-init probe sparse_buffer_memory_types.
  • On Intel Arc Windows Vulkan drivers (32.0.101.9150), an actual reserved buffer's requirements.memoryTypeBits can exclude arena.memory_type (e.g., requiring non-ReBAR DEVICE_LOCAL memory rather than the arena's DEVICE_LOCAL | HOST_VISIBLE type).
  • Heap::tiles() (line 9625) still took the arena fast-path, causing VulkanQueue::bind_tiles() (runtime/src/vulkan_backend.h:4164) to reject the binding (!(resource->memory_types & (1u << page.heap->memory_type))).
  • Additionally, Heap::tiles() (line 9636) previously overwrote the caller's memory_types with sparse_buffer_memory_types unconditionally instead of intersecting when overlapping.

Changes

  • Guard the arena fast-path in Heap::tiles() (runtime/shims/d3d12_vulkan_device.cpp:9625) with (memory_types & (1u << device_.arena.memory_type)).
  • Narrow memory_types via &= (line 9636) only when it overlaps device_.sparse_buffer_memory_types, preserving the caller's memoryTypeBits otherwise.

Verification (Intel Arc Pro B60, BMG-G21, Driver 32.0.101.9150)

  • Before: d3d12_buffer_tiles_test failed UpdateTileMappings on every mapped buffer tile (0/12 tiles).
  • After (f0b86e1):
    Vulkan replay: 12 full tiles matched across aliased, skipped, unmapped, reused and remapped ranges
    A rejected update left all tile mappings intact
    
    (Note: the subsequent native D3D12 comparison pass in d3d12_buffer_tiles_test still hits Intel's native D3D12 driver CopyTiles behavior noted in #725, while the Vulkan replay side now passes 12/12 tiles).

Tested on Intel Arc Pro B60 (0xe211, Windows 11, driver 32.0.101.9150); root-cause trace assisted locally via Hermes + Qwen 3.8 27B.

**@⁠pepefroge** on GitHub · 2026-11-26 21:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2405) `pepefroge:fix/intel-sparse-buffer-heap` → `main` · +2 −2 · 1 files · 1 commits · open ### Summary Fixes D3D12→Vulkan sparse buffer tile mappings failing with `ID3D12CommandQueue::UpdateTileMappings: invalid mapping or sparse residency unavailable` on Intel Arc (reported in #725). ### Root Cause - `DeviceState::tiles_share_arena()` (`runtime/shims/d3d12_vulkan_device.cpp:3536`) only checks whether `arena.memory_type` overlaps the device-init probe `sparse_buffer_memory_types`. - On Intel Arc Windows Vulkan drivers (`32.0.101.9150`), an actual reserved buffer's `requirements.memoryTypeBits` can exclude `arena.memory_type` (e.g., requiring non-ReBAR `DEVICE_LOCAL` memory rather than the arena's `DEVICE_LOCAL | HOST_VISIBLE` type). - `Heap::tiles()` (`line 9625`) still took the arena fast-path, causing `VulkanQueue::bind_tiles()` (`runtime/src/vulkan_backend.h:4164`) to reject the binding (`!(resource->memory_types & (1u << page.heap->memory_type))`). - Additionally, `Heap::tiles()` (`line 9636`) previously overwrote the caller's `memory_types` with `sparse_buffer_memory_types` unconditionally instead of intersecting when overlapping. ### Changes - Guard the arena fast-path in `Heap::tiles()` (`runtime/shims/d3d12_vulkan_device.cpp:9625`) with `(memory_types & (1u << device_.arena.memory_type))`. - Narrow `memory_types` via `&=` (`line 9636`) only when it overlaps `device_.sparse_buffer_memory_types`, preserving the caller's `memoryTypeBits` otherwise. ### Verification (Intel Arc Pro B60, BMG-G21, Driver `32.0.101.9150`) - Before: `d3d12_buffer_tiles_test` failed `UpdateTileMappings` on every mapped buffer tile (`0/12` tiles). - After (`f0b86e1`): ```text Vulkan replay: 12 full tiles matched across aliased, skipped, unmapped, reused and remapped ranges A rejected update left all tile mappings intact ``` *(Note: the subsequent native D3D12 comparison pass in `d3d12_buffer_tiles_test` still hits Intel's native D3D12 driver `CopyTiles` behavior noted in #725, while the Vulkan replay side now passes 12/12 tiles).* --- *Tested on Intel Arc Pro B60 (`0xe211`, Windows 11, driver `32.0.101.9150`); root-cause trace assisted locally via Hermes + Qwen 3.8 27B.*
tiles_share_arena() only checked the device-init probe sparse_buffer_memory_types against arena.memory_type, which could differ from an actual sparse buffer's memoryTypeBits on Intel Arc, causing bind_tiles() line 4164 to reject the mapping.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:35:16 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 22:48 UTC · original

There is one same-heap case where Heap::tiles() rejects a compatible second buffer at f0b86e1938.

Request on one heap Allowed memory types Result
Buffer A, with an empty heap Type 1 only (0x02) Gets dedicated backing of type 1
Buffer B, with A’s backing still live Types 1 and 4 (0x12), arena type 4 Returns null even though B accepts the existing type 1 backing

CPU check. I compiled the PR’s Heap::tiles() method with a mock allocator and a device probe mask of 0x12. The second call enters the arena branch and returns at if (tile_allocation_) return {};. Checking for an existing buffer tile allocation whose memory type is in the caller’s mask before considering the arena made the second call return the same allocation. All seven cases then matched expectations, including incompatible masks and buffer/image separation. It would be worth adding the two-call sequence above as a regression test.

RTX 4090 check. The unmodified PR passed d3d12_buffer_tiles on Windows 11, NVIDIA 616.64. Vulkan matched all 12 expected tiles and native D3D12 on the same card matched all three readbacks. This driver reported 0x02 for both sparse buffers and the initialization probe, with arena type 4, so it exercised the dedicated-only path. The mixed-mask finding above comes from the CPU fixture. AI-assisted verification.

**@⁠ecox982745** on GitHub · 2026-11-26 22:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2405#issuecomment-7204997731) There is one same-heap case where `Heap::tiles()` rejects a compatible second buffer at `f0b86e1938`. | Request on one heap | Allowed memory types | Result | | --- | --- | --- | | Buffer A, with an empty heap | Type 1 only (`0x02`) | Gets dedicated backing of type 1 | | Buffer B, with A’s backing still live | Types 1 and 4 (`0x12`), arena type 4 | Returns null even though B accepts the existing type 1 backing | **CPU check.** I compiled the PR’s `Heap::tiles()` method with a mock allocator and a device probe mask of `0x12`. The second call enters the arena branch and returns at `if (tile_allocation_) return {};`. Checking for an existing *buffer* tile allocation whose memory type is in the caller’s mask before considering the arena made the second call return the same allocation. All seven cases then matched expectations, including incompatible masks and buffer/image separation. It would be worth adding the two-call sequence above as a regression test. **RTX 4090 check.** The unmodified PR passed `d3d12_buffer_tiles` on Windows 11, NVIDIA 616.64. Vulkan matched all 12 expected tiles and native D3D12 on the same card matched all three readbacks. This driver reported `0x02` for both sparse buffers and the initialization probe, with arena type 4, so it exercised the dedicated-only path. The mixed-mask finding above comes from the CPU fixture. AI-assisted verification.
Author
Owner

@⁠BadgersMC on GitHub · 2026-11-27 01:23 UTC · original

Independent native Windows check (Profile M): RTX 3060 Ti desktop, 8 GB VRAM, NVIDIA 610.88, 16 GB RAM, MSVC 19.44. Compared the GitHub target base fac8b4bb with only the PR diff from f0b86e19 applied to that base. Same d3d12_buffer_tiles fixture, default 256 MiB arena, and Vulkan validation in both builds.

  • Base 3/3, PR diff 3/3. Each run matched all 12 Vulkan tiles and the three native D3D12 readbacks. The test's rejected update left the mappings intact.
  • Zero Vulkan validation errors. A separate patched replay with Vulkan loader logging confirmed VK_LAYER_KHRONOS_validation was loaded and passed.
  • This covers the existing tile fixture on Ampere. The mixed-memory-type same-heap case needs its own fixture. No game files used. AI-assisted (Codex).
**@⁠BadgersMC** on GitHub · 2026-11-27 01:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2405#issuecomment-7207248549) Independent native Windows check (Profile M): RTX 3060 Ti desktop, 8 GB VRAM, NVIDIA 610.88, 16 GB RAM, MSVC 19.44. Compared the GitHub target base `fac8b4bb` with only the PR diff from `f0b86e19` applied to that base. Same `d3d12_buffer_tiles` fixture, default 256 MiB arena, and Vulkan validation in both builds. - Base **3/3**, PR diff **3/3**. Each run matched all **12 Vulkan tiles** and the **three native D3D12 readbacks**. The test's rejected update left the mappings intact. - Zero Vulkan validation errors. A separate patched replay with Vulkan loader logging confirmed `VK_LAYER_KHRONOS_validation` was loaded and passed. - This covers the existing tile fixture on Ampere. The [mixed-memory-type same-heap case](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/2405) needs its own fixture. No game files used. AI-assisted (Codex).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-27 03:29 UTC · original

Your B60 result and BadgersMC’s NVIDIA result leave a useful independent comparison: does the same public fixture recover Vulkan tile mapping on the Alchemist A770 from #725? I opened one pinned Test Lab request and offered that specific pair to the A770 reporter. The request keeps Vulkan replay and native D3D12 outcomes separate and leaves the reported second-buffer/same-heap case for its own fixture. I’ll link any completed A770 result here with its original author.

**@⁠akimfomin** on GitHub · 2026-11-27 03:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2405#issuecomment-7209028391) Your B60 result and BadgersMC’s NVIDIA result leave a useful independent comparison: does the same public fixture recover Vulkan tile mapping on the Alchemist A770 from #725? I opened [one pinned Test Lab request](https://github.com/akimfomin/PortBridge/issues/117) and offered that specific pair to the A770 reporter. The request keeps Vulkan replay and native D3D12 outcomes separate and leaves the reported second-buffer/same-heap case for its own fixture. I’ll link any completed A770 result here with its original author.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2405/head:github-bot/gh-2405'
git switch 'github-bot/gh-2405'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2405'
git switch 'github-bot/gh-2405'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2405'
git switch 'github-bot/gh-2405'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2405'
git switch 'main'
git merge --squash 'github-bot/gh-2405'
git switch 'main'
git merge --ff-only 'github-bot/gh-2405'
git switch 'main'
git merge 'github-bot/gh-2405'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.