Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into submission-indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Jun 4, 2022
2 parents 9894497 + 4642021 commit ebf9bcd
Show file tree
Hide file tree
Showing 50 changed files with 445 additions and 439 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 13 additions & 22 deletions deno_webgpu/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,27 @@ pub async fn op_webgpu_buffer_get_map_async(
.get::<super::WebGpuDevice>(device_rid)?;
device = device_resource.0;

let boxed_sender = Box::new(sender);
let sender_ptr = Box::into_raw(boxed_sender) as *mut u8;

extern "C" fn buffer_map_future_wrapper(
status: wgpu_core::resource::BufferMapAsyncStatus,
user_data: *mut u8,
) {
let sender_ptr = user_data as *mut oneshot::Sender<Result<(), AnyError>>;
let boxed_sender = unsafe { Box::from_raw(sender_ptr) };
boxed_sender
let callback = Box::new(move |status| {
sender
.send(match status {
wgpu_core::resource::BufferMapAsyncStatus::Success => Ok(()),
_ => unreachable!(), // TODO
})
.unwrap();
}
});

// TODO(lucacasonato): error handling
let maybe_err = gfx_select!(buffer => instance.buffer_map_async(
buffer,
offset..(offset + size),
wgpu_core::resource::BufferMapOperation {
host: match mode {
1 => wgpu_core::device::HostMap::Read,
2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
},
callback: buffer_map_future_wrapper,
user_data: sender_ptr,
}
buffer,
offset..(offset + size),
wgpu_core::resource::BufferMapOperation {
host: match mode {
1 => wgpu_core::device::HostMap::Read,
2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
},
callback: wgpu_core::resource::BufferMapCallback::from_rust(callback),
}
))
.err();

Expand Down
7 changes: 7 additions & 0 deletions deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
if features.contains(wgpu_types::Features::DEPTH_CLIP_CONTROL) {
return_features.push("depth-clip-control");
}
if features.contains(wgpu_types::Features::DEPTH24UNORM_STENCIL8) {
return_features.push("depth24unorm-stencil8");
}
if features.contains(wgpu_types::Features::DEPTH32FLOAT_STENCIL8) {
return_features.push("depth32float-stencil8");
}
Expand Down Expand Up @@ -284,6 +287,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
features.set(
wgpu_types::Features::DEPTH_CLIP_CONTROL,
required_features.0.contains("depth-clip-control"),
);
features.set(
wgpu_types::Features::DEPTH24UNORM_STENCIL8,
required_features.0.contains("depth24unorm-stencil8"),
);
features.set(
wgpu_types::Features::DEPTH32FLOAT_STENCIL8,
Expand Down
2 changes: 1 addition & 1 deletion player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn main() {
},
Event::LoopDestroyed => {
log::info!("Closing");
gfx_select!(device => global.device_poll(device, true, None)).unwrap();
gfx_select!(device => global.device_poll(device, wgt::Maintain::Wait)).unwrap();
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/pipeline-statistics-query.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0000_0000_0080, // PIPELINE_STATISTICS_QUERY
features: 0x0000_0000_0000_0100, // PIPELINE_STATISTICS_QUERY
expectations: [
(
name: "Queried number of compute invocations is correct",
Expand Down
9 changes: 5 additions & 4 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
fs::{read_to_string, File},
io::{Read, Seek, SeekFrom},
path::{Path, PathBuf},
ptr, slice,
slice,
};

#[derive(serde::Deserialize)]
Expand Down Expand Up @@ -55,7 +55,7 @@ struct Test<'a> {
actions: Vec<wgc::device::trace::Action<'a>>,
}

extern "C" fn map_callback(status: wgc::resource::BufferMapAsyncStatus, _user_data: *mut u8) {
fn map_callback(status: wgc::resource::BufferMapAsyncStatus) {
match status {
wgc::resource::BufferMapAsyncStatus::Success => (),
_ => panic!("Unable to map"),
Expand Down Expand Up @@ -112,8 +112,9 @@ impl Test<'_> {
expect.offset .. expect.offset+expect.data.len() as wgt::BufferAddress,
wgc::resource::BufferMapOperation {
host: wgc::device::HostMap::Read,
callback: map_callback,
user_data: ptr::null_mut(),
callback: wgc::resource::BufferMapCallback::from_rust(
Box::new(map_callback)
),
}
))
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/LICENSE.APACHE
1 change: 1 addition & 0 deletions wgpu-core/LICENSE.MIT
10 changes: 6 additions & 4 deletions wgpu-core/src/command/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ pub enum RenderCommandError {
MissingTextureUsage(#[from] MissingTextureUsageError),
#[error(transparent)]
PushConstants(#[from] PushConstantUploadError),
#[error("Invalid Viewport parameters")]
InvalidViewport,
#[error("Invalid ScissorRect parameters")]
InvalidScissorRect,
#[error("Viewport width {0} and/or height {1} are less than or equal to 0")]
InvalidViewportDimension(f32, f32),
#[error("Viewport minDepth {0} and/or maxDepth {1} are not in [0, 1]")]
InvalidViewportDepth(f32, f32),
#[error("Scissor {0:?} is not contained in the render target {1:?}")]
InvalidScissorRect(Rect<u32>, wgt::Extent3d),
#[error("Support for {0} is not implemented yet")]
Unimplemented(&'static str),
}
Expand Down
22 changes: 13 additions & 9 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,14 +1451,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth_max,
} => {
let scope = PassErrorScope::SetViewport;
if rect.w <= 0.0
|| rect.h <= 0.0
|| depth_min < 0.0
|| depth_min > 1.0
|| depth_max < 0.0
|| depth_max > 1.0
{
return Err(RenderCommandError::InvalidViewport).map_pass_err(scope);
if rect.w <= 0.0 || rect.h <= 0.0 {
return Err(RenderCommandError::InvalidViewportDimension(
rect.w, rect.h,
))
.map_pass_err(scope);
}
if !(0.0..=1.0).contains(&depth_min) || !(0.0..=1.0).contains(&depth_max) {
return Err(RenderCommandError::InvalidViewportDepth(
depth_min, depth_max,
))
.map_pass_err(scope);
}
let r = hal::Rect {
x: rect.x,
Expand Down Expand Up @@ -1510,7 +1513,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|| rect.x + rect.w > info.extent.width
|| rect.y + rect.h > info.extent.height
{
return Err(RenderCommandError::InvalidScissorRect).map_pass_err(scope);
return Err(RenderCommandError::InvalidScissorRect(*rect, info.extent))
.map_pass_err(scope);
}
let r = hal::Rect {
x: rect.x,
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ pub(crate) fn validate_texture_copy_range(
wgt::TextureFormat::Depth32Float
| wgt::TextureFormat::Depth32FloatStencil8
| wgt::TextureFormat::Depth24Plus
| wgt::TextureFormat::Depth24PlusStencil8 => {
| wgt::TextureFormat::Depth24PlusStencil8
| wgt::TextureFormat::Depth24UnormStencil8 => {
if *copy_size != extent {
return Err(TransferError::InvalidDepthTextureExtent);
}
Expand Down
8 changes: 5 additions & 3 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
use wgt::TextureFormat as Tf;
match format {
Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => {
false
}
Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8
| Tf::Depth24UnormStencil8 => false,
_ => true,
}
}
Expand Down
9 changes: 6 additions & 3 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,18 @@ impl<A: hal::Api> LifetimeTracker<A> {
}
}

pub fn add_work_done_closure(&mut self, closure: SubmittedWorkDoneClosure) -> bool {
pub fn add_work_done_closure(
&mut self,
closure: SubmittedWorkDoneClosure,
) -> Option<SubmittedWorkDoneClosure> {
match self.active.last_mut() {
Some(active) => {
active.work_done_closures.push(closure);
true
None
}
// Note: we can't immediately invoke the closure, since it assumes
// nothing is currently locked in the hubs.
None => false,
None => Some(closure),
}
}
}
Expand Down
36 changes: 11 additions & 25 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ impl UserClosures {
self.submissions.extend(other.submissions);
}

unsafe fn fire(self) {
//Note: this logic is specifically moved out of `handle_mapping()` in order to
fn fire(self) {
// Note: this logic is specifically moved out of `handle_mapping()` in order to
// have nothing locked by the time we execute users callback code.
for (operation, status) in self.mappings {
(operation.callback)(status, operation.user_data);
operation.callback.call(status);
}
for closure in self.submissions {
(closure.callback)(closure.user_data);
closure.call();
}
}
}
Expand Down Expand Up @@ -1027,16 +1027,6 @@ impl<A: HalApi> Device<A> {
format_features: texture.format_features,
extent,
samples: texture.desc.sample_count,
// once a storage - forever a storage
sampled_internal_use: if texture
.desc
.usage
.contains(wgt::TextureUsages::STORAGE_BINDING)
{
hal::TextureUses::RESOURCE | hal::TextureUses::STORAGE_READ
} else {
hal::TextureUses::RESOURCE
},
selector,
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
})
Expand Down Expand Up @@ -2006,7 +1996,7 @@ impl<A: HalApi> Device<A> {
}
Ok((
wgt::TextureUsages::TEXTURE_BINDING,
view.sampled_internal_use,
hal::TextureUses::RESOURCE,
))
}
wgt::BindingType::StorageTexture {
Expand Down Expand Up @@ -4997,9 +4987,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_err(|_| DeviceError::Invalid)?
.maintain(hub, maintain, &mut token)?
};
unsafe {
closures.fire();
}

closures.fire();

Ok(queue_empty)
}

Expand Down Expand Up @@ -5082,9 +5072,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
self.poll_devices::<hal::api::Gles>(force_wait, &mut closures)? && all_queue_empty;
}

unsafe {
closures.fire();
}
closures.fire();

Ok(all_queue_empty)
}
Expand Down Expand Up @@ -5191,7 +5179,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
return Err(resource::BufferAccessError::AlreadyMapped);
}
resource::BufferMapState::Waiting(_) => {
op.call_error();
op.callback.call_error();
return Ok(());
}
resource::BufferMapState::Idle => {
Expand Down Expand Up @@ -5408,9 +5396,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
//Note: outside inner function so no locks are held when calling the callback
let closure = self.buffer_unmap_inner::<A>(buffer_id)?;
if let Some((operation, status)) = closure {
unsafe {
(operation.callback)(status, operation.user_data);
}
operation.callback.call(status);
}
Ok(())
}
Expand Down
Loading

0 comments on commit ebf9bcd

Please sign in to comment.