Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 109 additions & 109 deletions src/resources/cache/hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2176,8 +2176,8 @@
"webgpu:shader,validation,expression,call,builtin,textureSample:offset_argument,non_const:*": { "subcaseMS": 1.604 },
"webgpu:shader,validation,expression,call,builtin,textureSample:offset_argument:*": { "subcaseMS": 1.401 },
"webgpu:shader,validation,expression,call,builtin,textureSample:only_in_fragment:*": { "subcaseMS": 1.121 },
"webgpu:shader,validation,expression,call,builtin,textureSample:texture_type:*": { "subcaseMS": 1.888 },
"webgpu:shader,validation,expression,call,builtin,textureSample:return_type:*": { "subcaseMS": 1.888 },
"webgpu:shader,validation,expression,call,builtin,textureSample:texture_type:*": { "subcaseMS": 1.888 },
"webgpu:shader,validation,expression,call,builtin,textureSampleBaseClampToEdge:coords_argument:*": { "subcaseMS": 239.356 },
"webgpu:shader,validation,expression,call,builtin,textureSampleBias:array_index_argument:*": { "subcaseMS": 1.630 },
"webgpu:shader,validation,expression,call,builtin,textureSampleBias:bias_argument:*": { "subcaseMS": 1.102 },
Expand Down
47 changes: 22 additions & 25 deletions src/webgpu/shader/validation/expression/binary/add_sub_mul.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { keysOf, objectsToRecord } from '../../../../../common/util/data_tables.
import { assert } from '../../../../../common/util/util.js';
import { kBit } from '../../../../util/constants.js';
import {
concreteTypeOf,
isAbstractType,
isConvertible,
kAllScalarsAndVectors,
kConcreteNumericScalarsAndVectors,
kConvertableToFloatScalar,
ScalarType,
scalarTypeOf,
Type,
Expand All @@ -24,6 +26,8 @@ import {
validateConstOrOverrideBinaryOpEval,
} from '../call/builtin/const_override_validation.js';

import { resultType } from './result_type.js';

export const g = makeTestGroup(ShaderValidationTest);

// A list of operators tested in this file.
Expand Down Expand Up @@ -54,6 +58,7 @@ g.test('scalar_vector')
value => !(value.startsWith('vec3') || value.startsWith('vec4'))
)
)
.combine('compound_assignment', [false, true] as const)
.beginSubcases()
.combine('op', keysOf(kOperators))
)
Expand All @@ -71,36 +76,28 @@ g.test('scalar_vector')
const rhs = kScalarAndVectorTypes[t.params.rhs];
const lhsElement = scalarTypeOf(lhs);
const rhsElement = scalarTypeOf(rhs);
const hasBool = lhsElement === Type.bool || rhsElement === Type.bool;
const hasF16 = lhsElement === Type.f16 || rhsElement === Type.f16;
const code = `
const resType = resultType({ lhs, rhs, canConvertScalarToVector: true });
const resTypeIsTypeable = resType && !isAbstractType(scalarTypeOf(resType));
const code = t.params.compound_assignment
? `
${hasF16 ? 'enable f16;' : ''}
fn f() {
var v = ${lhs.create(0).wgsl()};
v ${op.op}= ${rhs.create(0).wgsl()};
}
`
: `
${hasF16 ? 'enable f16;' : ''}
const lhs = ${lhs.create(0).wgsl()};
const rhs = ${rhs.create(0).wgsl()};
const foo = lhs ${op.op} rhs;
const foo ${resTypeIsTypeable ? `: ${resType}` : ''} = lhs ${op.op} rhs;
`;

let elementsCompatible = lhsElement === rhsElement;
const elementTypes = [lhsElement, rhsElement];

// Booleans are not allowed for arithmetic expressions.
if (elementTypes.includes(Type.bool)) {
elementsCompatible = false;

// AbstractInt is allowed with everything but booleans which are already checked above.
} else if (elementTypes.includes(Type.abstractInt)) {
elementsCompatible = true;

// AbstractFloat is allowed with AbstractInt (checked above) or float types
} else if (elementTypes.includes(Type.abstractFloat)) {
elementsCompatible = elementTypes.every(e => kConvertableToFloatScalar.includes(e));
let valid = !hasBool && resType !== null;
if (valid && t.params.compound_assignment) {
valid = valid && isConvertible(resType!, concreteTypeOf(lhs));
}

// Determine if the full type is compatible. The only invalid case is mixed vector sizes.
let valid = elementsCompatible;
if (lhs instanceof VectorType && rhs instanceof VectorType) {
valid = valid && lhs.width === rhs.width;
}

t.expectCompileResult(valid, code);
});

Expand Down
Loading