Trait GraphicsBackendSelector

Source
pub trait GraphicsBackendSelector<TAdapter> {
    type Error: Debug + Display + Send + Sync + 'static;

    // Required methods
    fn select_backend<'life0, 'life1, 'async_trait>(
        &'life0 self,
        config: &'life1 BackendSelectionConfig,
    ) -> Pin<Box<dyn Future<Output = Result<BackendSelectionResult<TAdapter>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_adapters<'life0, 'async_trait>(
        &'life0 self,
        backend_type: GraphicsBackendType,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<GraphicsAdapterInfo>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn is_backend_supported(&self, backend_type: GraphicsBackendType) -> bool;
}
Expand description

A trait for a system that discovers and selects a suitable graphics backend.

This trait abstracts the logic for initializing a graphics context, querying the available adapters (GPUs), and selecting the best one based on a given configuration. Since adapter enumeration can be a slow I/O operation, the primary methods are asynchronous.

A concrete implementation of this trait will live in khora-infra and will typically wrap a library like wgpu.

Required Associated Types§

Source

type Error: Debug + Display + Send + Sync + 'static

The error type returned if backend selection fails.

Required Methods§

Source

fn select_backend<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 BackendSelectionConfig, ) -> Pin<Box<dyn Future<Output = Result<BackendSelectionResult<TAdapter>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously selects the best available graphics adapter based on the provided configuration.

This method will attempt to honor the preferences in the config (e.g., prefer a discrete GPU, or a specific backend API like Vulkan), falling back to other options if the preferred ones are not available.

§Arguments
§Returns

A Result containing a BackendSelectionResult with the chosen adapter and instance, or an error if no suitable adapter could be found.

Source

fn list_adapters<'life0, 'async_trait>( &'life0 self, backend_type: GraphicsBackendType, ) -> Pin<Box<dyn Future<Output = Result<Vec<GraphicsAdapterInfo>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Asynchronously queries and lists all available adapters for a specific backend API.

§Arguments
  • backend_type: The specific backend API (e.g., Vulkan, Dx12) to query.
§Returns

A Result containing a Vec of GraphicsAdapterInfo for all compatible adapters, or an error if the backend API is not available.

Source

fn is_backend_supported(&self, backend_type: GraphicsBackendType) -> bool

Synchronously checks if a specific backend API is supported on the current platform.

§Arguments
  • backend_type: The backend API to check.
§Returns

true if the backend is likely to be supported, false otherwise.

Implementors§