Avoid using WasmAbi functions on WebGPU backend (#3657)

Co-authored-by: Connor Fitzgerald <connor@modyfi.io>
This commit is contained in:
Josh Groves 2023-04-10 18:01:43 -02:30 committed by GitHub
parent 4d15567392
commit cfc038aeb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 545 additions and 1404 deletions

View File

@ -175,6 +175,10 @@ By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610).
- Fix metal erroring on an `array_stride` of 0. By @teoxoy in [#3538](https://github.com/gfx-rs/wgpu/pull/3538)
#### WebGPU
- Avoid using `WasmAbi` functions for WebGPU backend. By @grovesNL in [#3657](https://github.com/gfx-rs/wgpu/pull/3657)
#### General
- `copyTextureToTexture` src/dst aspects must both refer to all aspects of src/dst format. By @teoxoy in [#3431](https://github.com/gfx-rs/wgpu/pull/3431)

908
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2235,13 +2235,15 @@ impl crate::Context for Context {
}
}
fn queue_submit<I: Iterator<Item = Self::CommandBufferId>>(
fn queue_submit<I: Iterator<Item = (Self::CommandBufferId, Self::CommandBufferData)>>(
&self,
queue: &Self::QueueId,
_queue_data: &Self::QueueData,
command_buffers: I,
) -> (Self::SubmissionIndex, Self::SubmissionIndexData) {
let temp_command_buffers = command_buffers.collect::<SmallVec<[_; 4]>>();
let temp_command_buffers = command_buffers
.map(|(i, _)| i)
.collect::<SmallVec<[_; 4]>>();
let global = &self.0;
let index = match wgc::gfx_select!(*queue => global.queue_submit(*queue, &temp_command_buffers))
@ -2924,9 +2926,11 @@ impl crate::Context for Context {
&self,
_pass: &mut Self::RenderPassId,
pass_data: &mut Self::RenderPassData,
render_bundles: Box<dyn Iterator<Item = Self::RenderBundleId> + 'a>,
render_bundles: Box<
dyn Iterator<Item = (Self::RenderBundleId, &'a Self::RenderBundleData)> + 'a,
>,
) {
let temp_render_bundles = render_bundles.collect::<SmallVec<[_; 4]>>();
let temp_render_bundles = render_bundles.map(|(i, _)| i).collect::<SmallVec<[_; 4]>>();
unsafe {
wgpu_render_pass_execute_bundles(
pass_data,

File diff suppressed because it is too large Load Diff

View File

@ -570,7 +570,7 @@ pub trait Context: Debug + Send + Sized + Sync {
dest: crate::ImageCopyTextureTagged,
size: wgt::Extent3d,
);
fn queue_submit<I: Iterator<Item = Self::CommandBufferId>>(
fn queue_submit<I: Iterator<Item = (Self::CommandBufferId, Self::CommandBufferData)>>(
&self,
queue: &Self::QueueId,
queue_data: &Self::QueueData,
@ -987,7 +987,9 @@ pub trait Context: Debug + Send + Sized + Sync {
&self,
pass: &mut Self::RenderPassId,
pass_data: &mut Self::RenderPassData,
render_bundles: Box<dyn Iterator<Item = Self::RenderBundleId> + 'a>,
render_bundles: Box<
dyn Iterator<Item = (Self::RenderBundleId, &'a Self::RenderBundleData)> + 'a,
>,
);
}
@ -1025,6 +1027,7 @@ impl ObjectId {
}
}
#[allow(dead_code)]
pub fn id(&self) -> NonZeroU64 {
self.id.unwrap()
}
@ -1038,7 +1041,7 @@ impl ObjectId {
static_assertions::assert_impl_all!(ObjectId: Send, Sync);
fn downcast_ref<T: Debug + Send + Sync + 'static>(data: &crate::Data) -> &T {
pub(crate) fn downcast_ref<T: Debug + Send + Sync + 'static>(data: &crate::Data) -> &T {
strict_assert!(data.is::<T>());
// Copied from std.
unsafe { &*(data as *const dyn Any as *const T) }
@ -1501,7 +1504,7 @@ pub(crate) trait DynContext: Debug + Send + Sync {
&self,
queue: &ObjectId,
queue_data: &crate::Data,
command_buffers: Box<dyn Iterator<Item = ObjectId> + 'a>,
command_buffers: Box<dyn Iterator<Item = (ObjectId, Box<crate::Data>)> + 'a>,
) -> (ObjectId, Arc<crate::Data>);
fn queue_get_timestamp_period(&self, queue: &ObjectId, queue_data: &crate::Data) -> f32;
fn queue_on_submitted_work_done(
@ -1902,7 +1905,7 @@ pub(crate) trait DynContext: Debug + Send + Sync {
&self,
pass: &mut ObjectId,
pass_data: &mut crate::Data,
render_bundles: Box<dyn Iterator<Item = &'a ObjectId> + 'a>,
render_bundles: Box<dyn Iterator<Item = (&'a ObjectId, &'a crate::Data)> + 'a>,
);
}
@ -2902,11 +2905,14 @@ where
&self,
queue: &ObjectId,
queue_data: &crate::Data,
command_buffers: Box<dyn Iterator<Item = ObjectId> + 'a>,
command_buffers: Box<dyn Iterator<Item = (ObjectId, Box<crate::Data>)> + 'a>,
) -> (ObjectId, Arc<crate::Data>) {
let queue = <T::QueueId>::from(*queue);
let queue_data = downcast_ref(queue_data);
let command_buffers = command_buffers.into_iter().map(<T::CommandBufferId>::from);
let command_buffers = command_buffers.into_iter().map(|(id, data)| {
let command_buffer_data: <T as Context>::CommandBufferData = *data.downcast().unwrap();
(<T::CommandBufferId>::from(id), command_buffer_data)
});
let (submission_index, data) =
Context::queue_submit(self, &queue, queue_data, command_buffers);
(submission_index.into(), Arc::new(data) as _)
@ -3843,15 +3849,14 @@ where
&self,
pass: &mut ObjectId,
pass_data: &mut crate::Data,
render_bundles: Box<dyn Iterator<Item = &'a ObjectId> + 'a>,
render_bundles: Box<dyn Iterator<Item = (&'a ObjectId, &'a crate::Data)> + 'a>,
) {
let mut pass = <T::RenderPassId>::from(*pass);
let pass_data = downcast_mut::<T::RenderPassData>(pass_data);
let render_bundles = Box::new(
render_bundles
.into_iter()
.map(|id| <T::RenderBundleId>::from(*id)),
);
let render_bundles = Box::new(render_bundles.into_iter().map(|(id, data)| {
let render_bundle_data: &<T as Context>::RenderBundleData = downcast_ref(data);
(<T::RenderBundleId>::from(*id), render_bundle_data)
}));
Context::render_pass_execute_bundles(self, &mut pass, pass_data, render_bundles)
}
}

View File

@ -567,7 +567,7 @@ impl ComputePipeline {
pub struct CommandBuffer {
context: Arc<C>,
id: Option<ObjectId>,
data: Box<Data>,
data: Option<Box<Data>>,
}
static_assertions::assert_impl_all!(CommandBuffer: Send, Sync);
@ -575,7 +575,7 @@ impl Drop for CommandBuffer {
fn drop(&mut self) {
if !thread::panicking() {
if let Some(ref id) = self.id {
self.context.command_buffer_drop(id, self.data.as_ref());
self.context.command_buffer_drop(id, &self.data.take());
}
}
}
@ -2740,7 +2740,7 @@ impl CommandEncoder {
CommandBuffer {
context: Arc::clone(&self.context),
id: Some(id),
data,
data: Some(data),
}
}
@ -3224,7 +3224,11 @@ impl<'a> RenderPass<'a> {
&*self.parent.context,
&mut self.id,
self.data.as_mut(),
Box::new(render_bundles.into_iter().map(|rb| &rb.id)),
Box::new(
render_bundles
.into_iter()
.map(|rb| (&rb.id, rb.data.as_ref())),
),
)
}
}
@ -4034,7 +4038,7 @@ impl Queue {
Box::new(
command_buffers
.into_iter()
.map(|mut comb| comb.id.take().unwrap()),
.map(|mut comb| (comb.id.take().unwrap(), comb.data.take().unwrap())),
),
);