From 105a2ae5e1e830b2e461b72e313776cf47dc294a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Tue, 6 Jul 2021 17:06:51 +0100 Subject: [PATCH] [glsl-in] Check type dimensions in function calls --- src/front/glsl/functions.rs | 58 +++++++++++++++---- tests/in/glsl/900-implicit-conversions.vert | 7 +++ .../wgsl/900-implicit-conversions-vert.wgsl | 29 ++++++++++ 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/front/glsl/functions.rs b/src/front/glsl/functions.rs index b40a5fd334..b99daa85f6 100644 --- a/src/front/glsl/functions.rs +++ b/src/front/glsl/functions.rs @@ -696,20 +696,54 @@ impl Program<'_> { let decl_inner = &self.module.types[*decl_arg].inner; let call_inner = self.resolve_type(ctx, call_arg.0, call_arg.1)?; - if decl_inner != call_inner { - exact = false; + if decl_inner == call_inner { + continue; + } - match ( - decl_inner.scalar_kind().and_then(type_power), - call_inner.scalar_kind().and_then(type_power), - ) { - (Some(decl_power), Some(call_power)) => { - if decl_power < call_power { - continue 'outer; - } - } - _ => continue 'outer, + exact = false; + + let (decl_kind, call_kind) = match (decl_inner, call_inner) { + ( + &TypeInner::Scalar { + kind: decl_kind, .. + }, + &TypeInner::Scalar { + kind: call_kind, .. + }, + ) => (decl_kind, call_kind), + ( + &TypeInner::Vector { + kind: decl_kind, + size: decl_size, + .. + }, + &TypeInner::Vector { + kind: call_kind, + size: call_size, + .. + }, + ) if decl_size == call_size => (decl_kind, call_kind), + ( + &TypeInner::Matrix { + rows: decl_rows, + columns: decl_columns, + .. + }, + &TypeInner::Matrix { + rows: call_rows, + columns: call_columns, + .. + }, + ) if decl_columns == call_columns && decl_rows == call_rows => { + (ScalarKind::Float, ScalarKind::Float) } + _ => continue 'outer, + }; + + match (type_power(decl_kind), type_power(call_kind)) { + (Some(decl_power), Some(call_power)) + if decl_power > call_power => {} + _ => continue 'outer, } } diff --git a/tests/in/glsl/900-implicit-conversions.vert b/tests/in/glsl/900-implicit-conversions.vert index d3908bb112..c534cfad51 100644 --- a/tests/in/glsl/900-implicit-conversions.vert +++ b/tests/in/glsl/900-implicit-conversions.vert @@ -9,7 +9,14 @@ void exact(int a) {} void implicit(float a) {} void implicit(int a) {} +// All satisfy the kind condition but they have different dimensions +void implicit_dims(float v) { } +void implicit_dims(vec2 v) { } +void implicit_dims(vec3 v) { } +void implicit_dims(vec4 v) { } + void main() { exact(1); implicit(1u); + implicit_dims(ivec3(1)); } diff --git a/tests/out/wgsl/900-implicit-conversions-vert.wgsl b/tests/out/wgsl/900-implicit-conversions-vert.wgsl index 49e4a57044..4704b44192 100644 --- a/tests/out/wgsl/900-implicit-conversions-vert.wgsl +++ b/tests/out/wgsl/900-implicit-conversions-vert.wgsl @@ -26,9 +26,38 @@ fn implicit1(a6: i32) { return; } +fn implicit_dims(v: f32) { + var v1: f32; + + v1 = v; + return; +} + +fn implicit_dims1(v2: vec2) { + var v3: vec2; + + v3 = v2; + return; +} + +fn implicit_dims2(v4: vec3) { + var v5: vec3; + + v5 = v4; + return; +} + +fn implicit_dims3(v6: vec4) { + var v7: vec4; + + v7 = v6; + return; +} + fn main1() { exact1(1); implicit(f32(1u)); + implicit_dims2(vec3(vec3(1))); return; }