Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds validation tests for count* builtin functions. #3498

Merged
merged 10 commits into from
Apr 3, 2024
12 changes: 12 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,18 @@
"webgpu:shader,validation,expression,call,builtin,cos:values:*": { "subcaseMS": 0.338 },
"webgpu:shader,validation,expression,call,builtin,cosh:integer_argument:*": { "subcaseMS": 0.889 },
"webgpu:shader,validation,expression,call,builtin,cosh:values:*": { "subcaseMS": 0.272 },
"webgpu:shader,validation,expression,call,builtin,countLeadingZeros:bad_args:*": { "subcaseMS": 23.259 },
"webgpu:shader,validation,expression,call,builtin,countLeadingZeros:float_argument:*": { "subcaseMS": 64.191 },
"webgpu:shader,validation,expression,call,builtin,countLeadingZeros:must_use:*": { "subcaseMS": 4.120 },
"webgpu:shader,validation,expression,call,builtin,countLeadingZeros:values:*": { "subcaseMS": 3153.457 },
"webgpu:shader,validation,expression,call,builtin,countOneBits:bad_args:*": { "subcaseMS": 15.737 },
"webgpu:shader,validation,expression,call,builtin,countOneBits:float_argument:*": { "subcaseMS": 44.219 },
"webgpu:shader,validation,expression,call,builtin,countOneBits:must_use:*": { "subcaseMS": 3.284 },
"webgpu:shader,validation,expression,call,builtin,countOneBits:values:*": { "subcaseMS": 3771.859 },
"webgpu:shader,validation,expression,call,builtin,countTrailingZeros:bad_args:*": { "subcaseMS": 18.975 },
"webgpu:shader,validation,expression,call,builtin,countTrailingZeros:float_argument:*": { "subcaseMS": 46.181 },
"webgpu:shader,validation,expression,call,builtin,countTrailingZeros:must_use:*": { "subcaseMS": 3.934 },
"webgpu:shader,validation,expression,call,builtin,countTrailingZeros:values:*": { "subcaseMS": 3125.847 },
"webgpu:shader,validation,expression,call,builtin,degrees:integer_argument:*": { "subcaseMS": 1.311 },
"webgpu:shader,validation,expression,call,builtin,degrees:values:*": { "subcaseMS": 0.303 },
"webgpu:shader,validation,expression,call,builtin,derivatives:invalid_argument_types:*": { "subcaseMS": 1.000 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const builtin = 'countLeadingZeros';
export const description = `
Validation tests for the ${builtin}() builtin.
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js';
import {
kConcreteIntegerScalarsAndVectors,
kFloatScalarsAndVectors,
} from '../../../../../util/conversion.js';
import { ShaderValidationTest } from '../../../shader_validation_test.js';

import {
fullRangeForType,
kConstantAndOverrideStages,
stageSupportsType,
validateConstOrOverrideBuiltinEval,
} from './const_override_validation.js';

export const g = makeTestGroup(ShaderValidationTest);

const kValuesTypes = objectsToRecord(kConcreteIntegerScalarsAndVectors);

g.test('values')
.desc(
`
Validates that constant evaluation and override evaluation of ${builtin}() never errors
`
)
.params(u =>
u
.combine('stage', kConstantAndOverrideStages)
.combine('type', keysOf(kValuesTypes))
.filter(u => stageSupportsType(u.stage, kValuesTypes[u.type]))
.beginSubcases()
.expand('value', u => fullRangeForType(kValuesTypes[u.type]))
)
.fn(t => {
const expectedResult = true; // countLeadingZeros() should never error
validateConstOrOverrideBuiltinEval(
t,
builtin,
expectedResult,
[kValuesTypes[t.params.type].create(t.params.value)],
t.params.stage
);
});

const kFloatTypes = objectsToRecord(kFloatScalarsAndVectors);

g.test('float_argument')
.desc(
`
Validates that float arguments are rejected by ${builtin}()
`
)
.params(u => u.combine('type', keysOf(kFloatTypes)))
.fn(t => {
const type = kFloatTypes[t.params.type];
validateConstOrOverrideBuiltinEval(
t,
builtin,
/* expectedResult */ false,
[type.create(0)],
'constant'
);
});

const kGoodArgs = '(1u)';
lokokung marked this conversation as resolved.
Show resolved Hide resolved
const kBadArgs = {
// Bad number of args
'0args': '',
'2args': '(1u,2u)',
// Bad value for arg 0
'0bool': '(false)',
'0array': '(array(1u))',
lokokung marked this conversation as resolved.
Show resolved Hide resolved
'0struct': '(modf(2.2))',
};

g.test('bad_args')
.desc(`Test compilation failure of ${builtin} with bad arguments`)
.params(u => u.combine('arg', keysOf(kBadArgs)))
.fn(t => {
t.expectCompileResult(false, `const c = ${builtin}${kBadArgs[t.params.arg]};`);
});

g.test('must_use')
.desc(`Result of ${builtin} must be used`)
.fn(t => {
t.expectCompileResult(false, `fn f() { ${builtin}${kGoodArgs}; }`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const builtin = 'countOneBits';
export const description = `
Validation tests for the ${builtin}() builtin.
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js';
import {
kConcreteIntegerScalarsAndVectors,
kFloatScalarsAndVectors,
} from '../../../../../util/conversion.js';
import { ShaderValidationTest } from '../../../shader_validation_test.js';

import {
fullRangeForType,
kConstantAndOverrideStages,
stageSupportsType,
validateConstOrOverrideBuiltinEval,
} from './const_override_validation.js';

export const g = makeTestGroup(ShaderValidationTest);

const kValuesTypes = objectsToRecord(kConcreteIntegerScalarsAndVectors);

g.test('values')
.desc(
`
Validates that constant evaluation and override evaluation of ${builtin}() never errors
`
)
.params(u =>
u
.combine('stage', kConstantAndOverrideStages)
.combine('type', keysOf(kValuesTypes))
.filter(u => stageSupportsType(u.stage, kValuesTypes[u.type]))
.beginSubcases()
.expand('value', u => fullRangeForType(kValuesTypes[u.type]))
)
.fn(t => {
const expectedResult = true; // countOneBits() should never error
validateConstOrOverrideBuiltinEval(
t,
builtin,
expectedResult,
[kValuesTypes[t.params.type].create(t.params.value)],
t.params.stage
);
});

const kFloatTypes = objectsToRecord(kFloatScalarsAndVectors);

g.test('float_argument')
.desc(
`
Validates that float arguments are rejected by ${builtin}()
`
)
.params(u => u.combine('type', keysOf(kFloatTypes)))
.fn(t => {
const type = kFloatTypes[t.params.type];
validateConstOrOverrideBuiltinEval(
t,
builtin,
/* expectedResult */ false,
[type.create(0)],
'constant'
);
});

const kGoodArgs = '(1u)';
const kBadArgs = {
// Bad number of args
'0args': '',
'2args': '(1u,2u)',
// Bad value for arg 0
'0bool': '(false)',
'0array': '(array(1u))',
'0struct': '(modf(2.2))',
};

g.test('bad_args')
.desc(`Test compilation failure of ${builtin} with bad arguments`)
.params(u => u.combine('arg', keysOf(kBadArgs)))
.fn(t => {
t.expectCompileResult(false, `const c = ${builtin}${kBadArgs[t.params.arg]};`);
});

g.test('must_use')
.desc(`Result of ${builtin} must be used`)
.fn(t => {
t.expectCompileResult(false, `fn f() { ${builtin}${kGoodArgs}; }`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const builtin = 'countTrailingZeros';
export const description = `
Validation tests for the ${builtin}() builtin.
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js';
import {
kConcreteIntegerScalarsAndVectors,
kFloatScalarsAndVectors,
} from '../../../../../util/conversion.js';
import { ShaderValidationTest } from '../../../shader_validation_test.js';

import {
fullRangeForType,
kConstantAndOverrideStages,
stageSupportsType,
validateConstOrOverrideBuiltinEval,
} from './const_override_validation.js';

export const g = makeTestGroup(ShaderValidationTest);

const kValuesTypes = objectsToRecord(kConcreteIntegerScalarsAndVectors);

g.test('values')
.desc(
`
Validates that constant evaluation and override evaluation of ${builtin}() never errors
`
)
.params(u =>
u
.combine('stage', kConstantAndOverrideStages)
.combine('type', keysOf(kValuesTypes))
.filter(u => stageSupportsType(u.stage, kValuesTypes[u.type]))
.beginSubcases()
.expand('value', u => fullRangeForType(kValuesTypes[u.type]))
)
.fn(t => {
const expectedResult = true; // countTrailingZeros() should never error
validateConstOrOverrideBuiltinEval(
t,
builtin,
expectedResult,
[kValuesTypes[t.params.type].create(t.params.value)],
t.params.stage
);
});

const kFloatTypes = objectsToRecord(kFloatScalarsAndVectors);

g.test('float_argument')
.desc(
`
Validates that float arguments are rejected by ${builtin}()
`
)
.params(u => u.combine('type', keysOf(kFloatTypes)))
.fn(t => {
const type = kFloatTypes[t.params.type];
validateConstOrOverrideBuiltinEval(
t,
builtin,
/* expectedResult */ false,
[type.create(0)],
'constant'
);
});

const kGoodArgs = '(1u)';
const kBadArgs = {
// Bad number of args
'0args': '',
'2args': '(1u,2u)',
// Bad value for arg 0
'0bool': '(false)',
'0array': '(array(1u))',
'0struct': '(modf(2.2))',
};

g.test('bad_args')
.desc(`Test compilation failure of ${builtin} with bad arguments`)
.params(u => u.combine('arg', keysOf(kBadArgs)))
.fn(t => {
t.expectCompileResult(false, `const c = ${builtin}${kBadArgs[t.params.arg]};`);
});

g.test('must_use')
.desc(`Result of ${builtin} must be used`)
.fn(t => {
t.expectCompileResult(false, `fn f() { ${builtin}${kGoodArgs}; }`);
});
Loading