From fdd50e10fd8c19d7fd5f65dead2be6d6f7ee926a Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 16 Feb 2021 09:46:22 -0500 Subject: [PATCH] Update naga to gfx-11 --- Cargo.lock | 49 +++++++++++++-------- dummy/Cargo.toml | 2 +- wgpu-core/Cargo.toml | 24 ++++++----- wgpu-core/src/device/mod.rs | 86 ++++++++++++++++++++----------------- 4 files changed, 90 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6040d797..1d34f5e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,7 +58,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c69a8137596e84c22d57f3da1b5de1d4230b1742a710091c85f4d7ce50f00f38" dependencies = [ - "libloading", + "libloading 0.6.5", ] [[package]] @@ -304,11 +304,10 @@ dependencies = [ [[package]] name = "d3d12" version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a60cceb22c7c53035f8980524fdc7f17cf49681a3c154e6757d30afbec6ec4" +source = "git+https://github.com/gfx-rs/d3d12-rs?rev=be19a243b86e0bafb9937d661fc8eabb3e42b44e#be19a243b86e0bafb9937d661fc8eabb3e42b44e" dependencies = [ "bitflags", - "libloading", + "libloading 0.7.0", "winapi 0.3.9", ] @@ -370,7 +369,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" dependencies = [ - "libloading", + "libloading 0.6.5", ] [[package]] @@ -476,7 +475,7 @@ dependencies = [ [[package]] name = "gfx-auxil" version = "0.8.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "fxhash", "gfx-hal", @@ -486,13 +485,13 @@ dependencies = [ [[package]] name = "gfx-backend-dx11" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "arrayvec", "bitflags", "gfx-auxil", "gfx-hal", - "libloading", + "libloading 0.7.0", "log", "parking_lot", "range-alloc", @@ -507,7 +506,7 @@ dependencies = [ [[package]] name = "gfx-backend-dx12" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "arrayvec", "bit-set", @@ -527,7 +526,7 @@ dependencies = [ [[package]] name = "gfx-backend-empty" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "gfx-hal", "log", @@ -537,16 +536,17 @@ dependencies = [ [[package]] name = "gfx-backend-gl" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "arrayvec", "bitflags", + "fxhash", "gfx-auxil", "gfx-hal", "glow", "js-sys", "khronos-egl", - "libloading", + "libloading 0.7.0", "log", "naga", "parking_lot", @@ -559,7 +559,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "arrayvec", "bitflags", @@ -567,6 +567,7 @@ dependencies = [ "cocoa-foundation", "copyless", "foreign-types", + "fxhash", "gfx-auxil", "gfx-hal", "log", @@ -583,7 +584,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "arrayvec", "ash", @@ -603,7 +604,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.7.0" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" dependencies = [ "bitflags", "naga", @@ -775,7 +776,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8020ff3b84f9ac87461216ad0501bc09b33c1cbe17404d8ea405160fd164bab" dependencies = [ "libc", - "libloading", + "libloading 0.6.5", ] [[package]] @@ -806,6 +807,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "libloading" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +dependencies = [ + "cfg-if 1.0.0", + "winapi 0.3.9", +] + [[package]] name = "lock_api" version = "0.4.1" @@ -935,7 +946,7 @@ dependencies = [ [[package]] name = "naga" version = "0.3.1" -source = "git+https://github.com/gfx-rs/naga?tag=gfx-10#4f19903f465b6970054b29b1750235e5e9b83ca5" +source = "git+https://github.com/gfx-rs/naga?tag=gfx-11#539db1a317d62c8c50e21ff908cf952c731a05b6" dependencies = [ "bit-set", "bitflags", @@ -1201,7 +1212,7 @@ dependencies = [ [[package]] name = "range-alloc" version = "0.1.2" -source = "git+https://github.com/gfx-rs/gfx?rev=f29dcc767cfeca8870061e82466b7431a0f57283#f29dcc767cfeca8870061e82466b7431a0f57283" +source = "git+https://github.com/gfx-rs/gfx?rev=80655862ac4afc5efb6675eb9ac7c38e73544750#80655862ac4afc5efb6675eb9ac7c38e73544750" [[package]] name = "raw-window-handle" @@ -1254,7 +1265,7 @@ checksum = "58fd0c55a54ecce0889aaca4ee87831cfe8c83c275c439443162be1f0eab5fdc" dependencies = [ "bitflags", "float-cmp", - "libloading", + "libloading 0.6.5", "once_cell", "renderdoc-sys", "winapi 0.3.9", diff --git a/dummy/Cargo.toml b/dummy/Cargo.toml index 37de0d18..2b268997 100644 --- a/dummy/Cargo.toml +++ b/dummy/Cargo.toml @@ -12,4 +12,4 @@ publish = false [dependencies.wgc] path = "../wgpu-core" package = "wgpu-core" -features = ["serial-pass", "trace"] +features = ["cross", "serial-pass", "trace"] diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index f88846a2..51159cc3 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -13,6 +13,8 @@ license = "MPL-2.0" [features] default = [] +# Enable SPIRV-Cross +cross = ["gfx-backend-metal/cross", "gfx-backend-gl/cross"] # Enable API tracing trace = ["ron", "serde", "wgt/trace", "naga/serialize"] # Enable API replaying @@ -36,28 +38,28 @@ thiserror = "1" gpu-alloc = { version = "0.3", features = ["tracing"] } gpu-descriptor = { version = "0.1", features = ["tracing"] } -hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283" } -gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283" } +hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } +gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } [target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies] -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", features = ["naga"] } -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", features = ["naga"] } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } [target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies] -gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", features = ["naga"] } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", optional = true } +gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750", optional = true } [target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies] -gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283" } -gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283" } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", features = ["naga"] } +gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } +gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750", features = ["naga"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "f29dcc767cfeca8870061e82466b7431a0f57283", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "80655862ac4afc5efb6675eb9ac7c38e73544750" } [dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-10" +tag = "gfx-11" features = ["spv-in", "spv-out", "wgsl-in"] [dependencies.wgt] diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 690d6944..cb8aefe2 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -13,8 +13,8 @@ use crate::{ pipeline, resource, span, swap_chain, track::{BufferState, TextureSelector, TextureState, TrackerSet}, validation::{self, check_buffer_usage, check_texture_usage}, - FastHashMap, FastHashSet, Label, LabelHelpers, LifeGuard, MultiRefCount, PrivateFeatures, - Stored, SubmissionIndex, MAX_BIND_GROUPS, + FastHashMap, Label, LabelHelpers, LifeGuard, MultiRefCount, PrivateFeatures, Stored, + SubmissionIndex, MAX_BIND_GROUPS, }; use arrayvec::ArrayVec; @@ -285,7 +285,7 @@ pub struct Device { pub(crate) private_features: PrivateFeatures, pub(crate) limits: wgt::Limits, pub(crate) features: wgt::Features, - spirv_capabilities: FastHashSet, + spv_options: naga::back::spv::Options, //TODO: move this behind another mutex. This would allow several methods to switch // to borrow Device immutably, such as `write_buffer`, `write_texture`, and `buffer_unmap`. pending_writes: queue::PendingWrites, @@ -310,8 +310,6 @@ impl Device { desc: &DeviceDescriptor, trace_path: Option<&std::path::Path>, ) -> Result { - use naga::back::spv::Capability as C; - let cmd_allocator = command::CommandAllocator::new(queue_group.family, &raw) .or(Err(CreateDeviceError::OutOfMemory))?; @@ -323,11 +321,26 @@ impl Device { None => (), } - let mut spirv_capabilities = FastHashSet::default(); - spirv_capabilities.insert(C::Shader); - spirv_capabilities.insert(C::Matrix); - spirv_capabilities.insert(C::Sampled1D); - spirv_capabilities.insert(C::Image1D); + let spv_options = { + use naga::back::spv; + let mut flags = spv::WriterFlags::empty(); + if cfg!(debug_assertions) { + flags |= spv::WriterFlags::DEBUG; + } + spv::Options { + lang_version: (1, 0), + capabilities: [ + spv::Capability::Shader, + spv::Capability::Matrix, + spv::Capability::Sampled1D, + spv::Capability::Image1D, + ] + .iter() + .cloned() + .collect(), + flags, + } + }; Ok(Self { raw, @@ -363,7 +376,7 @@ impl Device { private_features, limits: desc.limits.clone(), features: desc.features.clone(), - spirv_capabilities, + spv_options, pending_writes: queue::PendingWrites::new(), }) } @@ -995,41 +1008,39 @@ impl Device { let (naga_result, interface) = match module { // If succeeded, then validate it and attempt to give it to gfx-hal directly. - Some(module) => { - let interface = if desc.flags.contains(wgt::ShaderFlags::VALIDATION) { - naga::proc::Validator::new().validate(&module)?; - if !self.features.contains(wgt::Features::PUSH_CONSTANTS) - && module - .global_variables - .iter() - .any(|(_, var)| var.class == naga::StorageClass::PushConstant) - { - return Err(pipeline::CreateShaderModuleError::MissingFeature( - wgt::Features::PUSH_CONSTANTS, - )); - } - Some(validation::Interface::new(&module)) - } else { - None - }; + Some(module) if desc.flags.contains(wgt::ShaderFlags::VALIDATION) => { + let analysis = naga::proc::Validator::new().validate(&module)?; + if !self.features.contains(wgt::Features::PUSH_CONSTANTS) + && module + .global_variables + .iter() + .any(|(_, var)| var.class == naga::StorageClass::PushConstant) + { + return Err(pipeline::CreateShaderModuleError::MissingFeature( + wgt::Features::PUSH_CONSTANTS, + )); + } + let interface = validation::Interface::new(&module); let naga_result = if desc .flags .contains(wgt::ShaderFlags::EXPERIMENTAL_TRANSLATION) { - match unsafe { self.raw.create_shader_module_from_naga(module) } { + let shader = hal::device::NagaShader { module, analysis }; + match unsafe { self.raw.create_shader_module_from_naga(shader) } { Ok(raw) => Ok(raw), - Err((hal::device::ShaderError::CompilationFailed(msg), module)) => { + Err((hal::device::ShaderError::CompilationFailed(msg), shader)) => { tracing::warn!("Shader module compilation failed: {}", msg); - Err(Some(module)) + Err(Some(shader.module)) } - Err((_, module)) => Err(Some(module)), + Err((_, shader)) => Err(Some(shader.module)), } } else { Err(Some(module)) }; - (naga_result, interface) + (naga_result, Some(interface)) } - None => (Err(None), None), + Some(module) => (Err(Some(module)), None), + _ => (Err(None), None), }; // Otherwise, fall back to SPIR-V. @@ -1041,12 +1052,7 @@ impl Device { None => { // Produce a SPIR-V from the Naga module let module = maybe_module.unwrap(); - let mut flags = naga::back::spv::WriterFlags::empty(); - if cfg!(debug_assertions) { - flags |= naga::back::spv::WriterFlags::DEBUG; - } - naga::back::spv::write_vec(&module, flags, self.spirv_capabilities.clone()) - .map(Cow::Owned) + naga::back::spv::write_vec(&module, &self.spv_options).map(Cow::Owned) } }; match spv {