Skip to content

replay: texture copy format-conversion destination bounds no longer wrap in 32 bits - #9140

Open
tedin7 wants to merge 1 commit into
ItsNotRexed:mainfrom
tedin7:fast-replay-copy-dst-wrap
Open

tedin7 wants to merge 1 commit into
ItsNotRexed:mainfrom
tedin7:fast-replay-copy-dst-wrap

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #9065 (comment)
@ItsNotRexed: an exe PR, as you asked.

What

Use 64-bit destination bounds sums for texture-to-texture BC/uncompressed conversion. Add CPU-only replay regression coverage. AI-assisted.

Why

32-bit addition could wrap and accept an invalid destination offset, emitting an image copy with a negative offset.

Tested

  • Worker (Linux, GNU C++ 14.2.0): built and ran replay_copy_offset_test via ctest: passed. Before the fix the same test failed for x = 0xFFFFFFFF and y = 0xFFFFFFFF (an image copy was emitted); the x = 0 positive control passed.
  • Pod p2, clang-cl + Wine (/root/fast_test_exe.sh, target replay_copy_offset_test, fresh configure): EXIT 0 with the fix.
  • Negative control on p2: same test with runtime/src/vulkan_replay.h reverted to origin/main: EXIT 1 (FAIL: conversion bounds result, FAIL: invalid conversion emits no image copy).
  • Review (gpt-6.2-sol): CLEAN. git diff --check and the game-data check passed.
  • No GPU used, so no WARP or Vulkan device comparison; nothing here was Wine-only.

What is left out

The buffer/texture footprint path, covered by PR #8777, is unchanged. No GPU or game-file testing.

AI-assisted: yes

@al3xar al3xar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review and test.

Independent Windows MSVC + GPU verification of c0209f3d2 on Windows 11 x64 (es-ES), MSVC 19.44.35230.0 (RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON), NVIDIA GeForce RTX 3060 (driver 621.24, Vulkan SDK 1.4.363.0), no game files used: pass.

  • Merge & hygiene: Merges cleanly with upstream/main (867d922f0, git merge-tree exit 0); python -I scripts/check_no_game_data.py clean.
  • Build: replay_copy_offset_test and d3d12_copy_xfmt_test built cleanly with MSVC /W4 (no new warnings).
  • Tests (LEONIDA_VK_VALIDATION=1):
    • replay_copy_offset_test: pass (exit 0).
    • d3d12_copy_xfmt_test: pass, 0 validation errors (46 compared, 0 differ (BC <-> uncompressed, controls), 0 depth <-> colour differ).
  • Negative control: Reverting runtime/src/vulkan_replay.h to upstream/main causes replay_copy_offset_test to fail on the new 32-bit wrap cases (UINT32_MAX, exit 1).
  • Code check: Widening the destination block and texel sums to std::uint64_t in prepare_texture_copy cleanly prevents 32-bit wraparound on BC/uncompressed format-conversion copies.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows review (commit c0209f3d202a47651b46a51e48cd2396b071854e)

What changed:

  • runtime/src/vulkan_replay.h:
    • In prepare_texture_copy, promotes destination block offset arithmetic to std::uint64_t.
    • Prevents 32-bit integer overflow wrapping when copying large mip offsets or elevated slice bounds during texture format conversion.
  • runtime/test/replay_copy_offset_test.cpp:
    • Tests boundary conditions at UINT32_MAX.

Verification:

  • Verified on Windows host: boundary checks and promotion logic pass cleanly.
  • Clean diff: no game data.

LGTM!

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review

What changed: prepare_texture_copy destination bounds for format-conversion copies no longer wrap in 32 bits; BC→uncompressed cases covered in replay_copy_offset_test.

Checked: compiled + ran runtime/test/replay_copy_offset_test.cpp → replay_copy_offset: ….

Looks correct; no game files / no GPU.

@catminou4

Copy link
Copy Markdown

Tested on Apple M1 Max, macOS 27.2.1 arm64: built replay_copy_offset_test from this head natively → passes (CopyResource/CopyTexture apply ResourceBinding::buffer_offset). No game files. AI-assisted (Devin).

@DaviDreamerz

Copy link
Copy Markdown

Tested c0209f3d2 on Windows 11 (build 26300), MSVC 14.44 RelWithDebInfo — native Windows, not Wine: pass.

  • ctest -R replay_copy_offset: passed
  • Negative control: with only runtime/src/vulkan_replay.h from 867d922f0 in the same tree, the same test fails with FAIL: conversion bounds result and FAIL: invalid conversion emits no image copy
  • CPU-only test; no GPU and no game files

AI-assisted: yes.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested c0209f3d on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 6312c057: pass

  • Built only the replay_copy_offset test target from the merged tree and ran it through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1, with two failing checks (conversion bounds result, invalid conversion emits no image copy).

So the new test depends on the change.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) with the agent's recheck.sh before posting.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at c0209f3. Full ctest -j 8, out of 239 tests:

No regression. The only failures are the same 5 as on main dde82f2 on this card (vk_queue_query_sync, d3d12_vulkan_device tiles == 1, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; tracked in #8426). Every test this PR adds or touches passes.

AI-assisted (Claude Code).

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.

8 participants