Skip to content

Commit

Permalink
Add tests for GPUDevice.adapterInfo (#4023)
Browse files Browse the repository at this point in the history
Co-authored-by: Kai Ninomiya <kainino@chromium.org>
  • Loading branch information
beaufortfrancois and kainino0x authored Nov 6, 2024
1 parent 8a781f5 commit 0d22c00
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/w3c-image-capture": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@webgpu/types": "^0.1.50",
"@webgpu/types": "^0.1.51",
"ansi-colors": "4.1.3",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-const-enum": "^1.2.0",
Expand Down
99 changes: 97 additions & 2 deletions src/webgpu/api/operation/adapter/info.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export const description = `
Tests GPUAdapter.info members formatting.
Tests for GPUAdapterInfo.
`;

import { Fixture } from '../../../../common/framework/fixture.js';
import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { keysOf } from '../../../../common/util/data_tables.js';
import { getGPU } from '../../../../common/util/navigator_gpu.js';
import { assert } from '../../../../common/util/util.js';
import { assert, objectEquals } from '../../../../common/util/util.js';

export const g = makeTestGroup(Fixture);

Expand Down Expand Up @@ -39,3 +40,97 @@ g.test('adapter_info')
`adapterInfo.device should be a normalized identifier. But it's '${adapterInfo.device}'`
);
});

g.test('same_object')
.desc(
`
GPUAdapter.info and GPUDevice.adapterInfo provide the same object each time they're accessed,
but different objects from one another.`
)
.fn(async t => {
const gpu = getGPU(t.rec);
const adapter = await gpu.requestAdapter();
assert(adapter !== null);

const adapterInfo1 = adapter.info;
const adapterInfo2 = adapter.info;
t.expect(adapterInfo1 === adapterInfo2, 'adapter.info should obey [SameObject]');

const device = await t.requestDeviceTracked(adapter);
assert(device !== null);

const deviceAdapterInfo1 = device.adapterInfo;
const deviceAdapterInfo2 = device.adapterInfo;
t.expect(
deviceAdapterInfo1 === deviceAdapterInfo2,
'device.adapterInfo should obey [SameObject]'
);

t.expect(
adapter.info !== device.adapterInfo,
'adapter.info and device.adapterInfo should NOT return the same object'
);
});

g.test('device_matches_adapter')
.desc(
`
Test that GPUDevice.adapterInfo matches GPUAdapter.info. Cases access the members in
different orders to make sure that they are consistent regardless of the access order.`
)
.paramsSubcasesOnly(u =>
u.combine('testDeviceFirst', [true, false]).combine('testMembersFirst', [true, false])
)
.fn(async t => {
const { testDeviceFirst, testMembersFirst } = t.params;

const gpu = getGPU(t.rec);
const adapter = await gpu.requestAdapter();
assert(adapter !== null);

const device = await t.requestDeviceTracked(adapter);
assert(device !== null);

const deviceInfo: unknown[] = [];
const adapterInfo: unknown[] = [];

const kGPUAdapterInfoKeys = keysOf(GPUAdapterInfo.prototype);
if (testMembersFirst) {
if (testDeviceFirst) {
assert(device.adapterInfo instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
deviceInfo.push(device.adapterInfo[k]);
}
assert(adapter.info instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
adapterInfo.push(adapter.info[k]);
}
} else {
assert(adapter.info instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
adapterInfo.push(adapter.info[k]);
}
assert(device.adapterInfo instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
deviceInfo.push(device.adapterInfo[k]);
}
}
} else {
if (testDeviceFirst) {
assert(device.adapterInfo instanceof GPUAdapterInfo);
assert(adapter.info instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
deviceInfo.push(device.adapterInfo[k]);
adapterInfo.push(adapter.info[k]);
}
} else {
assert(adapter.info instanceof GPUAdapterInfo);
assert(device.adapterInfo instanceof GPUAdapterInfo);
for (const k of kGPUAdapterInfoKeys) {
adapterInfo.push(adapter.info[k]);
deviceInfo.push(device.adapterInfo[k]);
}
}
t.expect(objectEquals(deviceInfo, adapterInfo));
}
});

0 comments on commit 0d22c00

Please sign in to comment.