Skip to content

Commit

Permalink
Update code that uses adapter.isCompatibilityMode (#4131)
Browse files Browse the repository at this point in the history
* Update tests using .isCompatibilityMode to understand .featureLevel

And update all comments about removing `compatibilityMode: boolean`.

* address comments
  • Loading branch information
kainino0x authored Jan 8, 2025
1 parent 40867c3 commit 2a7c7f9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/common/runtime/cmdline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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 @@ -27,7 +27,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 @@ -122,7 +122,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 @@ -85,7 +85,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
35 changes: 25 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,34 @@ 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 as-yet-unlanded proposed change to the Compat design, but for now it doesn't hurt
// to just check. Unlanded PR: https://github.com/gpuweb/gpuweb/pull/5036
!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();
}
});
15 changes: 10 additions & 5 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,17 @@ 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
// MAINTENANCE_TODO: Remove casts once we have a standardized way to do this
// (see https://github.com/gpuweb/gpuweb/pull/5037#issuecomment-2576110161).
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 2a7c7f9

Please sign in to comment.