mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 08:21:25 +01:00
Remove dispatch2 dependency (#9048)
This commit is contained in:
1 parent
3f60e75976
commit
c7f3db8bf1
6 files changed
+55
-28
No files matched your search
Generated
-4
@@ -1178,8 +1178,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||
dependencies = [
|
||||
"bitflags 2.11.0",
|
||||
"block2 0.6.2",
|
||||
"libc",
|
||||
"objc2 0.6.3",
|
||||
]
|
||||
|
||||
@@ -2869,7 +2867,6 @@ checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794"
|
||||
dependencies = [
|
||||
"bitflags 2.11.0",
|
||||
"block2 0.6.2",
|
||||
"dispatch2",
|
||||
"objc2 0.6.3",
|
||||
"objc2-foundation 0.3.2",
|
||||
]
|
||||
@@ -4940,7 +4937,6 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"cfg-if",
|
||||
"cfg_aliases 0.2.1",
|
||||
"dispatch2",
|
||||
"env_logger",
|
||||
"glam",
|
||||
"glow",
|
||||
|
||||
@@ -203,7 +203,6 @@ xshell = "0.2.2"
|
||||
|
||||
# Metal dependencies
|
||||
block2 = "0.6.2"
|
||||
dispatch2 = "0.3.0"
|
||||
objc2 = "0.6.3"
|
||||
objc2-core-foundation = { version = "0.3.2", default-features = false, features = [
|
||||
"std",
|
||||
@@ -219,7 +218,6 @@ objc2-foundation = { version = "0.3.2", default-features = false, features = [
|
||||
objc2-metal = { version = "0.3.2", default-features = false, features = [
|
||||
"std",
|
||||
"block2",
|
||||
"dispatch2",
|
||||
"MTLAllocation",
|
||||
"MTLBlitCommandEncoder",
|
||||
"MTLBlitPass",
|
||||
|
||||
@@ -75,7 +75,6 @@ metal = [
|
||||
"naga/msl-out",
|
||||
"dep:arrayvec",
|
||||
"dep:block2",
|
||||
"dep:dispatch2",
|
||||
"dep:bytemuck",
|
||||
"dep:hashbrown",
|
||||
"dep:libc",
|
||||
@@ -285,7 +284,6 @@ mach-dxcompiler-rs = { workspace = true, optional = true }
|
||||
[target.'cfg(target_vendor = "apple")'.dependencies]
|
||||
# Backend: Metal
|
||||
block2 = { workspace = true, optional = true }
|
||||
dispatch2 = { workspace = true, optional = true }
|
||||
bytemuck = { workspace = true, optional = true }
|
||||
objc2 = { workspace = true, optional = true }
|
||||
objc2-core-foundation = { workspace = true, optional = true }
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
|
||||
use core::{
|
||||
ffi::c_void,
|
||||
ptr::{self, NonNull},
|
||||
sync::atomic,
|
||||
};
|
||||
use dispatch2::DispatchData;
|
||||
use core::{ptr::NonNull, sync::atomic};
|
||||
use std::{thread, time};
|
||||
|
||||
use bytemuck::TransparentWrapper;
|
||||
@@ -1143,20 +1138,11 @@ impl crate::Device for super::Device {
|
||||
num_workgroups,
|
||||
} => {
|
||||
// SAFETY: this creates a reference to `file` that is dropped before `file` is dropped.
|
||||
let data = unsafe {
|
||||
DispatchData::new(
|
||||
NonNull::new(file.as_ptr() as *mut c_void).unwrap(),
|
||||
file.len(),
|
||||
None,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
let library = self
|
||||
.shared
|
||||
.device
|
||||
.newLibraryWithData_error(&data)
|
||||
.map_err(|e| crate::ShaderError::Compilation(format!("Metallib: {e:?}")))?;
|
||||
drop(data);
|
||||
let library = super::library_from_metallib::new_library_from_metallib_bytes(
|
||||
&self.shared.device,
|
||||
file,
|
||||
)
|
||||
.map_err(|e| crate::ShaderError::Compilation(format!("Metallib: {e:?}")))?;
|
||||
Ok(super::ShaderModule {
|
||||
source: ShaderModuleSource::Passthrough(PassthroughShader {
|
||||
library,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
use core::{ffi::c_void, ptr::NonNull};
|
||||
|
||||
use objc2::{
|
||||
msg_send,
|
||||
rc::Retained,
|
||||
runtime::{AnyObject, ProtocolObject},
|
||||
};
|
||||
use objc2_foundation::NSError;
|
||||
use objc2_metal::{MTLDevice, MTLLibrary};
|
||||
|
||||
#[link(name = "System")] // libdispatch lives inside libSystem
|
||||
extern "C" {
|
||||
fn dispatch_data_create(
|
||||
buffer: NonNull<c_void>,
|
||||
size: usize,
|
||||
queue: Option<NonNull<c_void>>, // dispatch_queue_t _Nullable
|
||||
destructor: *mut c_void, // dispatch_block_t _Nullable
|
||||
) -> *mut AnyObject; // dispatch_data_t
|
||||
|
||||
fn dispatch_release(object: *mut AnyObject); // dispatch_data_t
|
||||
}
|
||||
|
||||
const DISPATCH_DATA_DESTRUCTOR_DEFAULT: *mut c_void = core::ptr::null_mut();
|
||||
|
||||
/// See <https://github.com/madsmtm/objc2/issues/819>.
|
||||
///
|
||||
/// newLibraryWithData requires DispatchData, part of the Dispatch library.
|
||||
/// Not only is this a big additional dependency for a glorified `Vec<u8>`
|
||||
/// in this case, but the code in the dispatch2 rust crate is a WIP and
|
||||
/// Mozilla has decided not to vendor it yet.
|
||||
///
|
||||
/// This function allows us to deal with DispatchData without dealing
|
||||
/// with these problems.
|
||||
pub(crate) fn new_library_from_metallib_bytes(
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
data: &[u8],
|
||||
) -> Result<Retained<ProtocolObject<dyn MTLLibrary>>, Retained<NSError>> {
|
||||
let buffer = NonNull::new(data.as_ptr().cast_mut()).unwrap().cast();
|
||||
let data =
|
||||
unsafe { dispatch_data_create(buffer, data.len(), None, DISPATCH_DATA_DESTRUCTOR_DEFAULT) };
|
||||
assert!(!data.is_null());
|
||||
|
||||
let res: Result<Retained<ProtocolObject<dyn MTLLibrary>>, Retained<NSError>> =
|
||||
unsafe { msg_send![device, newLibraryWithData: data, error: _] };
|
||||
|
||||
unsafe { dispatch_release(data) };
|
||||
res
|
||||
}
|
||||
@@ -22,6 +22,7 @@ mod adapter;
|
||||
mod command;
|
||||
mod conv;
|
||||
mod device;
|
||||
mod library_from_metallib;
|
||||
mod surface;
|
||||
mod time;
|
||||
|
||||
|
||||
Reference in new issue
Block a user