Fixes crash when there's a missing texture argument (#6486)

This commit is contained in:
Gábor Gyebnár 2024-11-07 16:35:36 +01:00 committed by GitHub
parent 9b47b06a4f
commit 47d20d913d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 2 deletions

View File

@ -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).

View File

@ -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 }
@ -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 }

View File

@ -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);
}
}