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

Closed
github-bot wants to merge 1 commit from gh-pr/1768/head into gh-pr/1768/base
Owner

@⁠Coderlord on GitHub · 2026-11-25 11:45 UTC · original
Coderlord:rt-slot133-import-offset → main · +46 −13 · 3 files · 1 commits · closed without merging

Claimed in the coordination issue as: RT-SLOT133-IMPORT-OFFSET (#1608)

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)
**@⁠Coderlord** on GitHub · 2026-11-25 11:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1768) `Coderlord:rt-slot133-import-offset` → `main` · +46 −13 · 3 files · 1 commits · closed without merging Claimed in the coordination issue as: RT-SLOT133-IMPORT-OFFSET (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
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 it,
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.

The Vulkan buffer now starts at the page and binds the imported memory at 0; the D3D12 buffer is
ResourceBinding::buffer_offset into it and its device address is offset to match (the title VA alias and the
arena checks 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, and
declines as before when they are not.

d3d12_xmem_placed_test places a 64-byte buffer at +0xc60 of a committed page and checks that it is an import (one
more title_host_imports) and that a GPU copy reads the CPU's writes at the title's address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:15 +00:00
github-bot closed this pull request 2026-11-26 10:04:15 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 14:49 UTC · original

Thanks, @⁠Coderlord, and thanks for the +0xc60 measurement. Closing this as a duplicate of #1192 (RT-HOST-IMPORT-PREFIX, claimed in #14 the day before), which is now merged. It makes the same change in create_host_buffer and also stages texture copies at offsets Vulkan can't take:

  • With #1192's test, this branch fails a +4 RGBA16 texture copy as unsupported, which main answered with a shadow.
  • The new d3d12_xmem_placed case requires an import, so it fails on a driver that refuses xmem windows (RADV under Wine).
  • #1192 also passes your +0xc60 case.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 14:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1768#issuecomment-7165883018) Thanks, @⁠Coderlord, and thanks for the +0xc60 measurement. Closing this as a duplicate of #1192 (`RT-HOST-IMPORT-PREFIX`, claimed in #14 the day before), which is now merged. It makes the same change in `create_host_buffer` and also stages texture copies at offsets Vulkan can't take: - With #1192's test, this branch fails a +4 RGBA16 texture copy as unsupported, which `main` answered with a shadow. - The new `d3d12_xmem_placed` case requires an import, so it fails on a driver that refuses xmem windows (RADV under Wine). - #1192 also passes your +0xc60 case. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠QemmHD on GitHub · 2026-11-25 14:54 UTC · original

Review (code read; not built): this now conflicts with main in d3d12_vulkan_device.cpp, because #1192 (merged today) landed the same core change: the buffer sized offset+backing, memory bound at 0, BDA+offset, and binding.buffer_offset. What #1768 still adds on top is the extension of the import over the following committed, writable pages when the memory requirement runs past the buffer's own pages (the 32-byte buffer at +0xfe0), plus the +0xc60 xmem_placed test. Suggest rebasing onto main and keeping only that page extension and its test. I'm happy to build and run it on an RTX 4070 SUPER after the rebase.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-25 14:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1768#issuecomment-7165989984) Review (code read; not built): this now conflicts with main in `d3d12_vulkan_device.cpp`, because #1192 (merged today) landed the same core change: the buffer sized offset+backing, memory bound at 0, BDA+offset, and `binding.buffer_offset`. What #1768 still adds on top is the extension of the import over the following committed, writable pages when the memory requirement runs past the buffer's own pages (the 32-byte buffer at +0xfe0), plus the +0xc60 `xmem_placed` test. Suggest rebasing onto main and keeping only that page extension and its test. I'm happy to build and run it on an RTX 4070 SUPER after the rebase. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-25 15:10 UTC · original

Independent verification of head 55a77a3a467490619e3c74573cf1aebe8c3330c7, merged onto current main (71a769d7d) without conflicts.

Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.

  • With the PR: d3d12_xmem_placed, d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch, plus neighbours xs_proxy_mock_slot133_layout, title_window, title_window_plan, d3d12_execute_indirect_validation, d3d12_graphics_indirect_heap_resources: 9/9 pass. The new case prints "a 64-byte buffer at +0xc60 of a page is imported and the GPU reads the CPU's writes".
  • The PR's tests against main's runtime: d3d12_xmem_placed fails at line 431: rt::d3d12::title_host_imports(real) == imports + 1 (the buffer at +0xc60 becomes a shadow, not an import), so the bug reproduces on this NVIDIA card too; the three d3d12_existing_heap* tests pass either way.

Diff read: the Vulkan buffer now starts at the page and the D3D12 buffer is binding.buffer_offset into it, which the replay paths already honour for arena buffers (descriptor views, copies, clears); BDA + offset keeps the VA equal to the address. No problem found.

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

**@⁠Tyrannys** on GitHub · 2026-11-25 15:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1768#issuecomment-7166416051) **Independent verification** of head `55a77a3a467490619e3c74573cf1aebe8c3330c7`, merged onto current `main` (71a769d7d) without conflicts. Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo. - With the PR: `d3d12_xmem_placed`, `d3d12_existing_heap`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`, plus neighbours `xs_proxy_mock_slot133_layout`, `title_window`, `title_window_plan`, `d3d12_execute_indirect_validation`, `d3d12_graphics_indirect_heap_resources`: **9/9 pass**. The new case prints "a 64-byte buffer at +0xc60 of a page is imported and the GPU reads the CPU's writes". - The PR's tests against `main`'s runtime: `d3d12_xmem_placed` **fails** at `line 431: rt::d3d12::title_host_imports(real) == imports + 1` (the buffer at +0xc60 becomes a shadow, not an import), so the bug reproduces on this NVIDIA card too; the three `d3d12_existing_heap*` tests pass either way. Diff read: the Vulkan buffer now starts at the page and the D3D12 buffer is `binding.buffer_offset` into it, which the replay paths already honour for arena buffers (descriptor views, copies, clears); BDA + `offset` keeps the VA equal to the address. No problem found. No game files used. AI-assisted (Claude Code).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.