mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
parent
35b0a16a88
commit
287c6e6b47
92
Cargo.lock
generated
92
Cargo.lock
generated
@ -162,11 +162,12 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64-simd"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "781dd20c3aff0bd194fe7d2a977dd92f21c173891f3a03b677359e5fa457e5d5"
|
||||
checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195"
|
||||
dependencies = [
|
||||
"simd-abstraction",
|
||||
"outref",
|
||||
"vsimd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -548,18 +549,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "deno_console"
|
||||
version = "0.84.0"
|
||||
version = "0.92.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1fcedec1b382f40fd1ab38d18edb5715d5cd5f65bd949c83387c43152fd34a8"
|
||||
checksum = "55193bcb66a9a9830e1348280acbb9dd65c67d9a9a0586af9730079886408dce"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deno_core"
|
||||
version = "0.166.0"
|
||||
version = "0.174.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5db7d38c223a683b23b7ff4967572ec863f40397fa1bb792383273629e1e39f"
|
||||
checksum = "8077367e7e7ab2f52f1bc6285af301a1a6328b984991a3ff22236ad79862fce3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@ -582,9 +583,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "deno_ops"
|
||||
version = "0.44.0"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27e85062a5f1a79194e7dd1bb8c664f0979bf5c869a8f2208192cbcb6e18e6e7"
|
||||
checksum = "dc9d81c9e5cd9590be6043546f4565670cb6e6a7de1986fd1c354adce04eb9d4"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"pmutil",
|
||||
@ -597,9 +598,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "deno_url"
|
||||
version = "0.84.0"
|
||||
version = "0.92.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26886a84668c9420acbec6ca83b33a51c68310efdf3cdc7ec797c2f2bc873af8"
|
||||
checksum = "906895a8ba4a95f48c51a32947061bf82f42da8f7c8df787012503f1a6042685"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
"serde",
|
||||
@ -609,9 +610,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "deno_web"
|
||||
version = "0.115.0"
|
||||
version = "0.123.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bacd1dda9935fdc8727057b26b3bdfdb8f72a7dd0b168a2eeb3537c99c5bf1e6"
|
||||
checksum = "af75e7ff90a3f719adc074a8789da16687b9e77a97d67eb727b65fae71262637"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64-simd",
|
||||
@ -637,9 +638,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "deno_webidl"
|
||||
version = "0.84.0"
|
||||
version = "0.92.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cfddf618b405e0399cf923f3ce7d3d7e2b472f817d2fb7f70a12e0cafd849a5"
|
||||
checksum = "387a0cfb076580e0237ba6f1b338ee2688779c6a5e531d4a8a2a82b216917ae0"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
]
|
||||
@ -1727,9 +1728,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "osmesa-sys"
|
||||
@ -1742,9 +1743,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "outref"
|
||||
version = "0.1.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f222829ae9293e33a9f5e9f440c6760a3d450a64affe1846486b140db81c1f4"
|
||||
checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a"
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
@ -2035,9 +2036,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.6.0"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -2050,15 +2051,6 @@ version = "0.6.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "renderdoc-sys"
|
||||
version = "1.0.0"
|
||||
@ -2247,9 +2239,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_v8"
|
||||
version = "0.77.0"
|
||||
version = "0.85.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36203a818a80f973b4b487bfc32d173b2bf78821869513af2f6e8c93938fa0e3"
|
||||
checksum = "dba78050262072324b0b1efba11db7367735251adf7ec734fd75780c598c743b"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"derive_more",
|
||||
@ -2299,15 +2291,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-abstraction"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cadb29c57caadc51ff8346233b5cec1d240b68ce55cf1afc764818791876987"
|
||||
dependencies = [
|
||||
"outref",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.7"
|
||||
@ -2412,16 +2395,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.3.0"
|
||||
version = "3.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
|
||||
checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"remove_dir_all",
|
||||
"winapi",
|
||||
"rustix",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2495,9 +2477,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.24.0"
|
||||
version = "1.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7125661431c26622a80ca5051a2f936c9a678318e0351007b0cc313143024e5c"
|
||||
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
@ -2640,9 +2622,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.1.2"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
|
||||
checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
|
||||
dependencies = [
|
||||
"getrandom 0.2.8",
|
||||
"serde",
|
||||
@ -2650,9 +2632,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "v8"
|
||||
version = "0.60.1"
|
||||
version = "0.64.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07fd5b3ed559897ff02c0f62bc0a5f300bfe79bb4c77a50031b8df771701c628"
|
||||
checksum = "a2287b485fa902172da3722d7e557e083afd63921777e0c6e5c0fba28e6d59d3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"fslock",
|
||||
@ -2672,6 +2654,12 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "vsimd"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64"
|
||||
|
||||
[[package]]
|
||||
name = "waker-fn"
|
||||
version = "1.1.0"
|
||||
|
12
Cargo.toml
12
Cargo.toml
@ -122,13 +122,13 @@ wasm-bindgen-test = "0.3"
|
||||
web-sys = "0.3.61"
|
||||
|
||||
# deno dependencies
|
||||
deno_console = "0.84.0"
|
||||
deno_core = "0.166.0"
|
||||
deno_url = "0.84.0"
|
||||
deno_web = "0.115.0"
|
||||
deno_webidl = "0.84.0"
|
||||
deno_console = "0.92.0"
|
||||
deno_core = "0.174.0"
|
||||
deno_url = "0.92.0"
|
||||
deno_web = "0.123.0"
|
||||
deno_webidl = "0.92.0"
|
||||
deno_webgpu = { path = "./deno_webgpu" }
|
||||
tokio = "1.19.0"
|
||||
tokio = "1.25.0"
|
||||
termcolor = "1.2.0"
|
||||
wgpu-core = { path = "./wgpu-core" }
|
||||
wgpu-types = { path = "./wgpu-types" }
|
||||
|
@ -66,6 +66,7 @@ buf.set(numbers);
|
||||
storageBuffer.unmap();
|
||||
|
||||
const computePipeline = device.createComputePipeline({
|
||||
layout: "auto",
|
||||
compute: {
|
||||
module: shaderModule,
|
||||
entryPoint: "main",
|
||||
@ -91,7 +92,7 @@ const computePass = encoder.beginComputePass();
|
||||
computePass.setPipeline(computePipeline);
|
||||
computePass.setBindGroup(0, bindGroup);
|
||||
computePass.insertDebugMarker("compute collatz iterations");
|
||||
computePass.dispatch(numbers.length);
|
||||
computePass.dispatchWorkgroups(numbers.length);
|
||||
computePass.end();
|
||||
|
||||
encoder.copyBufferToBuffer(storageBuffer, 0, stagingBuffer, 0, size);
|
||||
|
413
cts_runner/src/bootstrap.js
vendored
413
cts_runner/src/bootstrap.js
vendored
@ -5,228 +5,209 @@
|
||||
//
|
||||
delete Object.prototype.__proto__;
|
||||
|
||||
((window) => {
|
||||
const core = Deno.core;
|
||||
const {
|
||||
Error,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
Symbol,
|
||||
StringPrototypeReplace,
|
||||
} = window.__bootstrap.primordials;
|
||||
const webidl = window.__bootstrap.webidl;
|
||||
const eventTarget = window.__bootstrap.eventTarget;
|
||||
const globalInterfaces = window.__bootstrap.globalInterfaces;
|
||||
const { Console } = window.__bootstrap.console;
|
||||
const timers = window.__bootstrap.timers;
|
||||
const base64 = window.__bootstrap.base64;
|
||||
const encoding = window.__bootstrap.encoding;
|
||||
const url = window.__bootstrap.url;
|
||||
const domException = window.__bootstrap.domException;
|
||||
const performance = window.__bootstrap.performance;
|
||||
const webgpu = window.__bootstrap.webgpu;
|
||||
const core = Deno.core;
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const {
|
||||
Error,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
ObjectSetPrototypeOf,
|
||||
Symbol,
|
||||
DateNow,
|
||||
} = primordials;
|
||||
|
||||
const util = {
|
||||
immutableDefine(o, p, value) {
|
||||
ObjectDefineProperty(o, p, {
|
||||
value,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
});
|
||||
},
|
||||
writable(value) {
|
||||
return {
|
||||
value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
nonEnumerable(value) {
|
||||
return {
|
||||
value,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
readOnly(value) {
|
||||
return {
|
||||
value,
|
||||
enumerable: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
import { pathFromURL } from "ext:deno_web/00_infra.js";
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js";
|
||||
import * as event from "ext:deno_web/02_event.js";
|
||||
import * as timers from "ext:deno_web/02_timers.js";
|
||||
import * as base64 from "ext:deno_web/05_base64.js";
|
||||
import * as encoding from "ext:deno_web/08_text_encoding.js";
|
||||
import { Console } from "ext:deno_console/02_console.js";
|
||||
import * as url from "ext:deno_url/00_url.js";
|
||||
import DOMException from "ext:deno_web/01_dom_exception.js";
|
||||
import * as performance from "ext:deno_web/15_performance.js";
|
||||
import * as webgpu from "ext:deno_webgpu/01_webgpu.js";
|
||||
|
||||
class Navigator {
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
let globalThis_;
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({})}`;
|
||||
}
|
||||
}
|
||||
|
||||
const navigator = webidl.createBranded(Navigator);
|
||||
|
||||
ObjectDefineProperties(Navigator.prototype, {
|
||||
gpu: {
|
||||
configurable: true,
|
||||
const util = {
|
||||
writable(value) {
|
||||
return {
|
||||
value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
webidl.assertBranded(this, Navigator);
|
||||
return webgpu.gpu;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const windowOrWorkerGlobalScope = {
|
||||
CloseEvent: util.nonEnumerable(CloseEvent),
|
||||
CustomEvent: util.nonEnumerable(CustomEvent),
|
||||
DOMException: util.nonEnumerable(domException.DOMException),
|
||||
ErrorEvent: util.nonEnumerable(ErrorEvent),
|
||||
Event: util.nonEnumerable(Event),
|
||||
EventTarget: util.nonEnumerable(EventTarget),
|
||||
Navigator: util.nonEnumerable(Navigator),
|
||||
navigator: {
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
nonEnumerable(value) {
|
||||
return {
|
||||
value,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
readOnly(value) {
|
||||
return {
|
||||
value,
|
||||
enumerable: true,
|
||||
get: () => navigator,
|
||||
},
|
||||
Performance: util.nonEnumerable(performance.Performance),
|
||||
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
|
||||
PerformanceMark: util.nonEnumerable(performance.PerformanceMark),
|
||||
PerformanceMeasure: util.nonEnumerable(performance.PerformanceMeasure),
|
||||
TextDecoder: util.nonEnumerable(encoding.TextDecoder),
|
||||
TextEncoder: util.nonEnumerable(encoding.TextEncoder),
|
||||
URL: util.nonEnumerable(url.URL),
|
||||
URLSearchParams: util.nonEnumerable(url.URLSearchParams),
|
||||
atob: util.writable(base64.atob),
|
||||
btoa: util.writable(base64.btoa),
|
||||
console: util.writable(new Console(core.print)),
|
||||
setInterval: util.writable(timers.setInterval),
|
||||
setTimeout: util.writable(timers.setTimeout),
|
||||
clearInterval: util.writable(timers.clearInterval),
|
||||
clearTimeout: util.writable(timers.clearTimeout),
|
||||
performance: util.writable(performance.performance),
|
||||
|
||||
GPU: util.nonEnumerable(webgpu.GPU),
|
||||
GPUAdapter: util.nonEnumerable(webgpu.GPUAdapter),
|
||||
GPUAdapterLimits: util.nonEnumerable(webgpu.GPUAdapterLimits),
|
||||
GPUSupportedFeatures: util.nonEnumerable(webgpu.GPUSupportedFeatures),
|
||||
GPUDevice: util.nonEnumerable(webgpu.GPUDevice),
|
||||
GPUQueue: util.nonEnumerable(webgpu.GPUQueue),
|
||||
GPUBuffer: util.nonEnumerable(webgpu.GPUBuffer),
|
||||
GPUBufferUsage: util.nonEnumerable(webgpu.GPUBufferUsage),
|
||||
GPUMapMode: util.nonEnumerable(webgpu.GPUMapMode),
|
||||
GPUTexture: util.nonEnumerable(webgpu.GPUTexture),
|
||||
GPUTextureUsage: util.nonEnumerable(webgpu.GPUTextureUsage),
|
||||
GPUTextureView: util.nonEnumerable(webgpu.GPUTextureView),
|
||||
GPUSampler: util.nonEnumerable(webgpu.GPUSampler),
|
||||
GPUBindGroupLayout: util.nonEnumerable(webgpu.GPUBindGroupLayout),
|
||||
GPUPipelineLayout: util.nonEnumerable(webgpu.GPUPipelineLayout),
|
||||
GPUBindGroup: util.nonEnumerable(webgpu.GPUBindGroup),
|
||||
GPUShaderModule: util.nonEnumerable(webgpu.GPUShaderModule),
|
||||
GPUShaderStage: util.nonEnumerable(webgpu.GPUShaderStage),
|
||||
GPUComputePipeline: util.nonEnumerable(webgpu.GPUComputePipeline),
|
||||
GPURenderPipeline: util.nonEnumerable(webgpu.GPURenderPipeline),
|
||||
GPUColorWrite: util.nonEnumerable(webgpu.GPUColorWrite),
|
||||
GPUCommandEncoder: util.nonEnumerable(webgpu.GPUCommandEncoder),
|
||||
GPURenderPassEncoder: util.nonEnumerable(webgpu.GPURenderPassEncoder),
|
||||
GPUComputePassEncoder: util.nonEnumerable(webgpu.GPUComputePassEncoder),
|
||||
GPUCommandBuffer: util.nonEnumerable(webgpu.GPUCommandBuffer),
|
||||
GPURenderBundleEncoder: util.nonEnumerable(webgpu.GPURenderBundleEncoder),
|
||||
GPURenderBundle: util.nonEnumerable(webgpu.GPURenderBundle),
|
||||
GPUQuerySet: util.nonEnumerable(webgpu.GPUQuerySet),
|
||||
GPUOutOfMemoryError: util.nonEnumerable(webgpu.GPUOutOfMemoryError),
|
||||
GPUValidationError: util.nonEnumerable(webgpu.GPUValidationError),
|
||||
};
|
||||
|
||||
windowOrWorkerGlobalScope.console.enumerable = false;
|
||||
|
||||
const mainRuntimeGlobalProperties = {
|
||||
Window: globalInterfaces.windowConstructorDescriptor,
|
||||
window: util.readOnly(globalThis),
|
||||
self: util.readOnly(globalThis),
|
||||
};
|
||||
|
||||
// Taken from deno/runtime/js/06_util.js
|
||||
function pathFromURL(pathOrUrl) {
|
||||
if (pathOrUrl instanceof URL) {
|
||||
if (pathOrUrl.protocol != "file:") {
|
||||
throw new TypeError("Must be a file URL.");
|
||||
}
|
||||
if (pathOrUrl.hostname !== "") {
|
||||
throw new TypeError("Host must be empty.");
|
||||
}
|
||||
return decodeURIComponent(
|
||||
StringPrototypeReplace(
|
||||
pathOrUrl.pathname,
|
||||
/%(?![0-9A-Fa-f]{2})/g,
|
||||
"%25",
|
||||
),
|
||||
);
|
||||
}
|
||||
return pathOrUrl;
|
||||
}
|
||||
|
||||
const denoNs = {
|
||||
exit(code) {
|
||||
core.opSync("op_exit", code);
|
||||
},
|
||||
readFileSync(path) {
|
||||
return core.opSync("op_read_file_sync", pathFromURL(path));
|
||||
},
|
||||
readTextFileSync(path) {
|
||||
const buf = core.opSync("op_read_file_sync", pathFromURL(path));
|
||||
const decoder = new TextDecoder();
|
||||
return decoder.decode(buf);
|
||||
},
|
||||
writeFileSync(path, buf) {
|
||||
return core.opSync("op_write_file_sync", pathFromURL(path), buf);
|
||||
},
|
||||
};
|
||||
|
||||
function registerErrors() {
|
||||
core.registerErrorBuilder(
|
||||
"DOMExceptionOperationError",
|
||||
function DOMExceptionOperationError(msg) {
|
||||
return new DOMException(msg, "OperationError");
|
||||
};
|
||||
},
|
||||
getterOnly(getter) {
|
||||
return {
|
||||
get: getter,
|
||||
set() {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let hasBootstrapped = false;
|
||||
|
||||
function bootstrapRuntime({ args, cwd }) {
|
||||
core.setMacrotaskCallback(timers.handleTimerMacrotask);
|
||||
if (hasBootstrapped) {
|
||||
throw new Error("Runtime has already been bootstrapped.");
|
||||
}
|
||||
delete globalThis.__bootstrap;
|
||||
delete globalThis.bootstrap;
|
||||
hasBootstrapped = true;
|
||||
|
||||
registerErrors();
|
||||
|
||||
Object.defineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
Object.defineProperties(globalThis, mainRuntimeGlobalProperties);
|
||||
Object.setPrototypeOf(globalThis, Window.prototype);
|
||||
eventTarget.setEventTargetData(globalThis);
|
||||
|
||||
denoNs.args = args;
|
||||
denoNs.cwd = () => cwd;
|
||||
util.immutableDefine(globalThis, "Deno", denoNs);
|
||||
Object.freeze(globalThis.Deno);
|
||||
|
||||
core.ops();
|
||||
Error.prepareStackTrace = core.createPrepareStackTrace();
|
||||
}
|
||||
|
||||
ObjectDefineProperties(globalThis, {
|
||||
bootstrap: {
|
||||
value: bootstrapRuntime,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
class Navigator {
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
[Symbol.for("Deno.customInspect")](inspect) {
|
||||
return `${this.constructor.name} ${inspect({})}`;
|
||||
}
|
||||
}
|
||||
const NavigatorPrototype = Navigator.prototype;
|
||||
|
||||
const navigator = webidl.createBranded(Navigator);
|
||||
|
||||
ObjectDefineProperties(Navigator.prototype, {
|
||||
gpu: {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
webidl.assertBranded(this, NavigatorPrototype);
|
||||
return webgpu.gpu;
|
||||
},
|
||||
});
|
||||
})(globalThis);
|
||||
},
|
||||
});
|
||||
|
||||
const windowOrWorkerGlobalScope = {
|
||||
CloseEvent: util.nonEnumerable(event.CloseEvent),
|
||||
CustomEvent: util.nonEnumerable(event.CustomEvent),
|
||||
DOMException: util.nonEnumerable(DOMException),
|
||||
ErrorEvent: util.nonEnumerable(event.ErrorEvent),
|
||||
Event: util.nonEnumerable(event.Event),
|
||||
EventTarget: util.nonEnumerable(event.EventTarget),
|
||||
Navigator: util.nonEnumerable(Navigator),
|
||||
navigator: util.getterOnly(() => navigator),
|
||||
Performance: util.nonEnumerable(performance.Performance),
|
||||
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
|
||||
PerformanceMark: util.nonEnumerable(performance.PerformanceMark),
|
||||
PerformanceMeasure: util.nonEnumerable(performance.PerformanceMeasure),
|
||||
TextDecoder: util.nonEnumerable(encoding.TextDecoder),
|
||||
TextEncoder: util.nonEnumerable(encoding.TextEncoder),
|
||||
URL: util.nonEnumerable(url.URL),
|
||||
URLSearchParams: util.nonEnumerable(url.URLSearchParams),
|
||||
atob: util.writable(base64.atob),
|
||||
btoa: util.writable(base64.btoa),
|
||||
console: util.writable(new Console(core.print)),
|
||||
setInterval: util.writable(timers.setInterval),
|
||||
setTimeout: util.writable(timers.setTimeout),
|
||||
clearInterval: util.writable(timers.clearInterval),
|
||||
clearTimeout: util.writable(timers.clearTimeout),
|
||||
performance: util.writable(performance.performance),
|
||||
|
||||
GPU: util.nonEnumerable(webgpu.GPU),
|
||||
GPUAdapter: util.nonEnumerable(webgpu.GPUAdapter),
|
||||
GPUAdapterLimits: util.nonEnumerable(webgpu.GPUAdapterLimits),
|
||||
GPUSupportedFeatures: util.nonEnumerable(webgpu.GPUSupportedFeatures),
|
||||
GPUDevice: util.nonEnumerable(webgpu.GPUDevice),
|
||||
GPUQueue: util.nonEnumerable(webgpu.GPUQueue),
|
||||
GPUBuffer: util.nonEnumerable(webgpu.GPUBuffer),
|
||||
GPUBufferUsage: util.nonEnumerable(webgpu.GPUBufferUsage),
|
||||
GPUMapMode: util.nonEnumerable(webgpu.GPUMapMode),
|
||||
GPUTexture: util.nonEnumerable(webgpu.GPUTexture),
|
||||
GPUTextureUsage: util.nonEnumerable(webgpu.GPUTextureUsage),
|
||||
GPUTextureView: util.nonEnumerable(webgpu.GPUTextureView),
|
||||
GPUSampler: util.nonEnumerable(webgpu.GPUSampler),
|
||||
GPUBindGroupLayout: util.nonEnumerable(webgpu.GPUBindGroupLayout),
|
||||
GPUPipelineLayout: util.nonEnumerable(webgpu.GPUPipelineLayout),
|
||||
GPUBindGroup: util.nonEnumerable(webgpu.GPUBindGroup),
|
||||
GPUShaderModule: util.nonEnumerable(webgpu.GPUShaderModule),
|
||||
GPUShaderStage: util.nonEnumerable(webgpu.GPUShaderStage),
|
||||
GPUComputePipeline: util.nonEnumerable(webgpu.GPUComputePipeline),
|
||||
GPURenderPipeline: util.nonEnumerable(webgpu.GPURenderPipeline),
|
||||
GPUColorWrite: util.nonEnumerable(webgpu.GPUColorWrite),
|
||||
GPUCommandEncoder: util.nonEnumerable(webgpu.GPUCommandEncoder),
|
||||
GPURenderPassEncoder: util.nonEnumerable(webgpu.GPURenderPassEncoder),
|
||||
GPUComputePassEncoder: util.nonEnumerable(webgpu.GPUComputePassEncoder),
|
||||
GPUCommandBuffer: util.nonEnumerable(webgpu.GPUCommandBuffer),
|
||||
GPURenderBundleEncoder: util.nonEnumerable(webgpu.GPURenderBundleEncoder),
|
||||
GPURenderBundle: util.nonEnumerable(webgpu.GPURenderBundle),
|
||||
GPUQuerySet: util.nonEnumerable(webgpu.GPUQuerySet),
|
||||
GPUOutOfMemoryError: util.nonEnumerable(webgpu.GPUOutOfMemoryError),
|
||||
GPUValidationError: util.nonEnumerable(webgpu.GPUValidationError),
|
||||
};
|
||||
|
||||
windowOrWorkerGlobalScope.console.enumerable = false;
|
||||
|
||||
const mainRuntimeGlobalProperties = {
|
||||
Window: globalInterfaces.windowConstructorDescriptor,
|
||||
window: util.readOnly(globalThis),
|
||||
self: util.readOnly(globalThis),
|
||||
};
|
||||
|
||||
const denoNs = {
|
||||
exit(code) {
|
||||
core.opSync("op_exit", code);
|
||||
},
|
||||
readFileSync(path) {
|
||||
return core.opSync("op_read_file_sync", pathFromURL(path));
|
||||
},
|
||||
readTextFileSync(path) {
|
||||
const buf = core.opSync("op_read_file_sync", pathFromURL(path));
|
||||
const decoder = new TextDecoder();
|
||||
return decoder.decode(buf);
|
||||
},
|
||||
writeFileSync(path, buf) {
|
||||
return core.opSync("op_write_file_sync", pathFromURL(path), buf);
|
||||
},
|
||||
};
|
||||
|
||||
core.registerErrorBuilder(
|
||||
"DOMExceptionOperationError",
|
||||
function DOMExceptionOperationError(msg) {
|
||||
return new DOMException(msg, "OperationError");
|
||||
},
|
||||
);
|
||||
|
||||
let hasBootstrapped = false;
|
||||
|
||||
function bootstrapRuntime({ args, cwd }) {
|
||||
if (hasBootstrapped) {
|
||||
throw new Error("Runtime has already been bootstrapped.");
|
||||
}
|
||||
performance.setTimeOrigin(DateNow());
|
||||
globalThis_ = globalThis;
|
||||
|
||||
// Remove bootstrapping data from the global scope
|
||||
delete globalThis.__bootstrap;
|
||||
delete globalThis.bootstrap;
|
||||
hasBootstrapped = true;
|
||||
|
||||
event.setEventTargetData(globalThis);
|
||||
event.saveGlobalThisReference(globalThis);
|
||||
|
||||
Error.prepareStackTrace = core.prepareStackTrace;
|
||||
|
||||
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
|
||||
ObjectSetPrototypeOf(globalThis, Window.prototype);
|
||||
event.setEventTargetData(globalThis);
|
||||
|
||||
denoNs.args = args;
|
||||
denoNs.cwd = () => cwd;
|
||||
|
||||
ObjectDefineProperty(globalThis, "Deno", util.readOnly(denoNs));
|
||||
|
||||
Error.prepareStackTrace = core.prepareStackTrace;
|
||||
}
|
||||
|
||||
globalThis.bootstrap = bootstrapRuntime;
|
||||
|
@ -6,11 +6,10 @@ use std::{
|
||||
|
||||
use deno_core::anyhow::anyhow;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::located_script_name;
|
||||
use deno_core::op;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::v8;
|
||||
use deno_core::JsRuntime;
|
||||
use deno_core::RuntimeOptions;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
@ -37,11 +36,11 @@ async fn run() -> Result<(), AnyError> {
|
||||
module_loader: Some(Rc::new(deno_core::FsModuleLoader)),
|
||||
get_error_class_fn: Some(&get_error_class_name),
|
||||
extensions: vec![
|
||||
deno_webidl::init(),
|
||||
deno_console::init(),
|
||||
deno_url::init(),
|
||||
deno_web::init::<Permissions>(BlobStore::default(), None),
|
||||
deno_webgpu::init(true),
|
||||
deno_webidl::init_esm(),
|
||||
deno_console::init_esm(),
|
||||
deno_url::init_ops_and_esm(),
|
||||
deno_web::init_ops_and_esm::<Permissions>(BlobStore::default(), None),
|
||||
deno_webgpu::init_ops_and_esm(true),
|
||||
extension(),
|
||||
],
|
||||
..Default::default()
|
||||
@ -49,8 +48,23 @@ async fn run() -> Result<(), AnyError> {
|
||||
let mut isolate = JsRuntime::new(options);
|
||||
let args = args_iter.collect::<Vec<String>>();
|
||||
let cfg = json!({"args": args, "cwd": env::current_dir().unwrap().to_string_lossy() });
|
||||
let bootstrap_script = format!("globalThis.bootstrap({})", serde_json::to_string(&cfg)?);
|
||||
isolate.execute_script(&located_script_name!(), &bootstrap_script)?;
|
||||
|
||||
{
|
||||
let context = isolate.global_context();
|
||||
let scope = &mut isolate.handle_scope();
|
||||
let context_local = v8::Local::new(scope, context);
|
||||
let global_obj = context_local.global(scope);
|
||||
let bootstrap_str = v8::String::new(scope, "bootstrap").unwrap();
|
||||
let bootstrap_fn = global_obj.get(scope, bootstrap_str.into()).unwrap();
|
||||
let bootstrap_fn = v8::Local::<v8::Function>::try_from(bootstrap_fn).unwrap();
|
||||
|
||||
let options_v8 = deno_core::serde_v8::to_v8(scope, cfg).unwrap();
|
||||
let bootstrap_fn = v8::Local::new(scope, bootstrap_fn);
|
||||
let undefined = v8::undefined(scope);
|
||||
bootstrap_fn
|
||||
.call(scope, undefined.into(), &[options_v8])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
isolate.op_state().borrow_mut().put(Permissions {});
|
||||
|
||||
@ -71,16 +85,13 @@ async fn run() -> Result<(), AnyError> {
|
||||
}
|
||||
|
||||
fn extension() -> deno_core::Extension {
|
||||
deno_core::Extension::builder("bootstrap")
|
||||
deno_core::Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.ops(vec![
|
||||
op_exit::decl(),
|
||||
op_read_file_sync::decl(),
|
||||
op_write_file_sync::decl(),
|
||||
])
|
||||
.js(deno_core::include_js_files!(
|
||||
prefix "deno:cts_runner",
|
||||
"bootstrap.js",
|
||||
))
|
||||
.esm(deno_core::include_js_files!("bootstrap.js",))
|
||||
.build()
|
||||
}
|
||||
|
||||
|
5246
deno_webgpu/01_webgpu.js
Normal file
5246
deno_webgpu/01_webgpu.js
Normal file
File diff suppressed because it is too large
Load Diff
2055
deno_webgpu/02_idl_types.js
Normal file
2055
deno_webgpu/02_idl_types.js
Normal file
File diff suppressed because it is too large
Load Diff
137
deno_webgpu/03_surface.js
Normal file
137
deno_webgpu/03_surface.js
Normal file
@ -0,0 +1,137 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// @ts-check
|
||||
/// <reference path="../../core/lib.deno_core.d.ts" />
|
||||
/// <reference path="../web/internal.d.ts" />
|
||||
/// <reference path="../web/lib.deno_web.d.ts" />
|
||||
/// <reference path="./lib.deno_webgpu.d.ts" />
|
||||
|
||||
const core = globalThis.Deno.core;
|
||||
const ops = core.ops;
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
const { Symbol } = primordials;
|
||||
import {
|
||||
_device,
|
||||
assertDevice,
|
||||
createGPUTexture,
|
||||
} from "ext:deno_webgpu/01_webgpu.js";
|
||||
|
||||
const _surfaceRid = Symbol("[[surfaceRid]]");
|
||||
const _configuration = Symbol("[[configuration]]");
|
||||
const _canvas = Symbol("[[canvas]]");
|
||||
const _currentTexture = Symbol("[[currentTexture]]");
|
||||
class GPUCanvasContext {
|
||||
/** @type {number} */
|
||||
[_surfaceRid];
|
||||
/** @type {InnerGPUDevice} */
|
||||
[_device];
|
||||
[_configuration];
|
||||
[_canvas];
|
||||
/** @type {GPUTexture | undefined} */
|
||||
[_currentTexture];
|
||||
|
||||
get canvas() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
return this[_canvas];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
configure(configuration) {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'configure' on 'GPUCanvasContext'";
|
||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||
configuration = webidl.converters.GPUCanvasConfiguration(configuration, {
|
||||
prefix,
|
||||
context: "Argument 1",
|
||||
});
|
||||
|
||||
this[_device] = configuration.device[_device];
|
||||
this[_configuration] = configuration;
|
||||
const device = assertDevice(this, { prefix, context: "configuration.device" });
|
||||
|
||||
const { err } = ops.op_webgpu_surface_configure({
|
||||
surfaceRid: this[_surfaceRid],
|
||||
deviceRid: device.rid,
|
||||
format: configuration.format,
|
||||
viewFormats: configuration.viewFormats,
|
||||
usage: configuration.usage,
|
||||
width: configuration.width,
|
||||
height: configuration.height,
|
||||
alphaMode: configuration.alphaMode,
|
||||
});
|
||||
|
||||
device.pushError(err);
|
||||
}
|
||||
|
||||
unconfigure() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
|
||||
this[_configuration] = null;
|
||||
this[_device] = null;
|
||||
}
|
||||
|
||||
getCurrentTexture() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'getCurrentTexture' on 'GPUCanvasContext'";
|
||||
|
||||
if (this[_configuration] === null) {
|
||||
throw new DOMException("context is not configured.", "InvalidStateError");
|
||||
}
|
||||
|
||||
const device = assertDevice(this, { prefix, context: "this" });
|
||||
|
||||
if (this[_currentTexture]) {
|
||||
return this[_currentTexture];
|
||||
}
|
||||
|
||||
const { rid } = ops.op_webgpu_surface_get_current_texture(device.rid, this[_surfaceRid]);
|
||||
|
||||
const texture = createGPUTexture(
|
||||
{
|
||||
size: {
|
||||
width: this[_configuration].width,
|
||||
height: this[_configuration].height,
|
||||
depthOrArrayLayers: 1,
|
||||
},
|
||||
mipLevelCount: 1,
|
||||
sampleCount: 1,
|
||||
dimension: "2d",
|
||||
format: this[_configuration].format,
|
||||
usage: this[_configuration].usage,
|
||||
},
|
||||
device,
|
||||
rid,
|
||||
);
|
||||
device.trackResource(texture);
|
||||
this[_currentTexture] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Extended from spec. Required to present the texture; browser don't need this.
|
||||
present() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'present' on 'GPUCanvasContext'";
|
||||
const device = assertDevice(this[_currentTexture], { prefix, context: "this" });
|
||||
ops.op_webgpu_surface_present(device.rid, this[_surfaceRid]);
|
||||
this[_currentTexture].destroy();
|
||||
this[_currentTexture] = undefined;
|
||||
}
|
||||
}
|
||||
const GPUCanvasContextPrototype = GPUCanvasContext.prototype;
|
||||
|
||||
function createCanvasContext(options) {
|
||||
const canvasContext = webidl.createBranded(GPUCanvasContext);
|
||||
canvasContext[_surfaceRid] = options.surfaceRid;
|
||||
canvasContext[_canvas] = options.canvas;
|
||||
return canvasContext;
|
||||
}
|
||||
|
||||
window.__bootstrap.webgpu = {
|
||||
...window.__bootstrap.webgpu,
|
||||
GPUCanvasContext,
|
||||
createCanvasContext,
|
||||
};
|
82
deno_webgpu/04_surface_idl_types.js
Normal file
82
deno_webgpu/04_surface_idl_types.js
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// @ts-check
|
||||
/// <reference path="../../core/lib.deno_core.d.ts" />
|
||||
/// <reference path="../web/internal.d.ts" />
|
||||
/// <reference path="../web/lib.deno_web.d.ts" />
|
||||
/// <reference path="./lib.deno_webgpu.d.ts" />
|
||||
|
||||
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
||||
import { GPUTextureUsage } from "ext:deno_webgpu/01_webgpu.js";
|
||||
|
||||
// ENUM: GPUCanvasAlphaMode
|
||||
webidl.converters["GPUCanvasAlphaMode"] = webidl.createEnumConverter(
|
||||
"GPUCanvasAlphaMode",
|
||||
[
|
||||
"opaque",
|
||||
"premultiplied",
|
||||
],
|
||||
);
|
||||
|
||||
// NON-SPEC: ENUM: GPUPresentMode
|
||||
webidl.converters["GPUPresentMode"] = webidl.createEnumConverter(
|
||||
"GPUPresentMode",
|
||||
[
|
||||
"autoVsync",
|
||||
"autoNoVsync",
|
||||
"fifo",
|
||||
"fifoRelaxed",
|
||||
"immediate",
|
||||
"mailbox",
|
||||
],
|
||||
);
|
||||
|
||||
// DICT: GPUCanvasConfiguration
|
||||
const dictMembersGPUCanvasConfiguration = [
|
||||
{ key: "device", converter: webidl.converters.GPUDevice, required: true },
|
||||
{
|
||||
key: "format",
|
||||
converter: webidl.converters.GPUTextureFormat,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "usage",
|
||||
converter: webidl.converters["GPUTextureUsageFlags"],
|
||||
defaultValue: GPUTextureUsage.RENDER_ATTACHMENT,
|
||||
},
|
||||
{
|
||||
key: "alphaMode",
|
||||
converter: webidl.converters["GPUCanvasAlphaMode"],
|
||||
defaultValue: "opaque",
|
||||
},
|
||||
|
||||
// Extended from spec
|
||||
{
|
||||
key: "presentMode",
|
||||
converter: webidl.converters["GPUPresentMode"],
|
||||
},
|
||||
{
|
||||
key: "width",
|
||||
converter: webidl.converters["long"],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "height",
|
||||
converter: webidl.converters["long"],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "viewFormats",
|
||||
converter: webidl.createSequenceConverter(
|
||||
webidl.converters["GPUTextureFormat"],
|
||||
),
|
||||
get defaultValue() {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
];
|
||||
webidl.converters["GPUCanvasConfiguration"] = webidl
|
||||
.createDictionaryConverter(
|
||||
"GPUCanvasConfiguration",
|
||||
dictMembersGPUCanvasConfiguration,
|
||||
);
|
@ -10,6 +10,9 @@ readme = "README.md"
|
||||
repository.workspace = true
|
||||
description = "WebGPU implementation for Deno"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[features]
|
||||
surface = ["wgpu-core/raw-window-handle", "dep:raw-window-handle"]
|
||||
|
||||
|
@ -6,6 +6,7 @@ use deno_core::error::AnyError;
|
||||
use deno_core::include_js_files;
|
||||
use deno_core::op;
|
||||
use deno_core::Extension;
|
||||
use deno_core::ExtensionBuilder;
|
||||
use deno_core::OpState;
|
||||
use deno_core::Resource;
|
||||
use deno_core::ResourceId;
|
||||
@ -131,26 +132,30 @@ impl Resource for WebGpuQuerySet {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(unstable: bool) -> Extension {
|
||||
Extension::builder(env!("CARGO_PKG_NAME"))
|
||||
.dependencies(vec!["deno_webidl", "deno_web"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:deno_webgpu",
|
||||
"01_webgpu.js",
|
||||
"02_idl_types.js",
|
||||
))
|
||||
.ops(declare_webgpu_ops())
|
||||
.state(move |state| {
|
||||
// TODO: check & possibly streamline this
|
||||
// Unstable might be able to be OpMiddleware
|
||||
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
||||
// let unstable = unstable_checker.unstable;
|
||||
state.put(Unstable(unstable));
|
||||
Ok(())
|
||||
})
|
||||
fn ext() -> ExtensionBuilder {
|
||||
Extension::builder_with_deps(env!("CARGO_PKG_NAME"), &["deno_webidl", "deno_web"])
|
||||
}
|
||||
|
||||
fn ops(ext: &mut ExtensionBuilder, unstable: bool) -> &mut ExtensionBuilder {
|
||||
ext.ops(declare_webgpu_ops()).state(move |state| {
|
||||
// TODO: check & possibly streamline this
|
||||
// Unstable might be able to be OpMiddleware
|
||||
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
||||
// let unstable = unstable_checker.unstable;
|
||||
state.put(Unstable(unstable));
|
||||
})
|
||||
}
|
||||
|
||||
pub fn init_ops_and_esm(unstable: bool) -> Extension {
|
||||
ops(&mut ext(), unstable)
|
||||
.esm(include_js_files!("01_webgpu.js", "02_idl_types.js",))
|
||||
.build()
|
||||
}
|
||||
|
||||
pub fn init_ops(unstable: bool) -> Extension {
|
||||
ops(&mut ext(), unstable).build()
|
||||
}
|
||||
|
||||
fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
|
||||
let mut return_features: Vec<&'static str> = vec![];
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,136 +0,0 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// @ts-check
|
||||
/// <reference path="../../core/lib.deno_core.d.ts" />
|
||||
/// <reference path="../web/internal.d.ts" />
|
||||
/// <reference path="../web/lib.deno_web.d.ts" />
|
||||
/// <reference path="./lib.deno_webgpu.d.ts" />
|
||||
|
||||
"use strict";
|
||||
|
||||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const ops = core.ops;
|
||||
const webidl = window.__bootstrap.webidl;
|
||||
const { Symbol } = window.__bootstrap.primordials;
|
||||
const { _device, assertDevice, createGPUTexture } = window.__bootstrap.webgpu;
|
||||
|
||||
const _surfaceRid = Symbol("[[surfaceRid]]");
|
||||
const _configuration = Symbol("[[configuration]]");
|
||||
const _canvas = Symbol("[[canvas]]");
|
||||
const _currentTexture = Symbol("[[currentTexture]]");
|
||||
class GPUCanvasContext {
|
||||
/** @type {number} */
|
||||
[_surfaceRid];
|
||||
/** @type {InnerGPUDevice} */
|
||||
[_device];
|
||||
[_configuration];
|
||||
[_canvas];
|
||||
/** @type {GPUTexture | undefined} */
|
||||
[_currentTexture];
|
||||
|
||||
get canvas() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
return this[_canvas];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
webidl.illegalConstructor();
|
||||
}
|
||||
|
||||
configure(configuration) {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'configure' on 'GPUCanvasContext'";
|
||||
webidl.requiredArguments(arguments.length, 1, { prefix });
|
||||
configuration = webidl.converters.GPUCanvasConfiguration(configuration, {
|
||||
prefix,
|
||||
context: "Argument 1",
|
||||
});
|
||||
|
||||
this[_device] = configuration.device[_device];
|
||||
this[_configuration] = configuration;
|
||||
const device = assertDevice(this, { prefix, context: "configuration.device" });
|
||||
|
||||
const { err } = ops.op_webgpu_surface_configure({
|
||||
surfaceRid: this[_surfaceRid],
|
||||
deviceRid: device.rid,
|
||||
format: configuration.format,
|
||||
viewFormats: configuration.viewFormats,
|
||||
usage: configuration.usage,
|
||||
width: configuration.width,
|
||||
height: configuration.height,
|
||||
alphaMode: configuration.alphaMode,
|
||||
});
|
||||
|
||||
device.pushError(err);
|
||||
}
|
||||
|
||||
unconfigure() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
|
||||
this[_configuration] = null;
|
||||
this[_device] = null;
|
||||
}
|
||||
|
||||
getCurrentTexture() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'getCurrentTexture' on 'GPUCanvasContext'";
|
||||
|
||||
if (this[_configuration] === null) {
|
||||
throw new DOMException("context is not configured.", "InvalidStateError");
|
||||
}
|
||||
|
||||
const device = assertDevice(this, { prefix, context: "this" });
|
||||
|
||||
if (this[_currentTexture]) {
|
||||
return this[_currentTexture];
|
||||
}
|
||||
|
||||
const { rid } = ops.op_webgpu_surface_get_current_texture(device.rid, this[_surfaceRid]);
|
||||
|
||||
const texture = createGPUTexture(
|
||||
{
|
||||
size: {
|
||||
width: this[_configuration].width,
|
||||
height: this[_configuration].height,
|
||||
depthOrArrayLayers: 1,
|
||||
},
|
||||
mipLevelCount: 1,
|
||||
sampleCount: 1,
|
||||
dimension: "2d",
|
||||
format: this[_configuration].format,
|
||||
usage: this[_configuration].usage,
|
||||
},
|
||||
device,
|
||||
rid,
|
||||
);
|
||||
device.trackResource(texture);
|
||||
this[_currentTexture] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
// Extended from spec. Required to present the texture; browser don't need this.
|
||||
present() {
|
||||
webidl.assertBranded(this, GPUCanvasContextPrototype);
|
||||
const prefix = "Failed to execute 'present' on 'GPUCanvasContext'";
|
||||
const device = assertDevice(this[_currentTexture], { prefix, context: "this" });
|
||||
ops.op_webgpu_surface_present(device.rid, this[_surfaceRid]);
|
||||
this[_currentTexture].destroy();
|
||||
this[_currentTexture] = undefined;
|
||||
}
|
||||
}
|
||||
const GPUCanvasContextPrototype = GPUCanvasContext.prototype;
|
||||
|
||||
function createCanvasContext(options) {
|
||||
const canvasContext = webidl.createBranded(GPUCanvasContext);
|
||||
canvasContext[_surfaceRid] = options.surfaceRid;
|
||||
canvasContext[_canvas] = options.canvas;
|
||||
return canvasContext;
|
||||
}
|
||||
|
||||
window.__bootstrap.webgpu = {
|
||||
...window.__bootstrap.webgpu,
|
||||
GPUCanvasContext,
|
||||
createCanvasContext,
|
||||
};
|
||||
})(this);
|
@ -1,86 +0,0 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// @ts-check
|
||||
/// <reference path="../../core/lib.deno_core.d.ts" />
|
||||
/// <reference path="../web/internal.d.ts" />
|
||||
/// <reference path="../web/lib.deno_web.d.ts" />
|
||||
/// <reference path="./lib.deno_webgpu.d.ts" />
|
||||
|
||||
"use strict";
|
||||
|
||||
((window) => {
|
||||
const webidl = window.__bootstrap.webidl;
|
||||
const { GPUTextureUsage } = window.__bootstrap.webgpu;
|
||||
|
||||
// ENUM: GPUCanvasAlphaMode
|
||||
webidl.converters["GPUCanvasAlphaMode"] = webidl.createEnumConverter(
|
||||
"GPUCanvasAlphaMode",
|
||||
[
|
||||
"opaque",
|
||||
"premultiplied",
|
||||
],
|
||||
);
|
||||
|
||||
// NON-SPEC: ENUM: GPUPresentMode
|
||||
webidl.converters["GPUPresentMode"] = webidl.createEnumConverter(
|
||||
"GPUPresentMode",
|
||||
[
|
||||
"autoVsync",
|
||||
"autoNoVsync",
|
||||
"fifo",
|
||||
"fifoRelaxed",
|
||||
"immediate",
|
||||
"mailbox",
|
||||
],
|
||||
);
|
||||
|
||||
// DICT: GPUCanvasConfiguration
|
||||
const dictMembersGPUCanvasConfiguration = [
|
||||
{ key: "device", converter: webidl.converters.GPUDevice, required: true },
|
||||
{
|
||||
key: "format",
|
||||
converter: webidl.converters.GPUTextureFormat,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "usage",
|
||||
converter: webidl.converters["GPUTextureUsageFlags"],
|
||||
defaultValue: GPUTextureUsage.RENDER_ATTACHMENT,
|
||||
},
|
||||
{
|
||||
key: "alphaMode",
|
||||
converter: webidl.converters["GPUCanvasAlphaMode"],
|
||||
defaultValue: "opaque",
|
||||
},
|
||||
|
||||
// Extended from spec
|
||||
{
|
||||
key: "presentMode",
|
||||
converter: webidl.converters["GPUPresentMode"],
|
||||
},
|
||||
{
|
||||
key: "width",
|
||||
converter: webidl.converters["long"],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "height",
|
||||
converter: webidl.converters["long"],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
key: "viewFormats",
|
||||
converter: webidl.createSequenceConverter(
|
||||
webidl.converters["GPUTextureFormat"],
|
||||
),
|
||||
get defaultValue() {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
];
|
||||
webidl.converters["GPUCanvasConfiguration"] = webidl
|
||||
.createDictionaryConverter(
|
||||
"GPUCanvasConfiguration",
|
||||
dictMembersGPUCanvasConfiguration,
|
||||
);
|
||||
})(this);
|
@ -5,6 +5,7 @@ use deno_core::error::AnyError;
|
||||
use deno_core::include_js_files;
|
||||
use deno_core::op;
|
||||
use deno_core::Extension;
|
||||
use deno_core::ExtensionBuilder;
|
||||
use deno_core::OpState;
|
||||
use deno_core::Resource;
|
||||
use deno_core::ResourceId;
|
||||
@ -13,30 +14,41 @@ use std::borrow::Cow;
|
||||
use std::rc::Rc;
|
||||
use wgpu_types::SurfaceStatus;
|
||||
|
||||
pub fn init_surface(unstable: bool) -> Extension {
|
||||
Extension::builder("deno_webgpu_surface")
|
||||
.dependencies(vec!["deno_webidl", "deno_web", "deno_webgpu"])
|
||||
.js(include_js_files!(
|
||||
prefix "deno:deno_webgpu",
|
||||
"03_surface.js",
|
||||
"04_surface_idl_types.js",
|
||||
fn ext() -> ExtensionBuilder {
|
||||
Extension::builder_with_deps(
|
||||
"deno_webgpu_surface",
|
||||
&["deno_webidl", "deno_web", "deno_webgpu"],
|
||||
)
|
||||
}
|
||||
|
||||
fn ops(ext: &mut ExtensionBuilder, unstable: bool) -> &mut ExtensionBuilder {
|
||||
ext.ops(vec![
|
||||
op_webgpu_surface_configure::decl(),
|
||||
op_webgpu_surface_get_current_texture::decl(),
|
||||
op_webgpu_surface_present::decl(),
|
||||
])
|
||||
.state(move |state| {
|
||||
// TODO: check & possibly streamline this
|
||||
// Unstable might be able to be OpMiddleware
|
||||
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
||||
// let unstable = unstable_checker.unstable;
|
||||
state.put(super::Unstable(unstable));
|
||||
})
|
||||
}
|
||||
|
||||
pub fn init_ops_and_esm(unstable: bool) -> Extension {
|
||||
ops(&mut ext(), unstable)
|
||||
.esm(include_js_files!(
|
||||
"03_surface.js",
|
||||
"04_surface_idl_types.js",
|
||||
))
|
||||
.ops(vec![
|
||||
op_webgpu_surface_configure::decl(),
|
||||
op_webgpu_surface_get_current_texture::decl(),
|
||||
op_webgpu_surface_present::decl(),
|
||||
])
|
||||
.state(move |state| {
|
||||
// TODO: check & possibly streamline this
|
||||
// Unstable might be able to be OpMiddleware
|
||||
// let unstable_checker = state.borrow::<super::UnstableChecker>();
|
||||
// let unstable = unstable_checker.unstable;
|
||||
state.put(super::Unstable(unstable));
|
||||
Ok(())
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
pub fn init_ops(unstable: bool) -> Extension {
|
||||
ops(&mut ext(), unstable).build()
|
||||
}
|
||||
|
||||
pub struct WebGpuSurface(pub crate::Instance, pub wgpu_core::id::SurfaceId);
|
||||
impl Resource for WebGpuSurface {
|
||||
fn name(&self) -> Cow<str> {
|
Loading…
Reference in New Issue
Block a user