Skip to content

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

Open
lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:fix/map-readback-range
Open

lixonik wants to merge 1 commit into
ProjectLeonida:mainfrom
lixonik:fix/map-readback-range

Conversation

@lixonik

@lixonik lixonik commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.

@qhukz13

qhukz13 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 d86ac98 ("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 457bb67'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 d3d12: stage title textures when their format or usage rules out host copies #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).

@lixonik
lixonik force-pushed the fix/map-readback-range branch from 457bb67 to 7ea8728 Compare November 26, 2026 05:46
@djrolfes

Copy link
Copy Markdown
Contributor

Continuing the existing RT-PROTON-3070TI-VALIDATION claim: validating 7ea8728 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

Copy link
Copy Markdown
Contributor

Linux/Wine validation result for 7ea8728 (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

Copy link
Copy Markdown
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants