Repository: denoland/deno
Pull request: fix(webgpu): move `isFallbackAdapter` from `GPUAdapter` to `GPUAdapterInfo`

<!--
Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label.
-->

fix #28618

I also fixed `Deno.privateCustomInspect`, which was defined as static methods of the classes and was not working properly.


Changed files:
filename: cli/tsc/dts/lib.deno_webgpu.d.ts
patch: @@ -17,35 +17,39 @@ interface GPUObjectDescriptorBase {
 
 /** @category GPU */
 declare class GPUSupportedLimits {
-  maxTextureDimension1D?: number;
-  maxTextureDimension2D?: number;
-  maxTextureDimension3D?: number;
-  maxTextureArrayLayers?: number;
-  maxBindGroups?: number;
-  maxBindingsPerBindGroup?: number;
-  maxDynamicUniformBuffersPerPipelineLayout?: number;
-  maxDynamicStorageBuffersPerPipelineLayout?: number;
-  maxSampledTexturesPerShaderStage?: number;
-  maxSamplersPerShaderStage?: number;
-  maxStorageBuffersPerShaderStage?: number;
-  maxStorageTexturesPerShaderStage?: number;
-  maxUniformBuffersPerShaderStage?: number;
-  maxUniformBufferBindingSize?: number;
-  maxStorageBufferBindingSize?: number;
-  minUniformBufferOffsetAlignment?: number;
-  minStorageBufferOffsetAlignment?: number;
-  maxVertexBuffers?: number;
-  maxBufferSize?: number;
-  maxVertexAttributes?: number;
-  maxVertexBufferArrayStride?: number;
-  maxColorAttachments?: number;
-  maxColorAttachmentBytesPerSample?: number;
-  maxComputeWorkgroupStorageSize?: number;
-  maxComputeInvocationsPerWorkgroup?: number;
-  maxComputeWorkgroupSizeX?: number;
-  maxComputeWorkgroupSizeY?: number;
-  maxComputeWorkgroupSizeZ?: number;
-  maxComputeWorkgroupsPerDimension?: number;
+  readonly maxTextureDimension1D: number;
+  readonly maxTextureDimension2D: number;
+  readonly maxTextureDimension3D: number;
+  readonly maxTextureArrayLayers: number;
+  readonly maxBindGroups: number;
+  // TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
+  readonly maxBindGroupsPlusVertexBuffers?: number;
+  readonly maxBindingsPerBindGroup: number;
+  readonly maxDynamicUniformBuffersPerPipelineLayout: number;
+  readonly maxDynamicStorageBuffersPerPipelineLayout: number;
+  readonly maxSampledTexturesPerShaderStage: number;
+  readonly maxSamplersPerShaderStage: number;
+  readonly maxStorageBuffersPerShaderStage: number;
+  readonly maxStorageTexturesPerShaderStage: number;
+  readonly maxUniformBuffersPerShaderStage: number;
+  readonly maxUniformBufferBindingSize: number;
+  readonly maxStorageBufferBindingSize: number;
+  readonly minUniformBufferOffsetAlignment: number;
+  readonly minStorageBufferOffsetAlignment: number;
+  readonly maxVertexBuffers: number;
+  readonly maxBufferSize: number;
+  readonly maxVertexAttributes: number;
+  readonly maxVertexBufferArrayStride: number;
+  // TODO(@crowlKats): support max_inter_stage_shader_variables
+  readonly maxInterStageShaderVariables?: number;
+  readonly maxColorAttachments: number;
+  readonly maxColorAttachmentBytesPerSample: number;
+  readonly maxComputeWorkgroupStorageSize: number;
+  readonly maxComputeInvocationsPerWorkgroup: number;
+  readonly maxComputeWorkgroupSizeX: number;
+  readonly maxComputeWorkgroupSizeY: number;
+  readonly maxComputeWorkgroupSizeZ: number;
+  readonly maxComputeWorkgroupsPerDimension: number;
 }
 
 /** @category GPU */
@@ -74,6 +78,7 @@ declare class GPUAdapterInfo {
   readonly description: string;
   readonly subgroupMinSize: number;
   readonly subgroupMaxSize: number;
+  readonly isFallbackAdapter: boolean;
 }
 
 /**
@@ -164,7 +169,6 @@ declare class GPUAdapter {
   readonly features: GPUSupportedFeatures;
   readonly limits: GPUSupportedLimits;
   readonly info: GPUAdapterInfo;
-  readonly isFallbackAdapter: boolean;
 
   requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
 }

filename: ext/webgpu/01_webgpu.js
patch: @@ -53,9 +53,10 @@ import {
 import { DOMException } from "ext:deno_web/01_dom_exception.js";
 import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
 
-const customInspect = SymbolFor("Deno.privateCustomInspect");
+const privateCustomInspect = SymbolFor("Deno.privateCustomInspect");
 const _message = Symbol("[[message]]");
 const illegalConstructorKey = Symbol("illegalConstructorKey");
+
 class GPUError {
   constructor(key = null) {
     if (key !== illegalConstructorKey) {
@@ -69,7 +70,7 @@ class GPUError {
     return this[_message];
   }
 
-  [customInspect](inspect, inspectOptions) {
+  [privateCustomInspect](inspect, inspectOptions) {
     return inspect(
       createFilteredInspectProxy({
         object: this,
@@ -166,14 +167,16 @@ class GPUUncapturedErrorEvent extends Event {
 }
 const GPUUncapturedErrorEventPrototype = GPUUncapturedErrorEvent.prototype;
 
-ObjectDefineProperty(GPU, customInspect, {
+const GPUPrototype = GPU.prototype;
+ObjectDefineProperty(GPUPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
   },
 });
 
-ObjectDefineProperty(GPUAdapter, customInspect, {
+const GPUAdapterPrototype = GPUAdapter.prototype;
+ObjectDefineProperty(GPUAdapterPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -184,16 +187,15 @@ ObjectDefineProperty(GPUAdapter, customInspect, {
           "features",
           "limits",
           "info",
-          "isFallbackAdapter",
         ],
       }),
       inspectOptions,
     );
   },
 });
-const GPUAdapterPrototype = GPUAdapter.prototype;
 
-ObjectDefineProperty(GPUAdapterInfo, customInspect, {
+const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype;
+ObjectDefineProperty(GPUAdapterInfoPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -205,15 +207,19 @@ ObjectDefineProperty(GPUAdapterInfo, customInspect, {
           "architecture",
           "device",
           "description",
+          "subgroupMinSize",
+          "subgroupMaxSize",
+          "isFallbackAdapter",
         ],
       }),
       inspectOptions,
     );
   },
 });
-const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype;
 
-ObjectDefineProperty(GPUSupportedFeatures, customInspect, {
+const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype;
+webidl.setlikeObjectWrap(GPUSupportedFeaturesPrototype, true);
+ObjectDefineProperty(GPUSupportedFeaturesPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     if (ObjectPrototypeIsPrototypeOf(GPUSupportedFeaturesPrototype, this)) {
@@ -225,10 +231,61 @@ ObjectDefineProperty(GPUSupportedFeatures, customInspect, {
     }
   },
 });
-const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype;
-webidl.setlikeObjectWrap(GPUSupportedFeaturesPrototype, true);
 
-ObjectDefineProperty(GPUDeviceLostInfo, customInspect, {
+const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype;
+ObjectDefineProperty(GPUSupportedLimitsPrototype, privateCustomInspect, {
+  __proto__: null,
+  value(inspect, inspectOptions) {
+    return inspect(
+      createFilteredInspectProxy({
+        object: this,
+        evaluate: ObjectPrototypeIsPrototypeOf(
+          GPUSupportedLimitsPrototype,
+          this,
+        ),
+        keys: [
+          "maxTextureDimension1D",
+          "maxTextureDimension2D",
+          "maxTextureDimension3D",
+          "maxTextureArrayLayers",
+          "maxBindGroups",
+          // TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
+          // "maxBindGroupsPlusVertexBuffers",
+          "maxBindingsPerBindGroup",
+          "maxDynamicUniformBuffersPerPipelineLayout",
+          "maxDynamicStorageBuffersPerPipelineLayout",
+          "maxSampledTexturesPerShaderStage",
+          "maxSamplersPerShaderStage",
+          "maxStorageBuffersPerShaderStage",
+          "maxStorageTexturesPerShaderStage",
+          "maxUniformBuffersPerShaderStage",
+          "maxUniformBufferBindingSize",
+          "maxStorageBufferBindingSize",
+          "minUniformBufferOffsetAlignment",
+          "minStorageBufferOffsetAlignment",
+          "maxVertexBuffers",
+          "maxBufferSize",
+          "maxVertexAttributes",
+          "maxVertexBufferArrayStride",
+          // TODO(@crowlKats): support max_inter_stage_shader_variables
+          // "maxInterStageShaderVariables",
+          "maxColorAttachments",
+          "maxColorAttachmentBytesPerSample",
+          "maxComputeWorkgroupStorageSize",
+          "maxComputeInvocationsPerWorkgroup",
+          "maxComputeWorkgroupSizeX",
+          "maxComputeWorkgroupSizeY",
+          "maxComputeWorkgroupSizeZ",
+          "maxComputeWorkgroupsPerDimension",
+        ],
+      }),
+      inspectOptions,
+    );
+  },
+});
+
+const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype;
+ObjectDefineProperty(GPUDeviceLostInfoPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -247,9 +304,11 @@ ObjectDefineProperty(GPUDeviceLostInfo, customInspect, {
     );
   },
 });
-const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype;
 
-ObjectDefineProperty(GPUDevice, customInspect, {
+const GPUDevicePrototype = GPUDevice.prototype;
+ObjectSetPrototypeOf(GPUDevicePrototype, EventTargetPrototype);
+defineEventHandler(GPUDevicePrototype, "uncapturederror");
+ObjectDefineProperty(GPUDevicePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -270,11 +329,9 @@ ObjectDefineProperty(GPUDevice, customInspect, {
     );
   },
 });
-const GPUDevicePrototype = GPUDevice.prototype;
-ObjectSetPrototypeOf(GPUDevicePrototype, EventTargetPrototype);
-defineEventHandler(GPUDevice.prototype, "uncapturederror");
 
-ObjectDefineProperty(GPUQueue, customInspect, {
+const GPUQueuePrototype = GPUQueue.prototype;
+ObjectDefineProperty(GPUQueuePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -289,9 +346,9 @@ ObjectDefineProperty(GPUQueue, customInspect, {
     );
   },
 });
-const GPUQueuePrototype = GPUQueue.prototype;
 
-ObjectDefineProperty(GPUBuffer, customInspect, {
+const GPUBufferPrototype = GPUBuffer.prototype;
+ObjectDefineProperty(GPUBufferPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -309,7 +366,6 @@ ObjectDefineProperty(GPUBuffer, customInspect, {
     );
   },
 });
-const GPUBufferPrototype = GPUBuffer.prototype;
 
 class GPUBufferUsage {
   constructor() {
@@ -361,7 +417,8 @@ class GPUMapMode {
   }
 }
 
-ObjectDefineProperty(GPUTexture, customInspect, {
+const GPUTexturePrototype = GPUTexture.prototype;
+ObjectDefineProperty(GPUTexturePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -384,7 +441,6 @@ ObjectDefineProperty(GPUTexture, customInspect, {
     );
   },
 });
-const GPUTexturePrototype = GPUTexture.prototype;
 
 class GPUTextureUsage {
   constructor() {
@@ -408,7 +464,8 @@ class GPUTextureUsage {
   }
 }
 
-ObjectDefineProperty(GPUTextureView, customInspect, {
+const GPUTextureViewPrototype = GPUTextureView.prototype;
+ObjectDefineProperty(GPUTextureViewPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -423,20 +480,29 @@ ObjectDefineProperty(GPUTextureView, customInspect, {
     );
   },
 });
-const GPUTextureViewPrototype = GPUTextureView.prototype;
 
-ObjectDefineProperty(GPUSampler, customInspect, {
+const GPUSamplerPrototype = GPUSampler.prototype;
+ObjectDefineProperty(GPUSamplerPrototype, privateCustomInspect, {
   __proto__: null,
-  value(inspect) {
-    return `${this.constructor.name} ${
-      inspect({
-        label: this.label,
-      })
-    }`;
+  value(inspect, inspectOptions) {
+    return inspect(
+      createFilteredInspectProxy({
+        object: this,
+        evaluate: ObjectPrototypeIsPrototypeOf(
+          GPUSamplerPrototype,
+          this,
+        ),
+        keys: [
+          "label",
+        ],
+      }),
+      inspectOptions,
+    );
   },
 });
 
-ObjectDefineProperty(GPUBindGroupLayout, customInspect, {
+const GPUBindGroupLayoutPrototype = GPUBindGroupLayout.prototype;
+ObjectDefineProperty(GPUBindGroupLayout, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -454,9 +520,9 @@ ObjectDefineProperty(GPUBindGroupLayout, customInspect, {
     );
   },
 });
-const GPUBindGroupLayoutPrototype = GPUBindGroupLayout.prototype;
 
-ObjectDefineProperty(GPUPipelineLayout, customInspect, {
+const GPUPipelineLayoutPrototype = GPUPipelineLayout.prototype;
+ObjectDefineProperty(GPUPipelineLayoutPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -474,9 +540,9 @@ ObjectDefineProperty(GPUPipelineLayout, customInspect, {
     );
   },
 });
-const GPUPipelineLayoutPrototype = GPUPipelineLayout.prototype;
 
-ObjectDefineProperty(GPUBindGroup, customInspect, {
+const GPUBindGroupPrototype = GPUBindGroup.prototype;
+ObjectDefineProperty(GPUBindGroupPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -491,9 +557,9 @@ ObjectDefineProperty(GPUBindGroup, customInspect, {
     );
   },
 });
-const GPUBindGroupPrototype = GPUBindGroup.prototype;
 
-ObjectDefineProperty(GPUShaderModule, customInspect, {
+const GPUShaderModulePrototype = GPUShaderModule.prototype;
+ObjectDefineProperty(GPUShaderModulePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -508,7 +574,6 @@ ObjectDefineProperty(GPUShaderModule, customInspect, {
     );
   },
 });
-const GPUShaderModulePrototype = GPUShaderModule.prototype;
 
 class GPUShaderStage {
   constructor() {
@@ -528,7 +593,8 @@ class GPUShaderStage {
   }
 }
 
-ObjectDefineProperty(GPUComputePipeline, customInspect, {
+const GPUComputePipelinePrototype = GPUComputePipeline.prototype;
+ObjectDefineProperty(GPUComputePipelinePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -546,9 +612,9 @@ ObjectDefineProperty(GPUComputePipeline, customInspect, {
     );
   },
 });
-const GPUComputePipelinePrototype = GPUComputePipeline.prototype;
 
-ObjectDefineProperty(GPURenderPipeline, customInspect, {
+const GPURenderPipelinePrototype = GPURenderPipeline.prototype;
+ObjectDefineProperty(GPURenderPipelinePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -566,7 +632,6 @@ ObjectDefineProperty(GPURenderPipeline, customInspect, {
     );
   },
 });
-const GPURenderPipelinePrototype = GPURenderPipeline.prototype;
 
 class GPUColorWrite {
   constructor() {
@@ -590,7 +655,8 @@ class GPUColorWrite {
   }
 }
 
-ObjectDefineProperty(GPUCommandEncoder, customInspect, {
+const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype;
+ObjectDefineProperty(GPUCommandEncoderPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -608,9 +674,9 @@ ObjectDefineProperty(GPUCommandEncoder, customInspect, {
     );
   },
 });
-const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype;
 
-ObjectDefineProperty(GPURenderPassEncoder, customInspect, {
+const GPURenderPassEncoderPrototype = GPURenderPassEncoder.prototype;
+ObjectDefineProperty(GPURenderPassEncoderPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -628,9 +694,9 @@ ObjectDefineProperty(GPURenderPassEncoder, customInspect, {
     );
   },
 });
-const GPURenderPassEncoderPrototype = GPURenderPassEncoder.prototype;
 
-ObjectDefineProperty(GPUComputePassEncoder, customInspect, {
+const GPUComputePassEncoderPrototype = GPUComputePassEncoder.prototype;
+ObjectDefineProperty(GPUComputePassEncoderPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -648,9 +714,9 @@ ObjectDefineProperty(GPUComputePassEncoder, customInspect, {
     );
   },
 });
-const GPUComputePassEncoderPrototype = GPUComputePassEncoder.prototype;
 
-ObjectDefineProperty(GPUCommandBuffer, customInspect, {
+const GPUCommandBufferPrototype = GPUCommandBuffer.prototype;
+ObjectDefineProperty(GPUCommandBufferPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -665,9 +731,9 @@ ObjectDefineProperty(GPUCommandBuffer, customInspect, {
     );
   },
 });
-const GPUCommandBufferPrototype = GPUCommandBuffer.prototype;
 
-ObjectDefineProperty(GPURenderBundleEncoder, customInspect, {
+const GPURenderBundleEncoderPrototype = GPURenderBundleEncoder.prototype;
+ObjectDefineProperty(GPURenderBundleEncoderPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -685,9 +751,9 @@ ObjectDefineProperty(GPURenderBundleEncoder, customInspect, {
     );
   },
 });
-const GPURenderBundleEncoderPrototype = GPURenderBundleEncoder.prototype;
 
-ObjectDefineProperty(GPURenderBundle, customInspect, {
+const GPURenderBundlePrototype = GPURenderBundle.prototype;
+ObjectDefineProperty(GPURenderBundlePrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -702,9 +768,9 @@ ObjectDefineProperty(GPURenderBundle, customInspect, {
     );
   },
 });
-const GPURenderBundlePrototype = GPURenderBundle.prototype;
 
-ObjectDefineProperty(GPUQuerySet, customInspect, {
+const GPUQuerySetPrototype = GPUQuerySet.prototype;
+ObjectDefineProperty(GPUQuerySetPrototype, privateCustomInspect, {
   __proto__: null,
   value(inspect, inspectOptions) {
     return inspect(
@@ -721,7 +787,6 @@ ObjectDefineProperty(GPUQuerySet, customInspect, {
     );
   },
 });
-const GPUQuerySetPrototype = GPUQuerySet.prototype;
 
 // Converters
 

filename: ext/webgpu/adapter.rs
patch: @@ -88,6 +88,7 @@ impl GPUAdapter {
       GPUSupportedFeatures::new(scope, features)
     })
   }
+
   #[getter]
   #[global]
   fn limits(&self, scope: &mut v8::HandleScope) -> v8::Global<v8::Object> {
@@ -96,11 +97,6 @@ impl GPUAdapter {
       GPUSupportedLimits(adapter_limits)
     })
   }
-  #[getter]
-  fn is_fallback_adapter(&self) -> bool {
-    // TODO(lucacasonato): report correctly from wgpu
-    false
-  }
 
   #[async_method(fake)]
   #[global]
@@ -475,4 +471,10 @@ impl GPUAdapterInfo {
   fn subgroup_max_size(&self) -> u32 {
     self.subgroup_max_size
   }
+
+  #[getter]
+  fn is_fallback_adapter(&self) -> bool {
+    // TODO(lucacasonato): report correctly from wgpu
+    false
+  }
 }