mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1606077 - Address clippy safety error in device_create_buffer_mapped r=jrmuizel
Address most wgpu clippy warnings Differential Revision: https://phabricator.services.mozilla.com/D58411 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1b23bcd87b
commit
284ba100bb
@ -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:
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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> {
|
||||
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
@ -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()) }
|
||||
};
|
||||
@ -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();
|
||||
@ -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(
|
||||
@ -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>(
|
||||
@ -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!(
|
||||
|
@ -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,
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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
|
||||
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -92,7 +92,7 @@ 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,
|
||||
@ -100,7 +100,7 @@ pub extern "C" fn wgpu_render_pass_set_bind_group(
|
||||
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 {
|
||||
&[]
|
||||
};
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ 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,
|
||||
@ -266,7 +266,7 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(
|
||||
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 {
|
||||
&[]
|
||||
};
|
||||
|
@ -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,
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user