Struct IsolatedBudgetPolicy

Source
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: IsolatedBudgetConfig

Immutable limits used by subsequent decisions; callers may replace them between frames.

§frame_bytes_acc: u64

Estimated offscreen bytes scheduled in the current frame.

§isolated_pass_count: u32

Isolated passes scheduled in the current frame.

§downgrades: IsolatedDowngradeCounts

Clamp and skip counters for the current frame.

§backdrop_capture_count: u32

Backdrop snapshots scheduled in the current frame.

§blend_capture_count: u32

Blend destination snapshots scheduled in the current frame.

Implementations§

Source§

impl IsolatedBudgetPolicy

Source

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);
Source

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());
Source

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));
Source

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());
Source

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);
Source

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));
Source

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));
Source

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 });
Source

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);
Source

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);
Source

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));
Source

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());
Source

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);
Source

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));
Source

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);
Source

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());
Source

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));
Source

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

Source§

fn clone(&self) -> IsolatedBudgetPolicy

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IsolatedBudgetPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<A> IntoClickAction<A> for A
where A: Clone + 'static,

§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Props for T
where T: Clone + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,