runtime: guard overflow/div-by-zero and remove duplicate passes in d3d12_xs_alloc_size #2029
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2029"
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 IlyassRS3 on 2026-11-25T18:32:32Z.
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.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T18:32:46Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:51:46Z.
Hi @IlyassRS3, thanks for this pull request. It currently conflicts with
main(conflicting file(s):runtime/shims/d3d12_xs_alloc_size.h), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:40:38Z.
Carried as #2739 because of the conflict with main after #2566; @IlyassRS3, if you come back, say so and the carry is dropped.