Skip to content

UMA: used and sparse_used are running totals, alloc_in searches its window only - #522

Open
TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/xcl-perf3
Open

TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/xcl-perf3

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Uma::used() added up every live block on each call, and Uma::sparse_used() added up every sparse reservation. used() is asked before every coherent graphics VirtualAlloc (kernelx.rs:315), every committed placed resource (real.rs:1235) and every readback heap (real.rs:1263). So N title allocations cost O(N²) under the UMA lock. Both are now running totals, kept up to date where blocks and reservations are taken and returned.

alloc_in(k) also filtered the whole free map for window k. A free range never crosses a window boundary (each window is shorter than WINDOW), so it now walks only the keys in k's 4 GiB range. First-fit order and results are unchanged.

This doesn't change take_sparse_in's search; #483 bounds that one. The two PRs merge cleanly in either order (checked with git merge-tree).

What is in it

  • crates/xcl/src/gpu/uma.rs only:
    • Inner::used_bytes is updated in reserve_pool, alloc_where and free. used() and the XCL_TRACE_MEM trace read it.
    • Uma::sparse_bytes is updated through a new take_sparse wrapper (used by sparse_reserve, sparse_alloc_in and sparse_alloc) and in sparse_release. sparse_used() reads it.
    • alloc_where searches free.range(k·WINDOW..(k+1)·WINDOW) when it is given a window.
    • New test used_totals_follow_allocations_and_frees: the totals match the blocks and reservations through allocations, frees, coalescing, failed requests and unknown addresses.

Tested

  • RX 6800 (Adrenalin driver 32.0.21045.29003), Ryzen 9 5900X, Windows 11, rustc 1.100.0 stable-x86_64-pc-windows-msvc, release build.
  • cargo test -p xcl --lib: 634 passed, 3 failed, 21 ignored. The 3 failures are in title_textures::tests / vram::tests, and the same tests fail on origin/main (4 failures there on this machine). cargo test -p xcl --lib uma: 10 passed.
  • Throwaway microbenchmark (not committed), release build on the 5900X, for_runtime(1 GiB):
    • 4000 committed reserves, each preceded by a size() - used() check, plus 100k used() + sparse_used() reads: 592 ms → 0.97 ms (~600×).
    • 4000 sparse_alloc_in(0, 64 KiB) + sparse_used(): 12.2 ms → 0.43 ms (~28×).

Regression run

main:

xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 786 (PresentX 786)
presents per 2 s (last 3): 60 60 32
device removals: 0
crashes: 0
peak commit: 15147 MB

PR:

xcl-smoke v1
commit: 638c03951413279f24af06fbe3532f9732d67096
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 824 (PresentX 824)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15146 MB

Not tested

  • cargo test --workspace (only the xcl lib tests were run), other GPUs, MinGW builds.

AI use

  • Claude Code (Claude Opus 5.5) found the hot spot, wrote the change and the test, ran the benchmarks, tests and regression runs; reviewed by the submitter.

🤖 Generated with Claude Code

@thehollowedone

Copy link
Copy Markdown

Tested

I built and tested the full synthetic workspace on the RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug. For both revisions I ran cargo build --offline --locked --workspace followed by cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4, with all XCL_SAMPLE_* variables unset.

Revision Cargo passed Failed Ignored GPU skips included in passes
Exact parent 7ebf1b8 677 0 41 2
PR head 638c039 678 0 41 2

The PR adds one UMA accounting test, and the texture and VRAM failures reported on the RX 6800 did not occur in either run here. Both revisions reported the same wave64 skips (gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware).

Not tested

Retail titles, release performance, or the PR integrated with newer main commits.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 638c03951413279f24af06fbe3532f9732d67096 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; used_totals_follow_allocations_and_frees passes.

Review: I checked that the running totals cannot drift: in uma.rs at the PR head, both used.inserts add to used_bytes and the one used.remove subtracts the removed size; every reservation goes through take_sparse, which adds the same size take_sparse_in inserts, and sparse_release subtracts the size it removes from the map. alloc_in's range(k·WINDOW..(k+1)·WINDOW) relies on free ranges not crossing a window, which holds since each window is shorter than WINDOW. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@thaqiart139-alt

Copy link
Copy Markdown

Test report for this PR's head 638c039, merged into main 689f2db (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with XCL_ADAPTER.
  • System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
main 689f2db with this PR
RTX 5070 971 passed, 4 failed, 45 ignored 972 passed, 4 failed, 45 ignored
Radeon iGPU 974 passed, 1 failed, 45 ignored 975 passed, 1 failed, 45 ignored
SKIPPED tests (the same on main and with this PR)
  • RTX 5070:
    • no wave64:
      • gpu::recomp::lower::tests: a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu
      • gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu, and the wave64 cases of its f16 / f32 / f64 / integer_programs_on_the_gpu
      • gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
    • the wave32 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused ("its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's")
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off)
  • Radeon iGPU:
    • no mesh shaders: gpu::dxil::geometry_tests::gpu_geometry_direct_records, emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_geometry_mode_es_gs_strip_with_branches, gpu_mesh_mode_two_passes
    • the wave32 and wave64 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused, as above
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off)

Not tested

  • a title run, MinGW builds; other GPUs; Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/gpu/uma.rs
…indow only

`Uma::used()` summed every live block and `sparse_used()` every sparse
reservation on each call. kernelx asks `used()` before each coherent
graphics allocation and real.rs before each committed placed resource and
readback heap, so allocating N blocks cost O(N^2). Both are now totals
updated where blocks and reservations are taken and returned.

`alloc_in(k)` filtered the whole free map for window k. Free ranges never
straddle windows, so it now walks only the keys in k's 4 GiB range.
First fit order is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TG0000

TG0000 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 1a0bbe3: head af0f5b8. The conflict was in the tests only. I also checked main's new window layouts: every place that takes or returns a block or a sparse range goes through the running totals.

Run on this head (Ryzen 9 5900X, Windows 11, MSVC): cargo test -p xcl --lib uma: 16 passed, 0 failed. Clippy stops on three TAU constants in files this PR does not touch, with this toolchain.

Not run on this head: the whole suite, the microbenchmark and the xcl-smoke pair. The blocks in the description are of 638c039, so the description check is expected to ask for a fresh one until it is run.

AI-assisted (Claude Code).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants