diff --git a/Cargo.lock b/Cargo.lock
index f824c50791..b30c86e989 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,6 +16,12 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
+[[package]]
+name = "ahash"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
+
[[package]]
name = "aho-corasick"
version = "0.7.15"
@@ -73,6 +79,15 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
+[[package]]
+name = "ash"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c69a8137596e84c22d57f3da1b5de1d4230b1742a710091c85f4d7ce50f00f38"
+dependencies = [
+ "libloading",
+]
+
[[package]]
name = "ast_node"
version = "0.7.1"
@@ -180,6 +195,21 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
+[[package]]
+name = "bit-set"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
+dependencies = [
+ "bit-vec",
+]
+
+[[package]]
+name = "bit-vec"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+
[[package]]
name = "bitflags"
version = "1.2.1"
@@ -198,6 +228,12 @@ dependencies = [
"wyz",
]
+[[package]]
+name = "block"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
+
[[package]]
name = "block-buffer"
version = "0.9.0"
@@ -257,6 +293,9 @@ name = "cc"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
+dependencies = [
+ "jobserver",
+]
[[package]]
name = "cfg-if"
@@ -270,6 +309,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+[[package]]
+name = "cfg_aliases"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
+
[[package]]
name = "chrono"
version = "0.4.19"
@@ -298,6 +343,55 @@ dependencies = [
"vec_map",
]
+[[package]]
+name = "cocoa-foundation"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
+dependencies = [
+ "bitflags",
+ "block",
+ "core-foundation",
+ "core-graphics-types",
+ "foreign-types",
+ "libc",
+ "objc",
+]
+
+[[package]]
+name = "copyless"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
+
+[[package]]
+name = "core-foundation"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
+
+[[package]]
+name = "core-graphics-types"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
+dependencies = [
+ "bitflags",
+ "core-foundation",
+ "foreign-types",
+ "libc",
+]
+
[[package]]
name = "cpuid-bool"
version = "0.1.2"
@@ -343,6 +437,17 @@ dependencies = [
"lazy_static",
]
+[[package]]
+name = "d3d12"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0a60cceb22c7c53035f8980524fdc7f17cf49681a3c154e6757d30afbec6ec4"
+dependencies = [
+ "bitflags",
+ "libloading",
+ "winapi 0.3.9",
+]
+
[[package]]
name = "darling"
version = "0.10.2"
@@ -538,6 +643,7 @@ dependencies = [
"deno_crypto",
"deno_fetch",
"deno_web",
+ "deno_webgpu",
"deno_websocket",
"dlopen",
"encoding_rs",
@@ -579,6 +685,17 @@ dependencies = [
"serde",
]
+[[package]]
+name = "deno_webgpu"
+version = "0.1.0"
+dependencies = [
+ "deno_core",
+ "serde",
+ "tokio",
+ "wgpu-core",
+ "wgpu-types",
+]
+
[[package]]
name = "deno_websocket"
version = "0.5.0"
@@ -840,6 +957,21 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+[[package]]
+name = "foreign-types"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
+dependencies = [
+ "foreign-types-shared",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+
[[package]]
name = "form_urlencoded"
version = "1.0.0"
@@ -1059,6 +1191,205 @@ dependencies = [
"wasi 0.10.0+wasi-snapshot-preview1",
]
+[[package]]
+name = "gfx-auxil"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7b33ecf067f2117668d91c9b0f2e5f223ebd1ffec314caa2f3de27bb580186d"
+dependencies = [
+ "fxhash",
+ "gfx-hal",
+ "spirv_cross",
+]
+
+[[package]]
+name = "gfx-backend-dx11"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f851d03c2e8f117e3702bf41201a4fafa447d5cb1276d5375870ae7573d069dd"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "gfx-auxil",
+ "gfx-hal",
+ "libloading",
+ "log",
+ "parking_lot",
+ "range-alloc",
+ "raw-window-handle",
+ "smallvec",
+ "spirv_cross",
+ "thunderdome",
+ "winapi 0.3.9",
+ "wio",
+]
+
+[[package]]
+name = "gfx-backend-dx12"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36dc6ba2b7647e2c2b27b8f74ff5ccdd53c703776588eee5b1de515fdcbd6bc9"
+dependencies = [
+ "arrayvec",
+ "bit-set",
+ "bitflags",
+ "d3d12",
+ "gfx-auxil",
+ "gfx-hal",
+ "log",
+ "parking_lot",
+ "range-alloc",
+ "raw-window-handle",
+ "smallvec",
+ "spirv_cross",
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "gfx-backend-empty"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f07ef26a65954cfdd7b4c587f485100d1bb3b0bd6a51b02d817d6c87cca7a91"
+dependencies = [
+ "gfx-hal",
+ "log",
+ "raw-window-handle",
+]
+
+[[package]]
+name = "gfx-backend-gl"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e17fd85420547bceb851fadb90f196f168abfc252d57528bd2d749db0d18b75f"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "gfx-auxil",
+ "gfx-hal",
+ "glow",
+ "js-sys",
+ "khronos-egl",
+ "libloading",
+ "log",
+ "naga",
+ "parking_lot",
+ "raw-window-handle",
+ "spirv_cross",
+ "wasm-bindgen",
+ "web-sys",
+]
+
+[[package]]
+name = "gfx-backend-metal"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8dc54b456ece69ef49f8893269ebf24ac70969ed34ba2719c3f3abcc8fbff14e"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "block",
+ "cocoa-foundation",
+ "copyless",
+ "foreign-types",
+ "gfx-auxil",
+ "gfx-hal",
+ "log",
+ "metal",
+ "naga",
+ "objc",
+ "parking_lot",
+ "range-alloc",
+ "raw-window-handle",
+ "spirv_cross",
+ "storage-map",
+]
+
+[[package]]
+name = "gfx-backend-vulkan"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dabe88b1a5c91e0f969b441cc57e70364858066e4ba937deeb62065654ef9bd9"
+dependencies = [
+ "arrayvec",
+ "ash",
+ "byteorder",
+ "core-graphics-types",
+ "gfx-hal",
+ "inplace_it",
+ "log",
+ "naga",
+ "objc",
+ "parking_lot",
+ "raw-window-handle",
+ "smallvec",
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "gfx-hal"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1d9cc8d3b573dda62d0baca4f02e0209786e22c562caff001d77c389008781d"
+dependencies = [
+ "bitflags",
+ "naga",
+ "raw-window-handle",
+ "thiserror",
+]
+
+[[package]]
+name = "glow"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "072136d2c3783f3a92f131acb227bc806d3886278e2a4dc1e9990ec89ef9e70b"
+dependencies = [
+ "js-sys",
+ "slotmap",
+ "wasm-bindgen",
+ "web-sys",
+]
+
+[[package]]
+name = "gpu-alloc"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e7724b9aef57ea36d70faf54e0ee6265f86e41de16bed8333efdeab5b00e16b"
+dependencies = [
+ "bitflags",
+ "gpu-alloc-types",
+ "tracing",
+]
+
+[[package]]
+name = "gpu-alloc-types"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "gpu-descriptor"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e8a70f1e87a3840ed6a3e99e02c2b861e4dbdf26f0d07e38f42ea5aff46cfce2"
+dependencies = [
+ "bitflags",
+ "gpu-descriptor-types",
+ "hashbrown",
+ "tracing",
+]
+
+[[package]]
+name = "gpu-descriptor-types"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126"
+dependencies = [
+ "bitflags",
+]
+
[[package]]
name = "h2"
version = "0.3.0"
@@ -1084,6 +1415,9 @@ name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
+dependencies = [
+ "ahash",
+]
[[package]]
name = "heck"
@@ -1246,6 +1580,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "inplace_it"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca"
+
[[package]]
name = "input_buffer"
version = "0.4.0"
@@ -1301,6 +1641,15 @@ version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
+[[package]]
+name = "jobserver"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "js-sys"
version = "0.3.47"
@@ -1326,6 +1675,16 @@ dependencies = [
"winapi-build",
]
+[[package]]
+name = "khronos-egl"
+version = "3.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8020ff3b84f9ac87461216ad0501bc09b33c1cbe17404d8ea405160fd164bab"
+dependencies = [
+ "libc",
+ "libloading",
+]
+
[[package]]
name = "lazy_static"
version = "1.4.0"
@@ -1351,6 +1710,16 @@ version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
+[[package]]
+name = "libloading"
+version = "0.6.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883"
+dependencies = [
+ "cfg-if 1.0.0",
+ "winapi 0.3.9",
+]
+
[[package]]
name = "linked-hash-map"
version = "0.5.4"
@@ -1435,6 +1804,15 @@ dependencies = [
"syn 1.0.60",
]
+[[package]]
+name = "malloc_buf"
+version = "0.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "match_cfg"
version = "0.1.0"
@@ -1453,6 +1831,20 @@ version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
+[[package]]
+name = "metal"
+version = "0.21.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4598d719460ade24c7d91f335daf055bf2a7eec030728ce751814c50cdd6a26c"
+dependencies = [
+ "bitflags",
+ "block",
+ "cocoa-foundation",
+ "foreign-types",
+ "log",
+ "objc",
+]
+
[[package]]
name = "mime"
version = "0.3.16"
@@ -1492,6 +1884,23 @@ dependencies = [
"winapi 0.3.9",
]
+[[package]]
+name = "naga"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8f30d7036f137a2f64fd7d53b70a91545d3f09e030b77b3816ff7bd4cf3f789"
+dependencies = [
+ "bit-set",
+ "bitflags",
+ "fxhash",
+ "log",
+ "num-traits",
+ "petgraph",
+ "serde",
+ "spirv_headers",
+ "thiserror",
+]
+
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
@@ -1600,6 +2009,25 @@ dependencies = [
"libc",
]
+[[package]]
+name = "objc"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
+dependencies = [
+ "malloc_buf",
+ "objc_exception",
+]
+
+[[package]]
+name = "objc_exception"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
+dependencies = [
+ "cc",
+]
+
[[package]]
name = "once_cell"
version = "1.5.2"
@@ -2012,6 +2440,21 @@ dependencies = [
"rand_core 0.5.1",
]
+[[package]]
+name = "range-alloc"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
+
+[[package]]
+name = "raw-window-handle"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "redox_syscall"
version = "0.1.57"
@@ -2128,6 +2571,17 @@ dependencies = [
"winapi 0.3.9",
]
+[[package]]
+name = "ron"
+version = "0.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "064ea8613fb712a19faf920022ec8ddf134984f100090764a4e1d768f3827f1f"
+dependencies = [
+ "base64 0.13.0",
+ "bitflags",
+ "serde",
+]
+
[[package]]
name = "rustc_version"
version = "0.2.3"
@@ -2349,6 +2803,12 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
+[[package]]
+name = "slotmap"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd"
+
[[package]]
name = "smallvec"
version = "1.6.1"
@@ -2388,6 +2848,27 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
+[[package]]
+name = "spirv_cross"
+version = "0.23.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06db6bd7b6518f761593783e2896eefe55e90455efc5f44511078ce0426ed418"
+dependencies = [
+ "cc",
+ "js-sys",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "spirv_headers"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c"
+dependencies = [
+ "bitflags",
+ "num-traits",
+]
+
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@@ -2400,6 +2881,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+[[package]]
+name = "storage-map"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c"
+dependencies = [
+ "lock_api",
+]
+
[[package]]
name = "string_cache"
version = "0.8.1"
@@ -2925,6 +3415,12 @@ dependencies = [
"once_cell",
]
+[[package]]
+name = "thunderdome"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7572415bd688d401c52f6e36f4c8e805b9ae1622619303b9fa835d531db0acae"
+
[[package]]
name = "time"
version = "0.1.44"
@@ -3087,9 +3583,21 @@ checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
+ "tracing-attributes",
"tracing-core",
]
+[[package]]
+name = "tracing-attributes"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43f080ea7e4107844ef4766459426fa2d5c1ada2e47edba05dc7fa99d9629f47"
+dependencies = [
+ "proc-macro2 1.0.24",
+ "quote 1.0.8",
+ "syn 1.0.60",
+]
+
[[package]]
name = "tracing-core"
version = "0.1.17"
@@ -3468,6 +3976,46 @@ dependencies = [
"webpki",
]
+[[package]]
+name = "wgpu-core"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c89fa2cc5d72236461ac09c5be967012663e29cb62f1a972654cbf35e49dffa8"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "cfg_aliases",
+ "copyless",
+ "fxhash",
+ "gfx-backend-dx11",
+ "gfx-backend-dx12",
+ "gfx-backend-empty",
+ "gfx-backend-gl",
+ "gfx-backend-metal",
+ "gfx-backend-vulkan",
+ "gfx-hal",
+ "gpu-alloc",
+ "gpu-descriptor",
+ "naga",
+ "parking_lot",
+ "ron",
+ "serde",
+ "smallvec",
+ "thiserror",
+ "tracing",
+ "wgpu-types",
+]
+
+[[package]]
+name = "wgpu-types"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72fa9ba80626278fd87351555c363378d08122d7601e58319be3d6fa85a87747"
+dependencies = [
+ "bitflags",
+ "serde",
+]
+
[[package]]
name = "which"
version = "4.0.2"
@@ -3554,6 +4102,15 @@ dependencies = [
"toml",
]
+[[package]]
+name = "wio"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5"
+dependencies = [
+ "winapi 0.3.9",
+]
+
[[package]]
name = "wyz"
version = "0.2.0"
diff --git a/cli/build.rs b/cli/build.rs
index a54bf962c7..236097cbf8 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -11,6 +11,7 @@ use deno_core::RuntimeOptions;
use deno_runtime::deno_crypto;
use deno_runtime::deno_fetch;
use deno_runtime::deno_web;
+use deno_runtime::deno_webgpu;
use deno_runtime::deno_websocket;
use regex::Regex;
use std::collections::HashMap;
@@ -62,6 +63,7 @@ fn create_compiler_snapshot(
let mut op_crate_libs = HashMap::new();
op_crate_libs.insert("deno.web", deno_web::get_declaration());
op_crate_libs.insert("deno.fetch", deno_fetch::get_declaration());
+ op_crate_libs.insert("deno.webgpu", deno_webgpu::get_declaration());
op_crate_libs.insert("deno.websocket", deno_websocket::get_declaration());
op_crate_libs.insert("deno.crypto", deno_crypto::get_declaration());
@@ -260,6 +262,10 @@ fn main() {
"cargo:rustc-env=DENO_FETCH_LIB_PATH={}",
deno_fetch::get_declaration().display()
);
+ println!(
+ "cargo:rustc-env=DENO_WEBGPU_LIB_PATH={}",
+ deno_webgpu::get_declaration().display()
+ );
println!(
"cargo:rustc-env=DENO_WEBSOCKET_LIB_PATH={}",
deno_websocket::get_declaration().display()
diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts
index 721c89af22..2d46e5fe05 100644
--- a/cli/dts/lib.deno.window.d.ts
+++ b/cli/dts/lib.deno.window.d.ts
@@ -3,6 +3,7 @@
///
///
///
+///
///
declare class Window extends EventTarget {
@@ -17,12 +18,18 @@ declare class Window extends EventTarget {
confirm: (message?: string) => boolean;
prompt: (message?: string, defaultValue?: string) => string | null;
Deno: typeof Deno;
+ navigator: Navigator;
}
declare var window: Window & typeof globalThis;
declare var self: Window & typeof globalThis;
declare var onload: ((this: Window, ev: Event) => any) | null;
declare var onunload: ((this: Window, ev: Event) => any) | null;
+declare var navigator: Navigator;
+
+declare interface Navigator {
+ readonly gpu: GPU;
+}
/**
* Shows the given message and waits for the enter key pressed.
diff --git a/cli/dts/lib.deno.worker.d.ts b/cli/dts/lib.deno.worker.d.ts
index a8f42f3362..93549ecd5c 100644
--- a/cli/dts/lib.deno.worker.d.ts
+++ b/cli/dts/lib.deno.worker.d.ts
@@ -3,6 +3,7 @@
///
///
///
+///
///
declare class WorkerGlobalScope {
@@ -29,6 +30,13 @@ declare class WorkerGlobalScope {
close: () => void;
postMessage: (message: any) => void;
Deno: typeof Deno;
+ navigator: WorkerNavigator;
+}
+
+declare var navigator: WorkerNavigator;
+
+declare interface WorkerNavigator {
+ readonly gpu: GPU;
}
declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
diff --git a/cli/flags.rs b/cli/flags.rs
index a803ff63ff..6add2df878 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -234,6 +234,7 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
DENO_DIR Set the cache directory
DENO_INSTALL_ROOT Set deno install's output directory
(defaults to $HOME/.deno/bin)
+ DENO_WEBGPU_TRACE Directory to use for wgpu traces
HTTP_PROXY Proxy address for HTTP requests
(module downloads, fetch)
HTTPS_PROXY Proxy address for HTTPS requests
diff --git a/cli/main.rs b/cli/main.rs
index 7871fe882f..0fa63a138e 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -278,10 +278,11 @@ fn print_cache_info(
pub fn get_types(unstable: bool) -> String {
let mut types = format!(
- "{}\n{}\n{}\n{}\n{}\n{}",
+ "{}\n{}\n{}\n{}\n{}\n{}\n{}",
crate::tsc::DENO_NS_LIB,
crate::tsc::DENO_WEB_LIB,
crate::tsc::DENO_FETCH_LIB,
+ crate::tsc::DENO_WEBGPU_LIB,
crate::tsc::DENO_WEBSOCKET_LIB,
crate::tsc::SHARED_GLOBALS_LIB,
crate::tsc::WINDOW_LIB,
@@ -1022,6 +1023,8 @@ fn init_logger(maybe_level: Option) {
)
// https://github.com/denoland/deno/issues/6641
.filter_module("rustyline", LevelFilter::Off)
+ // wgpu backend crates (gfx_backend), have a lot of useless INFO and WARN logs
+ .filter_module("gfx", LevelFilter::Error)
.format(|buf, record| {
let mut target = record.target().to_string();
if let Some(line_no) = record.line() {
diff --git a/cli/tests/unit/unit_tests.ts b/cli/tests/unit/unit_tests.ts
index 8af28c1bb7..2664a9ab0e 100644
--- a/cli/tests/unit/unit_tests.ts
+++ b/cli/tests/unit/unit_tests.ts
@@ -76,3 +76,4 @@ import "./write_text_file_test.ts";
import "./performance_test.ts";
import "./version_test.ts";
import "./websocket_test.ts";
+import "./webgpu_test.ts";
diff --git a/cli/tests/unit/webgpu_test.ts b/cli/tests/unit/webgpu_test.ts
new file mode 100644
index 0000000000..628a3c8db9
--- /dev/null
+++ b/cli/tests/unit/webgpu_test.ts
@@ -0,0 +1,225 @@
+// TODO(lucacasonato): remove when GPUBufferUsage and friends are added to dlint
+// deno-lint-ignore-file no-undef
+
+import { assert, assertEquals, unitTest } from "./test_util.ts";
+
+let isCI: boolean;
+try {
+ isCI = (Deno.env.get("CI")?.length ?? 0) > 0;
+} catch {
+ isCI = true;
+}
+
+// Skip this test on linux CI, because the vulkan emulator is not good enough
+// yet, and skip on macOS because these do not have virtual GPUs.
+unitTest({
+ perms: { read: true, env: true },
+ ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI,
+}, async function webgpuComputePass() {
+ const adapter = await navigator.gpu.requestAdapter();
+ assert(adapter);
+
+ const numbers = [1, 4, 3, 295];
+
+ const device = await adapter.requestDevice();
+ assert(device);
+
+ const shaderCode = await Deno.readTextFile(
+ "cli/tests/webgpu_computepass_shader.wgsl",
+ );
+
+ const shaderModule = device.createShaderModule({
+ code: shaderCode,
+ });
+
+ const size = new Uint32Array(numbers).byteLength;
+
+ const stagingBuffer = device.createBuffer({
+ size: size,
+ usage: 1 | 8,
+ });
+
+ const storageBuffer = device.createBuffer({
+ label: "Storage Buffer",
+ size: size,
+ usage: 0x80 | 8 | 4,
+ mappedAtCreation: true,
+ });
+
+ const buf = new Uint32Array(storageBuffer.getMappedRange());
+
+ buf.set(numbers);
+
+ storageBuffer.unmap();
+
+ const bindGroupLayout = device.createBindGroupLayout({
+ entries: [
+ {
+ binding: 0,
+ visibility: 4,
+ buffer: {
+ type: "storage",
+ minBindingSize: 4,
+ },
+ },
+ ],
+ });
+
+ const bindGroup = device.createBindGroup({
+ layout: bindGroupLayout,
+ entries: [
+ {
+ binding: 0,
+ resource: {
+ buffer: storageBuffer,
+ },
+ },
+ ],
+ });
+
+ const pipelineLayout = device.createPipelineLayout({
+ bindGroupLayouts: [bindGroupLayout],
+ });
+
+ const computePipeline = device.createComputePipeline({
+ layout: pipelineLayout,
+ compute: {
+ module: shaderModule,
+ entryPoint: "main",
+ },
+ });
+
+ const encoder = device.createCommandEncoder();
+
+ const computePass = encoder.beginComputePass();
+ computePass.setPipeline(computePipeline);
+ computePass.setBindGroup(0, bindGroup);
+ computePass.insertDebugMarker("compute collatz iterations");
+ computePass.dispatch(numbers.length);
+ computePass.endPass();
+
+ encoder.copyBufferToBuffer(storageBuffer, 0, stagingBuffer, 0, size);
+
+ device.queue.submit([encoder.finish()]);
+
+ await stagingBuffer.mapAsync(1);
+
+ const data = stagingBuffer.getMappedRange();
+
+ assertEquals(new Uint32Array(data), new Uint32Array([0, 2, 7, 55]));
+
+ stagingBuffer.unmap();
+
+ device.destroy();
+
+ // TODO(lucacasonato): webgpu spec should add a explicit destroy method for
+ // adapters.
+ const resources = Object.keys(Deno.resources());
+ Deno.close(Number(resources[resources.length - 1]));
+});
+
+// Skip this test on linux CI, because the vulkan emulator is not good enough
+// yet, and skip on macOS because these do not have virtual GPUs.
+unitTest({
+ perms: { read: true, env: true },
+ ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI,
+}, async function webgpuHelloTriangle() {
+ const adapter = await navigator.gpu.requestAdapter();
+ assert(adapter);
+
+ const device = await adapter.requestDevice();
+ assert(device);
+
+ const shaderCode = await Deno.readTextFile(
+ "cli/tests/webgpu_hellotriangle_shader.wgsl",
+ );
+
+ const shaderModule = device.createShaderModule({
+ code: shaderCode,
+ });
+
+ const pipelineLayout = device.createPipelineLayout({
+ bindGroupLayouts: [],
+ });
+
+ const renderPipeline = device.createRenderPipeline({
+ layout: pipelineLayout,
+ vertex: {
+ module: shaderModule,
+ entryPoint: "vs_main",
+ },
+ fragment: {
+ module: shaderModule,
+ entryPoint: "fs_main",
+ targets: [
+ {
+ format: "rgba8unorm-srgb",
+ },
+ ],
+ },
+ });
+
+ const dimensions = {
+ width: 200,
+ height: 200,
+ };
+ const unpaddedBytesPerRow = dimensions.width * 4;
+ const align = 256;
+ const paddedBytesPerRowPadding = (align - unpaddedBytesPerRow % align) %
+ align;
+ const paddedBytesPerRow = unpaddedBytesPerRow + paddedBytesPerRowPadding;
+
+ const outputBuffer = device.createBuffer({
+ label: "Capture",
+ size: paddedBytesPerRow * dimensions.height,
+ usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
+ });
+ const texture = device.createTexture({
+ label: "Capture",
+ size: dimensions,
+ format: "rgba8unorm-srgb",
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
+ });
+
+ const encoder = device.createCommandEncoder();
+ const renderPass = encoder.beginRenderPass({
+ colorAttachments: [
+ {
+ view: texture.createView(),
+ storeOp: "store",
+ loadValue: [0, 1, 0, 1],
+ },
+ ],
+ });
+ renderPass.setPipeline(renderPipeline);
+ renderPass.draw(3, 1);
+ renderPass.endPass();
+
+ encoder.copyTextureToBuffer(
+ {
+ texture,
+ },
+ {
+ buffer: outputBuffer,
+ bytesPerRow: paddedBytesPerRow,
+ rowsPerImage: 0,
+ },
+ dimensions,
+ );
+
+ device.queue.submit([encoder.finish()]);
+
+ await outputBuffer.mapAsync(1);
+ const data = new Uint8Array(outputBuffer.getMappedRange());
+
+ assertEquals(data, await Deno.readFile("cli/tests/webgpu_hellotriangle.out"));
+
+ outputBuffer.unmap();
+
+ device.destroy();
+
+ // TODO(lucacasonato): webgpu spec should add a explicit destroy method for
+ // adapters.
+ const resources = Object.keys(Deno.resources());
+ Deno.close(Number(resources[resources.length - 1]));
+});
diff --git a/cli/tests/webgpu_computepass_shader.wgsl b/cli/tests/webgpu_computepass_shader.wgsl
new file mode 100644
index 0000000000..2433f32433
--- /dev/null
+++ b/cli/tests/webgpu_computepass_shader.wgsl
@@ -0,0 +1,39 @@
+[[builtin(global_invocation_id)]]
+var global_id: vec3;
+
+[[block]]
+struct PrimeIndices {
+ data: [[stride(4)]] array;
+}; // this is used as both input and output for convenience
+
+[[group(0), binding(0)]]
+var v_indices: [[access(read_write)]] PrimeIndices;
+
+// The Collatz Conjecture states that for any integer n:
+// If n is even, n = n/2
+// If n is odd, n = 3n+1
+// And repeat this process for each new n, you will always eventually reach 1.
+// Though the conjecture has not been proven, no counterexample has ever been found.
+// This function returns how many times this recurrence needs to be applied to reach 1.
+fn collatz_iterations(n_base: u32) -> u32{
+ var n: u32 = n_base;
+ var i: u32 = 0u;
+ loop {
+ if (n <= 1u) {
+ break;
+ }
+ if (n % 2u == 0u) {
+ n = n / 2u;
+ }
+ else {
+ n = 3u * n + 1u;
+ }
+ i = i + 1u;
+ }
+ return i;
+}
+
+[[stage(compute), workgroup_size(1)]]
+fn main() {
+ v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
+}
diff --git a/cli/tests/webgpu_hellotriangle.out b/cli/tests/webgpu_hellotriangle.out
new file mode 100644
index 0000000000..91454dbfc6
Binary files /dev/null and b/cli/tests/webgpu_hellotriangle.out differ
diff --git a/cli/tests/webgpu_hellotriangle_shader.wgsl b/cli/tests/webgpu_hellotriangle_shader.wgsl
new file mode 100644
index 0000000000..71934415be
--- /dev/null
+++ b/cli/tests/webgpu_hellotriangle_shader.wgsl
@@ -0,0 +1,19 @@
+[[builtin(vertex_index)]]
+var in_vertex_index: u32;
+[[builtin(position)]]
+var out_pos: vec4;
+
+[[stage(vertex)]]
+fn vs_main() {
+ var x: f32 = f32(i32(in_vertex_index) - 1);
+ var y: f32 = f32(i32(in_vertex_index & 1) * 2 - 1);
+ out_pos = vec4(x, y, 0.0, 1.0);
+}
+
+[[location(0)]]
+var out_color: vec4;
+
+[[stage(fragment)]]
+fn fs_main() {
+ out_color = vec4(1.0, 0.0, 0.0, 1.0);
+}
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 6328175b9c..8d28b959d3 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -31,6 +31,7 @@ use std::sync::Mutex;
pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts");
pub static DENO_WEB_LIB: &str = include_str!(env!("DENO_WEB_LIB_PATH"));
pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH"));
+pub static DENO_WEBGPU_LIB: &str = include_str!(env!("DENO_WEBGPU_LIB_PATH"));
pub static DENO_WEBSOCKET_LIB: &str =
include_str!(env!("DENO_WEBSOCKET_LIB_PATH"));
pub static SHARED_GLOBALS_LIB: &str =
diff --git a/op_crates/web/02_event.js b/op_crates/web/02_event.js
index d253599e5e..ac813d0911 100644
--- a/op_crates/web/02_event.js
+++ b/op_crates/web/02_event.js
@@ -1204,6 +1204,7 @@
window.removeEventListener = EventTarget.prototype.removeEventListener;
window.__bootstrap = (window.__bootstrap || {});
window.__bootstrap.eventTarget = {
+ EventTarget,
setEventTargetData,
};
window.__bootstrap.event = {
diff --git a/op_crates/web/internal.d.ts b/op_crates/web/internal.d.ts
index d43332e4b0..8be80c8a52 100644
--- a/op_crates/web/internal.d.ts
+++ b/op_crates/web/internal.d.ts
@@ -270,6 +270,10 @@ declare namespace globalThis {
): (v: any, opts: ValueConverterOpts) => any;
}
+ declare var eventTarget: {
+ EventTarget: typeof EventTarget;
+ };
+
declare var url: {
URLSearchParams: typeof URLSearchParams;
};
diff --git a/op_crates/webgpu/01_webgpu.js b/op_crates/webgpu/01_webgpu.js
new file mode 100644
index 0000000000..7a078619e0
--- /dev/null
+++ b/op_crates/webgpu/01_webgpu.js
@@ -0,0 +1,5048 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// @ts-check
+///
+///
+///
+///
+
+"use strict";
+
+((window) => {
+ const core = window.Deno.core;
+ const webidl = window.__bootstrap.webidl;
+ const eventTarget = window.__bootstrap.eventTarget;
+
+ /**
+ * @param {any} self
+ * @param {{prefix: string, context: string}} opts
+ * @returns {InnerGPUDevice & {rid: number}}
+ */
+ function assertDevice(self, { prefix, context }) {
+ const device = self[_device];
+ const deviceRid = device?.rid;
+ if (deviceRid === undefined) {
+ throw new DOMException(
+ `${prefix}: ${context} references an invalid or destroyed device.`,
+ "OperationError",
+ );
+ }
+ return device;
+ }
+
+ /**
+ * @param {InnerGPUDevice} self
+ * @param {any} resource
+ * @param {{prefix: string, resourceContext: string, selfContext: string}} opts
+ * @returns {InnerGPUDevice & {rid: number}}
+ */
+ function assertDeviceMatch(
+ self,
+ resource,
+ { prefix, resourceContext, selfContext },
+ ) {
+ const resourceDevice = assertDevice(resource, {
+ prefix,
+ context: resourceContext,
+ });
+ if (resourceDevice.rid !== self.rid) {
+ throw new DOMException(
+ `${prefix}: ${resourceContext} belongs to a diffent device than ${selfContext}.`,
+ "OperationError",
+ );
+ }
+ return { ...resourceDevice, rid: resourceDevice.rid };
+ }
+
+ /**
+ * @param {any} self
+ * @param {{prefix: string, context: string}} opts
+ * @returns {number}
+ */
+ function assertResource(self, { prefix, context }) {
+ const rid = self[_rid];
+ if (rid === undefined) {
+ throw new DOMException(
+ `${prefix}: ${context} an invalid or destroyed resource.`,
+ "OperationError",
+ );
+ }
+ return rid;
+ }
+
+ /**
+ * @param {number[] | GPUExtent3DDict} data
+ * @returns {GPUExtent3DDict}
+ */
+ function normalizeGPUExtent3D(data) {
+ if (Array.isArray(data)) {
+ return {
+ width: data[0],
+ height: data[1],
+ depth: data[2],
+ };
+ } else {
+ return data;
+ }
+ }
+
+ /**
+ * @param {number[] | GPUOrigin3DDict} data
+ * @returns {GPUOrigin3DDict}
+ */
+ function normalizeGPUOrigin3D(data) {
+ if (Array.isArray(data)) {
+ return {
+ x: data[0],
+ y: data[1],
+ z: data[2],
+ };
+ } else {
+ return data;
+ }
+ }
+
+ /**
+ * @param {number[] | GPUColor} data
+ * @returns {GPUColor}
+ */
+ function normalizeGPUColor(data) {
+ if (Array.isArray(data)) {
+ return {
+ r: data[0],
+ g: data[1],
+ b: data[2],
+ a: data[3],
+ };
+ } else {
+ return data;
+ }
+ }
+
+ class GPUOutOfMemoryError extends Error {
+ constructor() {
+ super();
+ }
+ }
+
+ class GPUValidationError extends Error {
+ /** @param {string} message */
+ constructor(message) {
+ const prefix = "Failed to construct 'GPUValidationError'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ message = webidl.converters.DOMString(message, {
+ prefix,
+ context: "Argument 1",
+ });
+ super(message);
+ }
+ }
+
+ class GPU {
+ [webidl.brand] = webidl.brand;
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPURequestAdapterOptions} options
+ */
+ async requestAdapter(options = {}) {
+ webidl.assertBranded(this, GPU);
+ options = webidl.converters.GPURequestAdapterOptions(options, {
+ prefix: "Failed to execute 'requestAdapter' on 'GPU'",
+ context: "Argument 1",
+ });
+
+ const { err, ...data } = await core.jsonOpAsync(
+ "op_webgpu_request_adapter",
+ { ...options },
+ );
+
+ if (err) {
+ return null;
+ } else {
+ return createGPUAdapter(data.name, data);
+ }
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${inspect({})}`;
+ }
+ }
+
+ const _name = Symbol("[[name]]");
+ const _adapter = Symbol("[[adapter]]");
+ const _cleanup = Symbol("[[cleanup]]");
+
+ /**
+ * @typedef InnerGPUAdapter
+ * @property {number} rid
+ * @property {GPUAdapterFeatures} features
+ * @property {GPUAdapterLimits} limits
+ */
+
+ /**
+ * @param {string} name
+ * @param {InnerGPUAdapter} inner
+ * @returns {GPUAdapter}
+ */
+ function createGPUAdapter(name, inner) {
+ /** @type {GPUAdapter} */
+ const adapter = webidl.createBranded(GPUAdapter);
+ adapter[_name] = name;
+ adapter[_adapter] = {
+ ...inner,
+ features: createGPUAdapterFeatures(inner.features),
+ limits: createGPUAdapterLimits(inner.limits),
+ };
+ return adapter;
+ }
+
+ class GPUAdapter {
+ /** @type {string} */
+ [_name];
+ /** @type {InnerGPUAdapter} */
+ [_adapter];
+
+ /** @returns {string} */
+ get name() {
+ webidl.assertBranded(this, GPUAdapter);
+ return this[_name];
+ }
+ /** @returns {GPUAdapterFeatures} */
+ get features() {
+ webidl.assertBranded(this, GPUAdapter);
+ return this[_adapter].features;
+ }
+ /** @returns {GPUAdapterLimits} */
+ get limits() {
+ webidl.assertBranded(this, GPUAdapter);
+ return this[_adapter].limits;
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPUDeviceDescriptor} descriptor
+ * @returns {Promise}
+ */
+ async requestDevice(descriptor = {}) {
+ webidl.assertBranded(this, GPUAdapter);
+ const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'";
+ descriptor = webidl.converters.GPUDeviceDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const nonGuaranteedFeatures = descriptor.nonGuaranteedFeatures ?? [];
+ for (const feature of nonGuaranteedFeatures) {
+ if (!this[_adapter].features.has(feature)) {
+ throw new TypeError(
+ `${prefix}: nonGuaranteedFeatures must be a subset of the adapter features.`,
+ );
+ }
+ }
+ const nonGuaranteedLimits = descriptor.nonGuaranteedLimits ?? [];
+ // TODO(lucacasonato): validate nonGuaranteedLimits
+
+ const { rid, features, limits } = await core.jsonOpAsync(
+ "op_webgpu_request_device",
+ {
+ adapterRid: this[_adapter].rid,
+ labe: descriptor.label,
+ nonGuaranteedFeatures,
+ nonGuaranteedLimits,
+ },
+ );
+
+ const inner = new InnerGPUDevice({
+ rid,
+ adapter: this,
+ features: Object.freeze(features),
+ limits: Object.freeze(limits),
+ });
+ return createGPUDevice(
+ descriptor.label ?? null,
+ inner,
+ createGPUQueue(descriptor.label ?? null, inner),
+ );
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ name: this.name,
+ features: this.features,
+ limits: this.limits,
+ })
+ }`;
+ }
+ }
+
+ const _limits = Symbol("[[limits]]");
+
+ function createGPUAdapterLimits(features) {
+ /** @type {GPUAdapterLimits} */
+ const adapterFeatures = webidl.createBranded(GPUAdapterLimits);
+ adapterFeatures[_limits] = features;
+ return adapterFeatures;
+ }
+
+ /**
+ * @typedef InnerAdapterLimits
+ * @property {number} maxTextureDimension1D
+ * @property {number} maxTextureDimension2D
+ * @property {number} maxTextureDimension3D
+ * @property {number} maxTextureArrayLayers
+ * @property {number} maxBindGroups
+ * @property {number} maxDynamicUniformBuffersPerPipelineLayout
+ * @property {number} maxDynamicStorageBuffersPerPipelineLayout
+ * @property {number} maxSampledTexturesPerShaderStage
+ * @property {number} maxSamplersPerShaderStage
+ * @property {number} maxStorageBuffersPerShaderStage
+ * @property {number} maxStorageTexturesPerShaderStage
+ * @property {number} maxUniformBuffersPerShaderStage
+ * @property {number} maxUniformBufferBindingSize
+ * @property {number} maxStorageBufferBindingSize
+ * @property {number} maxVertexBuffers
+ * @property {number} maxVertexAttributes
+ * @property {number} maxVertexBufferArrayStride
+ */
+
+ class GPUAdapterLimits {
+ /** @type {InnerAdapterLimits} */
+ [_limits];
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ get maxTextureDimension1D() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxTextureDimension2D() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxTextureDimension3D() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxTextureArrayLayers() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxBindGroups() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxBindGroups;
+ }
+ get maxDynamicUniformBuffersPerPipelineLayout() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxDynamicUniformBuffersPerPipelineLayout;
+ }
+ get maxDynamicStorageBuffersPerPipelineLayout() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxDynamicStorageBuffersPerPipelineLayout;
+ }
+ get maxSampledTexturesPerShaderStage() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxSampledTexturesPerShaderStage;
+ }
+ get maxSamplersPerShaderStage() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxSamplersPerShaderStage;
+ }
+ get maxStorageBuffersPerShaderStage() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxStorageBuffersPerShaderStage;
+ }
+ get maxStorageTexturesPerShaderStage() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxStorageTexturesPerShaderStage;
+ }
+ get maxUniformBuffersPerShaderStage() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxUniformBuffersPerShaderStage;
+ }
+ get maxUniformBufferBindingSize() {
+ webidl.assertBranded(this, GPUAdapterLimits);
+ return this[_limits].maxUniformBufferBindingSize;
+ }
+ get maxStorageBufferBindingSize() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxVertexBuffers() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxVertexAttributes() {
+ throw new TypeError("Not yet implemented");
+ }
+ get maxVertexBufferArrayStride() {
+ throw new TypeError("Not yet implemented");
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${inspect(this[_limits])}`;
+ }
+ }
+
+ const _features = Symbol("[[features]]");
+
+ function createGPUAdapterFeatures(features) {
+ /** @type {GPUAdapterFeatures} */
+ const adapterFeatures = webidl.createBranded(GPUAdapterFeatures);
+ adapterFeatures[_features] = new Set(features);
+ return adapterFeatures;
+ }
+
+ class GPUAdapterFeatures {
+ /** @type {Set} */
+ [_features];
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /** @return {IterableIterator<[string, string]>} */
+ entries() {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features].entries();
+ }
+
+ /** @return {void} */
+ forEach(callbackfn, thisArg) {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ this[_features].forEach(callbackfn, thisArg);
+ }
+
+ /** @return {boolean} */
+ has(value) {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features].has(value);
+ }
+
+ /** @return {IterableIterator} */
+ keys() {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features].keys();
+ }
+
+ /** @return {IterableIterator} */
+ values() {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features].values();
+ }
+
+ /** @return {number} */
+ get size() {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features].size;
+ }
+
+ [Symbol.iterator]() {
+ webidl.assertBranded(this, GPUAdapterFeatures);
+ return this[_features][Symbol.iterator]();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${inspect([...this.values()])}`;
+ }
+ }
+
+ const _reason = Symbol("[[reason]]");
+ const _message = Symbol("[[message]]");
+
+ /**
+ *
+ * @param {string | undefined} reason
+ * @param {string} message
+ * @returns {GPUDeviceLostInfo}
+ */
+ function createGPUDeviceLostInfo(reason, message) {
+ /** @type {GPUDeviceLostInfo} */
+ const deviceLostInfo = webidl.createBranded(GPUDeviceLostInfo);
+ deviceLostInfo[_reason] = reason;
+ deviceLostInfo[_message] = message;
+ return deviceLostInfo;
+ }
+
+ class GPUDeviceLostInfo {
+ /** @type {string | undefined} */
+ [_reason];
+ /** @type {string} */
+ [_message];
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ get reason() {
+ webidl.assertBranded(this, GPUDeviceLostInfo);
+ return this[_reason];
+ }
+ get message() {
+ webidl.assertBranded(this, GPUDeviceLostInfo);
+ return this[_message];
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({ reason: this[_reason], message: this[_message] })
+ }`;
+ }
+ }
+
+ const _label = Symbol("[[label]]");
+
+ /**
+ * @param {string} name
+ * @param {any} type
+ */
+ function GPUObjectBaseMixin(name, type) {
+ type.prototype[_label] = null;
+ Object.defineProperty(type.prototype, "label", {
+ /**
+ * @return {string | null}
+ */
+ get() {
+ webidl.assertBranded(this, type);
+ return this[_label];
+ },
+ /**
+ * @param {string | null} label
+ */
+ set(label) {
+ webidl.assertBranded(this, type);
+ label = webidl.converters["UVString?"](label, {
+ prefix: `Failed to set 'label' on '${name}'`,
+ context: "Argument 1",
+ });
+ this[_label] = label;
+ },
+ });
+ }
+
+ const _device = Symbol("[[device]]");
+ const _queue = Symbol("[[queue]]");
+
+ /**
+ * @typedef ErrorScope
+ * @property {string} filter
+ * @property {GPUError | undefined} error
+ */
+
+ /**
+ * @typedef InnerGPUDeviceOptions
+ * @property {GPUAdapter} adapter
+ * @property {number | undefined} rid
+ * @property {GPUFeatureName[]} features
+ * @property {object} limits
+ */
+
+ class InnerGPUDevice {
+ /** @type {GPUAdapter} */
+ adapter;
+ /** @type {number | undefined} */
+ rid;
+ /** @type {GPUFeatureName[]} */
+ features;
+ /** @type {object} */
+ limits;
+ /** @type {WeakRef[]} */
+ resources;
+ /** @type {boolean} */
+ isLost;
+ /** @type {Promise} */
+ lost;
+ /** @type {(info: GPUDeviceLostInfo) => void} */
+ resolveLost;
+ /** @type {ErrorScope[]} */
+ errorScopeStack;
+
+ /**
+ * @param {InnerGPUDeviceOptions} options
+ */
+ constructor(options) {
+ this.adapter = options.adapter;
+ this.rid = options.rid;
+ this.features = options.features;
+ this.limits = options.limits;
+ this.resources = [];
+ this.isLost = false;
+ this.resolveLost = () => {};
+ this.lost = new Promise((resolve) => {
+ this.resolveLost = resolve;
+ });
+ this.errorScopeStack = [];
+ }
+
+ /** @param {any} resource */
+ trackResource(resource) {
+ this.resources.push(new WeakRef(resource));
+ }
+
+ /** @param {{ type: string, value: string | null } | undefined} err */
+ pushError(err) {
+ if (err) {
+ switch (err.type) {
+ case "lost":
+ this.isLost = true;
+ this.resolveLost(
+ createGPUDeviceLostInfo(undefined, "device was lost"),
+ );
+ break;
+ case "validation":
+ case "out-of-memory":
+ for (
+ let i = this.errorScopeStack.length - 1;
+ i >= 0;
+ i--
+ ) {
+ const scope = this.errorScopeStack[i];
+ if (scope.filter == err.type) {
+ if (!scope.error) {
+ switch (err.type) {
+ case "validation":
+ scope.error = new GPUValidationError(
+ err.value ?? "validation error",
+ );
+ break;
+ case "out-of-memory":
+ scope.error = new GPUOutOfMemoryError();
+ break;
+ }
+ }
+ return;
+ }
+ }
+ // TODO(lucacasonato): emit a UncapturedErrorEvent
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} inner
+ * @param {GPUQueue} queue
+ * @returns {GPUDevice}
+ */
+ function createGPUDevice(label, inner, queue) {
+ /** @type {GPUDevice} */
+ const device = webidl.createBranded(GPUDevice);
+ device[_label] = label;
+ device[_device] = inner;
+ device[_queue] = queue;
+ return device;
+ }
+
+ // TODO(@crowlKats): https://gpuweb.github.io/gpuweb/#errors-and-debugging
+ class GPUDevice extends eventTarget.EventTarget {
+ /** @type {InnerGPUDevice} */
+ [_device];
+
+ /** @type {GPUQueue} */
+ [_queue];
+
+ [_cleanup]() {
+ const device = this[_device];
+ const resources = device.resources;
+ while (resources.length > 0) {
+ const resource = resources.pop()?.deref();
+ if (resource) {
+ resource[_cleanup]();
+ }
+ }
+ const rid = device.rid;
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ device.rid = undefined;
+ }
+ }
+
+ get adapter() {
+ webidl.assertBranded(this, GPUDevice);
+ return this[_device].adapter;
+ }
+ get features() {
+ webidl.assertBranded(this, GPUDevice);
+ return this[_device].features;
+ }
+ get limits() {
+ webidl.assertBranded(this, GPUDevice);
+ return this[_device].limits;
+ }
+ get queue() {
+ webidl.assertBranded(this, GPUDevice);
+ return this[_queue];
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ super();
+ }
+
+ destroy() {
+ webidl.assertBranded(this, GPUDevice);
+ this[_cleanup]();
+ }
+
+ /**
+ * @param {GPUBufferDescriptor} descriptor
+ * @returns {GPUBuffer}
+ */
+ createBuffer(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createBuffer' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUBufferDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_buffer", {
+ deviceRid: device.rid,
+ ...descriptor,
+ });
+ device.pushError(err);
+ /** @type {CreateGPUBufferOptions} */
+ let options;
+ if (descriptor.mappedAtCreation) {
+ options = {
+ mapping: new ArrayBuffer(descriptor.size),
+ mappingRange: [0, descriptor.size],
+ mappedRanges: [],
+ state: "mapped at creation",
+ };
+ } else {
+ options = {
+ mapping: null,
+ mappedRanges: null,
+ mappingRange: null,
+ state: "unmapped",
+ };
+ }
+ const buffer = createGPUBuffer(
+ descriptor.label ?? null,
+ device,
+ rid,
+ descriptor.size,
+ descriptor.usage,
+ options,
+ );
+ device.trackResource((buffer));
+ return buffer;
+ }
+
+ /**
+ * @param {GPUTextureDescriptor} descriptor
+ * @returns {GPUTexture}
+ */
+ createTexture(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createTexture' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUTextureDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_texture", {
+ deviceRid: device.rid,
+ ...descriptor,
+ size: normalizeGPUExtent3D(descriptor.size),
+ });
+ device.pushError(err);
+
+ const texture = createGPUTexture(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((texture));
+ return texture;
+ }
+
+ /**
+ * @param {GPUSamplerDescriptor} descriptor
+ * @returns {GPUSampler}
+ */
+ createSampler(descriptor = {}) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createSampler' on 'GPUDevice'";
+ descriptor = webidl.converters.GPUSamplerDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_sampler", {
+ deviceRid: device.rid,
+ ...descriptor,
+ });
+ device.pushError(err);
+
+ const sampler = createGPUSampler(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((sampler));
+ return sampler;
+ }
+
+ /**
+ * @param {GPUBindGroupLayoutDescriptor} descriptor
+ * @returns {GPUBindGroupLayout}
+ */
+ createBindGroupLayout(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createBindGroupLayout' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUBindGroupLayoutDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ for (const entry of descriptor.entries) {
+ let i = 0;
+ if (entry.buffer) i++;
+ if (entry.sampler) i++;
+ if (entry.texture) i++;
+ if (entry.storageTexture) i++;
+
+ if (i !== 1) {
+ throw new Error(); // TODO(@crowlKats): correct error
+ }
+ }
+
+ const { rid, err } = core.jsonOpSync(
+ "op_webgpu_create_bind_group_layout",
+ {
+ deviceRid: device.rid,
+ ...descriptor,
+ },
+ );
+ device.pushError(err);
+
+ const bindGroupLayout = createGPUBindGroupLayout(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((bindGroupLayout));
+ return bindGroupLayout;
+ }
+
+ /**
+ * @param {GPUPipelineLayoutDescriptor} descriptor
+ * @returns {GPUPipelineLayout}
+ */
+ createPipelineLayout(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createPipelineLayout' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUPipelineLayoutDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const bindGroupLayouts = descriptor.bindGroupLayouts.map(
+ (layout, i) => {
+ const context = `bind group layout ${i + 1}`;
+ const rid = assertResource(layout, { prefix, context });
+ assertDeviceMatch(device, layout, {
+ prefix,
+ selfContext: "this",
+ resourceContext: context,
+ });
+ return rid;
+ },
+ );
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_pipeline_layout", {
+ deviceRid: device.rid,
+ label: descriptor.label,
+ bindGroupLayouts,
+ });
+ device.pushError(err);
+
+ const pipelineLayout = createGPUPipelineLayout(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((pipelineLayout));
+ return pipelineLayout;
+ }
+
+ /**
+ * @param {GPUBindGroupDescriptor} descriptor
+ * @returns {GPUBindGroup}
+ */
+ createBindGroup(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createBindGroup' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUBindGroupDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const layout = assertResource(descriptor.layout, {
+ prefix,
+ context: "layout",
+ });
+ assertDeviceMatch(device, descriptor.layout, {
+ prefix,
+ resourceContext: "layout",
+ selfContext: "this",
+ });
+ const entries = descriptor.entries.map((entry, i) => {
+ const context = `entry ${i + 1}`;
+ const resource = entry.resource;
+ if (resource instanceof GPUSampler) {
+ const rid = assertResource(resource, {
+ prefix,
+ context,
+ });
+ assertDeviceMatch(device, resource, {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ return {
+ binding: entry.binding,
+ kind: "GPUSampler",
+ resource: rid,
+ };
+ } else if (resource instanceof GPUTextureView) {
+ const rid = assertResource(resource, {
+ prefix,
+ context,
+ });
+ assertResource(resource[_texture], {
+ prefix,
+ context,
+ });
+ assertDeviceMatch(device, resource[_texture], {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ return {
+ binding: entry.binding,
+ kind: "GPUTextureView",
+ resource: rid,
+ };
+ } else {
+ const rid = assertResource(resource.buffer, { prefix, context });
+ assertDeviceMatch(device, resource.buffer, {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ return {
+ binding: entry.binding,
+ kind: "GPUBufferBinding",
+ resource: rid,
+ offset: entry.resource.offset,
+ size: entry.resource.size,
+ };
+ }
+ });
+
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_bind_group", {
+ deviceRid: device.rid,
+ label: descriptor.label,
+ layout,
+ entries,
+ });
+ device.pushError(err);
+
+ const bindGroup = createGPUBindGroup(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((bindGroup));
+ return bindGroup;
+ }
+
+ /**
+ * @param {GPUShaderModuleDescriptor} descriptor
+ */
+ createShaderModule(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createShaderModule' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUShaderModuleDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync(
+ "op_webgpu_create_shader_module",
+ {
+ deviceRid: device.rid,
+ label: descriptor.label,
+ code: (typeof descriptor.code === "string")
+ ? descriptor.code
+ : undefined,
+ sourceMap: descriptor.sourceMap,
+ },
+ ...(descriptor.code instanceof Uint32Array
+ ? [new Uint8Array(descriptor.code.buffer)]
+ : []),
+ );
+ device.pushError(err);
+
+ const shaderModule = createGPUShaderModule(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((shaderModule));
+ return shaderModule;
+ }
+
+ /**
+ * @param {GPUComputePipelineDescriptor} descriptor
+ * @returns {GPUComputePipeline}
+ */
+ createComputePipeline(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createComputePipeline' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUComputePipelineDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ let layout = undefined;
+ if (descriptor.layout) {
+ const context = "layout";
+ layout = assertResource(descriptor.layout, { prefix, context });
+ assertDeviceMatch(device, descriptor.layout, {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ }
+ const module = assertResource(descriptor.compute.module, {
+ prefix,
+ context: "compute shader module",
+ });
+ assertDeviceMatch(device, descriptor.compute.module, {
+ prefix,
+ resourceContext: "compute shader module",
+ selfContext: "this",
+ });
+
+ const { rid, err } = core.jsonOpSync(
+ "op_webgpu_create_compute_pipeline",
+ {
+ deviceRid: device.rid,
+ label: descriptor.label,
+ layout,
+ compute: {
+ module,
+ entryPoint: descriptor.compute.entryPoint,
+ },
+ },
+ );
+ device.pushError(err);
+
+ const computePipeline = createGPUComputePipeline(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((computePipeline));
+ return computePipeline;
+ }
+
+ /**
+ * @param {GPURenderPipelineDescriptor} descriptor
+ * @returns {GPURenderPipeline}
+ */
+ createRenderPipeline(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createRenderPipeline' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPURenderPipelineDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ let layout = undefined;
+ if (descriptor.layout) {
+ const context = "layout";
+ layout = assertResource(descriptor.layout, { prefix, context });
+ assertDeviceMatch(device, descriptor.layout, {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ }
+ const module = assertResource(descriptor.vertex.module, {
+ prefix,
+ context: "vertex shader module",
+ });
+ assertDeviceMatch(device, descriptor.vertex.module, {
+ prefix,
+ resourceContext: "vertex shader module",
+ selfContext: "this",
+ });
+ let fragment = undefined;
+ if (descriptor.fragment) {
+ const module = assertResource(descriptor.fragment.module, {
+ prefix,
+ context: "fragment shader module",
+ });
+ assertDeviceMatch(device, descriptor.fragment.module, {
+ prefix,
+ resourceContext: "fragment shader module",
+ selfContext: "this",
+ });
+ fragment = {
+ module,
+ entryPoint: descriptor.fragment.entryPoint,
+ targets: descriptor.fragment.targets,
+ };
+ }
+
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_render_pipeline", {
+ deviceRid: device.rid,
+ label: descriptor.label,
+ layout,
+ vertex: {
+ module,
+ entryPoint: descriptor.vertex.entryPoint,
+ buffers: descriptor.vertex.buffers,
+ },
+ primitive: descriptor.primitive,
+ depthStencil: descriptor.depthStencil,
+ multisample: descriptor.multisample,
+ fragment,
+ });
+ device.pushError(err);
+
+ const renderPipeline = createGPURenderPipeline(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((renderPipeline));
+ return renderPipeline;
+ }
+
+ createComputePipelineAsync(descriptor) {
+ // TODO(lucacasonato): this should be real async
+ return Promise.resolve(this.createComputePipeline(descriptor));
+ }
+
+ createRenderPipelineAsync(descriptor) {
+ // TODO(lucacasonato): this should be real async
+ return Promise.resolve(this.createRenderPipeline(descriptor));
+ }
+
+ /**
+ * @param {GPUCommandEncoderDescriptor} descriptor
+ * @returns {GPUCommandEncoder}
+ */
+ createCommandEncoder(descriptor = {}) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createCommandEncoder' on 'GPUDevice'";
+ descriptor = webidl.converters.GPUCommandEncoderDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_command_encoder", {
+ deviceRid: device.rid,
+ ...descriptor,
+ });
+ device.pushError(err);
+
+ const commandEncoder = createGPUCommandEncoder(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((commandEncoder));
+ return commandEncoder;
+ }
+
+ /**
+ * @param {GPURenderBundleEncoderDescriptor} descriptor
+ * @returns {GPURenderBundleEncoder}
+ */
+ createRenderBundleEncoder(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix =
+ "Failed to execute 'createRenderBundleEncoder' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPURenderBundleEncoderDescriptor(
+ descriptor,
+ {
+ prefix,
+ context: "Argument 1",
+ },
+ );
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync(
+ "op_webgpu_create_render_bundle_encoder",
+ {
+ deviceRid: device.rid,
+ ...descriptor,
+ },
+ );
+ device.pushError(err);
+
+ const renderBundleEncoder = createGPURenderBundleEncoder(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((renderBundleEncoder));
+ return renderBundleEncoder;
+ }
+
+ /**
+ * @param {GPUQuerySetDescriptor} descriptor
+ * @returns {GPUQuerySet}
+ */
+ createQuerySet(descriptor) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'createQuerySet' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPUQuerySetDescriptor(
+ descriptor,
+ {
+ prefix,
+ context: "Argument 1",
+ },
+ );
+ const device = assertDevice(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_query_set", {
+ deviceRid: device.rid,
+ ...descriptor,
+ });
+ device.pushError(err);
+
+ const querySet = createGPUQuerySet(
+ descriptor.label ?? null,
+ device,
+ rid,
+ descriptor,
+ );
+ device.trackResource((querySet));
+ return querySet;
+ }
+
+ get lost() {
+ webidl.assertBranded(this, GPUDevice);
+ const device = this[_device];
+ if (!device) {
+ return Promise.resolve(true);
+ }
+ if (device.rid === undefined) {
+ return Promise.resolve(true);
+ }
+ return device.lost;
+ }
+
+ /**
+ * @param {GPUErrorFilter} filter
+ */
+ pushErrorScope(filter) {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'pushErrorScope' on 'GPUDevice'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ filter = webidl.converters.GPUErrorFilter(filter, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ device.errorScopeStack.push({ filter, error: undefined });
+ }
+
+ /**
+ * @returns {Promise}
+ */
+ // deno-lint-ignore require-await
+ async popErrorScope() {
+ webidl.assertBranded(this, GPUDevice);
+ const prefix = "Failed to execute 'pushErrorScope' on 'GPUDevice'";
+ const device = assertDevice(this, { prefix, context: "this" });
+ if (device.isLost) {
+ throw new DOMException("Device has been lost.", "OperationError");
+ }
+ const scope = device.errorScopeStack.pop();
+ if (!scope) {
+ throw new DOMException(
+ "There are no error scopes on that stack.",
+ "OperationError",
+ );
+ }
+ return scope.error ?? null;
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ adapter: this.adapter,
+ features: this.features,
+ label: this.label,
+ limits: this.limits,
+ queue: this.queue,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUDevice", GPUDevice);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @returns {GPUQueue}
+ */
+ function createGPUQueue(label, device) {
+ /** @type {GPUQueue} */
+ const queue = webidl.createBranded(GPUQueue);
+ queue[_label] = label;
+ queue[_device] = device;
+ return queue;
+ }
+
+ class GPUQueue {
+ /** @type {InnerGPUDevice} */
+ [_device];
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPUCommandBuffer[]} commandBuffers
+ */
+ submit(commandBuffers) {
+ webidl.assertBranded(this, GPUQueue);
+ const prefix = "Failed to execute 'submit' on 'GPUQueue'";
+ webidl.requiredArguments(arguments.length, 1, {
+ prefix,
+ });
+ commandBuffers = webidl.converters["sequence"](
+ commandBuffers,
+ { prefix, context: "Argument 1" },
+ );
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandBufferRids = commandBuffers.map((buffer, i) => {
+ const context = `command buffer ${i + 1}`;
+ const rid = assertResource(buffer, { prefix, context });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ selfContext: "this",
+ resourceContext: context,
+ });
+ return rid;
+ });
+ const { err } = core.jsonOpSync("op_webgpu_queue_submit", {
+ queueRid: device.rid,
+ commandBuffers: commandBufferRids,
+ });
+ device.pushError(err);
+ }
+
+ onSubmittedWorkDone() {
+ webidl.assertBranded(this, GPUQueue);
+ return Promise.resolve();
+ }
+
+ /**
+ * @param {GPUBuffer} buffer
+ * @param {number} bufferOffset
+ * @param {BufferSource} data
+ * @param {number} [dataOffset]
+ * @param {number} [size]
+ */
+ writeBuffer(buffer, bufferOffset, data, dataOffset = 0, size) {
+ webidl.assertBranded(this, GPUQueue);
+ const prefix = "Failed to execute 'writeBuffer' on 'GPUQueue'";
+ webidl.requiredArguments(arguments.length, 3, { prefix });
+ buffer = webidl.converters["GPUBuffer"](buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ bufferOffset = webidl.converters["GPUSize64"](bufferOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ data = webidl.converters.BufferSource(data, {
+ prefix,
+ context: "Argument 3",
+ });
+ dataOffset = webidl.converters["GPUSize64"](dataOffset, {
+ prefix,
+ context: "Argument 4",
+ });
+ size = size === undefined
+ ? undefined
+ : webidl.converters["GPUSize64"](size, {
+ prefix,
+ context: "Argument 5",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const bufferRid = assertResource(buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ selfContext: "this",
+ resourceContext: "Argument 1",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_write_buffer",
+ {
+ queueRid: device.rid,
+ buffer: bufferRid,
+ bufferOffset,
+ dataOffset,
+ size,
+ },
+ new Uint8Array(ArrayBuffer.isView(data) ? data.buffer : data),
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUImageCopyTexture} destination
+ * @param {BufferSource} data
+ * @param {GPUImageDataLayout} dataLayout
+ * @param {GPUExtent3D} size
+ */
+ writeTexture(destination, data, dataLayout, size) {
+ webidl.assertBranded(this, GPUQueue);
+ const prefix = "Failed to execute 'writeTexture' on 'GPUQueue'";
+ webidl.requiredArguments(arguments.length, 4, { prefix });
+ destination = webidl.converters.GPUImageCopyTexture(destination, {
+ prefix,
+ context: "Argument 1",
+ });
+ data = webidl.converters.BufferSource(data, {
+ prefix,
+ context: "Argument 2",
+ });
+ dataLayout = webidl.converters.GPUImageDataLayout(dataLayout, {
+ prefix,
+ context: "Argument 3",
+ });
+ size = webidl.converters.GPUExtent3D(size, {
+ prefix,
+ context: "Argument 4",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const textureRid = assertResource(destination.texture, {
+ prefix,
+ context: "texture",
+ });
+ assertDeviceMatch(device, destination.texture, {
+ prefix,
+ selfContext: "this",
+ resourceContext: "texture",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_write_texture",
+ {
+ queueRid: device.rid,
+ destination: {
+ texture: textureRid,
+ mipLevel: destination.mipLevel,
+ origin: destination.origin
+ ? normalizeGPUOrigin3D(destination.origin)
+ : undefined,
+ },
+ dataLayout,
+ size: normalizeGPUExtent3D(size),
+ },
+ new Uint8Array(ArrayBuffer.isView(data) ? data.buffer : data),
+ );
+ device.pushError(err);
+ }
+
+ copyImageBitmapToTexture(_source, _destination, _copySize) {
+ throw new Error("Not yet implemented");
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUQueue", GPUQueue);
+
+ const _rid = Symbol("[[rid]]");
+
+ const _size = Symbol("[[size]]");
+ const _usage = Symbol("[[usage]]");
+ const _state = Symbol("[[state]]");
+ const _mappingRange = Symbol("[[mapping_range]]");
+ const _mappedRanges = Symbol("[[mapped_ranges]]");
+ const _mapMode = Symbol("[[map_mode]]");
+
+ /**
+ * @typedef CreateGPUBufferOptions
+ * @property {ArrayBuffer | null} mapping
+ * @property {number[] | null} mappingRange
+ * @property {[ArrayBuffer, number, number][] | null} mappedRanges
+ * @property {"mapped" | "mapped at creation" | "mapped pending" | "unmapped" | "destroy" } state
+ */
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @param {number} size
+ * @param {number} usage
+ * @param {CreateGPUBufferOptions} options
+ * @returns {GPUBuffer}
+ */
+ function createGPUBuffer(label, device, rid, size, usage, options) {
+ /** @type {GPUBuffer} */
+ const buffer = webidl.createBranded(GPUBuffer);
+ buffer[_label] = label;
+ buffer[_device] = device;
+ buffer[_rid] = rid;
+ buffer[_size] = size;
+ buffer[_usage] = usage;
+ buffer[_mappingRange] = options.mappingRange;
+ buffer[_mappedRanges] = options.mappedRanges;
+ buffer[_state] = options.state;
+ return buffer;
+ }
+
+ class GPUBuffer {
+ /** @type {InnerGPUDevice} */
+ [_device];
+
+ /** @type {number} */
+ [_rid];
+
+ /** @type {number} */
+ [_size];
+
+ /** @type {number} */
+ [_usage];
+
+ /** @type {"mapped" | "mapped at creation" | "mapped pending" | "unmapped" | "destroy"} */
+ [_state];
+
+ /** @type {[number, number] | null} */
+ [_mappingRange];
+
+ /** @type {[ArrayBuffer, number, number][] | null} */
+ [_mappedRanges];
+
+ /** @type {number} */
+ [_mapMode];
+
+ [_cleanup]() {
+ const mappedRanges = this[_mappedRanges];
+ if (mappedRanges) {
+ while (mappedRanges.length > 0) {
+ const mappedRange = mappedRanges.pop();
+ if (mappedRange !== undefined) {
+ core.close(mappedRange[1]);
+ }
+ }
+ }
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ this[_state] = "destroy";
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {number} mode
+ * @param {number} offset
+ * @param {number} [size]
+ */
+ async mapAsync(mode, offset = 0, size) {
+ webidl.assertBranded(this, GPUBuffer);
+ const prefix = "Failed to execute 'mapAsync' on 'GPUBuffer'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ mode = webidl.converters.GPUMapModeFlags(mode, {
+ prefix,
+ context: "Argument 1",
+ });
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 2",
+ });
+ size = size === undefined
+ ? undefined
+ : webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 3",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const bufferRid = assertResource(this, { prefix, context: "this" });
+ /** @type {number} */
+ let rangeSize;
+ if (size === undefined) {
+ rangeSize = Math.max(0, this[_size] - offset);
+ } else {
+ rangeSize = this[_size];
+ }
+ if ((offset % 8) !== 0) {
+ throw new DOMException(
+ `${prefix}: offset must be a multiple of 8.`,
+ "OperationError",
+ );
+ }
+ if ((rangeSize % 4) !== 0) {
+ throw new DOMException(
+ `${prefix}: rangeSize must be a multiple of 4.`,
+ "OperationError",
+ );
+ }
+ if ((offset + rangeSize) > this[_size]) {
+ throw new DOMException(
+ `${prefix}: offset + rangeSize must be less than or equal to buffer size.`,
+ "OperationError",
+ );
+ }
+ if (this[_state] !== "unmapped") {
+ throw new DOMException(
+ `${prefix}: GPUBuffer is not currently unmapped.`,
+ "OperationError",
+ );
+ }
+ const readMode = (mode & 0x0001) === 0x0001;
+ const writeMode = (mode & 0x0002) === 0x0002;
+ if ((readMode && writeMode) || (!readMode && !writeMode)) {
+ throw new DOMException(
+ `${prefix}: exactly one of READ or WRITE map mode must be set.`,
+ "OperationError",
+ );
+ }
+ if (readMode && !((this[_usage] && 0x0001) === 0x0001)) {
+ throw new DOMException(
+ `${prefix}: READ map mode not valid because buffer does not have MAP_READ usage.`,
+ "OperationError",
+ );
+ }
+ if (writeMode && !((this[_usage] && 0x0002) === 0x0002)) {
+ throw new DOMException(
+ `${prefix}: WRITE map mode not valid because buffer does not have MAP_WRITE usage.`,
+ "OperationError",
+ );
+ }
+
+ this[_mapMode] = mode;
+ this[_state] = "mapping pending";
+ const { err } = await core.jsonOpAsync(
+ "op_webgpu_buffer_get_map_async",
+ {
+ bufferRid,
+ deviceRid: device.rid,
+ mode,
+ offset,
+ size: rangeSize,
+ },
+ );
+ device.pushError(err);
+ this[_state] = "mapped";
+ this[_mappingRange] = [offset, offset + rangeSize];
+ /** @type {[ArrayBuffer, number, number][] | null} */
+ this[_mappedRanges] = [];
+ }
+
+ /**
+ * @param {number} offset
+ * @param {number} size
+ */
+ getMappedRange(offset = 0, size) {
+ webidl.assertBranded(this, GPUBuffer);
+ const prefix = "Failed to execute 'getMappedRange' on 'GPUBuffer'";
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 1",
+ });
+ size = size === undefined
+ ? undefined
+ : webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDevice(this, { prefix, context: "this" });
+ const bufferRid = assertResource(this, { prefix, context: "this" });
+ /** @type {number} */
+ let rangeSize;
+ if (size === undefined) {
+ rangeSize = Math.max(0, this[_size] - offset);
+ } else {
+ rangeSize = this[_size];
+ }
+ if (this[_state] !== "mapped" && this[_state] !== "mapped at creation") {
+ throw new DOMException(
+ `${prefix}: buffer is not mapped.`,
+ "OperationError",
+ );
+ }
+ if ((offset % 8) !== 0) {
+ throw new DOMException(
+ `${prefix}: offset must be a multiple of 8.`,
+ "OperationError",
+ );
+ }
+ if ((rangeSize % 4) !== 0) {
+ throw new DOMException(
+ `${prefix}: rangeSize must be a multiple of 4.`,
+ "OperationError",
+ );
+ }
+ const mappingRange = this[_mappingRange];
+ if (!mappingRange) {
+ throw new DOMException(`${prefix}: invalid state.`, "OperationError");
+ }
+ if (offset < mappingRange[0]) {
+ throw new DOMException(
+ `${prefix}: offset is out of bounds.`,
+ "OperationError",
+ );
+ }
+ if ((offset + rangeSize) > mappingRange[1]) {
+ throw new DOMException(
+ `${prefix}: offset is out of bounds.`,
+ "OperationError",
+ );
+ }
+ const mappedRanges = this[_mappedRanges];
+ if (!mappedRanges) {
+ throw new DOMException(`${prefix}: invalid state.`, "OperationError");
+ }
+ for (const [buffer, _rid, start] of mappedRanges) {
+ // TODO(lucacasonato): is this logic correct?
+ const end = start + buffer.byteLength;
+ if (
+ (start >= offset && start < (offset + rangeSize)) ||
+ (end >= offset && end < (offset + rangeSize))
+ ) {
+ throw new DOMException(
+ `${prefix}: requested buffer overlaps with another mapped range.`,
+ "OperationError",
+ );
+ }
+ }
+
+ const buffer = new ArrayBuffer(rangeSize);
+ const { rid } = core.jsonOpSync(
+ "op_webgpu_buffer_get_mapped_range",
+ {
+ bufferRid,
+ offset: offset - mappingRange[0],
+ size: rangeSize,
+ },
+ new Uint8Array(buffer),
+ );
+
+ mappedRanges.push([buffer, rid, offset]);
+
+ return buffer;
+ }
+
+ unmap() {
+ webidl.assertBranded(this, GPUBuffer);
+ const prefix = "Failed to execute 'unmap' on 'GPUBuffer'";
+ const device = assertDevice(this, { prefix, context: "this" });
+ const bufferRid = assertResource(this, { prefix, context: "this" });
+ if (this[_state] === "unmapped" || this[_state] === "destroyed") {
+ throw new DOMException(
+ `${prefix}: buffer is not ready to be unmapped.`,
+ "OperationError",
+ );
+ }
+ if (this[_state] === "mapping pending") {
+ // TODO(lucacasonato): this is not spec compliant.
+ throw new DOMException(
+ `${prefix}: can not unmap while mapping. This is a Deno limitation.`,
+ "OperationError",
+ );
+ } else if (
+ this[_state] === "mapped" || this[_state] === "mapped at creation"
+ ) {
+ /** @type {boolean} */
+ let write = false;
+ if (this[_state] === "mapped at creation") {
+ write = true;
+ } else if (this[_state] === "mapped") {
+ const mapMode = this[_mapMode];
+ if (mapMode === undefined) {
+ throw new DOMException(
+ `${prefix}: invalid state.`,
+ "OperationError",
+ );
+ }
+ if ((mapMode & 0x0002) === 0x0002) {
+ write = true;
+ }
+ }
+
+ const mappedRanges = this[_mappedRanges];
+ if (!mappedRanges) {
+ throw new DOMException(`${prefix}: invalid state.`, "OperationError");
+ }
+ for (const [buffer, mappedRid] of mappedRanges) {
+ const { err } = core.jsonOpSync("op_webgpu_buffer_unmap", {
+ bufferRid,
+ mappedRid,
+ }, ...(write ? [new Uint8Array(buffer)] : []));
+ device.pushError(err);
+ if (err) return;
+ }
+ this[_mappingRange] = null;
+ this[_mappedRanges] = null;
+ }
+
+ this[_state] = "unmapped";
+ }
+
+ destroy() {
+ webidl.assertBranded(this, GPUBuffer);
+ this[_cleanup]();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUBuffer", GPUBuffer);
+
+ class GPUBufferUsage {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ static get MAP_READ() {
+ return 0x0001;
+ }
+ static get MAP_WRITE() {
+ return 0x0002;
+ }
+ static get COPY_SRC() {
+ return 0x0004;
+ }
+ static get COPY_DST() {
+ return 0x0008;
+ }
+ static get INDEX() {
+ return 0x0010;
+ }
+ static get VERTEX() {
+ return 0x0020;
+ }
+ static get UNIFORM() {
+ return 0x0040;
+ }
+ static get STORAGE() {
+ return 0x0080;
+ }
+ static get INDIRECT() {
+ return 0x0100;
+ }
+ static get QUERY_RESOLVE() {
+ return 0x0200;
+ }
+ }
+
+ class GPUMapMode {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ static get READ() {
+ return 0x0001;
+ }
+ static get WRITE() {
+ return 0x0002;
+ }
+ }
+
+ const _views = Symbol("[[views]]");
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUTexture}
+ */
+ function createGPUTexture(label, device, rid) {
+ /** @type {GPUTexture} */
+ const texture = webidl.createBranded(GPUTexture);
+ texture[_label] = label;
+ texture[_device] = device;
+ texture[_rid] = rid;
+ texture[_views] = [];
+ return texture;
+ }
+
+ class GPUTexture {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+ /** @type {WeakRef[]} */
+ [_views];
+
+ [_cleanup]() {
+ const views = this[_views];
+ while (views.length > 0) {
+ const view = views.pop()?.deref();
+ if (view) {
+ view[_cleanup]();
+ }
+ }
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPUTextureViewDescriptor} descriptor
+ */
+ createView(descriptor = {}) {
+ webidl.assertBranded(this, GPUTexture);
+ const prefix = "Failed to execute 'createView' on 'GPUTexture'";
+ webidl.requiredArguments(arguments.length, 0, { prefix });
+ descriptor = webidl.converters.GPUTextureViewDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const textureRid = assertResource(this, { prefix, context: "this" });
+ const { rid, err } = core.jsonOpSync("op_webgpu_create_texture_view", {
+ textureRid,
+ ...descriptor,
+ });
+ device.pushError(err);
+
+ const textureView = createGPUTextureView(
+ descriptor.label ?? null,
+ this,
+ rid,
+ );
+ this[_views].push(new WeakRef(textureView));
+ return textureView;
+ }
+
+ destroy() {
+ webidl.assertBranded(this, GPUTexture);
+ this[_cleanup]();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUTexture", GPUTexture);
+
+ class GPUTextureUsage {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ static get COPY_SRC() {
+ return 0x01;
+ }
+ static get COPY_DST() {
+ return 0x02;
+ }
+ static get SAMPLED() {
+ return 0x04;
+ }
+ static get STORAGE() {
+ return 0x08;
+ }
+ static get RENDER_ATTACHMENT() {
+ return 0x10;
+ }
+ }
+
+ const _texture = Symbol("[[texture]]");
+
+ /**
+ * @param {string | null} label
+ * @param {GPUTexture} texture
+ * @param {number} rid
+ * @returns {GPUTextureView}
+ */
+ function createGPUTextureView(label, texture, rid) {
+ /** @type {GPUTextureView} */
+ const textureView = webidl.createBranded(GPUTextureView);
+ textureView[_label] = label;
+ textureView[_texture] = texture;
+ textureView[_rid] = rid;
+ return textureView;
+ }
+ class GPUTextureView {
+ /** @type {GPUTexture} */
+ [_texture];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUTextureView", GPUTextureView);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUSampler}
+ */
+ function createGPUSampler(label, device, rid) {
+ /** @type {GPUSampler} */
+ const sampler = webidl.createBranded(GPUSampler);
+ sampler[_label] = label;
+ sampler[_device] = device;
+ sampler[_rid] = rid;
+ return sampler;
+ }
+ class GPUSampler {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUSampler", GPUSampler);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUBindGroupLayout}
+ */
+ function createGPUBindGroupLayout(label, device, rid) {
+ /** @type {GPUBindGroupLayout} */
+ const bindGroupLayout = webidl.createBranded(GPUBindGroupLayout);
+ bindGroupLayout[_label] = label;
+ bindGroupLayout[_device] = device;
+ bindGroupLayout[_rid] = rid;
+ return bindGroupLayout;
+ }
+ class GPUBindGroupLayout {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUBindGroupLayout", GPUBindGroupLayout);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUPipelineLayout}
+ */
+ function createGPUPipelineLayout(label, device, rid) {
+ /** @type {GPUPipelineLayout} */
+ const pipelineLayout = webidl.createBranded(GPUPipelineLayout);
+ pipelineLayout[_label] = label;
+ pipelineLayout[_device] = device;
+ pipelineLayout[_rid] = rid;
+ return pipelineLayout;
+ }
+ class GPUPipelineLayout {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUPipelineLayout", GPUPipelineLayout);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUBindGroup}
+ */
+ function createGPUBindGroup(label, device, rid) {
+ /** @type {GPUBindGroup} */
+ const bindGroup = webidl.createBranded(GPUBindGroup);
+ bindGroup[_label] = label;
+ bindGroup[_device] = device;
+ bindGroup[_rid] = rid;
+ return bindGroup;
+ }
+ class GPUBindGroup {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUBindGroup", GPUBindGroup);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUShaderModule}
+ */
+ function createGPUShaderModule(label, device, rid) {
+ /** @type {GPUShaderModule} */
+ const bindGroup = webidl.createBranded(GPUShaderModule);
+ bindGroup[_label] = label;
+ bindGroup[_device] = device;
+ bindGroup[_rid] = rid;
+ return bindGroup;
+ }
+ class GPUShaderModule {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ compilationInfo() {
+ throw new Error("Not yet implemented");
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUShaderModule", GPUShaderModule);
+
+ class GPUShaderStage {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ static get VERTEX() {
+ return 0x1;
+ }
+
+ static get FRAGMENT() {
+ return 0x2;
+ }
+
+ static get COMPUTE() {
+ return 0x4;
+ }
+ }
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUComputePipeline}
+ */
+ function createGPUComputePipeline(label, device, rid) {
+ /** @type {GPUComputePipeline} */
+ const pipeline = webidl.createBranded(GPUComputePipeline);
+ pipeline[_label] = label;
+ pipeline[_device] = device;
+ pipeline[_rid] = rid;
+ return pipeline;
+ }
+ class GPUComputePipeline {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {number} index
+ * @returns {GPUBindGroupLayout}
+ */
+ getBindGroupLayout(index) {
+ webidl.assertBranded(this, GPURenderPipeline);
+ const prefix =
+ "Failed to execute 'getBindGroupLayout' on 'GPUComputePipeline'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ index = webidl.converters["unsigned long"](index, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const computePipelineRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { rid, label, err } = core.jsonOpSync(
+ "op_webgpu_compute_pipeline_get_bind_group_layout",
+ { computePipelineRid, index },
+ );
+ device.pushError(err);
+
+ const bindGroupLayout = createGPUBindGroupLayout(
+ label,
+ device,
+ rid,
+ );
+ device.trackResource((bindGroupLayout));
+ return bindGroupLayout;
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUComputePipeline", GPUComputePipeline);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPURenderPipeline}
+ */
+ function createGPURenderPipeline(label, device, rid) {
+ /** @type {GPURenderPipeline} */
+ const pipeline = webidl.createBranded(GPURenderPipeline);
+ pipeline[_label] = label;
+ pipeline[_device] = device;
+ pipeline[_rid] = rid;
+ return pipeline;
+ }
+ class GPURenderPipeline {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {number} index
+ */
+ getBindGroupLayout(index) {
+ webidl.assertBranded(this, GPURenderPipeline);
+ const prefix =
+ "Failed to execute 'getBindGroupLayout' on 'GPURenderPipeline'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ index = webidl.converters["unsigned long"](index, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderPipelineRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { rid, label, err } = core.jsonOpSync(
+ "op_webgpu_render_pipeline_get_bind_group_layout",
+ { renderPipelineRid, index },
+ );
+ device.pushError(err);
+
+ const bindGroupLayout = createGPUBindGroupLayout(
+ label,
+ device,
+ rid,
+ );
+ device.trackResource((bindGroupLayout));
+ return bindGroupLayout;
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPURenderPipeline", GPURenderPipeline);
+
+ class GPUColorWrite {
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ static get RED() {
+ return 0x1;
+ }
+ static get GREEN() {
+ return 0x2;
+ }
+ static get BLUE() {
+ return 0x4;
+ }
+ static get ALPHA() {
+ return 0x8;
+ }
+ static get ALL() {
+ return 0xF;
+ }
+ }
+
+ const _encoders = Symbol("[[encoders]]");
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUCommandEncoder}
+ */
+ function createGPUCommandEncoder(label, device, rid) {
+ /** @type {GPUCommandEncoder} */
+ const encoder = webidl.createBranded(GPUCommandEncoder);
+ encoder[_label] = label;
+ encoder[_device] = device;
+ encoder[_rid] = rid;
+ encoder[_encoders] = [];
+ return encoder;
+ }
+ class GPUCommandEncoder {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+ /** @type {WeakRef[]} */
+ [_encoders];
+
+ [_cleanup]() {
+ const encoders = this[_encoders];
+ while (encoders.length > 0) {
+ const encoder = encoders.pop()?.deref();
+ if (encoder) {
+ encoder[_cleanup]();
+ }
+ }
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPURenderPassDescriptor} descriptor
+ * @return {GPURenderPassEncoder}
+ */
+ beginRenderPass(descriptor) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'beginRenderPass' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ descriptor = webidl.converters.GPURenderPassDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+
+ if (this[_rid] === undefined) {
+ throw new DOMException(
+ "Failed to execute 'beginRenderPass' on 'GPUCommandEncoder': already consumed",
+ "OperationError",
+ );
+ }
+
+ let depthStencilAttachment;
+ if (descriptor.depthStencilAttachment) {
+ const view = assertResource(descriptor.depthStencilAttachment.view, {
+ prefix,
+ context: "texture view for depth stencil attachment",
+ });
+ assertDeviceMatch(
+ device,
+ descriptor.depthStencilAttachment.view[_texture],
+ {
+ prefix,
+ resourceContext: "texture view for depth stencil attachment",
+ selfContext: "this",
+ },
+ );
+
+ depthStencilAttachment = {
+ ...descriptor.depthStencilAttachment,
+ view,
+ };
+
+ if (
+ typeof descriptor.depthStencilAttachment.depthLoadValue === "string"
+ ) {
+ depthStencilAttachment.depthLoadOp =
+ descriptor.depthStencilAttachment.depthLoadValue;
+ } else {
+ depthStencilAttachment.depthLoadOp = "clear";
+ depthStencilAttachment.depthLoadValue =
+ descriptor.depthStencilAttachment.depthLoadValue;
+ }
+
+ if (
+ typeof descriptor.depthStencilAttachment.stencilLoadValue === "string"
+ ) {
+ depthStencilAttachment.stencilLoadOp =
+ descriptor.depthStencilAttachment.stencilLoadValue;
+ depthStencilAttachment.stencilLoadValue = undefined;
+ } else {
+ depthStencilAttachment.stencilLoadOp = "clear";
+ depthStencilAttachment.stencilLoadValue =
+ descriptor.depthStencilAttachment.stencilLoadValue;
+ }
+ }
+ const colorAttachments = descriptor.colorAttachments.map(
+ (colorAttachment, i) => {
+ const context = `color attachment ${i + 1}`;
+ const view = assertResource(colorAttachment.view, {
+ prefix,
+ context: `texture view for ${context}`,
+ });
+ assertResource(colorAttachment.view[_texture], {
+ prefix,
+ context: `texture backing texture view for ${context}`,
+ });
+ assertDeviceMatch(
+ device,
+ colorAttachment.view[_texture],
+ {
+ prefix,
+ resourceContext: `texture view for ${context}`,
+ selfContext: "this",
+ },
+ );
+ let resolveTarget;
+ if (colorAttachment.resolveTarget) {
+ resolveTarget = assertResource(
+ colorAttachment.resolveTarget,
+ {
+ prefix,
+ context: `resolve target texture view for ${context}`,
+ },
+ );
+ assertResource(colorAttachment.resolveTarget[_texture], {
+ prefix,
+ context:
+ `texture backing resolve target texture view for ${context}`,
+ });
+ assertDeviceMatch(
+ device,
+ colorAttachment.resolveTarget[_texture],
+ {
+ prefix,
+ resourceContext: `resolve target texture view for ${context}`,
+ selfContext: "this",
+ },
+ );
+ }
+ const attachment = {
+ view: view,
+ resolveTarget,
+ storeOp: colorAttachment.storeOp,
+ };
+
+ if (typeof colorAttachment.loadValue === "string") {
+ attachment.loadOp = colorAttachment.loadValue;
+ } else {
+ attachment.loadOp = "clear";
+ attachment.loadValue = normalizeGPUColor(
+ colorAttachment.loadValue,
+ );
+ }
+
+ return attachment;
+ },
+ );
+
+ const { rid } = core.jsonOpSync(
+ "op_webgpu_command_encoder_begin_render_pass",
+ {
+ commandEncoderRid,
+ ...descriptor,
+ colorAttachments,
+ depthStencilAttachment,
+ },
+ );
+
+ const renderPassEncoder = createGPURenderPassEncoder(
+ descriptor.label ?? null,
+ this,
+ rid,
+ );
+ this[_encoders].push(new WeakRef(renderPassEncoder));
+ return renderPassEncoder;
+ }
+
+ /**
+ * @param {GPUComputePassDescriptor} descriptor
+ */
+ beginComputePass(descriptor = {}) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'beginComputePass' on 'GPUCommandEncoder'";
+ descriptor = webidl.converters.GPUComputePassDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+
+ assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+
+ const { rid } = core.jsonOpSync(
+ "op_webgpu_command_encoder_begin_compute_pass",
+ {
+ commandEncoderRid,
+ ...descriptor,
+ },
+ );
+
+ const computePassEncoder = createGPUComputePassEncoder(
+ descriptor.label ?? null,
+ this,
+ rid,
+ );
+ this[_encoders].push(new WeakRef(computePassEncoder));
+ return computePassEncoder;
+ }
+
+ /**
+ * @param {GPUBuffer} source
+ * @param {number} sourceOffset
+ * @param {GPUBuffer} destination
+ * @param {number} destinationOffset
+ * @param {number} size
+ */
+ copyBufferToBuffer(
+ source,
+ sourceOffset,
+ destination,
+ destinationOffset,
+ size,
+ ) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'copyBufferToBuffer' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 5, { prefix });
+ source = webidl.converters.GPUBuffer(source, {
+ prefix,
+ context: "Argument 1",
+ });
+ sourceOffset = webidl.converters.GPUSize64(sourceOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ destination = webidl.converters.GPUBuffer(destination, {
+ prefix,
+ context: "Argument 3",
+ });
+ destinationOffset = webidl.converters.GPUSize64(destinationOffset, {
+ prefix,
+ context: "Argument 4",
+ });
+ size = webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 5",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const sourceRid = assertResource(source, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, source, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ const destinationRid = assertResource(destination, {
+ prefix,
+ context: "Argument 3",
+ });
+ assertDeviceMatch(device, destination, {
+ prefix,
+ resourceContext: "Argument 3",
+ selfContext: "this",
+ });
+
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_copy_buffer_to_buffer",
+ {
+ commandEncoderRid,
+ source: sourceRid,
+ sourceOffset,
+ destination: destinationRid,
+ destinationOffset,
+ size,
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUImageCopyBuffer} source
+ * @param {GPUImageCopyTexture} destination
+ * @param {GPUExtent3D} copySize
+ */
+ copyBufferToTexture(source, destination, copySize) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'copyBufferToTexture' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 3, { prefix });
+ source = webidl.converters.GPUImageCopyBuffer(source, {
+ prefix,
+ context: "Argument 1",
+ });
+ destination = webidl.converters.GPUImageCopyTexture(destination, {
+ prefix,
+ context: "Argument 2",
+ });
+ copySize = webidl.converters.GPUExtent3D(copySize, {
+ prefix,
+ context: "Argument 3",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const sourceBufferRid = assertResource(source.buffer, {
+ prefix,
+ context: "source in Argument 1",
+ });
+ assertDeviceMatch(device, source.buffer, {
+ prefix,
+ resourceContext: "source in Argument 1",
+ selfContext: "this",
+ });
+ const destinationTextureRid = assertResource(destination.texture, {
+ prefix,
+ context: "texture in Argument 2",
+ });
+ assertDeviceMatch(device, destination.texture, {
+ prefix,
+ resourceContext: "texture in Argument 2",
+ selfContext: "this",
+ });
+
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_copy_buffer_to_texture",
+ {
+ commandEncoderRid,
+ source: {
+ ...source,
+ buffer: sourceBufferRid,
+ },
+ destination: {
+ texture: destinationTextureRid,
+ mipLevel: destination.mipLevel,
+ origin: destination.origin
+ ? normalizeGPUOrigin3D(destination.origin)
+ : undefined,
+ },
+ copySize: normalizeGPUExtent3D(copySize),
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUImageCopyTexture} source
+ * @param {GPUImageCopyBuffer} destination
+ * @param {GPUExtent3D} copySize
+ */
+ copyTextureToBuffer(source, destination, copySize) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'copyTextureToBuffer' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 3, { prefix });
+ source = webidl.converters.GPUImageCopyTexture(source, {
+ prefix,
+ context: "Argument 1",
+ });
+ destination = webidl.converters.GPUImageCopyBuffer(destination, {
+ prefix,
+ context: "Argument 2",
+ });
+ copySize = webidl.converters.GPUExtent3D(copySize, {
+ prefix,
+ context: "Argument 3",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const sourceTextureRid = assertResource(source.texture, {
+ prefix,
+ context: "texture in Argument 1",
+ });
+ assertDeviceMatch(device, source.texture, {
+ prefix,
+ resourceContext: "texture in Argument 1",
+ selfContext: "this",
+ });
+ const destinationBufferRid = assertResource(destination.buffer, {
+ prefix,
+ context: "buffer in Argument 2",
+ });
+ assertDeviceMatch(device, destination.buffer, {
+ prefix,
+ resourceContext: "buffer in Argument 2",
+ selfContext: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_copy_texture_to_buffer",
+ {
+ commandEncoderRid,
+ source: {
+ texture: sourceTextureRid,
+ mipLevel: source.mipLevel,
+ origin: source.origin
+ ? normalizeGPUOrigin3D(source.origin)
+ : undefined,
+ },
+ destination: {
+ ...destination,
+ buffer: destinationBufferRid,
+ },
+ copySize: normalizeGPUExtent3D(copySize),
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUImageCopyTexture} source
+ * @param {GPUImageCopyTexture} destination
+ * @param {GPUExtent3D} copySize
+ */
+ copyTextureToTexture(source, destination, copySize) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'copyTextureToTexture' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 3, { prefix });
+ source = webidl.converters.GPUImageCopyTexture(source, {
+ prefix,
+ context: "Argument 1",
+ });
+ destination = webidl.converters.GPUImageCopyTexture(destination, {
+ prefix,
+ context: "Argument 2",
+ });
+ copySize = webidl.converters.GPUExtent3D(copySize, {
+ prefix,
+ context: "Argument 3",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const sourceTextureRid = assertResource(source.texture, {
+ prefix,
+ context: "texture in Argument 1",
+ });
+ assertDeviceMatch(device, source.texture, {
+ prefix,
+ resourceContext: "texture in Argument 1",
+ selfContext: "this",
+ });
+ const destinationTextureRid = assertResource(destination.texture, {
+ prefix,
+ context: "texture in Argument 2",
+ });
+ assertDeviceMatch(device, destination.texture, {
+ prefix,
+ resourceContext: "texture in Argument 2",
+ selfContext: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_copy_texture_to_texture",
+ {
+ commandEncoderRid,
+ source: {
+ texture: sourceTextureRid,
+ mipLevel: source.mipLevel,
+ origin: source.origin
+ ? normalizeGPUOrigin3D(source.origin)
+ : undefined,
+ },
+ destination: {
+ texture: destinationTextureRid,
+ mipLevel: destination.mipLevel,
+ origin: destination.origin
+ ? normalizeGPUOrigin3D(destination.origin)
+ : undefined,
+ },
+ copySize: normalizeGPUExtent3D(copySize),
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {string} groupLabel
+ */
+ pushDebugGroup(groupLabel) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'pushDebugGroup' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ groupLabel = webidl.converters.USVString(groupLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_push_debug_group",
+ {
+ commandEncoderRid,
+ groupLabel,
+ },
+ );
+ device.pushError(err);
+ }
+
+ popDebugGroup() {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix = "Failed to execute 'popDebugGroup' on 'GPUCommandEncoder'";
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_pop_debug_group",
+ {
+ commandEncoderRid,
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {string} markerLabel
+ */
+ insertDebugMarker(markerLabel) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'insertDebugMarker' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ markerLabel = webidl.converters.USVString(markerLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_insert_debug_marker",
+ {
+ commandEncoderRid,
+ markerLabel,
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} queryIndex
+ */
+ writeTimestamp(querySet, queryIndex) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'writeTimestamp' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ queryIndex = webidl.converters.GPUSize32(queryIndex, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_write_timestamp",
+ {
+ commandEncoderRid,
+ querySet: querySetRid,
+ queryIndex,
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} firstQuery
+ * @param {number} queryCount
+ * @param {GPUBuffer} destination
+ * @param {number} destinationOffset
+ */
+ resolveQuerySet(
+ querySet,
+ firstQuery,
+ queryCount,
+ destination,
+ destinationOffset,
+ ) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix =
+ "Failed to execute 'resolveQuerySet' on 'GPUCommandEncoder'";
+ webidl.requiredArguments(arguments.length, 5, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ firstQuery = webidl.converters.GPUSize32(firstQuery, {
+ prefix,
+ context: "Argument 2",
+ });
+ queryCount = webidl.converters.GPUSize32(queryCount, {
+ prefix,
+ context: "Argument 3",
+ });
+ destination = webidl.converters.GPUQuerySet(destination, {
+ prefix,
+ context: "Argument 4",
+ });
+ destinationOffset = webidl.converters.GPUSize64(destinationOffset, {
+ prefix,
+ context: "Argument 5",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ const destinationRid = assertResource(destination, {
+ prefix,
+ context: "Argument 3",
+ });
+ assertDeviceMatch(device, destination, {
+ prefix,
+ resourceContext: "Argument 3",
+ selfContext: "this",
+ });
+ const { err } = core.jsonOpSync(
+ "op_webgpu_command_encoder_resolve_query_set",
+ {
+ commandEncoderRid,
+ querySet: querySetRid,
+ firstQuery,
+ queryCount,
+ destination: destinationRid,
+ destinationOffset,
+ },
+ );
+ device.pushError(err);
+ }
+
+ /**
+ * @param {GPUCommandBufferDescriptor} descriptor
+ * @returns {GPUCommandBuffer}
+ */
+ finish(descriptor = {}) {
+ webidl.assertBranded(this, GPUCommandEncoder);
+ const prefix = "Failed to execute 'finish' on 'GPUCommandEncoder'";
+ descriptor = webidl.converters.GPUCommandBufferDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const commandEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { rid, err } = core.jsonOpSync("op_webgpu_command_encoder_finish", {
+ commandEncoderRid,
+ ...descriptor,
+ });
+ device.pushError(err);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+
+ const commandBuffer = createGPUCommandBuffer(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((commandBuffer));
+ return commandBuffer;
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUCommandEncoder", GPUCommandEncoder);
+
+ const _encoder = Symbol("[[encoder]]");
+
+ /**
+ * @param {string | null} label
+ * @param {GPUCommandEncoder} encoder
+ * @param {number} rid
+ * @returns {GPURenderPassEncoder}
+ */
+ function createGPURenderPassEncoder(label, encoder, rid) {
+ /** @type {GPURenderPassEncoder} */
+ const passEncoder = webidl.createBranded(GPURenderPassEncoder);
+ passEncoder[_label] = label;
+ passEncoder[_encoder] = encoder;
+ passEncoder[_rid] = rid;
+ return passEncoder;
+ }
+
+ class GPURenderPassEncoder {
+ /** @type {GPUCommandEncoder} */
+ [_encoder];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {number} x
+ * @param {number} y
+ * @param {number} width
+ * @param {number} height
+ * @param {number} minDepth
+ * @param {number} maxDepth
+ */
+ setViewport(x, y, width, height, minDepth, maxDepth) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setViewport' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 6, { prefix });
+ x = webidl.converters.float(x, { prefix, context: "Argument 1" });
+ y = webidl.converters.float(y, { prefix, context: "Argument 2" });
+ width = webidl.converters.float(width, { prefix, context: "Argument 3" });
+ height = webidl.converters.float(height, {
+ prefix,
+ context: "Argument 4",
+ });
+ minDepth = webidl.converters.float(minDepth, {
+ prefix,
+ context: "Argument 5",
+ });
+ maxDepth = webidl.converters.float(maxDepth, {
+ prefix,
+ context: "Argument 6",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_set_viewport", {
+ renderPassRid,
+ x,
+ y,
+ width,
+ height,
+ minDepth,
+ maxDepth,
+ });
+ }
+
+ /**
+ *
+ * @param {number} x
+ * @param {number} y
+ * @param {number} width
+ * @param {number} height
+ */
+ setScissorRect(x, y, width, height) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setScissorRect' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 4, { prefix });
+ x = webidl.converters.GPUIntegerCoordinate(x, {
+ prefix,
+ context: "Argument 1",
+ });
+ y = webidl.converters.GPUIntegerCoordinate(y, {
+ prefix,
+ context: "Argument 2",
+ });
+ width = webidl.converters.GPUIntegerCoordinate(width, {
+ prefix,
+ context: "Argument 3",
+ });
+ height = webidl.converters.GPUIntegerCoordinate(height, {
+ prefix,
+ context: "Argument 4",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_set_scissor_rect", {
+ renderPassRid,
+ x,
+ y,
+ width,
+ height,
+ });
+ }
+
+ /**
+ * @param {GPUColor} color
+ */
+ setBlendColor(color) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setBlendColor' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ color = webidl.converters.GPUColor(color, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_set_blend_color", {
+ renderPassRid,
+ color: normalizeGPUColor(color),
+ });
+ }
+
+ /**
+ * @param {number} reference
+ */
+ setStencilReference(reference) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setStencilReference' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ reference = webidl.converters.GPUStencilValue(reference, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_set_stencil_reference", {
+ renderPassRid,
+ reference,
+ });
+ }
+
+ beginOcclusionQuery(_queryIndex) {
+ throw new Error("Not yet implemented");
+ }
+
+ endOcclusionQuery() {
+ throw new Error("Not yet implemented");
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} queryIndex
+ */
+ beginPipelineStatisticsQuery(querySet, queryIndex) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'beginPipelineStatisticsQuery' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ queryIndex = webidl.converters.GPUSize32(queryIndex, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_begin_pipeline_statistics_query", {
+ renderPassRid,
+ querySet: querySetRid,
+ queryIndex,
+ });
+ }
+
+ endPipelineStatisticsQuery() {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'endPipelineStatisticsQuery' on 'GPURenderPassEncoder'";
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_end_pipeline_statistics_query", {
+ renderPassRid,
+ });
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} queryIndex
+ */
+ writeTimestamp(querySet, queryIndex) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'writeTimestamp' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ queryIndex = webidl.converters.GPUSize32(queryIndex, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_write_timestamp", {
+ renderPassRid,
+ querySet: querySetRid,
+ queryIndex,
+ });
+ }
+
+ /**
+ * @param {GPURenderBundle[]} bundles
+ */
+ executeBundles(bundles) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'executeBundles' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ bundles = webidl.converters["sequence"](bundles, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const bundleRids = bundles.map((bundle, i) => {
+ const context = `bundle ${i + 1}`;
+ const rid = assertResource(bundle, { prefix, context });
+ assertDeviceMatch(device, bundle, {
+ prefix,
+ resourceContext: context,
+ selfContext: "this",
+ });
+ return rid;
+ });
+ core.jsonOpSync("op_webgpu_render_pass_execute_bundles", {
+ renderPassRid,
+ bundles: bundleRids,
+ });
+ }
+
+ endPass() {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix = "Failed to execute 'endPass' on 'GPURenderPassEncoder'";
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const commandEncoderRid = assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const { err } = core.jsonOpSync("op_webgpu_render_pass_end_pass", {
+ commandEncoderRid,
+ renderPassRid,
+ });
+ device.pushError(err);
+ this[_rid] = undefined;
+ }
+
+ // TODO(lucacasonato): has an overload
+ setBindGroup(
+ index,
+ bindGroup,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ ) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setBindGroup' on 'GPURenderPassEncoder'";
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const bindGroupRid = assertResource(bindGroup, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDeviceMatch(device, bindGroup, {
+ prefix,
+ resourceContext: "Argument 2",
+ selfContext: "this",
+ });
+ if (dynamicOffsetsData instanceof Uint32Array) {
+ core.jsonOpSync(
+ "op_webgpu_render_pass_set_bind_group",
+ {
+ renderPassRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ },
+ dynamicOffsetsData,
+ );
+ } else {
+ dynamicOffsetsData ??= [];
+ core.jsonOpSync("op_webgpu_render_pass_set_bind_group", {
+ renderPassRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart: 0,
+ dynamicOffsetsDataLength: dynamicOffsetsData.length,
+ });
+ }
+ }
+
+ /**
+ * @param {string} groupLabel
+ */
+ pushDebugGroup(groupLabel) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'pushDebugGroup' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ groupLabel = webidl.converters.USVString(groupLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_push_debug_group", {
+ renderPassRid,
+ groupLabel,
+ });
+ }
+
+ popDebugGroup() {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'popDebugGroup' on 'GPURenderPassEncoder'";
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_pop_debug_group", {
+ renderPassRid,
+ });
+ }
+
+ /**
+ * @param {string} markerLabel
+ */
+ insertDebugMarker(markerLabel) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'insertDebugMarker' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ markerLabel = webidl.converters.USVString(markerLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_insert_debug_marker", {
+ renderPassRid,
+ markerLabel,
+ });
+ }
+
+ /**
+ * @param {GPURenderPipeline} pipeline
+ */
+ setPipeline(pipeline) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setPipeline' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ pipeline = webidl.converters.GPURenderPipeline(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const pipelineRid = assertResource(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, pipeline, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_set_pipeline", {
+ renderPassRid,
+ pipeline: pipelineRid,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} buffer
+ * @param {GPUIndexFormat} indexFormat
+ * @param {number} offset
+ * @param {number} size
+ */
+ setIndexBuffer(buffer, indexFormat, offset = 0, size = 0) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setIndexBuffer' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ buffer = webidl.converters.GPUBuffer(buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indexFormat = webidl.converters.GPUIndexFormat(indexFormat, {
+ prefix,
+ context: "Argument 2",
+ });
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 3",
+ });
+ size = webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 4",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const bufferRid = assertResource(buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_set_index_buffer", {
+ renderPassRid,
+ buffer: bufferRid,
+ indexFormat,
+ offset,
+ size,
+ });
+ }
+
+ /**
+ * @param {number} slot
+ * @param {GPUBuffer} buffer
+ * @param {number} offset
+ * @param {number} size
+ */
+ setVertexBuffer(slot, buffer, offset = 0, size = 0) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'setVertexBuffer' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ slot = webidl.converters.GPUSize32(slot, {
+ prefix,
+ context: "Argument 2",
+ });
+ buffer = webidl.converters.GPUBuffer(buffer, {
+ prefix,
+ context: "Argument 2",
+ });
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 3",
+ });
+ size = webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 4",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const bufferRid = assertResource(buffer, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ resourceContext: "Argument 2",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_set_vertex_buffer", {
+ renderPassRid,
+ slot,
+ buffer: bufferRid,
+ offset,
+ size,
+ });
+ }
+
+ /**
+ * @param {number} vertexCount
+ * @param {number} instanceCount
+ * @param {number} firstVertex
+ * @param {number} firstInstance
+ */
+ draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix = "Failed to execute 'draw' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ vertexCount = webidl.converters.GPUSize32(vertexCount, {
+ prefix,
+ context: "Argument 1",
+ });
+ instanceCount = webidl.converters.GPUSize32(instanceCount, {
+ prefix,
+ context: "Argument 2",
+ });
+ firstVertex = webidl.converters.GPUSize32(firstVertex, {
+ prefix,
+ context: "Argument 3",
+ });
+ firstInstance = webidl.converters.GPUSize32(firstInstance, {
+ prefix,
+ context: "Argument 4",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_draw", {
+ renderPassRid,
+ vertexCount,
+ instanceCount,
+ firstVertex,
+ firstInstance,
+ });
+ }
+
+ /**
+ * @param {number} indexCount
+ * @param {number} instanceCount
+ * @param {number} firstIndex
+ * @param {number} baseVertex
+ * @param {number} firstInstance
+ */
+ drawIndexed(
+ indexCount,
+ instanceCount = 1,
+ firstIndex = 0,
+ baseVertex = 0,
+ firstInstance = 0,
+ ) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'drawIndexed' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ indexCount = webidl.converters.GPUSize32(indexCount, {
+ prefix,
+ context: "Argument 1",
+ });
+ instanceCount = webidl.converters.GPUSize32(instanceCount, {
+ prefix,
+ context: "Argument 2",
+ });
+ firstIndex = webidl.converters.GPUSize32(firstIndex, {
+ prefix,
+ context: "Argument 3",
+ });
+ baseVertex = webidl.converters.GPUSignedOffset32(baseVertex, {
+ prefix,
+ context: "Argument 4",
+ });
+ firstInstance = webidl.converters.GPUSize32(firstInstance, {
+ prefix,
+ context: "Argument 5",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_render_pass_draw_indexed", {
+ renderPassRid,
+ indexCount,
+ instanceCount,
+ firstIndex,
+ baseVertex,
+ firstInstance,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} indirectBuffer
+ * @param {number} indirectOffset
+ */
+ drawIndirect(indirectBuffer, indirectOffset) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'drawIndirect' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ indirectBuffer = webidl.converters.GPUBuffer(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indirectOffset = webidl.converters.GPUSize64(indirectOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const indirectBufferRid = assertResource(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, indirectBuffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_draw_indirect", {
+ renderPassRid,
+ indirectBuffer: indirectBufferRid,
+ indirectOffset,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} indirectBuffer
+ * @param {number} indirectOffset
+ */
+ drawIndexedIndirect(indirectBuffer, indirectOffset) {
+ webidl.assertBranded(this, GPURenderPassEncoder);
+ const prefix =
+ "Failed to execute 'drawIndirect' on 'GPURenderPassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ indirectBuffer = webidl.converters.GPUBuffer(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indirectOffset = webidl.converters.GPUSize64(indirectOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const renderPassRid = assertResource(this, { prefix, context: "this" });
+ const indirectBufferRid = assertResource(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, indirectBuffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_pass_draw_indexed_indirect", {
+ renderPassRid,
+ indirectBuffer: indirectBufferRid,
+ indirectOffset,
+ });
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPURenderPassEncoder", GPURenderPassEncoder);
+
+ /**
+ * @param {string | null} label
+ * @param {GPUCommandEncoder} encoder
+ * @param {number} rid
+ * @returns {GPUComputePassEncoder}
+ */
+ function createGPUComputePassEncoder(label, encoder, rid) {
+ /** @type {GPUComputePassEncoder} */
+ const computePassEncoder = webidl.createBranded(GPUComputePassEncoder);
+ computePassEncoder[_label] = label;
+ computePassEncoder[_encoder] = encoder;
+ computePassEncoder[_rid] = rid;
+ return computePassEncoder;
+ }
+
+ class GPUComputePassEncoder {
+ /** @type {GPUCommandEncoder} */
+ [_encoder];
+
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPUComputePipeline} pipeline
+ */
+ setPipeline(pipeline) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'setPipeline' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ pipeline = webidl.converters.GPUComputePipeline(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const pipelineRid = assertResource(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, pipeline, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_compute_pass_set_pipeline", {
+ computePassRid,
+ pipeline: pipelineRid,
+ });
+ }
+
+ /**
+ * @param {number} x
+ * @param {number} y
+ * @param {number} z
+ */
+ dispatch(x, y = 1, z = 1) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix = "Failed to execute 'dispatch' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ x = webidl.converters.GPUSize32(x, { prefix, context: "Argument 1" });
+ y = webidl.converters.GPUSize32(y, { prefix, context: "Argument 2" });
+ z = webidl.converters.GPUSize32(z, { prefix, context: "Argument 3" });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_compute_pass_dispatch", {
+ computePassRid,
+ x,
+ y,
+ z,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} indirectBuffer
+ * @param {number} indirectOffset
+ */
+ dispatchIndirect(indirectBuffer, indirectOffset) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'dispatchIndirect' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ indirectBuffer = webidl.converters.GPUBuffer(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indirectOffset = webidl.converters.GPUSize64(indirectOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const indirectBufferRid = assertResource(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, indirectBuffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_compute_pass_dispatch_indirect", {
+ computePassRid: computePassRid,
+ indirectBuffer: indirectBufferRid,
+ indirectOffset,
+ });
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} queryIndex
+ */
+ beginPipelineStatisticsQuery(querySet, queryIndex) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'beginPipelineStatisticsQuery' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ queryIndex = webidl.converters.GPUSize32(queryIndex, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync(
+ "op_webgpu_compute_pass_begin_pipeline_statistics_query",
+ {
+ computePassRid,
+ querySet: querySetRid,
+ queryIndex,
+ },
+ );
+ }
+
+ endPipelineStatisticsQuery() {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'endPipelineStatisticsQuery' on 'GPUComputePassEncoder'";
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_compute_pass_end_pipeline_statistics_query", {
+ computePassRid,
+ });
+ }
+
+ /**
+ * @param {GPUQuerySet} querySet
+ * @param {number} queryIndex
+ */
+ writeTimestamp(querySet, queryIndex) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'writeTimestamp' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ querySet = webidl.converters.GPUQuerySet(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ queryIndex = webidl.converters.GPUSize32(queryIndex, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const querySetRid = assertResource(querySet, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, querySet, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_compute_pass_write_timestamp", {
+ computePassRid,
+ querySet: querySetRid,
+ queryIndex,
+ });
+ }
+
+ endPass() {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix = "Failed to execute 'endPass' on 'GPUComputePassEncoder'";
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const commandEncoderRid = assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const { err } = core.jsonOpSync("op_webgpu_compute_pass_end_pass", {
+ commandEncoderRid,
+ computePassRid,
+ });
+ device.pushError(err);
+ this[_rid] = undefined;
+ }
+
+ // TODO(lucacasonato): has an overload
+ setBindGroup(
+ index,
+ bindGroup,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ ) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'";
+ const device = assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ const bindGroupRid = assertResource(bindGroup, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDeviceMatch(device, bindGroup, {
+ prefix,
+ resourceContext: "Argument 2",
+ selfContext: "this",
+ });
+ if (dynamicOffsetsData instanceof Uint32Array) {
+ core.jsonOpSync(
+ "op_webgpu_compute_pass_set_bind_group",
+ {
+ computePassRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ },
+ dynamicOffsetsData,
+ );
+ } else {
+ dynamicOffsetsData ??= [];
+ core.jsonOpSync("op_webgpu_compute_pass_set_bind_group", {
+ computePassRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart: 0,
+ dynamicOffsetsDataLength: dynamicOffsetsData.length,
+ });
+ }
+ }
+
+ /**
+ * @param {string} groupLabel
+ */
+ pushDebugGroup(groupLabel) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'pushDebugGroup' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ groupLabel = webidl.converters.USVString(groupLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_compute_pass_push_debug_group", {
+ computePassRid,
+ groupLabel,
+ });
+ }
+
+ popDebugGroup() {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'popDebugGroup' on 'GPUComputePassEncoder'";
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_compute_pass_pop_debug_group", {
+ computePassRid,
+ });
+ }
+
+ /**
+ * @param {string} markerLabel
+ */
+ insertDebugMarker(markerLabel) {
+ webidl.assertBranded(this, GPUComputePassEncoder);
+ const prefix =
+ "Failed to execute 'insertDebugMarker' on 'GPUComputePassEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ markerLabel = webidl.converters.USVString(markerLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ assertResource(this[_encoder], {
+ prefix,
+ context: "encoder referenced by this",
+ });
+ const computePassRid = assertResource(this, { prefix, context: "this" });
+ core.jsonOpSync("op_webgpu_compute_pass_insert_debug_marker", {
+ computePassRid,
+ markerLabel,
+ });
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUComputePassEncoder", GPUComputePassEncoder);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUCommandBuffer}
+ */
+ function createGPUCommandBuffer(label, device, rid) {
+ /** @type {GPUCommandBuffer} */
+ const commandBuffer = webidl.createBranded(GPUCommandBuffer);
+ commandBuffer[_label] = label;
+ commandBuffer[_device] = device;
+ commandBuffer[_rid] = rid;
+ return commandBuffer;
+ }
+
+ class GPUCommandBuffer {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ get executionTime() {
+ throw new Error("Not yet implemented");
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ // TODO(crowlKats): executionTime
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUCommandBuffer", GPUCommandBuffer);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPURenderBundleEncoder}
+ */
+ function createGPURenderBundleEncoder(label, device, rid) {
+ /** @type {GPURenderBundleEncoder} */
+ const bundleEncoder = webidl.createBranded(GPURenderBundleEncoder);
+ bundleEncoder[_label] = label;
+ bundleEncoder[_device] = device;
+ bundleEncoder[_rid] = rid;
+ return bundleEncoder;
+ }
+
+ class GPURenderBundleEncoder {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ /**
+ * @param {GPURenderBundleDescriptor} descriptor
+ */
+ finish(descriptor = {}) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix = "Failed to execute 'finish' on 'GPURenderBundleEncoder'";
+ descriptor = webidl.converters.GPURenderBundleDescriptor(descriptor, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const { rid, err } = core.jsonOpSync(
+ "op_webgpu_render_bundle_encoder_finish",
+ {
+ renderBundleEncoderRid,
+ ...descriptor,
+ },
+ );
+ device.pushError(err);
+ this[_rid] = undefined;
+
+ const renderBundle = createGPURenderBundle(
+ descriptor.label ?? null,
+ device,
+ rid,
+ );
+ device.trackResource((renderBundle));
+ return renderBundle;
+ }
+
+ // TODO(lucacasonato): has an overload
+ setBindGroup(
+ index,
+ bindGroup,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ ) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'setBindGroup' on 'GPURenderBundleEncoder'";
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const bindGroupRid = assertResource(bindGroup, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDeviceMatch(device, bindGroup, {
+ prefix,
+ resourceContext: "Argument 2",
+ selfContext: "this",
+ });
+ if (dynamicOffsetsData instanceof Uint32Array) {
+ core.jsonOpSync(
+ "op_webgpu_render_bundle_encoder_set_bind_group",
+ {
+ renderBundleEncoderRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsDataStart,
+ dynamicOffsetsDataLength,
+ },
+ dynamicOffsetsData,
+ );
+ } else {
+ dynamicOffsetsData ??= [];
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_set_bind_group", {
+ renderBundleEncoderRid,
+ index,
+ bindGroup: bindGroupRid,
+ dynamicOffsetsData,
+ dynamicOffsetsDataStart: 0,
+ dynamicOffsetsDataLength: dynamicOffsetsData.length,
+ });
+ }
+ }
+
+ /**
+ * @param {string} groupLabel
+ */
+ pushDebugGroup(groupLabel) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'pushDebugGroup' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ groupLabel = webidl.converters.USVString(groupLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", {
+ renderBundleEncoderRid,
+ groupLabel,
+ });
+ }
+
+ popDebugGroup() {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'popDebugGroup' on 'GPURenderBundleEncoder'";
+ assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_pop_debug_group", {
+ renderBundleEncoderRid,
+ });
+ }
+
+ /**
+ * @param {string} markerLabel
+ */
+ insertDebugMarker(markerLabel) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'insertDebugMarker' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ markerLabel = webidl.converters.USVString(markerLabel, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_push_debug_group", {
+ renderBundleEncoderRid,
+ markerLabel,
+ });
+ }
+
+ /**
+ * @param {GPURenderPipeline} pipeline
+ */
+ setPipeline(pipeline) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'setPipeline' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ pipeline = webidl.converters.GPURenderPipeline(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const pipelineRid = assertResource(pipeline, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, pipeline, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_set_pipeline", {
+ renderBundleEncoderRid,
+ pipeline: pipelineRid,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} buffer
+ * @param {GPUIndexFormat} indexFormat
+ * @param {number} offset
+ * @param {number} size
+ */
+ setIndexBuffer(buffer, indexFormat, offset = 0, size = 0) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'setIndexBuffer' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ buffer = webidl.converters.GPUBuffer(buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indexFormat = webidl.converters.GPUIndexFormat(indexFormat, {
+ prefix,
+ context: "Argument 2",
+ });
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 3",
+ });
+ size = webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 4",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const bufferRid = assertResource(buffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_set_index_buffer", {
+ renderBundleEncoderRid,
+ buffer: bufferRid,
+ indexFormat,
+ offset,
+ size,
+ });
+ }
+
+ /**
+ * @param {number} slot
+ * @param {GPUBuffer} buffer
+ * @param {number} offset
+ * @param {number} size
+ */
+ setVertexBuffer(slot, buffer, offset = 0, size = 0) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'setVertexBuffer' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ slot = webidl.converters.GPUSize32(slot, {
+ prefix,
+ context: "Argument 2",
+ });
+ buffer = webidl.converters.GPUBuffer(buffer, {
+ prefix,
+ context: "Argument 2",
+ });
+ offset = webidl.converters.GPUSize64(offset, {
+ prefix,
+ context: "Argument 3",
+ });
+ size = webidl.converters.GPUSize64(size, {
+ prefix,
+ context: "Argument 4",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const bufferRid = assertResource(buffer, {
+ prefix,
+ context: "Argument 2",
+ });
+ assertDeviceMatch(device, buffer, {
+ prefix,
+ resourceContext: "Argument 2",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", {
+ renderBundleEncoderRid,
+ slot,
+ buffer: bufferRid,
+ offset,
+ size,
+ });
+ }
+
+ /**
+ * @param {number} vertexCount
+ * @param {number} instanceCount
+ * @param {number} firstVertex
+ * @param {number} firstInstance
+ */
+ draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix = "Failed to execute 'draw' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ vertexCount = webidl.converters.GPUSize32(vertexCount, {
+ prefix,
+ context: "Argument 1",
+ });
+ instanceCount = webidl.converters.GPUSize32(instanceCount, {
+ prefix,
+ context: "Argument 2",
+ });
+ firstVertex = webidl.converters.GPUSize32(firstVertex, {
+ prefix,
+ context: "Argument 3",
+ });
+ firstInstance = webidl.converters.GPUSize32(firstInstance, {
+ prefix,
+ context: "Argument 4",
+ });
+ assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_draw", {
+ renderBundleEncoderRid,
+ vertexCount,
+ instanceCount,
+ firstVertex,
+ firstInstance,
+ });
+ }
+
+ /**
+ * @param {number} indexCount
+ * @param {number} instanceCount
+ * @param {number} firstIndex
+ * @param {number} baseVertex
+ * @param {number} firstInstance
+ */
+ drawIndexed(
+ indexCount,
+ instanceCount = 1,
+ firstIndex = 0,
+ baseVertex = 0,
+ firstInstance = 0,
+ ) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'drawIndexed' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ indexCount = webidl.converters.GPUSize32(indexCount, {
+ prefix,
+ context: "Argument 1",
+ });
+ instanceCount = webidl.converters.GPUSize32(instanceCount, {
+ prefix,
+ context: "Argument 2",
+ });
+ firstIndex = webidl.converters.GPUSize32(firstIndex, {
+ prefix,
+ context: "Argument 3",
+ });
+ baseVertex = webidl.converters.GPUSignedOffset32(baseVertex, {
+ prefix,
+ context: "Argument 4",
+ });
+ firstInstance = webidl.converters.GPUSize32(firstInstance, {
+ prefix,
+ context: "Argument 5",
+ });
+ assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indexed", {
+ renderBundleEncoderRid,
+ indexCount,
+ instanceCount,
+ firstIndex,
+ baseVertex,
+ firstInstance,
+ });
+ }
+
+ /**
+ * @param {GPUBuffer} indirectBuffer
+ * @param {number} indirectOffset
+ */
+ drawIndirect(indirectBuffer, indirectOffset) {
+ webidl.assertBranded(this, GPURenderBundleEncoder);
+ const prefix =
+ "Failed to execute 'drawIndirect' on 'GPURenderBundleEncoder'";
+ webidl.requiredArguments(arguments.length, 2, { prefix });
+ indirectBuffer = webidl.converters.GPUBuffer(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ indirectOffset = webidl.converters.GPUSize64(indirectOffset, {
+ prefix,
+ context: "Argument 2",
+ });
+ const device = assertDevice(this, { prefix, context: "this" });
+ const renderBundleEncoderRid = assertResource(this, {
+ prefix,
+ context: "this",
+ });
+ const indirectBufferRid = assertResource(indirectBuffer, {
+ prefix,
+ context: "Argument 1",
+ });
+ assertDeviceMatch(device, indirectBuffer, {
+ prefix,
+ resourceContext: "Argument 1",
+ selfContext: "this",
+ });
+ core.jsonOpSync("op_webgpu_render_bundle_encoder_draw_indirect", {
+ renderBundleEncoderRid,
+ indirectBuffer: indirectBufferRid,
+ indirectOffset,
+ });
+ }
+
+ drawIndexedIndirect(_indirectBuffer, _indirectOffset) {
+ throw new Error("Not yet implemented");
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPURenderBundleEncoder", GPURenderBundleEncoder);
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPURenderBundle}
+ */
+ function createGPURenderBundle(label, device, rid) {
+ /** @type {GPURenderBundle} */
+ const bundle = webidl.createBranded(GPURenderBundle);
+ bundle[_label] = label;
+ bundle[_device] = device;
+ bundle[_rid] = rid;
+ return bundle;
+ }
+
+ class GPURenderBundle {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPURenderBundle", GPURenderBundle);
+
+ const _descriptor = Symbol("[[descriptor]]");
+
+ /**
+ * @param {string | null} label
+ * @param {InnerGPUDevice} device
+ * @param {number} rid
+ * @returns {GPUQuerySet}
+ */
+ function createGPUQuerySet(label, device, rid, descriptor) {
+ /** @type {GPUQuerySet} */
+ const queue = webidl.createBranded(GPUQuerySet);
+ queue[_label] = label;
+ queue[_device] = device;
+ queue[_rid] = rid;
+ queue[_descriptor] = descriptor;
+ return queue;
+ }
+
+ class GPUQuerySet {
+ /** @type {InnerGPUDevice} */
+ [_device];
+ /** @type {number | undefined} */
+ [_rid];
+ /** @type {GPUQuerySetDescriptor} */
+ [_descriptor];
+
+ [_cleanup]() {
+ const rid = this[_rid];
+ if (rid !== undefined) {
+ core.close(rid);
+ /** @type {number | undefined} */
+ this[_rid] = undefined;
+ }
+ }
+
+ constructor() {
+ webidl.illegalConstructor();
+ }
+
+ destroy() {
+ webidl.assertBranded(this, GPUQuerySet);
+ this[_cleanup]();
+ }
+
+ [Symbol.for("Deno.customInspect")](inspect) {
+ return `${this.constructor.name} ${
+ inspect({
+ label: this.label,
+ })
+ }`;
+ }
+ }
+ GPUObjectBaseMixin("GPUQuerySet", GPUQuerySet);
+
+ window.__bootstrap.webgpu = {
+ gpu: webidl.createBranded(GPU),
+ GPU,
+ GPUAdapter,
+ GPUAdapterLimits,
+ GPUAdapterFeatures,
+ GPUDevice,
+ GPUQueue,
+ GPUBuffer,
+ GPUBufferUsage,
+ GPUMapMode,
+ GPUTextureUsage,
+ GPUTexture,
+ GPUTextureView,
+ GPUSampler,
+ GPUBindGroupLayout,
+ GPUPipelineLayout,
+ GPUBindGroup,
+ GPUShaderModule,
+ GPUShaderStage,
+ GPUComputePipeline,
+ GPURenderPipeline,
+ GPUColorWrite,
+ GPUCommandEncoder,
+ GPURenderPassEncoder,
+ GPUComputePassEncoder,
+ GPUCommandBuffer,
+ GPURenderBundleEncoder,
+ GPURenderBundle,
+ GPUQuerySet,
+ GPUOutOfMemoryError,
+ GPUValidationError,
+ };
+})(this);
diff --git a/op_crates/webgpu/02_idl_types.js b/op_crates/webgpu/02_idl_types.js
new file mode 100644
index 0000000000..68c3e32475
--- /dev/null
+++ b/op_crates/webgpu/02_idl_types.js
@@ -0,0 +1,1800 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// @ts-check
+///
+
+"use strict";
+
+((window) => {
+ const webidl = window.__bootstrap.webidl;
+ const {
+ GPU,
+ GPUAdapter,
+ GPUAdapterLimits,
+ GPUAdapterFeatures,
+ GPUDevice,
+ GPUQueue,
+ GPUBuffer,
+ GPUBufferUsage,
+ GPUMapMode,
+ GPUTextureUsage,
+ GPUTexture,
+ GPUTextureView,
+ GPUSampler,
+ GPUBindGroupLayout,
+ GPUPipelineLayout,
+ GPUBindGroup,
+ GPUShaderModule,
+ GPUShaderStage,
+ GPUComputePipeline,
+ GPURenderPipeline,
+ GPUColorWrite,
+ GPUCommandEncoder,
+ GPURenderPassEncoder,
+ GPUComputePassEncoder,
+ GPUCommandBuffer,
+ GPURenderBundleEncoder,
+ GPURenderBundle,
+ GPUQuerySet,
+ GPUOutOfMemoryError,
+ GPUValidationError,
+ } = window.__bootstrap.webgpu;
+
+ // This needs to be initalized after all of the base classes are implmented,
+ // otherwise their converters might not be available yet.
+
+ // DICTIONARY: GPUObjectDescriptorBase
+ const dictMembersGPUObjectDescriptorBase = [
+ { key: "label", converter: webidl.converters["USVString"] },
+ ];
+ webidl.converters["GPUObjectDescriptorBase"] = webidl
+ .createDictionaryConverter(
+ "GPUObjectDescriptorBase",
+ dictMembersGPUObjectDescriptorBase,
+ );
+
+ // INTERFACE: GPUAdapterLimits
+ webidl.converters.GPUAdapterLimits = webidl.createInterfaceConverter(
+ "GPUAdapterLimits",
+ GPUAdapterLimits,
+ );
+
+ // INTERFACE: GPUAdapterFeatures
+ webidl.converters.GPUAdapterFeatures = webidl.createInterfaceConverter(
+ "GPUAdapterFeatures",
+ GPUAdapterFeatures,
+ );
+
+ // INTERFACE: GPU
+ webidl.converters.GPU = webidl.createInterfaceConverter("GPU", GPU);
+
+ // ENUM: GPUPowerPreference
+ webidl.converters["GPUPowerPreference"] = webidl.createEnumConverter(
+ "GPUPowerPreference",
+ [
+ "low-power",
+ "high-performance",
+ ],
+ );
+
+ // DICTIONARY: GPURequestAdapterOptions
+ const dictMembersGPURequestAdapterOptions = [
+ {
+ key: "powerPreference",
+ converter: webidl.converters["GPUPowerPreference"],
+ },
+ ];
+ webidl.converters["GPURequestAdapterOptions"] = webidl
+ .createDictionaryConverter(
+ "GPURequestAdapterOptions",
+ dictMembersGPURequestAdapterOptions,
+ );
+
+ // INTERFACE: GPUAdapter
+ webidl.converters.GPUAdapter = webidl.createInterfaceConverter(
+ "GPUAdapter",
+ GPUAdapter,
+ );
+
+ // ENUM: GPUFeatureName
+ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter(
+ "GPUFeatureName",
+ [
+ "depth-clamping",
+ "depth24unorm-stencil8",
+ "depth32float-stencil8",
+ "pipeline-statistics-query",
+ "texture-compression-bc",
+ "timestamp-query",
+ ],
+ );
+
+ // DICTIONARY: GPUDeviceDescriptor
+ const dictMembersGPUDeviceDescriptor = [
+ {
+ key: "nonGuaranteedFeatures",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUFeatureName"],
+ ),
+ defaultValue: [],
+ },
+ {
+ key: "nonGuaranteedLimits",
+ converter: webidl.converters.any,
+ defaultValue: {},
+ },
+ ];
+ webidl.converters["GPUDeviceDescriptor"] = webidl.createDictionaryConverter(
+ "GPUDeviceDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUDeviceDescriptor,
+ );
+
+ // INTERFACE: GPUDevice
+ webidl.converters.GPUDevice = webidl.createInterfaceConverter(
+ "GPUDevice",
+ GPUDevice,
+ );
+
+ // INTERFACE: GPUBuffer
+ webidl.converters.GPUBuffer = webidl.createInterfaceConverter(
+ "GPUBuffer",
+ GPUBuffer,
+ );
+
+ // TYPEDEF: GPUSize64
+ webidl.converters["GPUSize64"] = (V, opts) =>
+ webidl.converters["unsigned long long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUBufferUsageFlags
+ webidl.converters["GPUBufferUsageFlags"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // DICTIONARY: GPUBufferDescriptor
+ const dictMembersGPUBufferDescriptor = [
+ { key: "size", converter: webidl.converters["GPUSize64"], required: true },
+ {
+ key: "usage",
+ converter: webidl.converters["GPUBufferUsageFlags"],
+ required: true,
+ },
+ {
+ key: "mappedAtCreation",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPUBufferDescriptor"] = webidl.createDictionaryConverter(
+ "GPUBufferDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUBufferDescriptor,
+ );
+
+ // INTERFACE: GPUBufferUsage
+ webidl.converters.GPUBufferUsage = webidl.createInterfaceConverter(
+ "GPUBufferUsage",
+ GPUBufferUsage,
+ );
+
+ // TYPEDEF: GPUMapModeFlags
+ webidl.converters["GPUMapModeFlags"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // INTERFACE: GPUMapMode
+ webidl.converters.GPUMapMode = webidl.createInterfaceConverter(
+ "GPUMapMode",
+ GPUMapMode,
+ );
+
+ // INTERFACE: GPUTexture
+ webidl.converters.GPUTexture = webidl.createInterfaceConverter(
+ "GPUTexture",
+ GPUTexture,
+ );
+
+ // TYPEDEF: GPUExtent3D
+ webidl.converters["GPUExtent3D"] = webidl.converters.any;
+
+ // TYPEDEF: GPUIntegerCoordinate
+ webidl.converters["GPUIntegerCoordinate"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUSize32
+ webidl.converters["GPUSize32"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // ENUM: GPUTextureDimension
+ webidl.converters["GPUTextureDimension"] = webidl.createEnumConverter(
+ "GPUTextureDimension",
+ [
+ "1d",
+ "2d",
+ "3d",
+ ],
+ );
+
+ // ENUM: GPUTextureFormat
+ webidl.converters["GPUTextureFormat"] = webidl.createEnumConverter(
+ "GPUTextureFormat",
+ [
+ "r8unorm",
+ "r8snorm",
+ "r8uint",
+ "r8sint",
+ "r16uint",
+ "r16sint",
+ "r16float",
+ "rg8unorm",
+ "rg8snorm",
+ "rg8uint",
+ "rg8sint",
+ "r32uint",
+ "r32sint",
+ "r32float",
+ "rg16uint",
+ "rg16sint",
+ "rg16float",
+ "rgba8unorm",
+ "rgba8unorm-srgb",
+ "rgba8snorm",
+ "rgba8uint",
+ "rgba8sint",
+ "bgra8unorm",
+ "bgra8unorm-srgb",
+ "rgb9e5ufloat",
+ "rgb10a2unorm",
+ "rg11b10ufloat",
+ "rg32uint",
+ "rg32sint",
+ "rg32float",
+ "rgba16uint",
+ "rgba16sint",
+ "rgba16float",
+ "rgba32uint",
+ "rgba32sint",
+ "rgba32float",
+ "stencil8",
+ "depth16unorm",
+ "depth24plus",
+ "depth24plus-stencil8",
+ "depth32float",
+ "bc1-rgba-unorm",
+ "bc1-rgba-unorm-srgb",
+ "bc2-rgba-unorm",
+ "bc2-rgba-unorm-srgb",
+ "bc3-rgba-unorm",
+ "bc3-rgba-unorm-srgb",
+ "bc4-r-unorm",
+ "bc4-r-snorm",
+ "bc5-rg-unorm",
+ "bc5-rg-snorm",
+ "bc6h-rgb-ufloat",
+ "bc6h-rgb-float",
+ "bc7-rgba-unorm",
+ "bc7-rgba-unorm-srgb",
+ "depth24unorm-stencil8",
+ "depth32float-stencil8",
+ ],
+ );
+
+ // TYPEDEF: GPUTextureUsageFlags
+ webidl.converters["GPUTextureUsageFlags"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // DICTIONARY: GPUTextureDescriptor
+ const dictMembersGPUTextureDescriptor = [
+ {
+ key: "size",
+ converter: webidl.converters["GPUExtent3D"],
+ required: true,
+ },
+ {
+ key: "mipLevelCount",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 1,
+ },
+ {
+ key: "sampleCount",
+ converter: webidl.converters["GPUSize32"],
+ defaultValue: 1,
+ },
+ {
+ key: "dimension",
+ converter: webidl.converters["GPUTextureDimension"],
+ defaultValue: "2d",
+ },
+ {
+ key: "format",
+ converter: webidl.converters["GPUTextureFormat"],
+ required: true,
+ },
+ {
+ key: "usage",
+ converter: webidl.converters["GPUTextureUsageFlags"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUTextureDescriptor"] = webidl.createDictionaryConverter(
+ "GPUTextureDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUTextureDescriptor,
+ );
+
+ // INTERFACE: GPUTextureUsage
+ webidl.converters.GPUTextureUsage = webidl.createInterfaceConverter(
+ "GPUTextureUsage",
+ GPUTextureUsage,
+ );
+
+ // INTERFACE: GPUTextureView
+ webidl.converters.GPUTextureView = webidl.createInterfaceConverter(
+ "GPUTextureView",
+ GPUTextureView,
+ );
+
+ // ENUM: GPUTextureViewDimension
+ webidl.converters["GPUTextureViewDimension"] = webidl.createEnumConverter(
+ "GPUTextureViewDimension",
+ [
+ "1d",
+ "2d",
+ "2d-array",
+ "cube",
+ "cube-array",
+ "3d",
+ ],
+ );
+
+ // ENUM: GPUTextureAspect
+ webidl.converters["GPUTextureAspect"] = webidl.createEnumConverter(
+ "GPUTextureAspect",
+ [
+ "all",
+ "stencil-only",
+ "depth-only",
+ ],
+ );
+
+ // DICTIONARY: GPUTextureViewDescriptor
+ const dictMembersGPUTextureViewDescriptor = [
+ { key: "format", converter: webidl.converters["GPUTextureFormat"] },
+ {
+ key: "dimension",
+ converter: webidl.converters["GPUTextureViewDimension"],
+ },
+ {
+ key: "aspect",
+ converter: webidl.converters["GPUTextureAspect"],
+ defaultValue: "all",
+ },
+ {
+ key: "baseMipLevel",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "mipLevelCount",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ },
+ {
+ key: "baseArrayLayer",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "arrayLayerCount",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ },
+ ];
+ webidl.converters["GPUTextureViewDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUTextureViewDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUTextureViewDescriptor,
+ );
+
+ // INTERFACE: GPUSampler
+ webidl.converters.GPUSampler = webidl.createInterfaceConverter(
+ "GPUSampler",
+ GPUSampler,
+ );
+
+ // ENUM: GPUAddressMode
+ webidl.converters["GPUAddressMode"] = webidl.createEnumConverter(
+ "GPUAddressMode",
+ [
+ "clamp-to-edge",
+ "repeat",
+ "mirror-repeat",
+ ],
+ );
+
+ // ENUM: GPUFilterMode
+ webidl.converters["GPUFilterMode"] = webidl.createEnumConverter(
+ "GPUFilterMode",
+ [
+ "nearest",
+ "linear",
+ ],
+ );
+
+ // ENUM: GPUCompareFunction
+ webidl.converters["GPUCompareFunction"] = webidl.createEnumConverter(
+ "GPUCompareFunction",
+ [
+ "never",
+ "less",
+ "equal",
+ "less-equal",
+ "greater",
+ "not-equal",
+ "greater-equal",
+ "always",
+ ],
+ );
+
+ // DICTIONARY: GPUSamplerDescriptor
+ const dictMembersGPUSamplerDescriptor = [
+ {
+ key: "addressModeU",
+ converter: webidl.converters["GPUAddressMode"],
+ defaultValue: "clamp-to-edge",
+ },
+ {
+ key: "addressModeV",
+ converter: webidl.converters["GPUAddressMode"],
+ defaultValue: "clamp-to-edge",
+ },
+ {
+ key: "addressModeW",
+ converter: webidl.converters["GPUAddressMode"],
+ defaultValue: "clamp-to-edge",
+ },
+ {
+ key: "magFilter",
+ converter: webidl.converters["GPUFilterMode"],
+ defaultValue: "nearest",
+ },
+ {
+ key: "minFilter",
+ converter: webidl.converters["GPUFilterMode"],
+ defaultValue: "nearest",
+ },
+ {
+ key: "mipmapFilter",
+ converter: webidl.converters["GPUFilterMode"],
+ defaultValue: "nearest",
+ },
+ {
+ key: "lodMinClamp",
+ converter: webidl.converters["float"],
+ defaultValue: 0,
+ },
+ {
+ key: "lodMaxClamp",
+ converter: webidl.converters["float"],
+ defaultValue: 0xffffffff,
+ },
+ { key: "compare", converter: webidl.converters["GPUCompareFunction"] },
+ {
+ key: "maxAnisotropy",
+ converter: (V, opts) =>
+ webidl.converters["unsigned short"](V, { ...opts, clamp: true }),
+ defaultValue: 1,
+ },
+ ];
+ webidl.converters["GPUSamplerDescriptor"] = webidl.createDictionaryConverter(
+ "GPUSamplerDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUSamplerDescriptor,
+ );
+
+ // INTERFACE: GPUBindGroupLayout
+ webidl.converters.GPUBindGroupLayout = webidl.createInterfaceConverter(
+ "GPUBindGroupLayout",
+ GPUBindGroupLayout,
+ );
+
+ // TYPEDEF: GPUIndex32
+ webidl.converters["GPUIndex32"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUShaderStageFlags
+ webidl.converters["GPUShaderStageFlags"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // ENUM: GPUBufferBindingType
+ webidl.converters["GPUBufferBindingType"] = webidl.createEnumConverter(
+ "GPUBufferBindingType",
+ [
+ "uniform",
+ "storage",
+ "read-only-storage",
+ ],
+ );
+
+ // DICTIONARY: GPUBufferBindingLayout
+ const dictMembersGPUBufferBindingLayout = [
+ {
+ key: "type",
+ converter: webidl.converters["GPUBufferBindingType"],
+ defaultValue: "uniform",
+ },
+ {
+ key: "hasDynamicOffset",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ {
+ key: "minBindingSize",
+ converter: webidl.converters["GPUSize64"],
+ defaultValue: 0,
+ },
+ ];
+ webidl.converters["GPUBufferBindingLayout"] = webidl
+ .createDictionaryConverter(
+ "GPUBufferBindingLayout",
+ dictMembersGPUBufferBindingLayout,
+ );
+
+ // ENUM: GPUSamplerBindingType
+ webidl.converters["GPUSamplerBindingType"] = webidl.createEnumConverter(
+ "GPUSamplerBindingType",
+ [
+ "filtering",
+ "non-filtering",
+ "comparison",
+ ],
+ );
+
+ // DICTIONARY: GPUSamplerBindingLayout
+ const dictMembersGPUSamplerBindingLayout = [
+ {
+ key: "type",
+ converter: webidl.converters["GPUSamplerBindingType"],
+ defaultValue: "filtering",
+ },
+ ];
+ webidl.converters["GPUSamplerBindingLayout"] = webidl
+ .createDictionaryConverter(
+ "GPUSamplerBindingLayout",
+ dictMembersGPUSamplerBindingLayout,
+ );
+
+ // ENUM: GPUTextureSampleType
+ webidl.converters["GPUTextureSampleType"] = webidl.createEnumConverter(
+ "GPUTextureSampleType",
+ [
+ "float",
+ "unfilterable-float",
+ "depth",
+ "sint",
+ "uint",
+ ],
+ );
+
+ // DICTIONARY: GPUTextureBindingLayout
+ const dictMembersGPUTextureBindingLayout = [
+ {
+ key: "sampleType",
+ converter: webidl.converters["GPUTextureSampleType"],
+ defaultValue: "float",
+ },
+ {
+ key: "viewDimension",
+ converter: webidl.converters["GPUTextureViewDimension"],
+ defaultValue: "2d",
+ },
+ {
+ key: "multisampled",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPUTextureBindingLayout"] = webidl
+ .createDictionaryConverter(
+ "GPUTextureBindingLayout",
+ dictMembersGPUTextureBindingLayout,
+ );
+
+ // ENUM: GPUStorageTextureAccess
+ webidl.converters["GPUStorageTextureAccess"] = webidl.createEnumConverter(
+ "GPUStorageTextureAccess",
+ [
+ "read-only",
+ "write-only",
+ ],
+ );
+
+ // DICTIONARY: GPUStorageTextureBindingLayout
+ const dictMembersGPUStorageTextureBindingLayout = [
+ {
+ key: "access",
+ converter: webidl.converters["GPUStorageTextureAccess"],
+ required: true,
+ },
+ {
+ key: "format",
+ converter: webidl.converters["GPUTextureFormat"],
+ required: true,
+ },
+ {
+ key: "viewDimension",
+ converter: webidl.converters["GPUTextureViewDimension"],
+ defaultValue: "2d",
+ },
+ ];
+ webidl.converters["GPUStorageTextureBindingLayout"] = webidl
+ .createDictionaryConverter(
+ "GPUStorageTextureBindingLayout",
+ dictMembersGPUStorageTextureBindingLayout,
+ );
+
+ // DICTIONARY: GPUBindGroupLayoutEntry
+ const dictMembersGPUBindGroupLayoutEntry = [
+ {
+ key: "binding",
+ converter: webidl.converters["GPUIndex32"],
+ required: true,
+ },
+ {
+ key: "visibility",
+ converter: webidl.converters["GPUShaderStageFlags"],
+ required: true,
+ },
+ { key: "buffer", converter: webidl.converters["GPUBufferBindingLayout"] },
+ { key: "sampler", converter: webidl.converters["GPUSamplerBindingLayout"] },
+ { key: "texture", converter: webidl.converters["GPUTextureBindingLayout"] },
+ {
+ key: "storageTexture",
+ converter: webidl.converters["GPUStorageTextureBindingLayout"],
+ },
+ ];
+ webidl.converters["GPUBindGroupLayoutEntry"] = webidl
+ .createDictionaryConverter(
+ "GPUBindGroupLayoutEntry",
+ dictMembersGPUBindGroupLayoutEntry,
+ );
+
+ // DICTIONARY: GPUBindGroupLayoutDescriptor
+ const dictMembersGPUBindGroupLayoutDescriptor = [
+ {
+ key: "entries",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUBindGroupLayoutEntry"],
+ ),
+ required: true,
+ },
+ ];
+ webidl.converters["GPUBindGroupLayoutDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUBindGroupLayoutDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUBindGroupLayoutDescriptor,
+ );
+
+ // INTERFACE: GPUShaderStage
+ webidl.converters.GPUShaderStage = webidl.createInterfaceConverter(
+ "GPUShaderStage",
+ GPUShaderStage,
+ );
+
+ // INTERFACE: GPUBindGroup
+ webidl.converters.GPUBindGroup = webidl.createInterfaceConverter(
+ "GPUBindGroup",
+ GPUBindGroup,
+ );
+
+ // TYPEDEF: GPUBindingResource
+ webidl.converters["GPUBindingResource"] = webidl.converters.any;
+
+ // DICTIONARY: GPUBindGroupEntry
+ const dictMembersGPUBindGroupEntry = [
+ {
+ key: "binding",
+ converter: webidl.converters["GPUIndex32"],
+ required: true,
+ },
+ {
+ key: "resource",
+ converter: webidl.converters["GPUBindingResource"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUBindGroupEntry"] = webidl.createDictionaryConverter(
+ "GPUBindGroupEntry",
+ dictMembersGPUBindGroupEntry,
+ );
+
+ // DICTIONARY: GPUBindGroupDescriptor
+ const dictMembersGPUBindGroupDescriptor = [
+ {
+ key: "layout",
+ converter: webidl.converters["GPUBindGroupLayout"],
+ required: true,
+ },
+ {
+ key: "entries",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUBindGroupEntry"],
+ ),
+ required: true,
+ },
+ ];
+ webidl.converters["GPUBindGroupDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUBindGroupDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUBindGroupDescriptor,
+ );
+
+ // DICTIONARY: GPUBufferBinding
+ const dictMembersGPUBufferBinding = [
+ {
+ key: "buffer",
+ converter: webidl.converters["GPUBuffer"],
+ required: true,
+ },
+ {
+ key: "offset",
+ converter: webidl.converters["GPUSize64"],
+ defaultValue: 0,
+ },
+ { key: "size", converter: webidl.converters["GPUSize64"] },
+ ];
+ webidl.converters["GPUBufferBinding"] = webidl.createDictionaryConverter(
+ "GPUBufferBinding",
+ dictMembersGPUBufferBinding,
+ );
+
+ // INTERFACE: GPUPipelineLayout
+ webidl.converters.GPUPipelineLayout = webidl.createInterfaceConverter(
+ "GPUPipelineLayout",
+ GPUPipelineLayout,
+ );
+
+ // DICTIONARY: GPUPipelineLayoutDescriptor
+ const dictMembersGPUPipelineLayoutDescriptor = [
+ {
+ key: "bindGroupLayouts",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUBindGroupLayout"],
+ ),
+ required: true,
+ },
+ ];
+ webidl.converters["GPUPipelineLayoutDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUPipelineLayoutDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUPipelineLayoutDescriptor,
+ );
+
+ // ENUM: GPUCompilationMessageType
+ webidl.converters["GPUCompilationMessageType"] = webidl.createEnumConverter(
+ "GPUCompilationMessageType",
+ [
+ "error",
+ "warning",
+ "info",
+ ],
+ );
+
+ // // INTERFACE: GPUCompilationMessage
+ // webidl.converters.GPUCompilationMessage = webidl.createInterfaceConverter(
+ // "GPUCompilationMessage",
+ // GPUCompilationMessage,
+ // );
+
+ // // INTERFACE: GPUCompilationInfo
+ // webidl.converters.GPUCompilationInfo = webidl.createInterfaceConverter(
+ // "GPUCompilationInfo",
+ // GPUCompilationInfo,
+ // );
+
+ // INTERFACE: GPUShaderModule
+ webidl.converters.GPUShaderModule = webidl.createInterfaceConverter(
+ "GPUShaderModule",
+ GPUShaderModule,
+ );
+
+ // DICTIONARY: GPUShaderModuleDescriptor
+ const dictMembersGPUShaderModuleDescriptor = [
+ { key: "code", converter: webidl.converters["USVString"], required: true },
+ { key: "sourceMap", converter: webidl.converters["object"] },
+ ];
+ webidl.converters["GPUShaderModuleDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUShaderModuleDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUShaderModuleDescriptor,
+ );
+
+ // DICTIONARY: GPUPipelineDescriptorBase
+ const dictMembersGPUPipelineDescriptorBase = [
+ { key: "layout", converter: webidl.converters["GPUPipelineLayout"] },
+ ];
+ webidl.converters["GPUPipelineDescriptorBase"] = webidl
+ .createDictionaryConverter(
+ "GPUPipelineDescriptorBase",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUPipelineDescriptorBase,
+ );
+
+ // DICTIONARY: GPUProgrammableStage
+ const dictMembersGPUProgrammableStage = [
+ {
+ key: "module",
+ converter: webidl.converters["GPUShaderModule"],
+ required: true,
+ },
+ {
+ key: "entryPoint",
+ converter: webidl.converters["USVString"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUProgrammableStage"] = webidl.createDictionaryConverter(
+ "GPUProgrammableStage",
+ dictMembersGPUProgrammableStage,
+ );
+
+ // INTERFACE: GPUComputePipeline
+ webidl.converters.GPUComputePipeline = webidl.createInterfaceConverter(
+ "GPUComputePipeline",
+ GPUComputePipeline,
+ );
+
+ // DICTIONARY: GPUComputePipelineDescriptor
+ const dictMembersGPUComputePipelineDescriptor = [
+ {
+ key: "compute",
+ converter: webidl.converters["GPUProgrammableStage"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUComputePipelineDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUComputePipelineDescriptor",
+ dictMembersGPUPipelineDescriptorBase,
+ dictMembersGPUComputePipelineDescriptor,
+ );
+
+ // INTERFACE: GPURenderPipeline
+ webidl.converters.GPURenderPipeline = webidl.createInterfaceConverter(
+ "GPURenderPipeline",
+ GPURenderPipeline,
+ );
+
+ // ENUM: GPUInputStepMode
+ webidl.converters["GPUInputStepMode"] = webidl.createEnumConverter(
+ "GPUInputStepMode",
+ [
+ "vertex",
+ "instance",
+ ],
+ );
+
+ // ENUM: GPUVertexFormat
+ webidl.converters["GPUVertexFormat"] = webidl.createEnumConverter(
+ "GPUVertexFormat",
+ [
+ "uchar2",
+ "uchar4",
+ "char2",
+ "char4",
+ "uchar2norm",
+ "uchar4norm",
+ "char2norm",
+ "char4norm",
+ "ushort2",
+ "ushort4",
+ "short2",
+ "short4",
+ "ushort2norm",
+ "ushort4norm",
+ "short2norm",
+ "short4norm",
+ "half2",
+ "half4",
+ "float",
+ "float2",
+ "float3",
+ "float4",
+ "uint",
+ "uint2",
+ "uint3",
+ "uint4",
+ "int",
+ "int2",
+ "int3",
+ "int4",
+ ],
+ );
+
+ // DICTIONARY: GPUVertexAttribute
+ const dictMembersGPUVertexAttribute = [
+ {
+ key: "format",
+ converter: webidl.converters["GPUVertexFormat"],
+ required: true,
+ },
+ {
+ key: "offset",
+ converter: webidl.converters["GPUSize64"],
+ required: true,
+ },
+ {
+ key: "shaderLocation",
+ converter: webidl.converters["GPUIndex32"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUVertexAttribute"] = webidl.createDictionaryConverter(
+ "GPUVertexAttribute",
+ dictMembersGPUVertexAttribute,
+ );
+
+ // DICTIONARY: GPUVertexBufferLayout
+ const dictMembersGPUVertexBufferLayout = [
+ {
+ key: "arrayStride",
+ converter: webidl.converters["GPUSize64"],
+ required: true,
+ },
+ {
+ key: "stepMode",
+ converter: webidl.converters["GPUInputStepMode"],
+ defaultValue: "vertex",
+ },
+ {
+ key: "attributes",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUVertexAttribute"],
+ ),
+ required: true,
+ },
+ ];
+ webidl.converters["GPUVertexBufferLayout"] = webidl.createDictionaryConverter(
+ "GPUVertexBufferLayout",
+ dictMembersGPUVertexBufferLayout,
+ );
+
+ // DICTIONARY: GPUVertexState
+ const dictMembersGPUVertexState = [
+ {
+ key: "buffers",
+ converter: webidl.createSequenceConverter(
+ webidl.createNullableConverter(
+ webidl.converters["GPUVertexBufferLayout"],
+ ),
+ ),
+ defaultValue: [],
+ },
+ ];
+ webidl.converters["GPUVertexState"] = webidl.createDictionaryConverter(
+ "GPUVertexState",
+ dictMembersGPUProgrammableStage,
+ dictMembersGPUVertexState,
+ );
+
+ // ENUM: GPUPrimitiveTopology
+ webidl.converters["GPUPrimitiveTopology"] = webidl.createEnumConverter(
+ "GPUPrimitiveTopology",
+ [
+ "point-list",
+ "line-list",
+ "line-strip",
+ "triangle-list",
+ "triangle-strip",
+ ],
+ );
+
+ // ENUM: GPUIndexFormat
+ webidl.converters["GPUIndexFormat"] = webidl.createEnumConverter(
+ "GPUIndexFormat",
+ [
+ "uint16",
+ "uint32",
+ ],
+ );
+
+ // ENUM: GPUFrontFace
+ webidl.converters["GPUFrontFace"] = webidl.createEnumConverter(
+ "GPUFrontFace",
+ [
+ "ccw",
+ "cw",
+ ],
+ );
+
+ // ENUM: GPUCullMode
+ webidl.converters["GPUCullMode"] = webidl.createEnumConverter("GPUCullMode", [
+ "none",
+ "front",
+ "back",
+ ]);
+
+ // DICTIONARY: GPUPrimitiveState
+ const dictMembersGPUPrimitiveState = [
+ {
+ key: "topology",
+ converter: webidl.converters["GPUPrimitiveTopology"],
+ defaultValue: "triangle-list",
+ },
+ { key: "stripIndexFormat", converter: webidl.converters["GPUIndexFormat"] },
+ {
+ key: "frontFace",
+ converter: webidl.converters["GPUFrontFace"],
+ defaultValue: "ccw",
+ },
+ {
+ key: "cullMode",
+ converter: webidl.converters["GPUCullMode"],
+ defaultValue: "none",
+ },
+ ];
+ webidl.converters["GPUPrimitiveState"] = webidl.createDictionaryConverter(
+ "GPUPrimitiveState",
+ dictMembersGPUPrimitiveState,
+ );
+
+ // ENUM: GPUStencilOperation
+ webidl.converters["GPUStencilOperation"] = webidl.createEnumConverter(
+ "GPUStencilOperation",
+ [
+ "keep",
+ "zero",
+ "replace",
+ "invert",
+ "increment-clamp",
+ "decrement-clamp",
+ "increment-wrap",
+ "decrement-wrap",
+ ],
+ );
+
+ // DICTIONARY: GPUStencilFaceState
+ const dictMembersGPUStencilFaceState = [
+ {
+ key: "compare",
+ converter: webidl.converters["GPUCompareFunction"],
+ defaultValue: "always",
+ },
+ {
+ key: "failOp",
+ converter: webidl.converters["GPUStencilOperation"],
+ defaultValue: "keep",
+ },
+ {
+ key: "depthFailOp",
+ converter: webidl.converters["GPUStencilOperation"],
+ defaultValue: "keep",
+ },
+ {
+ key: "passOp",
+ converter: webidl.converters["GPUStencilOperation"],
+ defaultValue: "keep",
+ },
+ ];
+ webidl.converters["GPUStencilFaceState"] = webidl.createDictionaryConverter(
+ "GPUStencilFaceState",
+ dictMembersGPUStencilFaceState,
+ );
+
+ // TYPEDEF: GPUStencilValue
+ webidl.converters["GPUStencilValue"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUDepthBias
+ webidl.converters["GPUDepthBias"] = (V, opts) =>
+ webidl.converters["long"](V, { ...opts, enforceRange: true });
+
+ // DICTIONARY: GPUDepthStencilState
+ const dictMembersGPUDepthStencilState = [
+ {
+ key: "format",
+ converter: webidl.converters["GPUTextureFormat"],
+ required: true,
+ },
+ {
+ key: "depthWriteEnabled",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ {
+ key: "depthCompare",
+ converter: webidl.converters["GPUCompareFunction"],
+ defaultValue: "always",
+ },
+ {
+ key: "stencilFront",
+ converter: webidl.converters["GPUStencilFaceState"],
+ defaultValue: {},
+ },
+ {
+ key: "stencilBack",
+ converter: webidl.converters["GPUStencilFaceState"],
+ defaultValue: {},
+ },
+ {
+ key: "stencilReadMask",
+ converter: webidl.converters["GPUStencilValue"],
+ defaultValue: 0xFFFFFFFF,
+ },
+ {
+ key: "stencilWriteMask",
+ converter: webidl.converters["GPUStencilValue"],
+ defaultValue: 0xFFFFFFFF,
+ },
+ {
+ key: "depthBias",
+ converter: webidl.converters["GPUDepthBias"],
+ defaultValue: 0,
+ },
+ {
+ key: "depthBiasSlopeScale",
+ converter: webidl.converters["float"],
+ defaultValue: 0,
+ },
+ {
+ key: "depthBiasClamp",
+ converter: webidl.converters["float"],
+ defaultValue: 0,
+ },
+ {
+ key: "clampDepth",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPUDepthStencilState"] = webidl.createDictionaryConverter(
+ "GPUDepthStencilState",
+ dictMembersGPUDepthStencilState,
+ );
+
+ // TYPEDEF: GPUSampleMask
+ webidl.converters["GPUSampleMask"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // DICTIONARY: GPUMultisampleState
+ const dictMembersGPUMultisampleState = [
+ {
+ key: "count",
+ converter: webidl.converters["GPUSize32"],
+ defaultValue: 1,
+ },
+ {
+ key: "mask",
+ converter: webidl.converters["GPUSampleMask"],
+ defaultValue: 0xFFFFFFFF,
+ },
+ {
+ key: "alphaToCoverageEnabled",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPUMultisampleState"] = webidl.createDictionaryConverter(
+ "GPUMultisampleState",
+ dictMembersGPUMultisampleState,
+ );
+
+ // ENUM: GPUBlendFactor
+ webidl.converters["GPUBlendFactor"] = webidl.createEnumConverter(
+ "GPUBlendFactor",
+ [
+ "zero",
+ "one",
+ "src-color",
+ "one-minus-src-color",
+ "src-alpha",
+ "one-minus-src-alpha",
+ "dst-color",
+ "one-minus-dst-color",
+ "dst-alpha",
+ "one-minus-dst-alpha",
+ "src-alpha-saturated",
+ "blend-color",
+ "one-minus-blend-color",
+ ],
+ );
+
+ // ENUM: GPUBlendOperation
+ webidl.converters["GPUBlendOperation"] = webidl.createEnumConverter(
+ "GPUBlendOperation",
+ [
+ "add",
+ "subtract",
+ "reverse-subtract",
+ "min",
+ "max",
+ ],
+ );
+
+ // DICTIONARY: GPUBlendComponent
+ const dictMembersGPUBlendComponent = [
+ {
+ key: "srcFactor",
+ converter: webidl.converters["GPUBlendFactor"],
+ defaultValue: "one",
+ },
+ {
+ key: "dstFactor",
+ converter: webidl.converters["GPUBlendFactor"],
+ defaultValue: "zero",
+ },
+ {
+ key: "operation",
+ converter: webidl.converters["GPUBlendOperation"],
+ defaultValue: "add",
+ },
+ ];
+ webidl.converters["GPUBlendComponent"] = webidl.createDictionaryConverter(
+ "GPUBlendComponent",
+ dictMembersGPUBlendComponent,
+ );
+
+ // DICTIONARY: GPUBlendState
+ const dictMembersGPUBlendState = [
+ {
+ key: "color",
+ converter: webidl.converters["GPUBlendComponent"],
+ required: true,
+ },
+ {
+ key: "alpha",
+ converter: webidl.converters["GPUBlendComponent"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUBlendState"] = webidl.createDictionaryConverter(
+ "GPUBlendState",
+ dictMembersGPUBlendState,
+ );
+
+ // TYPEDEF: GPUColorWriteFlags
+ webidl.converters["GPUColorWriteFlags"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // DICTIONARY: GPUColorTargetState
+ const dictMembersGPUColorTargetState = [
+ {
+ key: "format",
+ converter: webidl.converters["GPUTextureFormat"],
+ required: true,
+ },
+ { key: "blend", converter: webidl.converters["GPUBlendState"] },
+ {
+ key: "writeMask",
+ converter: webidl.converters["GPUColorWriteFlags"],
+ defaultValue: 0xF,
+ },
+ ];
+ webidl.converters["GPUColorTargetState"] = webidl.createDictionaryConverter(
+ "GPUColorTargetState",
+ dictMembersGPUColorTargetState,
+ );
+
+ // DICTIONARY: GPUFragmentState
+ const dictMembersGPUFragmentState = [
+ {
+ key: "targets",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUColorTargetState"],
+ ),
+ required: true,
+ },
+ ];
+ webidl.converters["GPUFragmentState"] = webidl.createDictionaryConverter(
+ "GPUFragmentState",
+ dictMembersGPUProgrammableStage,
+ dictMembersGPUFragmentState,
+ );
+
+ // DICTIONARY: GPURenderPipelineDescriptor
+ const dictMembersGPURenderPipelineDescriptor = [
+ {
+ key: "vertex",
+ converter: webidl.converters["GPUVertexState"],
+ required: true,
+ },
+ {
+ key: "primitive",
+ converter: webidl.converters["GPUPrimitiveState"],
+ defaultValue: {},
+ },
+ {
+ key: "depthStencil",
+ converter: webidl.converters["GPUDepthStencilState"],
+ },
+ {
+ key: "multisample",
+ converter: webidl.converters["GPUMultisampleState"],
+ defaultValue: {},
+ },
+ { key: "fragment", converter: webidl.converters["GPUFragmentState"] },
+ ];
+ webidl.converters["GPURenderPipelineDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPURenderPipelineDescriptor",
+ dictMembersGPUPipelineDescriptorBase,
+ dictMembersGPURenderPipelineDescriptor,
+ );
+
+ // INTERFACE: GPUColorWrite
+ webidl.converters.GPUColorWrite = webidl.createInterfaceConverter(
+ "GPUColorWrite",
+ GPUColorWrite,
+ );
+
+ // INTERFACE: GPUCommandBuffer
+ webidl.converters.GPUCommandBuffer = webidl.createInterfaceConverter(
+ "GPUCommandBuffer",
+ GPUCommandBuffer,
+ );
+
+ // DICTIONARY: GPUCommandBufferDescriptor
+ const dictMembersGPUCommandBufferDescriptor = [];
+ webidl.converters["GPUCommandBufferDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUCommandBufferDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUCommandBufferDescriptor,
+ );
+
+ // INTERFACE: GPUCommandEncoder
+ webidl.converters.GPUCommandEncoder = webidl.createInterfaceConverter(
+ "GPUCommandEncoder",
+ GPUCommandEncoder,
+ );
+
+ // DICTIONARY: GPUCommandEncoderDescriptor
+ const dictMembersGPUCommandEncoderDescriptor = [
+ {
+ key: "measureExecutionTime",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPUCommandEncoderDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUCommandEncoderDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUCommandEncoderDescriptor,
+ );
+
+ // DICTIONARY: GPUImageDataLayout
+ const dictMembersGPUImageDataLayout = [
+ {
+ key: "offset",
+ converter: webidl.converters["GPUSize64"],
+ defaultValue: 0,
+ },
+ { key: "bytesPerRow", converter: webidl.converters["GPUSize32"] },
+ { key: "rowsPerImage", converter: webidl.converters["GPUSize32"] },
+ ];
+ webidl.converters["GPUImageDataLayout"] = webidl.createDictionaryConverter(
+ "GPUImageDataLayout",
+ dictMembersGPUImageDataLayout,
+ );
+
+ // DICTIONARY: GPUImageCopyBuffer
+ const dictMembersGPUImageCopyBuffer = [
+ {
+ key: "buffer",
+ converter: webidl.converters["GPUBuffer"],
+ required: true,
+ },
+ ];
+ webidl.converters["GPUImageCopyBuffer"] = webidl.createDictionaryConverter(
+ "GPUImageCopyBuffer",
+ dictMembersGPUImageDataLayout,
+ dictMembersGPUImageCopyBuffer,
+ );
+
+ // TYPEDEF: GPUOrigin3D
+ webidl.converters["GPUOrigin3D"] = webidl.converters.any;
+
+ // DICTIONARY: GPUImageCopyTexture
+ const dictMembersGPUImageCopyTexture = [
+ {
+ key: "texture",
+ converter: webidl.converters["GPUTexture"],
+ required: true,
+ },
+ {
+ key: "mipLevel",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "origin",
+ converter: webidl.converters["GPUOrigin3D"],
+ defaultValue: {},
+ },
+ {
+ key: "aspect",
+ converter: webidl.converters["GPUTextureAspect"],
+ defaultValue: "all",
+ },
+ ];
+ webidl.converters["GPUImageCopyTexture"] = webidl.createDictionaryConverter(
+ "GPUImageCopyTexture",
+ dictMembersGPUImageCopyTexture,
+ );
+
+ // INTERFACE: GPUComputePassEncoder
+ webidl.converters.GPUComputePassEncoder = webidl.createInterfaceConverter(
+ "GPUComputePassEncoder",
+ GPUComputePassEncoder,
+ );
+
+ // DICTIONARY: GPUComputePassDescriptor
+ const dictMembersGPUComputePassDescriptor = [];
+ webidl.converters["GPUComputePassDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPUComputePassDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUComputePassDescriptor,
+ );
+
+ // INTERFACE: GPURenderPassEncoder
+ webidl.converters.GPURenderPassEncoder = webidl.createInterfaceConverter(
+ "GPURenderPassEncoder",
+ GPURenderPassEncoder,
+ );
+
+ // ENUM: GPUStoreOp
+ webidl.converters["GPUStoreOp"] = webidl.createEnumConverter("GPUStoreOp", [
+ "store",
+ "clear",
+ ]);
+
+ // DICTIONARY: GPURenderPassColorAttachment
+ const dictMembersGPURenderPassColorAttachment = [
+ {
+ key: "view",
+ converter: webidl.converters["GPUTextureView"],
+ required: true,
+ },
+ { key: "resolveTarget", converter: webidl.converters["GPUTextureView"] },
+ { key: "loadValue", converter: webidl.converters.any, required: true },
+ {
+ key: "storeOp",
+ converter: webidl.converters["GPUStoreOp"],
+ defaultValue: "store",
+ },
+ ];
+ webidl.converters["GPURenderPassColorAttachment"] = webidl
+ .createDictionaryConverter(
+ "GPURenderPassColorAttachment",
+ dictMembersGPURenderPassColorAttachment,
+ );
+
+ // DICTIONARY: GPURenderPassDepthStencilAttachment
+ const dictMembersGPURenderPassDepthStencilAttachment = [
+ {
+ key: "view",
+ converter: webidl.converters["GPUTextureView"],
+ required: true,
+ },
+ { key: "depthLoadValue", converter: webidl.converters.any, required: true },
+ {
+ key: "depthStoreOp",
+ converter: webidl.converters["GPUStoreOp"],
+ required: true,
+ },
+ {
+ key: "depthReadOnly",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ {
+ key: "stencilLoadValue",
+ converter: webidl.converters.any,
+ required: true,
+ },
+ {
+ key: "stencilStoreOp",
+ converter: webidl.converters["GPUStoreOp"],
+ required: true,
+ },
+ {
+ key: "stencilReadOnly",
+ converter: webidl.converters["boolean"],
+ defaultValue: false,
+ },
+ ];
+ webidl.converters["GPURenderPassDepthStencilAttachment"] = webidl
+ .createDictionaryConverter(
+ "GPURenderPassDepthStencilAttachment",
+ dictMembersGPURenderPassDepthStencilAttachment,
+ );
+
+ // INTERFACE: GPUQuerySet
+ webidl.converters.GPUQuerySet = webidl.createInterfaceConverter(
+ "GPUQuerySet",
+ GPUQuerySet,
+ );
+
+ // DICTIONARY: GPURenderPassDescriptor
+ const dictMembersGPURenderPassDescriptor = [
+ {
+ key: "colorAttachments",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPURenderPassColorAttachment"],
+ ),
+ required: true,
+ },
+ {
+ key: "depthStencilAttachment",
+ converter: webidl.converters["GPURenderPassDepthStencilAttachment"],
+ },
+ { key: "occlusionQuerySet", converter: webidl.converters["GPUQuerySet"] },
+ ];
+ webidl.converters["GPURenderPassDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPURenderPassDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPURenderPassDescriptor,
+ );
+
+ // ENUM: GPULoadOp
+ webidl.converters["GPULoadOp"] = webidl.createEnumConverter("GPULoadOp", [
+ "load",
+ ]);
+
+ // INTERFACE: GPURenderBundle
+ webidl.converters.GPURenderBundle = webidl.createInterfaceConverter(
+ "GPURenderBundle",
+ GPURenderBundle,
+ );
+
+ // DICTIONARY: GPURenderBundleDescriptor
+ const dictMembersGPURenderBundleDescriptor = [];
+ webidl.converters["GPURenderBundleDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPURenderBundleDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPURenderBundleDescriptor,
+ );
+
+ // INTERFACE: GPURenderBundleEncoder
+ webidl.converters.GPURenderBundleEncoder = webidl.createInterfaceConverter(
+ "GPURenderBundleEncoder",
+ GPURenderBundleEncoder,
+ );
+
+ // DICTIONARY: GPURenderBundleEncoderDescriptor
+ const dictMembersGPURenderBundleEncoderDescriptor = [
+ {
+ key: "colorFormats",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUTextureFormat"],
+ ),
+ required: true,
+ },
+ {
+ key: "depthStencilFormat",
+ converter: webidl.converters["GPUTextureFormat"],
+ },
+ {
+ key: "sampleCount",
+ converter: webidl.converters["GPUSize32"],
+ defaultValue: 1,
+ },
+ ];
+ webidl.converters["GPURenderBundleEncoderDescriptor"] = webidl
+ .createDictionaryConverter(
+ "GPURenderBundleEncoderDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPURenderBundleEncoderDescriptor,
+ );
+
+ // INTERFACE: GPUQueue
+ webidl.converters.GPUQueue = webidl.createInterfaceConverter(
+ "GPUQueue",
+ GPUQueue,
+ );
+
+ // ENUM: GPUQueryType
+ webidl.converters["GPUQueryType"] = webidl.createEnumConverter(
+ "GPUQueryType",
+ [
+ "occlusion",
+ "pipeline-statistics",
+ "timestamp",
+ ],
+ );
+
+ // ENUM: GPUPipelineStatisticName
+ webidl.converters["GPUPipelineStatisticName"] = webidl.createEnumConverter(
+ "GPUPipelineStatisticName",
+ [
+ "vertex-shader-invocations",
+ "clipper-invocations",
+ "clipper-primitives-out",
+ "fragment-shader-invocations",
+ "compute-shader-invocations",
+ ],
+ );
+
+ // DICTIONARY: GPUQuerySetDescriptor
+ const dictMembersGPUQuerySetDescriptor = [
+ {
+ key: "type",
+ converter: webidl.converters["GPUQueryType"],
+ required: true,
+ },
+ { key: "count", converter: webidl.converters["GPUSize32"], required: true },
+ {
+ key: "pipelineStatistics",
+ converter: webidl.createSequenceConverter(
+ webidl.converters["GPUPipelineStatisticName"],
+ ),
+ defaultValue: [],
+ },
+ ];
+ webidl.converters["GPUQuerySetDescriptor"] = webidl.createDictionaryConverter(
+ "GPUQuerySetDescriptor",
+ dictMembersGPUObjectDescriptorBase,
+ dictMembersGPUQuerySetDescriptor,
+ );
+
+ // ENUM: GPUDeviceLostReason
+ webidl.converters["GPUDeviceLostReason"] = webidl.createEnumConverter(
+ "GPUDeviceLostReason",
+ [
+ "destroyed",
+ ],
+ );
+
+ // // INTERFACE: GPUDeviceLostInfo
+ // webidl.converters.GPUDeviceLostInfo = webidl.createInterfaceConverter(
+ // "GPUDeviceLostInfo",
+ // GPUDeviceLostInfo,
+ // );
+
+ // ENUM: GPUErrorFilter
+ webidl.converters["GPUErrorFilter"] = webidl.createEnumConverter(
+ "GPUErrorFilter",
+ [
+ "out-of-memory",
+ "validation",
+ ],
+ );
+
+ // INTERFACE: GPUOutOfMemoryError
+ webidl.converters.GPUOutOfMemoryError = webidl.createInterfaceConverter(
+ "GPUOutOfMemoryError",
+ GPUOutOfMemoryError,
+ );
+
+ // INTERFACE: GPUValidationError
+ webidl.converters.GPUValidationError = webidl.createInterfaceConverter(
+ "GPUValidationError",
+ GPUValidationError,
+ );
+
+ // TYPEDEF: GPUError
+ webidl.converters["GPUError"] = webidl.converters.any;
+
+ // // INTERFACE: GPUUncapturedErrorEvent
+ // webidl.converters.GPUUncapturedErrorEvent = webidl.createInterfaceConverter(
+ // "GPUUncapturedErrorEvent",
+ // GPUUncapturedErrorEvent,
+ // );
+
+ // DICTIONARY: GPUUncapturedErrorEventInit
+ const dictMembersGPUUncapturedErrorEventInit = [
+ { key: "error", converter: webidl.converters["GPUError"], required: true },
+ ];
+ webidl.converters["GPUUncapturedErrorEventInit"] = webidl
+ .createDictionaryConverter(
+ "GPUUncapturedErrorEventInit",
+ // dictMembersEventInit,
+ dictMembersGPUUncapturedErrorEventInit,
+ );
+
+ // TYPEDEF: GPUBufferDynamicOffset
+ webidl.converters["GPUBufferDynamicOffset"] = (V, opts) =>
+ webidl.converters["unsigned long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUSignedOffset32
+ webidl.converters["GPUSignedOffset32"] = (V, opts) =>
+ webidl.converters["long"](V, { ...opts, enforceRange: true });
+
+ // TYPEDEF: GPUFlagsConstant
+ webidl.converters["GPUFlagsConstant"] = webidl.converters["unsigned long"];
+
+ // DICTIONARY: GPUColorDict
+ const dictMembersGPUColorDict = [
+ { key: "r", converter: webidl.converters["double"], required: true },
+ { key: "g", converter: webidl.converters["double"], required: true },
+ { key: "b", converter: webidl.converters["double"], required: true },
+ { key: "a", converter: webidl.converters["double"], required: true },
+ ];
+ webidl.converters["GPUColorDict"] = webidl.createDictionaryConverter(
+ "GPUColorDict",
+ dictMembersGPUColorDict,
+ );
+
+ // TYPEDEF: GPUColor
+ webidl.converters["GPUColor"] = webidl.converters.any;
+
+ // DICTIONARY: GPUOrigin2DDict
+ const dictMembersGPUOrigin2DDict = [
+ {
+ key: "x",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "y",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ ];
+ webidl.converters["GPUOrigin2DDict"] = webidl.createDictionaryConverter(
+ "GPUOrigin2DDict",
+ dictMembersGPUOrigin2DDict,
+ );
+
+ // TYPEDEF: GPUOrigin2D
+ webidl.converters["GPUOrigin2D"] = webidl.converters.any;
+
+ // DICTIONARY: GPUOrigin3DDict
+ const dictMembersGPUOrigin3DDict = [
+ {
+ key: "x",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "y",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ {
+ key: "z",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 0,
+ },
+ ];
+ webidl.converters["GPUOrigin3DDict"] = webidl.createDictionaryConverter(
+ "GPUOrigin3DDict",
+ dictMembersGPUOrigin3DDict,
+ );
+
+ // DICTIONARY: GPUExtent3DDict
+ const dictMembersGPUExtent3DDict = [
+ {
+ key: "width",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 1,
+ },
+ {
+ key: "height",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 1,
+ },
+ {
+ key: "depthOrArrayLayers",
+ converter: webidl.converters["GPUIntegerCoordinate"],
+ defaultValue: 1,
+ },
+ ];
+ webidl.converters["GPUExtent3DDict"] = webidl.createDictionaryConverter(
+ "GPUExtent3DDict",
+ dictMembersGPUExtent3DDict,
+ );
+
+ webidl.converters["sequence"] = webidl
+ .createSequenceConverter(webidl.converters["GPURenderBundle"]);
+ webidl.converters["sequence"] = webidl
+ .createSequenceConverter(webidl.converters["GPUCommandBuffer"]);
+ webidl.converters["UVString?"] = webidl.createNullableConverter(
+ webidl.converters.USVString,
+ );
+})(this);
diff --git a/op_crates/webgpu/Cargo.toml b/op_crates/webgpu/Cargo.toml
new file mode 100644
index 0000000000..92d9e01f34
--- /dev/null
+++ b/op_crates/webgpu/Cargo.toml
@@ -0,0 +1,21 @@
+# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+[package]
+name = "deno_webgpu"
+version = "0.1.0"
+edition = "2018"
+description = "provides webgpu Web API to deno_core"
+authors = ["the Deno authors"]
+license = "MIT"
+readme = "README.md"
+repository = "https://github.com/denoland/deno"
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+deno_core = { version = "0.79.0", path = "../../core" }
+tokio = { version = "1.1.1", features = ["full"] }
+serde = { version = "1.0.123", features = ["derive"] }
+wgpu-core = { version = "0.7.0", features = ["trace"] }
+wgpu-types = "0.7.0"
diff --git a/op_crates/webgpu/README.md b/op_crates/webgpu/README.md
new file mode 100644
index 0000000000..2f915dcbbe
--- /dev/null
+++ b/op_crates/webgpu/README.md
@@ -0,0 +1,35 @@
+# deno_webgpu
+
+This op crate implements the WebGPU API as defined in
+https://gpuweb.github.io/gpuweb/ in Deno. The implementation targets the spec
+draft as of February 22, 2021. The spec is still very much in flux. This op
+crate tries to stay up to date with the spec, but is constrained by the features
+implemented in our GPU backend library [wgpu](https://github.com/gfx-rs/wgpu).
+
+The spec is still very bare bones, and is still missing many details. As the
+spec becomes more concrete, we will implement to follow the spec more closely.
+
+In addition, setting the `DENO_WEBGPU_TRACE` environmental variable will output
+a
+[wgpu trace](https://github.com/gfx-rs/wgpu/wiki/Debugging-wgpu-Applications#tracing-infrastructure)
+to the specified directory.
+
+For testing this op crate will make use of the WebGPU conformance tests suite,
+running through our WPT runner. This will be used to validate implementation
+conformance.
+
+GitHub CI doesn't run with GPUs, so testing relies on software like DX WARP &
+Vulkan lavapipe. Currently only using DX WARP works, so tests are only run on
+Windows.
+
+## Links
+
+Specification: https://gpuweb.github.io/gpuweb/
+
+Design documents: https://github.com/gpuweb/gpuweb/tree/main/design
+
+Conformance tests suite: https://github.com/gpuweb/cts
+
+WebGPU examples for Deno: https://github.com/crowlKats/webgpu-examples
+
+wgpu-users matrix channel: https://matrix.to/#/#wgpu-users:matrix.org
diff --git a/op_crates/webgpu/binding.rs b/op_crates/webgpu/binding.rs
new file mode 100644
index 0000000000..b93b223cf5
--- /dev/null
+++ b/op_crates/webgpu/binding.rs
@@ -0,0 +1,362 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
+use deno_core::serde_json::json;
+use deno_core::serde_json::Value;
+use deno_core::ZeroCopyBuf;
+use deno_core::{OpState, Resource};
+use serde::Deserialize;
+use std::borrow::Cow;
+
+use super::error::WebGPUError;
+
+pub(crate) struct WebGPUBindGroupLayout(
+ pub(crate) wgpu_core::id::BindGroupLayoutId,
+);
+impl Resource for WebGPUBindGroupLayout {
+ fn name(&self) -> Cow {
+ "webGPUBindGroupLayout".into()
+ }
+}
+
+pub(crate) struct WebGPUBindGroup(pub(crate) wgpu_core::id::BindGroupId);
+impl Resource for WebGPUBindGroup {
+ fn name(&self) -> Cow {
+ "webGPUBindGroup".into()
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUBufferBindingLayout {
+ #[serde(rename = "type")]
+ kind: Option,
+ has_dynamic_offset: Option,
+ min_binding_size: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUSamplerBindingLayout {
+ #[serde(rename = "type")]
+ kind: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUTextureBindingLayout {
+ sample_type: Option,
+ view_dimension: Option,
+ multisampled: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUStorageTextureBindingLayout {
+ access: String,
+ format: String,
+ view_dimension: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUBindGroupLayoutEntry {
+ binding: u32,
+ visibility: u32,
+ buffer: Option,
+ sampler: Option,
+ texture: Option,
+ storage_texture: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateBindGroupLayoutArgs {
+ device_rid: u32,
+ label: Option,
+ entries: Vec,
+}
+
+pub fn op_webgpu_create_bind_group_layout(
+ state: &mut OpState,
+ args: CreateBindGroupLayoutArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let mut entries = vec![];
+
+ for entry in &args.entries {
+ entries.push(wgpu_types::BindGroupLayoutEntry {
+ binding: entry.binding,
+ visibility: wgpu_types::ShaderStage::from_bits(entry.visibility).unwrap(),
+ ty: if let Some(buffer) = &entry.buffer {
+ wgpu_types::BindingType::Buffer {
+ ty: match &buffer.kind {
+ Some(kind) => match kind.as_str() {
+ "uniform" => wgpu_types::BufferBindingType::Uniform,
+ "storage" => {
+ wgpu_types::BufferBindingType::Storage { read_only: false }
+ }
+ "read-only-storage" => {
+ wgpu_types::BufferBindingType::Storage { read_only: true }
+ }
+ _ => unreachable!(),
+ },
+ None => wgpu_types::BufferBindingType::Uniform,
+ },
+ has_dynamic_offset: buffer.has_dynamic_offset.unwrap_or(false),
+ min_binding_size: if let Some(min_binding_size) =
+ buffer.min_binding_size
+ {
+ std::num::NonZeroU64::new(min_binding_size)
+ } else {
+ None
+ },
+ }
+ } else if let Some(sampler) = &entry.sampler {
+ match &sampler.kind {
+ Some(kind) => match kind.as_str() {
+ "filtering" => wgpu_types::BindingType::Sampler {
+ filtering: true,
+ comparison: false,
+ },
+ "non-filtering" => wgpu_types::BindingType::Sampler {
+ filtering: false,
+ comparison: false,
+ },
+ "comparison" => wgpu_types::BindingType::Sampler {
+ filtering: false,
+ comparison: true,
+ },
+ _ => unreachable!(),
+ },
+ None => wgpu_types::BindingType::Sampler {
+ filtering: true,
+ comparison: false,
+ },
+ }
+ } else if let Some(texture) = &entry.texture {
+ wgpu_types::BindingType::Texture {
+ sample_type: match &texture.sample_type {
+ Some(sample_type) => match sample_type.as_str() {
+ "float" => {
+ wgpu_types::TextureSampleType::Float { filterable: true }
+ }
+ "unfilterable-float" => {
+ wgpu_types::TextureSampleType::Float { filterable: false }
+ }
+ "depth" => wgpu_types::TextureSampleType::Depth,
+ "sint" => wgpu_types::TextureSampleType::Sint,
+ "uint" => wgpu_types::TextureSampleType::Uint,
+ _ => unreachable!(),
+ },
+ None => wgpu_types::TextureSampleType::Float { filterable: true },
+ },
+ view_dimension: match &texture.view_dimension {
+ Some(view_dimension) => {
+ super::texture::serialize_dimension(view_dimension)
+ }
+ None => wgpu_types::TextureViewDimension::D2,
+ },
+ multisampled: texture.multisampled.unwrap_or(false),
+ }
+ } else if let Some(storage_texture) = &entry.storage_texture {
+ wgpu_types::BindingType::StorageTexture {
+ access: match storage_texture.access.as_str() {
+ "read-only" => wgpu_types::StorageTextureAccess::ReadOnly,
+ "write-only" => wgpu_types::StorageTextureAccess::WriteOnly,
+ _ => unreachable!(),
+ },
+ format: super::texture::serialize_texture_format(
+ &storage_texture.format,
+ )?,
+ view_dimension: match &storage_texture.view_dimension {
+ Some(view_dimension) => {
+ super::texture::serialize_dimension(view_dimension)
+ }
+ None => wgpu_types::TextureViewDimension::D2,
+ },
+ }
+ } else {
+ unreachable!()
+ },
+ count: None, // native-only
+ });
+ }
+
+ let descriptor = wgpu_core::binding_model::BindGroupLayoutDescriptor {
+ label: args.label.map(Cow::from),
+ entries: Cow::from(entries),
+ };
+
+ let (bind_group_layout, maybe_err) = gfx_select!(device => instance.device_create_bind_group_layout(
+ device,
+ &descriptor,
+ std::marker::PhantomData
+ ));
+
+ let rid = state
+ .resource_table
+ .add(WebGPUBindGroupLayout(bind_group_layout));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreatePipelineLayoutArgs {
+ device_rid: u32,
+ label: Option,
+ bind_group_layouts: Vec,
+}
+
+pub fn op_webgpu_create_pipeline_layout(
+ state: &mut OpState,
+ args: CreatePipelineLayoutArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let mut bind_group_layouts = vec![];
+
+ for rid in &args.bind_group_layouts {
+ let bind_group_layout = state
+ .resource_table
+ .get::(*rid)
+ .ok_or_else(bad_resource_id)?;
+ bind_group_layouts.push(bind_group_layout.0);
+ }
+
+ let descriptor = wgpu_core::binding_model::PipelineLayoutDescriptor {
+ label: args.label.map(Cow::from),
+ bind_group_layouts: Cow::from(bind_group_layouts),
+ push_constant_ranges: Default::default(),
+ };
+
+ let (pipeline_layout, maybe_err) = gfx_select!(device => instance.device_create_pipeline_layout(
+ device,
+ &descriptor,
+ std::marker::PhantomData
+ ));
+
+ let rid = state
+ .resource_table
+ .add(super::pipeline::WebGPUPipelineLayout(pipeline_layout));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPUBindGroupEntry {
+ binding: u32,
+ kind: String,
+ resource: u32,
+ offset: Option,
+ size: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateBindGroupArgs {
+ device_rid: u32,
+ label: Option,
+ layout: u32,
+ entries: Vec,
+}
+
+pub fn op_webgpu_create_bind_group(
+ state: &mut OpState,
+ args: CreateBindGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let mut entries = vec![];
+
+ for entry in &args.entries {
+ let e = wgpu_core::binding_model::BindGroupEntry {
+ binding: entry.binding,
+ resource: match entry.kind.as_str() {
+ "GPUSampler" => {
+ let sampler_resource = state
+ .resource_table
+ .get::(entry.resource)
+ .ok_or_else(bad_resource_id)?;
+ wgpu_core::binding_model::BindingResource::Sampler(sampler_resource.0)
+ }
+ "GPUTextureView" => {
+ let texture_view_resource = state
+ .resource_table
+ .get::(entry.resource)
+ .ok_or_else(bad_resource_id)?;
+ wgpu_core::binding_model::BindingResource::TextureView(
+ texture_view_resource.0,
+ )
+ }
+ "GPUBufferBinding" => {
+ let buffer_resource = state
+ .resource_table
+ .get::(entry.resource)
+ .ok_or_else(bad_resource_id)?;
+ wgpu_core::binding_model::BindingResource::Buffer(
+ wgpu_core::binding_model::BufferBinding {
+ buffer_id: buffer_resource.0,
+ offset: entry.offset.unwrap_or(0),
+ size: std::num::NonZeroU64::new(entry.size.unwrap_or(0)),
+ },
+ )
+ }
+ _ => unreachable!(),
+ },
+ };
+ entries.push(e);
+ }
+
+ let bind_group_layout = state
+ .resource_table
+ .get::(args.layout)
+ .ok_or_else(bad_resource_id)?;
+
+ let descriptor = wgpu_core::binding_model::BindGroupDescriptor {
+ label: args.label.map(Cow::from),
+ layout: bind_group_layout.0,
+ entries: Cow::from(entries),
+ };
+
+ let (bind_group, maybe_err) = gfx_select!(device => instance.device_create_bind_group(
+ device,
+ &descriptor,
+ std::marker::PhantomData
+ ));
+
+ let rid = state.resource_table.add(WebGPUBindGroup(bind_group));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
diff --git a/op_crates/webgpu/buffer.rs b/op_crates/webgpu/buffer.rs
new file mode 100644
index 0000000000..8ff9f31153
--- /dev/null
+++ b/op_crates/webgpu/buffer.rs
@@ -0,0 +1,243 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
+use deno_core::futures::channel::oneshot;
+use deno_core::serde_json::json;
+use deno_core::serde_json::Value;
+use deno_core::OpState;
+use deno_core::ZeroCopyBuf;
+use deno_core::{BufVec, Resource};
+use serde::Deserialize;
+use std::borrow::Cow;
+use std::cell::RefCell;
+use std::rc::Rc;
+use std::time::Duration;
+
+use super::error::DOMExceptionOperationError;
+use super::error::WebGPUError;
+
+pub(crate) struct WebGPUBuffer(pub(crate) wgpu_core::id::BufferId);
+impl Resource for WebGPUBuffer {
+ fn name(&self) -> Cow {
+ "webGPUBuffer".into()
+ }
+}
+
+struct WebGPUBufferMapped(*mut u8, usize);
+impl Resource for WebGPUBufferMapped {
+ fn name(&self) -> Cow {
+ "webGPUBufferMapped".into()
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateBufferArgs {
+ device_rid: u32,
+ label: Option,
+ size: u64,
+ usage: u32,
+ mapped_at_creation: Option,
+}
+
+pub fn op_webgpu_create_buffer(
+ state: &mut OpState,
+ args: CreateBufferArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let descriptor = wgpu_core::resource::BufferDescriptor {
+ label: args.label.map(Cow::from),
+ size: args.size,
+ usage: wgpu_types::BufferUsage::from_bits(args.usage).unwrap(),
+ mapped_at_creation: args.mapped_at_creation.unwrap_or(false),
+ };
+
+ let (buffer, maybe_err) = gfx_select!(device => instance.device_create_buffer(
+ device,
+ &descriptor,
+ std::marker::PhantomData
+ ));
+
+ let rid = state.resource_table.add(WebGPUBuffer(buffer));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BufferGetMapAsyncArgs {
+ buffer_rid: u32,
+ device_rid: u32,
+ mode: u32,
+ offset: u64,
+ size: u64,
+}
+
+pub async fn op_webgpu_buffer_get_map_async(
+ state: Rc>,
+ args: BufferGetMapAsyncArgs,
+ _bufs: BufVec,
+) -> Result {
+ let (sender, receiver) = oneshot::channel::>();
+
+ let device;
+ {
+ let state_ = state.borrow();
+ let instance = state_.borrow::();
+ let buffer_resource = state_
+ .resource_table
+ .get::(args.buffer_rid)
+ .ok_or_else(bad_resource_id)?;
+ let buffer = buffer_resource.0;
+ let device_resource = state_
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ device = device_resource.0;
+
+ let boxed_sender = Box::new(sender);
+ let sender_ptr = Box::into_raw(boxed_sender) as *mut u8;
+
+ extern "C" fn buffer_map_future_wrapper(
+ status: wgpu_core::resource::BufferMapAsyncStatus,
+ user_data: *mut u8,
+ ) {
+ let sender_ptr = user_data as *mut oneshot::Sender>;
+ let boxed_sender = unsafe { Box::from_raw(sender_ptr) };
+ boxed_sender
+ .send(match status {
+ wgpu_core::resource::BufferMapAsyncStatus::Success => Ok(()),
+ _ => unreachable!(), // TODO
+ })
+ .unwrap();
+ }
+
+ // TODO(lucacasonato): error handling
+ gfx_select!(buffer => instance.buffer_map_async(
+ buffer,
+ args.offset..(args.offset + args.size),
+ wgpu_core::resource::BufferMapOperation {
+ host: match args.mode {
+ 1 => wgpu_core::device::HostMap::Read,
+ 2 => wgpu_core::device::HostMap::Write,
+ _ => unreachable!(),
+ },
+ callback: buffer_map_future_wrapper,
+ user_data: sender_ptr,
+ }
+ ))?;
+ }
+
+ 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, false)).unwrap()
+ }
+ 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(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BufferGetMappedRangeArgs {
+ buffer_rid: u32,
+ offset: u64,
+ size: u64,
+}
+
+pub fn op_webgpu_buffer_get_mapped_range(
+ state: &mut OpState,
+ args: BufferGetMappedRangeArgs,
+ zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let buffer_resource = state
+ .resource_table
+ .get::(args.buffer_rid)
+ .ok_or_else(bad_resource_id)?;
+ let buffer = buffer_resource.0;
+
+ let slice_pointer = gfx_select!(buffer => instance.buffer_get_mapped_range(
+ buffer,
+ args.offset,
+ std::num::NonZeroU64::new(args.size)
+ ))
+ .map_err(|e| DOMExceptionOperationError::new(&e.to_string()))?;
+
+ let slice = unsafe {
+ std::slice::from_raw_parts_mut(slice_pointer, args.size as usize)
+ };
+ zero_copy[0].copy_from_slice(slice);
+
+ let rid = state
+ .resource_table
+ .add(WebGPUBufferMapped(slice_pointer, args.size as usize));
+
+ Ok(json!({
+ "rid": rid,
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BufferUnmapArgs {
+ buffer_rid: u32,
+ mapped_rid: u32,
+}
+
+pub fn op_webgpu_buffer_unmap(
+ state: &mut OpState,
+ args: BufferUnmapArgs,
+ zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let mapped_resource = state
+ .resource_table
+ .take::(args.mapped_rid)
+ .ok_or_else(bad_resource_id)?;
+ let instance = state.borrow::();
+ let buffer_resource = state
+ .resource_table
+ .get::(args.buffer_rid)
+ .ok_or_else(bad_resource_id)?;
+ let buffer = buffer_resource.0;
+
+ let slice_pointer = mapped_resource.0;
+ let size = mapped_resource.1;
+
+ if let Some(buffer) = zero_copy.get(0) {
+ let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, size) };
+ slice.copy_from_slice(&buffer);
+ }
+
+ let maybe_err = gfx_select!(buffer => instance.buffer_unmap(buffer)).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
diff --git a/op_crates/webgpu/bundle.rs b/op_crates/webgpu/bundle.rs
new file mode 100644
index 0000000000..7043b0a9e4
--- /dev/null
+++ b/op_crates/webgpu/bundle.rs
@@ -0,0 +1,465 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
+use deno_core::serde_json::json;
+use deno_core::serde_json::Value;
+use deno_core::ZeroCopyBuf;
+use deno_core::{OpState, Resource};
+use serde::Deserialize;
+use std::borrow::Cow;
+use std::cell::RefCell;
+use std::rc::Rc;
+
+use super::error::WebGPUError;
+use super::texture::serialize_texture_format;
+
+struct WebGPURenderBundleEncoder(
+ RefCell,
+);
+impl Resource for WebGPURenderBundleEncoder {
+ fn name(&self) -> Cow {
+ "webGPURenderBundleEncoder".into()
+ }
+}
+
+pub(crate) struct WebGPURenderBundle(pub(crate) wgpu_core::id::RenderBundleId);
+impl Resource for WebGPURenderBundle {
+ fn name(&self) -> Cow {
+ "webGPURenderBundle".into()
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateRenderBundleEncoderArgs {
+ device_rid: u32,
+ label: Option,
+ color_formats: Vec,
+ depth_stencil_format: Option,
+ sample_count: Option,
+}
+
+pub fn op_webgpu_create_render_bundle_encoder(
+ state: &mut OpState,
+ args: CreateRenderBundleEncoderArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let mut color_formats = vec![];
+
+ for format in &args.color_formats {
+ color_formats.push(serialize_texture_format(format)?);
+ }
+
+ let descriptor = wgpu_core::command::RenderBundleEncoderDescriptor {
+ label: args.label.map(Cow::from),
+ color_formats: Cow::from(color_formats),
+ depth_stencil_format: args
+ .depth_stencil_format
+ .map(|s| serialize_texture_format(&s))
+ .transpose()?,
+ sample_count: args.sample_count.unwrap_or(1),
+ };
+
+ let res =
+ wgpu_core::command::RenderBundleEncoder::new(&descriptor, device, None);
+ let (render_bundle_encoder, maybe_err) = match res {
+ Ok(encoder) => (encoder, None),
+ Err(e) => (
+ wgpu_core::command::RenderBundleEncoder::dummy(device),
+ Some(e),
+ ),
+ };
+
+ let rid = state
+ .resource_table
+ .add(WebGPURenderBundleEncoder(RefCell::new(
+ render_bundle_encoder,
+ )));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from),
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderFinishArgs {
+ render_bundle_encoder_rid: u32,
+ label: Option,
+}
+
+pub fn op_webgpu_render_bundle_encoder_finish(
+ state: &mut OpState,
+ args: RenderBundleEncoderFinishArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .take::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder = Rc::try_unwrap(render_bundle_encoder_resource)
+ .ok()
+ .expect("unwrapping render_bundle_encoder_resource should succeed")
+ .0
+ .into_inner();
+ let instance = state.borrow::();
+
+ let (render_bundle, maybe_err) = gfx_select!(render_bundle_encoder.parent() => instance.render_bundle_encoder_finish(
+ render_bundle_encoder,
+ &wgpu_core::command::RenderBundleDescriptor {
+ label: args.label.map(Cow::from),
+ },
+ std::marker::PhantomData
+ ));
+
+ let rid = state.resource_table.add(WebGPURenderBundle(render_bundle));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderSetBindGroupArgs {
+ render_bundle_encoder_rid: u32,
+ index: u32,
+ bind_group: u32,
+ dynamic_offsets_data: Option>,
+ dynamic_offsets_data_start: usize,
+ dynamic_offsets_data_length: usize,
+}
+
+pub fn op_webgpu_render_bundle_encoder_set_bind_group(
+ state: &mut OpState,
+ args: RenderBundleEncoderSetBindGroupArgs,
+ zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let bind_group_resource = state
+ .resource_table
+ .get::(args.bind_group)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ // I know this might look like it can be easily deduplicated, but it can not
+ // be due to the lifetime of the args.dynamic_offsets_data slice. Because we
+ // need to use a raw pointer here the slice can be freed before the pointer
+ // is used in wgpu_render_pass_set_bind_group. See
+ // https://matrix.to/#/!XFRnMvAfptAHthwBCx:matrix.org/$HgrlhD-Me1DwsGb8UdMu2Hqubgks8s7ILwWRwigOUAg
+ match args.dynamic_offsets_data {
+ Some(data) => unsafe {
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ args.index,
+ bind_group_resource.0,
+ data.as_slice().as_ptr(),
+ args.dynamic_offsets_data_length,
+ );
+ },
+ None => {
+ let (prefix, data, suffix) = unsafe { zero_copy[0].align_to::() };
+ assert!(prefix.is_empty());
+ assert!(suffix.is_empty());
+ unsafe {
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ args.index,
+ bind_group_resource.0,
+ data[args.dynamic_offsets_data_start..].as_ptr(),
+ args.dynamic_offsets_data_length,
+ );
+ }
+ }
+ };
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderPushDebugGroupArgs {
+ render_bundle_encoder_rid: u32,
+ group_label: String,
+}
+
+pub fn op_webgpu_render_bundle_encoder_push_debug_group(
+ state: &mut OpState,
+ args: RenderBundleEncoderPushDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ let label = std::ffi::CString::new(args.group_label).unwrap();
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_push_debug_group(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ label.as_ptr(),
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderPopDebugGroupArgs {
+ render_bundle_encoder_rid: u32,
+}
+
+pub fn op_webgpu_render_bundle_encoder_pop_debug_group(
+ state: &mut OpState,
+ args: RenderBundleEncoderPopDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_pop_debug_group(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderInsertDebugMarkerArgs {
+ render_bundle_encoder_rid: u32,
+ marker_label: String,
+}
+
+pub fn op_webgpu_render_bundle_encoder_insert_debug_marker(
+ state: &mut OpState,
+ args: RenderBundleEncoderInsertDebugMarkerArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ let label = std::ffi::CString::new(args.marker_label).unwrap();
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_insert_debug_marker(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ label.as_ptr(),
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderSetPipelineArgs {
+ render_bundle_encoder_rid: u32,
+ pipeline: u32,
+}
+
+pub fn op_webgpu_render_bundle_encoder_set_pipeline(
+ state: &mut OpState,
+ args: RenderBundleEncoderSetPipelineArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_pipeline_resource = state
+ .resource_table
+ .get::(args.pipeline)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_pipeline(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ render_pipeline_resource.0,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderSetIndexBufferArgs {
+ render_bundle_encoder_rid: u32,
+ buffer: u32,
+ index_format: String,
+ offset: u64,
+ size: u64,
+}
+
+pub fn op_webgpu_render_bundle_encoder_set_index_buffer(
+ state: &mut OpState,
+ args: RenderBundleEncoderSetIndexBufferArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let buffer_resource = state
+ .resource_table
+ .get::(args.buffer)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ render_bundle_encoder_resource
+ .0
+ .borrow_mut()
+ .set_index_buffer(
+ buffer_resource.0,
+ super::pipeline::serialize_index_format(args.index_format),
+ args.offset,
+ std::num::NonZeroU64::new(args.size),
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderSetVertexBufferArgs {
+ render_bundle_encoder_rid: u32,
+ slot: u32,
+ buffer: u32,
+ offset: u64,
+ size: u64,
+}
+
+pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
+ state: &mut OpState,
+ args: RenderBundleEncoderSetVertexBufferArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let buffer_resource = state
+ .resource_table
+ .get::(args.buffer)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ args.slot,
+ buffer_resource.0,
+ args.offset,
+ std::num::NonZeroU64::new(args.size),
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderDrawArgs {
+ render_bundle_encoder_rid: u32,
+ vertex_count: u32,
+ instance_count: u32,
+ first_vertex: u32,
+ first_instance: u32,
+}
+
+pub fn op_webgpu_render_bundle_encoder_draw(
+ state: &mut OpState,
+ args: RenderBundleEncoderDrawArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ args.vertex_count,
+ args.instance_count,
+ args.first_vertex,
+ args.first_instance,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderDrawIndexedArgs {
+ render_bundle_encoder_rid: u32,
+ index_count: u32,
+ instance_count: u32,
+ first_index: u32,
+ base_vertex: i32,
+ first_instance: u32,
+}
+
+pub fn op_webgpu_render_bundle_encoder_draw_indexed(
+ state: &mut OpState,
+ args: RenderBundleEncoderDrawIndexedArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indexed(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ args.index_count,
+ args.instance_count,
+ args.first_index,
+ args.base_vertex,
+ args.first_instance,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RenderBundleEncoderDrawIndirectArgs {
+ render_bundle_encoder_rid: u32,
+ indirect_buffer: u32,
+ indirect_offset: u64,
+}
+
+pub fn op_webgpu_render_bundle_encoder_draw_indirect(
+ state: &mut OpState,
+ args: RenderBundleEncoderDrawIndirectArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let buffer_resource = state
+ .resource_table
+ .get::(args.indirect_buffer)
+ .ok_or_else(bad_resource_id)?;
+ let render_bundle_encoder_resource = state
+ .resource_table
+ .get::(args.render_bundle_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indirect(
+ &mut render_bundle_encoder_resource.0.borrow_mut(),
+ buffer_resource.0,
+ args.indirect_offset,
+ );
+
+ Ok(json!({}))
+}
diff --git a/op_crates/webgpu/command_encoder.rs b/op_crates/webgpu/command_encoder.rs
new file mode 100644
index 0000000000..b91f677ee8
--- /dev/null
+++ b/op_crates/webgpu/command_encoder.rs
@@ -0,0 +1,734 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
+use deno_core::serde_json::json;
+use deno_core::serde_json::Value;
+use deno_core::ZeroCopyBuf;
+use deno_core::{OpState, Resource};
+use serde::Deserialize;
+use std::borrow::Cow;
+use std::cell::RefCell;
+
+use super::error::WebGPUError;
+
+pub(crate) struct WebGPUCommandEncoder(
+ pub(crate) wgpu_core::id::CommandEncoderId,
+);
+impl Resource for WebGPUCommandEncoder {
+ fn name(&self) -> Cow {
+ "webGPUCommandEncoder".into()
+ }
+}
+
+pub(crate) struct WebGPUCommandBuffer(
+ pub(crate) wgpu_core::id::CommandBufferId,
+);
+impl Resource for WebGPUCommandBuffer {
+ fn name(&self) -> Cow {
+ "webGPUCommandBuffer".into()
+ }
+}
+
+fn serialize_store_op(store_op: String) -> wgpu_core::command::StoreOp {
+ match store_op.as_str() {
+ "store" => wgpu_core::command::StoreOp::Store,
+ "clear" => wgpu_core::command::StoreOp::Clear,
+ _ => unreachable!(),
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateCommandEncoderArgs {
+ device_rid: u32,
+ label: Option,
+ _measure_execution_time: Option, // not yet implemented
+}
+
+pub fn op_webgpu_create_command_encoder(
+ state: &mut OpState,
+ args: CreateCommandEncoderArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let device_resource = state
+ .resource_table
+ .get::(args.device_rid)
+ .ok_or_else(bad_resource_id)?;
+ let device = device_resource.0;
+
+ let descriptor = wgpu_types::CommandEncoderDescriptor {
+ label: args.label.map(Cow::from),
+ };
+
+ let (command_encoder, maybe_err) = gfx_select!(device => instance.device_create_command_encoder(
+ device,
+ &descriptor,
+ std::marker::PhantomData
+ ));
+
+ let rid = state
+ .resource_table
+ .add(WebGPUCommandEncoder(command_encoder));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from),
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct GPURenderPassColorAttachment {
+ view: u32,
+ resolve_target: Option,
+ load_op: String,
+ load_value: Option,
+ store_op: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct GPURenderPassDepthStencilAttachment {
+ view: u32,
+ depth_load_op: String,
+ depth_load_value: Option,
+ depth_store_op: String,
+ depth_read_only: Option,
+ stencil_load_op: String,
+ stencil_load_value: Option,
+ stencil_store_op: String,
+ stencil_read_only: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderBeginRenderPassArgs {
+ command_encoder_rid: u32,
+ label: Option,
+ color_attachments: Vec,
+ depth_stencil_attachment: Option,
+ _occlusion_query_set: Option, // not yet implemented
+}
+
+pub fn op_webgpu_command_encoder_begin_render_pass(
+ state: &mut OpState,
+ args: CommandEncoderBeginRenderPassArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ let mut color_attachments = vec![];
+
+ for color_attachment in args.color_attachments {
+ let texture_view_resource = state
+ .resource_table
+ .get::(color_attachment.view)
+ .ok_or_else(bad_resource_id)?;
+
+ let attachment = wgpu_core::command::ColorAttachmentDescriptor {
+ attachment: texture_view_resource.0,
+ resolve_target: color_attachment
+ .resolve_target
+ .map(|rid| {
+ state
+ .resource_table
+ .get::(rid)
+ .ok_or_else(bad_resource_id)
+ })
+ .transpose()?
+ .map(|texture| texture.0),
+ channel: match color_attachment.load_op.as_str() {
+ "load" => wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Load,
+ store_op: color_attachment
+ .store_op
+ .map_or(wgpu_core::command::StoreOp::Store, serialize_store_op),
+ clear_value: Default::default(),
+ read_only: false,
+ },
+ "clear" => {
+ let color = color_attachment.load_value.unwrap();
+ wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Clear,
+ store_op: color_attachment
+ .store_op
+ .map_or(wgpu_core::command::StoreOp::Store, serialize_store_op),
+ clear_value: wgpu_types::Color {
+ r: color.r,
+ g: color.g,
+ b: color.b,
+ a: color.a,
+ },
+ read_only: false,
+ }
+ }
+ _ => unreachable!(),
+ },
+ };
+
+ color_attachments.push(attachment)
+ }
+
+ let mut depth_stencil_attachment = None;
+
+ if let Some(attachment) = args.depth_stencil_attachment {
+ let texture_view_resource = state
+ .resource_table
+ .get::(attachment.view)
+ .ok_or_else(bad_resource_id)?;
+
+ depth_stencil_attachment =
+ Some(wgpu_core::command::DepthStencilAttachmentDescriptor {
+ attachment: texture_view_resource.0,
+ depth: match attachment.depth_load_op.as_str() {
+ "load" => wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Load,
+ store_op: serialize_store_op(attachment.depth_store_op),
+ clear_value: 0.0,
+ read_only: attachment.depth_read_only.unwrap_or(false),
+ },
+ "clear" => wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Clear,
+ store_op: serialize_store_op(attachment.depth_store_op),
+ clear_value: attachment.depth_load_value.unwrap(),
+ read_only: attachment.depth_read_only.unwrap_or(false),
+ },
+ _ => unreachable!(),
+ },
+ stencil: match attachment.stencil_load_op.as_str() {
+ "load" => wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Load,
+ store_op: serialize_store_op(attachment.stencil_store_op),
+ clear_value: 0,
+ read_only: attachment.stencil_read_only.unwrap_or(false),
+ },
+ "clear" => wgpu_core::command::PassChannel {
+ load_op: wgpu_core::command::LoadOp::Clear,
+ store_op: serialize_store_op(attachment.stencil_store_op),
+ clear_value: attachment.stencil_load_value.unwrap(),
+ read_only: attachment.stencil_read_only.unwrap_or(false),
+ },
+ _ => unreachable!(),
+ },
+ });
+ }
+
+ let descriptor = wgpu_core::command::RenderPassDescriptor {
+ label: args.label.map(Cow::from),
+ color_attachments: Cow::from(color_attachments),
+ depth_stencil_attachment: depth_stencil_attachment.as_ref(),
+ };
+
+ let render_pass = wgpu_core::command::RenderPass::new(
+ command_encoder_resource.0,
+ &descriptor,
+ );
+
+ let rid = state
+ .resource_table
+ .add(super::render_pass::WebGPURenderPass(RefCell::new(
+ render_pass,
+ )));
+
+ Ok(json!({
+ "rid": rid,
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderBeginComputePassArgs {
+ command_encoder_rid: u32,
+ label: Option,
+}
+
+pub fn op_webgpu_command_encoder_begin_compute_pass(
+ state: &mut OpState,
+ args: CommandEncoderBeginComputePassArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ let descriptor = wgpu_core::command::ComputePassDescriptor {
+ label: args.label.map(Cow::from),
+ };
+
+ let compute_pass = wgpu_core::command::ComputePass::new(
+ command_encoder_resource.0,
+ &descriptor,
+ );
+
+ let rid = state
+ .resource_table
+ .add(super::compute_pass::WebGPUComputePass(RefCell::new(
+ compute_pass,
+ )));
+
+ Ok(json!({
+ "rid": rid,
+ }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderCopyBufferToBufferArgs {
+ command_encoder_rid: u32,
+ source: u32,
+ source_offset: u64,
+ destination: u32,
+ destination_offset: u64,
+ size: u64,
+}
+
+pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
+ state: &mut OpState,
+ args: CommandEncoderCopyBufferToBufferArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let source_buffer_resource = state
+ .resource_table
+ .get::(args.source)
+ .ok_or_else(bad_resource_id)?;
+ let source_buffer = source_buffer_resource.0;
+ let destination_buffer_resource = state
+ .resource_table
+ .get::(args.destination)
+ .ok_or_else(bad_resource_id)?;
+ let destination_buffer = destination_buffer_resource.0;
+
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_copy_buffer_to_buffer(
+ command_encoder,
+ source_buffer,
+ args.source_offset,
+ destination_buffer,
+ args.destination_offset,
+ args.size
+ )).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct GPUImageCopyBuffer {
+ buffer: u32,
+ offset: Option,
+ bytes_per_row: Option,
+ rows_per_image: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct GPUOrigin3D {
+ pub x: Option,
+ pub y: Option,
+ pub z: Option,
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct GPUImageCopyTexture {
+ pub texture: u32,
+ pub mip_level: Option,
+ pub origin: Option,
+ pub _aspect: Option, // not yet implemented
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderCopyBufferToTextureArgs {
+ command_encoder_rid: u32,
+ source: GPUImageCopyBuffer,
+ destination: GPUImageCopyTexture,
+ copy_size: super::texture::GPUExtent3D,
+}
+
+pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
+ state: &mut OpState,
+ args: CommandEncoderCopyBufferToTextureArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let source_buffer_resource = state
+ .resource_table
+ .get::(args.source.buffer)
+ .ok_or_else(bad_resource_id)?;
+ let destination_texture_resource = state
+ .resource_table
+ .get::(args.destination.texture)
+ .ok_or_else(bad_resource_id)?;
+
+ let source = wgpu_core::command::BufferCopyView {
+ buffer: source_buffer_resource.0,
+ layout: wgpu_types::TextureDataLayout {
+ offset: args.source.offset.unwrap_or(0),
+ bytes_per_row: args.source.bytes_per_row.unwrap_or(0),
+ rows_per_image: args.source.rows_per_image.unwrap_or(0),
+ },
+ };
+ let destination = wgpu_core::command::TextureCopyView {
+ texture: destination_texture_resource.0,
+ mip_level: args.destination.mip_level.unwrap_or(0),
+ origin: args
+ .destination
+ .origin
+ .map_or(Default::default(), |origin| wgpu_types::Origin3d {
+ x: origin.x.unwrap_or(0),
+ y: origin.y.unwrap_or(0),
+ z: origin.z.unwrap_or(0),
+ }),
+ };
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_copy_buffer_to_texture(
+ command_encoder,
+ &source,
+ &destination,
+ &wgpu_types::Extent3d {
+ width: args.copy_size.width.unwrap_or(1),
+ height: args.copy_size.height.unwrap_or(1),
+ depth: args.copy_size.depth.unwrap_or(1),
+ }
+ )).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderCopyTextureToBufferArgs {
+ command_encoder_rid: u32,
+ source: GPUImageCopyTexture,
+ destination: GPUImageCopyBuffer,
+ copy_size: super::texture::GPUExtent3D,
+}
+
+pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
+ state: &mut OpState,
+ args: CommandEncoderCopyTextureToBufferArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let source_texture_resource = state
+ .resource_table
+ .get::(args.source.texture)
+ .ok_or_else(bad_resource_id)?;
+ let destination_buffer_resource = state
+ .resource_table
+ .get::(args.destination.buffer)
+ .ok_or_else(bad_resource_id)?;
+
+ let source = wgpu_core::command::TextureCopyView {
+ texture: source_texture_resource.0,
+ mip_level: args.source.mip_level.unwrap_or(0),
+ origin: args.source.origin.map_or(Default::default(), |origin| {
+ wgpu_types::Origin3d {
+ x: origin.x.unwrap_or(0),
+ y: origin.y.unwrap_or(0),
+ z: origin.z.unwrap_or(0),
+ }
+ }),
+ };
+ let destination = wgpu_core::command::BufferCopyView {
+ buffer: destination_buffer_resource.0,
+ layout: wgpu_types::TextureDataLayout {
+ offset: args.destination.offset.unwrap_or(0),
+ bytes_per_row: args.destination.bytes_per_row.unwrap_or(0),
+ rows_per_image: args.destination.rows_per_image.unwrap_or(0),
+ },
+ };
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_copy_texture_to_buffer(
+ command_encoder,
+ &source,
+ &destination,
+ &wgpu_types::Extent3d {
+ width: args.copy_size.width.unwrap_or(1),
+ height: args.copy_size.height.unwrap_or(1),
+ depth: args.copy_size.depth.unwrap_or(1),
+ }
+ )).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderCopyTextureToTextureArgs {
+ command_encoder_rid: u32,
+ source: GPUImageCopyTexture,
+ destination: GPUImageCopyTexture,
+ copy_size: super::texture::GPUExtent3D,
+}
+
+pub fn op_webgpu_command_encoder_copy_texture_to_texture(
+ state: &mut OpState,
+ args: CommandEncoderCopyTextureToTextureArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let source_texture_resource = state
+ .resource_table
+ .get::(args.source.texture)
+ .ok_or_else(bad_resource_id)?;
+ let destination_texture_resource = state
+ .resource_table
+ .get::(args.destination.texture)
+ .ok_or_else(bad_resource_id)?;
+
+ let source = wgpu_core::command::TextureCopyView {
+ texture: source_texture_resource.0,
+ mip_level: args.source.mip_level.unwrap_or(0),
+ origin: args.source.origin.map_or(Default::default(), |origin| {
+ wgpu_types::Origin3d {
+ x: origin.x.unwrap_or(0),
+ y: origin.y.unwrap_or(0),
+ z: origin.z.unwrap_or(0),
+ }
+ }),
+ };
+ let destination = wgpu_core::command::TextureCopyView {
+ texture: destination_texture_resource.0,
+ mip_level: args.destination.mip_level.unwrap_or(0),
+ origin: args
+ .destination
+ .origin
+ .map_or(Default::default(), |origin| wgpu_types::Origin3d {
+ x: origin.x.unwrap_or(0),
+ y: origin.y.unwrap_or(0),
+ z: origin.z.unwrap_or(0),
+ }),
+ };
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_copy_texture_to_texture(
+ command_encoder,
+ &source,
+ &destination,
+ &wgpu_types::Extent3d {
+ width: args.copy_size.width.unwrap_or(1),
+ height: args.copy_size.height.unwrap_or(1),
+ depth: args.copy_size.depth.unwrap_or(1),
+ }
+ )).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderPushDebugGroupArgs {
+ command_encoder_rid: u32,
+ group_label: String,
+}
+
+pub fn op_webgpu_command_encoder_push_debug_group(
+ state: &mut OpState,
+ args: CommandEncoderPushDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+
+ let maybe_err = gfx_select!(command_encoder => instance
+ .command_encoder_push_debug_group(command_encoder, &args.group_label))
+ .err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderPopDebugGroupArgs {
+ command_encoder_rid: u32,
+}
+
+pub fn op_webgpu_command_encoder_pop_debug_group(
+ state: &mut OpState,
+ args: CommandEncoderPopDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder)).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderInsertDebugMarkerArgs {
+ command_encoder_rid: u32,
+ marker_label: String,
+}
+
+pub fn op_webgpu_command_encoder_insert_debug_marker(
+ state: &mut OpState,
+ args: CommandEncoderInsertDebugMarkerArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+
+ let maybe_err = gfx_select!(command_encoder => instance.command_encoder_insert_debug_marker(
+ command_encoder,
+ &args.marker_label
+ )).err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderWriteTimestampArgs {
+ command_encoder_rid: u32,
+ query_set: u32,
+ query_index: u32,
+}
+
+pub fn op_webgpu_command_encoder_write_timestamp(
+ state: &mut OpState,
+ args: CommandEncoderWriteTimestampArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let query_set_resource = state
+ .resource_table
+ .get::(args.query_set)
+ .ok_or_else(bad_resource_id)?;
+
+ let maybe_err =
+ gfx_select!(command_encoder => instance.command_encoder_write_timestamp(
+ command_encoder,
+ query_set_resource.0,
+ args.query_index
+ ))
+ .err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderResolveQuerySetArgs {
+ command_encoder_rid: u32,
+ query_set: u32,
+ first_query: u32,
+ query_count: u32,
+ destination: u32,
+ destination_offset: u64,
+}
+
+pub fn op_webgpu_command_encoder_resolve_query_set(
+ state: &mut OpState,
+ args: CommandEncoderResolveQuerySetArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let instance = state.borrow::();
+ let command_encoder_resource = state
+ .resource_table
+ .get::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let query_set_resource = state
+ .resource_table
+ .get::(args.query_set)
+ .ok_or_else(bad_resource_id)?;
+ let destination_resource = state
+ .resource_table
+ .get::(args.destination)
+ .ok_or_else(bad_resource_id)?;
+
+ let maybe_err =
+ gfx_select!(command_encoder => instance.command_encoder_resolve_query_set(
+ command_encoder,
+ query_set_resource.0,
+ args.first_query,
+ args.query_count,
+ destination_resource.0,
+ args.destination_offset
+ ))
+ .err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandEncoderFinishArgs {
+ command_encoder_rid: u32,
+ label: Option,
+}
+
+pub fn op_webgpu_command_encoder_finish(
+ state: &mut OpState,
+ args: CommandEncoderFinishArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let command_encoder_resource = state
+ .resource_table
+ .take::(args.command_encoder_rid)
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let instance = state.borrow::();
+
+ let descriptor = wgpu_types::CommandBufferDescriptor {
+ label: args.label.map(Cow::from),
+ };
+
+ let (command_buffer, maybe_err) = gfx_select!(command_encoder => instance.command_encoder_finish(
+ command_encoder,
+ &descriptor
+ ));
+
+ let rid = state
+ .resource_table
+ .add(WebGPUCommandBuffer(command_buffer));
+
+ Ok(json!({
+ "rid": rid,
+ "err": maybe_err.map(WebGPUError::from)
+ }))
+}
diff --git a/op_crates/webgpu/compute_pass.rs b/op_crates/webgpu/compute_pass.rs
new file mode 100644
index 0000000000..711bdea97a
--- /dev/null
+++ b/op_crates/webgpu/compute_pass.rs
@@ -0,0 +1,365 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::bad_resource_id;
+use deno_core::error::AnyError;
+use deno_core::serde_json::json;
+use deno_core::serde_json::Value;
+use deno_core::ZeroCopyBuf;
+use deno_core::{OpState, Resource};
+use serde::Deserialize;
+use std::borrow::Cow;
+use std::cell::RefCell;
+
+use super::error::WebGPUError;
+
+pub(crate) struct WebGPUComputePass(
+ pub(crate) RefCell,
+);
+impl Resource for WebGPUComputePass {
+ fn name(&self) -> Cow {
+ "webGPUComputePass".into()
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassSetPipelineArgs {
+ compute_pass_rid: u32,
+ pipeline: u32,
+}
+
+pub fn op_webgpu_compute_pass_set_pipeline(
+ state: &mut OpState,
+ args: ComputePassSetPipelineArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pipeline_resource = state
+ .resource_table
+ .get::(args.pipeline)
+ .ok_or_else(bad_resource_id)?;
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_set_pipeline(
+ &mut compute_pass_resource.0.borrow_mut(),
+ compute_pipeline_resource.0,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassDispatchArgs {
+ compute_pass_rid: u32,
+ x: u32,
+ y: u32,
+ z: u32,
+}
+
+pub fn op_webgpu_compute_pass_dispatch(
+ state: &mut OpState,
+ args: ComputePassDispatchArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch(
+ &mut compute_pass_resource.0.borrow_mut(),
+ args.x,
+ args.y,
+ args.z,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassDispatchIndirectArgs {
+ compute_pass_rid: u32,
+ indirect_buffer: u32,
+ indirect_offset: u64,
+}
+
+pub fn op_webgpu_compute_pass_dispatch_indirect(
+ state: &mut OpState,
+ args: ComputePassDispatchIndirectArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let buffer_resource = state
+ .resource_table
+ .get::(args.indirect_buffer)
+ .ok_or_else(bad_resource_id)?;
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch_indirect(
+ &mut compute_pass_resource.0.borrow_mut(),
+ buffer_resource.0,
+ args.indirect_offset,
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassBeginPipelineStatisticsQueryArgs {
+ compute_pass_rid: u32,
+ query_set: u32,
+ query_index: u32,
+}
+
+pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query(
+ state: &mut OpState,
+ args: ComputePassBeginPipelineStatisticsQueryArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+ let query_set_resource = state
+ .resource_table
+ .get::(args.query_set)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_begin_pipeline_statistics_query(
+ &mut compute_pass_resource.0.borrow_mut(),
+ query_set_resource.0,
+ args.query_index,
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassEndPipelineStatisticsQueryArgs {
+ compute_pass_rid: u32,
+}
+
+pub fn op_webgpu_compute_pass_end_pipeline_statistics_query(
+ state: &mut OpState,
+ args: ComputePassEndPipelineStatisticsQueryArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_end_pipeline_statistics_query(
+ &mut compute_pass_resource.0.borrow_mut(),
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassWriteTimestampArgs {
+ compute_pass_rid: u32,
+ query_set: u32,
+ query_index: u32,
+}
+
+pub fn op_webgpu_compute_pass_write_timestamp(
+ state: &mut OpState,
+ args: ComputePassWriteTimestampArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+ let query_set_resource = state
+ .resource_table
+ .get::(args.query_set)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_write_timestamp(
+ &mut compute_pass_resource.0.borrow_mut(),
+ query_set_resource.0,
+ args.query_index,
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassEndPassArgs {
+ command_encoder_rid: u32,
+ compute_pass_rid: u32,
+}
+
+pub fn op_webgpu_compute_pass_end_pass(
+ state: &mut OpState,
+ args: ComputePassEndPassArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let command_encoder_resource = state
+ .resource_table
+ .get::(
+ args.command_encoder_rid,
+ )
+ .ok_or_else(bad_resource_id)?;
+ let command_encoder = command_encoder_resource.0;
+ let compute_pass_resource = state
+ .resource_table
+ .take::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+ let compute_pass = &compute_pass_resource.0.borrow();
+ let instance = state.borrow::();
+
+ let maybe_err =
+ gfx_select!(command_encoder => instance.command_encoder_run_compute_pass(
+ command_encoder,
+ compute_pass
+ ))
+ .err();
+
+ Ok(json!({ "err": maybe_err.map(WebGPUError::from) }))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassSetBindGroupArgs {
+ compute_pass_rid: u32,
+ index: u32,
+ bind_group: u32,
+ dynamic_offsets_data: Option>,
+ dynamic_offsets_data_start: usize,
+ dynamic_offsets_data_length: usize,
+}
+
+pub fn op_webgpu_compute_pass_set_bind_group(
+ state: &mut OpState,
+ args: ComputePassSetBindGroupArgs,
+ zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let bind_group_resource = state
+ .resource_table
+ .get::(args.bind_group)
+ .ok_or_else(bad_resource_id)?;
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_set_bind_group(
+ &mut compute_pass_resource.0.borrow_mut(),
+ args.index,
+ bind_group_resource.0,
+ match args.dynamic_offsets_data {
+ Some(data) => data.as_ptr(),
+ None => {
+ let (prefix, data, suffix) = zero_copy[0].align_to::();
+ assert!(prefix.is_empty());
+ assert!(suffix.is_empty());
+ data[args.dynamic_offsets_data_start..].as_ptr()
+ }
+ },
+ args.dynamic_offsets_data_length,
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassPushDebugGroupArgs {
+ compute_pass_rid: u32,
+ group_label: String,
+}
+
+pub fn op_webgpu_compute_pass_push_debug_group(
+ state: &mut OpState,
+ args: ComputePassPushDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ let label = std::ffi::CString::new(args.group_label).unwrap();
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_push_debug_group(
+ &mut compute_pass_resource.0.borrow_mut(),
+ label.as_ptr(),
+ 0, // wgpu#975
+ );
+ }
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassPopDebugGroupArgs {
+ compute_pass_rid: u32,
+}
+
+pub fn op_webgpu_compute_pass_pop_debug_group(
+ state: &mut OpState,
+ args: ComputePassPopDebugGroupArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_pop_debug_group(
+ &mut compute_pass_resource.0.borrow_mut(),
+ );
+
+ Ok(json!({}))
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ComputePassInsertDebugMarkerArgs {
+ compute_pass_rid: u32,
+ marker_label: String,
+}
+
+pub fn op_webgpu_compute_pass_insert_debug_marker(
+ state: &mut OpState,
+ args: ComputePassInsertDebugMarkerArgs,
+ _zero_copy: &mut [ZeroCopyBuf],
+) -> Result {
+ let compute_pass_resource = state
+ .resource_table
+ .get::(args.compute_pass_rid)
+ .ok_or_else(bad_resource_id)?;
+
+ unsafe {
+ let label = std::ffi::CString::new(args.marker_label).unwrap();
+ wgpu_core::command::compute_ffi::wgpu_compute_pass_insert_debug_marker(
+ &mut compute_pass_resource.0.borrow_mut(),
+ label.as_ptr(),
+ 0, // wgpu#975
+ );
+ }
+
+ Ok(json!({}))
+}
diff --git a/op_crates/webgpu/error.rs b/op_crates/webgpu/error.rs
new file mode 100644
index 0000000000..e793dabfa3
--- /dev/null
+++ b/op_crates/webgpu/error.rs
@@ -0,0 +1,252 @@
+use deno_core::error::AnyError;
+use serde::Serialize;
+use std::fmt;
+use wgpu_core::binding_model::CreateBindGroupError;
+use wgpu_core::binding_model::CreateBindGroupLayoutError;
+use wgpu_core::binding_model::CreatePipelineLayoutError;
+use wgpu_core::binding_model::GetBindGroupLayoutError;
+use wgpu_core::command::CommandAllocatorError;
+use wgpu_core::command::CommandEncoderError;
+use wgpu_core::command::ComputePassError;
+use wgpu_core::command::CopyError;
+use wgpu_core::command::CreateRenderBundleError;
+use wgpu_core::command::QueryError;
+use wgpu_core::command::RenderBundleError;
+use wgpu_core::command::RenderPassError;
+use wgpu_core::device::queue::QueueSubmitError;
+use wgpu_core::device::queue::QueueWriteError;
+use wgpu_core::device::DeviceError;
+use wgpu_core::pipeline::CreateComputePipelineError;
+use wgpu_core::pipeline::CreateRenderPipelineError;
+use wgpu_core::pipeline::CreateShaderModuleError;
+use wgpu_core::resource::BufferAccessError;
+use wgpu_core::resource::CreateBufferError;
+use wgpu_core::resource::CreateQuerySetError;
+use wgpu_core::resource::CreateSamplerError;
+use wgpu_core::resource::CreateTextureError;
+use wgpu_core::resource::CreateTextureViewError;
+
+#[derive(Serialize)]
+#[serde(tag = "type", content = "value")]
+#[serde(rename_all = "kebab-case")]
+pub enum WebGPUError {
+ Lost,
+ OutOfMemory,
+ Validation(String),
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateBufferError) -> Self {
+ match err {
+ CreateBufferError::Device(err) => err.into(),
+ CreateBufferError::AccessError(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: DeviceError) -> Self {
+ match err {
+ DeviceError::Lost => WebGPUError::Lost,
+ DeviceError::OutOfMemory => WebGPUError::OutOfMemory,
+ DeviceError::Invalid => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: BufferAccessError) -> Self {
+ match err {
+ BufferAccessError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateBindGroupLayoutError) -> Self {
+ match err {
+ CreateBindGroupLayoutError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreatePipelineLayoutError) -> Self {
+ match err {
+ CreatePipelineLayoutError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateBindGroupError) -> Self {
+ match err {
+ CreateBindGroupError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: RenderBundleError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateRenderBundleError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CommandAllocatorError) -> Self {
+ match err {
+ CommandAllocatorError::Device(err) => err.into(),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CopyError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CommandEncoderError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: QueryError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: ComputePassError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateComputePipelineError) -> Self {
+ match err {
+ CreateComputePipelineError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: GetBindGroupLayoutError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateRenderPipelineError) -> Self {
+ match err {
+ CreateRenderPipelineError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: RenderPassError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateSamplerError) -> Self {
+ match err {
+ CreateSamplerError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateShaderModuleError) -> Self {
+ match err {
+ CreateShaderModuleError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateTextureError) -> Self {
+ match err {
+ CreateTextureError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateTextureViewError) -> Self {
+ WebGPUError::Validation(err.to_string())
+ }
+}
+
+impl From for WebGPUError {
+ fn from(err: CreateQuerySetError) -> Self {
+ match err {
+ CreateQuerySetError::Device(err) => err.into(),
+ err => WebGPUError::Validation(err.to_string()),
+ }
+ }
+}
+
+impl From