Update deno (#3562)

Co-authored-by: crowlkats <crowlkats@toaxl.com>
This commit is contained in:
Teodor Tanasoaia 2023-03-11 07:24:20 +01:00 committed by GitHub
parent 35b0a16a88
commit 287c6e6b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 7847 additions and 7867 deletions

92
Cargo.lock generated
View File

@ -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"

View File

@ -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" }

View File

@ -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);

View File

@ -5,35 +5,33 @@
//
delete Object.prototype.__proto__;
((window) => {
const core = Deno.core;
const {
const core = Deno.core;
const primordials = globalThis.__bootstrap.primordials;
const {
Error,
ObjectDefineProperty,
ObjectDefineProperties,
ObjectSetPrototypeOf,
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;
DateNow,
} = primordials;
const util = {
immutableDefine(o, p, value) {
ObjectDefineProperty(o, p, {
value,
configurable: false,
writable: false,
});
},
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";
let globalThis_;
const util = {
writable(value) {
return {
value,
@ -55,9 +53,18 @@ delete Object.prototype.__proto__;
enumerable: true,
};
},
getterOnly(getter) {
return {
get: getter,
set() {
},
enumerable: true,
configurable: true,
};
},
};
class Navigator {
class Navigator {
constructor() {
webidl.illegalConstructor();
}
@ -65,34 +72,31 @@ delete Object.prototype.__proto__;
[Symbol.for("Deno.customInspect")](inspect) {
return `${this.constructor.name} ${inspect({})}`;
}
}
}
const NavigatorPrototype = Navigator.prototype;
const navigator = webidl.createBranded(Navigator);
const navigator = webidl.createBranded(Navigator);
ObjectDefineProperties(Navigator.prototype, {
ObjectDefineProperties(Navigator.prototype, {
gpu: {
configurable: true,
enumerable: true,
get() {
webidl.assertBranded(this, Navigator);
webidl.assertBranded(this, NavigatorPrototype);
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),
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: {
configurable: true,
enumerable: true,
get: () => navigator,
},
navigator: util.getterOnly(() => navigator),
Performance: util.nonEnumerable(performance.Performance),
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
PerformanceMark: util.nonEnumerable(performance.PerformanceMark),
@ -140,37 +144,17 @@ delete Object.prototype.__proto__;
GPUQuerySet: util.nonEnumerable(webgpu.GPUQuerySet),
GPUOutOfMemoryError: util.nonEnumerable(webgpu.GPUOutOfMemoryError),
GPUValidationError: util.nonEnumerable(webgpu.GPUValidationError),
};
};
windowOrWorkerGlobalScope.console.enumerable = false;
windowOrWorkerGlobalScope.console.enumerable = false;
const mainRuntimeGlobalProperties = {
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 = {
const denoNs = {
exit(code) {
core.opSync("op_exit", code);
},
@ -185,48 +169,45 @@ delete Object.prototype.__proto__;
writeFileSync(path, buf) {
return core.opSync("op_write_file_sync", pathFromURL(path), buf);
},
};
};
function registerErrors() {
core.registerErrorBuilder(
core.registerErrorBuilder(
"DOMExceptionOperationError",
function DOMExceptionOperationError(msg) {
return new DOMException(msg, "OperationError");
},
);
}
);
let hasBootstrapped = false;
let hasBootstrapped = false;
function bootstrapRuntime({ args, cwd }) {
core.setMacrotaskCallback(timers.handleTimerMacrotask);
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;
registerErrors();
event.setEventTargetData(globalThis);
event.saveGlobalThisReference(globalThis);
Object.defineProperties(globalThis, windowOrWorkerGlobalScope);
Object.defineProperties(globalThis, mainRuntimeGlobalProperties);
Object.setPrototypeOf(globalThis, Window.prototype);
eventTarget.setEventTargetData(globalThis);
Error.prepareStackTrace = core.prepareStackTrace;
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties);
ObjectSetPrototypeOf(globalThis, Window.prototype);
event.setEventTargetData(globalThis);
denoNs.args = args;
denoNs.cwd = () => cwd;
util.immutableDefine(globalThis, "Deno", denoNs);
Object.freeze(globalThis.Deno);
core.ops();
Error.prepareStackTrace = core.createPrepareStackTrace();
}
ObjectDefineProperty(globalThis, "Deno", util.readOnly(denoNs));
ObjectDefineProperties(globalThis, {
bootstrap: {
value: bootstrapRuntime,
configurable: true,
},
});
})(globalThis);
Error.prepareStackTrace = core.prepareStackTrace;
}
globalThis.bootstrap = bootstrapRuntime;

View File

@ -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

File diff suppressed because it is too large Load Diff

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
View 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,
};

View 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,
);

View File

@ -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"]

View File

@ -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| {
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));
Ok(())
})
}
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

View File

@ -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);

View File

@ -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);

View File

@ -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,15 +14,15 @@ 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",
))
.ops(vec![
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(),
@ -32,11 +33,22 @@ pub fn init_surface(unstable: bool) -> Extension {
// let unstable_checker = state.borrow::<super::UnstableChecker>();
// let unstable = unstable_checker.unstable;
state.put(super::Unstable(unstable));
Ok(())
})
}
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",
))
.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> {