Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degenerification part 1/3: wgpu-hal DynDevice & friends #6098

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7f4cf4f
introduce DynResource & DynBuffer as first user
Wumpf Jul 10, 2024
eddab98
Buffer bindings no longer depend on hal api struct, but directly on b…
Wumpf Jul 14, 2024
f9d47ec
BufferBarrier no longer depend on hal api struct, but directly on buf…
Wumpf Jul 14, 2024
880e5a9
Introduce DynCommandEncoder, implement index & vertex buffer ops on it
Wumpf Jul 14, 2024
6f8ef5c
DynCommandEncoder implement begin/end encoding, debug markers, variou…
Wumpf Jul 15, 2024
debe041
introduce DynQuerySet, associated DynCommandEncoder methods
Wumpf Jul 15, 2024
233d2ba
Introduce DynPipelineLayout & DynBindGroup
Wumpf Jul 15, 2024
6576838
Introduce DynComputePipeline & DynRenderPipeline
Wumpf Jul 15, 2024
7548973
fold ComputePassTimestampWrites & RenderPassTimestampWrites and make …
Wumpf Jul 15, 2024
ff49edc
introduce DynTexture & DynTextureView
Wumpf Jul 17, 2024
15748cb
render/compute pass descriptors work now with dyn types
Wumpf Jul 17, 2024
c19659b
implement begin/end render/computepass for dyncommandencoder
Wumpf Jul 20, 2024
1ee9d4b
implement transition_textures for DynCommandEncoder
Wumpf Jul 20, 2024
8bb009e
buffer / texture copy operations for DynCommandEncoder
Wumpf Jul 20, 2024
5719e38
texture & buffer transitioning always uses DynCommandEncoder now
Wumpf Jul 20, 2024
2502283
Introduce DynDevice
Wumpf Jul 20, 2024
7b25389
add most remaining dyn type traits
Wumpf Jul 20, 2024
b662e71
impl DynShaderModule for all backends
Wumpf Jul 20, 2024
e9860f7
impl DynCommandBuffer
Wumpf Jul 21, 2024
8595a1c
Device now has to implement DynResource
Wumpf Jul 21, 2024
e4744df
impl DynFence for all fences
Wumpf Jul 21, 2024
d94e465
impl DynSurfaceTexture for all surface textures
Wumpf Jul 21, 2024
39b214a
introduce DynSurface
Wumpf Jul 21, 2024
24bd6e0
introduce DynQueue
Wumpf Jul 21, 2024
d685660
DynDevice buffer operations
Wumpf Jul 21, 2024
9dd24e0
DynDevice create/destroy for texture/textureview/sampler
Wumpf Jul 24, 2024
3217d43
DynDevice create/destroy command encoder
Wumpf Jul 27, 2024
38c9031
DynDevice create/destroy bind group layout
Wumpf Jul 27, 2024
ba06be2
DynDevice create/destroy pipeline layout
Wumpf Jul 27, 2024
f37a871
DynDevice create/destroy bind group
Wumpf Jul 27, 2024
533def2
DynDevice create/destroy ShaderModule
Wumpf Jul 27, 2024
bf1bf41
DynDevice create/destroy compute/render pipeline
Wumpf Jul 28, 2024
7d8f753
DynDevice pipeline cache
Wumpf Jul 28, 2024
af35846
DynDevice create/destroy query set
Wumpf Jul 28, 2024
96914ea
DynDevice fence
Wumpf Jul 28, 2024
3bf21ab
DynDevice wait/capture/pipeline_cache_get_data
Wumpf Jul 28, 2024
afd32e0
DynDevice acceleration structure handling
Wumpf Jul 28, 2024
666d2fa
DynDevice exit, counters, report
Wumpf Jul 28, 2024
4c30ef5
DynCommandencoder end_encoding, reset_all
Wumpf Jul 28, 2024
7981855
DynCommandEncoder acceleration structure building
Wumpf Jul 28, 2024
34fe670
remove unnecessary debug constraints from Api (handled by Dyn traits)
Wumpf Jul 28, 2024
2eb9c73
introduce DynAdapter
Wumpf Aug 4, 2024
75aaa13
introduce DynInstance
Wumpf Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
7 changes: 6 additions & 1 deletion wgpu-hal/src/dynamic/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {}

Expand Down
54 changes: 54 additions & 0 deletions wgpu-hal/src/dynamic/queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::{
DeviceError, DynCommandBuffer, DynFence, DynResource, DynSurface, DynSurfaceTexture,
FenceValue, Queue, SurfaceError,
};

use super::DynResourceExt as _;

pub trait DynQueue: DynResource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: We don't document a safety contract or adherence thereto for these methods. We should do this.

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) }
}
}
6 changes: 6 additions & 0 deletions wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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>;

Expand Down
6 changes: 6 additions & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
6 changes: 6 additions & 0 deletions wgpu-hal/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down