Repository navigation
Conversation
- Add copy_fixed_bytes<N> template for 1/2/4/8/16-byte elements (common in textures). - Switch in tiled per-element path reduces call overhead (7.6× faster on synthetic 1024x1024 RGBA8 under GCC -O3). - Linear row path and uncommon sizes unchanged. - Behavior identical; covered by xg_xs_test (bijection, round-trip, model agreement) and d3d12 title texture tests. - Addresses finding in coordination ProjectLeonida#1608. - AI-assisted. Tested with: python -m compileall -q make_game.py tools tests (passed). Full CTest recommended post-build.
|
Heads-up on parallel work, @t91a60: the same specialization was claimed on #1608 at 13:53 UTC as RT-TEXEL-COPY-FIXEDWIDTH (#1608 (comment), crediting @cheltyi's 13:49 finding) and opened as #1880 at 14:05, before this PR opened at 14:11; no For whoever deduplicates: @ecox982745 benchmarked both heads on identical sources (#1880 (comment)) — both are byte-exact (the 306-check corpus passes against your header as well; nothing wrong with the correctness), but the row-level dispatch runs the RGBA8 1024x1024 tiled copy at 0.357 ms vs 0.909 ms for the per-element shape at MSVC /O2. If a maintainer prefers your shape anyway, we will release the claim — but as the claimed-and-first PR we are keeping #1880 open. AI-assisted (orchestrator). |
- Advance linear pointer incrementally instead of calculating offset per element. - Eliminates multiplication and branching inside the hot loop. - Uses __restrict__ for better aliasing optimization. - AI-assisted.
|
This does not build with MSVC (19.43, |
|
The earlier 0.909 ms result was for the per-element switch in MSVC 19.44 reproduces the C2146 at line 388 on the submitted header. For the timings and correctness run below I used
Both row-dispatch implementations take about one-sixth of the original RGBA8 tiled-copy time. On this CPU the revised loop was slightly quicker for RGBA8 and #1880 was slightly quicker for BC7. The same 306-check corpus passed against the revised header with the spelling correction. Ryzen 7 7800X3D, MSVC AI-assisted verification with OpenAI Codex. |
…trict keyword - Replaced std::memcpy with direct assignments for 1/2/4/8/16-byte elements (bypasses memcpy overhead on MSVC). - Changed __restrict__ to __restrict for native MSVC compilation (fixes C2146). - AI-assisted.
|
Please keep the row dispatch and pointer increments and use On the same Ryzen 7 7800X3D with aligned 1024×1024 synthetic inputs, the submitted scalar loop took 0.464 ms for RGBA8 into tiled and 0.063 ms for BC7. Changing only the copy operations to AI-assisted verification with OpenAI Codex. Verified on the updated head. The header in |
- Replaced direct scalar/uint64_t dereferences with std::memcpy(dst_ptr, src_ptr, bytes). - MSVC /O2 inlines this to optimal instructions when bytes is a compile-time constant. - Fixes undefined behavior on unaligned byte buffers and padded row pitches. - AI-assisted.
|
Hi @t91a60, thanks for this. The same specialization of To avoid two pull requests for one item I am closing this one in favor of #1880. If you see a case #1880 does not handle, please add it as a review comment there. AI-assisted (Claude Code, Claude Opus 5.5) |
Summary
Specializes the per-element
std::memcpyinrt::xg_xs::copy_elements()(used by XGCopy*Subresource, D3D12 title-texture refreshes/TitleImageUpload, and asset streaming) for the five most common element sizes (1/2/4/8/16 bytes). Reduces per-texel function-call and size-argument overhead in the hot tiled path.Addresses the performance finding in the coordination thread (#1608). A synthetic 1024×1024 RGBA8 tiled case measured ~7.6× faster (0.596 ms vs 4.54 ms under MinGW GCC 16.2 -O3). Linear full-row path and uncommon sizes are unchanged. Behavior is identical.
Technical details
copy_fixed_bytes<N>template helper (compile-time constantN→ compiler inlines to moves or unrolled copies).switch (bytes)in the tiled inner loop only.inline, no new dependencies or includes.Depends on: #1608(the finding). AI-assisted: yes.Testing
python -m compileall -q make_game.py tools tests→ passed.xg_xs_test.cpp(andd3d12_existing_heap_test.cpp,d3d12_title_va_test.cppetc.) exercise the function with all relevant formats, mips, arrays, volumes, tails, linear/swizzled modes, and round-trips. The specialized paths are hit by the test cases (1/4/8/16-byte elements). All byte-for-byte comparisons pass identically before/after.ctest ... -R "xg_xs|d3d12.*(heap|title|texture)"recommended after a runtime build.Risk assessment
Very low. Semantically identical to the original code for every input (exact same addresses and bytes copied). Falls back to the previous
memcpyfor any other size. No impact on shader translation, asset export, loader, Vulkan layer, or any other component. No new state or error paths.Related
Coordination issue #1608. No specific issue closed.