Skip to content

Commit

Permalink
Fixes crash when there's a missing texture argument (#6486)
Browse files Browse the repository at this point in the history
  • Loading branch information
aedm authored Nov 7, 2024
1 parent 9b47b06 commit 47d20d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Bottom level categories:

### Bug Fixes

#### Naga

- Fix crash when a texture argument is missing. By @aedm in [#6486](https://github.com/gfx-rs/wgpu/pull/6486)

#### General

- Ensure that `Features::TIMESTAMP_QUERY` is set when using timestamp writes in render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
Expand Down
10 changes: 8 additions & 2 deletions naga/src/valid/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ impl FunctionInfo {
let image_storage = match sampling.image {
GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var),
GlobalOrArgument::Argument(i) => {
let handle = arguments[i as usize];
let Some(handle) = arguments.get(i as usize).cloned() else {
// Argument count mismatch, will be reported later by validate_call
break;
};
GlobalOrArgument::from_expression(expression_arena, handle).map_err(
|source| {
FunctionError::Expression { handle, source }
Expand All @@ -434,7 +437,10 @@ impl FunctionInfo {
let sampler_storage = match sampling.sampler {
GlobalOrArgument::Global(var) => GlobalOrArgument::Global(var),
GlobalOrArgument::Argument(i) => {
let handle = arguments[i as usize];
let Some(handle) = arguments.get(i as usize).cloned() else {
// Argument count mismatch, will be reported later by validate_call
break;
};
GlobalOrArgument::from_expression(expression_arena, handle).map_err(
|source| {
FunctionError::Expression { handle, source }
Expand Down
37 changes: 37 additions & 0 deletions naga/tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,40 @@ fn binding_arrays_cannot_hold_scalars() {

assert!(t.validator.validate(&t.module).is_err());
}

#[cfg(feature = "wgsl-in")]
#[test]
fn validation_error_messages() {
let cases = [(
r#"@group(0) @binding(0) var my_sampler: sampler;
fn foo(tex: texture_2d<f32>) -> vec4<f32> {
return textureSampleLevel(tex, my_sampler, vec2f(0, 0), 0.0);
}
fn main() {
foo();
}
"#,
"\
error: Function [1] 'main' is invalid
┌─ wgsl:7:17
\n7 │ ╭ fn main() {
8 │ │ foo();
│ │ ^^^^ invalid function call
│ ╰──────────────────────────^ naga::Function [1]
\n = Call to [0] is invalid
= Requires 1 arguments, but 0 are provided
",
)];

for (source, expected_err) in cases {
let module = naga::front::wgsl::parse_str(source).unwrap();
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
.validate_no_overrides(&module)
.expect_err("module should be invalid");
println!("{}", err.emit_to_string(source));
assert_eq!(err.emit_to_string(source), expected_err);
}
}

0 comments on commit 47d20d9

Please sign in to comment.