Skip to content

first_light: check_image reads the readback through a float view (BUILD-1052) - #3783

Closed
ezbyDev wants to merge 1 commit into
ItsNotRexed:mainfrom
ezbyDev:build-1052-check-image-view
Closed

ezbyDev wants to merge 1 commit into
ItsNotRexed:mainfrom
ezbyDev:build-1052-check-image-view

Conversation

@ezbyDev

@ezbyDev ezbyDev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BUILD-1052 (#3574 (comment))

What and why

tools/first_light.py's check_image unpacked the whole readback into a Python float per channel:
struct.unpack(f"<{len(data) // 4}f", data). A first-light frame is 512x512 RGBA32F, so one check built a
1,048,576-item tuple (33,555,456 bytes peak at the reported size; 33,553,580 here) just to count alpha coverage
and probe four pixels.

The frame is now read through a little-endian float view, memoryview(data).cast("f"), which is the host byte
order on x86 and ARM64. The view allocates nothing per channel, pixels[3::4] counts the alpha channel, and only
the four probed pixels are turned into a tuple, so the failure messages still print the same four values. A
big-endian host keeps the explicit little-endian struct.unpack path. The covered count, ratio, tolerances and
diagnostics are unchanged.

One synthetic 512x512 RGBA32F frame (every pixel .25/.75/0/1, centre UV .25/.75), Python 3.12.10, Windows 11,
CPU only:

peak traced allocation median check time (21 runs, after warm-up)
parent f847748c 33,556,112 B 78.72 ms
this branch 1,868 B 17.76 ms

Tested

  • python -I tests/test_first_light.py: 12 tests, OK, 3 skipped (LEONIDA_FIRST_LIGHT_DIR unset, the
    package-gated ones). The new test fails on the parent with AssertionError: 33553580 not less than 1048576.
    This sandbox cannot enter directories created with mode 0o700 (tempfile's default), so the local run wrapped
    os.mkdir to ignore the mode; the test file is unmodified and CI runs it as-is.
  • python -m compileall -q make_game.py tools tests: clean.
  • python -I tests/test_text_write_line_endings.py: 2 tests OK.
  • python -I tests/test_first_light.py -k OracleTests: 5 tests OK, including the new one.
  • Merges cleanly with first_light: test NaN rejection across checked UV-mode channels #3606, which changes the tolerance lines of the same function: git merge of its head onto
    this branch auto-merged both files.
  • No GPU run: this path never reaches Vulkan. The AMD Radeon RX 9060 XT (driver 32.0.32029.2010) on this machine
    was not used, and no game files were read.
  • AI-assisted (Claude Code).

Checklist

  • 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. (No new rule.)

Depends on: none

…le of Python floats (BUILD-1052)

check_image() unpacked every channel of the frame into one Python float, so a 512x512 RGBA32F readback (the
first-light output) became a 1,048,576-item tuple: 33,555,456 bytes peak and ~79 ms median per check on this
machine, for a coverage count and four probed pixels. Read the frame through a little-endian float view instead
(memoryview.cast('f'), the host byte order on x86 and ARM64) and count the alpha channel from its slice. Peak
allocation for the same frame is now 1,868 bytes and the median check 17.8 ms. A big-endian host and the tests
keep the explicit struct.unpack path, and the failure messages still print four channel values.

Pinned by tests/test_first_light.py::OracleTests::test_a_512_square_frame_is_checked_without_expanding_it, which
fails on the parent (33,553,580 bytes) and passes here.
@ezbyDev

ezbyDev commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Withdrawing this: @Koro4e claimed BUILD-1052 first (#3574 (comment)) and has #3771 for it, which I missed because my copy of the tracker predated that comment. Keeping a second PR for the same function would only add review work, so this is closed and I have released the claim. Thanks for the pointer, @KoertLichtendonk.

(For the record, in case anything here is useful for #3771: check_image reads the frame through a little-endian float view, counts alpha from pixels[3::4], and the tracemalloc test shows 33,553,580 bytes on the parent vs 1,868 bytes here.)

@ezbyDev ezbyDev closed this Nov 22, 2026
@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Overlap: this is the second open PR for BUILD-1052. #3771 (@Koro4e) makes the same change to check_image: it reads the frame through a memoryview(data).cast("f") float view in place of the per-channel struct.unpack tuple.

This PR has two things #3771 lacks: the sys.byteorder fallback to struct.unpack on big-endian hosts, and the new tests in tests/test_first_light.py. Those could go to #3771 as review suggestions or as a follow-up on top of it, rather than as a second PR for the same item.

AI-assisted (Devin).

@eyyun

eyyun commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested 9c7cff45 on Windows 11 (Python 3.13), and compared it side-by-side with #3771 (which also targets BUILD-1052):

AI-assisted.

@ezbyDev
ezbyDev deleted the build-1052-check-image-view branch November 22, 2026 22:18
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