2025-01-01 04:12:39 +09:00
|
|
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
2023-12-09 01:19:16 +01:00
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../../core/lib.deno_core.d.ts" />
|
|
|
|
/// <reference path="../web/internal.d.ts" />
|
2025-02-19 02:53:21 +01:00
|
|
|
/// <reference path="../../cli/tsc/dts/lib.deno_web.d.ts" />
|
|
|
|
/// <reference path="../../cli/tsc/dts/lib.deno_webgpu.d.ts" />
|
2023-12-09 01:19:16 +01:00
|
|
|
|
|
|
|
import { core, primordials } from "ext:core/mod.js";
|
2024-01-26 23:46:46 +01:00
|
|
|
import {
|
2025-02-12 14:45:41 +01:00
|
|
|
GPU,
|
|
|
|
GPUAdapter,
|
|
|
|
GPUAdapterInfo,
|
|
|
|
GPUBindGroup,
|
|
|
|
GPUBindGroupLayout,
|
|
|
|
GPUBuffer,
|
|
|
|
GPUCommandBuffer,
|
|
|
|
GPUCommandEncoder,
|
|
|
|
GPUComputePassEncoder,
|
|
|
|
GPUComputePipeline,
|
|
|
|
GPUDevice,
|
|
|
|
GPUDeviceLostInfo,
|
|
|
|
GPUPipelineLayout,
|
|
|
|
GPUQuerySet,
|
|
|
|
GPUQueue,
|
|
|
|
GPURenderBundle,
|
|
|
|
GPURenderBundleEncoder,
|
|
|
|
GPURenderPassEncoder,
|
|
|
|
GPURenderPipeline,
|
|
|
|
GPUSampler,
|
|
|
|
GPUShaderModule,
|
|
|
|
GPUSupportedFeatures,
|
|
|
|
GPUSupportedLimits,
|
|
|
|
GPUTexture,
|
|
|
|
GPUTextureView,
|
|
|
|
op_create_gpu,
|
2024-01-26 23:46:46 +01:00
|
|
|
} from "ext:core/ops";
|
2023-12-09 01:19:16 +01:00
|
|
|
const {
|
|
|
|
ObjectDefineProperty,
|
|
|
|
ObjectPrototypeIsPrototypeOf,
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectSetPrototypeOf,
|
2023-12-09 01:19:16 +01:00
|
|
|
Symbol,
|
|
|
|
SymbolFor,
|
|
|
|
} = primordials;
|
2024-01-11 07:37:25 +09:00
|
|
|
|
|
|
|
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
2024-05-05 07:22:18 -07:00
|
|
|
import {
|
|
|
|
defineEventHandler,
|
|
|
|
Event,
|
2025-02-12 14:45:41 +01:00
|
|
|
EventTargetPrototype,
|
2024-05-05 07:22:18 -07:00
|
|
|
setEventTargetData,
|
|
|
|
} from "ext:deno_web/02_event.js";
|
2024-01-11 07:37:25 +09:00
|
|
|
import { DOMException } from "ext:deno_web/01_dom_exception.js";
|
|
|
|
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
const customInspect = SymbolFor("Deno.privateCustomInspect");
|
2023-12-09 01:19:16 +01:00
|
|
|
const _message = Symbol("[[message]]");
|
|
|
|
const illegalConstructorKey = Symbol("illegalConstructorKey");
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUError {
|
2023-12-09 01:19:16 +01:00
|
|
|
constructor(key = null) {
|
|
|
|
if (key !== illegalConstructorKey) {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[_message];
|
|
|
|
get message() {
|
|
|
|
webidl.assertBranded(this, GPUErrorPrototype);
|
|
|
|
return this[_message];
|
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
|
|
|
|
[customInspect](inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUErrorPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"message",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
|
|
|
const GPUErrorPrototype = GPUError.prototype;
|
|
|
|
|
|
|
|
class GPUValidationError extends GPUError {
|
|
|
|
/** @param {string} message */
|
|
|
|
constructor(message) {
|
|
|
|
const prefix = "Failed to construct 'GPUValidationError'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
|
|
|
message = webidl.converters.DOMString(message, prefix, "Argument 1");
|
|
|
|
super(illegalConstructorKey);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
this[_message] = message;
|
|
|
|
}
|
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
core.registerErrorClass("GPUValidationError", GPUValidationError);
|
2023-12-09 01:19:16 +01:00
|
|
|
|
|
|
|
class GPUOutOfMemoryError extends GPUError {
|
|
|
|
constructor(message) {
|
|
|
|
const prefix = "Failed to construct 'GPUOutOfMemoryError'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, prefix);
|
|
|
|
message = webidl.converters.DOMString(message, prefix, "Argument 1");
|
|
|
|
super(illegalConstructorKey);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
this[_message] = message;
|
|
|
|
}
|
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
core.registerErrorClass("GPUOutOfMemoryError", GPUOutOfMemoryError);
|
2024-05-05 07:22:18 -07:00
|
|
|
|
|
|
|
class GPUInternalError extends GPUError {
|
|
|
|
constructor() {
|
|
|
|
super(illegalConstructorKey);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
}
|
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
core.registerErrorClass("GPUInternalError", GPUInternalError);
|
|
|
|
|
|
|
|
class GPUPipelineError extends DOMException {
|
|
|
|
#reason;
|
|
|
|
|
|
|
|
constructor(message = "", options = { __proto__: null }) {
|
|
|
|
const prefix = "Failed to construct 'GPUPipelineError'";
|
|
|
|
message = webidl.converters.DOMString(message, prefix, "Argument 1");
|
|
|
|
options = webidl.converters.GPUPipelineErrorInit(
|
|
|
|
options,
|
|
|
|
prefix,
|
|
|
|
"Argument 2",
|
|
|
|
);
|
|
|
|
super(message, "GPUPipelineError");
|
|
|
|
|
|
|
|
this.#reason = options.reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
get reason() {
|
|
|
|
webidl.assertBranded(this, GPUPipelineErrorPrototype);
|
|
|
|
return this.#reason;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const GPUPipelineErrorPrototype = GPUPipelineError.prototype;
|
2024-05-05 07:22:18 -07:00
|
|
|
|
|
|
|
class GPUUncapturedErrorEvent extends Event {
|
|
|
|
#error;
|
|
|
|
|
|
|
|
constructor(type, gpuUncapturedErrorEventInitDict) {
|
|
|
|
super(type, gpuUncapturedErrorEventInitDict);
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
|
|
|
|
const prefix = "Failed to construct 'GPUUncapturedErrorEvent'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, prefix);
|
|
|
|
gpuUncapturedErrorEventInitDict = webidl.converters
|
|
|
|
.GPUUncapturedErrorEventInit(
|
|
|
|
gpuUncapturedErrorEventInitDict,
|
|
|
|
prefix,
|
|
|
|
"Argument 2",
|
|
|
|
);
|
|
|
|
|
|
|
|
this.#error = gpuUncapturedErrorEventInitDict.error;
|
|
|
|
}
|
|
|
|
|
|
|
|
get error() {
|
|
|
|
webidl.assertBranded(this, GPUUncapturedErrorEventPrototype);
|
|
|
|
return this.#error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const GPUUncapturedErrorEventPrototype = GPUUncapturedErrorEvent.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPU, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUAdapter, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUAdapterPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"features",
|
|
|
|
"limits",
|
2024-08-07 18:17:33 +09:00
|
|
|
"info",
|
2023-12-09 01:19:16 +01:00
|
|
|
"isFallbackAdapter",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
const GPUAdapterPrototype = GPUAdapter.prototype;
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUAdapterInfo, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUAdapterInfoPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"vendor",
|
|
|
|
"architecture",
|
|
|
|
"device",
|
|
|
|
"description",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype;
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUSupportedFeatures, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
if (ObjectPrototypeIsPrototypeOf(GPUSupportedFeaturesPrototype, this)) {
|
|
|
|
return `${this.constructor.name} ${
|
|
|
|
// deno-lint-ignore prefer-primordials
|
|
|
|
inspect([...this], inspectOptions)}`;
|
|
|
|
} else {
|
|
|
|
return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
|
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype;
|
2025-02-12 14:45:41 +01:00
|
|
|
webidl.setlikeObjectWrap(GPUSupportedFeaturesPrototype, true);
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUDeviceLostInfo, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUDeviceLostInfoPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"reason",
|
|
|
|
"message",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype;
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUDevice, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUDevicePrototype, this),
|
|
|
|
keys: [
|
|
|
|
"features",
|
|
|
|
"label",
|
|
|
|
"limits",
|
|
|
|
"lost",
|
|
|
|
"queue",
|
|
|
|
// TODO(lucacasonato): emit an UncapturedErrorEvent
|
|
|
|
// "onuncapturederror"
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUDevicePrototype = GPUDevice.prototype;
|
|
|
|
ObjectSetPrototypeOf(GPUDevicePrototype, EventTargetPrototype);
|
|
|
|
defineEventHandler(GPUDevice.prototype, "uncapturederror");
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUQueue, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUQueuePrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUQueuePrototype = GPUQueue.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUBuffer, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUBufferPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
"mapState",
|
|
|
|
"size",
|
|
|
|
"usage",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUBufferPrototype = GPUBuffer.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUBufferUsage {
|
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get MAP_READ() {
|
|
|
|
return 0x0001;
|
|
|
|
}
|
|
|
|
static get MAP_WRITE() {
|
|
|
|
return 0x0002;
|
|
|
|
}
|
|
|
|
static get COPY_SRC() {
|
|
|
|
return 0x0004;
|
|
|
|
}
|
|
|
|
static get COPY_DST() {
|
|
|
|
return 0x0008;
|
|
|
|
}
|
|
|
|
static get INDEX() {
|
|
|
|
return 0x0010;
|
|
|
|
}
|
|
|
|
static get VERTEX() {
|
|
|
|
return 0x0020;
|
|
|
|
}
|
|
|
|
static get UNIFORM() {
|
|
|
|
return 0x0040;
|
|
|
|
}
|
|
|
|
static get STORAGE() {
|
|
|
|
return 0x0080;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get INDIRECT() {
|
|
|
|
return 0x0100;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get QUERY_RESOLVE() {
|
|
|
|
return 0x0200;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUMapMode {
|
2023-12-09 01:19:16 +01:00
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get READ() {
|
|
|
|
return 0x0001;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get WRITE() {
|
|
|
|
return 0x0002;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUTexture, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUTexturePrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
"width",
|
|
|
|
"height",
|
|
|
|
"depthOrArrayLayers",
|
|
|
|
"mipLevelCount",
|
|
|
|
"sampleCount",
|
|
|
|
"dimension",
|
|
|
|
"format",
|
|
|
|
"usage",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
2023-12-09 01:19:16 +01:00
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUTexturePrototype = GPUTexture.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUTextureUsage {
|
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get COPY_SRC() {
|
|
|
|
return 0x01;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get COPY_DST() {
|
|
|
|
return 0x02;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get TEXTURE_BINDING() {
|
|
|
|
return 0x04;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get STORAGE_BINDING() {
|
|
|
|
return 0x08;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get RENDER_ATTACHMENT() {
|
|
|
|
return 0x10;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUTextureView, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUTextureViewPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
2023-12-09 01:19:16 +01:00
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUTextureViewPrototype = GPUTextureView.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUSampler, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect) {
|
|
|
|
return `${this.constructor.name} ${
|
|
|
|
inspect({
|
|
|
|
label: this.label,
|
|
|
|
})
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
});
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUBindGroupLayout, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUBindGroupLayoutPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
2023-12-09 01:19:16 +01:00
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUBindGroupLayoutPrototype = GPUBindGroupLayout.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUPipelineLayout, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUPipelineLayoutPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
2023-12-09 01:19:16 +01:00
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUPipelineLayoutPrototype = GPUPipelineLayout.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUBindGroup, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUBindGroupPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
2023-12-09 01:19:16 +01:00
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUBindGroupPrototype = GPUBindGroup.prototype;
|
2024-05-05 07:22:18 -07:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUShaderModule, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
2023-12-09 01:19:16 +01:00
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
2025-02-12 14:45:41 +01:00
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUShaderModulePrototype, this),
|
2023-12-09 01:19:16 +01:00
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2025-02-12 14:45:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPUShaderModulePrototype = GPUShaderModule.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUShaderStage {
|
2023-12-09 01:19:16 +01:00
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get VERTEX() {
|
|
|
|
return 0x1;
|
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get FRAGMENT() {
|
|
|
|
return 0x2;
|
|
|
|
}
|
2024-11-17 04:14:36 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get COMPUTE() {
|
|
|
|
return 0x4;
|
|
|
|
}
|
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUComputePipeline, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUComputePipelinePrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPUComputePipelinePrototype = GPUComputePipeline.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPURenderPipeline, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPURenderPipelinePrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const GPURenderPipelinePrototype = GPURenderPipeline.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
class GPUColorWrite {
|
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
static get RED() {
|
|
|
|
return 0x1;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get GREEN() {
|
|
|
|
return 0x2;
|
2023-12-09 01:19:16 +01:00
|
|
|
}
|
2025-02-12 14:45:41 +01:00
|
|
|
static get BLUE() {
|
|
|
|
return 0x4;
|
|
|
|
}
|
|
|
|
static get ALPHA() {
|
|
|
|
return 0x8;
|
|
|
|
}
|
|
|
|
static get ALL() {
|
|
|
|
return 0xF;
|
|
|
|
}
|
|
|
|
}
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUCommandEncoder, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUCommandEncoderPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPURenderPassEncoder, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPURenderPassEncoderPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPURenderPassEncoderPrototype = GPURenderPassEncoder.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUComputePassEncoder, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPUComputePassEncoderPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPUComputePassEncoderPrototype = GPUComputePassEncoder.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPUCommandBuffer, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUCommandBufferPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPUCommandBufferPrototype = GPUCommandBuffer.prototype;
|
|
|
|
|
|
|
|
ObjectDefineProperty(GPURenderBundleEncoder, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(
|
|
|
|
GPURenderBundleEncoderPrototype,
|
|
|
|
this,
|
|
|
|
),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPURenderBundleEncoderPrototype = GPURenderBundleEncoder.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
ObjectDefineProperty(GPURenderBundle, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPURenderBundlePrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPURenderBundlePrototype = GPURenderBundle.prototype;
|
|
|
|
|
|
|
|
ObjectDefineProperty(GPUQuerySet, customInspect, {
|
|
|
|
__proto__: null,
|
|
|
|
value(inspect, inspectOptions) {
|
|
|
|
return inspect(
|
|
|
|
createFilteredInspectProxy({
|
|
|
|
object: this,
|
|
|
|
evaluate: ObjectPrototypeIsPrototypeOf(GPUQuerySetPrototype, this),
|
|
|
|
keys: [
|
|
|
|
"label",
|
|
|
|
"type",
|
|
|
|
"count",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
inspectOptions,
|
|
|
|
);
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
2025-02-12 14:45:41 +01:00
|
|
|
});
|
|
|
|
const GPUQuerySetPrototype = GPUQuerySet.prototype;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
// Converters
|
2023-12-09 01:19:16 +01:00
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
webidl.converters["GPUPipelineErrorInit"] = webidl.createDictionaryConverter(
|
|
|
|
"GPUPipelineErrorInit",
|
2023-12-09 01:19:16 +01:00
|
|
|
[
|
2025-02-12 14:45:41 +01:00
|
|
|
{
|
|
|
|
key: "reason",
|
|
|
|
converter: webidl.converters.GPUPipelineErrorReason,
|
|
|
|
required: true,
|
2023-12-09 01:19:16 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
webidl.converters["GPUPipelineErrorReason"] = webidl.createEnumConverter(
|
|
|
|
"GPUPipelineErrorReason",
|
2023-12-09 01:19:16 +01:00
|
|
|
[
|
|
|
|
"validation",
|
2024-05-05 07:22:18 -07:00
|
|
|
"internal",
|
2023-12-09 01:19:16 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
webidl.converters["GPUError"] = webidl.converters.any /* put union here! */;
|
2023-12-09 01:19:16 +01:00
|
|
|
|
|
|
|
const dictMembersGPUUncapturedErrorEventInit = [
|
|
|
|
{ key: "error", converter: webidl.converters["GPUError"], required: true },
|
|
|
|
];
|
|
|
|
webidl.converters["GPUUncapturedErrorEventInit"] = webidl
|
|
|
|
.createDictionaryConverter(
|
|
|
|
"GPUUncapturedErrorEventInit",
|
|
|
|
// dictMembersEventInit,
|
|
|
|
dictMembersGPUUncapturedErrorEventInit,
|
|
|
|
);
|
|
|
|
|
2025-02-12 14:45:41 +01:00
|
|
|
let gpu;
|
|
|
|
function initGPU() {
|
|
|
|
if (!gpu) {
|
|
|
|
gpu = op_create_gpu(
|
|
|
|
webidl.brand,
|
|
|
|
setEventTargetData,
|
|
|
|
GPUUncapturedErrorEvent,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-01-05 19:55:01 +05:30
|
|
|
|
2023-12-09 01:19:16 +01:00
|
|
|
export {
|
|
|
|
GPU,
|
|
|
|
gpu,
|
|
|
|
GPUAdapter,
|
|
|
|
GPUAdapterInfo,
|
|
|
|
GPUBindGroup,
|
|
|
|
GPUBindGroupLayout,
|
|
|
|
GPUBuffer,
|
|
|
|
GPUBufferUsage,
|
|
|
|
GPUColorWrite,
|
|
|
|
GPUCommandBuffer,
|
|
|
|
GPUCommandEncoder,
|
|
|
|
GPUComputePassEncoder,
|
|
|
|
GPUComputePipeline,
|
|
|
|
GPUDevice,
|
|
|
|
GPUDeviceLostInfo,
|
|
|
|
GPUError,
|
2024-05-05 07:22:18 -07:00
|
|
|
GPUInternalError,
|
2023-12-09 01:19:16 +01:00
|
|
|
GPUMapMode,
|
|
|
|
GPUOutOfMemoryError,
|
|
|
|
GPUPipelineLayout,
|
|
|
|
GPUQuerySet,
|
|
|
|
GPUQueue,
|
|
|
|
GPURenderBundle,
|
|
|
|
GPURenderBundleEncoder,
|
|
|
|
GPURenderPassEncoder,
|
|
|
|
GPURenderPipeline,
|
|
|
|
GPUSampler,
|
|
|
|
GPUShaderModule,
|
|
|
|
GPUShaderStage,
|
|
|
|
GPUSupportedFeatures,
|
|
|
|
GPUSupportedLimits,
|
|
|
|
GPUTexture,
|
|
|
|
GPUTextureUsage,
|
|
|
|
GPUTextureView,
|
2024-05-05 07:22:18 -07:00
|
|
|
GPUUncapturedErrorEvent,
|
2023-12-09 01:19:16 +01:00
|
|
|
GPUValidationError,
|
2025-02-12 14:45:41 +01:00
|
|
|
initGPU,
|
2023-12-09 01:19:16 +01:00
|
|
|
};
|