Repository navigation
xg_xs copy_elements: dispatch fixed element widths 1/2/4/8/16 to a compile-time-sized copy loop (RT-TEXEL-COPY-FIXEDWIDTH) - #1880
Conversation
…time-sized memcpy loop copy_elements ran a runtime-sized std::memcpy per texel/block (the call is not inlined), which dominates TitleImageUpload::write on runtime texture refresh. The per-row element loop is now copy_tiled_row<Into, Width>, chosen by one switch on format.bytes per row: 1/2/4/8/16 get a constant-size memcpy, every other size takes the unchanged runtime-size loop. Addresses (row/column tables, pitches, linear fast path) are untouched, so the bytes written are identical, including for unaligned pointers and pitches and in both directions. texel_copy_test compares copy_elements with the original loop over the whole destination buffer: tiled and linear, mips and tails, arrays, volumes, widths 1/2/4/8/16 plus non-specialized 3/6/12, misaligned buffers and padded pitches.
|
On a Ryzen 7 7800X3D with MSVC 19.44
I built one executable per revision from the same benchmark source. The two PR parents have identical On this PR the two CPU suites passed ( Synthetic inputs. AI-assisted verification with OpenAI Codex. |
|
@ecox982745 — thank you; this closes the items the PR body listed as not-run. Recording for the merge decision: at Noting your benchmark also covers #1882 (per-element dispatch, same finding): on the identical benchmark it is 0.909 ms — byte-exact as well, ours is the row-level dispatch at 0.357 ms. The claim on this finding (RT-TEXEL-COPY-FIXEDWIDTH, comment 7164508666, 13:53 UTC) and #1880 (opened 14:05) both precede #1882 (opened 14:11, no claiming: for the item); per the board's claim-before-code rules I've noted that on #1882 — maintainers' call, of course. AI-assisted (orchestrator). |
|
Second run of the device tests for #1880 at head Config: Windows 11 (26300), RTX 4060 desktop, NVIDIA 610.88, MSVC 19.44, RelWithDebInfo, Vulkan SDK 1.4.363.0. Test targets only, no game files.
So: one unreproduced failure in a timing-dependent section, and no evidence either way that this PR causes it. Not covered: timing/frame benefit, full runtime build, full ctest. AI-assisted: yes (Claude Code ran the tests) |
|
@MoonEyes — thank you. Recording for the merge decision: the one AI-assisted (Claude Code). |
Native Windows 11 + MSVC
|
|
Verified by OreoFR
Note: shares AI-assisted (Claude Code, Claude Opus 5.5). |
RT-TEXEL-COPY-FIXEDWIDTH
Claimed on #1608 (#1608 (comment)); implements the first of @cheltyi's two findings (#1608 (comment)):
runtime/shims/xg_xs_layout.h'scopy_elementsissued a runtime-sizedmemcpyper texel/block — the pathTitleImageUpload::writeuses during runtime texture refresh. The finder's prototype (876 comparisons, ASan/UBSan clean, 4.54→0.596 ms on a synthetic 1024x1024 RGBA8 tiled texture under MinGW GCC 16.2 -O3) is the origin of this change; those numbers are the finder's, not re-measured here.What
copy_tiled_row<Into, Width>;copy_elementsdoes ONEswitch (bytes)per row: widths 1/2/4/8/16 get a compile-timeWidth, everything else takesWidth = 0— a verbatim copy of the old runtime-size loop. Address math untouched; linear textures still copy whole rows and never reach the element loop.Verification
runtime/test/texel_copy_test.cpp(ctesttexel_copy, no GPU): runscopy_elementsagainst a verbatim copy of the old loop, comparing the WHOLE destination buffer (bytes the copy must not touch are checked too). Corpus: 17 textures — R8, R16, RGBA8, RGBA16F, RGBA32F, BC1, BC3, BC5 (all five specialized widths) — tiled 4kb/64kb, linear, full mip chains with tails, arrays, 1D linear, 3D volumes; every case at 3 pointer misalignments × 3 pitch paddings; BOTH directions; and every case re-run with the width forced to 3/6/12 to prove the fallback path is unchanged./W4 /permissive-(VS 2022, winvm):texel_copy_testbuilt;ctest -R texel_copyPassed (4.57 s).xg_xs_testandd3d12_existing_heap_testwere not run (no device on this host).Attribution
AI-assisted (Claude Sonnet 5.5 worker implementation, contributor verification incl. the winvm MSVC build, orchestration).