use crate::{Device, GpuError, Opened, TextureFormat};
#[derive(Clone, Copy, Debug, Default)]
pub struct HostDeviceDesc {
pub resource_memory_limit_bytes: Option<u64>,
pub observe_device_errors: bool,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct ImportedTarget {
pub width: u32,
pub height: u32,
pub texture_format: TextureFormat,
pub render_format: TextureFormat,
}
impl TextureFormat {
#[must_use]
pub const fn without_srgb(self) -> Self {
match self {
Self::Rgba8UnormSrgb => Self::Rgba8Unorm,
Self::Bgra8UnormSrgb => Self::Bgra8Unorm,
other => other,
}
}
#[must_use]
pub const fn is_host_output(self) -> bool {
matches!(self, Self::Rgba8Unorm | Self::Bgra8Unorm)
}
}
pub trait HostDevice: Device {
type Context;
type ExternalTexture: Clone + std::fmt::Debug;
fn adopt(context: Self::Context, desc: &HostDeviceDesc) -> Result<Opened<Self>, GpuError>;
fn import_target(
&self,
texture: &Self::ExternalTexture,
render_format: TextureFormat,
) -> Result<(Self::TextureView, ImportedTarget), GpuError>;
fn export_texture(&self, texture: &Self::Texture) -> Self::ExternalTexture;
}