[PR #1768] [CLOSED] d3d12: import a slot-133 buffer at any offset in its page (RT-SLOT133-IMPORT-OFFSET) #1782

Closed
opened 2026-11-26 21:18:56 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1768
Author: @Coderlord
Created: 11/25/2026
Status: ❌ Closed

Base: main ← Head: rt-slot133-import-offset


📝 Commits (1)

  • 55a77a3 d3d12: import a slot-133 buffer at any offset in its page (RT-SLOT133-IMPORT-OFFSET)

📊 Changes

3 files changed (+46 additions, -13 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+26 -10)
📝 runtime/test/d3d12_existing_heap_test.cpp (+2 -2)
📝 runtime/test/d3d12_xmem_placed_test.cpp (+18 -1)

📄 Description

Claimed in the coordination issue as: RT-SLOT133-IMPORT-OFFSET (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161446177)

What and why

The retail title places small buffers 32 bytes apart through slot 133 (one at +0xc60 of a page, measured on an
RTX 5080). create_host_buffer imported the page that holds the address and bound the buffer at its offset in that
page, which Vulkan refuses off the buffer's alignment (64 on that card), so such a buffer was declined and became a
shadow. A 32-byte buffer near the end of a page (+0xfe0) was declined too: its memory requirement (64 bytes) ran
past the imported pages.

Now:

  • the Vulkan buffer starts at the page that holds the address and binds the imported memory at 0; the D3D12 buffer is
    ResourceBinding::buffer_offset into it, and its device address is offset to match, so the title VA alias and the
    below-the-arena check see the buffer's own address as before;
  • when the memory requirement reaches past the buffer's pages, the import takes the next pages too if they are
    committed and writable by the same rules as the buffer's own pages (no write-combine, no-cache or guard page,
    writable), and declines as before when they are not. The pin covers the larger range.

Replay already honors buffer_offset everywhere a binding is used (the GPU address arena relies on it), so copies,
clears, views and the VA lookup need no change.

Tested

On main ed94fbef9 plus this commit, Windows 11, RTX 5080, MSVC 2022 + Ninja, RelWithDebInfo:

  • ctest -R "^(d3d12_xmem_placed|d3d12_existing_heap.*|d3d12_title_va.*|title_va_alias)$": 7/7 passed
    (d3d12_existing_heap, _write_watch, _no_write_watch, d3d12_title_va, d3d12_title_va_shadow,
    d3d12_xmem_placed, title_va_alias). The new d3d12_xmem_placed case prints "a 64-byte buffer at +0xc60 of a
    page is imported and the GPU reads the CPU's writes": title_host_imports goes up by one (a shadow would not) and
    a GPU copy of the buffer reads what the CPU wrote at that address.
  • The same change was measured first in another tree on this card, where the retail boot had logged the refusal it
    removes ("offset 0xc60 in its page against alignment 0x40"); that buffer imported afterwards.
  • A retail boot of main (bcaa13dad) on this card without this change ran 400 s to the first-run pages with no
    fault; a boot with it has not been run yet.

GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 Pro 26300 (MSVC 2022, Ninja, RelWithDebInfo)

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)

🔄 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/1768 **Author:** [@Coderlord](https://github.com/Coderlord) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rt-slot133-import-offset` --- ### 📝 Commits (1) - [`55a77a3`](https://github.com/ubiquitarianism/leonida/commit/55a77a3a467490619e3c74573cf1aebe8c3330c7) d3d12: import a slot-133 buffer at any offset in its page (RT-SLOT133-IMPORT-OFFSET) ### 📊 Changes **3 files changed** (+46 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+26 -10) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+2 -2) 📝 `runtime/test/d3d12_xmem_placed_test.cpp` (+18 -1) </details> ### 📄 Description Claimed in the coordination issue as: RT-SLOT133-IMPORT-OFFSET (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161446177) ### What and why The retail title places small buffers 32 bytes apart through slot 133 (one at +0xc60 of a page, measured on an RTX 5080). `create_host_buffer` imported the page that holds the address and bound the buffer at its offset in that page, which Vulkan refuses off the buffer's alignment (64 on that card), so such a buffer was declined and became a shadow. A 32-byte buffer near the end of a page (+0xfe0) was declined too: its memory requirement (64 bytes) ran past the imported pages. Now: - the Vulkan buffer starts at the page that holds the address and binds the imported memory at 0; the D3D12 buffer is `ResourceBinding::buffer_offset` into it, and its device address is offset to match, so the title VA alias and the below-the-arena check see the buffer's own address as before; - when the memory requirement reaches past the buffer's pages, the import takes the next pages too if they are committed and writable by the same rules as the buffer's own pages (no write-combine, no-cache or guard page, writable), and declines as before when they are not. The pin covers the larger range. Replay already honors `buffer_offset` everywhere a binding is used (the GPU address arena relies on it), so copies, clears, views and the VA lookup need no change. ### Tested On `main` ed94fbef9 plus this commit, Windows 11, RTX 5080, MSVC 2022 + Ninja, RelWithDebInfo: - `ctest -R "^(d3d12_xmem_placed|d3d12_existing_heap.*|d3d12_title_va.*|title_va_alias)$"`: 7/7 passed (`d3d12_existing_heap`, `_write_watch`, `_no_write_watch`, `d3d12_title_va`, `d3d12_title_va_shadow`, `d3d12_xmem_placed`, `title_va_alias`). The new `d3d12_xmem_placed` case prints "a 64-byte buffer at +0xc60 of a page is imported and the GPU reads the CPU's writes": `title_host_imports` goes up by one (a shadow would not) and a GPU copy of the buffer reads what the CPU wrote at that address. - The same change was measured first in another tree on this card, where the retail boot had logged the refusal it removes ("offset 0xc60 in its page against alignment 0x40"); that buffer imported afterwards. - A retail boot of `main` (bcaa13dad) on this card without this change ran 400 s to the first-run pages with no fault; a boot with it has not been run yet. GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 Pro 26300 (MSVC 2022, Ninja, RelWithDebInfo) AI-assisted: yes (Claude Code) ### 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>
4ld0 2026-11-26 21:18:56 +01:00
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#1782
No description provided.