Skip to content

Commit

Permalink
Add tests for GPURequestAdapterOptions featureLevel (#4077)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored Dec 5, 2024
1 parent 08731e9 commit 9223c26
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/webgpu/api/operation/adapter/requestAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Tests for GPU.requestAdapter.
Test all possible options to requestAdapter.
default, low-power, and high performance should all always return adapters.
forceFallbackAdapter may or may not return an adapter.
invalid featureLevel values should not return an adapter.
GPU.requestAdapter can technically return null for any reason
but we need test functionality so the test requires an adapter except
Expand All @@ -26,6 +27,8 @@ const powerPreferenceModes: Array<GPUPowerPreference | undefined> = [
'high-performance',
];
const forceFallbackOptions: Array<boolean | undefined> = [undefined, false, true];
const validFeatureLevels: Array<string | undefined> = [undefined, 'core', 'compatibility'];
const invalidFeatureLevels: Array<string> = ['cor', 'Core', 'compatability', '', ' '];

async function testAdapter(t: Fixture, adapter: GPUAdapter | null) {
assert(adapter !== null, 'Failed to get adapter.');
Expand Down Expand Up @@ -120,6 +123,20 @@ g.test('requestAdapter')
await testAdapter(t, adapter);
});

g.test('requestAdapter_invalid_featureLevel')
.desc(`request adapter with invalid featureLevel string values return null`)
.params(u => u.combine('featureLevel', [...validFeatureLevels, ...invalidFeatureLevels]))
.fn(async t => {
const { featureLevel } = t.params;
const adapter = await getGPU(t.rec).requestAdapter({ featureLevel });

if (!validFeatureLevels.includes(featureLevel)) {
assert(adapter === null);
} else {
await testAdapter(t, adapter);
}
});

g.test('requestAdapter_no_parameters')
.desc(`request adapter with no parameters`)
.fn(async t => {
Expand Down

0 comments on commit 9223c26

Please sign in to comment.