diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index e5db9fc234..fc3f2fbd12 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -88,6 +88,7 @@ impl crate::Api for Api { } crate::impl_dyn_resource!( + Adapter, AccelerationStructure, BindGroup, BindGroupLayout, diff --git a/wgpu-hal/src/dynamic/adapter.rs b/wgpu-hal/src/dynamic/adapter.rs new file mode 100644 index 0000000000..7f9b63a838 --- /dev/null +++ b/wgpu-hal/src/dynamic/adapter.rs @@ -0,0 +1,56 @@ +use crate::{Adapter, DeviceError, SurfaceCapabilities, TextureFormatCapabilities}; + +use super::{DynDevice, DynQueue, DynResource, DynResourceExt, DynSurface}; + +pub struct DynOpenDevice { + pub device: Box, + pub queue: Box, +} + +pub trait DynAdapter: DynResource { + unsafe fn open( + &self, + features: wgt::Features, + limits: &wgt::Limits, + memory_hints: &wgt::MemoryHints, + ) -> Result; + + unsafe fn texture_format_capabilities( + &self, + format: wgt::TextureFormat, + ) -> TextureFormatCapabilities; + + unsafe fn surface_capabilities(&self, surface: &dyn DynSurface) -> Option; + + unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp; +} + +impl DynAdapter for A { + unsafe fn open( + &self, + features: wgt::Features, + limits: &wgt::Limits, + memory_hints: &wgt::MemoryHints, + ) -> Result { + unsafe { A::open(self, features, limits, memory_hints) }.map(|open_device| DynOpenDevice { + device: Box::new(open_device.device), + queue: Box::new(open_device.queue), + }) + } + + unsafe fn texture_format_capabilities( + &self, + format: wgt::TextureFormat, + ) -> TextureFormatCapabilities { + unsafe { A::texture_format_capabilities(self, format) } + } + + unsafe fn surface_capabilities(&self, surface: &dyn DynSurface) -> Option { + let surface = surface.expect_downcast_ref(); + unsafe { A::surface_capabilities(self, surface) } + } + + unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { + unsafe { A::get_presentation_timestamp(self) } + } +} diff --git a/wgpu-hal/src/dynamic/mod.rs b/wgpu-hal/src/dynamic/mod.rs index b8fc8a1f6c..490251a511 100644 --- a/wgpu-hal/src/dynamic/mod.rs +++ b/wgpu-hal/src/dynamic/mod.rs @@ -1,8 +1,10 @@ +mod adapter; mod command; mod device; mod queue; mod surface; +pub use adapter::{DynAdapter, DynOpenDevice}; pub use command::DynCommandEncoder; pub use device::DynDevice; pub use queue::DynQueue; diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 617d3f0729..86ee6df29d 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -165,6 +165,7 @@ impl crate::Api for Api { } crate::impl_dyn_resource!( + Adapter, AccelerationStructure, BindGroup, BindGroupLayout, diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 1f4ee79b47..0ba8bef8d0 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -266,10 +266,11 @@ mod dynamic; pub(crate) use dynamic::impl_dyn_resource; pub use dynamic::{ - DynAccelerationStructure, DynAcquiredSurfaceTexture, DynBindGroup, DynBindGroupLayout, - DynBuffer, DynCommandBuffer, DynCommandEncoder, DynComputePipeline, DynDevice, DynFence, - DynPipelineCache, DynPipelineLayout, DynQuerySet, DynQueue, DynRenderPipeline, DynResource, - DynSampler, DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView, + DynAccelerationStructure, DynAcquiredSurfaceTexture, DynAdapter, DynBindGroup, + DynBindGroupLayout, DynBuffer, DynCommandBuffer, DynCommandEncoder, DynComputePipeline, + DynDevice, DynFence, DynOpenDevice, DynPipelineCache, DynPipelineLayout, DynQuerySet, DynQueue, + DynRenderPipeline, DynResource, DynSampler, DynShaderModule, DynSurface, DynSurfaceTexture, + DynTexture, DynTextureView, }; use std::{ @@ -393,7 +394,7 @@ impl InstanceError { pub trait Api: Clone + fmt::Debug + Sized { type Instance: Instance; type Surface: DynSurface + Surface; - type Adapter: Adapter; + type Adapter: DynAdapter + Adapter; type Device: DynDevice + Device; type Queue: DynQueue + Queue; diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index f861474f8a..728ee8f496 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -72,6 +72,7 @@ impl crate::Api for Api { } crate::impl_dyn_resource!( + Adapter, AccelerationStructure, BindGroup, BindGroupLayout, diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index a77ff444b6..90c2cf2a0c 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -79,6 +79,7 @@ impl crate::Api for Api { } crate::impl_dyn_resource!( + Adapter, AccelerationStructure, BindGroup, BindGroupLayout,