diff --git a/Cargo.lock b/Cargo.lock index ba1a403628..8481ad4817 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,9 +153,9 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.71" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", @@ -178,7 +178,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide 0.7.1", + "miniz_oxide", "object", "rustc-demangle", ] @@ -531,7 +531,7 @@ name = "cts_runner" version = "0.1.0" dependencies = [ "deno_console", - "deno_core", + "deno_core 0.213.0", "deno_url", "deno_web", "deno_webgpu", @@ -619,24 +619,48 @@ dependencies = [ "uuid", ] +[[package]] +name = "deno-proc-macro-rules" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c65c2ffdafc1564565200967edc4851c7b55422d3913466688907efd05ea26f" +dependencies = [ + "deno-proc-macro-rules-macros", + "proc-macro2", + "syn 2.0.28", +] + +[[package]] +name = "deno-proc-macro-rules-macros" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3047b312b7451e3190865713a4dd6e1f821aed614ada219766ebc3024a690435" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.28", +] + [[package]] name = "deno_console" -version = "0.106.0" +version = "0.118.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86e7857cc8b133aed57e5f1dcfac6c0db308e70540727dfe0637af5281299758" +checksum = "4a1c32084b9ff8667d7d2176262739ce473e0341c7625325b48a2fbab0c903dc" dependencies = [ - "deno_core", + "deno_core 0.204.0", ] [[package]] name = "deno_core" -version = "0.188.0" +version = "0.204.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83573c39d4045b6c2e056a2ad87e49c43e57b64b54ee4381894c030390fa1f76" +checksum = "b4ddf51deb9a3bb60a4ab74784414b3f2f89de83a77d6d90a64c6447f7765d68" dependencies = [ "anyhow", "bytes", - "deno_ops", + "deno_ops 0.82.0", + "deno_unsync 0.1.1", "futures", "indexmap 1.9.3", "libc", @@ -646,53 +670,124 @@ dependencies = [ "pin-project", "serde", "serde_json", - "serde_v8", + "serde_v8 0.115.0", "smallvec", - "sourcemap", + "sourcemap 6.3.0", "tokio", "url", - "v8", + "v8 0.74.3", +] + +[[package]] +name = "deno_core" +version = "0.213.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1799de49977a9b73cd8f931ff429b452f3adfb2d5e9648098905923381a374f" +dependencies = [ + "anyhow", + "bytes", + "deno_ops 0.90.0", + "deno_unsync 0.2.1", + "futures", + "indexmap 2.0.0", + "libc", + "log", + "once_cell", + "parking_lot", + "pin-project", + "serde", + "serde_json", + "serde_v8 0.123.0", + "smallvec", + "sourcemap 7.0.0", + "tokio", + "url", + "v8 0.76.0", ] [[package]] name = "deno_ops" -version = "0.66.0" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0446caff6cdb14fbf6c5e85fc042e3102aa6c618fa19a2ef47b67fc2657c0e8e" +checksum = "1b660872f9a9737d3424470483dd6730d2129481af5055449a2a37ab5bc2145e" dependencies = [ - "lazy-regex", + "deno-proc-macro-rules", + "lazy-regex 2.5.0", "once_cell", "pmutil", "proc-macro-crate", "proc-macro2", "quote", "regex", + "strum", + "strum_macros", "syn 1.0.109", + "syn 2.0.28", + "thiserror", +] + +[[package]] +name = "deno_ops" +version = "0.90.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568aba570695e05f08c2181bcd6cd3579684af42f489b9ae42712348044b4af7" +dependencies = [ + "deno-proc-macro-rules", + "lazy-regex 3.0.2", + "once_cell", + "pmutil", + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "strum", + "strum_macros", + "syn 2.0.28", + "thiserror", +] + +[[package]] +name = "deno_unsync" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac0984205f25e71ddd1be603d76e70255953c12ff864707359ab195d26dfc7b3" +dependencies = [ + "tokio", +] + +[[package]] +name = "deno_unsync" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0720e562455d6374a5292baec3fc895ed8bfed0937428e3245e50979924e5b15" +dependencies = [ + "tokio", ] [[package]] name = "deno_url" -version = "0.106.0" +version = "0.118.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae0fa17e1fc70d8bb1f59d64a952b790afd774d3499524d7a760812eec07486" +checksum = "b9915e0eecac8ed1177b99eca8a220abfdcd8f4e7c5b0d99443b6b81eb90472b" dependencies = [ - "deno_core", + "deno_core 0.204.0", "serde", - "serde_repr", "urlpattern", ] [[package]] name = "deno_web" -version = "0.137.0" +version = "0.149.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10df5503ffec0b1a59541e2587f84873676d714e5d935ecc4d2792685827198" +checksum = "c183739430b71fd42f6edee0303f13f01b31e9cf80844157b7ca37b91e369275" dependencies = [ "async-trait", "base64-simd", - "deno_core", + "bytes", + "deno_core 0.204.0", "encoding_rs", "flate2", + "futures", "serde", "tokio", "uuid", @@ -703,7 +798,7 @@ dependencies = [ name = "deno_webgpu" version = "0.85.0" dependencies = [ - "deno_core", + "deno_core 0.213.0", "raw-window-handle 0.5.2", "serde", "tokio", @@ -713,11 +808,11 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.106.0" +version = "0.118.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980a92f4619ace414abd464ad417ae362c7be05020009dfd4c4f1794ed21c71f" +checksum = "71b84c418b9748f166a004eba3a67b2a8f8c1b9661bbe509c7c31cc21d7c72f6" dependencies = [ - "deno_core", + "deno_core 0.204.0", ] [[package]] @@ -776,9 +871,9 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] @@ -874,12 +969,13 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.24" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" dependencies = [ "crc32fast", - "miniz_oxide 0.5.4", + "libz-ng-sys", + "miniz_oxide", ] [[package]] @@ -1290,6 +1386,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.2" @@ -1441,7 +1543,18 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff63c423c68ea6814b7da9e88ce585f793c87ddd9e78f646970891769c8235d4" dependencies = [ - "lazy-regex-proc_macros", + "lazy-regex-proc_macros 2.4.1", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e723bd417b2df60a0f6a2b6825f297ea04b245d4ba52b5a22cb679bdf58b05fa" +dependencies = [ + "lazy-regex-proc_macros 3.0.1", "once_cell", "regex", ] @@ -1458,6 +1571,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "lazy-regex-proc_macros" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.28", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1490,6 +1615,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libz-ng-sys" +version = "1.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dd9f43e75536a46ee0f92b758f6b63846e594e86638c61a9251338a65baea63" +dependencies = [ + "cmake", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.4.3" @@ -1569,15 +1704,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" -dependencies = [ - "adler", -] - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -2063,13 +2189,13 @@ dependencies = [ [[package]] name = "pmutil" -version = "0.5.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] @@ -2082,7 +2208,7 @@ dependencies = [ "crc32fast", "fdeflate", "flate2", - "miniz_oxide 0.7.1", + "miniz_oxide", ] [[package]] @@ -2325,6 +2451,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.15" @@ -2440,21 +2572,26 @@ dependencies = [ ] [[package]] -name = "serde_repr" -version = "0.1.9" +name = "serde_v8" +version = "0.115.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" +checksum = "36f6cc041512391aabdae4dd11d51e370824ea35bfe896fb2585b6792e28c9bf" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "bytes", + "derive_more", + "num-bigint", + "serde", + "serde_bytes", + "smallvec", + "thiserror", + "v8 0.74.3", ] [[package]] name = "serde_v8" -version = "0.99.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abcb15f793aba70da4d29b2015c9b70943bd7f6970cab7963fcf83c19bbab1c9" +checksum = "cc3e1c4d2b20f6983e86077c66b25b8d768f2e102e09659af2af034ac47ae709" dependencies = [ "bytes", "derive_more", @@ -2463,7 +2600,7 @@ dependencies = [ "serde_bytes", "smallvec", "thiserror", - "v8", + "v8 0.76.0", ] [[package]] @@ -2581,6 +2718,22 @@ dependencies = [ "url", ] +[[package]] +name = "sourcemap" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbecc42a2b6131acc3bf9a25c9fe4161dba438eb52131bba83c5d781b5b70be3" +dependencies = [ + "data-encoding", + "debugid", + "if_chain", + "rustc_version 0.2.3", + "serde", + "serde_json", + "unicode-id", + "url", +] + [[package]] name = "spirv" version = "0.2.0+1.5.4" @@ -2609,6 +2762,28 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.28", +] + [[package]] name = "syn" version = "1.0.109" @@ -2895,9 +3070,21 @@ dependencies = [ [[package]] name = "v8" -version = "0.72.0" +version = "0.74.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eedac634b8dd39b889c5b62349cbc55913780226239166435c5cf66771792ea" +dependencies = [ + "bitflags 1.3.2", + "fslock", + "once_cell", + "which", +] + +[[package]] +name = "v8" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5c1d09f66ab7f69e36211c5488d47f683fef6b65b83a627cfd75ed9cef254e6" +checksum = "9d4e8ae7ef8b4e852e728e343cb6bb471a0424dfefa22585ea0c14a61252d73f" dependencies = [ "bitflags 1.3.2", "fslock", diff --git a/Cargo.toml b/Cargo.toml index 55c6048b86..cc96ef62f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,11 +135,11 @@ wasm-bindgen-test = "0.3" web-sys = "0.3.64" # deno dependencies -deno_console = "0.106.0" -deno_core = "0.188.0" -deno_url = "0.106.0" -deno_web = "0.137.0" -deno_webidl = "0.106.0" +deno_console = "0.118.0" +deno_core = "0.213.0" +deno_url = "0.118.0" +deno_web = "0.149.0" +deno_webidl = "0.118.0" deno_webgpu = { path = "./deno_webgpu" } tokio = "1.32.0" termcolor = "1.2.0" diff --git a/cts_runner/src/main.rs b/cts_runner/src/main.rs index c5a70aabc1..06e7a8b326 100644 --- a/cts_runner/src/main.rs +++ b/cts_runner/src/main.rs @@ -1,5 +1,6 @@ #[cfg(not(target_arch = "wasm32"))] mod native { + use std::sync::Arc; use std::{ env, fmt, io::{Read, Write}, @@ -8,13 +9,12 @@ mod native { use deno_core::anyhow::anyhow; use deno_core::error::AnyError; - use deno_core::op; + use deno_core::op2; use deno_core::resolve_url_or_path; use deno_core::serde_json::json; use deno_core::v8; use deno_core::JsRuntime; use deno_core::RuntimeOptions; - use deno_core::ZeroCopyBuf; use deno_web::BlobStore; use termcolor::Ansi; use termcolor::Color::Red; @@ -36,7 +36,10 @@ mod native { deno_webidl::deno_webidl::init_ops_and_esm(), deno_console::deno_console::init_ops_and_esm(), deno_url::deno_url::init_ops_and_esm(), - deno_web::deno_web::init_ops_and_esm::(BlobStore::default(), None), + deno_web::deno_web::init_ops_and_esm::( + Arc::new(BlobStore::default()), + None, + ), deno_webgpu::deno_webgpu::init_ops_and_esm(true), cts_runner::init_ops_and_esm(), ], @@ -47,7 +50,7 @@ mod native { let cfg = json!({"args": args, "cwd": env::current_dir().unwrap().to_string_lossy() }); { - let context = isolate.global_context(); + let context = isolate.main_context(); let scope = &mut isolate.handle_scope(); let context_local = v8::Local::new(scope, context); let global_obj = context_local.global(scope); @@ -56,7 +59,6 @@ mod native { let bootstrap_fn = v8::Local::::try_from(bootstrap_fn).unwrap(); let options_v8 = deno_core::serde_v8::to_v8(scope, cfg).unwrap(); - let bootstrap_fn = v8::Local::new(scope, bootstrap_fn); let undefined = v8::undefined(scope); bootstrap_fn .call(scope, undefined.into(), &[options_v8]) @@ -86,26 +88,27 @@ mod native { deps = [deno_webidl, deno_web], ops = [op_exit, op_read_file_sync, op_write_file_sync], esm_entry_point = "ext:cts_runner/bootstrap.js", - esm = ["bootstrap.js"], + esm = ["src/bootstrap.js"], ); - #[op] + #[op2(fast)] fn op_exit(code: i32) -> Result<(), AnyError> { std::process::exit(code) } - #[op] - fn op_read_file_sync(path: String) -> Result { - let path = std::path::Path::new(&path); + #[op2] + #[buffer] + fn op_read_file_sync(#[string] path: &str) -> Result, AnyError> { + let path = std::path::Path::new(path); let mut file = std::fs::File::open(path)?; let mut buf = Vec::new(); file.read_to_end(&mut buf)?; - Ok(ZeroCopyBuf::from(buf)) + Ok(buf) } - #[op] - fn op_write_file_sync(path: String, buf: ZeroCopyBuf) -> Result<(), AnyError> { - let path = std::path::Path::new(&path); + #[op2(fast)] + fn op_write_file_sync(#[string] path: &str, #[buffer] buf: &[u8]) -> Result<(), AnyError> { + let path = std::path::Path::new(path); let mut file = std::fs::File::create(path)?; file.write_all(&buf)?; Ok(()) diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index 9ecb3f5143..d3ed0b8686 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -176,12 +176,13 @@ impl From for wgpu_types::BindingType { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_bind_group_layout( state: &mut OpState, - device_rid: ResourceId, - label: Option, - entries: Vec, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[serde] entries: Vec, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -213,12 +214,13 @@ pub fn op_webgpu_create_bind_group_layout( ) => state, WebGpuBindGroupLayout) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_pipeline_layout( state: &mut OpState, - device_rid: ResourceId, - label: Option, - bind_group_layouts: Vec, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[serde] bind_group_layouts: Vec, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -257,13 +259,14 @@ pub struct GpuBindGroupEntry { size: Option, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_bind_group( state: &mut OpState, - device_rid: ResourceId, - label: Option, - layout: ResourceId, - entries: Vec, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[smi] layout: ResourceId, + #[serde] entries: Vec, ) -> Result { let instance = state.borrow::(); let device_resource = state diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index 7c5f9d58c2..3c209cc70c 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -3,14 +3,12 @@ use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::futures::channel::oneshot; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use std::borrow::Cow; use std::cell::RefCell; -use std::convert::TryFrom; use std::rc::Rc; use std::time::Duration; use wgpu_core::resource::BufferAccessResult; @@ -40,12 +38,13 @@ impl Resource for WebGpuBufferMapped { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_buffer( state: &mut OpState, - device_rid: ResourceId, - label: Option, - size: u64, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[number] size: u64, usage: u32, mapped_at_creation: bool, ) -> Result { @@ -70,14 +69,15 @@ pub fn op_webgpu_create_buffer( ) => state, WebGpuBuffer) } -#[op] +#[op2(async)] +#[serde] pub async fn op_webgpu_buffer_get_map_async( state: Rc>, - buffer_rid: ResourceId, - device_rid: ResourceId, + #[smi] buffer_rid: ResourceId, + #[smi] device_rid: ResourceId, mode: u32, - offset: u64, - size: u64, + #[number] offset: u64, + #[number] size: u64, ) -> Result { let (sender, receiver) = oneshot::channel::(); @@ -143,13 +143,14 @@ pub async fn op_webgpu_buffer_get_map_async( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_buffer_get_mapped_range( state: &mut OpState, - buffer_rid: ResourceId, - offset: u64, - size: Option, - mut buf: ZeroCopyBuf, + #[smi] buffer_rid: ResourceId, + #[number] offset: u64, + #[number] size: Option, + #[buffer] buf: &mut [u8], ) -> Result { let instance = state.borrow::(); let buffer_resource = state.resource_table.get::(buffer_rid)?; @@ -172,12 +173,13 @@ pub fn op_webgpu_buffer_get_mapped_range( Ok(WebGpuResult::rid(rid)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_buffer_unmap( state: &mut OpState, - buffer_rid: ResourceId, - mapped_rid: ResourceId, - buf: Option, + #[smi] buffer_rid: ResourceId, + #[smi] mapped_rid: ResourceId, + #[buffer] buf: Option<&[u8]>, ) -> Result { let mapped_resource = state .resource_table @@ -188,7 +190,7 @@ pub fn op_webgpu_buffer_unmap( if let Some(buf) = buf { let slice = unsafe { std::slice::from_raw_parts_mut(mapped_resource.0, mapped_resource.1) }; - slice.copy_from_slice(&buf); + slice.copy_from_slice(buf); } gfx_ok!(buffer => instance.buffer_unmap(buffer)) diff --git a/deno_webgpu/bundle.rs b/deno_webgpu/bundle.rs index bcb321f497..c93d67f3e2 100644 --- a/deno_webgpu/bundle.rs +++ b/deno_webgpu/bundle.rs @@ -2,11 +2,10 @@ use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -48,10 +47,11 @@ pub struct CreateRenderBundleEncoderArgs { stencil_read_only: bool, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_render_bundle_encoder( state: &mut OpState, - args: CreateRenderBundleEncoderArgs, + #[serde] args: CreateRenderBundleEncoderArgs, ) -> Result { let device_resource = state .resource_table @@ -92,11 +92,12 @@ pub fn op_webgpu_create_render_bundle_encoder( Ok(WebGpuResult::rid_err(rid, maybe_err)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_finish( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - label: Option, + #[smi] render_bundle_encoder_rid: ResourceId, + #[string] label: Option, ) -> Result { let render_bundle_encoder_resource = state .resource_table @@ -117,15 +118,16 @@ pub fn op_webgpu_render_bundle_encoder_finish( ) => state, WebGpuRenderBundle) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_set_bind_group( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, index: u32, - bind_group: ResourceId, - dynamic_offsets_data: ZeroCopyBuf, - dynamic_offsets_data_start: usize, - dynamic_offsets_data_length: usize, + #[smi] bind_group: ResourceId, + #[buffer] dynamic_offsets_data: &[u32], + #[number] dynamic_offsets_data_start: usize, + #[number] dynamic_offsets_data_length: usize, ) -> Result { let bind_group_resource = state .resource_table @@ -134,14 +136,6 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( .resource_table .get::(render_bundle_encoder_rid)?; - // Align the data - assert!(dynamic_offsets_data.len() % std::mem::size_of::() == 0); - // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a - // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; - assert!(prefix.is_empty()); - assert!(suffix.is_empty()); - let start = dynamic_offsets_data_start; let len = dynamic_offsets_data_length; @@ -149,7 +143,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( assert!(start <= dynamic_offsets_data.len()); assert!(len <= dynamic_offsets_data.len() - start); - let dynamic_offsets_data: &[u32] = &dynamic_offsets_data[start..start + len]; + let dynamic_offsets_data = &dynamic_offsets_data[start..start + len]; // SAFETY: the raw pointer and length are of the same slice, and that slice // lives longer than the below function invocation. @@ -166,11 +160,12 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_push_debug_group( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - group_label: String, + #[smi] render_bundle_encoder_rid: ResourceId, + #[string] group_label: &str, ) -> Result { let render_bundle_encoder_resource = state .resource_table @@ -189,10 +184,11 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_pop_debug_group( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, ) -> Result { let render_bundle_encoder_resource = state .resource_table @@ -205,11 +201,12 @@ pub fn op_webgpu_render_bundle_encoder_pop_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - marker_label: String, + #[smi] render_bundle_encoder_rid: ResourceId, + #[string] marker_label: &str, ) -> Result { let render_bundle_encoder_resource = state .resource_table @@ -228,11 +225,12 @@ pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_set_pipeline( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - pipeline: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, + #[smi] pipeline: ResourceId, ) -> Result { let render_pipeline_resource = state .resource_table @@ -249,14 +247,15 @@ pub fn op_webgpu_render_bundle_encoder_set_pipeline( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_set_index_buffer( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - buffer: ResourceId, - index_format: wgpu_types::IndexFormat, - offset: u64, - size: u64, + #[smi] render_bundle_encoder_rid: ResourceId, + #[smi] buffer: ResourceId, + #[serde] index_format: wgpu_types::IndexFormat, + #[number] offset: u64, + #[number] size: u64, ) -> Result { let buffer_resource = state .resource_table @@ -276,14 +275,15 @@ pub fn op_webgpu_render_bundle_encoder_set_index_buffer( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, slot: u32, - buffer: ResourceId, - offset: u64, - size: Option, + #[smi] buffer: ResourceId, + #[number] offset: u64, + #[number] size: Option, ) -> Result { let buffer_resource = state .resource_table @@ -311,10 +311,11 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_draw( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, vertex_count: u32, instance_count: u32, first_vertex: u32, @@ -335,10 +336,11 @@ pub fn op_webgpu_render_bundle_encoder_draw( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_draw_indexed( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, + #[smi] render_bundle_encoder_rid: ResourceId, index_count: u32, instance_count: u32, first_index: u32, @@ -361,12 +363,13 @@ pub fn op_webgpu_render_bundle_encoder_draw_indexed( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_bundle_encoder_draw_indirect( state: &mut OpState, - render_bundle_encoder_rid: ResourceId, - indirect_buffer: ResourceId, - indirect_offset: u64, + #[smi] render_bundle_encoder_rid: ResourceId, + #[smi] indirect_buffer: ResourceId, + #[number] indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table diff --git a/deno_webgpu/command_encoder.rs b/deno_webgpu/command_encoder.rs index 4857b0a7a7..447a398221 100644 --- a/deno_webgpu/command_encoder.rs +++ b/deno_webgpu/command_encoder.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -44,11 +44,12 @@ impl Resource for WebGpuCommandBuffer { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_command_encoder( state: &mut OpState, - device_rid: ResourceId, - label: Option, + #[smi] device_rid: ResourceId, + #[string] label: Option, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -91,14 +92,15 @@ pub struct GpuRenderPassDepthStencilAttachment { stencil_read_only: bool, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_begin_render_pass( state: &mut OpState, - command_encoder_rid: ResourceId, - label: Option, - color_attachments: Vec>, - depth_stencil_attachment: Option, - occlusion_query_set: Option, + #[smi] command_encoder_rid: ResourceId, + #[string] label: Option, + #[serde] color_attachments: Vec>, + #[serde] depth_stencil_attachment: Option, + #[smi] occlusion_query_set: Option, ) -> Result { let command_encoder_resource = state .resource_table @@ -196,11 +198,12 @@ pub fn op_webgpu_command_encoder_begin_render_pass( Ok(WebGpuResult::rid(rid)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_begin_compute_pass( state: &mut OpState, - command_encoder_rid: ResourceId, - label: Option, + #[smi] command_encoder_rid: ResourceId, + #[string] label: Option, ) -> Result { let command_encoder_resource = state .resource_table @@ -223,15 +226,16 @@ pub fn op_webgpu_command_encoder_begin_compute_pass( Ok(WebGpuResult::rid(rid)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_copy_buffer_to_buffer( state: &mut OpState, - command_encoder_rid: ResourceId, - source: ResourceId, - source_offset: u64, - destination: ResourceId, - destination_offset: u64, - size: u64, + #[smi] command_encoder_rid: ResourceId, + #[smi] source: ResourceId, + #[number] source_offset: u64, + #[smi] destination: ResourceId, + #[number] destination_offset: u64, + #[number] size: u64, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -275,13 +279,14 @@ pub struct GpuImageCopyTexture { pub aspect: wgpu_types::TextureAspect, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_copy_buffer_to_texture( state: &mut OpState, - command_encoder_rid: ResourceId, - source: GpuImageCopyBuffer, - destination: GpuImageCopyTexture, - copy_size: wgpu_types::Extent3d, + #[smi] command_encoder_rid: ResourceId, + #[serde] source: GpuImageCopyBuffer, + #[serde] destination: GpuImageCopyTexture, + #[serde] copy_size: wgpu_types::Extent3d, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -317,13 +322,14 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_copy_texture_to_buffer( state: &mut OpState, - command_encoder_rid: ResourceId, - source: GpuImageCopyTexture, - destination: GpuImageCopyBuffer, - copy_size: wgpu_types::Extent3d, + #[smi] command_encoder_rid: ResourceId, + #[serde] source: GpuImageCopyTexture, + #[serde] destination: GpuImageCopyBuffer, + #[serde] copy_size: wgpu_types::Extent3d, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -359,13 +365,14 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_copy_texture_to_texture( state: &mut OpState, - command_encoder_rid: ResourceId, - source: GpuImageCopyTexture, - destination: GpuImageCopyTexture, - copy_size: wgpu_types::Extent3d, + #[smi] command_encoder_rid: ResourceId, + #[serde] source: GpuImageCopyTexture, + #[serde] destination: GpuImageCopyTexture, + #[serde] copy_size: wgpu_types::Extent3d, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -399,13 +406,14 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_clear_buffer( state: &mut OpState, - command_encoder_rid: u32, - buffer_rid: u32, - offset: u64, - size: u64, + #[smi] command_encoder_rid: ResourceId, + #[smi] buffer_rid: ResourceId, + #[number] offset: u64, + #[number] size: u64, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -424,11 +432,12 @@ pub fn op_webgpu_command_encoder_clear_buffer( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_push_debug_group( state: &mut OpState, - command_encoder_rid: ResourceId, - group_label: String, + #[smi] command_encoder_rid: ResourceId, + #[string] group_label: &str, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -436,13 +445,14 @@ pub fn op_webgpu_command_encoder_push_debug_group( .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.1; - gfx_ok!(command_encoder => instance.command_encoder_push_debug_group(command_encoder, &group_label)) + gfx_ok!(command_encoder => instance.command_encoder_push_debug_group(command_encoder, group_label)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_pop_debug_group( state: &mut OpState, - command_encoder_rid: ResourceId, + #[smi] command_encoder_rid: ResourceId, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -453,11 +463,12 @@ pub fn op_webgpu_command_encoder_pop_debug_group( gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_insert_debug_marker( state: &mut OpState, - command_encoder_rid: ResourceId, - marker_label: String, + #[smi] command_encoder_rid: ResourceId, + #[string] marker_label: &str, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -467,15 +478,16 @@ pub fn op_webgpu_command_encoder_insert_debug_marker( gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker( command_encoder, - &marker_label + marker_label )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_write_timestamp( state: &mut OpState, - command_encoder_rid: ResourceId, - query_set: ResourceId, + #[smi] command_encoder_rid: ResourceId, + #[smi] query_set: ResourceId, query_index: u32, ) -> Result { let instance = state.borrow::(); @@ -494,15 +506,16 @@ pub fn op_webgpu_command_encoder_write_timestamp( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_resolve_query_set( state: &mut OpState, - command_encoder_rid: ResourceId, - query_set: ResourceId, + #[smi] command_encoder_rid: ResourceId, + #[smi] query_set: ResourceId, first_query: u32, query_count: u32, - destination: ResourceId, - destination_offset: u64, + #[smi] destination: ResourceId, + #[number] destination_offset: u64, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state @@ -526,11 +539,12 @@ pub fn op_webgpu_command_encoder_resolve_query_set( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_command_encoder_finish( state: &mut OpState, - command_encoder_rid: ResourceId, - label: Option, + #[smi] command_encoder_rid: ResourceId, + #[string] label: Option, ) -> Result { let command_encoder_resource = state .resource_table diff --git a/deno_webgpu/compute_pass.rs b/deno_webgpu/compute_pass.rs index cc70146917..83e615479d 100644 --- a/deno_webgpu/compute_pass.rs +++ b/deno_webgpu/compute_pass.rs @@ -1,11 +1,10 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use std::borrow::Cow; use std::cell::RefCell; @@ -18,11 +17,12 @@ impl Resource for WebGpuComputePass { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_set_pipeline( state: &mut OpState, - compute_pass_rid: ResourceId, - pipeline: ResourceId, + #[smi] compute_pass_rid: ResourceId, + #[smi] pipeline: ResourceId, ) -> Result { let compute_pipeline_resource = state .resource_table @@ -39,10 +39,11 @@ pub fn op_webgpu_compute_pass_set_pipeline( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_dispatch_workgroups( state: &mut OpState, - compute_pass_rid: ResourceId, + #[smi] compute_pass_rid: ResourceId, x: u32, y: u32, z: u32, @@ -61,12 +62,13 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_dispatch_workgroups_indirect( state: &mut OpState, - compute_pass_rid: ResourceId, - indirect_buffer: ResourceId, - indirect_offset: u64, + #[smi] compute_pass_rid: ResourceId, + #[smi] indirect_buffer: ResourceId, + #[number] indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table @@ -84,11 +86,12 @@ pub fn op_webgpu_compute_pass_dispatch_workgroups_indirect( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query( state: &mut OpState, - compute_pass_rid: ResourceId, - query_set: ResourceId, + #[smi] compute_pass_rid: ResourceId, + #[smi] query_set: ResourceId, query_index: u32, ) -> Result { let compute_pass_resource = state @@ -107,10 +110,11 @@ pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_end_pipeline_statistics_query( state: &mut OpState, - compute_pass_rid: ResourceId, + #[smi] compute_pass_rid: ResourceId, ) -> Result { let compute_pass_resource = state .resource_table @@ -123,11 +127,12 @@ pub fn op_webgpu_compute_pass_end_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_write_timestamp( state: &mut OpState, - compute_pass_rid: ResourceId, - query_set: ResourceId, + #[smi] compute_pass_rid: ResourceId, + #[smi] query_set: ResourceId, query_index: u32, ) -> Result { let compute_pass_resource = state @@ -146,11 +151,12 @@ pub fn op_webgpu_compute_pass_write_timestamp( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_end( state: &mut OpState, - command_encoder_rid: ResourceId, - compute_pass_rid: ResourceId, + #[smi] command_encoder_rid: ResourceId, + #[smi] compute_pass_rid: ResourceId, ) -> Result { let command_encoder_resource = state @@ -169,15 +175,16 @@ pub fn op_webgpu_compute_pass_end( )) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_set_bind_group( state: &mut OpState, - compute_pass_rid: ResourceId, + #[smi] compute_pass_rid: ResourceId, index: u32, - bind_group: ResourceId, - dynamic_offsets_data: ZeroCopyBuf, - dynamic_offsets_data_start: usize, - dynamic_offsets_data_length: usize, + #[smi] bind_group: ResourceId, + #[buffer] dynamic_offsets_data: &[u32], + #[number] dynamic_offsets_data_start: usize, + #[number] dynamic_offsets_data_length: usize, ) -> Result { let bind_group_resource = state .resource_table @@ -186,14 +193,6 @@ pub fn op_webgpu_compute_pass_set_bind_group( .resource_table .get::(compute_pass_rid)?; - // Align the data - assert!(dynamic_offsets_data_start % std::mem::size_of::() == 0); - // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a - // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; - assert!(prefix.is_empty()); - assert!(suffix.is_empty()); - let start = dynamic_offsets_data_start; let len = dynamic_offsets_data_length; @@ -218,11 +217,12 @@ pub fn op_webgpu_compute_pass_set_bind_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_push_debug_group( state: &mut OpState, - compute_pass_rid: ResourceId, - group_label: String, + #[smi] compute_pass_rid: ResourceId, + #[string] group_label: &str, ) -> Result { let compute_pass_resource = state .resource_table @@ -242,10 +242,11 @@ pub fn op_webgpu_compute_pass_push_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_pop_debug_group( state: &mut OpState, - compute_pass_rid: ResourceId, + #[smi] compute_pass_rid: ResourceId, ) -> Result { let compute_pass_resource = state .resource_table @@ -258,11 +259,12 @@ pub fn op_webgpu_compute_pass_pop_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pass_insert_debug_marker( state: &mut OpState, - compute_pass_rid: ResourceId, - marker_label: String, + #[smi] compute_pass_rid: ResourceId, + #[string] marker_label: &str, ) -> Result { let compute_pass_resource = state .resource_table diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 92a6a51334..fc237b1382 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -3,7 +3,7 @@ #![warn(unsafe_op_in_unsafe_fn)] use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -12,7 +12,6 @@ use serde::Serialize; use std::borrow::Cow; use std::cell::RefCell; use std::collections::HashSet; -use std::convert::TryFrom; use std::rc::Rc; pub use wgpu_core; pub use wgpu_types; @@ -385,10 +384,11 @@ pub struct GpuAdapterDevice { is_software: bool, } -#[op] +#[op2(async)] +#[serde] pub async fn op_webgpu_request_adapter( state: Rc>, - power_preference: Option, + #[serde] power_preference: Option, force_fallback_adapter: bool, ) -> Result { let mut state = state.borrow_mut(); @@ -630,13 +630,14 @@ impl From for wgpu_types::Features { } } -#[op] +#[op2(async)] +#[serde] pub async fn op_webgpu_request_device( state: Rc>, - adapter_rid: ResourceId, - label: Option, - required_features: GpuRequiredFeatures, - required_limits: Option, + #[smi] adapter_rid: ResourceId, + #[string] label: Option, + #[serde] required_features: GpuRequiredFeatures, + #[serde] required_limits: Option, ) -> Result { let mut state = state.borrow_mut(); let adapter_resource = state.resource_table.get::(adapter_rid)?; @@ -684,10 +685,11 @@ pub struct GPUAdapterInfo { description: String, } -#[op] +#[op2(async)] +#[serde] pub async fn op_webgpu_request_adapter_info( state: Rc>, - adapter_rid: ResourceId, + #[smi] adapter_rid: ResourceId, ) -> Result { let state = state.borrow_mut(); let adapter_resource = state.resource_table.get::(adapter_rid)?; @@ -759,10 +761,11 @@ impl From for wgpu_types::QueryType { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_query_set( state: &mut OpState, - args: CreateQuerySetArgs, + #[serde] args: CreateQuerySetArgs, ) -> Result { let device_resource = state.resource_table.get::(args.device_rid)?; let device = device_resource.1; diff --git a/deno_webgpu/pipeline.rs b/deno_webgpu/pipeline.rs index 13589df2da..cf2bd9b84c 100644 --- a/deno_webgpu/pipeline.rs +++ b/deno_webgpu/pipeline.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -81,13 +81,14 @@ pub struct GpuProgrammableStage { // constants: HashMap } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_compute_pipeline( state: &mut OpState, - device_rid: ResourceId, - label: Option, - layout: GPUPipelineLayoutOrGPUAutoLayoutMode, - compute: GpuProgrammableStage, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[serde] layout: GPUPipelineLayoutOrGPUAutoLayoutMode, + #[serde] compute: GpuProgrammableStage, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -148,10 +149,11 @@ pub struct PipelineLayout { err: Option, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_compute_pipeline_get_bind_group_layout( state: &mut OpState, - compute_pipeline_rid: ResourceId, + #[smi] compute_pipeline_rid: ResourceId, index: u32, ) -> Result { let instance = state.borrow::(); @@ -323,10 +325,11 @@ pub struct CreateRenderPipelineArgs { fragment: Option, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_render_pipeline( state: &mut OpState, - args: CreateRenderPipelineArgs, + #[serde] args: CreateRenderPipelineArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -412,10 +415,11 @@ pub fn op_webgpu_create_render_pipeline( Ok(WebGpuResult::rid_err(rid, maybe_err)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pipeline_get_bind_group_layout( state: &mut OpState, - render_pipeline_rid: ResourceId, + #[smi] render_pipeline_rid: ResourceId, index: u32, ) -> Result { let instance = state.borrow::(); diff --git a/deno_webgpu/queue.rs b/deno_webgpu/queue.rs index 2845990776..1f6258935f 100644 --- a/deno_webgpu/queue.rs +++ b/deno_webgpu/queue.rs @@ -1,21 +1,23 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use crate::command_encoder::WebGpuCommandBuffer; use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; +use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use serde::Deserialize; use super::error::WebGpuResult; type WebGpuQueue = super::WebGpuDevice; -#[op] +#[op2] +#[serde] pub fn op_webgpu_queue_submit( state: &mut OpState, - queue_rid: ResourceId, - command_buffers: Vec, + #[smi] queue_rid: ResourceId, + #[serde] command_buffers: Vec, ) -> Result { let instance = state.borrow::(); let queue_resource = state.resource_table.get::(queue_rid)?; @@ -24,9 +26,7 @@ pub fn op_webgpu_queue_submit( let ids = command_buffers .iter() .map(|rid| { - let buffer_resource = state - .resource_table - .get::(*rid)?; + let buffer_resource = state.resource_table.get::(*rid)?; let mut id = buffer_resource.1.borrow_mut(); Ok(id.take().unwrap()) }) @@ -35,7 +35,8 @@ pub fn op_webgpu_queue_submit( let maybe_err = gfx_select!(queue => instance.queue_submit(queue, &ids)).err(); for rid in command_buffers { - state.resource_table.close(rid)?; + let resource = state.resource_table.take::(rid)?; + resource.close(); } Ok(WebGpuResult::maybe_err(maybe_err)) @@ -59,15 +60,16 @@ impl From for wgpu_types::ImageDataLayout { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_write_buffer( state: &mut OpState, - queue_rid: ResourceId, - buffer: ResourceId, - buffer_offset: u64, - data_offset: usize, - size: Option, - buf: ZeroCopyBuf, + #[smi] queue_rid: ResourceId, + #[smi] buffer: ResourceId, + #[number] buffer_offset: u64, + #[number] data_offset: usize, + #[number] size: Option, + #[buffer] buf: &[u8], ) -> Result { let instance = state.borrow::(); let buffer_resource = state @@ -92,14 +94,15 @@ pub fn op_webgpu_write_buffer( Ok(WebGpuResult::maybe_err(maybe_err)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_write_texture( state: &mut OpState, - queue_rid: ResourceId, - destination: super::command_encoder::GpuImageCopyTexture, - data_layout: GpuImageDataLayout, - size: wgpu_types::Extent3d, - buf: ZeroCopyBuf, + #[smi] queue_rid: ResourceId, + #[serde] destination: super::command_encoder::GpuImageCopyTexture, + #[serde] data_layout: GpuImageDataLayout, + #[serde] size: wgpu_types::Extent3d, + #[buffer] buf: &[u8], ) -> Result { let instance = state.borrow::(); let texture_resource = state @@ -119,7 +122,7 @@ pub fn op_webgpu_write_texture( gfx_ok!(queue => instance.queue_write_texture( queue, &destination, - &*buf, + buf, &data_layout, &size )) diff --git a/deno_webgpu/render_pass.rs b/deno_webgpu/render_pass.rs index 678990ea3d..7b831f96be 100644 --- a/deno_webgpu/render_pass.rs +++ b/deno_webgpu/render_pass.rs @@ -2,11 +2,10 @@ use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -32,10 +31,11 @@ pub struct RenderPassSetViewportArgs { max_depth: f32, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_viewport( state: &mut OpState, - args: RenderPassSetViewportArgs, + #[serde] args: RenderPassSetViewportArgs, ) -> Result { let render_pass_resource = state .resource_table @@ -54,10 +54,11 @@ pub fn op_webgpu_render_pass_set_viewport( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_scissor_rect( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, x: u32, y: u32, width: u32, @@ -78,11 +79,12 @@ pub fn op_webgpu_render_pass_set_scissor_rect( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_blend_constant( state: &mut OpState, - render_pass_rid: ResourceId, - color: wgpu_types::Color, + #[smi] render_pass_rid: ResourceId, + #[serde] color: wgpu_types::Color, ) -> Result { let render_pass_resource = state .resource_table @@ -96,10 +98,11 @@ pub fn op_webgpu_render_pass_set_blend_constant( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_stencil_reference( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, reference: u32, ) -> Result { let render_pass_resource = state @@ -114,10 +117,11 @@ pub fn op_webgpu_render_pass_set_stencil_reference( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_begin_occlusion_query( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, query_index: u32, ) -> Result { let render_pass_resource = state @@ -132,10 +136,11 @@ pub fn op_webgpu_render_pass_begin_occlusion_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_end_occlusion_query( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, ) -> Result { let render_pass_resource = state .resource_table @@ -148,10 +153,11 @@ pub fn op_webgpu_render_pass_end_occlusion_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_begin_pipeline_statistics_query( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, query_set: u32, query_index: u32, ) -> Result { @@ -171,10 +177,11 @@ pub fn op_webgpu_render_pass_begin_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_end_pipeline_statistics_query( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, ) -> Result { let render_pass_resource = state .resource_table @@ -187,10 +194,11 @@ pub fn op_webgpu_render_pass_end_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_write_timestamp( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, query_set: u32, query_index: u32, ) -> Result { @@ -210,11 +218,12 @@ pub fn op_webgpu_render_pass_write_timestamp( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_execute_bundles( state: &mut OpState, - render_pass_rid: ResourceId, - bundles: Vec, + #[smi] render_pass_rid: ResourceId, + #[serde] bundles: Vec, ) -> Result { let bundles = bundles .iter() @@ -243,11 +252,12 @@ pub fn op_webgpu_render_pass_execute_bundles( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_end( state: &mut OpState, - command_encoder_rid: ResourceId, - render_pass_rid: ResourceId, + #[smi] command_encoder_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, ) -> Result { let command_encoder_resource = state @@ -263,15 +273,16 @@ pub fn op_webgpu_render_pass_end( gfx_ok!(command_encoder => instance.command_encoder_run_render_pass(command_encoder, render_pass)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_bind_group( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, index: u32, bind_group: u32, - dynamic_offsets_data: ZeroCopyBuf, - dynamic_offsets_data_start: usize, - dynamic_offsets_data_length: usize, + #[buffer] dynamic_offsets_data: &[u32], + #[number] dynamic_offsets_data_start: usize, + #[number] dynamic_offsets_data_length: usize, ) -> Result { let bind_group_resource = state .resource_table @@ -280,14 +291,6 @@ pub fn op_webgpu_render_pass_set_bind_group( .resource_table .get::(render_pass_rid)?; - // Align the data - assert_eq!(dynamic_offsets_data_start % std::mem::size_of::(), 0); - // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a - // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; - assert!(prefix.is_empty()); - assert!(suffix.is_empty()); - let start = dynamic_offsets_data_start; let len = dynamic_offsets_data_length; @@ -312,11 +315,12 @@ pub fn op_webgpu_render_pass_set_bind_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_push_debug_group( state: &mut OpState, - render_pass_rid: ResourceId, - group_label: String, + #[smi] render_pass_rid: ResourceId, + #[string] group_label: &str, ) -> Result { let render_pass_resource = state .resource_table @@ -336,10 +340,11 @@ pub fn op_webgpu_render_pass_push_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_pop_debug_group( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, ) -> Result { let render_pass_resource = state .resource_table @@ -352,11 +357,12 @@ pub fn op_webgpu_render_pass_pop_debug_group( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_insert_debug_marker( state: &mut OpState, - render_pass_rid: ResourceId, - marker_label: String, + #[smi] render_pass_rid: ResourceId, + #[string] marker_label: &str, ) -> Result { let render_pass_resource = state .resource_table @@ -376,10 +382,11 @@ pub fn op_webgpu_render_pass_insert_debug_marker( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_pipeline( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, pipeline: u32, ) -> Result { let render_pipeline_resource = state @@ -397,14 +404,15 @@ pub fn op_webgpu_render_pass_set_pipeline( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_index_buffer( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, buffer: u32, - index_format: wgpu_types::IndexFormat, - offset: u64, - size: Option, + #[serde] index_format: wgpu_types::IndexFormat, + #[number] offset: u64, + #[number] size: Option, ) -> Result { let buffer_resource = state .resource_table @@ -432,14 +440,15 @@ pub fn op_webgpu_render_pass_set_index_buffer( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_set_vertex_buffer( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, slot: u32, buffer: u32, - offset: u64, - size: Option, + #[number] offset: u64, + #[number] size: Option, ) -> Result { let buffer_resource = state .resource_table @@ -468,10 +477,11 @@ pub fn op_webgpu_render_pass_set_vertex_buffer( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_draw( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, vertex_count: u32, instance_count: u32, first_vertex: u32, @@ -492,10 +502,11 @@ pub fn op_webgpu_render_pass_draw( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_draw_indexed( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, index_count: u32, instance_count: u32, first_index: u32, @@ -518,12 +529,13 @@ pub fn op_webgpu_render_pass_draw_indexed( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_draw_indirect( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, indirect_buffer: u32, - indirect_offset: u64, + #[number] indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table @@ -541,12 +553,13 @@ pub fn op_webgpu_render_pass_draw_indirect( Ok(WebGpuResult::empty()) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_render_pass_draw_indexed_indirect( state: &mut OpState, - render_pass_rid: ResourceId, + #[smi] render_pass_rid: ResourceId, indirect_buffer: u32, - indirect_offset: u64, + #[number] indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table diff --git a/deno_webgpu/sampler.rs b/deno_webgpu/sampler.rs index d064ba2ebe..b6842a1b9e 100644 --- a/deno_webgpu/sampler.rs +++ b/deno_webgpu/sampler.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -43,10 +43,11 @@ pub struct CreateSamplerArgs { max_anisotropy: u16, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_sampler( state: &mut OpState, - args: CreateSamplerArgs, + #[serde] args: CreateSamplerArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state diff --git a/deno_webgpu/shader.rs b/deno_webgpu/shader.rs index fb4f316926..e680882536 100644 --- a/deno_webgpu/shader.rs +++ b/deno_webgpu/shader.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -25,12 +25,13 @@ impl Resource for WebGpuShaderModule { } } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_shader_module( state: &mut OpState, - device_rid: ResourceId, - label: Option, - code: String, + #[smi] device_rid: ResourceId, + #[string] label: Option, + #[string] code: Cow, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -38,7 +39,7 @@ pub fn op_webgpu_create_shader_module( .get::(device_rid)?; let device = device_resource.1; - let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code)); + let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(code); let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor { label: label.map(Cow::from), diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index 8f797f12a5..1ac9d8704d 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -2,7 +2,7 @@ use super::WebGpuResult; use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -51,10 +51,11 @@ pub struct SurfaceConfigureArgs { view_formats: Vec, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_surface_configure( state: &mut OpState, - args: SurfaceConfigureArgs, + #[serde] args: SurfaceConfigureArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -81,11 +82,12 @@ pub fn op_webgpu_surface_configure( Ok(WebGpuResult::maybe_err(err)) } -#[op] +#[op2] +#[serde] pub fn op_webgpu_surface_get_current_texture( state: &mut OpState, - device_rid: ResourceId, - surface_rid: ResourceId, + #[smi] device_rid: ResourceId, + #[smi] surface_rid: ResourceId, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -111,11 +113,11 @@ pub fn op_webgpu_surface_get_current_texture( } } -#[op] +#[op2(fast)] pub fn op_webgpu_surface_present( state: &mut OpState, - device_rid: ResourceId, - surface_rid: ResourceId, + #[smi] device_rid: ResourceId, + #[smi] surface_rid: ResourceId, ) -> Result<(), AnyError> { let instance = state.borrow::(); let device_resource = state diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 92c8457071..8491307262 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; -use deno_core::op; +use deno_core::op2; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; @@ -58,10 +58,11 @@ pub struct CreateTextureArgs { view_formats: Vec, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_texture( state: &mut OpState, - args: CreateTextureArgs, + #[serde] args: CreateTextureArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state @@ -106,10 +107,11 @@ pub struct CreateTextureViewArgs { range: wgpu_types::ImageSubresourceRange, } -#[op] +#[op2] +#[serde] pub fn op_webgpu_create_texture_view( state: &mut OpState, - args: CreateTextureViewArgs, + #[serde] args: CreateTextureViewArgs, ) -> Result { let instance = state.borrow::(); let texture_resource = state diff --git a/rust-toolchain b/rust-toolchain index 0f2697d74a..03d64db162 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -5,6 +5,6 @@ # to the user in the error, instead of "error: invalid channel name '[toolchain]'". [toolchain] -channel = "1.65" +channel = "1.70" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"]