Skip to content

Sync changes from mozilla-central gfx/wgpu #435

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Generated with cbindgen:0.9.1 */
/* Generated with cbindgen:0.12.0 */

/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
* To generate this file:
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ impl Binder {
self.entries
.iter()
.position(|entry| !entry.is_valid())
.unwrap_or(self.entries.len())
.unwrap_or_else(|| self.entries.len())
}
}
4 changes: 2 additions & 2 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ impl<F> Global<F> {
}

// Rebind resources
if pass.binder.pipeline_layout_id != Some(pipeline.layout_id.clone()) {
if pass.binder.pipeline_layout_id != Some(pipeline.layout_id) {
let pipeline_layout = &pipeline_layout_guard[pipeline.layout_id];
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
pass.binder.pipeline_layout_id = Some(pipeline.layout_id);
pass.binder
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
let mut is_compatible = true;
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
use arrayvec::ArrayVec;
use hal::{adapter::PhysicalDevice as _, command::CommandBuffer as _, device::Device as _};

use std::{borrow::Borrow, collections::hash_map::Entry, iter, mem, ptr, slice, thread::ThreadId};
use std::{borrow::Borrow, collections::hash_map::Entry, iter, mem, slice, thread::ThreadId};


pub struct RenderBundle<B: hal::Backend> {
Expand Down Expand Up @@ -528,10 +528,10 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
let mut attachment_index = color_attachments.len();
if color_attachments
.iter()
.any(|at| at.resolve_target != ptr::null())
.any(|at| !at.resolve_target.is_null())
{
for (i, at) in color_attachments.iter().enumerate() {
if at.resolve_target == ptr::null() {
if at.resolve_target.is_null() {
resolve_ids.push((
hal::pass::ATTACHMENT_UNUSED,
hal::image::Layout::ColorAttachmentOptimal,
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
}

// Rebind resource
if pass.binder.pipeline_layout_id != Some(pipeline.layout_id.clone()) {
if pass.binder.pipeline_layout_id != Some(pipeline.layout_id) {
let pipeline_layout = &pipeline_layout_guard[pipeline.layout_id];
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
pass.binder.pipeline_layout_id = Some(pipeline.layout_id);
pass.binder
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
let mut is_compatible = true;
Expand Down
23 changes: 9 additions & 14 deletions wgpu-core/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<B: GfxBackend> PendingResources<B> {
.active
.iter()
.position(|a| unsafe { !device.get_fence_status(&a.fence).unwrap() })
.unwrap_or(self.active.len());
.unwrap_or_else(|| self.active.len());
let last_done = if done_count != 0 {
self.active[done_count - 1].index
} else {
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<B: GfxBackend> Device<B> {
min_device_allocation: 0x1_00_00,
}),
};
(mt.properties.into(), mt.heap_index as u32, config)
(mt.properties, mt.heap_index as u32, config)
});
unsafe { Heaps::new(types, mem_props.memory_heaps.iter().cloned()) }
};
Expand Down Expand Up @@ -831,9 +831,8 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
&self,
device_id: DeviceId,
desc: &resource::BufferDescriptor,
mapped_ptr_out: *mut *mut u8,
id_in: F::Input,
) -> BufferId {
) -> (BufferId, *mut u8) {
let hub = B::hub(self);
let mut token = Token::root();
let mut desc = desc.clone();
Expand All @@ -844,17 +843,13 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
let mut buffer = device.create_buffer(device_id, &desc);
let ref_count = buffer.life_guard.ref_count.clone();

match map_buffer(&device.raw, &mut buffer, 0 .. desc.size, HostMap::Write) {
Ok(ptr) => unsafe {
*mapped_ptr_out = ptr;
},
let pointer = match map_buffer(&device.raw, &mut buffer, 0 .. desc.size, HostMap::Write) {
Ok(ptr) => ptr,
Err(e) => {
log::error!("failed to create buffer in a mapped state: {:?}", e);
unsafe {
*mapped_ptr_out = ptr::null_mut();
}
ptr::null_mut()
}
}
};

let id = hub.buffers.register_identity(id_in, buffer, &mut token);
let ok = device.trackers.lock().buffers.init(
Expand All @@ -864,7 +859,7 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
resource::BufferUsage::MAP_WRITE,
);
assert!(ok);
id
(id, pointer)
}

pub fn device_set_buffer_sub_data<B: GfxBackend>(
Expand Down Expand Up @@ -2020,7 +2015,7 @@ impl<F: IdentityFilter<SwapChainId>> Global<F> {
let num_frames = swap_chain::DESIRED_NUM_FRAMES
.max(*caps.image_count.start())
.min(*caps.image_count.end());
let config = desc.to_hal(num_frames, &device.features);
let config = desc.to_hal(num_frames, device.features);

if let Some(formats) = formats {
assert!(
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Id<T>(u64, PhantomData<T>);
impl<T> Id<T> {
pub const ERROR: Self = Self(0, PhantomData);

pub fn backend(&self) -> Backend {
pub fn backend(self) -> Backend {
match self.0 >> (64 - BACKEND_BITS) as u8 {
0 => Backend::Empty,
1 => Backend::Vulkan,
Expand Down Expand Up @@ -107,13 +107,13 @@ pub type ComputePassId = Id<crate::command::ComputePass<Dummy>>;
pub type SwapChainId = Id<crate::swap_chain::SwapChain<Dummy>>;

impl SurfaceId {
pub(crate) fn to_swap_chain_id(&self, backend: Backend) -> SwapChainId {
pub(crate) fn to_swap_chain_id(self, backend: Backend) -> SwapChainId {
let (index, epoch, _) = self.unzip();
Id::zip(index, epoch, backend)
}
}
impl SwapChainId {
pub(crate) fn to_surface_id(&self) -> SurfaceId {
pub(crate) fn to_surface_id(self) -> SurfaceId {
let (index, epoch, _) = self.unzip();
Id::zip(index, epoch, Backend::Empty)
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ pub enum CompareFunction {
}

impl CompareFunction {
pub fn is_trivial(&self) -> bool {
match *self {
pub fn is_trivial(self) -> bool {
match self {
CompareFunction::Never | CompareFunction::Always => true,
_ => false,
}
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/swap_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl SwapChainDescriptor {
pub(crate) fn to_hal(
&self,
num_frames: u32,
features: &Features,
features: Features,
) -> hal::window::SwapchainConfig {
let mut config = hal::window::SwapchainConfig::new(
self.width,
self.height,
conv::map_texture_format(self.format, *features),
conv::map_texture_format(self.format, features),
num_frames,
);
//TODO: check for supported
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
}
Err(e) => {
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
let desc = sc.desc.to_hal(sc.num_frames, &device.features);
let desc = sc.desc.to_hal(sc.num_frames, device.features);
unsafe {
suf.configure_swapchain(&device.raw, desc).unwrap();
suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/track/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<I: Copy + PartialOrd, T: Copy + PartialEq> RangedStates<I, T> {
Some(elem) => elem,
None => return,
};
while let Some(next) = iter.next() {
for next in iter {
if cur.0.end == next.0.start && cur.1 == next.1 {
num_removed += 1;
cur.0.end = next.0.end;
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/track/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl ResourceState for TextureState {
id,
selector: hal::image::SubresourceRange {
aspects,
levels: level .. level + 1,
levels: level .. level+1,
layers: layers.clone(),
},
usage: start.last .. final_usage,
Expand Down
14 changes: 7 additions & 7 deletions wgpu-native/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ pub extern "C" fn wgpu_render_pass_end_pass(pass_id: id::RenderPassId) {
}

#[no_mangle]
pub extern "C" fn wgpu_render_pass_set_bind_group(
pub unsafe extern "C" fn wgpu_render_pass_set_bind_group(
pass_id: id::RenderPassId,
index: u32,
bind_group_id: id::BindGroupId,
offsets: *const core::BufferAddress,
offsets_length: usize,
) {
let offsets = if offsets_length != 0 {
unsafe { slice::from_raw_parts(offsets, offsets_length) }
slice::from_raw_parts(offsets, offsets_length)
} else {
&[]
};
Expand Down Expand Up @@ -138,15 +138,15 @@ pub extern "C" fn wgpu_render_pass_set_index_buffer(
}

#[no_mangle]
pub extern "C" fn wgpu_render_pass_set_vertex_buffers(
pub unsafe extern "C" fn wgpu_render_pass_set_vertex_buffers(
pass_id: id::RenderPassId,
start_slot: u32,
buffers: *const id::BufferId,
offsets: *const core::BufferAddress,
length: usize,
) {
let buffers = unsafe { slice::from_raw_parts(buffers, length) };
let offsets = unsafe { slice::from_raw_parts(offsets, length) };
let buffers = slice::from_raw_parts(buffers, length);
let offsets = slice::from_raw_parts(offsets, length);
gfx_select!(pass_id => GLOBAL.render_pass_set_vertex_buffers(pass_id, start_slot, buffers, offsets))
}

Expand Down Expand Up @@ -258,15 +258,15 @@ pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: id::ComputePassId) {
}

#[no_mangle]
pub extern "C" fn wgpu_compute_pass_set_bind_group(
pub unsafe extern "C" fn wgpu_compute_pass_set_bind_group(
pass_id: id::ComputePassId,
index: u32,
bind_group_id: id::BindGroupId,
offsets: *const core::BufferAddress,
offsets_length: usize,
) {
let offsets = if offsets_length != 0 {
unsafe { slice::from_raw_parts(offsets, offsets_length) }
slice::from_raw_parts(offsets, offsets_length)
} else {
&[]
};
Expand Down
22 changes: 11 additions & 11 deletions wgpu-native/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub extern "C" fn wgpu_create_surface_from_windows_hwnd(
}

#[no_mangle]
pub extern "C" fn wgpu_request_adapter_async(
pub unsafe extern "C" fn wgpu_request_adapter_async(
desc: Option<&core::instance::RequestAdapterOptions>,
mask: core::instance::BackendBit,
callback: RequestAdapterCallback,
Expand All @@ -133,12 +133,10 @@ pub extern "C" fn wgpu_request_adapter_async(
&desc.cloned().unwrap_or_default(),
core::instance::AdapterInputs::Mask(mask, || PhantomData),
);
unsafe {
callback(
id.unwrap_or(id::AdapterId::ERROR),
userdata,
)
};
callback(
id.unwrap_or(id::AdapterId::ERROR),
userdata,
);
}

#[no_mangle]
Expand Down Expand Up @@ -171,12 +169,14 @@ pub extern "C" fn wgpu_device_create_buffer(
}

#[no_mangle]
pub extern "C" fn wgpu_device_create_buffer_mapped(
pub unsafe extern "C" fn wgpu_device_create_buffer_mapped(
device_id: id::DeviceId,
desc: &core::resource::BufferDescriptor,
mapped_ptr_out: *mut *mut u8,
) -> id::BufferId {
gfx_select!(device_id => GLOBAL.device_create_buffer_mapped(device_id, desc, mapped_ptr_out, PhantomData))
let (id, ptr) = gfx_select!(device_id => GLOBAL.device_create_buffer_mapped(device_id, desc, PhantomData));
*mapped_ptr_out = ptr;
id
}

#[no_mangle]
Expand Down Expand Up @@ -275,13 +275,13 @@ pub extern "C" fn wgpu_device_get_queue(device_id: id::DeviceId) -> id::QueueId
}

#[no_mangle]
pub extern "C" fn wgpu_queue_submit(
pub unsafe extern "C" fn wgpu_queue_submit(
queue_id: id::QueueId,
command_buffers: *const id::CommandBufferId,
command_buffers_length: usize,
) {
let command_buffer_ids =
unsafe { slice::from_raw_parts(command_buffers, command_buffers_length) };
slice::from_raw_parts(command_buffers, command_buffers_length);
gfx_select!(queue_id => GLOBAL.queue_submit(queue_id, command_buffer_ids))
}

Expand Down