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: 4 additions & 2 deletions wgpu-hal/src/dynamic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod command;
mod device;
mod surface;

pub use self::command::DynCommandEncoder;
pub use self::device::DynDevice;
pub use command::DynCommandEncoder;
pub use device::DynDevice;
pub use surface::{DynAcquiredSurfaceTexture, DynSurface};

use std::any::Any;

Expand Down
71 changes: 71 additions & 0 deletions wgpu-hal/src/dynamic/surface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::{
DynDevice, DynFence, DynResource, DynSurfaceTexture, Surface, SurfaceConfiguration,
SurfaceError,
};

use super::DynResourceExt as _;

#[derive(Debug)]
pub struct DynAcquiredSurfaceTexture {
pub texture: Box<dyn DynSurfaceTexture>,
/// The presentation configuration no longer matches
/// the surface properties exactly, but can still be used to present
/// to the surface successfully.
pub suboptimal: bool,
}

pub trait DynSurface: 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 configure(
&self,
device: &dyn DynDevice,
config: &SurfaceConfiguration,
) -> Result<(), SurfaceError>;

unsafe fn unconfigure(&self, device: &dyn DynDevice);

unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
fence: &dyn DynFence,
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError>;

unsafe fn discard_texture(&self, texture: Box<dyn DynSurfaceTexture>);
}

impl<S: Surface + DynResource> DynSurface for S {
unsafe fn configure(
&self,
device: &dyn DynDevice,
config: &SurfaceConfiguration,
) -> Result<(), SurfaceError> {
let device = device.expect_downcast_ref();
unsafe { S::configure(self, device, config) }
}

unsafe fn unconfigure(&self, device: &dyn DynDevice) {
let device = device.expect_downcast_ref();
unsafe { S::unconfigure(self, device) }
}

unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
fence: &dyn DynFence,
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError> {
let fence = fence.expect_downcast_ref();
unsafe { S::acquire_texture(self, timeout, fence) }.map(|acquired| {
acquired.map(|ast| {
let texture = Box::new(ast.texture);
let suboptimal = ast.suboptimal;
DynAcquiredSurfaceTexture {
texture,
suboptimal,
}
})
})
}

unsafe fn discard_texture(&self, texture: Box<dyn DynSurfaceTexture>) {
unsafe { S::discard_texture(self, texture.unbox()) }
}
}
8 changes: 4 additions & 4 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ mod dynamic;

pub(crate) use dynamic::impl_dyn_resource;
pub use dynamic::{
DynAccelerationStructure, DynBindGroup, DynBindGroupLayout, DynBuffer, DynCommandBuffer,
DynCommandEncoder, DynComputePipeline, DynDevice, DynFence, DynPipelineCache,
DynPipelineLayout, DynQuerySet, DynRenderPipeline, DynResource, DynSampler, DynShaderModule,
DynSurfaceTexture, DynTexture, DynTextureView,
DynAccelerationStructure, DynAcquiredSurfaceTexture, DynBindGroup, DynBindGroupLayout,
DynBuffer, DynCommandBuffer, DynCommandEncoder, DynComputePipeline, DynDevice, DynFence,
DynPipelineCache, DynPipelineLayout, DynQuerySet, DynRenderPipeline, DynResource, DynSampler,
DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView,
};

use std::{
Expand Down