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
37 changes: 37 additions & 0 deletions wgpu-hal/src/dynamic/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::{BufferBinding, CommandEncoder};

use super::DynBuffer;

pub trait DynCommandEncoder {
unsafe fn set_index_buffer<'a>(
&mut self,
binding: BufferBinding<'a, dyn DynBuffer>,
format: wgt::IndexFormat,
);

unsafe fn set_vertex_buffer<'a>(
&mut self,
index: u32,
binding: BufferBinding<'a, dyn DynBuffer>,
);
}

impl<C: CommandEncoder> DynCommandEncoder for C {
unsafe fn set_index_buffer<'a>(
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.

&mut self,
binding: BufferBinding<'a, dyn DynBuffer>,
format: wgt::IndexFormat,
) {
let binding = binding.expect_downcast();
unsafe { self.set_index_buffer(binding, format) };
}

unsafe fn set_vertex_buffer<'a>(
&mut self,
index: u32,
binding: BufferBinding<'a, dyn DynBuffer>,
) {
let binding = binding.expect_downcast();
unsafe { self.set_vertex_buffer(index, binding) };
}
}
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. We should do this.

16 changes: 16 additions & 0 deletions wgpu-hal/src/dynamic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
mod command;

pub use self::command::DynCommandEncoder;

use std::any::Any;

use wgt::WasmNotSendSync;

use crate::BufferBinding;

/// Base trait for all resources, allows downcasting via [`Any`].
pub trait DynResource: Any + WasmNotSendSync + 'static {
ErichDonGubler marked this conversation as resolved.
Show resolved Hide resolved
fn as_any(&self) -> &dyn Any;
Expand Down Expand Up @@ -81,3 +87,13 @@ impl<R: DynResource + ?Sized> DynResourceExt for R {
}

pub trait DynBuffer: DynResource + std::fmt::Debug {}

impl<'a> BufferBinding<'a, dyn DynBuffer> {
pub fn expect_downcast<B: DynBuffer>(self) -> BufferBinding<'a, B> {
BufferBinding {
buffer: self.buffer.expect_downcast_ref(),
offset: self.offset,
size: self.size,
}
}
}
4 changes: 2 additions & 2 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ pub mod api {

mod dynamic;

pub use dynamic::DynBuffer;
pub(crate) use dynamic::{impl_dyn_resource, DynResource};
pub use dynamic::{DynBuffer, DynCommandEncoder};

use std::{
borrow::{Borrow, Cow},
Expand Down Expand Up @@ -392,7 +392,7 @@ pub trait Api: Clone + fmt::Debug + Sized {
type Device: Device<A = Self>;

type Queue: Queue<A = Self>;
type CommandEncoder: CommandEncoder<A = Self>;
type CommandEncoder: DynCommandEncoder + CommandEncoder<A = Self>;

/// This API's command buffer type.
///
Expand Down