Struct RenderBudget

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

Implementations§

Source§

impl RenderBudget

Source

pub fn new(target_fps: f32) -> Result<RenderBudget, PerformanceError>

Source

pub fn set_enabled(&mut self, enabled: bool)

Changing this setting restores full scale and starts a fresh warm-up. Repeating the current setting leaves history and the last reason intact.

Source

pub fn reset(&mut self)

Restore full presentation scale and begin a new measurement warm-up. Keeps the target FPS and enabled setting. Use after a scene/restart or timing-source change; it does not touch simulation or user preferences.

use ferravex_play::performance::{BudgetReason, BudgetSample, RenderBudget};

let mut budget = RenderBudget::new(60.)?;
budget.set_enabled(true);
let sample = BudgetSample {
    frame_ms: 35., cpu_ms: 2., gpu_ms: Some(30.), paused: false,
};
for _ in 0..38 { // Eight warm-up samples, then 30 overload observations.
    budget.observe(sample)?;
}
assert_eq!(budget.level(), 1);
assert_eq!(budget.state().reason, BudgetReason::LoweredQuality);
budget.reset();
assert_eq!(budget.scale(), 1.);
assert!(budget.state().enabled);
assert_eq!(budget.state().reason, BudgetReason::Reset);
assert_eq!(budget.state().warmup_remaining, 8);
Source

pub fn state(&self) -> BudgetState

Inspect warm-up, hysteresis and the last reason without consuming data. BudgetDecision and the existing observation API remain unchanged.

use ferravex_play::performance::{BudgetReason, BudgetSample, RenderBudget};

let mut budget = RenderBudget::default();
budget.set_enabled(true);
let decision = budget.observe(BudgetSample {
    frame_ms: 16., cpu_ms: 2., gpu_ms: Some(8.), paused: false,
})?;
assert!(!decision.changed);
let state = budget.state();
assert_eq!(state.reason, BudgetReason::WarmingUp);
assert_eq!(state.warmup_remaining, 7);
assert_eq!(state.smoothed_gpu_ms, Some(8.));
Source

pub fn level(&self) -> u8

Source

pub fn scale(&self) -> f32

Source

pub fn observe( &mut self, s: BudgetSample, ) -> Result<BudgetDecision, PerformanceError>

Only confirmed, valid GPU measurements can lower fidelity. High CPU load, unavailable timers and background gaps never masquerade as GPU pressure.

The first eight consecutive eligible samples seed the exponential filter (weight 0.12). Subsequent samples add one overload point only when both current and smoothed GPU times exceed 110% of the target frame budget; otherwise two points decay. Thirty points lower quality one level. Recovery needs 180 consecutive samples with both times below 65%. Each change starts a 120-eligible-sample cooldown; evidence may accumulate during it. Scales remain bounded to 1.0 through 0.5 in steps of 0.125.

Paused, CPU-bound, missing-GPU and over-250-ms frames discard filter and evidence history and require fresh warm-up, retaining scale and cooldown. They do not advance the cooldown. Invalid data returns an error without mutation. Self::state explains the decision; no clocks are consulted.

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<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for RenderBudget

Source§

fn default() -> RenderBudget

Returns the “default value” for a type. Read more
Source§

impl Copy for RenderBudget

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.