introduce DynQueue

This commit is contained in:
Andreas Reich 2024-07-21 12:19:47 +02:00
parent 4e5721350f
commit 72f30a34f5
8 changed files with 93 additions and 4 deletions

View File

@ -458,6 +458,12 @@ pub struct Texture {
impl crate::DynTexture for Texture {}
impl crate::DynSurfaceTexture for Texture {}
impl std::borrow::Borrow<dyn crate::DynTexture> for Texture {
fn borrow(&self) -> &dyn crate::DynTexture {
self
}
}
unsafe impl Send for Texture {}
unsafe impl Sync for Texture {}

View File

@ -1,9 +1,11 @@
mod command;
mod device;
mod queue;
mod surface;
pub use command::DynCommandEncoder;
pub use device::DynDevice;
pub use queue::DynQueue;
pub use surface::{DynAcquiredSurfaceTexture, DynSurface};
use std::any::Any;
@ -103,7 +105,10 @@ pub trait DynQuerySet: DynResource + std::fmt::Debug {}
pub trait DynRenderPipeline: DynResource + std::fmt::Debug {}
pub trait DynSampler: DynResource + std::fmt::Debug {}
pub trait DynShaderModule: DynResource + std::fmt::Debug {}
pub trait DynSurfaceTexture: DynResource + std::fmt::Debug {}
pub trait DynSurfaceTexture:
DynResource + std::borrow::Borrow<dyn DynTexture> + std::fmt::Debug
{
}
pub trait DynTexture: DynResource + std::fmt::Debug {}
pub trait DynTextureView: DynResource + std::fmt::Debug {}

View File

@ -0,0 +1,54 @@
use crate::{
DeviceError, DynCommandBuffer, DynFence, DynResource, DynSurface, DynSurfaceTexture,
FenceValue, Queue, SurfaceError,
};
use super::DynResourceExt as _;
pub trait DynQueue: DynResource {
unsafe fn submit(
&self,
command_buffers: &[&dyn DynCommandBuffer],
surface_textures: &[&dyn DynSurfaceTexture],
signal_fence: (&mut dyn DynFence, FenceValue),
) -> Result<(), DeviceError>;
unsafe fn present(
&self,
surface: &dyn DynSurface,
texture: Box<dyn DynSurfaceTexture>,
) -> Result<(), SurfaceError>;
unsafe fn get_timestamp_period(&self) -> f32;
}
impl<Q: Queue + DynResource> DynQueue for Q {
unsafe fn submit(
&self,
command_buffers: &[&dyn DynCommandBuffer],
surface_textures: &[&dyn DynSurfaceTexture],
signal_fence: (&mut dyn DynFence, FenceValue),
) -> Result<(), DeviceError> {
let command_buffers = command_buffers
.iter()
.map(|cb| (*cb).expect_downcast_ref())
.collect::<Vec<_>>();
let surface_textures = surface_textures
.iter()
.map(|surface| (*surface).expect_downcast_ref())
.collect::<Vec<_>>();
let signal_fence = (signal_fence.0.expect_downcast_mut(), signal_fence.1);
unsafe { Q::submit(self, &command_buffers, &surface_textures, signal_fence) }
}
unsafe fn present(
&self,
surface: &dyn DynSurface,
texture: Box<dyn DynSurfaceTexture>,
) -> Result<(), SurfaceError> {
let surface = surface.expect_downcast_ref();
unsafe { Q::present(self, surface, texture.unbox()) }
}
unsafe fn get_timestamp_period(&self) -> f32 {
unsafe { Q::get_timestamp_period(self) }
}
}

View File

@ -55,6 +55,12 @@ impl crate::DynSurfaceTexture for Resource {}
impl crate::DynTexture for Resource {}
impl crate::DynTextureView for Resource {}
impl std::borrow::Borrow<dyn crate::DynTexture> for Resource {
fn borrow(&self) -> &dyn crate::DynTexture {
self
}
}
impl crate::Instance for Context {
type A = Api;

View File

@ -377,6 +377,12 @@ pub struct Texture {
impl crate::DynTexture for Texture {}
impl crate::DynSurfaceTexture for Texture {}
impl std::borrow::Borrow<dyn crate::DynTexture> for Texture {
fn borrow(&self) -> &dyn crate::DynTexture {
self
}
}
impl Texture {
pub fn default_framebuffer(format: wgt::TextureFormat) -> Self {
Self {

View File

@ -268,8 +268,8 @@ pub(crate) use dynamic::impl_dyn_resource;
pub use dynamic::{
DynAccelerationStructure, DynAcquiredSurfaceTexture, DynBindGroup, DynBindGroupLayout,
DynBuffer, DynCommandBuffer, DynCommandEncoder, DynComputePipeline, DynDevice, DynFence,
DynPipelineCache, DynPipelineLayout, DynQuerySet, DynRenderPipeline, DynResource, DynSampler,
DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView,
DynPipelineCache, DynPipelineLayout, DynQuerySet, DynQueue, DynRenderPipeline, DynResource,
DynSampler, DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView,
};
use std::{
@ -392,7 +392,7 @@ impl InstanceError {
pub trait Api: Clone + fmt::Debug + Sized {
type Instance: Instance<A = Self>;
type Surface: Surface<A = Self>;
type Surface: DynSurface + Surface<A = Self>;
type Adapter: Adapter<A = Self>;
type Device: DynDevice + Device<A = Self>;

View File

@ -390,6 +390,12 @@ impl std::borrow::Borrow<Texture> for SurfaceTexture {
}
}
impl std::borrow::Borrow<dyn crate::DynTexture> for SurfaceTexture {
fn borrow(&self) -> &dyn crate::DynTexture {
&self.texture
}
}
unsafe impl Send for SurfaceTexture {}
unsafe impl Sync for SurfaceTexture {}

View File

@ -386,6 +386,12 @@ impl Borrow<Texture> for SurfaceTexture {
}
}
impl Borrow<dyn crate::DynTexture> for SurfaceTexture {
fn borrow(&self) -> &dyn crate::DynTexture {
&self.texture
}
}
pub struct Adapter {
raw: vk::PhysicalDevice,
instance: Arc<InstanceShared>,