Skip to main content

RenderBudget

Struct RenderBudget 

Source
pub struct RenderBudget { /* private fields */ }
Expand description

Render time budget with graceful degradation.

Tracks elapsed time within a frame and manages degradation level to maintain responsive rendering under load.

Implementations§

Source§

impl RenderBudget

Source

pub fn new(total: Duration) -> Self

Create a new budget with the specified total time.

Source

pub fn from_config(config: &FrameBudgetConfig) -> Self

Create a budget from configuration.

Source

pub fn with_controller(self, config: BudgetControllerConfig) -> Self

Attach an adaptive budget controller to this render budget.

When a controller is attached, next_frame() feeds the measured frame duration to the controller and applies its degradation decisions instead of the simple threshold-based upgrade logic.

§Example
use ftui_render::budget::{RenderBudget, BudgetControllerConfig};
use std::time::Duration;

let budget = RenderBudget::new(Duration::from_millis(16))
    .with_controller(BudgetControllerConfig::default());
Source

pub fn total(&self) -> Duration

Get the total budget duration.

Source

pub fn elapsed(&self) -> Duration

Get the elapsed time since budget started.

Source

pub fn remaining(&self) -> Duration

Get the remaining time in the budget.

Source

pub fn remaining_fraction(&self) -> f32

Get the remaining time as a fraction of total (0.0 to 1.0).

Source

pub fn should_degrade(&self, estimated_cost: Duration) -> bool

Check if we should degrade given an estimated operation cost.

Returns true if the estimated cost exceeds remaining budget.

Source

pub fn degrade(&mut self)

Degrade to the next level.

Logs a warning when degradation occurs.

Source

pub fn degradation(&self) -> DegradationLevel

Get the current degradation level.

Source

pub fn set_degradation(&mut self, level: DegradationLevel)

Set the degradation level directly.

Use with caution - prefer degrade() and upgrade() for gradual changes.

Source

pub fn exhausted(&self) -> bool

Check if the budget is exhausted.

Returns true if no time remains OR if at SkipFrame level.

Source

pub fn should_upgrade(&self) -> bool

Check if we should attempt to upgrade quality.

Returns true if more than upgrade_threshold of budget remains and we’re not already at full quality, and cooldown has passed.

Source

pub fn upgrade(&mut self)

Upgrade to the previous (better quality) level.

Logs when upgrade occurs.

Source

pub fn reset(&mut self)

Reset the budget for a new frame.

Keeps the current degradation level but resets timing.

Source

pub fn next_frame(&mut self)

Reset the budget and attempt upgrade if conditions are met.

Call this at the start of each frame to enable recovery.

When an adaptive controller is attached (via with_controller), the measured frame duration is fed to the controller and its decision (degrade / upgrade / hold) is applied automatically. The simple threshold-based upgrade path is skipped in that case.

Source

pub fn record_frame_time(&mut self, elapsed: Duration)

Record the measured render+present time for the last frame.

Source

pub fn telemetry(&self) -> Option<BudgetTelemetry>

Get a telemetry snapshot from the adaptive controller, if attached.

Returns None if no controller is attached. This is allocation-free and safe to call every frame.

Source

pub fn controller(&self) -> Option<&BudgetController>

Get a reference to the adaptive controller, if attached.

Source

pub fn phase_budgets(&self) -> &PhaseBudgets

Get the phase budgets.

Source

pub fn phase_has_budget(&self, phase: Phase) -> bool

Check if a specific phase has budget remaining.

Source

pub fn phase_budget(&self, phase: Phase) -> Self

Create a sub-budget for a specific phase.

The sub-budget shares the same start time but has a phase-specific total.

Trait Implementations§

Source§

impl Clone for RenderBudget

Source§

fn clone(&self) -> RenderBudget

Returns a duplicate 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 RenderBudget

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
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.

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.