mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:25:52 +01:00
[PR #2022] d3d12: index TitleGpuPlacements in O(1) hash map and fix mip/layer overflow (RT-TITLE-GPU-PLACEMENTS-HASH-AND-OVERFLOW) #2027
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#2027
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/2022
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/rt-title-gpu-placements-hash📝 Commits (1)
6a65fe6d3d12: index TitleGpuPlacements in O(1) hash map and fix mip/layer overflow📊 Changes
2 files changed (+57 additions, -16 deletions)
View changed files
📝
runtime/shims/title_gpu_placements.h(+44 -16)📝
runtime/test/d3d12_existing_heap_test.cpp(+13 -0)📄 Description
Claim:
RT-TITLE-GPU-PLACEMENTS-HASH-AND-OVERFLOW(claim comment#7170709644on #1608).Problem
In
runtime/shims/title_gpu_placements.h(held underdescriptor_mutexfor every placed-resource descriptor lookup):TitleGpuPlacementsstored placements in astd::multimap<std::uint64_t, Resource*>even though every operation (add,remove,find) is an exact-VA lookup (never ordered iteration or range scan).alias == va:find(va, alias, matches)probed{va, alias}unconditionally even whenalias == va.matches(const gfx10::Image&, const D3D12_RESOURCE_DESC&):image.first_mip + image.mip_count > d.MipLevelsandimage.first_layer + image.layer_count <= d.DepthOrArraySizewrappeduint32_tnearUINT32_MAX(e.g.first_mip = 0xffffffffu, mip_count = 1wrapped to0 <= d.MipLevelsand falsely matched).Fix
std::multimapwithstd::unordered_map<std::uint64_t, Bucket>whereBucketstores the single common placement inline (Resource* first) with an overflowstd::vector<Resource*> extrafor overlapping lifetimes at the same VA — zero extra allocation in the single-resource case, O(1) lookup, and exact newest-first (LIFO) search order preserved.add()and skip the second probe infind()whenalias == va.matches()with overflow-free subtraction (image.first_mip > d.MipLevels || image.mip_count > d.MipLevels - image.first_mip, and similarly forfirst_layer/layer_count).runtime/test/d3d12_existing_heap_test.cpp(0CMakeLists.txtedits).Benchmark (
clang++ -std=c++20 -O2, bit-exact A/B, 16,384 placed resources x 500,000find()calls)std::multimap):42.60 msstd::unordered_map+ inline-1 LIFO bucket):1.49 ms(28.54x faster)Verification
runtime/shims/title_gpu_placements.hunit + A/B parity tests (verifying LIFO order, multi-element front/middle/back removal,va == aliassingle-probe, and wrapping mip/layer rejection vs old code) with minimal D3D12/DXGI stubs 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/title_gpu_placements.h runtime/test/d3d12_existing_heap_test.cppandpython3 -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.