Skip to content

Commit

Permalink
Update tests using .isCompatibilityMode to understand .featureLevel
Browse files Browse the repository at this point in the history
And update all comments about removing `compatibilityMode: boolean`.
  • Loading branch information
kainino0x committed Jan 8, 2025
1 parent 10b66cd commit 3b92a37
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/common/runtime/cmdline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ for (let i = 0; i < sys.args.length; ++i) {
let codeCoverage: CodeCoverageProvider | undefined = undefined;

if (globalTestConfig.compatibility || globalTestConfig.forceFallbackAdapter) {
// MAINTENANCE_TODO: remove the cast once compatibilityMode is officially added
// MAINTENANCE_TODO: remove compatibilityMode (and the typecast) once no longer needed.
setDefaultRequestAdapterOptions({
compatibilityMode: globalTestConfig.compatibility,
featureLevel: globalTestConfig.compatibility ? 'compatibility' : 'core',
Expand Down
2 changes: 1 addition & 1 deletion src/common/runtime/helper/utils_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function setupWorkerEnvironment(ctsOptions: CTSOptions): Logger {
if (powerPreference || compatibility) {
setDefaultRequestAdapterOptions({
...(powerPreference && { powerPreference }),
// MAINTENANCE_TODO: Change this to whatever the option ends up being
// MAINTENANCE_TODO: remove compatibilityMode once no longer needed.
...(compatibility && { compatibilityMode: true, featureLevel: 'compatibility' }),
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ for (let i = 0; i < sys.args.length; ++i) {
let codeCoverage: CodeCoverageProvider | undefined = undefined;

if (globalTestConfig.compatibility || globalTestConfig.forceFallbackAdapter) {
// MAINTENANCE_TODO: remove the cast once compatibilityMode is officially added
// MAINTENANCE_TODO: remove compatibilityMode (and the typecast) once no longer needed.
setDefaultRequestAdapterOptions({
compatibilityMode: globalTestConfig.compatibility,
featureLevel: globalTestConfig.compatibility ? 'compatibility' : 'core',
Expand Down
2 changes: 1 addition & 1 deletion src/common/runtime/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ stopButtonElem.addEventListener('click', () => {
if (powerPreference || compatibility || forceFallbackAdapter) {
setDefaultRequestAdapterOptions({
...(powerPreference && { powerPreference }),
// MAINTENANCE_TODO: Change this to whatever the option ends up being
// MAINTENANCE_TODO: remove compatibilityMode once no longer needed.
...(compatibility && { compatibilityMode: true, featureLevel: 'compatibility' }),
...(forceFallbackAdapter && { forceFallbackAdapter: true }),
});
Expand Down
34 changes: 24 additions & 10 deletions src/webgpu/api/operation/adapter/requestDevice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ g.test('always_returns_device')
Note: This is a regression test for a Chrome bug crbug.com/349062459
Checking that a requestDevice always return a device is checked in other tests above
but those tests have 'compatibilityMode: true' set for them by the API that getGPU
but those tests have 'featureLevel: "compatibility"' set for them by the API that getGPU
returns when the test suite is run in compatibility mode.
This test tries to force both compat and core separately so both code paths are
Expand All @@ -502,19 +502,33 @@ g.test('always_returns_device')
.fn(async t => {
const { compatibilityMode } = t.params;
const gpu = getGPU(t.rec);
// MAINTENANCE_TODO: Remove this cast compatibilityMode is added.
const adapter = await gpu.requestAdapter({ compatibilityMode } as GPURequestAdapterOptions);
// MAINTENANCE_TODO: Remove compatibilityMode and the cast once compatibilityMode is no longer
// used (mainly in `setDefaultRequestAdapterOptions`).
const adapter = await gpu.requestAdapter({
compatibilityMode,
featureLevel: compatibilityMode ? 'compatibility' : 'core',
} as GPURequestAdapterOptions);
if (adapter) {
const device = await t.requestDeviceTracked(adapter);
assert(device instanceof GPUDevice, 'requestDevice must return a device or throw');

if (!compatibilityMode) {
// This check is to make sure something lower-level is not forcing compatibility mode
// MAINTENANCE_TODO: Remove this cast compatibilityMode is added.
// This check is to make sure something lower-level is not forcing compatibility mode.

// MAINTENANCE_TODO: Simplify this check (and typecast) once we standardize how to do this.
const adapterExtensions = adapter as unknown as {
isCompatibilityMode?: boolean;
featureLevel?: string;
};
t.expect(
!(adapter as unknown as { isCompatibilityMode?: boolean }).isCompatibilityMode,
'must not be compatibility mode'
// Old version of Compat design.
!adapterExtensions.isCompatibilityMode &&
// Current version of Compat design, as of this writing.
adapterExtensions.featureLevel !== 'compatibility' &&
// An unlanded proposed change to the Compat design, but it doesn't hurt to just check.
!device.features.has('webgpu-core'),
'must not get a Compatibility adapter if not requested'
);
}
const device = await t.requestDeviceTracked(adapter);
t.expect(device instanceof GPUDevice, 'requestDevice must return a device or throw');
device.destroy();
}
});
12 changes: 8 additions & 4 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,15 @@ export function getDefaultLimits(featureLevel: FeatureLevel) {

export function getDefaultLimitsForAdapter(adapter: GPUAdapter) {
// MAINTENANCE_TODO: Remove casts when GPUAdapter IDL has isCompatibilityMode.
return getDefaultLimits(
(adapter as unknown as { isCompatibilityMode: boolean }).isCompatibilityMode
const adapterExtensions = adapter as unknown as {
isCompatibilityMode?: boolean;
featureLevel?: string;
};
const featureLevel =
adapterExtensions.featureLevel === 'compatibility' || adapterExtensions.isCompatibilityMode
? 'compatibility'
: 'core'
);
: 'core';
return getDefaultLimits(featureLevel);
}

const kEachStage = [
Expand Down

0 comments on commit 3b92a37

Please sign in to comment.