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§
Required Methods§
Sourcefn 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 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
config
: ABackendSelectionConfig
specifying backend preferences and constraints.
§Returns
A Result
containing a BackendSelectionResult
with the chosen adapter
and instance, or an error if no suitable adapter could be found.
Sourcefn 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 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.