perf(radv): skip sorting ordered dirty ranges #222
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!222
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-222"
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?
@tommiehansen on GitHub · 2026-12-02 19:12 UTC · original
tommiehansen:perf/radv-dirty-range-sort→main· +22 −11 · 1 files · 4 commits · openWhat this does
Skip sorting ordered dirty ranges.
Checks
cargo xtask policyon the final revision; no new game assets or build output intended.Verified
Current review head:
e7fdab6145a1028bbaea8b8b1ee5d4a2c7d3f64e. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.Cost
Sort avoided in 45/60 synthetic flushes; no live driver/FPS timing.
Detailed implementation and historical validation
RADV sorts the dirty range array before merging and publishing mapping updates, including when inserts were already in address order. Track possible loss of ordering under the existing lock, including insertion and backward extension of the last entry. Sort when needed and reset the marker alongside the range count.
The original iteration and range union still run in ascending order. The patch preserves paging operations, cache scopes, backing allocations, references and submission synchronization. Ordered batches avoid a sort on the mapping flush path.
Comparison
The avoided sort reduces CPU preparation work only; actual benefit depends on range counts and the share of ordered batches.
Validation
The patch applies to pinned Mesa 26.3.1. A compiled differential C harness emitted identical flush intervals in 4,096 generated sequences. A full Mesa Linux build was unavailable.
Hardware benchmarking was unavailable. Please compare streaming frame times and mapping behavior at native 1080p on RX 9060 XT 16 GB and native 1440p on RX 9070 XT under Linux, with RT enabled and frame generation disabled.
Pass 2B — dirty range model and integration
45591b0d20f287d6412133a1a795add6412133a1a795adBoth variants passed the Rust model oracle with identical rejection digests. The fixture contains ordered inserts, backward-extending merges and out-of-order inserts. The sort was skipped in 45 of 60 synthetic flushes. The separate standalone C model reported 5.028 → 1.928 µs for 2,048 ordered disjoint ranges and 38.332 → 38.416 µs for 2,048 unsorted ranges. Its 10,000-round differential check matched the unconditional-sort result. Neither model is a full Mesa build. The real RADV alias workload was Unsupported locally, so the frequency of ordered batches and frame-time impact on Linux remain unverified.
An integration simulation with #217 at
8754a4bfound six conflicts confined to nested patch hunk offsets. The actual C changes combined cleanly. After recalculating the offsets in a temporary copy, the patch parsed and both model variants passed with their individual digests. Once either PR lands, refresh the other PR’s nested hunk offsets against the resulting main branch. Both PRs are currently independently mergeable against main.Queue refresh — 2026-12-05
Merged upstream main
b581f7e0a8086158953a64068ba29305d5450d68into the existing branch without rewriting history. New head:268c1737520d004154d46241c22218f7ebd6c79e. The existing ordering assertion is retained. After #217 or #222 lands, regenerate the remaining patch header and recheck application.Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.
8f6bb3dc4cto788b162a20@tommiehansen on GitHub · 2026-12-03 19:59 UTC · original
Audit, 10,000-Round C Differential Check & Benchmark Verification
Audited
fork/perf/radv-dirty-range-sortagainstorigin/main(45591b0): no additional code changes needed (the patch cleanly tracks both out-of-order appends and backward-extending mergesum->dirty_count > 1 && last[-1].start > last->start, and resetsdirty_unsorted = falseon flush).Standalone C Model Benchmark & Differential Check (
clang -O2 -Wall -Wextra -Werror, A/B/B/A 8-block median)origin/main(qsortevery flush)dirty_unsorted)N=256)N=2048)N=2048 -> 64)N=256,qsortruns)N=2048,qsortruns)qsort.verify_patch.pyconfirmed all 39 hunks / 0 errors inpatches/mesa.patch.radv_amdgpu_um_dirty/radv_amdgpu_um_flush_locked; full Mesa compilation and live RADV/AMD GPU execution require external Linux hardware.@CorvetteCole on GitHub · 2026-12-04 01:36 UTC · original
Hardware numbers on RDNA3 at native 1440p. I tested this together with #217 (both on top of
45591b0'spatches/mesa.patch), so the result below is for the pair, not this PR alone.Setup
fec8830) built from eachpatches/mesa.patchwith the same options as the pinned build (meson --buildtype release -Db_ndebug=true,-O3,vulkan-drivers=amd, llvm off).45591b0withVKD3D_UNTYPED_VEC_SSBO=1(local, not in this repo), native 1440p (VICTORY_RENDER_SCALE=1.0),VICTORY_SHADER_OPT=63,VICTORY_WARM=0.d20f287and #217 at8754a4bon top of45591b0'smesa.patch. #217's patch applied cleanly; this PR's change was applied as a source delta with a 3-way apply and no conflicts (together 2 files, +21/−7 against45591b0's Mesa tree).drops=0on every run. Frame time is the mean of the last 8 samples.Frame time
45591b0mesa.patch→ + #217 + this PR45591b0runs, 36.46 ms)Same scene on every arm; captures look identical apart from the animated TV content.
What the run shows about this path
qsortand not changing what gets mapped.drops=0; I can't show a measurable gain from this PR alone.45591b0's own Mesa, the game logs "the driver does not move single pages … each pool stays where it starts" (thepages_move()probe inum.rsfails on Mesa 26.3.1 / this card), and "maps not shown" stays at1, so the3b73abeearly exit never fires in this workload.@Luxuride on GitHub · 2026-12-04 12:02 UTC · original
The invariant reads correct — appends happen under
um->lock(patches/mesa.patch:1370), the flush locks at:1018, the two flag sites (:764,:779) compare against the previously-last entry, and:764'slast[-1]is guarded bydirty_count > 1. No defect found.What I would push back on is the trade: you are asking the maintainer to keep an ordering invariant alive in a 5,400-line vendored patch (which #267 also rewrites hunks in) to save one
qsortof a few thousand 16-byte ranges per flush. And the stale-flag failure is silent —radv_amdgpu_um_flush_lockedmerges out-of-order ranges and updates mirrors over the wrong spans, i.e. wrong pixels rather than a crash.So: show the flush in a profile, or drop it. If you keep it, add an
assertin the flush (NDEBUG off costs nothing) and rebase together with #217 so the two hunk-header edits (+1437/+1438atpatches/mesa.patch:268) are regenerated once —setup.sh:72applies the patch withgit apply --indexand a wrong count breaks every setup run.@tommiehansen on GitHub · 2026-12-04 12:49 UTC · original
@Luxuride Pushed commit
e7fdab6adding the debug-only ordering assertion and regeneratingpatches/mesa.patchcleanly against pinnedmesa-26.3.1:#ifndef NDEBUGinradv_amdgpu_um_flush_locked()):if (um->dirty_unsorted) qsort(...):NDEBUGis defined (setup.shbuilds Mesa with-Db_ndebug=true), so release driver builds perform zero post-check scan.qsort):-O0,-O2, and-O2 -DNDEBUG) extractingradv_amdgpu_um_dirty()andradv_amdgpu_um_flush_locked()directly from the regenerated patch across ascending appends, backward merges (extendinglast->startbelowlast[-1].start), overlapping/descending starts, post-flushdirty_unsortedresets, and 1,000 randomized mixed batches (20,000+ intervals): 0 mismatches, merged flushed(start, end)spans identical to unconditionalqsort.git apply --indexchecks (without stacking #217/#222):#217(9afefcc) applies cleanly alone (git apply --index) onto pinnedmesa-26.3.1.#222(e7fdab6) applies cleanly alone (git apply --index) onto pinnedmesa-26.3.1.mesa-26.3.1via 3-way cherry-pick mergessrc/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.cautomatically with zero conflicts, and the combined 15-file patch applies cleanly withgit apply --index(1743 insertions(+), 7 deletions(-)).#322,45591b0vse7fdab6, Standard, 4 blocks):mapping/radv_dirty_range_sort_model:0.016 → 0.016 ms(−0.55%,Inconclusive,identicaldigests;sorts_executed:60 → 15,sorts_skipped:0 → 45,dirty_ranges_coalesced:15,360).mapping/radv_um_aliasisUnsupportedon CPU-only macOS; live Linux RADV driver profiles remain external/unmeasured, and timing improvements are not claimed from the CPU patch model.Skip sorting ordered RADV dirty rangesto perf(radv): skip sorting ordered dirty rangesView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.