wgpu-hal: Adjust imports to eventually allow no_std.

We need `core::error::Error` (Rust 1.81) to make it a reality.
This commit is contained in:
Kevin Reid
2025-02-20 11:09:42 -08:00
committed by Nicolas Silva
parent 7b00140b16
commit bea4fb9e2d
43 changed files with 213 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
use std::{ffi::OsString, os::windows::ffi::OsStringExt};
use std::{ffi::OsString, os::windows::ffi::OsStringExt, string::String};
use windows::Win32::Graphics::Dxgi;

View File

@@ -1,4 +1,8 @@
use std::{borrow::Cow, slice};
use std::{
borrow::Cow,
slice,
string::{String, ToString as _},
};
use parking_lot::Mutex;
use windows::Win32::{Foundation, System::Diagnostics::Debug};

View File

@@ -1,4 +1,4 @@
use std::ops::Deref;
use std::{ops::Deref, string::String, vec::Vec};
use windows::{core::Interface as _, Win32::Graphics::Dxgi};

View File

@@ -1,3 +1,5 @@
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
pub mod conv;
pub mod exception;
pub mod factory;

View File

@@ -1,6 +1,6 @@
//! RenderDoc integration - <https://renderdoc.org/>
use std::{ffi, os, ptr};
use std::{ffi, os, ptr, string::String};
/// The dynamically loaded RenderDoc API function table
#[repr(C)]

View File

@@ -1,8 +1,10 @@
use std::{
mem::{size_of, size_of_val},
ptr,
string::String,
sync::Arc,
thread,
vec::Vec,
};
use parking_lot::Mutex;

View File

