diff --git a/src/webgpu/shader/validation/expression/call/builtin/textureSample.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/textureSample.spec.ts index 11acb7305c77..da79f32deb37 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/textureSample.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/textureSample.spec.ts @@ -48,22 +48,26 @@ function innerType(type: string) { return type.substring(angleNdx + 1, type.length - (angleNdx >= 0 ? 1 : 0)); } -// Replace with non-hacky version -function isConvertible(src: string, dst: string) { +/** @returns true if an argument of type 'src' can be used for a parameter of type 'dst' */ +function isConvertible(src: Type, dst: Type) { if (src === dst) { return true; } - const angleNdx = src.indexOf('<'); - if (src.substring(0, angleNdx) !== dst.substring(0, angleNdx)) { + + const widthOf = (ty: Type) => { + return ty instanceof VectorType ? ty.width : 1; + }; + + if (widthOf(src) !== widthOf(dst)) { return false; } - src = src.substring(angleNdx + 1, src.length - (angleNdx >= 0 ? 1 : 0)); - dst = dst.substring(angleNdx + 1, dst.length - (angleNdx >= 0 ? 1 : 0)); + const elSrc = scalarTypeOf(src); + const elDst = scalarTypeOf(dst); - switch (src) { + switch (elSrc.kind) { case 'abstract-float': - switch (dst) { + switch (elDst.kind) { case 'abstract-float': case 'f16': case 'f32': @@ -73,7 +77,7 @@ function isConvertible(src: string, dst: string) { return false; } case 'abstract-int': - switch (dst) { + switch (elDst.kind) { case 'abstract-int': case 'abstract-float': case 'f16':