Recompiler: ShaderCache::bytes integer underflow / usize::MAX wraparound when evicting split compute (dispatch_chain) entries #2454
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2454
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?
@microwave805 on GitHub · 2026-11-25 19:30 UTC · original
Static audit on
main @ c7e1799found an integer underflow /usize::MAXwraparound inShaderCache::evict_one()whenever a split compute (dispatch_chain) shader is evicted. Part of #1269.Where
crates/xcl/src/gpu/recomp/pso.rs:731-739(ShaderEntry::bytes)crates/xcl/src/gpu/recomp/pso.rs:770-775(ShaderCache::evict_one)crates/xcl/src/gpu/recomp/pso.rs:813-840(ShaderCache::insert)Root cause
ShaderEntry::bytes()(pso.rs:736) accounts fordispatch_chainpiece capacities:However,
ShaderCache::insert()(pso.rs:813-816, 839) omitsdispatch_chainpieces when computingbytesforself.limitandself.bytes += bytes:When that entry is later evicted at
pso.rs:774(self.bytes -= old.bytes();),old.bytes()exceeds the amount added on insert by the sum ofchain.piecescapacities:shader_cache()Mutex.self.byteswraps to~usize::MAX, makingwhile self.bytes + bytes > self.limit(pso.rs:820) evict every entry on every subsequent insert (and risking addition wraparound).Trigger
Insert any split direct-DXIL compute shader (
shader.dispatch_chain.is_some()with non-emptypieces) intoShaderCache, then insert additional entries past the byte or entry limit so the split entry is evicted.Fix direction
Compute entry size through one shared helper (or construct
ShaderEntryfirst and useentry.bytes()in bothinsert()andevict_one()), and add a unit test inpso.rsthat inserts aCompiledwith a non-emptydispatch_chainand triggers eviction.AI use
main @ c7e1799and issue drafting.@Creaa on GitHub · 2026-11-25 19:33 UTC · original
Taking this. I will use the same size calculation for insertion and eviction, and add a unit test for the cache budget with a split compute shader. AI use: OpenAI Codex (GPT-6).
@ettehn on GitHub · 2026-11-26 12:27 UTC · original
Confirmed the insertion-driven eviction on Windows 11 (Rust 1.97.1 MSVC, debug) with one synthetic test and no GPU. With a split entry already cached, insert a plain entry sized to fill the whole byte budget. This exercises the eviction from inside
ShaderCache::insert.06055a7, the second insertion reachesevict_oneand panics atpso.rs:785withattempt to subtract with overflow.398cefb, the split entry is evicted, the replacement remains readable, andcache.bytesequals the budget. The same test passes.This verifies the debug panic and the fix at the insertion boundary. Release overflow behavior and retail runs were outside this check.
AI-assisted test and verification (OpenAI Codex).