diff --git a/src/front/glsl/builtins.rs b/src/front/glsl/builtins.rs index 287f66d6f1..2744fb79ad 100644 --- a/src/front/glsl/builtins.rs +++ b/src/front/glsl/builtins.rs @@ -2237,20 +2237,26 @@ pub fn sampled_to_depth( meta: Span, errors: &mut Vec, ) { + // Get the a mutable type handle of the underlying image storage let ty = match ctx[image] { Expression::GlobalVariable(handle) => &mut module.global_variables.get_mut(handle).ty, Expression::FunctionArgument(i) => { + // Mark the function argument as carrying a depth texture ctx.parameters_info[i as usize].depth = true; + // NOTE: We need to later also change the parameter type &mut ctx.arguments[i as usize].ty } _ => { + // Only globals and function arguments are allowed to carry an image return errors.push(Error { kind: ErrorKind::SemanticError("Not a valid texture expression".into()), meta, - }) + }); } }; + match module.types[*ty].inner { + // Update the image class to depth in case it already isn't TypeInner::Image { class, dim, @@ -2270,6 +2276,7 @@ pub fn sampled_to_depth( ) } ImageClass::Depth { .. } => {} + // Other image classes aren't allowed to be transformed to depth _ => errors.push(Error { kind: ErrorKind::SemanticError("Not a texture".into()), meta, @@ -2280,6 +2287,15 @@ pub fn sampled_to_depth( meta, }), }; + + // Copy the handle to allow borrowing the `ctx` again + let ty = *ty; + + // If the image was passed trough a function argument we also need to change + // the corresponding parameter + if let Expression::FunctionArgument(i) = ctx[image] { + ctx.parameters[i as usize] = ty; + } } bitflags::bitflags! { diff --git a/src/front/glsl/functions.rs b/src/front/glsl/functions.rs index 325f4d8abe..2c0445bdf2 100644 --- a/src/front/glsl/functions.rs +++ b/src/front/glsl/functions.rs @@ -671,6 +671,13 @@ impl Parser { let overload_param_ty = &self.module.types[*overload_parameter].inner; let call_arg_ty = self.resolve_type(ctx, call_argument.0, call_argument.1)?; + log::trace!( + "Testing parameter {}\n\tOverload = {:?}\n\tCall = {:?}", + i, + overload_param_ty, + call_arg_ty + ); + // Storage images cannot be directly compared since while the access is part of the // type in naga's IR, in glsl they are a qualifier and don't enter in the match as // long as the access needed is satisfied.