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

Add tests for GPUDevice.adapterInfo #4023

merged 9 commits into from
Nov 6, 2024

Conversation

beaufortfrancois
Copy link
Collaborator

This PR adds simple tests for the adapterInfo GPUDevice member. It can be tested in a Chromium build patched with https://chromium-review.googlesource.com/c/chromium/src/+/5980752. It is available behind the "Unsafe WebGPU support" flag at chrome://flag#enable-unsafe-webgpu as the spec PR gpuweb/gpuweb#4809 has not landed yet.

image

Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)
  • Test have be tested with compatibility mode validation enabled and behave as expected. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

assert(device.adapterInfo instanceof GPUAdapterInfo);
assert(adapter.info instanceof GPUAdapterInfo);

for (const k of Object.keys(GPUAdapterInfo.prototype)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landed the spec; didn't make adapter and device use the same object, so we should test that adapter.info !== device.adapterInfo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesn't say they have to be different object, so I wouldn't test that adapter.info !== device.adapterInfo. Note that Chromium experimental implementation actually returns the same object: https://chromium-review.googlesource.com/c/chromium/src/+/5980752/3/third_party/blink/renderer/modules/webgpu/gpu_device.cc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does implicitly require them to be different objects, because a new one is created the first time each of them is accessed, there's no opportunity to return the same one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this PR.
Do you know by any chance how to return a copy of adapter_->info() in Chromium?

Copy link
Collaborator

@kainino0x kainino0x Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should construct the adapterInfo when we construct GPUDevice and store it in a field of GPUDevice, the same way we do for info when we construct GPUAdapter. The initialization will be the same so we should take this code, move it into a GPUAdapter method called something like CreateAdapterInfoForAdapter(), have it return the GPUAdapterInfo object, and then call it from both GPUAdapter::GPUAdapter and GPUDevice::GPUDevice.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webgpu/gpu_adapter.cc;l=198-210;drc=0afc9ac9afcaab79fc54299039f4d27abf3a086d

src/webgpu/api/operation/adapter/info.spec.ts Show resolved Hide resolved
src/webgpu/api/operation/adapter/info.spec.ts Outdated Show resolved Hide resolved
src/webgpu/api/operation/adapter/info.spec.ts Outdated Show resolved Hide resolved
src/webgpu/api/operation/adapter/info.spec.ts Outdated Show resolved Hide resolved
src/webgpu/api/operation/adapter/info.spec.ts Outdated Show resolved Hide resolved
@kainino0x
Copy link
Collaborator

Tested my changes in Canary with --enable-unsafe-webgpu, still works as expected.

@kainino0x kainino0x enabled auto-merge (squash) November 5, 2024 22:21
@kainino0x kainino0x merged commit 0d22c00 into main Nov 6, 2024
1 check passed
@kainino0x kainino0x deleted the adapter-info branch November 6, 2024 00:21
@beaufortfrancois
Copy link
Collaborator Author

import { keysOf } from '../../../../common/util/data_tables.js'; is useful. Thanks for improving the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants