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
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1880"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-11-25T14:01:14Z.
RT-TEXEL-COPY-FIXEDWIDTH
Claimed on #1608 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164508666); implements the first of @cheltyi's two findings (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164354183):
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).
Rebase verification — 2026-11-30
71a769d7d85208f86c6e2e50263aca7df1becce9; head1cd6eaf7c67e05d0f9183da0869843acc498fadb.shader_library_corpusskipped.Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T14:17:20Z.
On a Ryzen 7 7800X3D with MSVC 19.44
/O2, the once-per-row dispatch in this PR took 0.357 ms to copy a synthetic 1024×1024 RGBA8 texture into its tiled layout. The original took 2.126 ms, and #1882's per-element dispatch took 0.909 ms in the same benchmark.5e95fa2f47f9e656e3cc4ac4101I built one executable per revision from the same benchmark source. The two PR parents have identical
xg_xs_layout.handgfx10_tiling.h. Each process used one pinned CPU thread and reused its buffers and column scratch. For each layout it ran five warm-up round trips and timed the next 15 copies in each direction, checking the final round trip byte-for-byte. The table gives the median across six process runs per build, using all six orderings of the three builds. For RGBA8 into tiled, the six run medians ranged from 0.357–0.362 ms on this PR and 0.908–0.942 ms on #1882. These are warm CPU copy timings. End-to-end texture streaming and frame times are still open.On this PR the two CPU suites passed (
xg_xs465 checks,texel_copy306 checks), and all threed3d12_existing_heapCTest variants passed on native Windows 11 with an RTX 4090 (616.64). I also compiled the same 306-check corpus against #1882's header and got zero failures.Synthetic inputs. AI-assisted verification with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-11-25T14:24:50Z.
@ecox982745 — thank you; this closes the items the PR body listed as not-run. Recording for the merge decision: at
7f9e656e3on a Ryzen 7 7800X3D / MSVC/O2, the row-level dispatch is 5.95x the original (0.357 ms vs 2.126 ms for RGBA8 1024x1024 into tiled, both directions) with linear-copy control unchanged (0.074 ms);xg_xs465 checks andtexel_copy306 checks pass, and all threed3d12_existing_heapvariants pass on native Windows 11 / RTX 4090 (616.64) — the device tests we couldn't run. Frame-time on a streaming workload remains open, as the finding said it would.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).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T18:16:01Z.
Second run of the device tests for #1880 at head
7f9e656e3, after @ecox982745's on an RTX 4090. One thing to report: a single failure I could not reproduce.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.
xg_xs(465 checks),texel_copy(306 checks),d3d12_existing_heap_no_write_watch,d3d12_existing_heap_write_watch: pass.d3d12_existing_heap: failed once on the first ctest pass, then passed 23 of 23 direct reruns. The failure was in the concurrent stress section:vulkan slot-133 heap-lock faults: the write-watched half is not hot after the stress, thenline 1757: !failed. That check guards the test's own validity (the watched half must stay hot), it is not a data comparison. An MSVC build was running on the machine at that moment.xg_xs_layout.hfrom the merge base (98c2f7777) passed 20 of 20, alternated with the PR binary. I could not reproduce the failure on either side.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)
Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-11-25T19:57:24Z.
@MoonEyes — thank you. Recording for the merge decision: the one
d3d12_existing_heapfailure (write-watched half not hot after the concurrent stress, a check on the test's own validity, with an MSVC build running) did not reproduce in 23/23 reruns on the PR build or 20/20 alternating with the merge-base header, so there is no evidence it comes from this change. The device tests (xg_xs465,texel_copy306, both write-watch variants) pass on the RTX 4060 and, per @ecox982745, the RTX 4090. Frame-time on a streaming workload is still not measured.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:06:36Z.
Native Windows 11 + MSVC
19.44+ RTX 3090 Vulkan Verification (7f9e656e37+origin/mainadfb3821a2)Verdict: PASS (0 blockers, 0 new
/W4warnings; 4.7x-8.0x RGBA8 & 2.0x-2.3x BC7 speedup confirmed)Environment & Merge Check
10.0.26200), MSVC19.44.35228(x64,/W4 /permissive- /utf-8 /O2 /EHsc), NVIDIA GeForce RTX 3090 (Ampere, ReBAR enabled)origin/main(adfb3821a2,git merge-tree --write-treerc=0).Red -> Green, CPU A/B Benchmark & RTX 3090 GPU Results
PR #1880 + origin/main):texel_copy_test.exe: PASS (306 checks, 0 failures,1.95 s,0new/W4warnings).xg_xs_test.exe: PASS (519 checks, 0 failures,0.43 s).1024x1024mip 0, 5 warmups + median of 25 round-trips, byte-exact verified):RGBA8(kSwizzled | k64kbD):into2.428 ms -> 0.514 ms(4.72x),out3.164 ms -> 0.395 ms(8.01x).BC7(kSwizzled | k64kbS):into0.125 ms -> 0.061 ms(2.05x),out0.113 ms -> 0.049 ms(2.31x).d3d12_existing_heap_test.exelinked with#1880'sxg_xs_layout.h):d3d12_existing_heap(default): PASS (rc=0,8/8OpenExistingHeapFromAddresscases + concurrent write-watch stress clean).d3d12_host_prefix(--host-prefix-only): PASS (rc=0,0.89 s).d3d12_mapped_plane_async(--mapped-plane-async): PASS (rc=0,0.35 s).d3d12_existing_heap_no_write_watch(LEONIDA_WRITE_WATCH=0): PASS (rc=0,7.12 s).d3d12_existing_heap_write_watch(LEONIDA_WRITE_WATCH=1): PASS (rc=0,9.09 s).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T02:41:19Z.
Verified by OreoFR
aa918e5d9+ PR head7f9e656e3ctest -R ^texel_copy$Note: shares
runtime/CMakeLists.txtwith the open #2566; a rebase may be needed if #2566 lands first.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by thiefyzheng on 2026-11-30T23:39:09Z.
Rebased onto current
main(71a769d7d85208f86c6e2e50263aca7df1becce9); new head is1cd6eaf7c67e05d0f9183da0869843acc498fadb. Theruntime/CMakeLists.txtconflict was resolved additively, preserving both main'sd3d12_xs_alloc_size_testand this PR'stexel_copy_test; the fixed-width implementation and focused test are otherwise unchanged.Rebased-head verification (Linux, CPU-only, synthetic data):
g++ 14.2.0, C++20, ASan+UBSantexel_copy_test: 306 checks, 0 failures. (A scratch-only DXGI enum header supplied the Windows constants outside the repository.)ctest -j4: 56/56 passed,shader_library_corpusskipped because its optional corpus is absent. Windows-onlytexel_copyis not part of this Linux ctest set and was run directly as above.check_no_game_data.pyon all three changed files andgit diff --check: clean.Not rerun: Windows/MSVC build, device tests, GPU correctness tests or performance benchmarks. Earlier Windows/NVIDIA measurements remain historical results, not a benchmark of this rebased head.
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-12-01T01:16:03Z.
Independent native Windows rebase check. I merged head
1cd6eaf7cinto maind920d850dwithout conflicts, giving tree0a24df8bd. A clean MSVC 19.44 Release build compiled all three stock targets. CTest registered them and each passed three consecutive serial runs.texel_copyd3d12_xs_alloc_sizexg_xsThis verifies the native CMake rebase kept the newly added copy test and main's adjacent allocation-size test. The tests used synthetic inputs and ran on the CPU.
AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:11:16Z.
Review: APPROVED
Clean, well-scoped optimization: dispatching fixed-width
copy_elements<N>specializations for 1/2/4/8/16-byte texels eliminates variable-lengthmemcpycalls in the inner swizzle/deswizzle loop while keeping the generic fallback for other strides. The 306-check byte-exact round-trip test (runtime/test/texel_copy_test.cpp) and independent A/B timings confirm correctness and the 4.7x-8.0x RGBA8 speedup, and all CI checks are green. Merging.(AI-assisted review.)