@@ -1,15 +1,17 @@
use std::{mem, ops::Range, vec::Vec};
use windows::Win32::{
Foundation,
Graphics::{Direct3D12, Dxgi},
};
use windows_core::Interface;
use super::conv;
use crate::{
auxil::{self, dxgi::result::HResult as _},
dx12::borrow_interface_temporarily,
AccelerationStructureEntries,
};
use std::{mem, ops::Range};
use windows::Win32::{
Foundation,
Graphics::{Direct3D12, Dxgi},
};
use windows_core::Interface;
fn make_box(origin: &wgt::Origin3d, size: &crate::CopyExtent) -> Direct3D12::D3D12_BOX {
Direct3D12::D3D12_BOX {

View File

@@ -1,4 +1,4 @@
use std::fmt;
use std::{fmt, vec::Vec};
use bit_set::BitSet;
use parking_lot::Mutex;

View File

@@ -4,8 +4,10 @@ use std::{
mem::{self, size_of, size_of_val},
num::NonZeroU32,
ptr, slice,
string::{String, ToString as _},
sync::Arc,
time::{Duration, Instant},
vec::Vec,
};
use parking_lot::Mutex;

View File

@@ -1,4 +1,4 @@
use std::{mem::size_of_val, sync::Arc};
use std::{mem::size_of_val, string::String, sync::Arc, vec::Vec};
use parking_lot::RwLock;
use windows::{

View File

@@ -72,6 +72,8 @@ Otherwise, we pass a range corresponding only to the current bind group.
!*/
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
mod adapter;
mod command;
mod conv;
@@ -84,7 +86,7 @@ mod suballocation;
mod types;
mod view;
use std::{ffi, fmt, mem, num::NonZeroU32, ops::Deref, sync::Arc};
use std::{borrow::ToOwned as _, ffi, fmt, mem, num::NonZeroU32, ops::Deref, sync::Arc, vec::Vec};
use arrayvec::ArrayVec;
use parking_lot::{Mutex, RwLock};

View File

@@ -2,6 +2,8 @@
//!
//! Nearly identical to the Vulkan sampler cache, with added descriptor heap management.
use std::vec::Vec;
use hashbrown::{hash_map::Entry, HashMap};
use ordered_float::OrderedFloat;

View File

@@ -1,6 +1,6 @@
use std::{ffi::CStr, path::PathBuf, string::String, vec::Vec};
use crate::auxil::dxgi::result::HResult;
use std::ffi::CStr;
use std::path::PathBuf;
use thiserror::Error;
use windows::{
core::{Interface, PCSTR, PCWSTR},

View File

@@ -1,3 +1,5 @@
use alloc::boxed::Box;
use crate::{
Adapter, Api, DeviceError, OpenDevice, SurfaceCapabilities, TextureFormatCapabilities,
};

View File

@@ -1,4 +1,5 @@
use std::ops::Range;
use alloc::{boxed::Box, vec::Vec};
use core::ops::Range;
use crate::{
AccelerationStructureBarrier, Api, Attachment, BufferBarrier, BufferBinding, BufferCopy,
@@ -13,7 +14,7 @@ use super::{
DynTexture, DynTextureView,
};
pub trait DynCommandEncoder: DynResource + std::fmt::Debug {
pub trait DynCommandEncoder: DynResource + core::fmt::Debug {
unsafe fn begin_encoding(&mut self, label: Label) -> Result<(), DeviceError>;
unsafe fn discard_encoding(&mut self);

View File

@@ -1,3 +1,5 @@
use alloc::{borrow::ToOwned as _, boxed::Box, vec::Vec};
use crate::{
AccelerationStructureBuildSizes, AccelerationStructureDescriptor, Api, BindGroupDescriptor,
BindGroupLayoutDescriptor, BufferDescriptor, BufferMapping, CommandEncoderDescriptor,

View File

@@ -1,3 +1,5 @@
use alloc::{boxed::Box, vec::Vec};
use crate::{Api, Capabilities, ExposedAdapter, Instance, InstanceError};
use super::{DynAdapter, DynResource, DynResourceExt as _, DynSurface};

View File

@@ -12,7 +12,11 @@ pub use instance::{DynExposedAdapter, DynInstance};
pub use queue::DynQueue;
pub use surface::{DynAcquiredSurfaceTexture, DynSurface};
use std::any::Any;
use alloc::boxed::Box;
use core::{
any::{Any, TypeId},
fmt,
};
use wgt::WasmNotSendSync;
@@ -33,11 +37,11 @@ macro_rules! impl_dyn_resource {
($($type:ty),*) => {
$(
impl crate::DynResource for $type {
fn as_any(&self) -> &dyn ::std::any::Any {
fn as_any(&self) -> &dyn ::core::any::Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
fn as_any_mut(&mut self) -> &mut dyn ::core::any::Any {
self
}
}
@@ -80,9 +84,9 @@ impl<R: DynResource + ?Sized> DynResourceExt for R {
unsafe fn unbox<T: DynResource + 'static>(self: Box<Self>) -> T {
debug_assert!(
<Self as Any>::type_id(self.as_ref()) == std::any::TypeId::of::<T>(),
<Self as Any>::type_id(self.as_ref()) == TypeId::of::<T>(),
"Resource doesn't have the expected type, expected {:?}, got {:?}",
std::any::TypeId::of::<T>(),
TypeId::of::<T>(),
<Self as Any>::type_id(self.as_ref())
);
@@ -100,25 +104,25 @@ impl<R: DynResource + ?Sized> DynResourceExt for R {
}
}
pub trait DynAccelerationStructure: DynResource + std::fmt::Debug {}
pub trait DynBindGroup: DynResource + std::fmt::Debug {}
pub trait DynBindGroupLayout: DynResource + std::fmt::Debug {}
pub trait DynBuffer: DynResource + std::fmt::Debug {}
pub trait DynCommandBuffer: DynResource + std::fmt::Debug {}
pub trait DynComputePipeline: DynResource + std::fmt::Debug {}
pub trait DynFence: DynResource + std::fmt::Debug {}
pub trait DynPipelineCache: DynResource + std::fmt::Debug {}
pub trait DynPipelineLayout: DynResource + std::fmt::Debug {}
pub trait DynQuerySet: DynResource + std::fmt::Debug {}
pub trait DynRenderPipeline: DynResource + std::fmt::Debug {}
pub trait DynSampler: DynResource + std::fmt::Debug {}
pub trait DynShaderModule: DynResource + std::fmt::Debug {}
pub trait DynAccelerationStructure: DynResource + fmt::Debug {}
pub trait DynBindGroup: DynResource + fmt::Debug {}
pub trait DynBindGroupLayout: DynResource + fmt::Debug {}
pub trait DynBuffer: DynResource + fmt::Debug {}
pub trait DynCommandBuffer: DynResource + fmt::Debug {}
pub trait DynComputePipeline: DynResource + fmt::Debug {}
pub trait DynFence: DynResource + fmt::Debug {}
pub trait DynPipelineCache: DynResource + fmt::Debug {}
pub trait DynPipelineLayout: DynResource + fmt::Debug {}
pub trait DynQuerySet: DynResource + fmt::Debug {}
pub trait DynRenderPipeline: DynResource + fmt::Debug {}
pub trait DynSampler: DynResource + fmt::Debug {}
pub trait DynShaderModule: DynResource + fmt::Debug {}
pub trait DynSurfaceTexture:
DynResource + std::borrow::Borrow<dyn DynTexture> + std::fmt::Debug
DynResource + core::borrow::Borrow<dyn DynTexture> + fmt::Debug
{
}
pub trait DynTexture: DynResource + std::fmt::Debug {}
pub trait DynTextureView: DynResource + std::fmt::Debug {}
pub trait DynTexture: DynResource + fmt::Debug {}
pub trait DynTextureView: DynResource + fmt::Debug {}
impl<'a> BufferBinding<'a, dyn DynBuffer> {
pub fn expect_downcast<B: DynBuffer>(self) -> BufferBinding<'a, B> {

View File

@@ -1,3 +1,5 @@
use alloc::{boxed::Box, vec::Vec};
use crate::{
DeviceError, DynCommandBuffer, DynFence, DynResource, DynSurface, DynSurfaceTexture,
FenceValue, Queue, SurfaceError,

View File

@@ -1,3 +1,6 @@
use alloc::boxed::Box;
use core::time::Duration;
use crate::{
DynDevice, DynFence, DynResource, DynSurfaceTexture, Surface, SurfaceConfiguration,
SurfaceError,
@@ -25,7 +28,7 @@ pub trait DynSurface: DynResource {
unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
timeout: Option<Duration>,
fence: &dyn DynFence,
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError>;
@@ -49,7 +52,7 @@ impl<S: Surface + DynResource> DynSurface for S {
unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
timeout: Option<Duration>,
fence: &dyn DynFence,
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError> {
let fence = fence.expect_downcast_ref();

View File

@@ -1,6 +1,8 @@
use alloc::{borrow::ToOwned as _, format, string::String, sync::Arc, vec, vec::Vec};
use core::sync::atomic::AtomicU8;
use glow::HasContext;
use parking_lot::Mutex;
use std::sync::{atomic::AtomicU8, Arc};
use wgt::AstcChannel;
use crate::auxil::db;
@@ -79,7 +81,7 @@ impl super::Adapter {
/// resulting in an `Err`.
pub(super) fn parse_full_version(src: &str) -> Result<(u8, u8), crate::InstanceError> {
let (version, _vendor_info) = match src.find(' ') {
Some(i) => (&src[..i], src[i + 1..].to_string()),
Some(i) => (&src[..i], src[i + 1..].to_owned()),
None => (src, String::new()),
};
@@ -1247,7 +1249,9 @@ impl super::AdapterShared {
let buffer_mapping =
unsafe { gl.map_buffer_range(target, offset, length as _, glow::MAP_READ_BIT) };
unsafe { std::ptr::copy_nonoverlapping(buffer_mapping, dst_data.as_mut_ptr(), length) };
unsafe {
core::ptr::copy_nonoverlapping(buffer_mapping, dst_data.as_mut_ptr(), length)
};
unsafe { gl.unmap_buffer(target) };
}

View File

@@ -1,10 +1,14 @@
use super::{conv, Command as C};
use arrayvec::ArrayVec;
use std::{
use alloc::string::String;
use core::{
mem::{self, size_of, size_of_val},
ops::Range,
slice,
};
use arrayvec::ArrayVec;
use super::{conv, Command as C};
#[derive(Clone, Copy, Debug, Default)]
struct TextureSlotDesc {
tex_target: super::BindTarget,
@@ -84,8 +88,7 @@ impl super::CommandBuffer {
}
fn add_push_constant_data(&mut self, data: &[u32]) -> Range<u32> {
let data_raw =
unsafe { std::slice::from_raw_parts(data.as_ptr().cast(), size_of_val(data)) };
let data_raw = unsafe { slice::from_raw_parts(data.as_ptr().cast(), size_of_val(data)) };
let start = self.data_bytes.len();
assert!(start < u32::MAX as usize);
self.data_bytes.extend_from_slice(data_raw);
@@ -262,7 +265,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn begin_encoding(&mut self, label: crate::Label) -> Result<(), crate::DeviceError> {
self.state = State::default();
self.cmd_buffer.label = label.map(str::to_string);
self.cmd_buffer.label = label.map(String::from);
Ok(())
}
unsafe fn discard_encoding(&mut self) {

View File

@@ -1,17 +1,16 @@
use super::{conv, PrivateCapabilities};
use crate::auxil::map_naga_stage;
use alloc::{
borrow::ToOwned, format, string::String, string::ToString as _, sync::Arc, vec, vec::Vec,
};
use core::{cmp::max, convert::TryInto, num::NonZeroU32, ptr, sync::atomic::Ordering};
use std::sync::Mutex;
use arrayvec::ArrayVec;
use glow::HasContext;
use naga::FastHashMap;
use std::{
cmp::max,
convert::TryInto,
ptr,
sync::{Arc, Mutex},
};
use super::{conv, PrivateCapabilities};
use crate::auxil::map_naga_stage;
use crate::TlasInstance;
use arrayvec::ArrayVec;
use std::sync::atomic::Ordering;
type ShaderStage<'a> = (
naga::ShaderStage,
@@ -24,7 +23,7 @@ struct CompilationContext<'a> {
sampler_map: &'a mut super::SamplerBindMap,
name_binding_map: &'a mut NameBindingMap,
push_constant_items: &'a mut Vec<naga::back::glsl::PushConstantItem>,
multiview: Option<std::num::NonZeroU32>,
multiview: Option<NonZeroU32>,
}
impl CompilationContext<'_> {
@@ -117,7 +116,7 @@ impl super::Device {
#[cfg(any(native, Emscripten))]
pub unsafe fn texture_from_raw(
&self,
name: std::num::NonZeroU32,
name: NonZeroU32,
desc: &crate::TextureDescriptor,
drop_callback: Option<crate::DropCallback>,
) -> super::Texture {
@@ -144,7 +143,7 @@ impl super::Device {
#[cfg(any(native, Emscripten))]
pub unsafe fn texture_from_raw_renderbuffer(
&self,
name: std::num::NonZeroU32,
name: NonZeroU32,
desc: &crate::TextureDescriptor,
drop_callback: Option<crate::DropCallback>,
) -> super::Texture {
@@ -212,7 +211,7 @@ impl super::Device {
use naga::back::glsl;
let pipeline_options = glsl::PipelineOptions {
shader_stage: naga_stage,
entry_point: stage.entry_point.to_string(),
entry_point: stage.entry_point.to_owned(),
multiview: context.multiview,
};
@@ -300,7 +299,7 @@ impl super::Device {
shaders: ArrayVec<ShaderStage<'a>, { crate::MAX_CONCURRENT_SHADER_STAGES }>,
layout: &super::PipelineLayout,
#[cfg_attr(target_arch = "wasm32", allow(unused))] label: Option<&str>,
multiview: Option<std::num::NonZeroU32>,
multiview: Option<NonZeroU32>,
) -> Result<Arc<super::PipelineInner>, crate::PipelineError> {
let mut program_stages = ArrayVec::new();
let mut group_to_binding_to_slot = Vec::with_capacity(layout.group_infos.len());
@@ -349,7 +348,7 @@ impl super::Device {
shaders: ArrayVec<ShaderStage<'a>, { crate::MAX_CONCURRENT_SHADER_STAGES }>,
layout: &super::PipelineLayout,
#[cfg_attr(target_arch = "wasm32", allow(unused))] label: Option<&str>,
multiview: Option<std::num::NonZeroU32>,
multiview: Option<NonZeroU32>,
glsl_version: naga::back::glsl::Version,
private_caps: PrivateCapabilities,
) -> Result<Arc<super::PipelineInner>, crate::PipelineError> {

View File

@@ -1,10 +1,15 @@
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
use std::{
ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, string::String, sync::Arc, time::Duration,
vec::Vec,
};
use glow::HasContext;
use hashbrown::HashMap;
use once_cell::sync::Lazy;
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};
use std::{ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::Arc, time::Duration};
/// The amount of time to wait while trying to obtain a lock to the adapter context
const CONTEXT_LOCK_TIMEOUT_SECS: u64 = 1;

View File

@@ -1,10 +1,10 @@
extern "C" {
/// returns 1 if success. 0 if failure. extension name must be null terminated
fn emscripten_webgl_enable_extension(
context: std::ffi::c_int,
extension: *const std::ffi::c_char,
) -> std::ffi::c_int;
fn emscripten_webgl_get_current_context() -> std::ffi::c_int;
context: core::ffi::c_int,
extension: *const core::ffi::c_char,
) -> core::ffi::c_int;
fn emscripten_webgl_get_current_context() -> core::ffi::c_int;
}
/// Webgl requires extensions to be enabled before using them.
/// This function can be used to enable webgl extension on emscripten target.

View File

@@ -1,4 +1,5 @@
use std::sync::atomic::Ordering;
use alloc::vec::Vec;
use core::sync::atomic::Ordering;
use glow::HasContext;

View File

@@ -98,8 +98,6 @@ mod device;
mod fence;
mod queue;
use crate::{CopyExtent, TextureDescriptor};
pub use fence::Fence;
#[cfg(not(any(windows, webgl)))]
@@ -117,14 +115,19 @@ use self::wgl::AdapterContext;
#[cfg(windows)]
use self::wgl::{Instance, Surface};
use arrayvec::ArrayVec;
use glow::HasContext;
use naga::FastHashMap;
use alloc::{boxed::Box, string::String, string::ToString as _, sync::Arc, vec::Vec};
use core::{
fmt,
ops::Range,
sync::atomic::{AtomicU32, AtomicU8},
};
use parking_lot::Mutex;
use std::sync::atomic::{AtomicU32, AtomicU8};
use std::{fmt, ops::Range, sync::Arc};
use arrayvec::ArrayVec;
use glow::HasContext;
use naga::FastHashMap;
use crate::{CopyExtent, TextureDescriptor};
#[derive(Clone, Debug)]
pub struct Api;
@@ -403,7 +406,7 @@ pub struct Texture {
impl crate::DynTexture for Texture {}
impl crate::DynSurfaceTexture for Texture {}
impl std::borrow::Borrow<dyn crate::DynTexture> for Texture {
impl core::borrow::Borrow<dyn crate::DynTexture> for Texture {
fn borrow(&self) -> &dyn crate::DynTexture {
self
}

View File

@@ -1,16 +1,13 @@
use super::{conv::is_layered_target, Command as C, PrivateCapabilities};
use alloc::sync::Arc;
use arrayvec::ArrayVec;
use core::{mem::size_of, slice, sync::atomic::Ordering};
use glow::HasContext;
use std::{
mem::size_of,
slice,
sync::{atomic::Ordering, Arc},
};
const DEBUG_ID: u32 = 0;
fn extract_marker<'a>(data: &'a [u8], range: &std::ops::Range<u32>) -> &'a str {
std::str::from_utf8(&data[range.start as usize..range.end as usize]).unwrap()
fn extract_marker<'a>(data: &'a [u8], range: &core::ops::Range<u32>) -> &'a str {
core::str::from_utf8(&data[range.start as usize..range.end as usize]).unwrap()
}
fn get_2d_target(target: u32, array_layer: u32) -> u32 {

View File

@@ -1,3 +1,5 @@
use alloc::{format, string::String, vec::Vec};
use glow::HasContext;
use parking_lot::{Mutex, RwLock};
use wasm_bindgen::{JsCast, JsValue};
@@ -420,7 +422,7 @@ impl crate::Surface for Surface {
unsafe fn acquire_texture(
&self,
_timeout_ms: Option<std::time::Duration>, //TODO
_timeout_ms: Option<core::time::Duration>, //TODO
_fence: &super::Fence,
) -> Result<Option<crate::AcquiredSurfaceTexture<super::Api>>, crate::SurfaceError> {
let swapchain = self.swapchain.read();

View File

@@ -1,14 +1,19 @@
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
use std::{
borrow::ToOwned as _,
ffi::{c_void, CStr, CString},
mem::{self, size_of, size_of_val, ManuallyDrop},
os::raw::c_int,
ptr,
string::String,
sync::{
mpsc::{sync_channel, SyncSender},
Arc,
},
thread,
time::Duration,
vec::Vec,
};
use glow::HasContext;

View File

@@ -202,6 +202,7 @@
//!
//! [wiki-debug]: https://github.com/gfx-rs/wgpu/wiki/Debugging-wgpu-Applications
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![allow(
// this happens on the GL backend, where it is both thread safe and non-thread safe in the same code.
@@ -226,7 +227,10 @@
clippy::pattern_type_mismatch,
)]
#![warn(
clippy::alloc_instead_of_core,
clippy::ptr_as_ptr,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
trivial_casts,
trivial_numeric_casts,
unsafe_op_in_unsafe_fn,
@@ -234,7 +238,12 @@
unused_qualifications
)]
extern crate alloc;
extern crate wgpu_types as wgt;
// TODO(https://github.com/gfx-rs/wgpu/issues/6826): disable std except on noop and gles-WebGL.
// Requires Rust 1.81 for core::error::Error.
#[macro_use]
extern crate std;
/// DirectX12 API internals.
#[cfg(dx12)]
@@ -276,14 +285,17 @@ pub use dynamic::{
DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView,
};
use std::{
borrow::{Borrow, Cow},
#[allow(unused)]
use alloc::boxed::Box;
use alloc::{borrow::Cow, string::String, sync::Arc, vec::Vec};
use core::{
borrow::Borrow,
fmt,
num::NonZeroU32,
ops::{Range, RangeInclusive},
ptr::NonNull,
sync::Arc,
};
use std::error::Error; // TODO(https://github.com/gfx-rs/wgpu/issues/6826): use core::error after MSRV bump
use bitflags::bitflags;
use parking_lot::Mutex;
@@ -305,7 +317,7 @@ pub const QUERY_SIZE: wgt::BufferAddress = 8;
pub type Label<'a> = Option<&'a str>;
pub type MemoryRange = Range<wgt::BufferAddress>;
pub type FenceValue = u64;
pub type AtomicFenceValue = std::sync::atomic::AtomicU64;
pub type AtomicFenceValue = core::sync::atomic::AtomicU64;
/// A callback to signal that wgpu is no longer using a resource.
#[cfg(any(gles, vulkan))]
@@ -417,7 +429,7 @@ pub struct InstanceError {
/// Underlying error value, if any is available.
#[source]
source: Option<Arc<dyn std::error::Error + Send + Sync + 'static>>,
source: Option<Arc<dyn Error + Send + Sync + 'static>>,
}
impl InstanceError {
@@ -429,10 +441,7 @@ impl InstanceError {
}
}
#[allow(dead_code)] // may be unused on some platforms
pub(crate) fn with_source(
message: String,
source: impl std::error::Error + Send + Sync + 'static,
) -> Self {
pub(crate) fn with_source(message: String, source: impl Error + Send + Sync + 'static) -> Self {
Self {
message,
source: Some(Arc::new(source)),
@@ -585,13 +594,13 @@ pub trait Surface: WasmNotSendSync {
///
/// [`texture`]: AcquiredSurfaceTexture::texture
/// [`SurfaceTexture`]: Api::SurfaceTexture
/// [`borrow`]: std::borrow::Borrow::borrow
/// [`borrow`]: alloc::borrow::Borrow::borrow
/// [`Texture`]: Api::Texture
/// [`Fence`]: Api::Fence
/// [`self.discard_texture`]: Surface::discard_texture
unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
timeout: Option<core::time::Duration>,
fence: &<Self::A as Api>::Fence,
) -> Result<Option<AcquiredSurfaceTexture<Self::A>>, SurfaceError>;

View File

@@ -1,6 +1,11 @@
use super::{conv, AsNative, TimestampQuerySupport};
use crate::CommandEncoder as _;
use std::{borrow::Cow, mem::size_of, ops::Range};
use std::{
borrow::{Cow, ToOwned as _},
mem::size_of,
ops::Range,
vec::Vec,
};
// has to match `Temp::binding_sizes`
const WORD_SIZE: usize = 4;

View File

@@ -1,9 +1,8 @@
use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
use core::{ptr::NonNull, sync::atomic};
use std::{thread, time};
use parking_lot::Mutex;
use std::{
ptr::NonNull,
sync::{atomic, Arc},
thread, time,
};
use super::conv;
use crate::auxil::map_naga_stage;
@@ -157,7 +156,7 @@ impl super::Device {
spirv_cross_compatibility: false,
fake_missing_bindings: false,
per_entry_point_map: naga::back::msl::EntryPointResourceMap::from([(
stage.entry_point.to_string(),
stage.entry_point.to_owned(),
ep_resources.clone(),
)]),
bounds_check_policies: naga::proc::BoundsCheckPolicies {

View File

@@ -13,6 +13,8 @@ end of the VS buffer table.
!*/
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
// `MTLFeatureSet` is superseded by `MTLGpuFamily`.
// However, `MTLGpuFamily` is only supported starting MacOS 10.15, whereas our minimum target is MacOS 10.13,
// See https://github.com/gpuweb/gpuweb/issues/1069 for minimum spec.
@@ -27,10 +29,13 @@ mod surface;
mod time;
use std::{
borrow::ToOwned as _,
fmt, iter, ops,
ptr::NonNull,
string::String,
sync::{atomic, Arc},
thread,
vec::Vec,
};
use arrayvec::ArrayVec;

View File

@@ -1,5 +1,6 @@
#![allow(clippy::let_unit_value)] // `let () =` being used to constrain result type
use std::borrow::ToOwned as _;
use std::mem::ManuallyDrop;
use std::ptr::NonNull;
use std::thread;

View File

@@ -1,7 +1,5 @@
use core::cell::UnsafeCell;
use core::ops::Range;
use core::ptr;
use std::sync::Arc;
use alloc::{sync::Arc, vec::Vec};
use core::{cell::UnsafeCell, ops::Range, ptr};
#[derive(Clone, Debug)]
pub struct Buffer {

View File

@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use core::mem;
use core::ops::Range;

View File

@@ -1,8 +1,13 @@
#![allow(unused_variables)]
use alloc::{string::String, vec, vec::Vec};
use core::{
ptr,
sync::atomic::{AtomicU64, Ordering},
time::Duration,
};
use crate::TlasInstance;
use core::ptr;
use core::sync::atomic::{AtomicU64, Ordering};
mod buffer;
pub use buffer::Buffer;
@@ -71,7 +76,7 @@ impl crate::DynSurfaceTexture for Resource {}
impl crate::DynTexture for Resource {}
impl crate::DynTextureView for Resource {}
impl std::borrow::Borrow<dyn crate::DynTexture> for Resource {
impl core::borrow::Borrow<dyn crate::DynTexture> for Resource {
fn borrow(&self) -> &dyn crate::DynTexture {
self
}
@@ -202,7 +207,7 @@ impl crate::Surface for Context {
unsafe fn acquire_texture(
&self,
timeout: Option<std::time::Duration>,
timeout: Option<Duration>,
fence: &Fence,
) -> Result<Option<crate::AcquiredSurfaceTexture<Api>>, crate::SurfaceError> {
Ok(None)

View File

@@ -1,9 +1,9 @@
use super::conv;
use std::{borrow::ToOwned as _, collections::BTreeMap, ffi::CStr, sync::Arc, vec::Vec};
use ash::{amd, ext, google, khr, vk};
use parking_lot::Mutex;
use std::{collections::BTreeMap, ffi::CStr, sync::Arc};
use super::conv;
fn depth_stencil_required_flags() -> vk::FormatFeatureFlags {
vk::FormatFeatureFlags::SAMPLED_IMAGE | vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT

View File

@@ -1,3 +1,5 @@
use std::vec::Vec;
use ash::vk;
impl super::PrivateCapabilities {

View File

@@ -1,21 +1,22 @@
use super::{conv, RawTlasInstance};
use arrayvec::ArrayVec;
use ash::{khr, vk};
use hashbrown::hash_map::Entry;
use parking_lot::Mutex;
use crate::TlasInstance;
use std::{
borrow::Cow,
borrow::{Cow, ToOwned as _},
collections::BTreeMap,
ffi::{CStr, CString},
mem::{self, size_of, MaybeUninit},
num::NonZeroU32,
ptr, slice,
sync::Arc,
vec::Vec,
};
use arrayvec::ArrayVec;
use ash::{khr, vk};
use hashbrown::hash_map::Entry;
use parking_lot::Mutex;
use super::{conv, RawTlasInstance};
use crate::TlasInstance;
impl super::DeviceShared {
/// Set the name of `object` to `name`.
///
@@ -903,7 +904,7 @@ impl super::Device {
runtime_checks,
} => {
let pipeline_options = naga::back::spv::PipelineOptions {
entry_point: stage.entry_point.to_string(),
entry_point: stage.entry_point.to_owned(),
shader_stage: naga_stage,
};
let needs_temp_options = !runtime_checks.bounds_checks

View File

@@ -1,9 +1,13 @@
use std::{
borrow::ToOwned as _,
boxed::Box,
ffi::{c_void, CStr, CString},
slice,
str::FromStr,
string::{String, ToString as _},
sync::Arc,
thread,
vec::Vec,
};
use arrayvec::ArrayVec;

View File

@@ -24,6 +24,8 @@ Otherwise, we manage a pool of `VkFence` objects behind each `hal::Fence`.
!*/
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
mod adapter;
mod command;
mod conv;
@@ -33,11 +35,13 @@ mod sampler;
use std::{
borrow::Borrow,
boxed::Box,
ffi::{CStr, CString},
fmt, mem,
num::NonZeroU32,
ops::DerefMut,
sync::Arc,
vec::Vec,
};
use arrayvec::ArrayVec;