[PR #1192] [MERGED] d3d12: preserve offsets in sub-page host buffer imports (RT-HOST-IMPORT-PREFIX) #1224

Closed
opened 2026-11-26 20:20:30 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1192
Author: @GGandCo
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: fix/host-import-prefix


📝 Commits (7)

  • 3f81c40 d3d12: preserve logical offsets in sub-page host imports
  • 9de93fe d3d12: retain fallback for byte-unaligned host buffers
  • 56846f6 tests: isolate host-prefix coherence and preserve full heap coverage
  • ca68cb7 fix: stage texel-misaligned imported host texture copies
  • 002c720 docs: preserve original statistics comment encoding
  • 769634d Merge main into fix/host-import-prefix
  • 45219a6 d3d12 test: skip the write-back check when a refused import is a shadow

📊 Changes

5 files changed (+194 additions, -20 deletions)

View changed files

📝 runtime/CMakeLists.txt (+2 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+11 -12)
📝 runtime/src/vulkan_replay.h (+8 -6)
📝 runtime/test/d3d12_existing_heap_test.cpp (+128 -2)
📝 runtime/test/replay_copy_offset_test.cpp (+45 -0)

📄 Description

Claimed in the coordination issue as: RT-HOST-IMPORT-PREFIX

Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142584768 (posted before this PR).

Depends on: none.

Overlaps: #1190 and #1100 touch the same existing-heap fixture/backend file. This PR only changes per-resource imported-buffer prefix alignment; it does not implement existing-heap placed resources or deferred image backing. I will rebase and preserve both sets of tests if either lands first.

What and why

A buffer 16 or 32 bytes into an importable host page can be valid for the logical resource while failing the Vulkan memory-binding alignment. Binding the logical VkBuffer at that prefix currently falls back to an unrelated allocation, so the caller's writes do not share its GPU memory.

Bind a VkBuffer covering the page prefix plus logical range at memory offset zero. Carry the logical prefix in ResourceBinding::buffer_offset and in a valid returned device address. Preserve logical VA, size, initial contents and the existing ordinary-buffer fallback for byte-unaligned addresses.

Extend the existing synthetic fixture with bidirectional copies and surrounding-byte sentinels. Add d3d12_host_prefix / --host-prefix-only so this behavior can be tested independently of OpenExistingHeapFromAddress. The full existing-heap suite remains enabled and includes the new cases.

Review regression fixed

The +4-byte host-prefix RGBA16 texture-copy regression reported in review is fixed with aligned transfer scratch, preserving the host alias. The isolated test now covers 0/4/8/16/32/64 prefixes, buffer copies and two-row RGBA16 texture copies in both directions, including every padding byte. Normal and Vulkan-validation runs pass locally; the unchanged previous head fails the new CPU replay fixture. Wine/Proton revalidation is pending.

Tested

Rebased onto main 98c2f7777 (current PR head 002c720f2). Conflict resolution keeps main's import-failure cleanup and page-pin release, BDA word padding, low-address import guards, shadow-fallback behavior and additional heap/placed-texture tests, plus this PR's logical prefix and aligned texture-copy staging. The RelWithDebInfo target build, isolated d3d12_host_prefix test normally and with Vulkan validation, and changed-file game-data/whitespace checks pass again on the rebased head. The negative control below was measured against main6293c1c4 / main58be9cdf8 before this rebase.

Local Windows / Intel UHD Graphics (101.6314):

  • Isolated candidate d3d12_host_prefix passes normally and with Vulkan validation enabled: 0, 16, 32 and 64-byte offsets, CPU-to-GPU and GPU-to-CPU coherence, initial contents, and unchanged prefix/tail.
  • Exact unchanged-main backend plus the identical isolated test fails at the 16- and 32-byte offsets because the resource VA differs from the caller VA. Aligned and 64-byte cases succeed. Restoring the candidate passes normally and with validation again.
  • Our separate local PR984 integration also passes this isolated test in both modes and its TLS/xmem/proxy regressions. That integration is not the clean-main build used above.

Independent reports on 02a2717b (before adding the isolated test):

Known limitation: the monolithic existing-heap executable on the local Intel machine still intermittently loses the device in its earlier aligned copy after the existing-heap checks, on both unchanged main and candidate. The isolated test above avoids those preceding operations; it does not remove their coverage. PR #1259 separately addresses that earlier-import lifetime issue: applied privately on top of this PR before the latest rebase, the full test passes normally, with validation and in three further repeats on this Intel machine (https://github.com/ubiquitarianism/leonida/pull/1259#issuecomment-7144543590). That fix is not included here. A private queue-barrier experiment was not reproducible and is not included. No game boot, gameplay or performance claim is made by this PR.

GPUs tested: Intel UHD Graphics / Windows, 101.6314 (local); NVIDIA RTX3060Ti / Windows,621.24 and Arch Linux+Wine11.22,595.58.03 (independent reports linked above).

AI-assisted: yes.

Checklist

  • Based on current main and rebased cleanly.
  • One topic; independent GPU/heap issues remain separate.
  • No game data, keys, decryption, generated shaders, captures or private runtime logs included.
  • No translator rule changed.

🔄 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/1192 **Author:** [@GGandCo](https://github.com/GGandCo) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/host-import-prefix` --- ### 📝 Commits (7) - [`3f81c40`](https://github.com/ubiquitarianism/leonida/commit/3f81c4015bf06cc7036f5ea1848d39b98c4cc266) d3d12: preserve logical offsets in sub-page host imports - [`9de93fe`](https://github.com/ubiquitarianism/leonida/commit/9de93fedd31ce8dca852d87c28b59fe77799ef97) d3d12: retain fallback for byte-unaligned host buffers - [`56846f6`](https://github.com/ubiquitarianism/leonida/commit/56846f650d2e712a24efd6d60124d9741f03d258) tests: isolate host-prefix coherence and preserve full heap coverage - [`ca68cb7`](https://github.com/ubiquitarianism/leonida/commit/ca68cb7859e79105896b6931503b301100e1834a) fix: stage texel-misaligned imported host texture copies - [`002c720`](https://github.com/ubiquitarianism/leonida/commit/002c720f299abe4f1e4c8a4d7db2b710b774f88f) docs: preserve original statistics comment encoding - [`769634d`](https://github.com/ubiquitarianism/leonida/commit/769634dd61e4ff352ebf0ce0b2c69fd4596bce9b) Merge main into fix/host-import-prefix - [`45219a6`](https://github.com/ubiquitarianism/leonida/commit/45219a640014635a633a9b1afaea78a9495f5424) d3d12 test: skip the write-back check when a refused import is a shadow ### 📊 Changes **5 files changed** (+194 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+2 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+11 -12) 📝 `runtime/src/vulkan_replay.h` (+8 -6) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+128 -2) 📝 `runtime/test/replay_copy_offset_test.cpp` (+45 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-HOST-IMPORT-PREFIX Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142584768 (posted before this PR). Depends on: none. Overlaps: #1190 and #1100 touch the same existing-heap fixture/backend file. This PR only changes per-resource imported-buffer prefix alignment; it does not implement existing-heap placed resources or deferred image backing. I will rebase and preserve both sets of tests if either lands first. ### What and why A buffer 16 or 32 bytes into an importable host page can be valid for the logical resource while failing the Vulkan memory-binding alignment. Binding the logical VkBuffer at that prefix currently falls back to an unrelated allocation, so the caller's writes do not share its GPU memory. Bind a VkBuffer covering the page prefix plus logical range at memory offset zero. Carry the logical prefix in ResourceBinding::buffer_offset and in a valid returned device address. Preserve logical VA, size, initial contents and the existing ordinary-buffer fallback for byte-unaligned addresses. Extend the existing synthetic fixture with bidirectional copies and surrounding-byte sentinels. Add d3d12_host_prefix / --host-prefix-only so this behavior can be tested independently of OpenExistingHeapFromAddress. The full existing-heap suite remains enabled and includes the new cases. ### Review regression fixed The +4-byte host-prefix RGBA16 texture-copy regression reported in review is fixed with aligned transfer scratch, preserving the host alias. The isolated test now covers 0/4/8/16/32/64 prefixes, buffer copies and two-row RGBA16 texture copies in both directions, including every padding byte. Normal and Vulkan-validation runs pass locally; the unchanged previous head fails the new CPU replay fixture. Wine/Proton revalidation is pending. ### Tested Rebased onto main 98c2f7777 (current PR head 002c720f2). Conflict resolution keeps main's import-failure cleanup and page-pin release, BDA word padding, low-address import guards, shadow-fallback behavior and additional heap/placed-texture tests, plus this PR's logical prefix and aligned texture-copy staging. The RelWithDebInfo target build, isolated d3d12_host_prefix test normally and with Vulkan validation, and changed-file game-data/whitespace checks pass again on the rebased head. The negative control below was measured against main6293c1c4 / main58be9cdf8 before this rebase. Local Windows / Intel UHD Graphics (101.6314): - Isolated candidate d3d12_host_prefix passes normally and with Vulkan validation enabled: 0, 16, 32 and 64-byte offsets, CPU-to-GPU and GPU-to-CPU coherence, initial contents, and unchanged prefix/tail. - Exact unchanged-main backend plus the identical isolated test fails at the 16- and 32-byte offsets because the resource VA differs from the caller VA. Aligned and 64-byte cases succeed. Restoring the candidate passes normally and with validation again. - Our separate local PR984 integration also passes this isolated test in both modes and its TLS/xmem/proxy regressions. That integration is not the clean-main build used above. Independent reports on 02a2717b (before adding the isolated test): - RTX3060Ti, native Windows11, NVIDIA621.24: unchanged-main control fails exactly the two new offsets; the candidate passes the full existing-heap executable, including bidirectional coherence and surrounding bytes: https://github.com/ubiquitarianism/leonida/pull/1192#issuecomment-7143110601 - RTX3060Ti, Arch Linux / Wine11.22, NVIDIA595.58.03: full existing-heap CTest passes: https://github.com/ubiquitarianism/leonida/pull/1192#issuecomment-7143088780 Known limitation: the monolithic existing-heap executable on the local Intel machine still intermittently loses the device in its earlier aligned copy after the existing-heap checks, on both unchanged main and candidate. The isolated test above avoids those preceding operations; it does not remove their coverage. PR #1259 separately addresses that earlier-import lifetime issue: applied privately on top of this PR before the latest rebase, the full test passes normally, with validation and in three further repeats on this Intel machine (https://github.com/ubiquitarianism/leonida/pull/1259#issuecomment-7144543590). That fix is not included here. A private queue-barrier experiment was not reproducible and is not included. No game boot, gameplay or performance claim is made by this PR. GPUs tested: Intel UHD Graphics / Windows, 101.6314 (local); NVIDIA RTX3060Ti / Windows,621.24 and Arch Linux+Wine11.22,595.58.03 (independent reports linked above). AI-assisted: yes. ### Checklist - [x] Based on current main and rebased cleanly. - [x] One topic; independent GPU/heap issues remain separate. - [x] No game data, keys, decryption, generated shaders, captures or private runtime logs included. - [x] No translator rule changed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:30 +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#1224
No description provided.