RT-MAP-READBACK-RANGE: skip GPU readback for write-only texture maps #2091

Closed
lixonik wants to merge 2 commits from upstream-pr/2091 into main
lixonik commented 2026-11-25 20:01:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T20:01:24Z.


Claimed as RT-MAP-READBACK-RANGE in the coordination thread.

With LEONIDA_MAP_READBACK=1, Map on an eligible title-placed texture could wait for a GPU copy and overwrite the CPU backing even when the caller declared it would read no bytes. Skip that copy when End <= Begin. A null range and a nonempty range still read back, as specified by ID3D12Resource::Map.

The new CTest uses a synthetic 1x1 RGBA32F render target and distinct CPU and GPU texels. It checks empty, inverted, nonempty and null ranges. The old implementation failed because the empty range overwrote the CPU texel. The fix passed all four cases and all five existing-heap/placement CTests on native Windows with a GeForce RTX 5070 and NVIDIA driver 610.88. The full translator semantic suite passed (491 files, 6,285 tests).

The reported retail exposure path was not exercised in this run.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498252659 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T20:01:24Z. --- Claimed as `RT-MAP-READBACK-RANGE` in the [coordination thread](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172880286). With `LEONIDA_MAP_READBACK=1`, `Map` on an eligible title-placed texture could wait for a GPU copy and overwrite the CPU backing even when the caller declared it would read no bytes. Skip that copy when `End <= Begin`. A null range and a nonempty range still read back, as specified by [ID3D12Resource::Map](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12resource-map). The new CTest uses a synthetic 1x1 RGBA32F render target and distinct CPU and GPU texels. It checks empty, inverted, nonempty and null ranges. The old implementation failed because the empty range overwrote the CPU texel. The fix passed all four cases and all five existing-heap/placement CTests on native Windows with a GeForce RTX 5070 and NVIDIA driver 610.88. The full translator semantic suite passed (491 files, 6,285 tests). The [reported retail exposure path](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167966834) was not exercised in this run. AI-assisted.
qhukz13 commented 2026-11-26 00:25:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-26T00:25:34Z.


