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

refactor: object wrap WebGPU #27665

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
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
336 changes: 204 additions & 132 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ rsa = { version = "0.9.3", default-features = false, features = ["std", "pem", "

# webgpu
raw-window-handle = "0.6.0"
wgpu-core = "0.21.1"
wgpu-types = "0.20"
wgpu-core = "24.0.0"
wgpu-types = "24.0.0"

# macros
quote = "1"
Expand Down
96 changes: 61 additions & 35 deletions cli/tsc/dts/lib.deno_webgpu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ declare class GPUSupportedLimits {
maxBufferSize?: number;
maxVertexAttributes?: number;
maxVertexBufferArrayStride?: number;
maxInterStageShaderComponents?: number;
maxColorAttachments?: number;
maxColorAttachmentBytesPerSample?: number;
maxComputeWorkgroupStorageSize?: number;
Expand Down Expand Up @@ -73,6 +72,8 @@ declare class GPUAdapterInfo {
readonly architecture: string;
readonly device: string;
readonly description: string;
readonly subgroupMinSize: number;
readonly subgroupMaxSize: number;
}

/** @category GPU */
Expand Down Expand Up @@ -105,36 +106,55 @@ declare class GPUAdapter {
/** @category GPU */
interface GPUDeviceDescriptor extends GPUObjectDescriptorBase {
requiredFeatures?: GPUFeatureName[];
requiredLimits?: Record<string, number>;
requiredLimits?: Record<string, number | undefined>;
}

/** @category GPU */
type GPUFeatureName =
| "depth-clip-control"
| "timestamp-query"
| "indirect-first-instance"
| "shader-f16"
| "depth32float-stencil8"
| "pipeline-statistics-query"
| "texture-compression-bc"
| "texture-compression-bc-sliced-3d"
| "texture-compression-etc2"
| "texture-compression-astc"
| "timestamp-query"
| "indirect-first-instance"
| "shader-f16"
| "rg11b10ufloat-renderable"
| "bgra8unorm-storage"
| "float32-filterable"
| "dual-source-blending"
| "subgroups"
// extended from spec
| "texture-format-16-bit-norm"
| "texture-compression-astc-hdr"
| "texture-adapter-specific-format-features"
| "pipeline-statistics-query"
| "timestamp-query-inside-passes"
| "mappable-primary-buffers"
| "sampled-texture-binding-array"
| "sampled-texture-array-dynamic-indexing"
| "sampled-texture-array-non-uniform-indexing"
| "unsized-binding-array"
| "texture-binding-array"
| "buffer-binding-array"
| "storage-resource-binding-array"
| "sampled-texture-and-storage-buffer-array-non-uniform-indexing"
| "uniform-buffer-and-storage-texture-array-non-uniform-indexing"
| "partially-bound-binding-array"
| "multi-draw-indirect"
| "multi-draw-indirect-count"
| "push-constants"
| "address-mode-clamp-to-zero"
| "address-mode-clamp-to-border"
| "texture-adapter-specific-format-features"
| "shader-float64"
| "vertex-attribute-64bit";
| "polygon-mode-line"
| "polygon-mode-point"
| "conservative-rasterization"
| "vertex-writable-storage"
| "clear-texture"
| "spirv-shader-passthrough"
| "multiview"
| "vertex-attribute-64-bit"
| "shader-f64"
| "shader-i16"
| "shader-primitive-index"
| "shader-early-depth-test";

/** @category GPU */
declare class GPUDevice extends EventTarget implements GPUObjectBase {
Expand All @@ -146,6 +166,7 @@ declare class GPUDevice extends EventTarget implements GPUObjectBase {

readonly features: GPUSupportedFeatures;
readonly limits: GPUSupportedLimits;
readonly adapterInfo: GPUAdapterInfo;
readonly queue: GPUQueue;

destroy(): undefined;
Expand Down Expand Up @@ -296,6 +317,7 @@ declare class GPUTextureView implements GPUObjectBase {
interface GPUTextureViewDescriptor extends GPUObjectDescriptorBase {
format?: GPUTextureFormat;
dimension?: GPUTextureViewDimension;
usage?: GPUTextureUsageFlags;
aspect?: GPUTextureAspect;
baseMipLevel?: number;
mipLevelCount?: number;
Expand Down Expand Up @@ -744,7 +766,11 @@ type GPUBlendFactor =
| "one-minus-dst-alpha"
| "src-alpha-saturated"
| "constant"
| "one-minus-constant";
| "one-minus-constant"
| "src1"
| "one-minus-src1"
| "src1-alpha"
| "one-minus-src1-alpha";

/** @category GPU */
type GPUBlendOperation =
Expand All @@ -758,8 +784,8 @@ type GPUBlendOperation =
interface GPUDepthStencilState {
format: GPUTextureFormat;

depthWriteEnabled: boolean;
depthCompare: GPUCompareFunction;
depthWriteEnabled?: boolean;
depthCompare?: GPUCompareFunction;

stencilFront?: GPUStencilFaceState;
stencilBack?: GPUStencilFaceState;
Expand Down Expand Up @@ -852,7 +878,7 @@ interface GPUVertexAttribute {
}

/** @category GPU */
interface GPUImageDataLayout {
interface GPUTexelCopyBufferLayout {
offset?: number;
bytesPerRow?: number;
rowsPerImage?: number;
Expand Down Expand Up @@ -884,20 +910,20 @@ declare class GPUCommandEncoder implements GPUObjectBase {
): undefined;

copyBufferToTexture(
source: GPUImageCopyBuffer,
destination: GPUImageCopyTexture,
source: GPUTexelCopyBufferInfo,
destination: GPUTexelCopyTextureInfo,
copySize: GPUExtent3D,
): undefined;

copyTextureToBuffer(
source: GPUImageCopyTexture,
destination: GPUImageCopyBuffer,
source: GPUTexelCopyTextureInfo,
destination: GPUTexelCopyBufferInfo,
copySize: GPUExtent3D,
): undefined;

copyTextureToTexture(
source: GPUImageCopyTexture,
destination: GPUImageCopyTexture,
source: GPUTexelCopyTextureInfo,
destination: GPUTexelCopyTextureInfo,
copySize: GPUExtent3D,
): undefined;

Expand Down Expand Up @@ -928,12 +954,12 @@ declare class GPUCommandEncoder implements GPUObjectBase {
interface GPUCommandEncoderDescriptor extends GPUObjectDescriptorBase {}

/** @category GPU */
interface GPUImageCopyBuffer extends GPUImageDataLayout {
interface GPUTexelCopyBufferInfo extends GPUTexelCopyBufferLayout {
buffer: GPUBuffer;
}

/** @category GPU */
interface GPUImageCopyTexture {
interface GPUTexelCopyTextureInfo {
texture: GPUTexture;
mipLevel?: number;
origin?: GPUOrigin3D;
Expand All @@ -944,13 +970,13 @@ interface GPUImageCopyTexture {
interface GPUProgrammablePassEncoder {
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsets?: number[],
): undefined;

setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsetsData: Uint32Array,
dynamicOffsetsDataStart: number,
dynamicOffsetsDataLength: number,
Expand All @@ -967,12 +993,12 @@ declare class GPUComputePassEncoder
label: string;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsets?: number[],
): undefined;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsetsData: Uint32Array,
dynamicOffsetsDataStart: number,
dynamicOffsetsDataLength: number,
Expand Down Expand Up @@ -1046,12 +1072,12 @@ declare class GPURenderPassEncoder
label: string;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsets?: number[],
): undefined;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsetsData: Uint32Array,
dynamicOffsetsDataStart: number,
dynamicOffsetsDataLength: number,
Expand Down Expand Up @@ -1198,12 +1224,12 @@ declare class GPURenderBundleEncoder
pushDebugGroup(groupLabel: string): undefined;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsets?: number[],
): undefined;
setBindGroup(
index: number,
bindGroup: GPUBindGroup,
bindGroup: GPUBindGroup | null,
dynamicOffsetsData: Uint32Array,
dynamicOffsetsDataStart: number,
dynamicOffsetsDataLength: number,
Expand Down Expand Up @@ -1255,9 +1281,9 @@ declare class GPUQueue implements GPUObjectBase {
): undefined;

writeTexture(
destination: GPUImageCopyTexture,
destination: GPUTexelCopyTextureInfo,
data: BufferSource,
dataLayout: GPUImageDataLayout,
dataLayout: GPUTexelCopyBufferLayout,
size: GPUExtent3D,
): undefined;
}
Expand Down
1 change: 1 addition & 0 deletions ext/web/02_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ export {
ErrorEvent,
Event,
EventTarget,
EventTargetPrototype,
listenerCount,
MessageEvent,
ProgressEvent,
Expand Down
Loading
Loading