mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:35:53 +01:00
[PR #2029] runtime: guard overflow/div-by-zero and remove duplicate passes in d3d12_xs_alloc_size #2035
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#2035
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/2029
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-xs-alloc-size-overflow-and-single-pass📝 Commits (1)
0c4bdderuntime: guard overflow/div-by-zero and remove duplicate passes in d3d12_xs_alloc_size📊 Changes
3 files changed (+274 additions, -45 deletions)
View changed files
📝
runtime/CMakeLists.txt(+9 -0)📝
runtime/shims/d3d12_xs_alloc_size.h(+94 -45)➕
runtime/test/xs_alloc_size_test.cpp(+171 -0)📄 Description
Coordination item:
RT-XS-ALLOC-SIZE-OVERFLOW-AND-SINGLE-PASS(claimed on #1608).Why
align_up_saturating(value, to)inruntime/shims/d3d12_xs_alloc_size.hdivided bytounconditionally, causing integer divide-by-zero ifto == 0.console_render_target_size()andconsole_depth_stencil_size()documented returning0on overflow, yet accumulatedslice += surface.tiled_size()andslice += kConsoleTileByteswithout checkingUINT64_MAX - slice. Multi-mip render targets (e.g.0x3FFFFFBF x 0x3FFFFFBF16-byte format, 2 mips) and multi-plane depth-stencil targets (e.g.0x7FFFFF7F x 0x7FFFFF7FD32_FLOAT_S8X24_UINT) silently wrappedsliceto4,611,683,819,404,197,888instead of returning0. Checkingdesc.Width > UINT32_MAXbeforestd::bit_width()also avoids entering the mip shift loop on >32-bit widths.console_placement()executed up to 3 passes wheneach != nullptr(anany_targetpre-scan plus two full passes that each calledpc_one(i)and re-evaluatedconsole_texture_layout/console_render_target_size/console_depth_stencil_size), doublingID3D12Device::GetResourceAllocationInfocalls and tripling XG layout work.Changes
runtime/shims/d3d12_xs_alloc_size.h:if (to <= 1) return value;inalign_up_saturating().desc.Width > UINT32_MAXupfront and checkUINT64_MAX - slicebefore every mip/tail addition inconsole_render_target_size()andconsole_depth_stencil_size().pc_onecalls when none apply, run a singlepc_onelayout pass stagingeachentries locally, and publishtotal/eachonly after succeeding withgrows == true.runtime/test/xs_alloc_size_test.cpp+runtime/CMakeLists.txt: add CPU-onlyxs_alloc_sizeunit test coveringalign_up_saturating(to=0), width/mip/plane overflow guards, fail-closedeach/totalpreservation, single-passpc_onecall count, and thecount > 16spill path.Verification
runtime/test/xs_alloc_size_test.cppwithclang++ -std=c++20 -Wall -Wextra -Werror:-O1 -g -fsanitize=address,undefined):xs_alloc_size_test: OK (0 failures).-O1 -g -fsanitize=thread):xs_alloc_size_test: OK (0 failures).-O2):xs_alloc_size_test: OK (0 failures).-O2benchmark (20,000 calls toconsole_placementover 8 mixed RT/CPU/DS descriptors with non-nulleach):main: wrapped overflow cases to4611683819404197888;pc_calls=320000(22.657 ms).0on both overflow cases;pc_calls=160000(2× fewerpc_onecalls,14.105 ms/ 1.61× faster, bit-exact layout checksum).python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_alloc_size.h runtime/test/xs_alloc_size_test.cpp runtime/CMakeLists.txt: clean.python3 -I tests/test_text_write_line_endings.py: 3/3 OK.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.