mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 01:11:22 +01:00
introduce DynAdapter
This commit is contained in:
1 parent
99ffc129eb
commit
6f01cbff06
7 files changed
+68
-5
No files matched your search
@@ -88,6 +88,7 @@ impl crate::Api for Api {
|
||||
}
|
||||
|
||||
crate::impl_dyn_resource!(
|
||||
Adapter,
|
||||
AccelerationStructure,
|
||||
BindGroup,
|
||||
BindGroupLayout,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
use crate::{Adapter, DeviceError, SurfaceCapabilities, TextureFormatCapabilities};
|
||||
|
||||
use super::{DynDevice, DynQueue, DynResource, DynResourceExt, DynSurface};
|
||||
|
||||
pub struct DynOpenDevice {
|
||||
pub device: Box<dyn DynDevice>,
|
||||
pub queue: Box<dyn DynQueue>,
|
||||
}
|
||||
|
||||
pub trait DynAdapter: DynResource {
|
||||
unsafe fn open(
|
||||
&self,
|
||||
features: wgt::Features,
|
||||
limits: &wgt::Limits,
|
||||
memory_hints: &wgt::MemoryHints,
|
||||
) -> Result<DynOpenDevice, DeviceError>;
|
||||
|
||||
unsafe fn texture_format_capabilities(
|
||||
&self,
|
||||
format: wgt::TextureFormat,
|
||||
) -> TextureFormatCapabilities;
|
||||
|
||||
unsafe fn surface_capabilities(&self, surface: &dyn DynSurface) -> Option<SurfaceCapabilities>;
|
||||
|
||||
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp;
|
||||
}
|
||||
|
||||
impl<A: Adapter + DynResource> DynAdapter for A {
|
||||
unsafe fn open(
|
||||
&self,
|
||||
features: wgt::Features,
|
||||
limits: &wgt::Limits,
|
||||
memory_hints: &wgt::MemoryHints,
|
||||
) -> Result<DynOpenDevice, DeviceError> {
|
||||
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<SurfaceCapabilities> {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -165,6 +165,7 @@ impl crate::Api for Api {
|
||||
}
|
||||
|
||||
crate::impl_dyn_resource!(
|
||||
Adapter,
|
||||
AccelerationStructure,
|
||||
BindGroup,
|
||||
BindGroupLayout,
|
||||
|
||||
+6
-5
@@ -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<A = Self>;
|
||||
type Surface: DynSurface + Surface<A = Self>;
|
||||
type Adapter: Adapter<A = Self>;
|
||||
type Adapter: DynAdapter + Adapter<A = Self>;
|
||||
type Device: DynDevice + Device<A = Self>;
|
||||
|
||||
type Queue: DynQueue + Queue<A = Self>;
|
||||
|
||||
@@ -72,6 +72,7 @@ impl crate::Api for Api {
|
||||
}
|
||||
|
||||
crate::impl_dyn_resource!(
|
||||
Adapter,
|
||||
AccelerationStructure,
|
||||
BindGroup,
|
||||
BindGroupLayout,
|
||||
|
||||
@@ -79,6 +79,7 @@ impl crate::Api for Api {
|
||||
}
|
||||
|
||||
crate::impl_dyn_resource!(
|
||||
Adapter,
|
||||
AccelerationStructure,
|
||||
BindGroup,
|
||||
BindGroupLayout,
|
||||
|
||||
Reference in new issue
Block a user