Skip to content

Commit

Permalink
Update src/webgpu/shader/validation/expression/call/builtin/textureSa…
Browse files Browse the repository at this point in the history
…mple.spec.ts


new isConvertable

Co-authored-by: Ben Clayton <[email protected]>
  • Loading branch information
greggman and ben-clayton authored Mar 12, 2024
1 parent 6cbf4bd commit 30ec586
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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':
Expand Down

0 comments on commit 30ec586

Please sign in to comment.