[PR #1458] d3d12: drop UNIFORM_BUFFER_BIT on sub-page host imports refused by 256B UBO alignment (D3D12-HOST-BUFFER-SUBPAGE-UBO) #1488

Open
opened 2026-11-26 20:21:25 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1458
Author: @robot00f
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/host-buffer-subpage-ubo


📝 Commits (1)

  • 9f85ac6 d3d12: drop UNIFORM_BUFFER_BIT on sub-page host imports refused by 256B UBO alignment

📊 Changes

2 files changed (+13 additions, -1 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+10 -0)
📝 runtime/test/d3d12_existing_heap_test.cpp (+3 -1)

📄 Description

Claimed in the coordination issue as: D3D12-HOST-BUFFER-SUBPAGE-UBO (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148550801)

What and why

On main (b4b7756e), d3d12_existing_heap fails deterministically (3/3) on NVIDIA Pascal at runtime/test/d3d12_existing_heap_test.cpp:196 during check_title_placed(device, "64 bytes into a page", pages + 64, 0x1000 - 64) (d3d12_existing_heap_test.cpp:271), where Resource::create_host_buffer returns E_NOTIMPL (0x80004001) and create_at_host_address falls back to a non-aliasing buffer.

Measured cause on NVIDIA GeForce GTX 1050 Ti (driver 582.28):

  • host_pointer_alignment = 4096, minUniformBufferOffsetAlignment = 256, minStorageBufferOffsetAlignment = 16.
  • Resource::create_host_buffer (runtime/shims/d3d12_vulkan_device.cpp:2077) unconditionally requests VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT.
  • On Turing+ NVIDIA GPUs (minUniformBufferOffsetAlignment = 64), a 4032-byte buffer at sub-page offset = 64 reports requirements.alignment = 64 and requirements.size = 4032, which fits in bytes = 4096.
  • On Pascal (minUniformBufferOffsetAlignment = 256), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT raises requirements.alignment from 16 to 256 and rounds requirements.size up to a multiple of 256 (4032 -> 4096, 16 -> 256). At offset = 64, both guards at d3d12_vulkan_device.cpp:2092 fail (64 % 256 != 0 and 4096 < 64 + 4096); a 16-byte UAV placed 64 bytes before the end of a page (offset = 4032, size = 16) likewise fails both checks (4032 % 256 != 0 and 4096 < 4032 + 256). Without VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, the same buffers report requirements.alignment = 16 and requirements.size = 4032 / 16.

D3D12 constant-buffer views require 256-byte address and size alignment (D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) anyway, and the layer encodes CBVs as 16-byte GFX10 raw V# descriptors (CreateConstantBufferView, d3d12_vulkan_device.cpp:6560) rather than VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.

Changes:

  • In Resource::create_host_buffer (runtime/shims/d3d12_vulkan_device.cpp), when (offset % requirements.alignment) || requirements.size > bytes - offset, recreate buffer_ without VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT and re-query VkMemoryRequirements before checking the final alignment and room guards (written as requirements.size > bytes - offset to avoid unsigned addition wrap). Page-aligned and 256-byte-aligned slices keep the existing usage flags unchanged, and genuinely unaligned addresses (bytes + 1) still take the committed-buffer fallback.
  • In runtime/test/d3d12_existing_heap_test.cpp, add a 16-byte sub-page case 64 bytes from the end of the committed range ("16 bytes near the end of the range") so both the sub-256-byte offset and the 256-byte UBO size-rounding overflow past the page boundary are covered.

Tested

Built with MSVC 19.44 (Visual Studio 2022 Professional), Ninja, RelWithDebInfo, VK_LOADER_LAYERS_DISABLE=~implicit~.

Test Before (main b4b7756e) After (fix/host-buffer-subpage-ubo)
d3d12_existing_heap (3 consecutive runs) 3/3 Failed (1.18 s, 0.73 s, 0.73 s) at line 196 ("64 bytes into a page", E_NOTIMPL) 3/3 Passed (0.89 s, 0.67 s, 0.67 s), including "64 bytes into a page", "16 bytes near the end of the range", and all 8 OpenExistingHeapFromAddress parity cases against GTX 1050 Ti and WARP
Neighbor runtime tests (device_proxy, xmem, vk_host_region_import, d3d12_xmem_placed, d3d12_descriptor, d3d12_console_descriptor_heap) — 6/6 Passed (2.29 s total)

Additional checks:

  • python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_existing_heap_test.cpp (exit 0)
  • python -I tests/test_docs_links.py (16 tests, OK) and python -I tests/test_docs_table_rows.py (2 tests, OK)
  • git diff --check (exit 0)
  • Not tested: LEONIDA_VK_VALIDATION=1 (VK_LAYER_KHRONOS_validation is not installed on this machine), the full ctest suite, Windows 11, Turing+/AMD/Intel GPUs, or Linux/Wine.

GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045

AI-assisted: yes (Antigravity)

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1458 **Author:** [@robot00f](https://github.com/robot00f) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/host-buffer-subpage-ubo` --- ### 📝 Commits (1) - [`9f85ac6`](https://github.com/ubiquitarianism/leonida/commit/9f85ac6de2fda8feb0895015e2a46b7a4359a4c1) d3d12: drop UNIFORM_BUFFER_BIT on sub-page host imports refused by 256B UBO alignment ### 📊 Changes **2 files changed** (+13 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+10 -0) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+3 -1) </details> ### 📄 Description Claimed in the coordination issue as: D3D12-HOST-BUFFER-SUBPAGE-UBO (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148550801) ### What and why On `main` (`b4b7756e`), `d3d12_existing_heap` fails deterministically (3/3) on NVIDIA Pascal at `runtime/test/d3d12_existing_heap_test.cpp:196` during `check_title_placed(device, "64 bytes into a page", pages + 64, 0x1000 - 64)` (`d3d12_existing_heap_test.cpp:271`), where `Resource::create_host_buffer` returns `E_NOTIMPL` (`0x80004001`) and `create_at_host_address` falls back to a non-aliasing buffer. Measured cause on NVIDIA GeForce GTX 1050 Ti (driver 582.28): - `host_pointer_alignment = 4096`, `minUniformBufferOffsetAlignment = 256`, `minStorageBufferOffsetAlignment = 16`. - `Resource::create_host_buffer` (`runtime/shims/d3d12_vulkan_device.cpp:2077`) unconditionally requests `VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT`. - On Turing+ NVIDIA GPUs (`minUniformBufferOffsetAlignment = 64`), a 4032-byte buffer at sub-page `offset = 64` reports `requirements.alignment = 64` and `requirements.size = 4032`, which fits in `bytes = 4096`. - On Pascal (`minUniformBufferOffsetAlignment = 256`), `VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT` raises `requirements.alignment` from `16` to `256` and rounds `requirements.size` up to a multiple of `256` (`4032 -> 4096`, `16 -> 256`). At `offset = 64`, both guards at `d3d12_vulkan_device.cpp:2092` fail (`64 % 256 != 0` and `4096 < 64 + 4096`); a 16-byte UAV placed 64 bytes before the end of a page (`offset = 4032`, `size = 16`) likewise fails both checks (`4032 % 256 != 0` and `4096 < 4032 + 256`). Without `VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT`, the same buffers report `requirements.alignment = 16` and `requirements.size = 4032` / `16`. D3D12 constant-buffer views require 256-byte address and size alignment (`D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT`) anyway, and the layer encodes CBVs as 16-byte GFX10 raw `V#` descriptors (`CreateConstantBufferView`, `d3d12_vulkan_device.cpp:6560`) rather than `VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER`. Changes: - In `Resource::create_host_buffer` (`runtime/shims/d3d12_vulkan_device.cpp`), when `(offset % requirements.alignment) || requirements.size > bytes - offset`, recreate `buffer_` without `VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT` and re-query `VkMemoryRequirements` before checking the final alignment and room guards (written as `requirements.size > bytes - offset` to avoid unsigned addition wrap). Page-aligned and 256-byte-aligned slices keep the existing usage flags unchanged, and genuinely unaligned addresses (`bytes + 1`) still take the committed-buffer fallback. - In `runtime/test/d3d12_existing_heap_test.cpp`, add a 16-byte sub-page case 64 bytes from the end of the committed range (`"16 bytes near the end of the range"`) so both the sub-256-byte offset and the 256-byte UBO size-rounding overflow past the page boundary are covered. ### Tested Built with MSVC 19.44 (Visual Studio 2022 Professional), Ninja, `RelWithDebInfo`, `VK_LOADER_LAYERS_DISABLE=~implicit~`. | Test | Before (`main` `b4b7756e`) | After (`fix/host-buffer-subpage-ubo`) | |---|---|---| | `d3d12_existing_heap` (3 consecutive runs) | 3/3 **Failed** (`1.18 s`, `0.73 s`, `0.73 s`) at line 196 (`"64 bytes into a page"`, `E_NOTIMPL`) | 3/3 **Passed** (`0.89 s`, `0.67 s`, `0.67 s`), including `"64 bytes into a page"`, `"16 bytes near the end of the range"`, and all 8 `OpenExistingHeapFromAddress` parity cases against GTX 1050 Ti and WARP | | Neighbor runtime tests (`device_proxy`, `xmem`, `vk_host_region_import`, `d3d12_xmem_placed`, `d3d12_descriptor`, `d3d12_console_descriptor_heap`) | — | 6/6 **Passed** (`2.29 s` total) | Additional checks: - `python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_existing_heap_test.cpp` (exit 0) - `python -I tests/test_docs_links.py` (16 tests, OK) and `python -I tests/test_docs_table_rows.py` (2 tests, OK) - `git diff --check` (exit 0) - Not tested: `LEONIDA_VK_VALIDATION=1` (`VK_LAYER_KHRONOS_validation` is not installed on this machine), the full `ctest` suite, Windows 11, Turing+/AMD/Intel GPUs, or Linux/Wine. GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045 AI-assisted: yes (Antigravity) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1488
No description provided.