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
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
"message": "Use requestDeviceTracked() instead of requestDevice().",
// We don't seem to need direct calls to requestDevice() at all so we can just disallow all of them.
"selector": "CallExpression > MemberExpression > Identifier[name=\"requestDevice\"]"
},
{
"message": "Use hasFeature() instead of features.has().",
// features.has takes any string. We want only valid feature names.
"selector": "CallExpression[callee.property.name='has'][callee.object.name='features'],CallExpression[callee.property.name='has'][callee.object.property.name='features']"
}
],

Expand Down
4 changes: 2 additions & 2 deletions src/common/framework/test_config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '../util/util.js';
import { assert, hasFeature } from '../util/util.js';

export type TestConfig = {
/**
Expand Down Expand Up @@ -90,7 +90,7 @@ export const globalTestConfig: TestConfig = {
// is trying to test that compatibility devices have the correct validation.
export function isCompatibilityDevice(device: GPUDevice) {
if (globalTestConfig.compatibility) {
assert(!device.features.has('core-features-and-limits'));
assert(!hasFeature(device.features, 'core-features-and-limits'));
}
return globalTestConfig.compatibility;
}
7 changes: 5 additions & 2 deletions src/common/util/navigator_gpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { TestCaseRecorder } from '../framework/fixture.js';
import { globalTestConfig } from '../framework/test_config.js';

import { ErrorWithExtra, assert, objectEquals } from './util.js';
import { ErrorWithExtra, assert, hasFeature, objectEquals } from './util.js';

/**
* Finds and returns the `navigator.gpu` object (or equivalent, for non-browser implementations).
Expand Down Expand Up @@ -164,7 +164,9 @@ export function getGPU(recorder: TestCaseRecorder | null): GPU {
Object.defineProperty(adapter, 'features', {
enumerable: false,
value: new Set(
adapter.features.has('core-features-and-limits') ? ['core-features-and-limits'] : []
hasFeature(adapter.features, 'core-features-and-limits')
? ['core-features-and-limits']
: []
),
});
}
Expand All @@ -177,6 +179,7 @@ export function getGPU(recorder: TestCaseRecorder | null): GPU {
for (const [feature] of desc.requiredFeatures) {
// Note: This adapter has had its features property over-ridden and will only return
// have nothing or 'core-features-and-limits'.
// eslint-disable-next-line no-restricted-syntax
if (!adapter.features.has(feature)) {
throw new TypeError(`requested feature ${feature} does not exist on adapter`);
}
Expand Down
9 changes: 9 additions & 0 deletions src/common/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,12 @@ export function filterUniqueValueTestVariants(valueTestVariants: ValueTestVarian
export function makeValueTestVariant(base: number, variant: ValueTestVariant) {
return base * variant.mult + variant.add;
}

/**
* Use instead of features.has because feature's has takes any string
* and we want to prevent typos.
*/
export function hasFeature(features: GPUSupportedFeatures, feature: GPUFeatureName) {
// eslint-disable-next-line no-restricted-syntax
return features.has(feature);
}
220 changes: 110 additions & 110 deletions src/resources/cache/hashes.json

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

4 changes: 2 additions & 2 deletions src/webgpu/api/operation/adapter/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Fixture } from '../../../../common/framework/fixture.js';
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { keysOf } from '../../../../common/util/data_tables.js';
import { getGPU } from '../../../../common/util/navigator_gpu.js';
import { assert, objectEquals } from '../../../../common/util/util.js';
import { assert, hasFeature, objectEquals } from '../../../../common/util/util.js';
import { isPowerOfTwo } from '../../../util/math.js';

export const g = makeTestGroup(Fixture);
Expand Down Expand Up @@ -158,7 +158,7 @@ If they exist, they must both exist and be powers of two, and
// Once 'subgroups' lands, the properties should be defined with default values 4 and 128
// when adapter does not support the feature.
// https://github.com/gpuweb/gpuweb/pull/4963
if (adapter.features.has('subgroups')) {
if (hasFeature(adapter.features, 'subgroups')) {
t.expect(
subgroupMinSize !== undefined,
'GPUAdapterInfo.subgroupMinSize must exist when subgroups supported'
Expand Down
12 changes: 6 additions & 6 deletions src/webgpu/api/operation/adapter/requestDevice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ potentially limited native resources.
import { Fixture } from '../../../../common/framework/fixture.js';
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { getGPU } from '../../../../common/util/navigator_gpu.js';
import { assert, assertReject, typedEntries } from '../../../../common/util/util.js';
import { assert, assertReject, hasFeature, typedEntries } from '../../../../common/util/util.js';
import {
getDefaultLimitsForCTS,
kFeatureNames,
Expand Down Expand Up @@ -44,7 +44,7 @@ g.test('default')

if (device.features.size === 1) {
t.expect(
device.features.has('core-features-and-limits'),
hasFeature(device.features, 'core-features-and-limits'),
'Default device should not have any features other than "core-features-and-limits"'
);
} else {
Expand Down Expand Up @@ -204,9 +204,9 @@ g.test('features,known')
assert(adapter !== null);

const promise = t.requestDeviceTracked(adapter, { requiredFeatures: [feature] });
if (adapter.features.has(feature)) {
if (hasFeature(adapter.features, feature)) {
const device = await promise;
t.expect(device.features.has(feature), 'Device should include the required feature');
t.expect(hasFeature(device.features, feature), 'Device should include the required feature');
} else {
t.shouldReject('TypeError', promise);
}
Expand Down Expand Up @@ -496,12 +496,12 @@ g.test('always_returns_device')
const device = await t.requestDeviceTracked(adapter);
assert(device instanceof GPUDevice, 'requestDevice must return a device or throw');

if (featureLevel === 'core' && adapter.features.has('core-features-and-limits')) {
if (featureLevel === 'core' && hasFeature(adapter.features, 'core-features-and-limits')) {
// Check if the device supports core, when featureLevel is core and adapter supports core.
// This check is to make sure something lower-level is not forcing compatibility mode.

t.expect(
device.features.has('core-features-and-limits'),
hasFeature(device.features, 'core-features-and-limits'),
'must not get a Compatibility adapter if not requested'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ changes to WebGPU do not break sites requesting everything.

// Test that all the adapter features are on the device.
for (const feature of t.adapter.features) {
// eslint-disable-next-line no-restricted-syntax
t.expect(t.device.features.has(feature), `device has feature: ${feature}`);
}
});
Loading