mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
change create_validator
to a free function so it's usable
This commit is contained in:
parent
18b758e388
commit
c7a16b36b1
@ -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
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
binding_model::{self, BindGroup, BindGroupLayout, BindGroupLayoutEntryError},
|
binding_model::{self, BindGroup, BindGroupLayout, BindGroupLayoutEntryError},
|
||||||
command, conv,
|
command, conv,
|
||||||
device::{
|
device::{
|
||||||
bgl,
|
bgl, create_validator,
|
||||||
life::{LifetimeTracker, WaitIdleError},
|
life::{LifetimeTracker, WaitIdleError},
|
||||||
queue::PendingWrites,
|
queue::PendingWrites,
|
||||||
AttachmentData, DeviceLostInvocation, MissingDownlevelFlags, MissingFeatures,
|
AttachmentData, DeviceLostInvocation, MissingDownlevelFlags, MissingFeatures,
|
||||||
@ -20,7 +20,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
instance::Adapter,
|
instance::Adapter,
|
||||||
lock::{rank, Mutex, MutexGuard, RwLock},
|
lock::{rank, Mutex, MutexGuard, RwLock},
|
||||||
pipeline::{self},
|
pipeline,
|
||||||
pool::ResourcePool,
|
pool::ResourcePool,
|
||||||
registry::Registry,
|
registry::Registry,
|
||||||
resource::{
|
resource::{
|
||||||
@ -1485,16 +1485,19 @@ impl<A: HalApi> Device<A> {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let info = self
|
let info = create_validator(
|
||||||
.create_validator(naga::valid::ValidationFlags::all())
|
self.features,
|
||||||
.validate(&module)
|
self.downlevel.flags,
|
||||||
.map_err(|inner| {
|
naga::valid::ValidationFlags::all(),
|
||||||
pipeline::CreateShaderModuleError::Validation(naga::error::ShaderError {
|
)
|
||||||
source,
|
.validate(&module)
|
||||||
label: desc.label.as_ref().map(|l| l.to_string()),
|
.map_err(|inner| {
|
||||||
inner: Box::new(inner),
|
pipeline::CreateShaderModuleError::Validation(naga::error::ShaderError {
|
||||||
})
|
source,
|
||||||
})?;
|
label: desc.label.as_ref().map(|l| l.to_string()),
|
||||||
|
inner: Box::new(inner),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
let interface =
|
let interface =
|
||||||
validation::Interface::new(&module, &info, self.limits.clone(), self.features);
|
validation::Interface::new(&module, &info, self.limits.clone(), self.features);
|
||||||
@ -1536,111 +1539,6 @@ impl<A: HalApi> Device<A> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a validator with the given validation flags.
|
|
||||||
pub fn create_validator(
|
|
||||||
self: &Arc<Self>,
|
|
||||||
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)]
|
#[allow(unused_unsafe)]
|
||||||
pub(crate) unsafe fn create_shader_module_spirv<'a>(
|
pub(crate) unsafe fn create_shader_module_spirv<'a>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
|
Loading…
Reference in New Issue
Block a user