pub struct IsolatedBudgetPolicy {
pub config: IsolatedBudgetConfig,
pub frame_bytes_acc: u64,
pub isolated_pass_count: u32,
pub downgrades: IsolatedDowngradeCounts,
pub backdrop_capture_count: u32,
pub blend_capture_count: u32,
}Expand description
Mutable per-frame budget state during CPU planning.
Construct one policy, call Self::reset_frame before each frame, and
record every scheduled allocation so later decisions see accumulated usage.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let policy = IsolatedBudgetPolicy::with_defaults();
assert_eq!(policy.frame_bytes_acc, 0);Fields§
§config: IsolatedBudgetConfigImmutable limits used by subsequent decisions; callers may replace them between frames.
frame_bytes_acc: u64Estimated offscreen bytes scheduled in the current frame.
isolated_pass_count: u32Isolated passes scheduled in the current frame.
downgrades: IsolatedDowngradeCountsClamp and skip counters for the current frame.
backdrop_capture_count: u32Backdrop snapshots scheduled in the current frame.
blend_capture_count: u32Blend destination snapshots scheduled in the current frame.
Implementations§
Source§impl IsolatedBudgetPolicy
impl IsolatedBudgetPolicy
Sourcepub fn new(config: IsolatedBudgetConfig) -> Self
pub fn new(config: IsolatedBudgetConfig) -> Self
Creates zeroed per-frame state with the supplied limits.
§Examples
use ailloli_ui_render_wgpu::{IsolatedBudgetConfig, IsolatedBudgetPolicy};
let policy = IsolatedBudgetPolicy::new(IsolatedBudgetConfig::default());
assert_eq!(policy.isolated_pass_count, 0);Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Creates zeroed per-frame state with IsolatedBudgetConfig::default.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
assert!(IsolatedBudgetPolicy::with_defaults().can_schedule_pass());Sourcepub fn reset_frame(&mut self)
pub fn reset_frame(&mut self)
Clears accumulated bytes, counts, and downgrades without changing limits.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_pass_scheduled(10, 10, false);
policy.reset_frame();
assert_eq!((policy.frame_bytes_acc, policy.isolated_pass_count), (0, 0));Sourcepub fn can_schedule_pass(&self) -> bool
pub fn can_schedule_pass(&self) -> bool
Returns true if another isolated pass may be scheduled.
This checks only the pass-count limit; callers must check area, byte, and nesting limits separately.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_isolated_passes_per_frame = 0;
assert!(!policy.can_schedule_pass());Sourcepub fn estimate_pass_bytes(
&self,
width: u32,
height: u32,
needs_stencil: bool,
) -> u64
pub fn estimate_pass_bytes( &self, width: u32, height: u32, needs_stencil: bool, ) -> u64
Estimated bytes for one pass (RGBA color + optional stencil copy).
§Panics
Debug builds panic if width * height * 4 exceeds u64.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let policy = IsolatedBudgetPolicy::with_defaults();
assert_eq!(policy.estimate_pass_bytes(10, 5, false), 200);
assert_eq!(policy.estimate_pass_bytes(10, 5, true), 400);Sourcepub fn would_exceed_bytes(
&self,
width: u32,
height: u32,
needs_stencil: bool,
) -> bool
pub fn would_exceed_bytes( &self, width: u32, height: u32, needs_stencil: bool, ) -> bool
Whether scheduling this pass would exceed the frame byte budget.
Equality with the limit is allowed; only a strictly larger total is rejected.
§Panics
Debug builds panic if the accumulated and estimated byte counts overflow.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_offscreen_bytes_per_frame = 399;
assert!(policy.would_exceed_bytes(10, 10, false));Sourcepub fn record_pass_scheduled(
&mut self,
width: u32,
height: u32,
needs_stencil: bool,
)
pub fn record_pass_scheduled( &mut self, width: u32, height: u32, needs_stencil: bool, )
Records one scheduled pass and its estimated allocation.
This method does not enforce limits; call it only after all checks pass.
§Panics
Debug builds panic on byte or pass-count overflow.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_pass_scheduled(10, 10, false);
assert_eq!((policy.frame_bytes_acc, policy.isolated_pass_count), (400, 1));Sourcepub fn clamp_blur_chain(&mut self, chain: &mut IsolatedEffectChain) -> bool
pub fn clamp_blur_chain(&mut self, chain: &mut IsolatedEffectChain) -> bool
Clamp blur radii in the effect chain; returns whether any radius was reduced.
Negative radii and NaN are not greater than the limit and remain unchanged. At most one downgrade is recorded per chain.
§Examples
use ailloli_ui_render_wgpu::{IsolatedBudgetPolicy, IsolatedEffect, IsolatedEffectChain};
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_blur_radius_px = 4.0;
let mut chain = IsolatedEffectChain { effects: vec![IsolatedEffect::Blur { radius_px: 8.0 }] };
assert!(policy.clamp_blur_chain(&mut chain));
assert_eq!(chain.effects[0], IsolatedEffect::Blur { radius_px: 4.0 });Sourcepub fn clamp_surface_bounds(&mut self, bounds: Rect) -> Rect
pub fn clamp_surface_bounds(&mut self, bounds: Rect) -> Rect
Scale bounds down (centered) so w*h <= max_offscreen_surface_px.
Zero, negative, and NaN areas are returned unchanged. A clamped rectangle preserves the original center and keeps both dimensions at least one.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_offscreen_surface_px = 100;
let bounds = policy.clamp_surface_bounds(Rect::new(0.0, 0.0, 20.0, 20.0));
assert!(bounds.w * bounds.h <= 100.01);Sourcepub fn record_bytes_skip(&mut self)
pub fn record_bytes_skip(&mut self)
Records that a pass was skipped by the aggregate byte budget.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_bytes_skip();
assert_eq!(policy.downgrades.bytes_budget_skipped, 1);Sourcepub fn nesting_depth_ok(&self, depth: u8) -> bool
pub fn nesting_depth_ok(&self, depth: u8) -> bool
Returns true when depth is within the configured nesting limit.
The comparison is exclusive: a limit of 3 admits depths 0, 1, and
2; a limit of zero admits none.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let policy = IsolatedBudgetPolicy::with_defaults();
assert!(policy.nesting_depth_ok(2));
assert!(!policy.nesting_depth_ok(3));Sourcepub fn can_schedule_backdrop(&self) -> bool
pub fn can_schedule_backdrop(&self) -> bool
Returns whether another backdrop snapshot fits the count limit.
Byte limits must be checked separately.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_backdrop_captures_per_frame = 0;
assert!(!policy.can_schedule_backdrop());Sourcepub fn clamp_backdrop_radius(&mut self, radius: f32) -> f32
pub fn clamp_backdrop_radius(&mut self, radius: f32) -> f32
Clamps a backdrop blur radius to the physical-pixel limit.
Negative values and NaN remain unchanged. A strict clamp records one downgrade.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.config.max_backdrop_blur_radius_px = 6.0;
assert_eq!(policy.clamp_backdrop_radius(9.0), 6.0);Sourcepub fn record_backdrop_scheduled(&mut self, width: u32, height: u32)
pub fn record_backdrop_scheduled(&mut self, width: u32, height: u32)
Records one backdrop snapshot as a four-byte-per-pixel allocation.
This method does not enforce limits.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_backdrop_scheduled(2, 3);
assert_eq!((policy.frame_bytes_acc, policy.backdrop_capture_count), (24, 1));Sourcepub fn record_backdrop_skip(&mut self)
pub fn record_backdrop_skip(&mut self)
Records a backdrop-capture budget skip.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_backdrop_skip();
assert_eq!(policy.downgrades.backdrop_budget_skipped, 1);Sourcepub fn can_schedule_blend(&self) -> bool
pub fn can_schedule_blend(&self) -> bool
Returns whether another blend destination snapshot fits the count limit.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let policy = IsolatedBudgetPolicy::with_defaults();
assert!(policy.can_schedule_blend());Sourcepub fn record_blend_scheduled(&mut self, width: u32, height: u32)
pub fn record_blend_scheduled(&mut self, width: u32, height: u32)
Records one blend destination snapshot as four bytes per pixel.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_blend_scheduled(4, 4);
assert_eq!((policy.frame_bytes_acc, policy.blend_capture_count), (64, 1));Sourcepub fn record_blend_skip(&mut self)
pub fn record_blend_skip(&mut self)
Records a blend destination-capture budget skip.
§Examples
use ailloli_ui_render_wgpu::IsolatedBudgetPolicy;
let mut policy = IsolatedBudgetPolicy::with_defaults();
policy.record_blend_skip();
assert_eq!(policy.downgrades.blend_capture_budget_skipped, 1);Trait Implementations§
Source§impl Clone for IsolatedBudgetPolicy
impl Clone for IsolatedBudgetPolicy
Source§fn clone(&self) -> IsolatedBudgetPolicy
fn clone(&self) -> IsolatedBudgetPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for IsolatedBudgetPolicy
impl RefUnwindSafe for IsolatedBudgetPolicy
impl Send for IsolatedBudgetPolicy
impl Sync for IsolatedBudgetPolicy
impl Unpin for IsolatedBudgetPolicy
impl UnwindSafe for IsolatedBudgetPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more