mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #2021] d3d12: speed up TitleImageUpload nonzero scan and harden bounds/release state (RT-TITLE-IMAGE-UPLOAD-FAST-SCAN-AND-GUARDS) #2026
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2026
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2021
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/rt-title-image-upload-fast-scan📝 Commits (1)
d26bfafd3d12: speed up TitleImageUpload nonzero scan and harden bounds/release state📊 Changes
3 files changed (+380 additions, -11 deletions)
View changed files
📝
runtime/CMakeLists.txt(+11 -0)📝
runtime/shims/d3d12_title_image_upload.h(+56 -11)➕
runtime/test/title_image_upload_test.cpp(+313 -0)📄 Description
Claim:
RT-TITLE-IMAGE-UPLOAD-FAST-SCAN-AND-GUARDS(claim comment#7170576832on #1608).Problem
In
runtime/shims/d3d12_title_image_upload.h:inspect && !nonzero,TitleImageUpload::write()scannedslot.mapped + copy.bufferOffsetone byte at a time viastd::any_of. On discrete GPUs,HOST_VISIBLE | HOST_COHERENTstaging buffers are typically write-combined (WC), making byte-by-byte reads across multi-megabyte zero-filled textures extremely slow.write()did not guard!tiledor!block.block, used wrapping(extent + block - 1) / block, did not checkbytes + padforVkDeviceSizewrap, and multipliedrow * mip.height_elementsbefore verifyingslice <= UINT32_MAX(allowing 64-bit wrap past the check).vkWaitSemaphoresinwait_slot(): checkedvk.vkGetSemaphoreCounterValuefor null, then calledvk.vkWaitSemaphoresunconditionally.release(): leftslot.value,next_,value_,consumers_, andregions_populated acrossrelease().Fix
detail::has_nonzero_bytes()scanning mapped staging memory in 64-byte unrolleduint64_tOR-reduction chunks (then 8-byte and byte tails).!tiledand!block.block, use overflow-free1u + (extent - 1u) / block.block, guard alignment padding againstUINT64_MAX - bytes, and checkrow > UINT32_MAX / mip.height_elementsbefore multiplyingslice.if (!vk.vkWaitSemaphores) return false;inwait_slot().slot.value,next_,value_,consumers_, andregions_inrelease().title_image_upload(runtime/test/title_image_upload_test.cpp) drivingTitleImageUploadwith mock Vulkan functions.Benchmark (
clang++ -std=c++20 -O2, 16 MiB all-zero texture x 50 scans)std::any_ofbyte scan:219.74 msdetail::has_nonzero_bytes(64-byte unrolleduint64_tOR-reduction):8.67 ms(25.35x faster on cached RAM, and avoids byte-by-byte WC read transactions on discrete GPU staging buffers)Verification
runtime/test/title_image_upload_test.cpp(with minimaldxgiformat.hstub + Vulkan-Headers) cleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/shims/d3d12_title_image_upload.h runtime/test/title_image_upload_test.cpp runtime/CMakeLists.txtandpython3 -I tests/test_text_write_line_endings.py: all passed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.