Skip to content

Commit

Permalink
Update print_environment to show featureLevel and defaultDevice (#4130)
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x authored Jan 10, 2025
1 parent 3fae862 commit 467b5f7
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/common/runtime/helper/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const kCTSOptionsInfo: OptionsInfos<CTSOptions> = {
],
},
debug: { description: 'show more info' },
compatibility: { description: 'run in compatibility mode' },
compatibility: { description: 'request adapters with featureLevel: "compatibility"' },
forceFallbackAdapter: { description: 'pass forceFallbackAdapter: true to requestAdapter' },
enforceDefaultLimits: {
description: `force the adapter limits to the default limits.
Expand Down
220 changes: 110 additions & 110 deletions src/resources/cache/hashes.json

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

41 changes: 27 additions & 14 deletions src/webgpu/print_environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ function consoleLogIfNotWPT(x: unknown) {

g.test('info')
.desc(
`Test which prints what global scope (e.g. worker type) it's running in.
Typically, tests will check for the presence of the feature they need (like HTMLCanvasElement)
and skip if it's not available.
`Test which prints what global scope (e.g. worker type) it's running in, and info about
the adapter and device that it gets.
Note, other tests should not check the global scope type to detect features; instead, they should
check for the presence of the feature they need (like HTMLCanvasElement) and skip if not available.
Run this test under various configurations to see different results
(Window, worker scopes, Node, etc.)
Expand All @@ -36,8 +38,19 @@ in the logs. On non-WPT runtimes, it will also print to the console with console
WPT disallows console.log and doesn't support logs on passing tests, so this does nothing on WPT.`
)
.fn(t => {
const isCompatibilityMode = (t.adapter as unknown as { isCompatibilityMode?: boolean })
.isCompatibilityMode;
// `t.device` will be the default device, because no additional capabilities were requested.
const defaultDeviceProperties = Object.fromEntries(
(function* () {
const device = t.device as unknown as Record<string, unknown>;
for (const key in device) {
// Skip things that we don't want to JSON.stringify.
if (['lost', 'queue', 'onuncapturederror', 'label'].includes(key)) {
continue;
}
yield [key, device[key]];
}
})()
);

const info = JSON.stringify(
{
Expand All @@ -46,20 +59,20 @@ WPT disallows console.log and doesn't support logs on passing tests, so this doe
globalTestConfig,
baseResourcePath: getResourcePath(''),
defaultRequestAdapterOptions: getDefaultRequestAdapterOptions(),
adapter: {
isFallbackAdapter: t.adapter.isFallbackAdapter,
isCompatibilityMode,
info: t.adapter.info,
features: Array.from(t.adapter.features),
limits: t.adapter.limits,
},
// Print all of the properties of the adapter and defaultDeviceProperties. JSON.stringify
// will skip methods (e.g. adapter.requestDevice), because they're not stringifiable.
adapter: t.adapter,
defaultDevice: defaultDeviceProperties,
},
// Flatten objects with prototype chains into plain objects, using `for..in`. (Otherwise,
// properties from the prototype chain will be ignored and things will print as `{}`.)
// - Replace `undefined` with `null`.
// - Expand iterable things into arrays.
// - Flatten objects with prototype chains into plain objects, using `for..in`. (Otherwise,
// properties from the prototype chain will be ignored and things will print as `{}`.)
(_key, value) => {
if (value === undefined || value === null) return null;
if (typeof value !== 'object') return value;
if (value instanceof Array) return value;
if (Symbol.iterator in value) return Array.from(value as Iterable<unknown>);

const valueObj = value as Record<string, unknown>;
return Object.fromEntries(
Expand Down

0 comments on commit 467b5f7

Please sign in to comment.