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..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/" @@ -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..83bda73195 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( @@ -6378,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/Cargo.toml b/deno_webgpu/Cargo.toml index ba72507dd7..b98b9eca42 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" @@ -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 9a4900112a..31cbcfc1a1 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -1,8 +1,8 @@ // 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::futures::channel::oneshot; use deno_core::op2; use deno_core::OpState; use deno_core::Resource; @@ -11,8 +11,10 @@ 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 wgpu_core::gfx_select; use super::error::DomExceptionOperationError; use super::error::WebGpuResult; @@ -79,9 +81,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 +93,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 +118,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/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/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..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; @@ -79,7 +81,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 +166,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 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, }, stencil: wgpu_core::command::PassChannel { diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index aafb225fb9..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),*)); @@ -263,6 +233,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 +484,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/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 { 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); }; 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"]