Skip to main content

HostConfig

Struct HostConfig 

Source
#[non_exhaustive]
pub struct HostConfig { pub sample_count: u32, pub redraw_interval: Option<Duration>, pub low_latency_present: bool, pub app_id: Option<String>, pub color_preferences: ColorPreferences, pub external_wakeup: Option<WakeupHook>, }
Expand description

Configuration for the optional native winit + wgpu host.

#[non_exhaustive]: build it from HostConfig::default() and the with_* methods, not as a struct literal, so an option added in a later release is not a breaking change.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§sample_count: u32

MSAA sample count used for Damascene’s SDF surfaces. The default is 4, matching the demo and validation app paths.

§redraw_interval: Option<Duration>

Optional fixed redraw cadence for apps with external live data sources such as audio meters. Animation-driven redraws still come from Runner::prepare().needs_redraw; this is only for host-owned clocks.

§low_latency_present: bool

Prefer the lowest-latency wgpu present mode the surface advertises (Mailbox, falling back to Fifo). Default is Fifo, which is vsync-locked and conservative on power.

Why this exists: with Fifo, every submit queues a frame for the next vsync; if the app submits faster than the display refresh, the compositor pulls the oldest queued frame at each vsync. On Wayland/Mesa during an interactive resize this shows up as the window content trailing the cursor in slow motion — by the time the latest size we rendered reaches the screen, several more compositor configure events have arrived. Mailbox replaces the pending frame on each submit, so the next vsync always shows the most recent render.

Cost: with Mailbox, render cadence is no longer naturally vsync-bounded — an animation that calls request_redraw from prepare.needs_redraw will render at GPU speed. Pair this with redraw_interval (or accept the cycles) if that’s not what you want.

§app_id: Option<String>

Stable identifier used by the windowing system / compositor / desktop services to group windows under this application.

  • Wayland: sets xdg_toplevel.app_id. Should match the basename of the .desktop file the app ships (reverse-DNS by convention, e.g. com.example.MyApp).
  • X11: sets both fields of WM_CLASS to the same value.
  • Windows / macOS / mobile: ignored.

When None, windowing-system defaults apply — typically the process name on Wayland, which several compositors render as a generic placeholder (e.g. surface-transient) in their config UIs and XDG-portal-backed system dialogs.

§color_preferences: ColorPreferences

App’s color-space preferences.

Mostly advisory. We never attach an image description to the surface — per wp_color_management_v1 a surface has a single color-management owner, and for an accelerated client that is the wgpu/Vulkan WSI, not us. We do read the compositor’s color-management state (for the Color Management showcase page) and, on a genuinely HDR output, select an extended-range float swapchain (Rgba16Float → scRGB via the WSI) so >1.0 values reach the display; SDR outputs stay on the 8-bit sRGB baseline. The default is ColorPreferences::sdr_only().

§external_wakeup: Option<WakeupHook>

Hook invoked once with a Wakeup handle for the host loop, just before the loop starts. See HostConfig::with_external_wakeup.

Implementations§

Source§

impl HostConfig

Source

pub fn with_redraw_interval(self, interval: Duration) -> HostConfig

Source

pub fn with_sample_count(self, sample_count: u32) -> HostConfig

Source

pub fn with_low_latency_present(self, low_latency_present: bool) -> HostConfig

Source

pub fn with_app_id(self, app_id: impl Into<String>) -> HostConfig

Source

pub fn with_color_preferences( self, color_preferences: ColorPreferences, ) -> HostConfig

Source

pub fn with_external_wakeup( self, hook: impl Fn(Wakeup) + Send + Sync + 'static, ) -> HostConfig

Register a hook that receives a Wakeup handle for the host loop. The hook runs once on the UI thread, just before the event loop starts; hand the handle to whatever owns your event-class data source.

This is the push-driven complement to with_redraw_interval: instead of the host polling on a fixed clock, app code schedules a frame exactly when something changed, and the idle app renders at 0 fps. The two compose — a fixed cadence for meter-class data and pushed wakes for event-class data don’t conflict — but most apps with conditional meters are better served by redraw_within on the meter widget plus this hook for events.

use damascene_winit_wgpu::HostConfig;

let (tx, rx) = std::sync::mpsc::channel();
let config = HostConfig::default().with_external_wakeup(move |wakeup| {
    let _ = tx.send(wakeup);
});
// A backend thread receives the handle and pokes the UI per event:
std::thread::spawn(move || {
    let wakeup = rx.recv().unwrap();
    // for each interesting backend event:
    wakeup.wake();
});

Trait Implementations§

Source§

impl Clone for HostConfig

Source§

fn clone(&self) -> HostConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HostConfig

Source§

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

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

impl Default for HostConfig

Source§

fn default() -> HostConfig

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more