Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmarks #2498

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn gather_inputs(folder: &str, extension: &str) -> Vec<Box<[u8]>> {
list
}

#[cfg(feature = "glsl-in")]
fn parse_glsl(stage: naga::ShaderStage, inputs: &[Box<[u8]>]) {
let mut parser = naga::front::glsl::Frontend::default();
let options = naga::front::glsl::Options {
Expand Down Expand Up @@ -148,8 +149,11 @@ fn backends(c: &mut Criterion) {
#[cfg(feature = "validate")]
let inputs = {
let mut validator = naga::valid::Validator::new(
naga::valid::ValidationFlags::empty(),
naga::valid::Capabilities::default(),
naga::valid::ValidationFlags::BLOCKS,
// atomicCompareExchangeWeak isn't implemented yet
// (#1413), so filter out anything that uses that.
naga::valid::Capabilities::default()
- naga::valid::Capabilities::ATOMIC_COMPARE_EXCHANGE_WEAK,
);
let input_modules = gather_modules();
input_modules
Expand Down Expand Up @@ -211,7 +215,10 @@ fn backends(c: &mut Criterion) {
group.bench_function("msl", |b| {
b.iter(|| {
let mut string = String::new();
let options = naga::back::msl::Options::default();
let options = naga::back::msl::Options {
lang_version: (2, 1),
.. Default::default()
};
for &(ref module, ref info) in inputs.iter() {
let pipeline_options = naga::back::msl::PipelineOptions::default();
let mut writer = naga::back::msl::Writer::new(&mut string);
Expand Down
13 changes: 13 additions & 0 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ impl super::Validator {
}

if let crate::AtomicFunction::Exchange { compare: Some(cmp) } = *fun {
if !self
.capabilities
.contains(super::Capabilities::ATOMIC_COMPARE_EXCHANGE_WEAK)
{
return Err(FunctionError::Expression {
handle: result,
source: ExpressionError::MissingCapabilities(
super::Capabilities::ATOMIC_COMPARE_EXCHANGE_WEAK,
),
}
.with_span_handle(result, context.expressions));
}

if context.resolve_type(cmp, &self.valid_expression_set)? != value_inner {
log::error!("Atomic exchange comparison has a different type from the value");
return Err(AtomicError::InvalidOperand(cmp)
Expand Down
10 changes: 9 additions & 1 deletion src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,20 @@ bitflags::bitflags! {
const RAY_QUERY = 0x1000;
/// Support for generating two sources for blending from fragement shaders
const DUAL_SOURCE_BLENDING = 0x2000;
/// Support for WGSL atomicCompareExchangeWeak
///
/// This is part of the WGSL standard, but it's not implemented yet for
/// some backends (#1413). Our benchmark harness would like to be able
/// to filter out modules we can't process successfully.
const ATOMIC_COMPARE_EXCHANGE_WEAK = 0x4000;
/// Support for binding arrays.
const BINDING_ARRAY = 0x8000;
}
}

impl Default for Capabilities {
fn default() -> Self {
Self::MULTISAMPLED_SHADING
Self::MULTISAMPLED_SHADING | Self::ATOMIC_COMPARE_EXCHANGE_WEAK
}
}

Expand Down
1 change: 1 addition & 0 deletions src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ impl super::Validator {
TypeInfo::new(TypeFlags::DATA | TypeFlags::SIZED, Alignment::ONE)
}
Ti::BindingArray { base, size } => {
self.require_type_capability(Capabilities::BINDING_ARRAY)?;
if base >= handle {
return Err(TypeError::InvalidArrayBaseType(base));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/in/binding-buffer-arrays.param.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
god_mode: false,
god_mode: true,
spv: (
version: (1, 1),
binding_map: {
Expand Down
3 changes: 3 additions & 0 deletions tests/in/spv/binding-arrays.dynamic.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
god_mode: true,
)
3 changes: 3 additions & 0 deletions tests/in/spv/binding-arrays.static.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
god_mode: true,
)
35 changes: 23 additions & 12 deletions tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,10 @@ fn matrix_with_bad_type() {
/// Unless you are generating code programmatically, the
/// `check_validation_error` macro will probably be more convenient to
/// use.
macro_rules! check_one_validation {
( $source:expr, $pattern:pat $( if $guard:expr )? ) => {
macro_rules! check_one_validation_with_capabilities {
( $capabilities:expr, $source:expr, $pattern:pat $( if $guard:expr )? ) => {
let source = $source;
let error = validation_error($source);
let error = validation_error($source, $capabilities);
if ! matches!(&error, $pattern $( if $guard )? ) {
eprintln!("validation error does not match pattern:\n\
source code: {}\n\
Expand All @@ -875,6 +875,15 @@ macro_rules! check_one_validation {
}
}

macro_rules! check_one_validation {
( $source:expr, $pattern:pat $( if $guard:expr )? ) => {
check_one_validation_with_capabilities!(
naga::valid::Capabilities::default(),
$source, $pattern $( if $guard )?
);
}
}

macro_rules! check_validation {
// We want to support an optional guard expression after the pattern, so
// that we can check values we can't match against, like strings.
Expand All @@ -893,20 +902,20 @@ macro_rules! check_validation {
}
}

fn validation_error(source: &str) -> Result<naga::valid::ModuleInfo, naga::valid::ValidationError> {
fn validation_error(
source: &str,
capabilities: naga::valid::Capabilities,
) -> Result<naga::valid::ModuleInfo, naga::valid::ValidationError> {
let module = match naga::front::wgsl::parse_str(source) {
Ok(module) => module,
Err(err) => {
eprintln!("WGSL parse failed:");
panic!("{}", err.emit_to_string(source));
}
};
naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::default(),
)
.validate(&module)
.map_err(|e| e.into_inner()) // TODO: Add tests for spans, too?
naga::valid::Validator::new(naga::valid::ValidationFlags::all(), capabilities)
.validate(&module)
.map_err(|e| e.into_inner()) // TODO: Add tests for spans, too?
}

#[test]
Expand Down Expand Up @@ -1939,8 +1948,10 @@ fn binding_array_private() {

#[test]
fn binding_array_non_struct() {
check_validation! {
"var<storage> x: binding_array<i32, 4>;":
use naga::valid::Capabilities;
check_one_validation_with_capabilities! {
Capabilities::default() | Capabilities::BINDING_ARRAY,
"var<storage> x: binding_array<i32, 4>;",
Err(naga::valid::ValidationError::Type {
source: naga::valid::TypeError::BindingArrayBaseTypeNotStruct(_),
..
Expand Down
Loading