From 2a4cec5c8ca52b0c8a6257d03baf6dc60b4fc3b3 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 1 Aug 2024 22:05:41 +0200 Subject: [PATCH 1/8] update & backport deno MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Luca Casonato Co-authored-by: Bartek IwaƄczuk Co-authored-by: chirsz Co-authored-by: Hajime-san <41257923+hajime-san@users.noreply.github.com> Co-authored-by: Volker Schlecht <47375452+vlkrs@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- Cargo.lock | 263 ++++++++++++++++++++++++++++----- Cargo.toml | 12 +- deno_webgpu/01_webgpu.js | 26 ++-- deno_webgpu/Cargo.toml | 2 +- deno_webgpu/buffer.rs | 48 +++--- deno_webgpu/byow.rs | 15 +- deno_webgpu/command_encoder.rs | 6 +- rust-toolchain.toml | 2 +- 9 files changed, 286 insertions(+), 90 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 203e990b3d..d8d63de63e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ env: # Once 1.76 coes out, we can use that instead of nightly. DOCS_RUST_VERSION: "nightly-2023-12-17" # This is the MSRV used by `wgpu` itself and all surrounding infrastructure. - REPO_MSRV: "1.76" + REPO_MSRV: "1.79" # This is the MSRV used by the `wgpu-core`, `wgpu-hal`, and `wgpu-types` crates, # to ensure that they can be used with firefox. CORE_MSRV: "1.76" diff --git a/Cargo.lock b/Cargo.lock index 2dbf69ee76..52955c8624 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,15 +306,53 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.72", + "which 4.4.2", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec 0.6.3", +] + [[package]] name = "bit-set" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ - "bit-vec", + "bit-vec 0.8.0", ] +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bit-vec" version = "0.8.0" @@ -337,6 +375,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block" version = "0.1.6" @@ -462,6 +512,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -510,6 +569,17 @@ dependencies = [ "half", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading 0.8.5", +] + [[package]] name = "clap" version = "4.5.11" @@ -977,23 +1047,23 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.143.0" +version = "0.164.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f770d8deb0eb0bfd596d242d9eaef5312ef57f0130964cb53c7f6a8107d13be" +checksum = "5b212dc5a2255fd7ff8f871ddaa59173a52c07a11beebe6fa2f280bb70889a40" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.272.0" +version = "0.299.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07093891f2af763023614cfe2d1ce5f9ce5a7920c4fcf2f00911bd0d93083523" +checksum = "428488cc6b392a199a159054da754f56a1fdc63ee03f16be2c21cbd22e936e7b" dependencies = [ "anyhow", "bincode", - "bit-set", - "bit-vec", + "bit-set 0.5.3", + "bit-vec 0.6.3", "bytes", "cooked-waker", "deno_core_icudata", @@ -1001,9 +1071,9 @@ dependencies = [ "deno_unsync", "futures", "libc", - "log", "memoffset 0.9.1", "parking_lot", + "percent-encoding", "pin-project", "serde", "serde_json", @@ -1024,9 +1094,9 @@ checksum = "a13951ea98c0a4c372f162d669193b4c9d991512de9f2381dd161027f34b26b1" [[package]] name = "deno_ops" -version = "0.148.0" +version = "0.175.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc73fc07ad26e71715d5a726d1dd228587c0d121a591b1931a0fcf958a2ec3b" +checksum = "2d2b71759647722be6ae051919b75cb66b3dccafe61b53c75ad5a6fad9d0ee4a" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -1037,11 +1107,38 @@ dependencies = [ "thiserror", ] +[[package]] +name = "deno_permissions" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e2171078873c19da034f09130c3118a50d036ef2a0256b0b5ea99159b53b76b" +dependencies = [ + "deno_core", + "deno_terminal", + "fqdn", + "libc", + "log", + "once_cell", + "serde", + "which 4.4.2", + "winapi", +] + +[[package]] +name = "deno_terminal" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daef12499e89ee99e51ad6000a91f600d3937fb028ad4918af76810c5bc9e0d5" +dependencies = [ + "once_cell", + "termcolor", +] + [[package]] name = "deno_unsync" -version = "0.3.10" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c8b95582c2023dbb66fccc37421b374026f5915fa507d437cb566904db9a3a" +checksum = "03ee1607db298c8f12124b345a52d5f2f504a7504c9d535f1d8f07127b237010" dependencies = [ "parking_lot", "tokio", @@ -1049,37 +1146,36 @@ dependencies = [ [[package]] name = "deno_url" -version = "0.143.0" +version = "0.164.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39d9e6ffd6a7157bfd3cf1385c59232e49587c9bbb898e64010f7f082242a203" +checksum = "303f4774cb4eb7b8b8b1d4b29017acf12dbc4341d9e764da79a690a34a561d1c" dependencies = [ "deno_core", - "serde", "urlpattern", ] [[package]] name = "deno_web" -version = "0.174.0" +version = "0.195.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "708666b5b346e6880c1372006615814db7fc5ef36bd1785f0b0e4f8617082999" +checksum = "595861d8f2e30a37cfba78bee83400402963100f2e35de9bef66146c12f48dd1" dependencies = [ "async-trait", "base64-simd 0.8.0", "bytes", "deno_core", + "deno_permissions", "encoding_rs", "flate2", "futures", "serde", "tokio", "uuid", - "windows-sys 0.48.0", ] [[package]] name = "deno_webgpu" -version = "0.118.0" +version = "0.131.0" dependencies = [ "deno_core", "raw-window-handle 0.6.2", @@ -1091,9 +1187,9 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.143.0" +version = "0.164.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddad93aa68e3c3c2d36976cd401af27a6ce750c23060e02401daf240f2acbe2" +checksum = "d4411072b4e79c6e5c423563feb8d9f9188a8b378b5d94436db0cbcfb2620539" dependencies = [ "deno_core", ] @@ -1377,6 +1473,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fqdn" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08b1eaa7dfddeab6036292995620bf0435712e619db6d7690605897e76975eb0" + [[package]] name = "freetype-rs" version = "0.26.0" @@ -1409,6 +1511,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.30" @@ -1570,6 +1678,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "glow" version = "0.14.0" @@ -1979,6 +2093,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.155" @@ -2154,6 +2274,12 @@ dependencies = [ "paste", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -2194,7 +2320,7 @@ version = "22.0.0" dependencies = [ "arbitrary", "arrayvec 0.7.4", - "bit-set", + "bit-set 0.8.0", "bitflags 2.6.0", "cfg_aliases", "codespan-reporting", @@ -2378,6 +2504,16 @@ dependencies = [ "rand_xorshift", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2779,6 +2915,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn 2.0.72", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -2854,6 +3000,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -3189,11 +3341,10 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.181.0" +version = "0.208.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd25bb66a20a1a405fb3733aaaf8a8a77a14fd55c8f5fd9db2a2e95bbd7eeab9" +checksum = "583f3c71a6f7acc1711ad718a33f6e799bacdc711d297b15bb28533f32264c58" dependencies = [ - "bytes", "num-bigint", "serde", "smallvec", @@ -3241,6 +3392,12 @@ dependencies = [ "libc", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -3354,14 +3511,16 @@ dependencies = [ [[package]] name = "sourcemap" -version = "7.1.1" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7768edd06c02535e0d50653968f46e1e0d3aa54742190d35dd9466f59de9c71" +checksum = "208d40b9e8cad9f93613778ea295ed8f3c2b1824217c6cfc7219d3f6f45b96d4" dependencies = [ "base64-simd 0.7.0", + "bitvec", "data-encoding", "debugid", "if_chain", + "rustc-hash", "rustc_version 0.2.3", "serde", "serde_json", @@ -3464,6 +3623,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "termcolor" version = "1.4.1" @@ -3858,17 +4023,19 @@ dependencies = [ [[package]] name = "v8" -version = "0.89.0" +version = "0.99.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe2197fbef82c98f7953d13568a961d4e1c663793b5caf3c74455a13918cdf33" +checksum = "fa3fc0608a78f0c7d4ec88025759cb78c90a29984b48540060355a626ae329c1" dependencies = [ + "bindgen", "bitflags 2.6.0", "fslock", "gzip-header", "home", "miniz_oxide", "once_cell", - "which", + "paste", + "which 6.0.2", ] [[package]] @@ -4260,7 +4427,7 @@ name = "wgpu-core" version = "22.0.0" dependencies = [ "arrayvec 0.7.4", - "bit-vec", + "bit-vec 0.8.0", "bitflags 2.6.0", "bytemuck", "cfg_aliases", @@ -4319,7 +4486,7 @@ dependencies = [ "android_system_properties", "arrayvec 0.7.4", "ash", - "bit-set", + "bit-set 0.8.0", "bitflags 2.6.0", "block", "cfg-if", @@ -4431,15 +4598,26 @@ dependencies = [ [[package]] name = "which" -version = "5.0.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", "home", "once_cell", "rustix", - "windows-sys 0.48.0", +] + +[[package]] +name = "which" +version = "6.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d9c5ed668ee1f17edb3b627225343d210006a90bb1e3745ce1f30b1fb115075" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", ] [[package]] @@ -4881,6 +5059,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "wio" version = "0.2.2" @@ -4890,6 +5074,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "x11-dl" version = "2.21.0" diff --git a/Cargo.toml b/Cargo.toml index 23d5b5cd7d..194b687bdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -177,12 +177,12 @@ web-sys = "0.3.69" web-time = "0.2.4" # deno dependencies -deno_console = "0.143.0" -deno_core = "0.272.0" -deno_url = "0.143.0" -deno_web = "0.174.0" -deno_webidl = "0.143.0" -deno_webgpu = { version = "0.118.0", path = "./deno_webgpu" } +deno_console = "0.164.0" +deno_core = "0.299.0" +deno_url = "0.164.0" +deno_web = "0.195.0" +deno_webidl = "0.164.0" +deno_webgpu = { version = "0.131.0", path = "./deno_webgpu" } tokio = "1.39.2" termcolor = "1.4.1" diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index f226c8ab5f..a8e6b5c6f1 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -337,7 +337,7 @@ class GPU { * @param {GPURequestAdapterOptions} options */ // deno-lint-ignore require-await - async requestAdapter(options = {}) { + async requestAdapter(options = { __proto__: null }) { webidl.assertBranded(this, GPUPrototype); options = webidl.converters.GPURequestAdapterOptions( options, @@ -428,7 +428,7 @@ class GPUAdapter { * @returns {Promise} */ // deno-lint-ignore require-await - async requestDevice(descriptor = {}) { + async requestDevice(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUAdapterPrototype); const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'"; descriptor = webidl.converters.GPUDeviceDescriptor( @@ -977,7 +977,7 @@ class InnerGPUDevice { ); break; case "out-of-memory": - constructedError = new GPUOutOfMemoryError(); + constructedError = new GPUOutOfMemoryError("not enough memory left"); break; case "internal": constructedError = new GPUInternalError(); @@ -1153,7 +1153,7 @@ class GPUDevice extends EventTarget { * @param {GPUSamplerDescriptor} descriptor * @returns {GPUSampler} */ - createSampler(descriptor = {}) { + createSampler(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUDevicePrototype); const prefix = "Failed to execute 'createSampler' on 'GPUDevice'"; descriptor = webidl.converters.GPUSamplerDescriptor( @@ -1434,6 +1434,7 @@ class GPUDevice extends EventTarget { fragment = { module, entryPoint: descriptor.fragment.entryPoint, + constants: descriptor.fragment.constants, targets: descriptor.fragment.targets, }; } @@ -1445,6 +1446,7 @@ class GPUDevice extends EventTarget { vertex: { module, entryPoint: descriptor.vertex.entryPoint, + constants: descriptor.vertex.constants, buffers: descriptor.vertex.buffers, }, primitive: descriptor.primitive, @@ -1557,6 +1559,7 @@ class GPUDevice extends EventTarget { fragment = { module, entryPoint: descriptor.fragment.entryPoint, + constants: descriptor.fragment.constants, targets: descriptor.fragment.targets, }; } @@ -1568,6 +1571,7 @@ class GPUDevice extends EventTarget { vertex: { module, entryPoint: descriptor.vertex.entryPoint, + constants: descriptor.vertex.constants, buffers: descriptor.vertex.buffers, }, primitive: descriptor.primitive, @@ -1599,14 +1603,14 @@ class GPUDevice extends EventTarget { rid, ); device.trackResource(renderPipeline); - return renderPipeline; + return PromiseResolve(renderPipeline); } /** * @param {GPUCommandEncoderDescriptor} descriptor * @returns {GPUCommandEncoder} */ - createCommandEncoder(descriptor = {}) { + createCommandEncoder(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUDevicePrototype); const prefix = "Failed to execute 'createCommandEncoder' on 'GPUDevice'"; descriptor = webidl.converters.GPUCommandEncoderDescriptor( @@ -1761,7 +1765,7 @@ defineEventHandler(GPUDevice.prototype, "uncapturederror"); class GPUPipelineError extends DOMException { #reason; - constructor(message = "", options = {}) { + constructor(message = "", options = { __proto__: null }) { const prefix = "Failed to construct 'GPUPipelineError'"; message = webidl.converters.DOMString(message, prefix, "Argument 1"); options = webidl.converters.GPUPipelineErrorInit( @@ -2403,7 +2407,7 @@ class GPUTexture { /** * @param {GPUTextureViewDescriptor} descriptor */ - createView(descriptor = {}) { + createView(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUTexturePrototype); const prefix = "Failed to execute 'createView' on 'GPUTexture'"; webidl.requiredArguments(arguments.length, 0, prefix); @@ -3183,7 +3187,7 @@ class GPUCommandEncoder { /** * @param {GPUComputePassDescriptor} descriptor */ - beginComputePass(descriptor = {}) { + beginComputePass(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUCommandEncoderPrototype); const prefix = "Failed to execute 'beginComputePass' on 'GPUCommandEncoder'"; @@ -3577,7 +3581,7 @@ class GPUCommandEncoder { * @param {GPUCommandBufferDescriptor} descriptor * @returns {GPUCommandBuffer} */ - finish(descriptor = {}) { + finish(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPUCommandEncoderPrototype); const prefix = "Failed to execute 'finish' on 'GPUCommandEncoder'"; descriptor = webidl.converters.GPUCommandBufferDescriptor( @@ -4544,7 +4548,7 @@ class GPURenderBundleEncoder { /** * @param {GPURenderBundleDescriptor} descriptor */ - finish(descriptor = {}) { + finish(descriptor = { __proto__: null }) { webidl.assertBranded(this, GPURenderBundleEncoderPrototype); const prefix = "Failed to execute 'finish' on 'GPURenderBundleEncoder'"; descriptor = webidl.converters.GPURenderBundleDescriptor( diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index ba72507dd7..5055688f3d 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webgpu" -version = "0.118.0" +version = "0.131.0" authors = ["the Deno authors"] edition.workspace = true license = "MIT" diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index 9a4900112a..8766264dd8 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -2,7 +2,6 @@ use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::futures::channel::oneshot; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -11,8 +10,9 @@ use std::borrow::Cow; use std::cell::RefCell; use std::ptr::NonNull; use std::rc::Rc; +use std::sync::Arc; +use std::sync::Mutex; use std::time::Duration; -use wgpu_core::resource::BufferAccessResult; use super::error::DomExceptionOperationError; use super::error::WebGpuResult; @@ -79,9 +79,8 @@ pub async fn op_webgpu_buffer_get_map_async( #[number] offset: u64, #[number] size: u64, ) -> Result { - let (sender, receiver) = oneshot::channel::(); - let device; + let done = Arc::new(Mutex::new(None)); { let state_ = state.borrow(); let instance = state_.borrow::(); @@ -92,11 +91,11 @@ pub async fn op_webgpu_buffer_get_map_async( .get::(device_rid)?; device = device_resource.1; + let done_ = done.clone(); let callback = Box::new(move |status| { - sender.send(status).unwrap(); + *done_.lock().unwrap() = Some(status); }); - // TODO(lucacasonato): error handling let maybe_err = gfx_select!(buffer => instance.buffer_map_async( buffer, offset, @@ -117,31 +116,22 @@ pub async fn op_webgpu_buffer_get_map_async( } } - let done = Rc::new(RefCell::new(false)); - let done_ = done.clone(); - let device_poll_fut = async move { - while !*done.borrow() { - { - let state = state.borrow(); - let instance = state.borrow::(); - gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::wait())) - .unwrap(); + loop { + let result = done.lock().unwrap().take(); + match result { + Some(Ok(())) => return Ok(WebGpuResult::empty()), + Some(Err(e)) => return Err(DomExceptionOperationError::new(&e.to_string()).into()), + None => { + { + let state = state.borrow(); + let instance = state.borrow::(); + gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::Poll)) + .unwrap(); + } + tokio::time::sleep(Duration::from_millis(10)).await; } - tokio::time::sleep(Duration::from_millis(10)).await; } - Ok::<(), AnyError>(()) - }; - - let receiver_fut = async move { - receiver.await??; - let mut done = done_.borrow_mut(); - *done = true; - Ok::<(), AnyError>(()) - }; - - tokio::try_join!(device_poll_fut, receiver_fut)?; - - Ok(WebGpuResult::empty()) + } } #[op2] diff --git a/deno_webgpu/byow.rs b/deno_webgpu/byow.rs index 49944ea1e7..1002458c90 100644 --- a/deno_webgpu/byow.rs +++ b/deno_webgpu/byow.rs @@ -6,7 +6,12 @@ use deno_core::op2; use deno_core::OpState; use deno_core::ResourceId; use std::ffi::c_void; -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(any( + target_os = "linux", + target_os = "macos", + target_os = "freebsd", + target_os = "openbsd" +))] use std::ptr::NonNull; use crate::surface::WebGpuSurface; @@ -19,7 +24,9 @@ pub fn op_webgpu_surface_create( p1: *const c_void, p2: *const c_void, ) -> Result { - let instance = state.borrow::(); + let instance = state.try_borrow::().ok_or_else(|| { + type_error("Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?") + })?; // Security note: // // The `p1` and `p2` parameters are pointers to platform-specific window @@ -96,7 +103,7 @@ fn raw_window( Ok((win_handle, display_handle)) } -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] fn raw_window( system: &str, window: *const c_void, @@ -124,7 +131,7 @@ fn raw_window( ), ); } else { - return Err(type_error("Invalid system on Linux")); + return Err(type_error("Invalid system on Linux/BSD")); } Ok((win_handle, display_handle)) diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index ba21bb05b5..7ebe5b49b8 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -79,7 +79,7 @@ pub struct GpuRenderPassColorAttachment { #[serde(rename_all = "camelCase")] pub struct GpuRenderPassDepthStencilAttachment { view: ResourceId, - depth_clear_value: f32, + depth_clear_value: Option, depth_load_op: Option, depth_store_op: Option, depth_read_only: bool, @@ -164,7 +164,9 @@ pub fn op_webgpu_command_encoder_begin_render_pass( store_op: attachment .depth_store_op .unwrap_or(wgpu_core::command::StoreOp::Store), - clear_value: attachment.depth_clear_value, + // In "01_webgpu.js", `depthLoadOp` is cheked to ensure its value is not "clear" + // when `depthClearValue` is undefined, so the default 0.0 doesn't matter. + clear_value: attachment.depth_clear_value.unwrap_or(0.0), read_only: attachment.depth_read_only, }, stencil: wgpu_core::command::PassChannel { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 45bb8d6d51..57541fc438 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.76" +channel = "1.79" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"] From 38e3be054c9d9604fc354cc918ce1348e2f59986 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 1 Aug 2024 22:48:20 +0200 Subject: [PATCH 2/8] fixes and spec update --- deno_webgpu/01_webgpu.js | 4 ++++ deno_webgpu/lib.rs | 7 +++++++ deno_webgpu/webgpu.idl | 13 +++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index a8e6b5c6f1..83bda73195 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -6382,6 +6382,10 @@ webidl.converters["GPUBlendFactor"] = webidl.createEnumConverter( "src-alpha-saturated", "constant", "one-minus-constant", + "src1", + "one-minus-src1", + "src1-alpha", + "one-minus-src1-alpha", ], ); diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index aafb225fb9..037b89c8f3 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -263,6 +263,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> { if features.contains(wgpu_types::Features::FLOAT32_FILTERABLE) { return_features.push("float32-filterable"); } + if features.contains(wgpu_types::Features::DUAL_SOURCE_BLENDING) { + return_features.push("dual-source-blending"); + } // extended from spec @@ -511,6 +514,10 @@ impl From for wgpu_types::Features { wgpu_types::Features::FLOAT32_FILTERABLE, required_features.0.contains("float32-filterable"), ); + features.set( + wgpu_types::Features::DUAL_SOURCE_BLENDING, + required_features.0.contains("dual-source-blending"), + ); // extended from spec diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index 07d9d60ec7..be4cd69a1c 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -92,21 +92,18 @@ dictionary GPUDeviceDescriptor }; enum GPUFeatureName { - // api "depth-clip-control", - // texture formats "depth32float-stencil8", "texture-compression-bc", "texture-compression-etc2", "texture-compression-astc", - // api "timestamp-query", "indirect-first-instance", - // shader "shader-f16", "rg11b10ufloat-renderable", "bgra8unorm-storage", "float32-filterable", + "dual-source-blending", // extended from spec @@ -751,6 +748,10 @@ enum GPUBlendFactor { "src-alpha-saturated", "constant", "one-minus-constant", + "src1", + "one-minus-src1", + "src1-alpha", + "one-minus-src1-alpha", }; enum GPUBlendOperation { @@ -1108,13 +1109,13 @@ interface GPUQueue { undefined writeBuffer( GPUBuffer buffer, GPUSize64 bufferOffset, - [AllowShared] BufferSource data, + AllowSharedBufferSource data, optional GPUSize64 dataOffset = 0, optional GPUSize64 size); undefined writeTexture( GPUImageCopyTexture destination, - [AllowShared] BufferSource data, + AllowSharedBufferSource data, GPUImageDataLayout dataLayout, GPUExtent3D size); }; From 9977ef6c8d35416e8ef17757db147f8c9be8a91a Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 2 Aug 2024 00:17:16 +0200 Subject: [PATCH 3/8] typo --- deno_webgpu/command_encoder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 7ebe5b49b8..1003f249e5 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -164,7 +164,7 @@ pub fn op_webgpu_command_encoder_begin_render_pass( store_op: attachment .depth_store_op .unwrap_or(wgpu_core::command::StoreOp::Store), - // In "01_webgpu.js", `depthLoadOp` is cheked to ensure its value is not "clear" + // In "01_webgpu.js", `depthLoadOp` is checked to ensure its value is not "clear" // when `depthClearValue` is undefined, so the default 0.0 doesn't matter. clear_value: attachment.depth_clear_value.unwrap_or(0.0), read_only: attachment.depth_read_only, From ac1fbec4bccb58f974ecd062fff64eee3c7179f4 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 2 Aug 2024 12:53:43 +0200 Subject: [PATCH 4/8] dedupe gfx_select macro --- deno_webgpu/Cargo.toml | 2 +- deno_webgpu/binding.rs | 5 +++-- deno_webgpu/buffer.rs | 2 ++ deno_webgpu/bundle.rs | 2 ++ deno_webgpu/command_encoder.rs | 2 ++ deno_webgpu/lib.rs | 34 ++-------------------------------- deno_webgpu/pipeline.rs | 2 ++ deno_webgpu/queue.rs | 2 ++ deno_webgpu/render_pass.rs | 1 + deno_webgpu/sampler.rs | 2 ++ deno_webgpu/shader.rs | 2 ++ deno_webgpu/surface.rs | 5 +++-- deno_webgpu/texture.rs | 2 ++ 13 files changed, 26 insertions(+), 37 deletions(-) diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index 5055688f3d..b98b9eca42 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -19,7 +19,7 @@ path = "lib.rs" deno_core.workspace = true serde = { workspace = true, features = ["derive"] } tokio = { workspace = true, features = ["full"] } -wgpu-types = { workspace = true, features = ["serde"] } +wgt = { workspace = true, package = "wgpu-types", features = ["serde"] } raw-window-handle = { workspace = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgpu-core] diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index 0efeb6716a..e1acb2cf67 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::error::WebGpuResult; +use super::wgpu_types; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -8,8 +10,7 @@ use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; - -use super::error::WebGpuResult; +use wgpu_core::gfx_select; pub(crate) struct WebGpuBindGroupLayout( pub(crate) crate::Instance, diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index 8766264dd8..31cbcfc1a1 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; @@ -13,6 +14,7 @@ use std::rc::Rc; use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; +use wgpu_core::gfx_select; use super::error::DomExceptionOperationError; use super::error::WebGpuResult; diff --git a/deno_webgpu/bundle.rs b/deno_webgpu/bundle.rs index dfe5ccf494..35adf417ad 100644 --- a/deno_webgpu/bundle.rs +++ b/deno_webgpu/bundle.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; @@ -10,6 +11,7 @@ use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 1003f249e5..bd7d59580e 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use crate::WebGpuQuerySet; use deno_core::error::AnyError; use deno_core::op2; @@ -10,6 +11,7 @@ use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 037b89c8f3..06f3358721 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -14,7 +14,8 @@ use std::cell::RefCell; use std::collections::HashSet; use std::rc::Rc; pub use wgpu_core; -pub use wgpu_types; +use wgpu_core::gfx_select; +pub use wgt as wgpu_types; use error::DomExceptionOperationError; use error::WebGpuResult; @@ -23,37 +24,6 @@ pub const UNSTABLE_FEATURE_NAME: &str = "webgpu"; #[macro_use] mod macros { - macro_rules! gfx_select { - ($id:expr => $p0:ident.$p1:tt.$method:ident $params:tt) => { - gfx_select!($id => {$p0.$p1}, $method $params) - }; - - ($id:expr => $p0:ident.$method:ident $params:tt) => { - gfx_select!($id => {$p0}, $method $params) - }; - - ($id:expr => {$($c:tt)*}, $method:ident $params:tt) => { - match $id.backend() { - #[cfg(any( - all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")), - feature = "vulkan-portability" - ))] - wgpu_types::Backend::Vulkan => $($c)*.$method:: $params, - #[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))] - wgpu_types::Backend::Metal => $($c)*.$method:: $params, - #[cfg(all(not(target_arch = "wasm32"), windows))] - wgpu_types::Backend::Dx12 => $($c)*.$method:: $params, - #[cfg(any( - all(unix, not(target_os = "macos"), not(target_os = "ios")), - feature = "angle", - target_arch = "wasm32" - ))] - wgpu_types::Backend::Gl => $($c)*.$method:: $params, - other => panic!("Unexpected backend {:?}", other), - } - }; - } - macro_rules! gfx_put { ($id:expr => $global:ident.$method:ident( $($param:expr),* ) => $state:expr, $rc:expr) => {{ let (val, maybe_err) = gfx_select!($id => $global.$method($($param),*)); diff --git a/deno_webgpu/pipeline.rs b/deno_webgpu/pipeline.rs index 86d530332f..71aa582891 100644 --- a/deno_webgpu/pipeline.rs +++ b/deno_webgpu/pipeline.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -10,6 +11,7 @@ use serde::Serialize; use std::borrow::Cow; use std::collections::HashMap; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuError; use super::error::WebGpuResult; diff --git a/deno_webgpu/queue.rs b/deno_webgpu/queue.rs index 2640134455..38aa6c42c1 100644 --- a/deno_webgpu/queue.rs +++ b/deno_webgpu/queue.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use crate::command_encoder::WebGpuCommandBuffer; use crate::Instance; use deno_core::error::AnyError; @@ -10,6 +11,7 @@ use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; diff --git a/deno_webgpu/render_pass.rs b/deno_webgpu/render_pass.rs index 941245971c..4187dfef09 100644 --- a/deno_webgpu/render_pass.rs +++ b/deno_webgpu/render_pass.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::op2; diff --git a/deno_webgpu/sampler.rs b/deno_webgpu/sampler.rs index 822c4bda14..bc0cdca0ae 100644 --- a/deno_webgpu/sampler.rs +++ b/deno_webgpu/sampler.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -8,6 +9,7 @@ use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; diff --git a/deno_webgpu/shader.rs b/deno_webgpu/shader.rs index 17cde43936..b2aff0e197 100644 --- a/deno_webgpu/shader.rs +++ b/deno_webgpu/shader.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -7,6 +8,7 @@ use deno_core::Resource; use deno_core::ResourceId; use std::borrow::Cow; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index a8b984eefe..a605371666 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use super::WebGpuResult; use deno_core::error::AnyError; use deno_core::op2; @@ -9,7 +10,7 @@ use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; -use wgpu_types::SurfaceStatus; +use wgpu_core::gfx_select; pub struct WebGpuSurface(pub crate::Instance, pub wgpu_core::id::SurfaceId); impl Resource for WebGpuSurface { @@ -86,7 +87,7 @@ pub fn op_webgpu_surface_get_current_texture( let output = gfx_select!(device => instance.surface_get_current_texture(surface, None))?; match output.status { - SurfaceStatus::Good | SurfaceStatus::Suboptimal => { + wgpu_types::SurfaceStatus::Good | wgpu_types::SurfaceStatus::Suboptimal => { let id = output.texture_id.unwrap(); let rid = state.resource_table.add(crate::texture::WebGpuTexture { instance: instance.clone(), diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 8acba24998..cdb99abb0c 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use super::wgpu_types; use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; @@ -8,6 +9,7 @@ use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; +use wgpu_core::gfx_select; use super::error::WebGpuResult; pub(crate) struct WebGpuTexture { From fe7d646adc2292502983ca4e867680eb563a4b3e Mon Sep 17 00:00:00 2001 From: crowlkats Date: Fri, 2 Aug 2024 12:56:28 +0200 Subject: [PATCH 5/8] fix workspace version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 194b687bdc..f2a200901d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ default-members = [ [workspace.package] edition = "2021" -rust-version = "1.76" +rust-version = "1.79" keywords = ["graphics"] license = "MIT OR Apache-2.0" homepage = "https://wgpu.rs/" From b96356dd3e140d6d57a4dc7699ef5c9627717b65 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 27 Nov 2024 18:35:49 +0100 Subject: [PATCH 6/8] update again --- Cargo.lock | 137 ++++++++++++++--------------- Cargo.toml | 12 +-- cts_runner/src/main.rs | 97 ++++++++++++++++++++- deno_webgpu/01_webgpu.js | 174 +++++++++++++++++++++---------------- deno_webgpu/02_surface.js | 36 ++++++-- deno_webgpu/Cargo.toml | 3 +- deno_webgpu/buffer.rs | 56 ++++++++---- deno_webgpu/bundle.rs | 55 ++++++------ deno_webgpu/byow.rs | 86 ++++++++++++++---- deno_webgpu/error.rs | 34 -------- deno_webgpu/lib.rs | 51 +++++------ deno_webgpu/render_pass.rs | 74 ++++++++-------- deno_webgpu/sampler.rs | 3 +- deno_webgpu/shader.rs | 3 +- deno_webgpu/surface.rs | 37 ++++++-- deno_webgpu/texture.rs | 5 +- deno_webgpu/webgpu.idl | 2 +- 17 files changed, 529 insertions(+), 336 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1669cf91a5..5d33382c3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -308,16 +308,14 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.4" +version = "0.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", "itertools", - "lazy_static", - "lazycell", "log", "prettyplease", "proc-macro2", @@ -326,7 +324,6 @@ dependencies = [ "rustc-hash", "shlex", "syn", - "which 4.4.2", ] [[package]] @@ -673,12 +670,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "cooked-waker" version = "5.0.0" @@ -849,18 +840,18 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.164.0" +version = "0.179.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b212dc5a2255fd7ff8f871ddaa59173a52c07a11beebe6fa2f280bb70889a40" +checksum = "2e09f2bbb2d842329b602da25dbab5cd4a342f9a8adcb7c02509fc322f796e79" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.299.0" +version = "0.321.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428488cc6b392a199a159054da754f56a1fdc63ee03f16be2c21cbd22e936e7b" +checksum = "cd2a54cda74cdc187d5fc2d23370a45cf09f912caf566dd1cd24a50157d809c7" dependencies = [ "anyhow", "bincode", @@ -872,6 +863,7 @@ dependencies = [ "deno_ops", "deno_unsync", "futures", + "indexmap", "libc", "memoffset", "parking_lot", @@ -886,42 +878,58 @@ dependencies = [ "tokio", "url", "v8", + "wasm_dep_analyzer", ] [[package]] name = "deno_core_icudata" -version = "0.0.73" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13951ea98c0a4c372f162d669193b4c9d991512de9f2381dd161027f34b26b1" +checksum = "fe4dccb6147bb3f3ba0c7a48e993bfeb999d2c2e47a81badee80e2b370c8d695" [[package]] name = "deno_ops" -version = "0.175.0" +version = "0.197.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2b71759647722be6ae051919b75cb66b3dccafe61b53c75ad5a6fad9d0ee4a" +checksum = "37a8825d92301cf445727c43f17fee2a20fcdf4370004339965156ae7c56c97e" dependencies = [ "proc-macro-rules", "proc-macro2", "quote", + "stringcase", "strum", "strum_macros", "syn", "thiserror", ] +[[package]] +name = "deno_path_util" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff25f6e08e7a0214bbacdd6f7195c7f1ebcd850c87a624e4ff06326b68b42d99" +dependencies = [ + "percent-encoding", + "thiserror", + "url", +] + [[package]] name = "deno_permissions" -version = "0.24.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2171078873c19da034f09130c3118a50d036ef2a0256b0b5ea99159b53b76b" +checksum = "14e822f98185ab3ddf06104b2407681e0008af52361af32f1cd171b7eda5aa59" dependencies = [ "deno_core", + "deno_path_util", "deno_terminal", "fqdn", "libc", "log", "once_cell", + "percent-encoding", "serde", + "thiserror", "which 4.4.2", "winapi", ] @@ -938,9 +946,9 @@ dependencies = [ [[package]] name = "deno_unsync" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ee1607db298c8f12124b345a52d5f2f504a7504c9d535f1d8f07127b237010" +checksum = "2f36b4ef61a04ce201b925a5dffa90f88437d37fee4836c758470dd15ba7f05e" dependencies = [ "parking_lot", "tokio", @@ -948,19 +956,20 @@ dependencies = [ [[package]] name = "deno_url" -version = "0.164.0" +version = "0.179.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "303f4774cb4eb7b8b8b1d4b29017acf12dbc4341d9e764da79a690a34a561d1c" +checksum = "ad9a108794e505f2b07665e19ff336c1bcba6adcf7182c90c1d3a6c741d7fcd0" dependencies = [ "deno_core", + "thiserror", "urlpattern", ] [[package]] name = "deno_web" -version = "0.195.0" +version = "0.210.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595861d8f2e30a37cfba78bee83400402963100f2e35de9bef66146c12f48dd1" +checksum = "7679087bcc41f7ae3385f8c12d43bc81cfc54cb9b1ef73983d20f5e39fa4e0da" dependencies = [ "async-trait", "base64-simd 0.8.0", @@ -971,17 +980,19 @@ dependencies = [ "flate2", "futures", "serde", + "thiserror", "tokio", "uuid", ] [[package]] name = "deno_webgpu" -version = "0.131.0" +version = "0.146.0" dependencies = [ "deno_core", "raw-window-handle 0.6.2", "serde", + "thiserror", "tokio", "wgpu-core", "wgpu-types", @@ -989,9 +1000,9 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.164.0" +version = "0.179.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4411072b4e79c6e5c423563feb8d9f9188a8b378b5d94436db0cbcfb2620539" +checksum = "5b55d845e3d64f8de7eff67aaa4b6fe1b23bbc2efe967c984f8c64c8dd85fad4" dependencies = [ "deno_core", ] @@ -1007,19 +1018,6 @@ dependencies = [ "syn", ] -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn", -] - [[package]] name = "diff" version = "0.1.13" @@ -1786,12 +1784,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.155" @@ -2742,16 +2734,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.23", + "semver", ] [[package]] @@ -2822,12 +2805,6 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "semver-parser" version = "0.7.0" @@ -2869,9 +2846,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.208.0" +version = "0.230.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583f3c71a6f7acc1711ad718a33f6e799bacdc711d297b15bb28533f32264c58" +checksum = "b5a783242d2af51d6955cc04bf2b64adb643ab588b61e9573c908a69dabf8c2f" dependencies = [ "num-bigint", "serde", @@ -2999,7 +2976,7 @@ dependencies = [ "debugid", "if_chain", "rustc-hash", - "rustc_version 0.2.3", + "rustc_version", "serde", "serde_json", "unicode-id-start", @@ -3045,6 +3022,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +[[package]] +name = "stringcase" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04028eeb851ed08af6aba5caa29f2d59a13ed168cee4d6bd753aeefcf1d636b0" + [[package]] name = "strsim" version = "0.11.1" @@ -3419,11 +3402,10 @@ dependencies = [ [[package]] name = "urlpattern" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9bd5ff03aea02fa45b13a7980151fe45009af1980ba69f651ec367121a31609" +checksum = "70acd30e3aa1450bc2eece896ce2ad0d178e9c079493819301573dae3c37ba6d" dependencies = [ - "derive_more", "regex", "serde", "unic-ucd-ident", @@ -3448,9 +3430,9 @@ dependencies = [ [[package]] name = "v8" -version = "0.99.0" +version = "130.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3fc0608a78f0c7d4ec88025759cb78c90a29984b48540060355a626ae329c1" +checksum = "c23b5c2caff00209b03a716609b275acae94b02dd3b63c4648e7232a84a8402f" dependencies = [ "bindgen", "bitflags 2.6.0", @@ -3589,6 +3571,15 @@ dependencies = [ "syn", ] +[[package]] +name = "wasm_dep_analyzer" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f270206a91783fd90625c8bb0d8fbd459d0b1d1bf209b656f713f01ae7c04b8" +dependencies = [ + "thiserror", +] + [[package]] name = "wayland-backend" version = "0.3.6" diff --git a/Cargo.toml b/Cargo.toml index 38d4eb8f50..1cb71435c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,12 +172,12 @@ web-sys = "0.3.72" web-time = "0.2.4" # deno dependencies -deno_console = "0.164.0" -deno_core = "0.299.0" -deno_url = "0.164.0" -deno_web = "0.195.0" -deno_webidl = "0.164.0" -deno_webgpu = { version = "0.131.0", path = "./deno_webgpu" } +deno_console = "0.179.0" +deno_core = "0.321.0" +deno_url = "0.179.0" +deno_web = "0.210.0" +deno_webidl = "0.179.0" +deno_webgpu = { version = "0.146.0", path = "./deno_webgpu" } tokio = "1.41.0" termcolor = "1.4.1" diff --git a/cts_runner/src/main.rs b/cts_runner/src/main.rs index fe8c1cf818..1899c122c1 100644 --- a/cts_runner/src/main.rs +++ b/cts_runner/src/main.rs @@ -21,6 +21,78 @@ mod native { use termcolor::ColorSpec; use termcolor::WriteColor; + // temporary + fn get_webgpu_error_class(e: &deno_webgpu::InitError) -> &'static str { + match e { + deno_webgpu::InitError::Resource(e) => { + deno_core::error::get_custom_error_class(e).unwrap_or("Error") + } + deno_webgpu::InitError::RequestDevice(_) => "DOMExceptionOperationError", + } + } + + fn get_webgpu_buffer_error_class(e: &deno_webgpu::buffer::BufferError) -> &'static str { + match e { + deno_webgpu::buffer::BufferError::Resource(e) => { + deno_core::error::get_custom_error_class(e).unwrap_or("Error") + } + deno_webgpu::buffer::BufferError::InvalidUsage => "TypeError", + deno_webgpu::buffer::BufferError::Access(_) => "DOMExceptionOperationError", + deno_webgpu::buffer::BufferError::Canceled(_) => "Error", + } + } + + fn get_webgpu_bundle_error_class(e: &deno_webgpu::bundle::BundleError) -> &'static str { + match e { + deno_webgpu::bundle::BundleError::Resource(e) => { + deno_core::error::get_custom_error_class(e).unwrap_or("Error") + } + deno_webgpu::bundle::BundleError::InvalidSize => "TypeError", + } + } + + fn get_webgpu_byow_error_class(e: &deno_webgpu::byow::ByowError) -> &'static str { + match e { + deno_webgpu::byow::ByowError::WebGPUNotInitiated => "TypeError", + deno_webgpu::byow::ByowError::InvalidParameters => "TypeError", + deno_webgpu::byow::ByowError::CreateSurface(_) => "Error", + deno_webgpu::byow::ByowError::InvalidSystem => "TypeError", + #[cfg(any( + target_os = "windows", + target_os = "linux", + target_os = "freebsd", + target_os = "openbsd" + ))] + deno_webgpu::byow::ByowError::NullWindow => "TypeError", + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] + deno_webgpu::byow::ByowError::NullDisplay => "TypeError", + #[cfg(target_os = "macos")] + deno_webgpu::byow::ByowError::NSViewDisplay => "TypeError", + } + } + + fn get_webgpu_render_pass_error_class( + e: &deno_webgpu::render_pass::RenderPassError, + ) -> &'static str { + match e { + deno_webgpu::render_pass::RenderPassError::Resource(e) => { + deno_core::error::get_custom_error_class(e).unwrap_or("Error") + } + deno_webgpu::render_pass::RenderPassError::InvalidSize => "TypeError", + deno_webgpu::render_pass::RenderPassError::RenderPass(_) => "Error", + } + } + + fn get_webgpu_surface_error_class(e: &deno_webgpu::surface::SurfaceError) -> &'static str { + match e { + deno_webgpu::surface::SurfaceError::Resource(e) => { + deno_core::error::get_custom_error_class(e).unwrap_or("Error") + } + deno_webgpu::surface::SurfaceError::Surface(_) => "Error", + deno_webgpu::surface::SurfaceError::InvalidStatus => "Error", + } + } + pub async fn run() -> Result<(), AnyError> { let mut args_iter = env::args(); let _ = args_iter.next(); @@ -112,7 +184,30 @@ mod native { fn get_error_class_name(e: &AnyError) -> &'static str { deno_core::error::get_custom_error_class(e) - .or_else(|| deno_webgpu::error::get_error_class_name(e)) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_error_class) + }) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_buffer_error_class) + }) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_bundle_error_class) + }) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_byow_error_class) + }) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_render_pass_error_class) + }) + .or_else(|| { + e.downcast_ref::() + .map(get_webgpu_surface_error_class) + }) .unwrap_or_else(|| { panic!("Error '{e}' contains boxed error of unsupported type: {e:#}"); }) diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index 8ab6bebd5b..0222391713 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -98,6 +98,11 @@ const { ArrayPrototypePush, DataViewPrototypeGetBuffer, Error, + Number, + NumberPOSITIVE_INFINITY, + NumberMAX_SAFE_INTEGER, + NumberNEGATIVE_INFINITY, + NumberMIN_SAFE_INTEGER, MathMax, ObjectDefineProperty, ObjectHasOwn, @@ -137,6 +142,8 @@ const _mappingRange = Symbol("[[mapping_range]]"); const _mappedRanges = Symbol("[[mapped_ranges]]"); const _mapMode = Symbol("[[map_mode]]"); const _adapter = Symbol("[[adapter]]"); +const _adapterInfo = Symbol("[[adapterInfo]]"); +const _invalid = Symbol("[[invalid]]"); const _cleanup = Symbol("[[cleanup]]"); const _vendor = Symbol("[[vendor]]"); const _architecture = Symbol("[[architecture]]"); @@ -173,7 +180,7 @@ function assertDevice(self, prefix, context) { const deviceRid = device?.rid; if (deviceRid === undefined) { throw new DOMException( - `${prefix}: ${context} references an invalid or destroyed device.`, + `${prefix}: ${context} references an invalid or destroyed device`, "OperationError", ); } @@ -190,7 +197,7 @@ function assertResource(self, prefix, context) { const rid = self[_rid]; if (rid === undefined) { throw new DOMException( - `${prefix}: ${context} an invalid or destroyed resource.`, + `${prefix}: ${context} an invalid or destroyed resource`, "OperationError", ); } @@ -396,11 +403,11 @@ function createGPUAdapter(inner) { return adapter; } -const _invalid = Symbol("[[invalid]]"); class GPUAdapter { /** @type {InnerGPUAdapter} */ [_adapter]; - /** @type {bool} */ + [_adapterInfo]; + /** @type {boolean} */ [_invalid]; /** @returns {GPUSupportedFeatures} */ @@ -416,7 +423,7 @@ class GPUAdapter { /** @returns {boolean} */ get isFallbackAdapter() { webidl.assertBranded(this, GPUAdapterPrototype); - return this[_adapter].isFallbackAdapter; + return this[_adapter].isFallback; } constructor() { @@ -443,7 +450,7 @@ class GPUAdapter { !SetPrototypeHas(this[_adapter].features[webidl.setlikeInner], feature) ) { throw new TypeError( - `${prefix}: requiredFeatures must be a subset of the adapter features.`, + `${prefix}: requiredFeatures must be a subset of the adapter features`, ); } } @@ -481,11 +488,15 @@ class GPUAdapter { } /** - * @returns {Promise} + * @returns {GPUAdapterInfo} */ - requestAdapterInfo() { + get info() { webidl.assertBranded(this, GPUAdapterPrototype); + if (this[_adapterInfo] !== undefined) { + return this[_adapterInfo]; + } + if (this[_invalid]) { throw new TypeError( "The adapter cannot be reused, as it has been invalidated by a device creation", @@ -504,7 +515,8 @@ class GPUAdapter { adapterInfo[_architecture] = architecture; adapterInfo[_device] = device; adapterInfo[_description] = description; - return PromiseResolve(adapterInfo); + this[_adapterInfo] = adapterInfo; + return adapterInfo; } [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { @@ -515,6 +527,7 @@ class GPUAdapter { keys: [ "features", "limits", + "info", "isFallbackAdapter", ], }), @@ -582,6 +595,18 @@ function createGPUSupportedLimits(limits) { return adapterFeatures; } +function normalizeLimit(limit) { + if (typeof limit === "bigint") { + limit = Number(limit); + if (limit === NumberPOSITIVE_INFINITY) { + limit = NumberMAX_SAFE_INTEGER; + } else if (limit === NumberNEGATIVE_INFINITY) { + limit = NumberMIN_SAFE_INTEGER; + } + } + return limit; +} + /** * @typedef InnerAdapterLimits * @property {number} maxTextureDimension1D @@ -621,123 +646,127 @@ class GPUSupportedLimits { get maxTextureDimension1D() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxTextureDimension1D; + return normalizeLimit(this[_limits].maxTextureDimension1D); } get maxTextureDimension2D() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxTextureDimension2D; + return normalizeLimit(this[_limits].maxTextureDimension2D); } get maxTextureDimension3D() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxTextureDimension3D; + return normalizeLimit(this[_limits].maxTextureDimension3D); } get maxTextureArrayLayers() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxTextureArrayLayers; + return normalizeLimit(this[_limits].maxTextureArrayLayers); } get maxBindGroups() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxBindGroups; + return normalizeLimit(this[_limits].maxBindGroups); } get maxBindingsPerBindGroup() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxBindingsPerBindGroup; + return normalizeLimit(this[_limits].maxBindingsPerBindGroup); } get maxBufferSize() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxBufferSize; + return normalizeLimit(this[_limits].maxBufferSize); } get maxDynamicUniformBuffersPerPipelineLayout() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxDynamicUniformBuffersPerPipelineLayout; + return normalizeLimit( + this[_limits].maxDynamicUniformBuffersPerPipelineLayout, + ); } get maxDynamicStorageBuffersPerPipelineLayout() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxDynamicStorageBuffersPerPipelineLayout; + return normalizeLimit( + this[_limits].maxDynamicStorageBuffersPerPipelineLayout, + ); } get maxSampledTexturesPerShaderStage() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxSampledTexturesPerShaderStage; + return normalizeLimit(this[_limits].maxSampledTexturesPerShaderStage); } get maxSamplersPerShaderStage() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxSamplersPerShaderStage; + return normalizeLimit(this[_limits].maxSamplersPerShaderStage); } get maxStorageBuffersPerShaderStage() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxStorageBuffersPerShaderStage; + return normalizeLimit(this[_limits].maxStorageBuffersPerShaderStage); } get maxStorageTexturesPerShaderStage() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxStorageTexturesPerShaderStage; + return normalizeLimit(this[_limits].maxStorageTexturesPerShaderStage); } get maxUniformBuffersPerShaderStage() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxUniformBuffersPerShaderStage; + return normalizeLimit(this[_limits].maxUniformBuffersPerShaderStage); } get maxUniformBufferBindingSize() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxUniformBufferBindingSize; + return normalizeLimit(this[_limits].maxUniformBufferBindingSize); } get maxStorageBufferBindingSize() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxStorageBufferBindingSize; + return normalizeLimit(this[_limits].maxStorageBufferBindingSize); } get minUniformBufferOffsetAlignment() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].minUniformBufferOffsetAlignment; + return normalizeLimit(this[_limits].minUniformBufferOffsetAlignment); } get minStorageBufferOffsetAlignment() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].minStorageBufferOffsetAlignment; + return normalizeLimit(this[_limits].minStorageBufferOffsetAlignment); } get maxVertexBuffers() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxVertexBuffers; + return normalizeLimit(this[_limits].maxVertexBuffers); } get maxVertexAttributes() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxVertexAttributes; + return normalizeLimit(this[_limits].maxVertexAttributes); } get maxVertexBufferArrayStride() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxVertexBufferArrayStride; + return normalizeLimit(this[_limits].maxVertexBufferArrayStride); } get maxInterStageShaderComponents() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxInterStageShaderComponents; + return normalizeLimit(this[_limits].maxInterStageShaderComponents); } get maxColorAttachments() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxColorAttachments; + return normalizeLimit(this[_limits].maxColorAttachments); } get maxColorAttachmentBytesPerSample() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxColorAttachmentBytesPerSample; + return normalizeLimit(this[_limits].maxColorAttachmentBytesPerSample); } get maxComputeWorkgroupStorageSize() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeWorkgroupStorageSize; + return normalizeLimit(this[_limits].maxComputeWorkgroupStorageSize); } get maxComputeInvocationsPerWorkgroup() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeInvocationsPerWorkgroup; + return normalizeLimit(this[_limits].maxComputeInvocationsPerWorkgroup); } get maxComputeWorkgroupSizeX() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeWorkgroupSizeX; + return normalizeLimit(this[_limits].maxComputeWorkgroupSizeX); } get maxComputeWorkgroupSizeY() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeWorkgroupSizeY; + return normalizeLimit(this[_limits].maxComputeWorkgroupSizeY); } get maxComputeWorkgroupSizeZ() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeWorkgroupSizeZ; + return normalizeLimit(this[_limits].maxComputeWorkgroupSizeZ); } get maxComputeWorkgroupsPerDimension() { webidl.assertBranded(this, GPUSupportedLimitsPrototype); - return this[_limits].maxComputeWorkgroupsPerDimension; + return normalizeLimit(this[_limits].maxComputeWorkgroupsPerDimension); } [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { @@ -875,6 +904,7 @@ const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype; function GPUObjectBaseMixin(name, type) { type.prototype[_label] = null; ObjectDefineProperty(type.prototype, "label", { + __proto__: null, /** * @return {string | null} */ @@ -1727,12 +1757,12 @@ class GPUDevice extends EventTarget { const prefix = "Failed to execute 'popErrorScope' on 'GPUDevice'"; const device = assertDevice(this, prefix, "this"); if (device.isLost) { - throw new DOMException("Device has been lost.", "OperationError"); + throw new DOMException("Device has been lost", "OperationError"); } const scope = ArrayPrototypePop(device.errorScopeStack); if (!scope) { throw new DOMException( - "There are no error scopes on the error scope stack.", + "There are no error scopes on the error scope stack", "OperationError", ); } @@ -2088,25 +2118,25 @@ class GPUBuffer { } if ((offset % 8) !== 0) { throw new DOMException( - `${prefix}: offset must be a multiple of 8.`, + `${prefix}: offset must be a multiple of 8, received ${offset}`, "OperationError", ); } if ((rangeSize % 4) !== 0) { throw new DOMException( - `${prefix}: rangeSize must be a multiple of 4.`, + `${prefix}: rangeSize must be a multiple of 4, received ${rangeSize}`, "OperationError", ); } if ((offset + rangeSize) > this[_size]) { throw new DOMException( - `${prefix}: offset + rangeSize must be less than or equal to buffer size.`, + `${prefix}: offset + rangeSize must be less than or equal to buffer size`, "OperationError", ); } if (this[_state] !== "unmapped") { throw new DOMException( - `${prefix}: GPUBuffer is not currently unmapped.`, + `${prefix}: GPUBuffer is not currently unmapped`, "OperationError", ); } @@ -2114,19 +2144,19 @@ class GPUBuffer { const writeMode = (mode & 0x0002) === 0x0002; if ((readMode && writeMode) || (!readMode && !writeMode)) { throw new DOMException( - `${prefix}: exactly one of READ or WRITE map mode must be set.`, + `${prefix}: exactly one of READ or WRITE map mode must be set`, "OperationError", ); } if (readMode && !((this[_usage] && 0x0001) === 0x0001)) { throw new DOMException( - `${prefix}: READ map mode not valid because buffer does not have MAP_READ usage.`, + `${prefix}: READ map mode not valid because buffer does not have MAP_READ usage`, "OperationError", ); } if (writeMode && !((this[_usage] && 0x0002) === 0x0002)) { throw new DOMException( - `${prefix}: WRITE map mode not valid because buffer does not have MAP_WRITE usage.`, + `${prefix}: WRITE map mode not valid because buffer does not have MAP_WRITE usage`, "OperationError", ); } @@ -2173,7 +2203,7 @@ class GPUBuffer { const mappedRanges = this[_mappedRanges]; if (!mappedRanges) { - throw new DOMException(`${prefix}: invalid state.`, "OperationError"); + throw new DOMException(`${prefix}: invalid state`, "OperationError"); } for (let i = 0; i < mappedRanges.length; ++i) { const { 0: buffer, 1: _rid, 2: start } = mappedRanges[i]; @@ -2184,7 +2214,7 @@ class GPUBuffer { (end >= offset && end < (offset + rangeSize)) ) { throw new DOMException( - `${prefix}: requested buffer overlaps with another mapped range.`, + `${prefix}: requested buffer overlaps with another mapped range`, "OperationError", ); } @@ -2210,14 +2240,14 @@ class GPUBuffer { const bufferRid = assertResource(this, prefix, "this"); if (this[_state] === "unmapped" || this[_state] === "destroyed") { throw new DOMException( - `${prefix}: buffer is not ready to be unmapped.`, + `${prefix}: buffer is not ready to be unmapped`, "OperationError", ); } if (this[_state] === "pending") { // TODO(lucacasonato): this is not spec compliant. throw new DOMException( - `${prefix}: can not unmap while mapping. This is a Deno limitation.`, + `${prefix}: can not unmap while mapping, this is a Deno limitation`, "OperationError", ); } else if ( @@ -2231,7 +2261,7 @@ class GPUBuffer { const mapMode = this[_mapMode]; if (mapMode === undefined) { throw new DOMException( - `${prefix}: invalid state.`, + `${prefix}: invalid state`, "OperationError", ); } @@ -2242,7 +2272,7 @@ class GPUBuffer { const mappedRanges = this[_mappedRanges]; if (!mappedRanges) { - throw new DOMException(`${prefix}: invalid state.`, "OperationError"); + throw new DOMException(`${prefix}: invalid state`, "OperationError"); } for (let i = 0; i < mappedRanges.length; ++i) { const { 0: buffer, 1: mappedRid } = mappedRanges[i]; @@ -5275,7 +5305,7 @@ webidl.converters["GPUExtent3D"] = (V, opts) => { if (V.length < min || V.length > max) { throw webidl.makeException( TypeError, - `A sequence of number used as a GPUExtent3D must have between ${min} and ${max} elements.`, + `A sequence of number used as a GPUExtent3D must have between ${min} and ${max} elements, received ${V.length} elements`, opts, ); } @@ -5285,7 +5315,7 @@ webidl.converters["GPUExtent3D"] = (V, opts) => { } throw webidl.makeException( TypeError, - "can not be converted to sequence or GPUExtent3DDict.", + "can not be converted to sequence or GPUExtent3DDict", opts, ); }; @@ -6623,7 +6653,7 @@ webidl.converters["GPUOrigin3D"] = (V, opts) => { if (V.length > length) { throw webidl.makeException( TypeError, - `A sequence of number used as a GPUOrigin3D must have at most ${length} elements.`, + `A sequence of number used as a GPUOrigin3D must have at most ${length} elements, received ${V.length} elements`, opts, ); } @@ -6633,7 +6663,7 @@ webidl.converters["GPUOrigin3D"] = (V, opts) => { } throw webidl.makeException( TypeError, - "can not be converted to sequence or GPUOrigin3DDict.", + "can not be converted to sequence or GPUOrigin3DDict", opts, ); }; @@ -6700,7 +6730,7 @@ webidl.converters["GPUOrigin2D"] = (V, opts) => { if (V.length > length) { throw webidl.makeException( TypeError, - `A sequence of number used as a GPUOrigin2D must have at most ${length} elements.`, + `A sequence of number used as a GPUOrigin2D must have at most ${length} elements`, opts, ); } @@ -6721,6 +6751,12 @@ webidl.converters.GPUComputePassEncoder = webidl.createInterfaceConverter( GPUComputePassEncoder.prototype, ); +// INTERFACE: GPUQuerySet +webidl.converters.GPUQuerySet = webidl.createInterfaceConverter( + "GPUQuerySet", + GPUQuerySet.prototype, +); + // DICTIONARY: GPUComputePassTimestampWrites webidl.converters["GPUComputePassTimestampWrites"] = webidl .createDictionaryConverter( @@ -6794,7 +6830,7 @@ webidl.converters["GPUColor"] = (V, opts) => { if (V.length !== length) { throw webidl.makeException( TypeError, - `A sequence of number used as a GPUColor must have exactly ${length} elements.`, + `A sequence of number used as a GPUColor must have exactly ${length} elements, received ${V.length} elements`, opts, ); } @@ -6804,7 +6840,7 @@ webidl.converters["GPUColor"] = (V, opts) => { } throw webidl.makeException( TypeError, - "can not be converted to sequence or GPUColorDict.", + "can not be converted to sequence or GPUColorDict", opts, ); }; @@ -6893,12 +6929,6 @@ webidl.converters["GPURenderPassDepthStencilAttachment"] = webidl dictMembersGPURenderPassDepthStencilAttachment, ); -// INTERFACE: GPUQuerySet -webidl.converters.GPUQuerySet = webidl.createInterfaceConverter( - "GPUQuerySet", - GPUQuerySet.prototype, -); - // DICTIONARY: GPURenderPassTimestampWrites webidl.converters["GPURenderPassTimestampWrites"] = webidl .createDictionaryConverter( @@ -7173,16 +7203,6 @@ const dictMembersGPUCanvasConfiguration = [ 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( diff --git a/deno_webgpu/02_surface.js b/deno_webgpu/02_surface.js index f35f745af4..1861b59b77 100644 --- a/deno_webgpu/02_surface.js +++ b/deno_webgpu/02_surface.js @@ -29,6 +29,8 @@ const _configuration = Symbol("[[configuration]]"); const _canvas = Symbol("[[canvas]]"); const _currentTexture = Symbol("[[currentTexture]]"); const _present = Symbol("[[present]]"); +const _dim = Symbol("[[dimensions]]"); + class GPUCanvasContext { /** @type {number} */ [_surfaceRid]; @@ -36,6 +38,7 @@ class GPUCanvasContext { [_canvas]; /** @type {GPUTexture | undefined} */ [_currentTexture]; + [_dim]; get canvas() { webidl.assertBranded(this, GPUCanvasContextPrototype); @@ -69,8 +72,8 @@ class GPUCanvasContext { format: configuration.format, viewFormats: configuration.viewFormats, usage: configuration.usage, - width: configuration.width, - height: configuration.height, + width: this[_dim].width, + height: this[_dim].height, alphaMode: configuration.alphaMode, }); @@ -92,7 +95,7 @@ class GPUCanvasContext { "Failed to execute 'getCurrentTexture' on 'GPUCanvasContext'"; if (this[_configuration] === null) { - throw new DOMException("context is not configured.", "InvalidStateError"); + throw new DOMException("Context is not configured", "InvalidStateError"); } const { createGPUTexture, assertDevice } = loadWebGPU(); @@ -163,6 +166,7 @@ function createCanvasContext(options) { const canvasContext = webidl.createBranded(GPUCanvasContext); canvasContext[_surfaceRid] = options.surfaceRid; canvasContext[_canvas] = options.canvas; + canvasContext[_dim] = { width: options.width, height: options.height }; return canvasContext; } @@ -172,16 +176,34 @@ function createCanvasContext(options) { class UnsafeWindowSurface { #ctx; #surfaceRid; + #options; + + constructor(options) { + if (typeof options !== "object") { + throw new TypeError("options must be provided."); + } + if ( + typeof options.width !== "number" || typeof options.height !== "number" + ) { + throw new TypeError("width and height must be provided."); + } - constructor(system, win, display) { - this.#surfaceRid = op_webgpu_surface_create(system, win, display); + this.#surfaceRid = op_webgpu_surface_create( + options.system, + options.windowHandle, + options.displayHandle, + ); + this.#options = options; } getContext(context) { if (context !== "webgpu") { - throw new TypeError("Only 'webgpu' context is supported."); + throw new TypeError("Only 'webgpu' context is supported"); } - this.#ctx = createCanvasContext({ surfaceRid: this.#surfaceRid }); + this.#ctx = createCanvasContext({ + surfaceRid: this.#surfaceRid, + ...this.#options, + }); return this.#ctx; } diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index b98b9eca42..af1a3ed686 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webgpu" -version = "0.131.0" +version = "0.146.0" authors = ["the Deno authors"] edition.workspace = true license = "MIT" @@ -21,6 +21,7 @@ serde = { workspace = true, features = ["derive"] } tokio = { workspace = true, features = ["full"] } wgt = { workspace = true, package = "wgpu-types", features = ["serde"] } raw-window-handle = { workspace = true } +thiserror.workspace = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgpu-core] workspace = true diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index 7adda54418..0a422f8f6e 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -1,10 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use super::error::DomExceptionOperationError; use super::error::WebGpuResult; use super::wgpu_types; -use deno_core::error::type_error; -use deno_core::error::AnyError; use deno_core::futures::channel::oneshot; use deno_core::op2; use deno_core::OpState; @@ -17,6 +14,18 @@ use std::rc::Rc; use std::time::Duration; use wgpu_core::resource::BufferAccessResult; +#[derive(Debug, thiserror::Error)] +pub enum BufferError { + #[error(transparent)] + Resource(deno_core::error::AnyError), + #[error("usage is not valid")] + InvalidUsage, + #[error(transparent)] + Access(#[from] wgpu_core::resource::BufferAccessError), + #[error(transparent)] + Canceled(#[from] oneshot::Canceled), +} + pub(crate) struct WebGpuBuffer( pub(crate) super::Instance, pub(crate) wgpu_core::id::BufferId, @@ -47,18 +56,18 @@ pub fn op_webgpu_create_buffer( #[number] size: u64, usage: u32, mapped_at_creation: bool, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(device_rid)?; + .get::(device_rid) + .map_err(BufferError::Resource)?; let device = device_resource.1; let descriptor = wgpu_core::resource::BufferDescriptor { label: Some(label), size, - usage: wgpu_types::BufferUsages::from_bits(usage) - .ok_or_else(|| type_error("usage is not valid"))?, + usage: wgpu_types::BufferUsages::from_bits(usage).ok_or(BufferError::InvalidUsage)?, mapped_at_creation, }; @@ -78,18 +87,22 @@ pub async fn op_webgpu_buffer_get_map_async( mode: u32, #[number] offset: u64, #[number] size: u64, -) -> Result { +) -> Result { let (sender, receiver) = oneshot::channel::(); let device; { let state_ = state.borrow(); let instance = state_.borrow::(); - let buffer_resource = state_.resource_table.get::(buffer_rid)?; + let buffer_resource = state_ + .resource_table + .get::(buffer_rid) + .map_err(BufferError::Resource)?; let buffer = buffer_resource.1; let device_resource = state_ .resource_table - .get::(device_rid)?; + .get::(device_rid) + .map_err(BufferError::Resource)?; device = device_resource.1; let callback = Box::new(move |status| { @@ -131,14 +144,14 @@ pub async fn op_webgpu_buffer_get_map_async( } tokio::time::sleep(Duration::from_millis(10)).await; } - Ok::<(), AnyError>(()) + Ok::<(), BufferError>(()) }; let receiver_fut = async move { receiver.await??; let mut done = done_.borrow_mut(); *done = true; - Ok::<(), AnyError>(()) + Ok::<(), BufferError>(()) }; tokio::try_join!(device_poll_fut, receiver_fut)?; @@ -154,14 +167,17 @@ pub fn op_webgpu_buffer_get_mapped_range( #[number] offset: u64, #[number] size: Option, #[buffer] buf: &mut [u8], -) -> Result { +) -> Result { let instance = state.borrow::(); - let buffer_resource = state.resource_table.get::(buffer_rid)?; + let buffer_resource = state + .resource_table + .get::(buffer_rid) + .map_err(BufferError::Resource)?; let buffer = buffer_resource.1; let (slice_pointer, range_size) = instance .buffer_get_mapped_range(buffer, offset, size) - .map_err(|e| DomExceptionOperationError::new(&e.to_string()))?; + .map_err(BufferError::Access)?; // SAFETY: guarantee to be safe from wgpu let slice = @@ -182,12 +198,16 @@ pub fn op_webgpu_buffer_unmap( #[smi] buffer_rid: ResourceId, #[smi] mapped_rid: ResourceId, #[buffer] buf: Option<&[u8]>, -) -> Result { +) -> Result { let mapped_resource = state .resource_table - .take::(mapped_rid)?; + .take::(mapped_rid) + .map_err(BufferError::Resource)?; let instance = state.borrow::(); - let buffer_resource = state.resource_table.get::(buffer_rid)?; + let buffer_resource = state + .resource_table + .get::(buffer_rid) + .map_err(BufferError::Resource)?; let buffer = buffer_resource.1; if let Some(buf) = buf { diff --git a/deno_webgpu/bundle.rs b/deno_webgpu/bundle.rs index 8e28fdfa1d..d612a6d6ce 100644 --- a/deno_webgpu/bundle.rs +++ b/deno_webgpu/bundle.rs @@ -1,8 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::wgpu_types; -use deno_core::error::type_error; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -12,6 +10,14 @@ use std::borrow::Cow; use std::cell::RefCell; use std::rc::Rc; +#[derive(Debug, thiserror::Error)] +pub enum BundleError { + #[error(transparent)] + Resource(deno_core::error::AnyError), + #[error("size must be larger than 0")] + InvalidSize, +} + use super::error::WebGpuResult; struct WebGpuRenderBundleEncoder(RefCell); @@ -52,7 +58,7 @@ pub struct CreateRenderBundleEncoderArgs { pub fn op_webgpu_create_render_bundle_encoder( state: &mut OpState, #[serde] args: CreateRenderBundleEncoderArgs, -) -> Result { +) -> Result { let device_resource = state .resource_table .get::(args.device_rid)?; @@ -98,7 +104,7 @@ pub fn op_webgpu_render_bundle_encoder_finish( state: &mut OpState, #[smi] render_bundle_encoder_rid: ResourceId, #[string] label: Cow, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .take::(render_bundle_encoder_rid)?; @@ -128,7 +134,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( #[buffer] dynamic_offsets_data: &[u32], #[number] dynamic_offsets_data_start: usize, #[number] dynamic_offsets_data_length: usize, -) -> Result { +) -> Result { let bind_group_resource = state .resource_table .get::(bind_group)?; @@ -166,7 +172,7 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group( state: &mut OpState, #[smi] render_bundle_encoder_rid: ResourceId, #[string] group_label: &str, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .get::(render_bundle_encoder_rid)?; @@ -189,7 +195,7 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group( pub fn op_webgpu_render_bundle_encoder_pop_debug_group( state: &mut OpState, #[smi] render_bundle_encoder_rid: ResourceId, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .get::(render_bundle_encoder_rid)?; @@ -207,7 +213,7 @@ pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( state: &mut OpState, #[smi] render_bundle_encoder_rid: ResourceId, #[string] marker_label: &str, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .get::(render_bundle_encoder_rid)?; @@ -231,7 +237,7 @@ pub fn op_webgpu_render_bundle_encoder_set_pipeline( state: &mut OpState, #[smi] render_bundle_encoder_rid: ResourceId, #[smi] pipeline: ResourceId, -) -> Result { +) -> Result { let render_pipeline_resource = state .resource_table .get::(pipeline)?; @@ -256,16 +262,16 @@ pub fn op_webgpu_render_bundle_encoder_set_index_buffer( #[serde] index_format: wgpu_types::IndexFormat, #[number] offset: u64, #[number] size: u64, -) -> Result { +) -> Result { let buffer_resource = state .resource_table - .get::(buffer)?; + .get::(buffer) + .map_err(BundleError::Resource)?; let render_bundle_encoder_resource = state .resource_table - .get::(render_bundle_encoder_rid)?; - let size = Some( - std::num::NonZeroU64::new(size).ok_or_else(|| type_error("size must be larger than 0"))?, - ); + .get::(render_bundle_encoder_rid) + .map_err(BundleError::Resource)?; + let size = Some(std::num::NonZeroU64::new(size).ok_or(BundleError::InvalidSize)?); render_bundle_encoder_resource .0 @@ -284,18 +290,17 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( #[smi] buffer: ResourceId, #[number] offset: u64, #[number] size: Option, -) -> Result { +) -> Result { let buffer_resource = state .resource_table - .get::(buffer)?; + .get::(buffer) + .map_err(BundleError::Resource)?; let render_bundle_encoder_resource = state .resource_table - .get::(render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid) + .map_err(BundleError::Resource)?; let size = if let Some(size) = size { - Some( - std::num::NonZeroU64::new(size) - .ok_or_else(|| type_error("size must be larger than 0"))?, - ) + Some(std::num::NonZeroU64::new(size).ok_or(BundleError::InvalidSize)?) } else { None }; @@ -320,7 +325,7 @@ pub fn op_webgpu_render_bundle_encoder_draw( instance_count: u32, first_vertex: u32, first_instance: u32, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .get::(render_bundle_encoder_rid)?; @@ -346,7 +351,7 @@ pub fn op_webgpu_render_bundle_encoder_draw_indexed( first_index: u32, base_vertex: i32, first_instance: u32, -) -> Result { +) -> Result { let render_bundle_encoder_resource = state .resource_table .get::(render_bundle_encoder_rid)?; @@ -370,7 +375,7 @@ pub fn op_webgpu_render_bundle_encoder_draw_indirect( #[smi] render_bundle_encoder_rid: ResourceId, #[smi] indirect_buffer: ResourceId, #[number] indirect_offset: u64, -) -> Result { +) -> Result { let buffer_resource = state .resource_table .get::(indirect_buffer)?; diff --git a/deno_webgpu/byow.rs b/deno_webgpu/byow.rs index 1002458c90..17182f0128 100644 --- a/deno_webgpu/byow.rs +++ b/deno_webgpu/byow.rs @@ -1,7 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::error::type_error; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::ResourceId; @@ -16,6 +14,39 @@ use std::ptr::NonNull; use crate::surface::WebGpuSurface; +#[derive(Debug, thiserror::Error)] +pub enum ByowError { + #[error("Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?")] + WebGPUNotInitiated, + #[error("Invalid parameters")] + InvalidParameters, + #[error(transparent)] + CreateSurface(wgpu_core::instance::CreateSurfaceError), + #[cfg(target_os = "windows")] + #[error("Invalid system on Windows")] + InvalidSystem, + #[cfg(target_os = "macos")] + #[error("Invalid system on macOS")] + InvalidSystem, + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] + #[error("Invalid system on Linux/BSD")] + InvalidSystem, + #[cfg(any( + target_os = "windows", + target_os = "linux", + target_os = "freebsd", + target_os = "openbsd" + ))] + #[error("window is null")] + NullWindow, + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] + #[error("display is null")] + NullDisplay, + #[cfg(target_os = "macos")] + #[error("ns_view is null")] + NSViewDisplay, +} + #[op2(fast)] #[smi] pub fn op_webgpu_surface_create( @@ -23,10 +54,10 @@ pub fn op_webgpu_surface_create( #[string] system: &str, p1: *const c_void, p2: *const c_void, -) -> Result { - let instance = state.try_borrow::().ok_or_else(|| { - type_error("Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?") - })?; +) -> Result { + let instance = state + .try_borrow::() + .ok_or(ByowError::WebGPUNotInitiated)?; // Security note: // // The `p1` and `p2` parameters are pointers to platform-specific window @@ -41,12 +72,16 @@ pub fn op_webgpu_surface_create( // // - Only FFI can export v8::External to user code. if p1.is_null() { - return Err(type_error("Invalid parameters")); + return Err(ByowError::InvalidParameters); } let (win_handle, display_handle) = raw_window(system, p1, p2)?; // SAFETY: see above comment - let surface = unsafe { instance.instance_create_surface(display_handle, win_handle, None)? }; + let surface = unsafe { + instance + .instance_create_surface(display_handle, win_handle, None) + .map_err(ByowError::CreateSurface)? + }; let rid = state .resource_table @@ -64,14 +99,14 @@ fn raw_window( system: &str, _ns_window: *const c_void, ns_view: *const c_void, -) -> Result { +) -> Result { if system != "cocoa" { - return Err(type_error("Invalid system on macOS")); + return Err(ByowError::InvalidSystem); } let win_handle = raw_window_handle::RawWindowHandle::AppKit(raw_window_handle::AppKitWindowHandle::new( - NonNull::new(ns_view as *mut c_void).ok_or(type_error("ns_view is null"))?, + NonNull::new(ns_view as *mut c_void).ok_or(ByowError::NSViewDisplay)?, )); let display_handle = @@ -84,15 +119,15 @@ fn raw_window( system: &str, window: *const c_void, hinstance: *const c_void, -) -> Result { +) -> Result { use raw_window_handle::WindowsDisplayHandle; if system != "win32" { - return Err(type_error("Invalid system on Windows")); + return Err(ByowError::InvalidSystem); } let win_handle = { let mut handle = raw_window_handle::Win32WindowHandle::new( - std::num::NonZeroIsize::new(window as isize).ok_or(type_error("window is null"))?, + std::num::NonZeroIsize::new(window as isize).ok_or(ByowError::NullWindow)?, ); handle.hinstance = std::num::NonZeroIsize::new(hinstance as isize); @@ -108,7 +143,7 @@ fn raw_window( system: &str, window: *const c_void, display: *const c_void, -) -> Result { +) -> Result { let (win_handle, display_handle); if system == "x11" { win_handle = raw_window_handle::RawWindowHandle::Xlib( @@ -121,18 +156,33 @@ fn raw_window( } else if system == "wayland" { win_handle = raw_window_handle::RawWindowHandle::Wayland( raw_window_handle::WaylandWindowHandle::new( - NonNull::new(window as *mut c_void).ok_or(type_error("window is null"))?, + NonNull::new(window as *mut c_void).ok_or(ByowError::NullWindow)?, ), ); display_handle = raw_window_handle::RawDisplayHandle::Wayland( raw_window_handle::WaylandDisplayHandle::new( - NonNull::new(display as *mut c_void).ok_or(type_error("display is null"))?, + NonNull::new(display as *mut c_void).ok_or(ByowError::NullDisplay)?, ), ); } else { - return Err(type_error("Invalid system on Linux/BSD")); + return Err(ByowError::InvalidSystem); } Ok((win_handle, display_handle)) } + +#[cfg(not(any( + target_os = "macos", + target_os = "windows", + target_os = "linux", + target_os = "freebsd", + target_os = "openbsd", +)))] +fn raw_window( + _system: &str, + _window: *const c_void, + _display: *const c_void, +) -> Result { + Err(deno_core::error::type_error("Unsupported platform")) +} diff --git a/deno_webgpu/error.rs b/deno_webgpu/error.rs index caea7d9d81..8af30f62de 100644 --- a/deno_webgpu/error.rs +++ b/deno_webgpu/error.rs @@ -1,11 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use deno_core::error::AnyError; use deno_core::ResourceId; use serde::Serialize; use std::convert::From; use std::error::Error; -use std::fmt; use std::fmt::Write; use wgpu_core::binding_model::CreateBindGroupError; use wgpu_core::binding_model::CreateBindGroupLayoutError; @@ -68,7 +66,6 @@ pub struct WebGpuResult { } impl WebGpuResult { - #[must_use] pub fn rid(rid: ResourceId) -> Self { Self { rid: Some(rid), @@ -76,7 +73,6 @@ impl WebGpuResult { } } - #[must_use] pub fn rid_err>(rid: ResourceId, err: Option) -> Self { Self { rid: Some(rid), @@ -84,7 +80,6 @@ impl WebGpuResult { } } - #[must_use] pub fn maybe_err>(err: Option) -> Self { Self { rid: None, @@ -92,7 +87,6 @@ impl WebGpuResult { } } - #[must_use] pub fn empty() -> Self { Self { rid: None, @@ -304,31 +298,3 @@ impl From for WebGpuError { WebGpuError::Validation(fmt_err(&err)) } } - -#[derive(Debug)] -pub struct DomExceptionOperationError { - pub msg: String, -} - -impl DomExceptionOperationError { - #[must_use] - pub fn new(msg: &str) -> Self { - DomExceptionOperationError { - msg: msg.to_string(), - } - } -} - -impl fmt::Display for DomExceptionOperationError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.pad(&self.msg) - } -} - -impl std::error::Error for DomExceptionOperationError {} - -#[must_use] -pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> { - e.downcast_ref::() - .map(|_| "DOMExceptionOperationError") -} diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 2e1c8fdeb2..854a3d32a7 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -2,7 +2,6 @@ #![cfg(not(target_arch = "wasm32"))] #![warn(unsafe_op_in_unsafe_fn)] -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -16,7 +15,6 @@ use std::rc::Rc; pub use wgpu_core; pub use wgt as wgpu_types; -use error::DomExceptionOperationError; use error::WebGpuResult; pub const UNSTABLE_FEATURE_NAME: &str = "webgpu"; @@ -54,6 +52,14 @@ pub mod shader; pub mod surface; pub mod texture; +#[derive(Debug, thiserror::Error)] +pub enum InitError { + #[error(transparent)] + Resource(deno_core::error::AnyError), + #[error(transparent)] + RequestDevice(wgpu_core::instance::RequestDeviceError), +} + pub type Instance = std::sync::Arc; struct WebGpuAdapter(Instance, wgpu_core::id::AdapterId); @@ -352,7 +358,7 @@ pub struct GpuAdapterRes { rid: ResourceId, limits: wgpu_types::Limits, features: Vec<&'static str>, - is_software: bool, + is_fallback: bool, } #[derive(Serialize)] @@ -362,7 +368,6 @@ pub struct GpuDeviceRes { queue_rid: ResourceId, limits: wgpu_types::Limits, features: Vec<&'static str>, - is_software: bool, } #[op2] @@ -371,15 +376,9 @@ pub fn op_webgpu_request_adapter( state: Rc>, #[serde] power_preference: Option, force_fallback_adapter: bool, -) -> Result { +) -> GpuAdapterResOrErr { let mut state = state.borrow_mut(); - // TODO(bartlomieju): replace with `state.feature_checker.check_or_exit` - // once we phase out `check_or_exit_with_legacy_fallback` - state - .feature_checker - .check_or_exit_with_legacy_fallback(UNSTABLE_FEATURE_NAME, "navigator.gpu.requestAdapter"); - let backends = std::env::var("DENO_WEBGPU_BACKEND").map_or_else( |_| wgpu_types::Backends::all(), |s| wgpu_core::instance::parse_backends_from_comma_list(&s), @@ -409,9 +408,9 @@ pub fn op_webgpu_request_adapter( let adapter = match res { Ok(adapter) => adapter, Err(err) => { - return Ok(GpuAdapterResOrErr::Error { + return GpuAdapterResOrErr::Error { err: err.to_string(), - }) + } } }; let adapter_features = instance.adapter_features(adapter); @@ -422,12 +421,13 @@ pub fn op_webgpu_request_adapter( let rid = state.resource_table.add(WebGpuAdapter(instance, adapter)); - Ok(GpuAdapterResOrErr::Features(GpuAdapterRes { + GpuAdapterResOrErr::Features(GpuAdapterRes { rid, features, limits: adapter_limits, - is_software: false, - })) + // TODO(lucacasonato): report correctly from wgpu + is_fallback: false, + }) } #[derive(Deserialize)] @@ -640,9 +640,12 @@ pub fn op_webgpu_request_device( #[string] label: String, #[serde] required_features: GpuRequiredFeatures, #[serde] required_limits: Option, -) -> Result { +) -> Result { let mut state = state.borrow_mut(); - let adapter_resource = state.resource_table.take::(adapter_rid)?; + let adapter_resource = state + .resource_table + .take::(adapter_rid) + .map_err(InitError::Resource)?; let adapter = adapter_resource.1; let instance = state.borrow::(); @@ -665,7 +668,7 @@ pub fn op_webgpu_request_device( ); adapter_resource.close(); - let (device, queue) = res.map_err(|err| DomExceptionOperationError::new(&err.to_string()))?; + let (device, queue) = res.map_err(InitError::RequestDevice)?; let device_features = instance.device_features(device); let features = deserialize_features(&device_features); @@ -683,8 +686,6 @@ pub fn op_webgpu_request_device( queue_rid, features, limits, - // TODO(lucacasonato): report correctly from wgpu - is_software: false, }) } @@ -702,9 +703,9 @@ pub struct GPUAdapterInfo { pub fn op_webgpu_request_adapter_info( state: Rc>, #[smi] adapter_rid: ResourceId, -) -> Result { - let mut state = state.borrow_mut(); - let adapter_resource = state.resource_table.take::(adapter_rid)?; +) -> Result { + let state = state.borrow_mut(); + let adapter_resource = state.resource_table.get::(adapter_rid)?; let adapter = adapter_resource.1; let instance = state.borrow::(); @@ -750,7 +751,7 @@ impl From for wgpu_types::QueryType { pub fn op_webgpu_create_query_set( state: &mut OpState, #[serde] args: CreateQuerySetArgs, -) -> Result { +) -> Result { let device_resource = state.resource_table.get::(args.device_rid)?; let device = device_resource.1; let instance = state.borrow::(); diff --git a/deno_webgpu/render_pass.rs b/deno_webgpu/render_pass.rs index 2238b63e20..e5bd3cfd57 100644 --- a/deno_webgpu/render_pass.rs +++ b/deno_webgpu/render_pass.rs @@ -1,8 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::wgpu_types; -use deno_core::error::type_error; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -13,6 +11,16 @@ use std::cell::RefCell; use super::error::WebGpuResult; +#[derive(Debug, thiserror::Error)] +pub enum RenderPassError { + #[error(transparent)] + Resource(deno_core::error::AnyError), + #[error("size must be larger than 0")] + InvalidSize, + #[error(transparent)] + RenderPass(#[from] wgpu_core::command::RenderPassError), +} + pub(crate) struct WebGpuRenderPass(pub(crate) RefCell); impl Resource for WebGpuRenderPass { fn name(&self) -> Cow { @@ -37,7 +45,7 @@ pub struct RenderPassSetViewportArgs { pub fn op_webgpu_render_pass_set_viewport( state: &mut OpState, #[serde] args: RenderPassSetViewportArgs, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(args.render_pass_rid)?; @@ -66,7 +74,7 @@ pub fn op_webgpu_render_pass_set_scissor_rect( y: u32, width: u32, height: u32, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -90,7 +98,7 @@ pub fn op_webgpu_render_pass_set_blend_constant( state: &mut OpState, #[smi] render_pass_rid: ResourceId, #[serde] color: wgpu_types::Color, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -108,7 +116,7 @@ pub fn op_webgpu_render_pass_set_stencil_reference( state: &mut OpState, #[smi] render_pass_rid: ResourceId, reference: u32, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -126,7 +134,7 @@ pub fn op_webgpu_render_pass_begin_occlusion_query( state: &mut OpState, #[smi] render_pass_rid: ResourceId, query_index: u32, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -143,7 +151,7 @@ pub fn op_webgpu_render_pass_begin_occlusion_query( pub fn op_webgpu_render_pass_end_occlusion_query( state: &mut OpState, #[smi] render_pass_rid: ResourceId, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -161,7 +169,7 @@ pub fn op_webgpu_render_pass_execute_bundles( state: &mut OpState, #[smi] render_pass_rid: ResourceId, #[serde] bundles: Vec, -) -> Result { +) -> Result { let bundles = bundles .iter() .map(|rid| { @@ -170,7 +178,7 @@ pub fn op_webgpu_render_pass_execute_bundles( .get::(*rid)?; Ok(render_bundle_resource.1) }) - .collect::, AnyError>>()?; + .collect::, deno_core::error::AnyError>>()?; let render_pass_resource = state .resource_table @@ -188,7 +196,7 @@ pub fn op_webgpu_render_pass_execute_bundles( pub fn op_webgpu_render_pass_end( state: &mut OpState, #[smi] render_pass_rid: ResourceId, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .take::(render_pass_rid)?; @@ -210,7 +218,7 @@ pub fn op_webgpu_render_pass_set_bind_group( #[buffer] dynamic_offsets_data: &[u32], #[number] dynamic_offsets_data_start: usize, #[number] dynamic_offsets_data_length: usize, -) -> Result { +) -> Result { let bind_group_resource = state .resource_table .get::(bind_group)?; @@ -245,7 +253,7 @@ pub fn op_webgpu_render_pass_push_debug_group( state: &mut OpState, #[smi] render_pass_rid: ResourceId, #[string] group_label: &str, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -266,7 +274,7 @@ pub fn op_webgpu_render_pass_push_debug_group( pub fn op_webgpu_render_pass_pop_debug_group( state: &mut OpState, #[smi] render_pass_rid: ResourceId, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -284,7 +292,7 @@ pub fn op_webgpu_render_pass_insert_debug_marker( state: &mut OpState, #[smi] render_pass_rid: ResourceId, #[string] marker_label: &str, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -306,7 +314,7 @@ pub fn op_webgpu_render_pass_set_pipeline( state: &mut OpState, #[smi] render_pass_rid: ResourceId, pipeline: u32, -) -> Result { +) -> Result { let render_pipeline_resource = state .resource_table .get::(pipeline)?; @@ -333,19 +341,18 @@ pub fn op_webgpu_render_pass_set_index_buffer( #[serde] index_format: wgpu_types::IndexFormat, #[number] offset: u64, #[number] size: Option, -) -> Result { +) -> Result { let buffer_resource = state .resource_table - .get::(buffer)?; + .get::(buffer) + .map_err(RenderPassError::Resource)?; let render_pass_resource = state .resource_table - .get::(render_pass_rid)?; + .get::(render_pass_rid) + .map_err(RenderPassError::Resource)?; let size = if let Some(size) = size { - Some( - std::num::NonZeroU64::new(size) - .ok_or_else(|| type_error("size must be larger than 0"))?, - ) + Some(std::num::NonZeroU64::new(size).ok_or(RenderPassError::InvalidSize)?) } else { None }; @@ -372,19 +379,18 @@ pub fn op_webgpu_render_pass_set_vertex_buffer( buffer: u32, #[number] offset: u64, #[number] size: Option, -) -> Result { +) -> Result { let buffer_resource = state .resource_table - .get::(buffer)?; + .get::(buffer) + .map_err(RenderPassError::Resource)?; let render_pass_resource = state .resource_table - .get::(render_pass_rid)?; + .get::(render_pass_rid) + .map_err(RenderPassError::Resource)?; let size = if let Some(size) = size { - Some( - std::num::NonZeroU64::new(size) - .ok_or_else(|| type_error("size must be larger than 0"))?, - ) + Some(std::num::NonZeroU64::new(size).ok_or(RenderPassError::InvalidSize)?) } else { None }; @@ -411,7 +417,7 @@ pub fn op_webgpu_render_pass_draw( instance_count: u32, first_vertex: u32, first_instance: u32, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -439,7 +445,7 @@ pub fn op_webgpu_render_pass_draw_indexed( first_index: u32, base_vertex: i32, first_instance: u32, -) -> Result { +) -> Result { let render_pass_resource = state .resource_table .get::(render_pass_rid)?; @@ -465,7 +471,7 @@ pub fn op_webgpu_render_pass_draw_indirect( #[smi] render_pass_rid: ResourceId, indirect_buffer: u32, #[number] indirect_offset: u64, -) -> Result { +) -> Result { let buffer_resource = state .resource_table .get::(indirect_buffer)?; @@ -491,7 +497,7 @@ pub fn op_webgpu_render_pass_draw_indexed_indirect( #[smi] render_pass_rid: ResourceId, indirect_buffer: u32, #[number] indirect_offset: u64, -) -> Result { +) -> Result { let buffer_resource = state .resource_table .get::(indirect_buffer)?; diff --git a/deno_webgpu/sampler.rs b/deno_webgpu/sampler.rs index f5f33dfa3c..31b8ce2a24 100644 --- a/deno_webgpu/sampler.rs +++ b/deno_webgpu/sampler.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::wgpu_types; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -48,7 +47,7 @@ pub struct CreateSamplerArgs { pub fn op_webgpu_create_sampler( state: &mut OpState, #[serde] args: CreateSamplerArgs, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table diff --git a/deno_webgpu/shader.rs b/deno_webgpu/shader.rs index 635b4f80ce..cfba6e7811 100644 --- a/deno_webgpu/shader.rs +++ b/deno_webgpu/shader.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::wgpu_types; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -32,7 +31,7 @@ pub fn op_webgpu_create_shader_module( #[smi] device_rid: ResourceId, #[string] label: Cow, #[string] code: Cow, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index 188f68724a..c90d5e3aca 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -2,7 +2,6 @@ use super::wgpu_types; use super::WebGpuResult; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -11,6 +10,16 @@ use serde::Deserialize; use std::borrow::Cow; use std::rc::Rc; +#[derive(Debug, thiserror::Error)] +pub enum SurfaceError { + #[error(transparent)] + Resource(deno_core::error::AnyError), + #[error("Invalid Surface Status")] + InvalidStatus, + #[error(transparent)] + Surface(wgpu_core::present::SurfaceError), +} + pub struct WebGpuSurface(pub crate::Instance, pub wgpu_core::id::SurfaceId); impl Resource for WebGpuSurface { fn name(&self) -> Cow { @@ -41,7 +50,7 @@ pub struct SurfaceConfigureArgs { pub fn op_webgpu_surface_configure( state: &mut OpState, #[serde] args: SurfaceConfigureArgs, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table @@ -74,12 +83,17 @@ pub fn op_webgpu_surface_get_current_texture( state: &mut OpState, #[smi] _device_rid: ResourceId, #[smi] surface_rid: ResourceId, -) -> Result { +) -> Result { let instance = state.borrow::(); - let surface_resource = state.resource_table.get::(surface_rid)?; + let surface_resource = state + .resource_table + .get::(surface_rid) + .map_err(SurfaceError::Resource)?; let surface = surface_resource.1; - let output = instance.surface_get_current_texture(surface, None)?; + let output = instance + .surface_get_current_texture(surface, None) + .map_err(SurfaceError::Surface)?; match output.status { wgpu_types::SurfaceStatus::Good | wgpu_types::SurfaceStatus::Suboptimal => { @@ -90,7 +104,7 @@ pub fn op_webgpu_surface_get_current_texture( }); Ok(WebGpuResult::rid(rid)) } - _ => Err(AnyError::msg("Invalid Surface Status")), + _ => Err(SurfaceError::InvalidStatus), } } @@ -99,12 +113,17 @@ pub fn op_webgpu_surface_present( state: &mut OpState, #[smi] _device_rid: ResourceId, #[smi] surface_rid: ResourceId, -) -> Result<(), AnyError> { +) -> Result<(), SurfaceError> { let instance = state.borrow::(); - let surface_resource = state.resource_table.get::(surface_rid)?; + let surface_resource = state + .resource_table + .get::(surface_rid) + .map_err(SurfaceError::Resource)?; let surface = surface_resource.1; - instance.surface_present(surface)?; + instance + .surface_present(surface) + .map_err(SurfaceError::Surface)?; Ok(()) } diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 93cf62bb03..5a31259586 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::wgpu_types; -use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -60,7 +59,7 @@ pub struct CreateTextureArgs { pub fn op_webgpu_create_texture( state: &mut OpState, #[serde] args: CreateTextureArgs, -) -> Result { +) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table @@ -104,7 +103,7 @@ pub struct CreateTextureViewArgs { pub fn op_webgpu_create_texture_view( state: &mut OpState, #[serde] args: CreateTextureViewArgs, -) -> Result { +) -> Result { let instance = state.borrow::(); let texture_resource = state .resource_table diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index eb626617fe..bdff4e4e27 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -78,11 +78,11 @@ enum GPUPowerPreference { [Exposed=(Window, Worker), SecureContext] interface GPUAdapter { [SameObject] readonly attribute GPUSupportedFeatures features; + [SameObject] readonly attribute GPUAdapterInfo info; [SameObject] readonly attribute GPUSupportedLimits limits; readonly attribute boolean isFallbackAdapter; Promise requestDevice(optional GPUDeviceDescriptor descriptor = {}); - Promise requestAdapterInfo(); }; dictionary GPUDeviceDescriptor From f833280db77d43801e9628e9da413c525b516ed9 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 27 Nov 2024 20:00:40 +0100 Subject: [PATCH 7/8] update .deny.toml --- .deny.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.deny.toml b/.deny.toml index b657b88a4b..7114878527 100644 --- a/.deny.toml +++ b/.deny.toml @@ -8,6 +8,10 @@ skip-tree = [ { name = "rustc_version", version = "0.2.3" }, { name = "sourcemap", version = "7.1.1" }, { name = "miniz_oxide", version = "0.7.4" }, + + # introduced by Deno, to be investigated + { name = "deno_core", version = "0.321.0" }, + { name = "deno_permissions", version = "0.39.0" } ] skip = [ { name = "hlsl-snapshots", version = "0.1.0" }, From 7dcf381a16b3973922809629820004af91b15cdf Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 27 Nov 2024 20:23:50 +0100 Subject: [PATCH 8/8] fmt --- .deny.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.deny.toml b/.deny.toml index 7114878527..8105a01ec6 100644 --- a/.deny.toml +++ b/.deny.toml @@ -11,7 +11,7 @@ skip-tree = [ # introduced by Deno, to be investigated { name = "deno_core", version = "0.321.0" }, - { name = "deno_permissions", version = "0.39.0" } + { name = "deno_permissions", version = "0.39.0" }, ] skip = [ { name = "hlsl-snapshots", version = "0.1.0" },