From c7a16b36b16be7484c2306d1155705f3f6241bf4 Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Sat, 18 May 2024 17:34:28 -0400 Subject: [PATCH] change `create_validator` to a free function so it's usable --- wgpu-core/src/device/mod.rs | 89 +++++++++++++++++++++ wgpu-core/src/device/resource.rs | 132 ++++--------------------------- 2 files changed, 104 insertions(+), 117 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 854ebfd76..a2f0bf31d 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -444,3 +444,92 @@ impl ImplicitPipelineIds<'_> { } } } + +/// Create a validator with the given validation flags. +pub fn create_validator( + features: wgt::Features, + downlevel: wgt::DownlevelFlags, + flags: naga::valid::ValidationFlags, +) -> naga::valid::Validator { + use naga::valid::Capabilities as Caps; + let mut caps = Caps::empty(); + caps.set( + Caps::PUSH_CONSTANT, + features.contains(wgt::Features::PUSH_CONSTANTS), + ); + caps.set(Caps::FLOAT64, features.contains(wgt::Features::SHADER_F64)); + caps.set( + Caps::PRIMITIVE_INDEX, + features.contains(wgt::Features::SHADER_PRIMITIVE_INDEX), + ); + caps.set( + Caps::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, + features + .contains(wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING), + ); + caps.set( + Caps::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, + features + .contains(wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING), + ); + // TODO: This needs a proper wgpu feature + caps.set( + Caps::SAMPLER_NON_UNIFORM_INDEXING, + features + .contains(wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING), + ); + caps.set( + Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS, + features.contains(wgt::Features::TEXTURE_FORMAT_16BIT_NORM), + ); + caps.set(Caps::MULTIVIEW, features.contains(wgt::Features::MULTIVIEW)); + caps.set( + Caps::EARLY_DEPTH_TEST, + features.contains(wgt::Features::SHADER_EARLY_DEPTH_TEST), + ); + caps.set( + Caps::SHADER_INT64, + features.contains(wgt::Features::SHADER_INT64), + ); + caps.set( + Caps::MULTISAMPLED_SHADING, + downlevel.contains(wgt::DownlevelFlags::MULTISAMPLED_SHADING), + ); + caps.set( + Caps::DUAL_SOURCE_BLENDING, + features.contains(wgt::Features::DUAL_SOURCE_BLENDING), + ); + caps.set( + Caps::CUBE_ARRAY_TEXTURES, + downlevel.contains(wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES), + ); + caps.set( + Caps::SUBGROUP, + features.intersects(wgt::Features::SUBGROUP | wgt::Features::SUBGROUP_VERTEX), + ); + caps.set( + Caps::SUBGROUP_BARRIER, + features.intersects(wgt::Features::SUBGROUP_BARRIER), + ); + + let mut subgroup_stages = naga::valid::ShaderStages::empty(); + subgroup_stages.set( + naga::valid::ShaderStages::COMPUTE | naga::valid::ShaderStages::FRAGMENT, + features.contains(wgt::Features::SUBGROUP), + ); + subgroup_stages.set( + naga::valid::ShaderStages::VERTEX, + features.contains(wgt::Features::SUBGROUP_VERTEX), + ); + + let subgroup_operations = if caps.contains(Caps::SUBGROUP) { + use naga::valid::SubgroupOperationSet as S; + S::BASIC | S::VOTE | S::ARITHMETIC | S::BALLOT | S::SHUFFLE | S::SHUFFLE_RELATIVE + } else { + naga::valid::SubgroupOperationSet::empty() + }; + let mut validator = naga::valid::Validator::new(flags, caps); + validator.subgroup_stages(subgroup_stages); + validator.subgroup_operations(subgroup_operations); + validator +} diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 3fdb66462..ba51507d1 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -4,7 +4,7 @@ use crate::{ binding_model::{self, BindGroup, BindGroupLayout, BindGroupLayoutEntryError}, command, conv, device::{ - bgl, + bgl, create_validator, life::{LifetimeTracker, WaitIdleError}, queue::PendingWrites, AttachmentData, DeviceLostInvocation, MissingDownlevelFlags, MissingFeatures, @@ -20,7 +20,7 @@ use crate::{ }, instance::Adapter, lock::{rank, Mutex, MutexGuard, RwLock}, - pipeline::{self}, + pipeline, pool::ResourcePool, registry::Registry, resource::{ @@ -1485,16 +1485,19 @@ impl Device { None }; - let info = self - .create_validator(naga::valid::ValidationFlags::all()) - .validate(&module) - .map_err(|inner| { - pipeline::CreateShaderModuleError::Validation(naga::error::ShaderError { - source, - label: desc.label.as_ref().map(|l| l.to_string()), - inner: Box::new(inner), - }) - })?; + let info = create_validator( + self.features, + self.downlevel.flags, + naga::valid::ValidationFlags::all(), + ) + .validate(&module) + .map_err(|inner| { + pipeline::CreateShaderModuleError::Validation(naga::error::ShaderError { + source, + label: desc.label.as_ref().map(|l| l.to_string()), + inner: Box::new(inner), + }) + })?; let interface = validation::Interface::new(&module, &info, self.limits.clone(), self.features); @@ -1536,111 +1539,6 @@ impl Device { }) } - /// Create a validator with the given validation flags. - pub fn create_validator( - self: &Arc, - flags: naga::valid::ValidationFlags, - ) -> naga::valid::Validator { - use naga::valid::Capabilities as Caps; - let mut caps = Caps::empty(); - caps.set( - Caps::PUSH_CONSTANT, - self.features.contains(wgt::Features::PUSH_CONSTANTS), - ); - caps.set( - Caps::FLOAT64, - self.features.contains(wgt::Features::SHADER_F64), - ); - caps.set( - Caps::PRIMITIVE_INDEX, - self.features - .contains(wgt::Features::SHADER_PRIMITIVE_INDEX), - ); - caps.set( - Caps::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - self.features.contains( - wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - ), - ); - caps.set( - Caps::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, - self.features.contains( - wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, - ), - ); - // TODO: This needs a proper wgpu feature - caps.set( - Caps::SAMPLER_NON_UNIFORM_INDEXING, - self.features.contains( - wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - ), - ); - caps.set( - Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS, - self.features - .contains(wgt::Features::TEXTURE_FORMAT_16BIT_NORM), - ); - caps.set( - Caps::MULTIVIEW, - self.features.contains(wgt::Features::MULTIVIEW), - ); - caps.set( - Caps::EARLY_DEPTH_TEST, - self.features - .contains(wgt::Features::SHADER_EARLY_DEPTH_TEST), - ); - caps.set( - Caps::SHADER_INT64, - self.features.contains(wgt::Features::SHADER_INT64), - ); - caps.set( - Caps::MULTISAMPLED_SHADING, - self.downlevel - .flags - .contains(wgt::DownlevelFlags::MULTISAMPLED_SHADING), - ); - caps.set( - Caps::DUAL_SOURCE_BLENDING, - self.features.contains(wgt::Features::DUAL_SOURCE_BLENDING), - ); - caps.set( - Caps::CUBE_ARRAY_TEXTURES, - self.downlevel - .flags - .contains(wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES), - ); - caps.set( - Caps::SUBGROUP, - self.features - .intersects(wgt::Features::SUBGROUP | wgt::Features::SUBGROUP_VERTEX), - ); - caps.set( - Caps::SUBGROUP_BARRIER, - self.features.intersects(wgt::Features::SUBGROUP_BARRIER), - ); - - let mut subgroup_stages = naga::valid::ShaderStages::empty(); - subgroup_stages.set( - naga::valid::ShaderStages::COMPUTE | naga::valid::ShaderStages::FRAGMENT, - self.features.contains(wgt::Features::SUBGROUP), - ); - subgroup_stages.set( - naga::valid::ShaderStages::VERTEX, - self.features.contains(wgt::Features::SUBGROUP_VERTEX), - ); - - let subgroup_operations = if caps.contains(Caps::SUBGROUP) { - use naga::valid::SubgroupOperationSet as S; - S::BASIC | S::VOTE | S::ARITHMETIC | S::BALLOT | S::SHUFFLE | S::SHUFFLE_RELATIVE - } else { - naga::valid::SubgroupOperationSet::empty() - }; - let mut validator = naga::valid::Validator::new(flags, caps); - validator.subgroup_stages(subgroup_stages); - validator.subgroup_operations(subgroup_operations); - validator - } - #[allow(unused_unsafe)] pub(crate) unsafe fn create_shader_module_spirv<'a>( self: &Arc,