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 GPUDevice.adapterInfo #4023

Merged
merged 9 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
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
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'
);
});
kainino0x marked this conversation as resolved.
Show resolved Hide resolved

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));
}
});
Loading