mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(gpu): an exact resident budget returns the loan and lends nothing (CodeRabbit)
set_resident_budget now gives the borrowed bytes back to the effect-map share before setting the exact budget, so memory_budget() stays the total, and fit_layers lends nothing until the next set_memory_budget. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CD2ipSyvx1tYwnHJZyDs59
This commit is contained in:
1 parent
336c419f2f
commit
18eb34b012
2 files changed
+16
-2
No files matched your search
@@ -472,6 +472,8 @@ pub struct Compositor {
|
||||
layer_need: u64,
|
||||
/// Bytes of `fx_budget` lent to `resident_budget` so those pages fit.
|
||||
lent: u64,
|
||||
/// `resident_budget` was set exactly ([`Compositor::set_resident_budget`]): nothing is lent.
|
||||
exact_resident: bool,
|
||||
/// What the view shows: a full refresh draws these cells last, so their pages are the
|
||||
/// ones still resident for the edits that follow.
|
||||
focus: Option<Rect>,
|
||||
@@ -744,6 +746,7 @@ impl Compositor {
|
||||
fx_budget: (FX_BUDGET as u64).saturating_sub(prefix::MAX_BYTES),
|
||||
layer_need: 0,
|
||||
lent: 0,
|
||||
exact_resident: false,
|
||||
focus: None,
|
||||
frame: 0,
|
||||
stamp: 0,
|
||||
@@ -793,8 +796,11 @@ impl Compositor {
|
||||
/// Set the GPU memory resident layer pages may hold (default [`RESIDENT_BUDGET`]), exactly:
|
||||
/// nothing is lent to it ([`Self::fit_layers`]) until the next [`Self::set_memory_budget`].
|
||||
pub fn set_resident_budget(&mut self, bytes: u64) {
|
||||
self.resident_budget = bytes;
|
||||
// The loan goes back to the effect maps, so the total budget stays what it was.
|
||||
self.fx_budget = self.fx_budget.saturating_add(self.lent);
|
||||
self.lent = 0;
|
||||
self.resident_budget = bytes;
|
||||
self.exact_resident = true;
|
||||
}
|
||||
|
||||
/// Set the GPU memory the compositor may hold for layer pages and caches together
|
||||
@@ -806,6 +812,7 @@ impl Compositor {
|
||||
self.fx_budget = caches.saturating_sub(self.prefix.budget());
|
||||
self.resident_budget = bytes.saturating_sub(caches);
|
||||
self.lent = 0;
|
||||
self.exact_resident = false;
|
||||
self.lend();
|
||||
}
|
||||
|
||||
@@ -831,7 +838,7 @@ impl Compositor {
|
||||
self.fx_budget = self.fx_budget.saturating_add(self.lent);
|
||||
self.resident_budget = self.resident_budget.saturating_sub(self.lent);
|
||||
let short = self.layer_need.saturating_sub(self.resident_budget);
|
||||
self.lent = if short <= self.fx_budget { short } else { 0 };
|
||||
self.lent = if short <= self.fx_budget && !self.exact_resident { short } else { 0 };
|
||||
self.fx_budget = self.fx_budget.saturating_sub(self.lent);
|
||||
self.resident_budget = self.resident_budget.saturating_add(self.lent);
|
||||
}
|
||||
|
||||
@@ -2872,6 +2872,13 @@ fn layer_pages_that_just_miss_borrow_the_effect_map_share() {
|
||||
comp.fit_layers(need, true);
|
||||
assert_eq!(comp.fit_layers(own, true), own);
|
||||
assert_eq!(comp.memory_budget(), budget);
|
||||
// An exact resident budget returns the loan and lends nothing until the next memory budget.
|
||||
comp.fit_layers(need, true);
|
||||
comp.set_resident_budget(own);
|
||||
assert_eq!(comp.memory_budget(), budget, "the loan went back to the effect maps");
|
||||
assert_eq!(comp.fit_layers(need, true), own, "an exact budget stays exact");
|
||||
comp.set_memory_budget(budget);
|
||||
assert_eq!(comp.resident_budget(), need, "the next memory budget lends again");
|
||||
}
|
||||
|
||||
// A pass-through group holding an adjustment renders isolated when layers clip to it, on the GPU
|
||||
|
||||
Reference in new issue
Block a user