From a421c1c8b646d3fc8558a4c2200895a3de5fe1c6 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 8 Jun 2021 11:46:53 -0400 Subject: [PATCH] Instance plumbing --- Cargo.lock | 26 +++ player/src/lib.rs | 78 ++++---- wgpu-core/Cargo.toml | 4 + wgpu-core/build.rs | 8 +- wgpu-core/src/device/mod.rs | 11 +- wgpu-core/src/hub.rs | 20 +- wgpu-core/src/id.rs | 2 +- wgpu-core/src/instance.rs | 155 +++++++-------- wgpu-core/src/lib.rs | 26 +-- wgpu-hal/Cargo.toml | 6 +- wgpu-hal/src/empty.rs | 6 +- wgpu-hal/src/lib.rs | 18 +- wgpu-hal/src/metal/mod.rs | 379 ++++++++++++++++++++++++++++++++++++ wgpu/Cargo.toml | 4 + wgpu/src/backend/direct.rs | 21 +- wgpu/src/lib.rs | 17 +- wgpu/src/util/device.rs | 5 +- 17 files changed, 589 insertions(+), 197 deletions(-) create mode 100644 wgpu-hal/src/metal/mod.rs diff --git a/Cargo.lock b/Cargo.lock index c7fd6d634..29ba8f25c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -892,6 +892,20 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metal" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c12e48c737ee9a55e8bb2352bcde588f79ae308d3529ee888f7cc0f469b5777" +dependencies = [ + "bitflags", + "block", + "cocoa-foundation", + "foreign-types", + "log", + "objc", +] + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -1155,6 +1169,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" dependencies = [ "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", ] [[package]] @@ -1858,6 +1882,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu-core", + "wgpu-hal", "wgpu-types", "winit", ] @@ -1890,6 +1915,7 @@ name = "wgpu-hal" version = "0.1.0" dependencies = [ "bitflags", + "metal", "naga", "raw-window-handle", "smallvec", diff --git a/player/src/lib.rs b/player/src/lib.rs index 61b9219da..881307b7c 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -39,12 +39,12 @@ impl wgc::hub::IdentityHandlerFactory impl wgc::hub::GlobalIdentityHandlerFactory for IdentityPassThroughFactory {} pub trait GlobalPlay { - fn encode_commands( + fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, commands: Vec, ) -> wgc::id::CommandBufferId; - fn process( + fn process( &self, device: wgc::id::DeviceId, action: trace::Action, @@ -54,7 +54,7 @@ pub trait GlobalPlay { } impl GlobalPlay for wgc::hub::Global { - fn encode_commands( + fn encode_commands( &self, encoder: wgc::id::CommandEncoderId, commands: Vec, @@ -139,48 +139,50 @@ impl GlobalPlay for wgc::hub::Global { cmd_buf } - fn process( + fn process( &self, device: wgc::id::DeviceId, action: trace::Action, dir: &Path, comb_manager: &mut wgc::hub::IdentityManager, ) { - use wgc::device::trace::Action as A; + use wgc::device::trace::Action; log::info!("action {:?}", action); //TODO: find a way to force ID perishing without excessive `maintain()` calls. match action { - A::Init { .. } => panic!("Unexpected Action::Init: has to be the first action only"), - A::CreateSwapChain { .. } | A::PresentSwapChain(_) => { + Action::Init { .. } => { + panic!("Unexpected Action::Init: has to be the first action only") + } + Action::CreateSwapChain { .. } | Action::PresentSwapChain(_) => { panic!("Unexpected SwapChain action: winit feature is not enabled") } - A::CreateBuffer(id, desc) => { + Action::CreateBuffer(id, desc) => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_buffer::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::FreeBuffer(id) => { + Action::FreeBuffer(id) => { self.buffer_destroy::(id).unwrap(); } - A::DestroyBuffer(id) => { + Action::DestroyBuffer(id) => { self.buffer_drop::(id, true); } - A::CreateTexture(id, desc) => { + Action::CreateTexture(id, desc) => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_texture::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::FreeTexture(id) => { + Action::FreeTexture(id) => { self.texture_destroy::(id).unwrap(); } - A::DestroyTexture(id) => { + Action::DestroyTexture(id) => { self.texture_drop::(id, true); } - A::CreateTextureView { + Action::CreateTextureView { id, parent_id, desc, @@ -191,56 +193,56 @@ impl GlobalPlay for wgc::hub::Global { panic!("{:?}", e); } } - A::DestroyTextureView(id) => { + Action::DestroyTextureView(id) => { self.texture_view_drop::(id, true).unwrap(); } - A::CreateSampler(id, desc) => { + Action::CreateSampler(id, desc) => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_sampler::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::DestroySampler(id) => { + Action::DestroySampler(id) => { self.sampler_drop::(id); } - A::GetSwapChainTexture { id, parent_id } => { + Action::GetSwapChainTexture { id, parent_id } => { self.device_maintain_ids::(device).unwrap(); self.swap_chain_get_current_texture_view::(parent_id, id) .unwrap() .view_id .unwrap(); } - A::CreateBindGroupLayout(id, desc) => { + Action::CreateBindGroupLayout(id, desc) => { let (_, error) = self.device_create_bind_group_layout::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::DestroyBindGroupLayout(id) => { + Action::DestroyBindGroupLayout(id) => { self.bind_group_layout_drop::(id); } - A::CreatePipelineLayout(id, desc) => { + Action::CreatePipelineLayout(id, desc) => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_pipeline_layout::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::DestroyPipelineLayout(id) => { + Action::DestroyPipelineLayout(id) => { self.pipeline_layout_drop::(id); } - A::CreateBindGroup(id, desc) => { + Action::CreateBindGroup(id, desc) => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_bind_group::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::DestroyBindGroup(id) => { + Action::DestroyBindGroup(id) => { self.bind_group_drop::(id); } - A::CreateShaderModule { id, desc, data } => { + Action::CreateShaderModule { id, desc, data } => { let source = if data.ends_with(".wgsl") { let code = fs::read_to_string(dir.join(data)).unwrap(); wgc::pipeline::ShaderModuleSource::Wgsl(Cow::Owned(code)) @@ -258,10 +260,10 @@ impl GlobalPlay for wgc::hub::Global { panic!("{:?}", e); } } - A::DestroyShaderModule(id) => { + Action::DestroyShaderModule(id) => { self.shader_module_drop::(id); } - A::CreateComputePipeline { + Action::CreateComputePipeline { id, desc, implicit_context, @@ -280,10 +282,10 @@ impl GlobalPlay for wgc::hub::Global { panic!("{:?}", e); } } - A::DestroyComputePipeline(id) => { + Action::DestroyComputePipeline(id) => { self.compute_pipeline_drop::(id); } - A::CreateRenderPipeline { + Action::CreateRenderPipeline { id, desc, implicit_context, @@ -302,10 +304,10 @@ impl GlobalPlay for wgc::hub::Global { panic!("{:?}", e); } } - A::DestroyRenderPipeline(id) => { + Action::DestroyRenderPipeline(id) => { self.render_pipeline_drop::(id); } - A::CreateRenderBundle { id, desc, base } => { + Action::CreateRenderBundle { id, desc, base } => { let bundle = wgc::command::RenderBundleEncoder::new(&desc, device, Some(base)).unwrap(); let (_, error) = self.render_bundle_encoder_finish::( @@ -317,20 +319,20 @@ impl GlobalPlay for wgc::hub::Global { panic!("{:?}", e); } } - A::DestroyRenderBundle(id) => { + Action::DestroyRenderBundle(id) => { self.render_bundle_drop::(id); } - A::CreateQuerySet { id, desc } => { + Action::CreateQuerySet { id, desc } => { self.device_maintain_ids::(device).unwrap(); let (_, error) = self.device_create_query_set::(device, &desc, id); if let Some(e) = error { panic!("{:?}", e); } } - A::DestroyQuerySet(id) => { + Action::DestroyQuerySet(id) => { self.query_set_drop::(id); } - A::WriteBuffer { + Action::WriteBuffer { id, data, range, @@ -347,7 +349,7 @@ impl GlobalPlay for wgc::hub::Global { .unwrap(); } } - A::WriteTexture { + Action::WriteTexture { to, data, layout, @@ -357,10 +359,10 @@ impl GlobalPlay for wgc::hub::Global { self.queue_write_texture::(device, &to, &bin, &layout, &size) .unwrap(); } - A::Submit(_index, ref commands) if commands.is_empty() => { + Action::Submit(_index, ref commands) if commands.is_empty() => { self.queue_submit::(device, &[]).unwrap(); } - A::Submit(_index, commands) => { + Action::Submit(_index, commands) => { let (encoder, error) = self.device_create_command_encoder::( device, &wgt::CommandEncoderDescriptor { label: None }, diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 6a9bd1478..257881d65 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -49,6 +49,10 @@ path = "../wgpu-hal" package = "wgpu-hal" version = "0.1" +[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies] +hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["metal"] } +#Note: could also enable "vulkan" for Vulkan Portability + [dev-dependencies] loom = "0.3" diff --git a/wgpu-core/build.rs b/wgpu-core/build.rs index 786064d70..feea506b3 100644 --- a/wgpu-core/build.rs +++ b/wgpu-core/build.rs @@ -11,10 +11,10 @@ fn main() { unix_wo_apple: {all(unix, not(apple))}, // Backends - vulkan: { all(not(wasm), any(windows, unix_wo_apple)) }, + vulkan: { all(false, not(wasm), any(windows, unix_wo_apple)) }, metal: { all(not(wasm), apple) }, - dx12: { all(not(wasm), windows) }, - dx11: { all(not(wasm), windows) }, - gl: { any(wasm, unix_wo_apple) }, + dx12: { all(false, not(wasm), windows) }, + dx11: { all(false, not(wasm), windows) }, + gl: { all(false, any(wasm, unix_wo_apple)) }, } } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e509b7c2b..a0587a0b3 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -4103,27 +4103,24 @@ impl Global { } pub fn poll_all_devices(&self, force_wait: bool) -> Result<(), WaitIdleError> { - //use crate::backend; let mut callbacks = Vec::new(); - /* #[cfg(vulkan)] { - self.poll_devices::(force_wait, &mut callbacks)?; + self.poll_devices::(force_wait, &mut callbacks)?; } #[cfg(metal)] { - self.poll_devices::(force_wait, &mut callbacks)?; + self.poll_devices::(force_wait, &mut callbacks)?; } #[cfg(dx12)] { - self.poll_devices::(force_wait, &mut callbacks)?; + self.poll_devices::(force_wait, &mut callbacks)?; } #[cfg(dx11)] { - self.poll_devices::(force_wait, &mut callbacks)?; + self.poll_devices::(force_wait, &mut callbacks)?; } - */ fire_map_callbacks(callbacks); diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 970aa2441..aa259cb7f 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -718,26 +718,22 @@ impl Hub { } } -#[derive(Debug)] pub struct Hubs { - /* #[cfg(vulkan)] vulkan: Hub, #[cfg(metal)] - metal: Hub, + metal: Hub, #[cfg(dx12)] dx12: Hub, #[cfg(dx11)] dx11: Hub, #[cfg(gl)] - gl: Hub,*/ - marker: PhantomData, + gl: Hub, } impl Hubs { fn new(factory: &F) -> Self { Self { - /* #[cfg(vulkan)] vulkan: Hub::new(factory), #[cfg(metal)] @@ -748,13 +744,10 @@ impl Hubs { dx11: Hub::new(factory), #[cfg(gl)] gl: Hub::new(factory), - */ - marker: PhantomData, } } } -#[derive(Debug)] pub struct Global { pub instance: Instance, pub surfaces: Registry, @@ -765,7 +758,7 @@ impl Global { pub fn new(name: &str, factory: G, backends: wgt::BackendBit) -> Self { profiling::scope!("new", "Global"); Self { - instance: Instance::new(name, 1, backends), + instance: Instance::new(name, backends), surfaces: Registry::without_backend(&factory, "Surface"), hubs: Hubs::new(&factory), } @@ -786,7 +779,6 @@ impl Drop for Global { let mut surface_guard = self.surfaces.data.write(); // destroy hubs before the instance gets dropped - /* #[cfg(vulkan)] { self.hubs.vulkan.clear(&mut *surface_guard, true); @@ -807,7 +799,6 @@ impl Drop for Global { { self.hubs.gl.clear(&mut *surface_guard, true); } - */ // destroy surfaces for element in surface_guard.map.drain(..) { @@ -834,10 +825,10 @@ impl HalApi for backend::Vulkan { fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface { surface.vulkan.as_mut().unwrap() } -} +}*/ #[cfg(metal)] -impl HalApi for backend::Metal { +impl HalApi for hal::api::Metal { const VARIANT: Backend = Backend::Metal; fn hub(global: &Global) -> &Hub { &global.hubs.metal @@ -847,6 +838,7 @@ impl HalApi for backend::Metal { } } +/* #[cfg(dx12)] impl HalApi for backend::Dx12 { const VARIANT: Backend = Backend::Dx12; diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 9578a77b5..b9d549775 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -8,7 +8,7 @@ use wgt::Backend; const BACKEND_BITS: usize = 3; const EPOCH_MASK: u32 = (1 << (32 - BACKEND_BITS)) - 1; -type Dummy = crate::backend::Empty; +type Dummy = hal::api::Empty; #[repr(transparent)] #[cfg_attr(feature = "trace", derive(serde::Serialize), serde(into = "SerialId"))] diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index e127018f1..705565191 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -11,50 +11,49 @@ use crate::{ use wgt::{Backend, BackendBit, PowerPreference, BIND_BUFFER_ALIGNMENT}; -use hal::Adapter as _; +use hal::{Adapter as _, Instance as _}; use thiserror::Error; pub type RequestAdapterOptions = wgt::RequestAdapterOptions; +type HalInstance = ::Instance; +type HalSurface = ::Surface; -#[derive(Debug)] pub struct Instance { - /* -#[cfg(vulkan)] -pub vulkan: Option, -#[cfg(metal)] -pub metal: Option, -#[cfg(dx12)] -pub dx12: Option, -#[cfg(dx11)] -pub dx11: Option, -#[cfg(gl)] -pub gl: Option, -*/} + #[allow(dead_code)] + name: String, + #[cfg(vulkan)] + pub vulkan: Option, + #[cfg(metal)] + pub metal: Option>, + #[cfg(dx12)] + pub dx12: Option, + #[cfg(dx11)] + pub dx11: Option, + #[cfg(gl)] + pub gl: Option, +} impl Instance { - pub fn new(name: &str, version: u32, backends: BackendBit) -> Self { - backends_map! { - let map = |(backend, backend_create)| { - if backends.contains(backend.into()) { - backend_create(name, version).ok() - } else { - None - } - }; - Self { - /* - #[cfg(vulkan)] - vulkan: map((Backend::Vulkan, gfx_backend_vulkan::Instance::create)), - #[cfg(metal)] - metal: map((Backend::Metal, gfx_backend_metal::Instance::create)), - #[cfg(dx12)] - dx12: map((Backend::Dx12, gfx_backend_dx12::Instance::create)), - #[cfg(dx11)] - dx11: map((Backend::Dx11, gfx_backend_dx11::Instance::create)), - #[cfg(gl)] - gl: map((Backend::Gl, gfx_backend_gl::Instance::create)), - */ + pub fn new(name: &str, backends: BackendBit) -> Self { + let map = |backend: Backend| unsafe { + if backends.contains(backend.into()) { + hal::Instance::init().ok() + } else { + None } + }; + Self { + name: name.to_string(), + #[cfg(vulkan)] + vulkan: map((Backend::Vulkan)), + #[cfg(metal)] + metal: map(Backend::Metal), + #[cfg(dx12)] + dx12: map((Backend::Dx12)), + #[cfg(dx11)] + dx11: map((Backend::Dx11)), + #[cfg(gl)] + gl: map((Backend::Gl)), } } @@ -68,7 +67,6 @@ impl Instance { } }; - /* #[cfg(vulkan)] map((surface.vulkan, &self.vulkan)), #[cfg(metal)] @@ -79,27 +77,22 @@ impl Instance { map((surface.dx11, &self.dx11)), #[cfg(gl)] map((surface.gl, &self.gl)), - */ } } } -type HalSurface = ::Surface; - -#[derive(Debug)] pub struct Surface { - /* -#[cfg(vulkan)] -pub vulkan: Option>, -#[cfg(metal)] -pub metal: Option>, -#[cfg(dx12)] -pub dx12: Option>, -#[cfg(dx11)] -pub dx11: Option>, -#[cfg(gl)] -pub gl: Option>, -*/} + #[cfg(vulkan)] + pub vulkan: Option>, + #[cfg(metal)] + pub metal: Option>, + #[cfg(dx12)] + pub dx12: Option>, + #[cfg(dx11)] + pub dx11: Option>, + #[cfg(gl)] + pub gl: Option>, +} impl crate::hub::Resource for Surface { const TYPE: &'static str = "Surface"; @@ -352,7 +345,6 @@ impl Global { }; Surface { - /* #[cfg(vulkan)] vulkan: map(&self.instance.vulkan), #[cfg(metal)] @@ -363,7 +355,6 @@ impl Global { dx11: map(&self.instance.dx11), #[cfg(gl)] gl: map(&self.instance.gl), - */ } } }; @@ -373,6 +364,7 @@ impl Global { id.0 } + /*TODO: raw CALayer handling #[cfg(metal)] pub fn instance_create_surface_metal( &self, @@ -382,18 +374,17 @@ impl Global { profiling::scope!("create_surface_metal", "Instance"); let surface = Surface { - /* metal: self.instance.metal.as_ref().map(|inst| { // we don't want to link to metal-rs for this #[allow(clippy::transmute_ptr_to_ref)] inst.create_surface_from_layer(unsafe { std::mem::transmute(layer) }) - }),*/ + }), }; let mut token = Token::root(); let id = self.surfaces.prepare(id_in).assign(surface, &mut token); id.0 - } + }*/ pub fn surface_drop(&self, id: SurfaceId) { profiling::scope!("drop", "Surface"); @@ -410,11 +401,11 @@ impl Global { let mut adapters = Vec::new(); backends_map! { - let map = |(instance_field, backend, backend_info, backend_hub)| { + let map = |(instance_field, backend, backend_info)| { if let Some(ref inst) = *instance_field { - let hub = backend_hub(self); + let hub = HalApi::hub(self); if let Some(id_backend) = inputs.find(backend) { - for raw in inst.enumerate_adapters() { + for raw in unsafe {inst.enumerate_adapters()} { let adapter = Adapter::new(raw); log::info!("Adapter {} {:?}", backend_info, adapter.raw.info); let id = hub.adapters @@ -426,18 +417,16 @@ impl Global { } }; - /* #[cfg(vulkan)] - map((&instance.vulkan, Backend::Vulkan, "Vulkan", backend::Vulkan::hub)), + map((&instance.vulkan, Backend::Vulkan, "Vulkan")), #[cfg(metal)] - map((&instance.metal, Backend::Metal, "Metal", backend::Metal::hub)), + map((&instance.metal, Backend::Metal, "Metal")), #[cfg(dx12)] - map((&instance.dx12, Backend::Dx12, "Dx12", backend::Dx12::hub)), + map((&instance.dx12, Backend::Dx12, "Dx12")), #[cfg(dx11)] - map((&instance.dx11, Backend::Dx11, "Dx11", backend::Dx11::hub)), + map((&instance.dx11, Backend::Dx11, "Dx11")), #[cfg(gl)] - map((&instance.gl, Backend::Gl, "GL", backend::Gl::hub)), - */ + map((&instance.gl, Backend::Gl, "GL")), } adapters @@ -473,13 +462,10 @@ impl Global { let map = |(instance_backend, id_backend, surface_backend)| { match *instance_backend { Some(ref inst) if id_backend.is_some() => { - let mut adapters = inst.enumerate_adapters(); + let mut adapters = unsafe { inst.enumerate_adapters() }; if let Some(surface_backend) = compatible_surface.and_then(surface_backend) { - adapters.retain(|a| { - a.queue_families - .iter() - .find(|qf| qf.queue_type().supports_graphics()) - .map_or(false, |qf| surface_backend.supports_queue_family(qf)) + adapters.retain(|exposed| unsafe { + exposed.adapter.surface_capabilities(surface_backend).is_some() }); } device_types.extend(adapters.iter().map(|ad| ad.info.device_type)); @@ -491,7 +477,6 @@ impl Global { // NB: The internal function definitions are a workaround for Rust // being weird with lifetimes for closure literals... - /* #[cfg(vulkan)] let adapters_vk = map((&instance.vulkan, &id_vulkan, { fn surface_vulkan(surf: &Surface) -> Option<&HalSurface> { @@ -501,7 +486,7 @@ impl Global { })); #[cfg(metal)] let adapters_mtl = map((&instance.metal, &id_metal, { - fn surface_metal(surf: &Surface) -> Option<&HalSurface> { + fn surface_metal(surf: &Surface) -> Option<&HalSurface> { surf.metal.as_ref() } surface_metal @@ -526,7 +511,7 @@ impl Global { surf.gl.as_ref() } surface_gl - }));*/ + })); } if device_types.is_empty() { @@ -564,11 +549,11 @@ impl Global { let mut selected = preferred_gpu.unwrap_or(0); backends_map! { - let map = |(info_adapter, id_backend, mut adapters_backend, backend_hub)| { + let map = |(info_adapter, id_backend, mut adapters_backend)| { if selected < adapters_backend.len() { let adapter = Adapter::new(adapters_backend.swap_remove(selected)); log::info!("Adapter {} {:?}", info_adapter, adapter.raw.info); - let id = backend_hub(self).adapters + let id = HalApi::hub(self).adapters .prepare(id_backend.take().unwrap()) .assign(adapter, &mut token); return Ok(id.0); @@ -576,18 +561,16 @@ impl Global { selected -= adapters_backend.len(); }; - /* #[cfg(vulkan)] - map(("Vulkan", &mut id_vulkan, adapters_vk, backend::Vulkan::hub)), + map(("Vulkan", &mut id_vulkan, adapters_vk)), #[cfg(metal)] - map(("Metal", &mut id_metal, adapters_mtl, backend::Metal::hub)), + map(("Metal", &mut id_metal, adapters_mtl)), #[cfg(dx12)] - map(("Dx12", &mut id_dx12, adapters_dx12, backend::Dx12::hub)), + map(("Dx12", &mut id_dx12, adapters_dx12)), #[cfg(dx11)] - map(("Dx11", &mut id_dx11, adapters_dx11, backend::Dx11::hub)), + map(("Dx11", &mut id_dx11, adapters_dx11)), #[cfg(gl)] - map(("GL", &mut id_gl, adapters_gl, backend::Gl::hub)), - */ + map(("GL", &mut id_gl, adapters_gl)), } let _ = ( diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 0af3c812a..a4c34fb8f 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -31,22 +31,6 @@ #[macro_use] mod macros; -pub mod backend { - pub use hal::empty::Api as Empty; - /* - #[cfg(dx11)] - pub use gfx_backend_dx11::Backend as Dx11; - #[cfg(dx12)] - pub use gfx_backend_dx12::Backend as Dx12; - #[cfg(gl)] - pub use gfx_backend_gl::Backend as Gl; - #[cfg(metal)] - pub use gfx_backend_metal::Backend as Metal; - #[cfg(vulkan)] - pub use gfx_backend_vulkan::Backend as Vulkan; - */ -} - pub mod binding_model; pub mod command; mod conv; @@ -61,6 +45,8 @@ pub mod swap_chain; mod track; mod validation; +pub use hal::api; + #[cfg(test)] use loom::sync::atomic; #[cfg(not(test))] @@ -257,11 +243,11 @@ macro_rules! gfx_select { // Note: For some reason the cfg aliases defined in build.rs don't succesfully apply in this // macro so we must specify their equivalents manually match $id.backend() { - /* - #[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))] - wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ), + //#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))] + //wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ), #[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))] - wgt::Backend::Metal => $global.$method::<$crate::backend::Metal>( $($param),* ), + wgt::Backend::Metal => $global.$method::<$crate::api::Metal>( $($param),* ), + /* #[cfg(all(not(target_arch = "wasm32"), windows))] wgt::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),* ), #[cfg(all(not(target_arch = "wasm32"), windows))] diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index d605a9d87..de1d7ab70 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -7,11 +7,12 @@ description = "WebGPU hardware abstraction layer" homepage = "https://github.com/gfx-rs/wgpu" repository = "https://github.com/gfx-rs/wgpu" keywords = ["graphics"] -license = "MPL-2.0" +license = "MIT OR Apache-2.0" [lib] [features] +metal = ["mtl"] [dependencies] bitflags = "1.0" @@ -20,6 +21,9 @@ smallvec = "1" thiserror = "1" wgt = { package = "wgpu-types", path = "../wgpu-types" } +# backends +mtl = { package = "metal", version = "0.22", optional = true } + [dependencies.naga] git = "https://github.com/gfx-rs/naga" tag = "gfx-25" diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index bbb44fde9..f2497d3c6 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -37,12 +37,16 @@ impl crate::Api for Api { } impl crate::Instance for Context { + unsafe fn init() -> Result { + Ok(Context) + } unsafe fn create_surface( &self, rwh: &impl raw_window_handle::HasRawWindowHandle, - ) -> Result { + ) -> Result { Ok(Context) } + unsafe fn destroy_surface(&self, surface: Context) {} unsafe fn enumerate_adapters(&self) -> Vec> { Vec::new() } diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 58d145cc3..2e1a31ebd 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -37,6 +37,14 @@ )] pub mod empty; +#[cfg(feature = "metal")] +mod metal; + +pub mod api { + pub use super::empty::Api as Empty; + #[cfg(feature = "metal")] + pub use super::metal::Api as Metal; +} use std::{ borrow::{Borrow, Cow}, @@ -97,8 +105,8 @@ pub enum SurfaceError { } #[derive(Clone, Debug, PartialEq, Error)] -#[error("Window handle is not supported")] -pub struct UnsupportedWindow; +#[error("Not supported")] +pub struct InstanceError; pub trait Api: Clone + Sized { type Instance: Instance; @@ -124,11 +132,13 @@ pub trait Api: Clone + Sized { type ComputePipeline; } -pub trait Instance { +pub trait Instance: Sized { + unsafe fn init() -> Result; unsafe fn create_surface( &self, rwh: &impl raw_window_handle::HasRawWindowHandle, - ) -> Result; + ) -> Result; + unsafe fn destroy_surface(&self, surface: A::Surface); unsafe fn enumerate_adapters(&self) -> Vec>; } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs new file mode 100644 index 000000000..f2497d3c6 --- /dev/null +++ b/wgpu-hal/src/metal/mod.rs @@ -0,0 +1,379 @@ +#![allow(unused_variables)] + +use std::ops::Range; + +#[derive(Clone)] +pub struct Api; +pub struct Context; +pub struct Encoder; +#[derive(Debug)] +pub struct Resource; + +type DeviceResult = Result; + +impl crate::Api for Api { + type Instance = Context; + type Surface = Context; + type Adapter = Context; + type Queue = Context; + type Device = Context; + + type CommandBuffer = Encoder; + + type Buffer = Resource; + type Texture = Resource; + type SurfaceTexture = Resource; + type TextureView = Resource; + type Sampler = Resource; + type QuerySet = Resource; + type Fence = Resource; + + type BindGroupLayout = Resource; + type BindGroup = Resource; + type PipelineLayout = Resource; + type ShaderModule = Resource; + type RenderPipeline = Resource; + type ComputePipeline = Resource; +} + +impl crate::Instance for Context { + unsafe fn init() -> Result { + Ok(Context) + } + unsafe fn create_surface( + &self, + rwh: &impl raw_window_handle::HasRawWindowHandle, + ) -> Result { + Ok(Context) + } + unsafe fn destroy_surface(&self, surface: Context) {} + unsafe fn enumerate_adapters(&self) -> Vec> { + Vec::new() + } +} + +impl crate::Surface for Context { + unsafe fn configure( + &mut self, + device: &Context, + config: &crate::SurfaceConfiguration, + ) -> Result<(), crate::SurfaceError> { + Ok(()) + } + + unsafe fn unconfigure(&mut self, device: &Context) {} + + unsafe fn acquire_texture( + &mut self, + timeout_ms: u32, + ) -> Result>, crate::SurfaceError> { + Ok(None) + } + unsafe fn discard_texture(&mut self, texture: Resource) {} +} + +impl crate::Adapter for Context { + unsafe fn open(&self, features: wgt::Features) -> DeviceResult> { + Err(crate::DeviceError::Lost) + } + unsafe fn close(&self, device: Context) {} + unsafe fn texture_format_capabilities( + &self, + format: wgt::TextureFormat, + ) -> crate::TextureFormatCapability { + crate::TextureFormatCapability::empty() + } + unsafe fn surface_capabilities(&self, surface: &Context) -> Option { + None + } +} + +impl crate::Queue for Context { + unsafe fn submit( + &mut self, + command_buffers: I, + signal_fence: Option<(&Resource, crate::FenceValue)>, + ) { + } + unsafe fn present( + &mut self, + surface: &mut Context, + texture: Resource, + ) -> Result<(), crate::SurfaceError> { + Ok(()) + } +} + +impl crate::Device for Context { + unsafe fn create_buffer(&self, desc: &crate::BufferDescriptor) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_buffer(&self, buffer: Resource) {} + unsafe fn map_buffer( + &self, + buffer: &Resource, + range: crate::MemoryRange, + ) -> DeviceResult> { + Err(crate::DeviceError::Lost) + } + unsafe fn unmap_buffer(&self, buffer: &Resource) -> DeviceResult<()> { + Ok(()) + } + unsafe fn flush_mapped_ranges(&self, buffer: &Resource, ranges: I) {} + unsafe fn invalidate_mapped_ranges(&self, buffer: &Resource, ranges: I) {} + + unsafe fn create_texture(&self, desc: &crate::TextureDescriptor) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_texture(&self, texture: Resource) {} + unsafe fn create_texture_view( + &self, + texture: &Resource, + desc: &crate::TextureViewDescriptor, + ) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_texture_view(&self, view: Resource) {} + unsafe fn create_sampler(&self, desc: &crate::SamplerDescriptor) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_sampler(&self, sampler: Resource) {} + + unsafe fn create_command_buffer( + &self, + desc: &crate::CommandBufferDescriptor, + ) -> DeviceResult { + Ok(Encoder) + } + unsafe fn destroy_command_buffer(&self, cmd_buf: Encoder) {} + + unsafe fn create_bind_group_layout( + &self, + desc: &crate::BindGroupLayoutDescriptor, + ) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_bind_group_layout(&self, bg_layout: Resource) {} + unsafe fn create_pipeline_layout( + &self, + desc: &crate::PipelineLayoutDescriptor, + ) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_pipeline_layout(&self, pipeline_layout: Resource) {} + unsafe fn create_bind_group( + &self, + desc: &crate::BindGroupDescriptor, + ) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_bind_group(&self, group: Resource) {} + + unsafe fn create_shader_module( + &self, + desc: &crate::ShaderModuleDescriptor, + shader: crate::NagaShader, + ) -> Result { + Ok(Resource) + } + unsafe fn destroy_shader_module(&self, module: Resource) {} + unsafe fn create_render_pipeline( + &self, + desc: &crate::RenderPipelineDescriptor, + ) -> Result { + Ok(Resource) + } + unsafe fn destroy_render_pipeline(&self, pipeline: Resource) {} + unsafe fn create_compute_pipeline( + &self, + desc: &crate::ComputePipelineDescriptor, + ) -> Result { + Ok(Resource) + } + unsafe fn destroy_compute_pipeline(&self, pipeline: Resource) {} + + unsafe fn create_query_set(&self, desc: &wgt::QuerySetDescriptor) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_query_set(&self, set: Resource) {} + unsafe fn create_fence(&self) -> DeviceResult { + Ok(Resource) + } + unsafe fn destroy_fence(&self, fence: Resource) {} + unsafe fn get_fence_value(&self, fence: &Resource) -> DeviceResult { + Ok(0) + } + unsafe fn wait( + &self, + fence: &Resource, + value: crate::FenceValue, + timeout_ms: u32, + ) -> DeviceResult { + Ok(true) + } + + unsafe fn start_capture(&self) -> bool { + false + } + unsafe fn stop_capture(&self) {} +} + +impl crate::CommandBuffer for Encoder { + unsafe fn finish(&mut self) {} + + unsafe fn transition_buffers<'a, T>(&mut self, barriers: T) + where + T: Iterator>, + { + } + + unsafe fn transition_textures<'a, T>(&mut self, barriers: T) + where + T: Iterator>, + { + } + + unsafe fn fill_buffer(&mut self, buffer: &Resource, range: crate::MemoryRange, value: u8) {} + + unsafe fn copy_buffer_to_buffer(&mut self, src: &Resource, dst: &Resource, regions: T) + where + T: Iterator, + { + } + + /// Note: `dst` current usage has to be `TextureUse::COPY_DST`. + unsafe fn copy_texture_to_texture( + &mut self, + src: &Resource, + src_usage: crate::TextureUse, + dst: &Resource, + regions: T, + ) { + } + + /// Note: `dst` current usage has to be `TextureUse::COPY_DST`. + unsafe fn copy_buffer_to_texture(&mut self, src: &Resource, dst: &Resource, regions: T) {} + + unsafe fn copy_texture_to_buffer( + &mut self, + src: &Resource, + src_usage: crate::TextureUse, + dst: &Resource, + regions: T, + ) { + } + + unsafe fn begin_query(&mut self, set: &Resource, index: u32) {} + unsafe fn end_query(&mut self, set: &Resource, index: u32) {} + unsafe fn write_timestamp(&mut self, set: &Resource, index: u32) {} + unsafe fn reset_queries(&mut self, set: &Resource, range: Range) {} + unsafe fn copy_query_results( + &mut self, + set: &Resource, + range: Range, + buffer: &Resource, + offset: wgt::BufferAddress, + ) { + } + + // render + + unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor) {} + unsafe fn end_render_pass(&mut self) {} + + unsafe fn set_bind_group( + &mut self, + layout: &Resource, + index: u32, + group: &Resource, + dynamic_offsets: &[u32], + ) { + } + unsafe fn set_push_constants( + &mut self, + layout: &Resource, + stages: wgt::ShaderStage, + offset: u32, + data: &[u32], + ) { + } + + unsafe fn insert_debug_marker(&mut self, label: &str) {} + unsafe fn begin_debug_marker(&mut self, group_label: &str) {} + unsafe fn end_debug_marker(&mut self) {} + + unsafe fn set_render_pipeline(&mut self, pipeline: &Resource) {} + + unsafe fn set_index_buffer<'a>( + &mut self, + binding: crate::BufferBinding<'a, Api>, + format: wgt::IndexFormat, + ) { + } + unsafe fn set_vertex_buffer<'a>(&mut self, index: u32, binding: crate::BufferBinding<'a, Api>) { + } + unsafe fn set_viewport(&mut self, rect: &crate::Rect, depth_range: Range) {} + unsafe fn set_scissor_rect(&mut self, rect: &crate::Rect) {} + unsafe fn set_stencil_reference(&mut self, value: u32) {} + unsafe fn set_blend_constants(&mut self, color: &wgt::Color) {} + + unsafe fn draw( + &mut self, + start_vertex: u32, + vertex_count: u32, + start_instance: u32, + instance_count: u32, + ) { + } + unsafe fn draw_indexed( + &mut self, + start_index: u32, + index_count: u32, + base_vertex: i32, + start_instance: u32, + instance_count: u32, + ) { + } + unsafe fn draw_indirect( + &mut self, + buffer: &Resource, + offset: wgt::BufferAddress, + draw_count: u32, + ) { + } + unsafe fn draw_indexed_indirect( + &mut self, + buffer: &Resource, + offset: wgt::BufferAddress, + draw_count: u32, + ) { + } + unsafe fn draw_indirect_count( + &mut self, + buffer: &Resource, + offset: wgt::BufferAddress, + count_buffer: &Resource, + count_offset: wgt::BufferAddress, + max_count: u32, + ) { + } + unsafe fn draw_indexed_indirect_count( + &mut self, + buffer: &Resource, + offset: wgt::BufferAddress, + count_buffer: &Resource, + count_offset: wgt::BufferAddress, + max_count: u32, + ) { + } + + // compute + + unsafe fn begin_compute_pass(&mut self) {} + unsafe fn end_compute_pass(&mut self) {} + + unsafe fn set_compute_pipeline(&mut self, pipeline: &Resource) {} + + unsafe fn dispatch(&mut self, count: [u32; 3]) {} + unsafe fn dispatch_indirect(&mut self, buffer: &Resource, offset: wgt::BufferAddress) {} +} diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ab49527de..1c46125eb 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -36,6 +36,10 @@ optional = true package = "wgpu-types" path = "../wgpu-types" +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.hal] +package = "wgpu-hal" +path = "../wgpu-hal" + [dependencies] arrayvec = "0.5" log = "0.4" diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 03a956d15..89036a4f1 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -50,6 +50,7 @@ impl Context { })) } + /*TODO: raw surface #[cfg(any(target_os = "ios", target_os = "macos"))] pub unsafe fn create_surface_from_core_animation_layer( self: &Arc, @@ -60,7 +61,7 @@ impl Context { context: Arc::clone(self), id, } - } + }*/ fn handle_error( &self, @@ -540,6 +541,7 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCo texture: view.texture.id.id, mip_level: view.mip_level, origin: view.origin, + aspect: view.aspect, } } @@ -806,7 +808,6 @@ impl crate::Context for Context { let global = &self.0; let descriptor = wgc::pipeline::ShaderModuleDescriptor { label: desc.label.map(Borrowed), - flags: desc.flags, }; let source = match desc.source { ShaderSource::SpirV(ref spv) => wgc::pipeline::ShaderModuleSource::SpirV(Borrowed(spv)), @@ -951,20 +952,20 @@ impl crate::Context for Context { device: &Self::DeviceId, desc: &PipelineLayoutDescriptor, ) -> Self::PipelineLayoutId { - // Limit is always less or equal to wgc::MAX_BIND_GROUPS, so this is always right + // Limit is always less or equal to hal::MAX_BIND_GROUPS, so this is always right // Guards following ArrayVec assert!( - desc.bind_group_layouts.len() <= wgc::MAX_BIND_GROUPS, + desc.bind_group_layouts.len() <= hal::MAX_BIND_GROUPS, "Bind group layout count {} exceeds device bind group limit {}", desc.bind_group_layouts.len(), - wgc::MAX_BIND_GROUPS + hal::MAX_BIND_GROUPS ); let temp_layouts = desc .bind_group_layouts .iter() .map(|bgl| bgl.id) - .collect::>(); + .collect::>(); let descriptor = wgc::binding_model::PipelineLayoutDescriptor { label: desc.label.map(Borrowed), bind_group_layouts: Borrowed(&temp_layouts), @@ -996,7 +997,7 @@ impl crate::Context for Context { ) -> Self::RenderPipelineId { use wgc::pipeline as pipe; - let vertex_buffers: ArrayVec<[_; wgc::device::MAX_VERTEX_BUFFERS]> = desc + let vertex_buffers: ArrayVec<[_; hal::MAX_VERTEX_BUFFERS]> = desc .vertex .buffers .iter() @@ -1011,7 +1012,7 @@ impl crate::Context for Context { Some(_) => None, None => Some(wgc::device::ImplicitPipelineIds { root_id: PhantomData, - group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS], + group_ids: &[PhantomData; hal::MAX_BIND_GROUPS], }), }; let descriptor = pipe::RenderPipelineDescriptor { @@ -1071,7 +1072,7 @@ impl crate::Context for Context { Some(_) => None, None => Some(wgc::device::ImplicitPipelineIds { root_id: PhantomData, - group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS], + group_ids: &[PhantomData; hal::MAX_BIND_GROUPS], }), }; let descriptor = pipe::ComputePipelineDescriptor { @@ -1731,7 +1732,7 @@ impl crate::Context for Context { resolve_target: ca.resolve_target.map(|rt| rt.id), channel: map_pass_channel(Some(&ca.ops)), }) - .collect::>(); + .collect::>(); let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { wgc::command::RenderPassDepthStencilAttachment { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index d703cd6b7..978436c44 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -33,12 +33,12 @@ pub use wgt::{ ImageDataLayout, IndexFormat, InputStepMode, Limits, MultisampleState, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, PrimitiveTopology, PushConstantRange, QuerySetDescriptor, QueryType, SamplerBorderColor, - ShaderFlags, ShaderLocation, ShaderModel, ShaderStage, StencilFaceState, StencilOperation, - StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, - TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, - TextureSampleType, TextureUsage, TextureViewDimension, VertexAttribute, VertexFormat, - BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, - PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, + ShaderLocation, ShaderModel, ShaderStage, StencilFaceState, StencilOperation, StencilState, + StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDimension, + TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, + TextureUsage, TextureViewDimension, VertexAttribute, VertexFormat, BIND_BUFFER_ALIGNMENT, + COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, + QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; use backend::{BufferMappedRange, Context as C}; @@ -750,8 +750,6 @@ pub struct ShaderModuleDescriptor<'a> { pub label: Label<'a>, /// Source code for the shader. pub source: ShaderSource<'a>, - /// Shader handling flags. - pub flags: ShaderFlags, } /// Handle to a pipeline layout. @@ -1420,6 +1418,7 @@ impl Instance { } } + /*TODO: raw CAL surface /// Creates a surface from `CoreAnimationLayer`. /// /// # Safety @@ -1431,7 +1430,7 @@ impl Instance { layer: *mut std::ffi::c_void, ) -> Surface { self.context.create_surface_from_core_animation_layer(layer) - } + }*/ /// Polls all devices. /// If `force_wait` is true and this is not running on the web, diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index b18f1b1b8..73c8f4f0b 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -1,4 +1,4 @@ -use std::{convert::TryFrom, num::NonZeroU32}; +use std::num::NonZeroU32; /// Describes a [Buffer](crate::Buffer) when allocating. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -106,7 +106,7 @@ impl DeviceExt for crate::Device { let height_blocks = mip_physical.height / format_info.block_dimensions.1 as u32; let bytes_per_row = width_blocks * format_info.block_size as u32; - let data_size = bytes_per_row * height_blocks * mip_extent.depth_or_array_layers; + let data_size = bytes_per_row * height_blocks * mip_size.depth_or_array_layers; let end_offset = binary_offset + data_size as usize; @@ -119,6 +119,7 @@ impl DeviceExt for crate::Device { y: 0, z: layer, }, + aspect: wgt::TextureAspect::All, }, &data[binary_offset..end_offset], crate::ImageDataLayout {