mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
Introduce DynCommandEncoder, implement index & vertex buffer ops on it
This commit is contained in:
parent
a4d9d38d03
commit
256ec6e447
37
wgpu-hal/src/dynamic/command.rs
Normal file
37
wgpu-hal/src/dynamic/command.rs
Normal file
@ -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>(
|
||||
&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) };
|
||||
}
|
||||
}
|
@ -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 {
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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},
|
||||
@ -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.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user