Skip to content

Commit

Permalink
Add featureLevel CTS option
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Dec 6, 2024
1 parent 9223c26 commit 0bd2bc7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/common/framework/test_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export type TestConfig = {
*/
unrollConstEvalLoops: boolean;

/**
* Feature level for the adapter request.
*/
featureLevel: string | null;

/**
* Whether or not we're running in compatibility mode.
*/
Expand All @@ -57,6 +62,7 @@ export const globalTestConfig: TestConfig = {
testHeartbeatCallback: () => {},
noRaceWithRejectOnTimeout: false,
unrollConstEvalLoops: false,
featureLevel: null,
compatibility: false,
forceFallbackAdapter: false,
logToWebSocket: false,
Expand Down
8 changes: 7 additions & 1 deletion src/common/runtime/cmdline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ for (let i = 0; i < sys.args.length; ++i) {
globalTestConfig.unrollConstEvalLoops = true;
} else if (a === '--compat') {
globalTestConfig.compatibility = true;
globalTestConfig.featureLevel = 'compatibility';
} else if (a === '--force-fallback-adapter') {
globalTestConfig.forceFallbackAdapter = true;
} else if (a === '--log-to-websocket') {
Expand All @@ -120,9 +121,14 @@ for (let i = 0; i < sys.args.length; ++i) {

let codeCoverage: CodeCoverageProvider | undefined = undefined;

if (globalTestConfig.compatibility || globalTestConfig.forceFallbackAdapter) {
if (
globalTestConfig.featureLevel ||
globalTestConfig.compatibility ||
globalTestConfig.forceFallbackAdapter
) {
// MAINTENANCE_TODO: remove the cast once compatibilityMode is officially added
setDefaultRequestAdapterOptions({
featureLevel: globalTestConfig.featureLevel,
compatibilityMode: globalTestConfig.compatibility,
forceFallbackAdapter: globalTestConfig.forceFallbackAdapter,
} as GPURequestAdapterOptions);
Expand Down
13 changes: 12 additions & 1 deletion src/common/runtime/helper/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function optionWorkerMode(
export interface CTSOptions {
worker: WorkerMode | null;
debug: boolean;
featureLevel: 'core' | 'compatibility' | null;
compatibility: boolean;
forceFallbackAdapter: boolean;
unrollConstEvalLoops: boolean;
Expand All @@ -61,6 +62,7 @@ export interface CTSOptions {
export const kDefaultCTSOptions: CTSOptions = {
worker: null,
debug: true,
featureLevel: null,
compatibility: false,
forceFallbackAdapter: false,
unrollConstEvalLoops: false,
Expand Down Expand Up @@ -98,7 +100,16 @@ export const kCTSOptionsInfo: OptionsInfos<CTSOptions> = {
],
},
debug: { description: 'show more info' },
compatibility: { description: 'run in compatibility mode' },
featureLevel: {
description: 'set feature level for some tests',
parser: optionString,
selectValueDescriptions: [
{ value: null, description: 'default' },
{ value: 'core', description: 'core' },
{ value: 'compatibility', description: 'compatibility' },
],
},
compatibility: { description: 'run in compatibility mode (non-standard)' },
forceFallbackAdapter: { description: 'pass forceFallbackAdapter: true to requestAdapter' },
unrollConstEvalLoops: { description: 'unroll const eval loops in WGSL' },
powerPreference: {
Expand Down
6 changes: 4 additions & 2 deletions src/common/runtime/helper/utils_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ export interface WorkerTestRunRequest {
* Set config environment for workers with ctsOptions and return a Logger.
*/
export function setupWorkerEnvironment(ctsOptions: CTSOptions): Logger {
const { powerPreference, compatibility } = ctsOptions;
const { featureLevel, powerPreference, compatibility } = ctsOptions;
globalTestConfig.enableDebugLogs = ctsOptions.debug;
globalTestConfig.unrollConstEvalLoops = ctsOptions.unrollConstEvalLoops;
globalTestConfig.featureLevel = featureLevel;
globalTestConfig.compatibility = compatibility;
globalTestConfig.logToWebSocket = ctsOptions.logToWebSocket;

const log = new Logger();

if (powerPreference || compatibility) {
if (featureLevel || powerPreference || compatibility) {
setDefaultRequestAdapterOptions({
...(featureLevel && { featureLevel }),
...(powerPreference && { powerPreference }),
// MAINTENANCE_TODO: Change this to whatever the option ends up being
...(compatibility && { compatibilityMode: true }),
Expand Down
8 changes: 7 additions & 1 deletion src/common/runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ for (let i = 0; i < sys.args.length; ++i) {
Colors.enabled = true;
} else if (a === '--compat') {
globalTestConfig.compatibility = true;
globalTestConfig.featureLevel = 'compatibility';
} else if (a === '--coverage') {
emitCoverage = true;
} else if (a === '--force-fallback-adapter') {
Expand Down Expand Up @@ -119,9 +120,14 @@ for (let i = 0; i < sys.args.length; ++i) {

let codeCoverage: CodeCoverageProvider | undefined = undefined;

if (globalTestConfig.compatibility || globalTestConfig.forceFallbackAdapter) {
if (
globalTestConfig.featureLevel ||
globalTestConfig.compatibility ||
globalTestConfig.forceFallbackAdapter
) {
// MAINTENANCE_TODO: remove the cast once compatibilityMode is officially added
setDefaultRequestAdapterOptions({
featureLevel: globalTestConfig.featureLevel,
compatibilityMode: globalTestConfig.compatibility,
forceFallbackAdapter: globalTestConfig.forceFallbackAdapter,
} as GPURequestAdapterOptions);
Expand Down
5 changes: 3 additions & 2 deletions src/common/runtime/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const { queries: qs, options } = parseSearchParamLikeWithOptions(
kStandaloneOptionsInfos,
window.location.search || rootQuerySpec
);
const { runnow, powerPreference, compatibility, forceFallbackAdapter } = options;
const { runnow, featureLevel, powerPreference, compatibility, forceFallbackAdapter } = options;
globalTestConfig.enableDebugLogs = options.debug;
globalTestConfig.unrollConstEvalLoops = options.unrollConstEvalLoops;
globalTestConfig.compatibility = compatibility;
Expand Down Expand Up @@ -81,8 +81,9 @@ stopButtonElem.addEventListener('click', () => {
stopRequested = true;
});

if (powerPreference || compatibility || forceFallbackAdapter) {
if (featureLevel || powerPreference || compatibility || forceFallbackAdapter) {
setDefaultRequestAdapterOptions({
...(featureLevel && { featureLevel }),
...(powerPreference && { powerPreference }),
// MAINTENANCE_TODO: Change this to whatever the option ends up being
...(compatibility && { compatibilityMode: true }),
Expand Down
4 changes: 2 additions & 2 deletions src/webgpu/gpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class GPUTestSubcaseBatchState extends SubcaseBatchState {
}

get isCompatibility() {
return globalTestConfig.compatibility;
return globalTestConfig.compatibility || globalTestConfig.featureLevel === 'compatibility';
}

getDefaultLimits() {
Expand Down Expand Up @@ -366,7 +366,7 @@ export class GPUTestBase extends Fixture<GPUTestSubcaseBatchState> {
}

get isCompatibility() {
return globalTestConfig.compatibility;
return globalTestConfig.compatibility || globalTestConfig.featureLevel === 'compatibility';
}

getDefaultLimits() {
Expand Down
4 changes: 3 additions & 1 deletion src/webgpu/util/device_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ function canonicalizeDescriptor(
const limitsCanonicalized: Record<string, number> = {};
// MAINTENANCE_TODO: Remove cast when @webgpu/types includes compatibilityMode
const adapterOptions = getDefaultRequestAdapterOptions() as unknown as {
featureLevel?: string;
compatibilityMode?: boolean;
};
const featureLevel = adapterOptions?.compatibilityMode ? 'compatibility' : 'core';
const featureLevel =
adapterOptions?.featureLevel || adapterOptions?.compatibilityMode ? 'compatibility' : 'core';
const defaultLimits = getDefaultLimits(featureLevel);
if (desc.requiredLimits) {
for (const limit of kLimits) {
Expand Down

0 comments on commit 0bd2bc7

Please sign in to comment.