Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for GPURequestAdapterOptions featureLevel #4077

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
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
Loading