Run on a GTX 1050 Ti (Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo) plus a merge check.

  • This head no longer merges into main. Merged onto main c50ed94b3 (301 commits ahead), runtime/test/d3d12_existing_heap_test.cpp conflicts: main's d86ac9813 ("Fill a never-filled mapped texture before its first submission", the async_plane mode) changed the same argument parsing in main() that --map-readback-only adds to. The shim change and the CMake lines merge cleanly; only the test needs a rebase.
  • At the head as it is (base 457bb6711's parent), 3 runs each, plain and with LEONIDA_VK_VALIDATION=1:
    • d3d12_placed_target_map_readback (the new one): passes.
    • d3d12_host_prefix: passes.
    • d3d12_existing_heap, _no_write_watch, _write_watch: fail at the persistent slot-133 plane check, which is a known Pascal case (the R8 plane's HOST_TRANSFER image gets no memory type), fixed by #1894 and failing on main here too; unrelated to this change.
    • No validation messages.
  • The one-line condition reads right: !read || read->End > read->Begin keeps the readback for a null range and a nonempty one, and drops it for empty and inverted ranges, as ID3D12Resource::Map documents.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7178741967 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2091#issuecomment-7178741967). Originally posted by [qhukz13](https://github.com/qhukz13) on 2026-11-26T00:25:34Z. --- Run on a GTX 1050 Ti (Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo) plus a merge check. - **This head no longer merges into main.** Merged onto main `c50ed94b3` (301 commits ahead), `runtime/test/d3d12_existing_heap_test.cpp` conflicts: main's d86ac9813 ("Fill a never-filled mapped texture before its first submission", the `async_plane` mode) changed the same argument parsing in `main()` that `--map-readback-only` adds to. The shim change and the CMake lines merge cleanly; only the test needs a rebase. - **At the head as it is (base 457bb6711's parent),** 3 runs each, plain and with `LEONIDA_VK_VALIDATION=1`: - `d3d12_placed_target_map_readback` (the new one): passes. - `d3d12_host_prefix`: passes. - `d3d12_existing_heap`, `_no_write_watch`, `_write_watch`: fail at the persistent slot-133 plane check, which is a known Pascal case (the R8 plane's HOST_TRANSFER image gets no memory type), fixed by #1894 and failing on main here too; unrelated to this change. - No validation messages. - The one-line condition reads right: `!read || read->End > read->Begin` keeps the readback for a null range and a nonempty one, and drops it for empty and inverted ranges, as `ID3D12Resource::Map` documents. AI-assisted (Claude Code).
djrolfes commented 2026-11-26 05:54:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-26T05:54:31Z.


Continuing the existing RT-PROTON-3070TI-VALIDATION claim: validating 7ea8728b9 in a separate Linux/Wine integration before enabling the existing LEONIDA_MAP_READBACK path. The completed prior run had 16 readable exposure-shaped Map diagnostic samples, but LEONIDA_MAP_READBACK was unset and there were zero map-readback operations logged. Output included a partial world image followed by black/near-white frames; that does not prove the missing readback is the cause.

I am reusing your range guard and synthetic test rather than implementing a second fix. Applied only the topic commit to 6641e1021 (not the newer base history); the test CLI conflict was resolved by retaining the local host-prefix mode and your new map-readback mode, without importing unrelated async-plane context. Local candidate f448c712a. Build/tests and a deliberate readback-enabled comparison follow; counts only, all raw retail evidence remains local. AI-assisted (OpenAI GPT-6.1 Sol).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7183913985 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2091#issuecomment-7183913985). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-26T05:54:31Z. --- Continuing the existing RT-PROTON-3070TI-VALIDATION claim: validating 7ea8728b9 in a separate Linux/Wine integration before enabling the existing LEONIDA_MAP_READBACK path. The completed prior run had 16 readable exposure-shaped Map diagnostic samples, but LEONIDA_MAP_READBACK was unset and there were zero map-readback operations logged. Output included a partial world image followed by black/near-white frames; that does not prove the missing readback is the cause. I am reusing your range guard and synthetic test rather than implementing a second fix. Applied only the topic commit to 6641e1021 (not the newer base history); the test CLI conflict was resolved by retaining the local host-prefix mode and your new map-readback mode, without importing unrelated async-plane context. Local candidate f448c712a. Build/tests and a deliberate readback-enabled comparison follow; counts only, all raw retail evidence remains local. AI-assisted (OpenAI GPT-6.1 Sol).
djrolfes commented 2026-11-26 05:57:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-26T05:57:40Z.


Linux/Wine validation result for 7ea8728b9 (topic-only application on local 6641e1021, candidate f448c712a). RTX 3070 Ti, NVIDIA 620.73.04, Wine 11.22, clang-cl/LLD 23.1.5 and xwin SDK 10.0.26100, RelWithDebInfo.

Targeted runtime build succeeds. Fresh offline Wine prefix, no retail package mounted: 19/19 focused CTests pass in 28.79 s. This includes d3d12_placed_target_map_readback (all four empty/inverted/nonempty/null cases), the three existing_heap modes, host_prefix, and the 14 wait/fault/queue/proxy tests already selected for this integration.

Independent negative control: relinked the exact new test object against the unmodified 6641e1021 gta6rt_d3d12_com.lib, leaving other linked inputs the same. The old-shim executable fails with exit 1 at the empty-range texel comparison (test line 1316), after logging the GPU texel was read back; the candidate passes. This isolates the write-only Map overwrite regression rather than merely running a new test that passes both ways.

Not a full Windows suite or a retail visual-fix claim. A separate retail comparison with the existing Map-readback switch is now running; output/causality remain unverified. All game-derived evidence stays local. AI-assisted (OpenAI GPT-6.1 Sol).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7183961962 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2091#issuecomment-7183961962). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-26T05:57:40Z. --- Linux/Wine validation result for 7ea8728b9 (topic-only application on local 6641e1021, candidate f448c712a). RTX 3070 Ti, NVIDIA 620.73.04, Wine 11.22, clang-cl/LLD 23.1.5 and xwin SDK 10.0.26100, RelWithDebInfo. Targeted runtime build succeeds. Fresh offline Wine prefix, no retail package mounted: 19/19 focused CTests pass in 28.79 s. This includes d3d12_placed_target_map_readback (all four empty/inverted/nonempty/null cases), the three existing_heap modes, host_prefix, and the 14 wait/fault/queue/proxy tests already selected for this integration. Independent negative control: relinked the exact new test object against the unmodified 6641e1021 gta6rt_d3d12_com.lib, leaving other linked inputs the same. The old-shim executable fails with exit 1 at the empty-range texel comparison (test line 1316), after logging the GPU texel was read back; the candidate passes. This isolates the write-only Map overwrite regression rather than merely running a new test that passes both ways. Not a full Windows suite or a retail visual-fix claim. A separate retail comparison with the existing Map-readback switch is now running; output/causality remain unverified. All game-derived evidence stays local. AI-assisted (OpenAI GPT-6.1 Sol).
djrolfes commented 2026-11-26 06:23:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-26T06:23:56Z.


Retail comparison finished (same local topic-only f448c712a integration, Linux/Wine/RTX3070Ti): at least32 successful GPU-to-CPU Map readbacks logged, with finite nonzero varying exposure-shaped texels and zero readback-failure messages. Thus the existing optional path is actually exercised, not just enabled in metadata. This does NOT establish a visual cure: the final two distinct captures show black output with HUD/credits overlays, not stable scenery.

The run stopped after1251.56s on a new title-side fixed-pool empty-list breakpoint, not device loss.1127 actual XboxPresentation::PresentX;805 held/804 met/zero expired gates;65536 indirect draws emitted with zero reported skips. The startup trace captured matching stacks/register state on seven title threads; investigating separately, with no attribution to this Map-range patch. Cache preserved; no automatic retry. Raw traces/captures/disassembly remain local.19/19 synthetic Wine tests plus the failing old-shim negative control remain the independently demonstrated result for your patch. AI-assisted (OpenAI GPT-6.1 Sol).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7184390560 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2091#issuecomment-7184390560). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-26T06:23:56Z. --- Retail comparison finished (same local topic-only f448c712a integration, Linux/Wine/RTX3070Ti): at least32 successful GPU-to-CPU Map readbacks logged, with finite nonzero varying exposure-shaped texels and zero readback-failure messages. Thus the existing optional path is actually exercised, not just enabled in metadata. This does NOT establish a visual cure: the final two distinct captures show black output with HUD/credits overlays, not stable scenery. The run stopped after1251.56s on a new title-side fixed-pool empty-list breakpoint, not device loss.1127 actual XboxPresentation::PresentX;805 held/804 met/zero expired gates;65536 indirect draws emitted with zero reported skips. The startup trace captured matching stacks/register state on seven title threads; investigating separately, with no attribution to this Map-range patch. Cache preserved; no automatic retry. Raw traces/captures/disassembly remain local.19/19 synthetic Wine tests plus the failing old-shim negative control remain the independently demonstrated result for your patch. AI-assisted (OpenAI GPT-6.1 Sol).
zmasi commented 2026-11-28 23:02:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:02:11Z.


#2091 | head 7ea8728b9a (merged cleanly with main adfb3821a2 — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_placed_target_map_readback|d3d12_host_prefix|d3d12_mapped_plane_async|d3d12_existing_heap)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: building d3d12_existing_heap_test against main's runtime/shims/d3d12_vulkan_device.cpp fails d3d12_placed_target_map_readback (slot-133 Map empty range line 1439: std::memcmp(mapped, test.expected_texel, sizeof(gpu_texel)) == 0 after logging map read-back #1 on the empty range) | green on PR+main: d3d12_placed_target_map_readback (empty and inverted ranges skip GPU readback; nonempty and null ranges perform map read-back #1 and #2), d3d12_host_prefix, and d3d12_mapped_plane_async pass on RTX 3090 with 0 Khronos validation errors, and full d3d12_existing_heap passes (rc=0); check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247153729 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7247153729). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T23:02:11Z. --- #2091 | head 7ea8728b9ac2ba7bf51982e7040b5129361b8d8f (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_placed_target_map_readback|d3d12_host_prefix|d3d12_mapped_plane_async|d3d12_existing_heap)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `d3d12_existing_heap_test` against `main`'s `runtime/shims/d3d12_vulkan_device.cpp` fails `d3d12_placed_target_map_readback` (`slot-133 Map empty range line 1439: std::memcmp(mapped, test.expected_texel, sizeof(gpu_texel)) == 0` after logging `map read-back #1` on the empty range) | green on PR+main: `d3d12_placed_target_map_readback` (empty and inverted ranges skip GPU readback; nonempty and null ranges perform `map read-back #1` and `#2`), `d3d12_host_prefix`, and `d3d12_mapped_plane_async` pass on RTX 3090 with `0` Khronos validation errors, and full `d3d12_existing_heap` passes (`rc=0`); `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
merzleckeier commented 2026-11-30 12:22:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T12:22:16Z.


Independent Wine A/B for the current Map readback patch. I cross-built Win64 Release from GitHub merge 428fb5e3 (base ec1d85846, PR head 2620baf0a) with Clang 23.1.5 and Windows SDK 10.0.26100. CachyOS, Wine 11.22, RTX 4070 SUPER (620.73.04) and Radeon 610M (RADV 26.3.1). Synthetic 1×1 placed render target.

MEASURED. The checked-in d3d12_placed_target_map_readback CTest passed on both GPUs. I then ran an instrumented copy with two extra range cases and per-case byte checks. The probe builds differed only by reverting the one-line Map guard in the control.

Map range Guard reverted PR guard
Empty, inverted or empty at a nonzero offset All three overwrite the CPU bytes with the GPU texel All three preserve the CPU bytes
Nonempty, nonempty at an offset, or null range pointer All three return the GPU texel All three return the GPU texel

Both GPUs gave the same results. The completion diagnostics recorded six GPU readbacks with the guard reverted and three with the PR guard. The three positive controls also verified the returned placement pointer and texel bytes.

d3d12_existing_heap and d3d12_mapped_plane_async passed through CTest on both GPUs. d3d12_host_prefix printed PASS and hit the 30-second CTest timeout on both. Running the same stock PR executable directly with --host-prefix-only returned 0 on both drivers.

AI-assisted with OpenAI Codex. The observations were independently checked against the raw logs.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7278338765 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7278338765). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T12:22:16Z. --- **Independent Wine A/B for the current Map readback patch.** I cross-built Win64 Release from GitHub merge `428fb5e3` (base `ec1d85846`, PR head `2620baf0a`) with Clang 23.1.5 and Windows SDK 10.0.26100. CachyOS, Wine 11.22, RTX 4070 SUPER (620.73.04) and Radeon 610M (RADV 26.3.1). Synthetic 1×1 placed render target. **MEASURED.** The checked-in `d3d12_placed_target_map_readback` CTest passed on both GPUs. I then ran an instrumented copy with two extra range cases and per-case byte checks. The probe builds differed only by reverting the one-line Map guard in the control. | Map range | Guard reverted | PR guard | |---|---|---| | Empty, inverted or empty at a nonzero offset | All three overwrite the CPU bytes with the GPU texel | All three preserve the CPU bytes | | Nonempty, nonempty at an offset, or null range pointer | All three return the GPU texel | All three return the GPU texel | Both GPUs gave the same results. The completion diagnostics recorded six GPU readbacks with the guard reverted and three with the PR guard. The three positive controls also verified the returned placement pointer and texel bytes. `d3d12_existing_heap` and `d3d12_mapped_plane_async` passed through CTest on both GPUs. `d3d12_host_prefix` printed PASS and hit the 30-second CTest timeout on both. Running the same stock PR executable directly with `--host-prefix-only` returned 0 on both drivers. AI-assisted with OpenAI Codex. The observations were independently checked against the raw logs.
merzleckeier commented 2026-11-30 12:26:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T12:26:08Z.


Follow-up on the Wine CTest timeout from my previous test report. I used the same stock PR executable from 428fb5e3.

  • With the persistent Wine server started and its services still uninitialized, the isolated host-prefix CTest printed PASS and hit a 12-second timeout on both GPUs. In an NVIDIA pipe-capture control, the executable returned 0 after printing PASS. The pipe still had no EOF at the seven-second observation cutoff, and services.exe and wineserver still held the same pipe. The CTest process showed those same kinds of pipe holders.
  • I repeated the four CTests after running wine wineboot </dev/null >/dev/null 2>&1 on the already-started server. 4/4 passed on each GPU. The host-prefix case completed in 1.29 s on the RTX 4070 SUPER and 1.14 s on the Radeon 610M. This is the startup order already described in the project testing guide.

Synthetic tests on Wine 11.22. AI-assisted with OpenAI Codex and independently checked against the raw logs.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7278432596 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7278432596). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T12:26:08Z. --- **Follow-up on the Wine CTest timeout** from my [previous test report](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7278338765). I used the same stock PR executable from `428fb5e3`. - With the persistent Wine server started and its services still uninitialized, the isolated host-prefix CTest printed PASS and hit a 12-second timeout on both GPUs. In an NVIDIA pipe-capture control, the executable returned 0 after printing PASS. The pipe still had no EOF at the seven-second observation cutoff, and `services.exe` and `wineserver` still held the same pipe. The CTest process showed those same kinds of pipe holders. - I repeated the four CTests after running `wine wineboot </dev/null >/dev/null 2>&1` on the already-started server. **4/4 passed on each GPU.** The host-prefix case completed in 1.29 s on the RTX 4070 SUPER and 1.14 s on the Radeon 610M. This is the startup order already described in the [project testing guide](https://github.com/ProjectLeonida/mandy/blob/main/docs/testing.md). Synthetic tests on Wine 11.22. AI-assisted with OpenAI Codex and independently checked against the raw logs.
lixonik commented 2026-11-30 12:28:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-30T12:28:01Z.


@merzleckeier Thanks for checking the offset cases and counting the actual readbacks. On the same PR head, 2620baf0a7668a036be97b55aa6f3aa3dc5ad166, the stock d3d12_host_prefix CTest passed in 0.35 s on native Windows 10 22H2, MSVC 19.44, RTX 5070 (NVIDIA 610.88), Vulkan validation enabled. d3d12_placed_target_map_readback, d3d12_existing_heap, and d3d12_mapped_plane_async also passed here. The Wine CTest timeout was outside this native run.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7278476331 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7278476331). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-30T12:28:01Z. --- @merzleckeier Thanks for checking the offset cases and counting the actual readbacks. On the same PR head, `2620baf0a7668a036be97b55aa6f3aa3dc5ad166`, the stock `d3d12_host_prefix` CTest passed in 0.35 s on native Windows 10 22H2, MSVC 19.44, RTX 5070 (NVIDIA 610.88), Vulkan validation enabled. `d3d12_placed_target_map_readback`, `d3d12_existing_heap`, and `d3d12_mapped_plane_async` also passed here. The Wine CTest timeout was outside this native run. AI-assisted.
aslan2142 commented 2026-12-02 00:44:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-02T00:44:07Z.


Thank you for the careful work and thorough verification here. The legacy C++/Vulkan runtime/ directory is now frozen and deprecated as active development focuses on the d3d12/ and clean-room Rust vulkan/ tracks, so we are closing open legacy runtime/ PRs. We really appreciate the effort that went into this.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7330897680 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2091#issuecomment-7330897680). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-02T00:44:07Z. --- Thank you for the careful work and thorough verification here. The legacy C++/Vulkan runtime/ directory is now frozen and deprecated as active development focuses on the d3d12/ and clean-room Rust vulkan/ tracks, so we are closing open legacy runtime/ PRs. We really appreciate the effort that went into this.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2091
No description provided.