From 60b637249afacd50fab58a21d984d03a5b05df24 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 8 Dec 2023 17:49:34 +0000 Subject: [PATCH] Bug 1868672 - Update `wgpu` to revision ff7b2c399301cca9bcbc5b19a869feb3c29ef785. r=webgpu-reviewers,supply-chain-reviewers,jimb # Changelog * #4807 Bump wasm-bindgen-test from 0.3.38 to 0.3.39 By dependabot[bot] in https://github.com/gfx-rs/wgpu/pull/4807 * #4830 Use Display instead of Debug to log errors. By nical in https://github.com/gfx-rs/wgpu/pull/4830 * #4755 [naga wgsl-in] Automatic conversions for `var` initializers. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4755 * #4755 [naga wgsl-in] Automatic conversions for `var` initializers. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4755 * #4755 [naga wgsl-in] Automatic conversions for `var` initializers. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4755 * #4832 vulkan: fix multi-planar texture creation By xiaopengli89 in https://github.com/gfx-rs/wgpu/pull/4832 * #4758 [vk] remove (old) unused blocklist for dual source blending By teoxoy in https://github.com/gfx-rs/wgpu/pull/4758 * #4828 Remove DX11 backend By valaphee in https://github.com/gfx-rs/wgpu/pull/4828 * #4836 [gl] add support for line and point polygon modes By valaphee in https://github.com/gfx-rs/wgpu/pull/4836 * #4820 Bump futures-lite from 2.0.1 to 2.1.0 By dependabot[bot] in https://github.com/gfx-rs/wgpu/pull/4820 * #4811 Expose shader validation By daxpedda in https://github.com/gfx-rs/wgpu/pull/4811 * #3507 [wgpu-hal] Inline RayQuery Support By daniel-keitel in https://github.com/gfx-rs/wgpu/pull/3507 * #4726 Fix Javascript exception on repeated `BufferSlice::get_mapped_range` calls By DouglasDwyer in https://github.com/gfx-rs/wgpu/pull/4726 * #4841 Remove `expose-ids` Feature By cwfitzgerald in https://github.com/gfx-rs/wgpu/pull/4841 * #4843 Some Minor `wgpu-core` Cleanups By cwfitzgerald in https://github.com/gfx-rs/wgpu/pull/4843 * #4844 Work around cbindgen issue By nical in https://github.com/gfx-rs/wgpu/pull/4844 Differential Revision: https://phabricator.services.mozilla.com/D195735 --- .cargo/config.in | 4 +- Cargo.lock | 10 +- dom/webgpu/Adapter.cpp | 3 - gfx/wgpu_bindings/Cargo.toml | 14 +- gfx/wgpu_bindings/moz.yaml | 4 +- supply-chain/audits.toml | 25 + third_party/rust/naga/.cargo-checksum.json | 2 +- .../rust/naga/src/front/wgsl/lower/mod.rs | 98 +- .../rust/wgpu-core/.cargo-checksum.json | 2 +- third_party/rust/wgpu-core/Cargo.toml | 1 - third_party/rust/wgpu-core/src/any_surface.rs | 4 - .../rust/wgpu-core/src/binding_model.rs | 7 +- .../rust/wgpu-core/src/device/global.rs | 43 +- third_party/rust/wgpu-core/src/device/life.rs | 2 +- third_party/rust/wgpu-core/src/device/mod.rs | 6 +- .../rust/wgpu-core/src/device/resource.rs | 27 +- third_party/rust/wgpu-core/src/global.rs | 14 - third_party/rust/wgpu-core/src/hal_api.rs | 21 - third_party/rust/wgpu-core/src/hub.rs | 6 - third_party/rust/wgpu-core/src/id.rs | 8 +- third_party/rust/wgpu-core/src/instance.rs | 34 - third_party/rust/wgpu-core/src/lib.rs | 9 +- third_party/rust/wgpu-core/src/pipeline.rs | 6 +- third_party/rust/wgpu-core/src/registry.rs | 1 - third_party/rust/wgpu-core/src/resource.rs | 18 +- .../rust/wgpu-hal/.cargo-checksum.json | 2 +- third_party/rust/wgpu-hal/Cargo.toml | 12 +- .../rust/wgpu-hal/examples/halmark/main.rs | 2 + .../examples/ray-traced-triangle/main.rs | 1113 +++++++++++++++++ .../examples/ray-traced-triangle/shader.wgsl | 37 + third_party/rust/wgpu-hal/src/auxil/mod.rs | 2 +- third_party/rust/wgpu-hal/src/dx11/adapter.rs | 303 ----- third_party/rust/wgpu-hal/src/dx11/command.rs | 271 ---- third_party/rust/wgpu-hal/src/dx11/device.rs | 242 ---- .../rust/wgpu-hal/src/dx11/instance.rs | 53 - third_party/rust/wgpu-hal/src/dx11/library.rs | 142 --- third_party/rust/wgpu-hal/src/dx11/mod.rs | 139 -- third_party/rust/wgpu-hal/src/dx12/command.rs | 20 + third_party/rust/wgpu-hal/src/dx12/conv.rs | 1 + third_party/rust/wgpu-hal/src/dx12/device.rs | 36 + third_party/rust/wgpu-hal/src/dx12/mod.rs | 5 + third_party/rust/wgpu-hal/src/empty.rs | 36 + third_party/rust/wgpu-hal/src/gles/adapter.rs | 9 +- third_party/rust/wgpu-hal/src/gles/command.rs | 18 + third_party/rust/wgpu-hal/src/gles/conv.rs | 17 +- third_party/rust/wgpu-hal/src/gles/device.rs | 21 + third_party/rust/wgpu-hal/src/gles/mod.rs | 2 + third_party/rust/wgpu-hal/src/gles/queue.rs | 4 + third_party/rust/wgpu-hal/src/lib.rs | 185 ++- .../rust/wgpu-hal/src/metal/command.rs | 18 + third_party/rust/wgpu-hal/src/metal/device.rs | 30 + third_party/rust/wgpu-hal/src/metal/mod.rs | 5 + .../rust/wgpu-hal/src/vulkan/adapter.rs | 117 +- .../rust/wgpu-hal/src/vulkan/command.rs | 237 ++++ third_party/rust/wgpu-hal/src/vulkan/conv.rs | 112 ++ .../rust/wgpu-hal/src/vulkan/device.rs | 285 ++++- third_party/rust/wgpu-hal/src/vulkan/mod.rs | 14 + .../rust/wgpu-types/.cargo-checksum.json | 2 +- third_party/rust/wgpu-types/src/lib.rs | 94 +- 59 files changed, 2518 insertions(+), 1437 deletions(-) create mode 100644 third_party/rust/wgpu-hal/examples/ray-traced-triangle/main.rs create mode 100644 third_party/rust/wgpu-hal/examples/ray-traced-triangle/shader.wgsl delete mode 100644 third_party/rust/wgpu-hal/src/dx11/adapter.rs delete mode 100644 third_party/rust/wgpu-hal/src/dx11/command.rs delete mode 100644 third_party/rust/wgpu-hal/src/dx11/device.rs delete mode 100644 third_party/rust/wgpu-hal/src/dx11/instance.rs delete mode 100644 third_party/rust/wgpu-hal/src/dx11/library.rs delete mode 100644 third_party/rust/wgpu-hal/src/dx11/mod.rs diff --git a/.cargo/config.in b/.cargo/config.in index 86e6ce6498ba3..969cf710f8886 100644 --- a/.cargo/config.in +++ b/.cargo/config.in @@ -25,9 +25,9 @@ git = "https://github.com/franziskuskiefer/cose-rust" rev = "43c22248d136c8b38fe42ea709d08da6355cf04b" replace-with = "vendored-sources" -[source."git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec"] +[source."git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785"] git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" replace-with = "vendored-sources" [source."git+https://github.com/hsivonen/chardetng?rev=3484d3e3ebdc8931493aa5df4d7ee9360a90e76b"] diff --git a/Cargo.lock b/Cargo.lock index a40675c1afc36..c4af919ef81d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1157,7 +1157,7 @@ dependencies = [ [[package]] name = "d3d12" version = "0.7.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec#767ac03245ee937d3dc552edc13fe7ab0a860eec" +source = "git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785#ff7b2c399301cca9bcbc5b19a869feb3c29ef785" dependencies = [ "bitflags 2.4.0", "libloading", @@ -3793,7 +3793,7 @@ checksum = "a2983372caf4480544083767bf2d27defafe32af49ab4df3a0b7fc90793a3664" [[package]] name = "naga" version = "0.14.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec#767ac03245ee937d3dc552edc13fe7ab0a860eec" +source = "git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785#ff7b2c399301cca9bcbc5b19a869feb3c29ef785" dependencies = [ "bit-set", "bitflags 2.4.0", @@ -6395,7 +6395,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.18.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec#767ac03245ee937d3dc552edc13fe7ab0a860eec" +source = "git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785#ff7b2c399301cca9bcbc5b19a869feb3c29ef785" dependencies = [ "arrayvec", "bit-vec", @@ -6418,7 +6418,7 @@ dependencies = [ [[package]] name = "wgpu-hal" version = "0.18.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec#767ac03245ee937d3dc552edc13fe7ab0a860eec" +source = "git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785#ff7b2c399301cca9bcbc5b19a869feb3c29ef785" dependencies = [ "android_system_properties", "arrayvec", @@ -6455,7 +6455,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.18.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=767ac03245ee937d3dc552edc13fe7ab0a860eec#767ac03245ee937d3dc552edc13fe7ab0a860eec" +source = "git+https://github.com/gfx-rs/wgpu?rev=ff7b2c399301cca9bcbc5b19a869feb3c29ef785#ff7b2c399301cca9bcbc5b19a869feb3c29ef785" dependencies = [ "bitflags 2.4.0", "js-sys", diff --git a/dom/webgpu/Adapter.cpp b/dom/webgpu/Adapter.cpp index 25fc3e2113dcb..434ba7c6fa715 100644 --- a/dom/webgpu/Adapter.cpp +++ b/dom/webgpu/Adapter.cpp @@ -77,9 +77,6 @@ void AdapterInfo::GetWgpuBackend(nsString& s) const { case ffi::WGPUBackend_Dx12: s.AssignLiteral("Dx12"); return; - case ffi::WGPUBackend_Dx11: - s.AssignLiteral("Dx11"); - return; case ffi::WGPUBackend_Gl: s.AssignLiteral("Gl"); return; diff --git a/gfx/wgpu_bindings/Cargo.toml b/gfx/wgpu_bindings/Cargo.toml index 51f6003d5a336..ac99616341b26 100644 --- a/gfx/wgpu_bindings/Cargo.toml +++ b/gfx/wgpu_bindings/Cargo.toml @@ -17,7 +17,7 @@ default = [] [dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" #Note: "replay" shouldn't ideally be needed, # but it allows us to serialize everything across IPC. features = ["replay", "trace", "serial-pass", "strict_asserts", "wgsl", "api_log_info"] @@ -27,36 +27,36 @@ features = ["replay", "trace", "serial-pass", "strict_asserts", "wgsl", "api_log [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" features = ["metal"] # We want the wgpu-core Direct3D backends on Windows. [target.'cfg(windows)'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" features = ["dx12"] # We want the wgpu-core Vulkan backend on Linux and Windows. [target.'cfg(any(windows, all(unix, not(any(target_os = "macos", target_os = "ios")))))'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" features = ["vulkan"] [dependencies.wgt] package = "wgpu-types" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" [dependencies.wgh] package = "wgpu-hal" git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" [target.'cfg(windows)'.dependencies.d3d12] git = "https://github.com/gfx-rs/wgpu" -rev = "767ac03245ee937d3dc552edc13fe7ab0a860eec" +rev = "ff7b2c399301cca9bcbc5b19a869feb3c29ef785" [target.'cfg(windows)'.dependencies] winapi = "0.3" diff --git a/gfx/wgpu_bindings/moz.yaml b/gfx/wgpu_bindings/moz.yaml index 055c8377afe80..7d44681e6c0e2 100644 --- a/gfx/wgpu_bindings/moz.yaml +++ b/gfx/wgpu_bindings/moz.yaml @@ -20,11 +20,11 @@ origin: # Human-readable identifier for this version/release # Generally "version NNN", "tag SSS", "bookmark SSS" - release: commit 767ac03245ee937d3dc552edc13fe7ab0a860eec + release: commit ff7b2c399301cca9bcbc5b19a869feb3c29ef785 # Revision to pull in # Must be a long or short commit SHA (long preferred) - revision: 767ac03245ee937d3dc552edc13fe7ab0a860eec + revision: ff7b2c399301cca9bcbc5b19a869feb3c29ef785 license: ['MIT', 'Apache-2.0'] diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 512af8822cf7c..1ef2fb5d9bf97 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -1201,6 +1201,11 @@ who = "Erich Gubler " criteria = "safe-to-deploy" delta = "0.7.0@git:6e21f7a9291db4395192d6b510d906978ae2d251 -> 0.7.0@git:a820a3ffba468cbb87c2a7e7bbe37065ed5207ee" +[[audits.d3d12]] +who = "Nicolas Silva " +criteria = "safe-to-deploy" +delta = "0.7.0@git:767ac03245ee937d3dc552edc13fe7ab0a860eec -> 0.7.0@git:ff7b2c399301cca9bcbc5b19a869feb3c29ef785" + [[audits.d3d12]] who = "Nicolas Silva " criteria = "safe-to-deploy" @@ -2497,6 +2502,11 @@ who = "Erich Gubler " criteria = "safe-to-deploy" delta = "0.14.0@git:6e21f7a9291db4395192d6b510d906978ae2d251 -> 0.14.0@git:a820a3ffba468cbb87c2a7e7bbe37065ed5207ee" +[[audits.naga]] +who = "Nicolas Silva " +criteria = "safe-to-deploy" +delta = "0.14.0@git:767ac03245ee937d3dc552edc13fe7ab0a860eec -> 0.14.0@git:ff7b2c399301cca9bcbc5b19a869feb3c29ef785" + [[audits.naga]] who = "Nicolas Silva " criteria = "safe-to-deploy" @@ -4270,6 +4280,11 @@ who = "Erich Gubler " criteria = "safe-to-deploy" delta = "0.18.0@git:6e21f7a9291db4395192d6b510d906978ae2d251 -> 0.18.0@git:a820a3ffba468cbb87c2a7e7bbe37065ed5207ee" +[[audits.wgpu-core]] +who = "Nicolas Silva " +criteria = "safe-to-deploy" +delta = "0.18.0@git:767ac03245ee937d3dc552edc13fe7ab0a860eec -> 0.18.0@git:ff7b2c399301cca9bcbc5b19a869feb3c29ef785" + [[audits.wgpu-core]] who = "Nicolas Silva " criteria = "safe-to-deploy" @@ -4343,6 +4358,11 @@ who = "Erich Gubler " criteria = "safe-to-deploy" delta = "0.18.0@git:6e21f7a9291db4395192d6b510d906978ae2d251 -> 0.18.0@git:a820a3ffba468cbb87c2a7e7bbe37065ed5207ee" +[[audits.wgpu-hal]] +who = "Nicolas Silva " +criteria = "safe-to-deploy" +delta = "0.18.0@git:767ac03245ee937d3dc552edc13fe7ab0a860eec -> 0.18.0@git:ff7b2c399301cca9bcbc5b19a869feb3c29ef785" + [[audits.wgpu-hal]] who = "Nicolas Silva " criteria = "safe-to-deploy" @@ -4416,6 +4436,11 @@ who = "Erich Gubler " criteria = "safe-to-deploy" delta = "0.18.0@git:6e21f7a9291db4395192d6b510d906978ae2d251 -> 0.18.0@git:a820a3ffba468cbb87c2a7e7bbe37065ed5207ee" +[[audits.wgpu-types]] +who = "Nicolas Silva " +criteria = "safe-to-deploy" +delta = "0.18.0@git:767ac03245ee937d3dc552edc13fe7ab0a860eec -> 0.18.0@git:ff7b2c399301cca9bcbc5b19a869feb3c29ef785" + [[audits.wgpu-types]] who = "Nicolas Silva " criteria = "safe-to-deploy" diff --git a/third_party/rust/naga/.cargo-checksum.json b/third_party/rust/naga/.cargo-checksum.json index 7d289c0444c20..cc6b6d2ae4bda 100644 --- a/third_party/rust/naga/.cargo-checksum.json +++ b/third_party/rust/naga/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".cargo/config.toml":"d7389d2a0c08ec72b79e83a3c76980903e3f9123625c32e69c798721193e2e74","CHANGELOG.md":"772216b2e6d35621ab36c985e8114b54403e2f3fb49bf1f8540c451fd06f8387","Cargo.toml":"5bd726a75d7177a43e517d27d412ac38879231f79795226ebcd0873ff1255fe9","README.md":"a76b47b656e7390265312709b62b357a4f39c7509ec9ebe0b133c5841a8ab60b","benches/criterion.rs":"f45e38b26e1323e934d32623572ff5395a53fed06f760eb1e07b22ed07858a38","src/arena.rs":"33ed2ec7b36429b133ed2a7de6fb9735827f69ea8b6c2ce97f64746a24a5bf36","src/back/dot/mod.rs":"a40050a73ac00c8fa43dd0b45a84fca6959d28c8c99ab3046b01f33c02f8c8f4","src/back/glsl/features.rs":"90c6a6255d550e9d97a04d6b6660c1a7af8e2433dd9379dc1d527693fa56523b","src/back/glsl/keywords.rs":"1546facbaddf696602102f32e47db7afc875f8ca3fbccc2122e0bcc45e022b53","src/back/glsl/mod.rs":"bba387392e3b9b22835d78a1db7d1490e7199cafcb347d54b22373b7b76b2900","src/back/hlsl/conv.rs":"5e40946f2d5ad6589dd2b0570d2c300dd96f92f0f954b829dc54a822de7774e8","src/back/hlsl/help.rs":"8f4ec24f74f3153a58b04f441bef16ecc8d400466d53187b06fb6b60a934a1ec","src/back/hlsl/keywords.rs":"eb4af8d697fb7f3991859d66339b5b2eac27c9fe41b73146ac838b207f462c9c","src/back/hlsl/mod.rs":"c677ebbb649a1c5f85f350d8da7129457d50ff52b1c88c1f0fac4a9d11eb020c","src/back/hlsl/storage.rs":"3170f165ff68d2482f8a8dbfa4bbf4b65d2446a7f208f33eea9eb187bb57eb09","src/back/hlsl/writer.rs":"8e61501bae6982273a525734d3e446694d4bf7a081419ec312c32b354e89d3ef","src/back/mod.rs":"b941caed50c086f49d25e76228d247ba6c2da6dbeea18d968c02dc68bb97f409","src/back/msl/keywords.rs":"998c0d86a26e5cf031c75f35cde28f2b390fe207a2e7d0eed8516ffdb99c1a8e","src/back/msl/mod.rs":"16d905902e30cf900ec924b66ff496adbbbc54af15c59713f358bfac042a625a","src/back/msl/sampler.rs":"9b01d68669e12ff7123243284b85e1a9d2c4d49140bd74ca32dedc007cbf15af","src/back/msl/writer.rs":"9503df4ae10d1d7b6840cb68e2e2ff4f7ed8761b217faa99e6927d87da546071","src/back/spv/block.rs":"976c0856d25dc0f54f4b5039b5e101088f32a92c373c7449682e9c8d64fc48c0","src/back/spv/helpers.rs":"a4e260130f39c7345decec40dadf1e94419c8f6d236ce7a53b5300aa72952a1b","src/back/spv/image.rs":"5840a6d5cdffbf30cb20a76ddfdb468041fc6b687a476b3b2fc2553bda6f4af7","src/back/spv/index.rs":"26611dd50df5cfd214900e19415f5374dd301d3b7d3bfedbc5ec0f254328287a","src/back/spv/instructions.rs":"d0ced535fdec49323105a7d6ee40a8ed6b4966ac5f0f40b062f0eb11a531b106","src/back/spv/layout.rs":"e263de53cd2f9a03ad94b82b434ce636609bc1ed435a2d1132951663bfaa8ebd","src/back/spv/mod.rs":"31b0229f59b5784b57851fcf6325095add58af6de3afa85d518a4e266c4b99a9","src/back/spv/ray.rs":"a34bf6b26d873f7270caa45841d9ef291aca8d9732ecd086b14d8856038e1e41","src/back/spv/recyclable.rs":"114db0ea12774d6514f995d07295cb9a42631ab75165fc60980c10e9b5ecb832","src/back/spv/selection.rs":"81e404abfa0a977f7c1f76ccb37a78d13ccadbda229048dad53cc67687cc39db","src/back/spv/writer.rs":"a76a73c0692162da24ab5508bc3ca70eb5e01367fe54472d100e237dbd594467","src/back/wgsl/mod.rs":"2dd12bbea9ace835850192bb68c5760953da6bac6a636073d1eca19381c0c0b6","src/back/wgsl/writer.rs":"f996c393aac339139eed8592b5fdd15fc786a49d3542985dc8ecb07f549a77ea","src/block.rs":"c69089e5bbb6de6ba24efb15b21d5d434fcabfbc4d48feae948d2a4da135aae7","src/compact/expressions.rs":"7a4c916282a5b484519ed29ab451c7b595d8dea73c83c5c2cf7efc6fbc648fda","src/compact/functions.rs":"174bd9167ecf6353afb8c36d365ba3f9b483233eb4bacf578e50183c7433aa15","src/compact/handle_set_map.rs":"817c5193352d5fd6a61a5c970daba23224e14a65aea15f8f1c8679c99f834ca2","src/compact/mod.rs":"8abea7a8a9870d953fb628a32bac2bc15e87e077910cb95aa1f26e58a0a35c2a","src/compact/statements.rs":"4df33ee9589300e769e75c674bdc30578e93704ec3eb2aabc7132121745b55c8","src/compact/types.rs":"18343f2ca2c123eea2531cffc1d54a7798797caccecaa1f9b8c4fd5dd6ca1a05","src/front/glsl/ast.rs":"2ae292c09fed43951e20ec6ce0b7b99efe91726cf90487d6c129137b08618e01","src/front/glsl/builtins.rs":"d35501d5b42b61c261da24436b82eafdf96371b1600d148648d90d041f736ae4","src/front/glsl/context.rs":"2f07a63209258a8459ae6a6ef8277313c4dc771ab96ef6f5ab3a383a0d3599ba","src/front/glsl/error.rs":"08409f8cc13b73c6eda938ff7ebf2b46e9d27c66d718d640ad8d6a33fddbb7a1","src/front/glsl/functions.rs":"60838c34b8295112e5696b52d710acebb93e0a982e05f8eb87d3b80f52eb7793","src/front/glsl/lex.rs":"08736ae8beb955da5b0e6e3e0f45995a824995f7096d516a2910417e9c7afa32","src/front/glsl/mod.rs":"c8e435a894d641e6c92fcd7d357d51e1136af1a69410fbaedb88c7262b2269df","src/front/glsl/offset.rs":"9358602ca4f9ef21d5066d674dae757bf88fdf5c289c4360534354d13bd41dc0","src/front/glsl/parser.rs":"fe5291512db412b33b6c09d5b3dcf7c54ff6ec55b47f0a078dcc11695e78471d","src/front/glsl/parser/declarations.rs":"d637cc52e553910a2e97b70b3366c15aefbe737f413adb11c27efd184c1fbf9d","src/front/glsl/parser/expressions.rs":"520cfc9402d5fbd48e52ef1d36562c6b74794c09ec33ec1ebb10aa48d129b66f","src/front/glsl/parser/functions.rs":"670ca6bba5a56f3919968658966b05ba824c2d76427b8927d4b111f715091629","src/front/glsl/parser/types.rs":"0971bc98cbde1d70c0ced1717c8726a12a5bfafa9a72b127ed242db5435ec8a8","src/front/glsl/parser_tests.rs":"fc2120fff132af850b52f9ac5d19f0c2fce7997b17ba49881b155d173359cfd3","src/front/glsl/token.rs":"42325adbef5bfc9e6f9e40e7ed3cbfa7ef498c05799fdb7694b123e6450410e1","src/front/glsl/types.rs":"58c9cf3d570dff8cb68f2931faf5b18e875e510741bf035ec10b9ff6df27c5d8","src/front/glsl/variables.rs":"fb2a09e386b6e98ca9fb8fb744afac1e8b19d1b67c6ede5c474e3ba860d3d4cb","src/front/interpolator.rs":"9b6ca498d5fbd9bc1515510a04e303a00b324121d7285da3c955cfe18eb4224c","src/front/mod.rs":"6f77ca3ff925cc16e5ae46132bd6196ca4c9c80a7db123f0d2ec09aae93ba51f","src/front/spv/convert.rs":"9b4ecc53131b6250cde4cae93557eb467127e9e8d0536d29a851538684ae5371","src/front/spv/error.rs":"3129fd1fe346441d61d0f641734df7e919919db15df706788d16402ebf480607","src/front/spv/function.rs":"3a3f0c07862750f79f8ebc273c5df11efc67272566458410f776bd8fa271a0f8","src/front/spv/image.rs":"5d55cfbf6752732a594114cd09a9a207216e1ee85d8f2c9bc4310217a55ea321","src/front/spv/mod.rs":"ccbeb4b80959c00323b2459e316b7c5c7e3f313ab94f2151fa44a2dee6255d4e","src/front/spv/null.rs":"e1446d99d04c76a9c3bbd24dd9b20c4711ce8a918a9b403be6cccbde1175b3b4","src/front/type_gen.rs":"b4f1df23380e06c9fdad4140810ce96ab041dbb1d371a07045b4e0069aa8ba55","src/front/wgsl/error.rs":"a2abfd483afe46e1e80d47568ea56c2d587de8dd6291739b03de788f37dada0e","src/front/wgsl/index.rs":"2b9a4929a46bd822d3ed6f9a150e24d437e5bdca8293eb748aebe80ce7e74153","src/front/wgsl/lower/construction.rs":"48b2c1b0ef93345bc3cdbf1af29690cc128a4507f0b9d7d908a136f4c0fd48ca","src/front/wgsl/lower/conversion.rs":"6d123e0148fc6d5b8df3d218ce1978a154d0edb86f65ca20fdc91bb4bf9475ce","src/front/wgsl/lower/mod.rs":"d1954f9845fd4fedbf688dbcff85310954eb69ac228a3e2a128bd5759ad8667d","src/front/wgsl/mod.rs":"02b194a0a29ef7281f71b424564e18ada4a8b1a0d8c26ec40b6be195bd4c4904","src/front/wgsl/parse/ast.rs":"c7eaae40179f0889f2b142d3b31968cbfab6d3cfe02e425912c6da8dadac51df","src/front/wgsl/parse/conv.rs":"01b25edbe80b263a3fa51bc980c075630bb31d4af851441323383eb4f3b83360","src/front/wgsl/parse/lexer.rs":"bff1d0e3cd920b2e9342b521bed7483595556b90088dc0b22e1599900585ff8e","src/front/wgsl/parse/mod.rs":"3b4895a2baf91c719b95f0afb6441ffac2036c2a9ff817e633882fd257afcc38","src/front/wgsl/parse/number.rs":"623423471a13cf9a45662ee3ac01554644ac544338c7493cfe6087549bab91f7","src/front/wgsl/tests.rs":"39d0b44d0f073a7599c88b7c4efd1572886f3af074fa2015454623be313b297f","src/front/wgsl/to_wgsl.rs":"2e2e30d86b07f209b866e530d3a882803bf28b39ce379052561a749f628e8e28","src/keywords/mod.rs":"0138f3931f8af0b0a05174549d0fd2152945b027dc3febefc1bbd676581d2e45","src/keywords/wgsl.rs":"7c3b364b60ca29cb8a68ef781de9ecd28b76b74bed18bf18a35d2ebffaa855ab","src/lib.rs":"c5d91c603ae310a7ef9ff8444898959a3dbbc32ba262cabb1fd5682823921d98","src/proc/constant_evaluator.rs":"0f55fb6f8310dee8dc021f27ab5c3c0ed896963f82150346fcdfbefc47b5e4a1","src/proc/emitter.rs":"39ac886c651e2ad33c06a676a7e4826a0e93de0af660c01e8e4b1f7406742f88","src/proc/index.rs":"f4250f6944c2b631e8140979024e8deb86fa8d5352d8641ba954a388b2c0940e","src/proc/layouter.rs":"b3d061c87424f36981c902716f37ab7b72f2bb2d0c2d7e900c51149318ea1a0a","src/proc/mod.rs":"e6ce6a376aa4e3584f0386fdbe95c7ea2a93abe19b03cc261b6152c8fca24842","src/proc/namer.rs":"7328fac41e40890c64c7ee2fa985a4395424f18b08d30f30ca2583fdabd2fd35","src/proc/terminator.rs":"13c59bf00f5b26171d971effc421091f5e00dedddd246c2daa44fe65aeda060a","src/proc/typifier.rs":"99de19270d01c12ec49d14323aa1d9b8774f1ee715804af7235deff70739ba3d","src/span.rs":"6560599f20b8bc2de746ee9fd6b05c32bb630af914fce8845d84fdc72f9a636c","src/valid/analyzer.rs":"8472b98f16a4a4a0fa7079197db25696f77ef3e1602a7cddea1930daebd27917","src/valid/compose.rs":"71a86bd4183f358c4ea25e7b512f318413956947c8035d2b8dc1f3fe7db4ecd2","src/valid/expression.rs":"1cdbd594dbdb33d8473d93c11112cf717e262bb8c35cee10b01db4322b2237d7","src/valid/function.rs":"5ec31146aacf7daae689836ff3e2978f075f2cc62b3fd829d09c760a6e606501","src/valid/handles.rs":"0878915e67b16d7c41cf8245d9ab3b3f4a604e7d4e87527ea40e03efcbf1f74a","src/valid/interface.rs":"6ddf5f8d5150342d2e8c754a71c92c85d8533fd1d4c6b7a83a05b508e8e8114d","src/valid/mod.rs":"9e2bafa06bea16db2c5a8f825eed4d008c474b87cda2fc7e82ca7a21229c6f20","src/valid/type.rs":"09e18bb9510dbb0cfb4a8ac054afee4c4f56063d614159ab5b956aa1e5850468"},"package":null} \ No newline at end of file +{"files":{".cargo/config.toml":"d7389d2a0c08ec72b79e83a3c76980903e3f9123625c32e69c798721193e2e74","CHANGELOG.md":"772216b2e6d35621ab36c985e8114b54403e2f3fb49bf1f8540c451fd06f8387","Cargo.toml":"5bd726a75d7177a43e517d27d412ac38879231f79795226ebcd0873ff1255fe9","README.md":"a76b47b656e7390265312709b62b357a4f39c7509ec9ebe0b133c5841a8ab60b","benches/criterion.rs":"f45e38b26e1323e934d32623572ff5395a53fed06f760eb1e07b22ed07858a38","src/arena.rs":"33ed2ec7b36429b133ed2a7de6fb9735827f69ea8b6c2ce97f64746a24a5bf36","src/back/dot/mod.rs":"a40050a73ac00c8fa43dd0b45a84fca6959d28c8c99ab3046b01f33c02f8c8f4","src/back/glsl/features.rs":"90c6a6255d550e9d97a04d6b6660c1a7af8e2433dd9379dc1d527693fa56523b","src/back/glsl/keywords.rs":"1546facbaddf696602102f32e47db7afc875f8ca3fbccc2122e0bcc45e022b53","src/back/glsl/mod.rs":"bba387392e3b9b22835d78a1db7d1490e7199cafcb347d54b22373b7b76b2900","src/back/hlsl/conv.rs":"5e40946f2d5ad6589dd2b0570d2c300dd96f92f0f954b829dc54a822de7774e8","src/back/hlsl/help.rs":"8f4ec24f74f3153a58b04f441bef16ecc8d400466d53187b06fb6b60a934a1ec","src/back/hlsl/keywords.rs":"eb4af8d697fb7f3991859d66339b5b2eac27c9fe41b73146ac838b207f462c9c","src/back/hlsl/mod.rs":"c677ebbb649a1c5f85f350d8da7129457d50ff52b1c88c1f0fac4a9d11eb020c","src/back/hlsl/storage.rs":"3170f165ff68d2482f8a8dbfa4bbf4b65d2446a7f208f33eea9eb187bb57eb09","src/back/hlsl/writer.rs":"8e61501bae6982273a525734d3e446694d4bf7a081419ec312c32b354e89d3ef","src/back/mod.rs":"b941caed50c086f49d25e76228d247ba6c2da6dbeea18d968c02dc68bb97f409","src/back/msl/keywords.rs":"998c0d86a26e5cf031c75f35cde28f2b390fe207a2e7d0eed8516ffdb99c1a8e","src/back/msl/mod.rs":"16d905902e30cf900ec924b66ff496adbbbc54af15c59713f358bfac042a625a","src/back/msl/sampler.rs":"9b01d68669e12ff7123243284b85e1a9d2c4d49140bd74ca32dedc007cbf15af","src/back/msl/writer.rs":"9503df4ae10d1d7b6840cb68e2e2ff4f7ed8761b217faa99e6927d87da546071","src/back/spv/block.rs":"976c0856d25dc0f54f4b5039b5e101088f32a92c373c7449682e9c8d64fc48c0","src/back/spv/helpers.rs":"a4e260130f39c7345decec40dadf1e94419c8f6d236ce7a53b5300aa72952a1b","src/back/spv/image.rs":"5840a6d5cdffbf30cb20a76ddfdb468041fc6b687a476b3b2fc2553bda6f4af7","src/back/spv/index.rs":"26611dd50df5cfd214900e19415f5374dd301d3b7d3bfedbc5ec0f254328287a","src/back/spv/instructions.rs":"d0ced535fdec49323105a7d6ee40a8ed6b4966ac5f0f40b062f0eb11a531b106","src/back/spv/layout.rs":"e263de53cd2f9a03ad94b82b434ce636609bc1ed435a2d1132951663bfaa8ebd","src/back/spv/mod.rs":"31b0229f59b5784b57851fcf6325095add58af6de3afa85d518a4e266c4b99a9","src/back/spv/ray.rs":"a34bf6b26d873f7270caa45841d9ef291aca8d9732ecd086b14d8856038e1e41","src/back/spv/recyclable.rs":"114db0ea12774d6514f995d07295cb9a42631ab75165fc60980c10e9b5ecb832","src/back/spv/selection.rs":"81e404abfa0a977f7c1f76ccb37a78d13ccadbda229048dad53cc67687cc39db","src/back/spv/writer.rs":"a76a73c0692162da24ab5508bc3ca70eb5e01367fe54472d100e237dbd594467","src/back/wgsl/mod.rs":"2dd12bbea9ace835850192bb68c5760953da6bac6a636073d1eca19381c0c0b6","src/back/wgsl/writer.rs":"f996c393aac339139eed8592b5fdd15fc786a49d3542985dc8ecb07f549a77ea","src/block.rs":"c69089e5bbb6de6ba24efb15b21d5d434fcabfbc4d48feae948d2a4da135aae7","src/compact/expressions.rs":"7a4c916282a5b484519ed29ab451c7b595d8dea73c83c5c2cf7efc6fbc648fda","src/compact/functions.rs":"174bd9167ecf6353afb8c36d365ba3f9b483233eb4bacf578e50183c7433aa15","src/compact/handle_set_map.rs":"817c5193352d5fd6a61a5c970daba23224e14a65aea15f8f1c8679c99f834ca2","src/compact/mod.rs":"8abea7a8a9870d953fb628a32bac2bc15e87e077910cb95aa1f26e58a0a35c2a","src/compact/statements.rs":"4df33ee9589300e769e75c674bdc30578e93704ec3eb2aabc7132121745b55c8","src/compact/types.rs":"18343f2ca2c123eea2531cffc1d54a7798797caccecaa1f9b8c4fd5dd6ca1a05","src/front/glsl/ast.rs":"2ae292c09fed43951e20ec6ce0b7b99efe91726cf90487d6c129137b08618e01","src/front/glsl/builtins.rs":"d35501d5b42b61c261da24436b82eafdf96371b1600d148648d90d041f736ae4","src/front/glsl/context.rs":"2f07a63209258a8459ae6a6ef8277313c4dc771ab96ef6f5ab3a383a0d3599ba","src/front/glsl/error.rs":"08409f8cc13b73c6eda938ff7ebf2b46e9d27c66d718d640ad8d6a33fddbb7a1","src/front/glsl/functions.rs":"60838c34b8295112e5696b52d710acebb93e0a982e05f8eb87d3b80f52eb7793","src/front/glsl/lex.rs":"08736ae8beb955da5b0e6e3e0f45995a824995f7096d516a2910417e9c7afa32","src/front/glsl/mod.rs":"c8e435a894d641e6c92fcd7d357d51e1136af1a69410fbaedb88c7262b2269df","src/front/glsl/offset.rs":"9358602ca4f9ef21d5066d674dae757bf88fdf5c289c4360534354d13bd41dc0","src/front/glsl/parser.rs":"fe5291512db412b33b6c09d5b3dcf7c54ff6ec55b47f0a078dcc11695e78471d","src/front/glsl/parser/declarations.rs":"d637cc52e553910a2e97b70b3366c15aefbe737f413adb11c27efd184c1fbf9d","src/front/glsl/parser/expressions.rs":"520cfc9402d5fbd48e52ef1d36562c6b74794c09ec33ec1ebb10aa48d129b66f","src/front/glsl/parser/functions.rs":"670ca6bba5a56f3919968658966b05ba824c2d76427b8927d4b111f715091629","src/front/glsl/parser/types.rs":"0971bc98cbde1d70c0ced1717c8726a12a5bfafa9a72b127ed242db5435ec8a8","src/front/glsl/parser_tests.rs":"fc2120fff132af850b52f9ac5d19f0c2fce7997b17ba49881b155d173359cfd3","src/front/glsl/token.rs":"42325adbef5bfc9e6f9e40e7ed3cbfa7ef498c05799fdb7694b123e6450410e1","src/front/glsl/types.rs":"58c9cf3d570dff8cb68f2931faf5b18e875e510741bf035ec10b9ff6df27c5d8","src/front/glsl/variables.rs":"fb2a09e386b6e98ca9fb8fb744afac1e8b19d1b67c6ede5c474e3ba860d3d4cb","src/front/interpolator.rs":"9b6ca498d5fbd9bc1515510a04e303a00b324121d7285da3c955cfe18eb4224c","src/front/mod.rs":"6f77ca3ff925cc16e5ae46132bd6196ca4c9c80a7db123f0d2ec09aae93ba51f","src/front/spv/convert.rs":"9b4ecc53131b6250cde4cae93557eb467127e9e8d0536d29a851538684ae5371","src/front/spv/error.rs":"3129fd1fe346441d61d0f641734df7e919919db15df706788d16402ebf480607","src/front/spv/function.rs":"3a3f0c07862750f79f8ebc273c5df11efc67272566458410f776bd8fa271a0f8","src/front/spv/image.rs":"5d55cfbf6752732a594114cd09a9a207216e1ee85d8f2c9bc4310217a55ea321","src/front/spv/mod.rs":"ccbeb4b80959c00323b2459e316b7c5c7e3f313ab94f2151fa44a2dee6255d4e","src/front/spv/null.rs":"e1446d99d04c76a9c3bbd24dd9b20c4711ce8a918a9b403be6cccbde1175b3b4","src/front/type_gen.rs":"b4f1df23380e06c9fdad4140810ce96ab041dbb1d371a07045b4e0069aa8ba55","src/front/wgsl/error.rs":"a2abfd483afe46e1e80d47568ea56c2d587de8dd6291739b03de788f37dada0e","src/front/wgsl/index.rs":"2b9a4929a46bd822d3ed6f9a150e24d437e5bdca8293eb748aebe80ce7e74153","src/front/wgsl/lower/construction.rs":"48b2c1b0ef93345bc3cdbf1af29690cc128a4507f0b9d7d908a136f4c0fd48ca","src/front/wgsl/lower/conversion.rs":"6d123e0148fc6d5b8df3d218ce1978a154d0edb86f65ca20fdc91bb4bf9475ce","src/front/wgsl/lower/mod.rs":"59df2e00495e136eb59a0d3cb6c5990a31b914cd9f6e488355a597cd72cc0f01","src/front/wgsl/mod.rs":"02b194a0a29ef7281f71b424564e18ada4a8b1a0d8c26ec40b6be195bd4c4904","src/front/wgsl/parse/ast.rs":"c7eaae40179f0889f2b142d3b31968cbfab6d3cfe02e425912c6da8dadac51df","src/front/wgsl/parse/conv.rs":"01b25edbe80b263a3fa51bc980c075630bb31d4af851441323383eb4f3b83360","src/front/wgsl/parse/lexer.rs":"bff1d0e3cd920b2e9342b521bed7483595556b90088dc0b22e1599900585ff8e","src/front/wgsl/parse/mod.rs":"3b4895a2baf91c719b95f0afb6441ffac2036c2a9ff817e633882fd257afcc38","src/front/wgsl/parse/number.rs":"623423471a13cf9a45662ee3ac01554644ac544338c7493cfe6087549bab91f7","src/front/wgsl/tests.rs":"39d0b44d0f073a7599c88b7c4efd1572886f3af074fa2015454623be313b297f","src/front/wgsl/to_wgsl.rs":"2e2e30d86b07f209b866e530d3a882803bf28b39ce379052561a749f628e8e28","src/keywords/mod.rs":"0138f3931f8af0b0a05174549d0fd2152945b027dc3febefc1bbd676581d2e45","src/keywords/wgsl.rs":"7c3b364b60ca29cb8a68ef781de9ecd28b76b74bed18bf18a35d2ebffaa855ab","src/lib.rs":"c5d91c603ae310a7ef9ff8444898959a3dbbc32ba262cabb1fd5682823921d98","src/proc/constant_evaluator.rs":"0f55fb6f8310dee8dc021f27ab5c3c0ed896963f82150346fcdfbefc47b5e4a1","src/proc/emitter.rs":"39ac886c651e2ad33c06a676a7e4826a0e93de0af660c01e8e4b1f7406742f88","src/proc/index.rs":"f4250f6944c2b631e8140979024e8deb86fa8d5352d8641ba954a388b2c0940e","src/proc/layouter.rs":"b3d061c87424f36981c902716f37ab7b72f2bb2d0c2d7e900c51149318ea1a0a","src/proc/mod.rs":"e6ce6a376aa4e3584f0386fdbe95c7ea2a93abe19b03cc261b6152c8fca24842","src/proc/namer.rs":"7328fac41e40890c64c7ee2fa985a4395424f18b08d30f30ca2583fdabd2fd35","src/proc/terminator.rs":"13c59bf00f5b26171d971effc421091f5e00dedddd246c2daa44fe65aeda060a","src/proc/typifier.rs":"99de19270d01c12ec49d14323aa1d9b8774f1ee715804af7235deff70739ba3d","src/span.rs":"6560599f20b8bc2de746ee9fd6b05c32bb630af914fce8845d84fdc72f9a636c","src/valid/analyzer.rs":"8472b98f16a4a4a0fa7079197db25696f77ef3e1602a7cddea1930daebd27917","src/valid/compose.rs":"71a86bd4183f358c4ea25e7b512f318413956947c8035d2b8dc1f3fe7db4ecd2","src/valid/expression.rs":"1cdbd594dbdb33d8473d93c11112cf717e262bb8c35cee10b01db4322b2237d7","src/valid/function.rs":"5ec31146aacf7daae689836ff3e2978f075f2cc62b3fd829d09c760a6e606501","src/valid/handles.rs":"0878915e67b16d7c41cf8245d9ab3b3f4a604e7d4e87527ea40e03efcbf1f74a","src/valid/interface.rs":"6ddf5f8d5150342d2e8c754a71c92c85d8533fd1d4c6b7a83a05b508e8e8114d","src/valid/mod.rs":"9e2bafa06bea16db2c5a8f825eed4d008c474b87cda2fc7e82ca7a21229c6f20","src/valid/type.rs":"09e18bb9510dbb0cfb4a8ac054afee4c4f56063d614159ab5b956aa1e5850468"},"package":null} \ No newline at end of file diff --git a/third_party/rust/naga/src/front/wgsl/lower/mod.rs b/third_party/rust/naga/src/front/wgsl/lower/mod.rs index b050ffc343d77..6486e6cf6b4e9 100644 --- a/third_party/rust/naga/src/front/wgsl/lower/mod.rs +++ b/third_party/rust/naga/src/front/wgsl/lower/mod.rs @@ -875,10 +875,30 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { ast::GlobalDeclKind::Var(ref v) => { let ty = self.resolve_ast_type(v.ty, &mut ctx)?; - let init = v - .init - .map(|init| self.expression(init, &mut ctx.as_const())) - .transpose()?; + let init; + if let Some(init_ast) = v.init { + let mut ectx = ctx.as_const(); + let lowered = self.expression_for_abstract(init_ast, &mut ectx)?; + let ty_res = crate::proc::TypeResolution::Handle(ty); + let converted = ectx + .try_automatic_conversions(lowered, &ty_res, v.name.span) + .map_err(|error| match error { + Error::AutoConversion { + dest_span: _, + dest_type, + source_span: _, + source_type, + } => Error::InitializationTypeMismatch { + name: v.name.span, + expected: dest_type, + got: source_type, + }, + other => other, + })?; + init = Some(converted); + } else { + init = None; + } let binding = if let Some(ref binding) = v.binding { Some(crate::ResourceBinding { @@ -1142,45 +1162,49 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { return Ok(()); } ast::LocalDecl::Var(ref v) => { - let mut emitter = Emitter::default(); - emitter.start(&ctx.function.expressions); - - let initializer = match v.init { - Some(init) => Some( - self.expression(init, &mut ctx.as_expression(block, &mut emitter))?, - ), - None => None, - }; - let explicit_ty = - v.ty.map(|ty| self.resolve_ast_type(ty, &mut ctx.as_global())) + v.ty.map(|ast| self.resolve_ast_type(ast, &mut ctx.as_global())) .transpose()?; - let ty = match (explicit_ty, initializer) { - (Some(explicit), Some(initializer)) => { - let mut ctx = ctx.as_expression(block, &mut emitter); - let initializer_ty = resolve_inner!(ctx, initializer); - if !ctx.module.types[explicit] - .inner - .equivalent(initializer_ty, &ctx.module.types) - { - let gctx = &ctx.module.to_ctx(); - return Err(Error::InitializationTypeMismatch { + let mut emitter = Emitter::default(); + emitter.start(&ctx.function.expressions); + let mut ectx = ctx.as_expression(block, &mut emitter); + + let ty; + let initializer; + match (v.init, explicit_ty) { + (Some(init), Some(explicit_ty)) => { + let init = self.expression_for_abstract(init, &mut ectx)?; + let ty_res = crate::proc::TypeResolution::Handle(explicit_ty); + let init = ectx + .try_automatic_conversions(init, &ty_res, v.name.span) + .map_err(|error| match error { + Error::AutoConversion { + dest_span: _, + dest_type, + source_span: _, + source_type, + } => Error::InitializationTypeMismatch { name: v.name.span, - expected: explicit.to_wgsl(gctx), - got: initializer_ty.to_wgsl(gctx), - }); - } - explicit + expected: dest_type, + got: source_type, + }, + other => other, + })?; + ty = explicit_ty; + initializer = Some(init); } - (Some(explicit), None) => explicit, - (None, Some(initializer)) => ctx - .as_expression(block, &mut emitter) - .register_type(initializer)?, - (None, None) => { - return Err(Error::MissingType(v.name.span)); + (Some(init), None) => { + let concretized = self.expression(init, &mut ectx)?; + ty = ectx.register_type(concretized)?; + initializer = Some(concretized); } - }; + (None, Some(explicit_ty)) => { + ty = explicit_ty; + initializer = None; + } + (None, None) => return Err(Error::MissingType(v.name.span)), + } let (const_initializer, initializer) = { match initializer { diff --git a/third_party/rust/wgpu-core/.cargo-checksum.json b/third_party/rust/wgpu-core/.cargo-checksum.json index cdc6e2013d442..1878a858cef5c 100644 --- a/third_party/rust/wgpu-core/.cargo-checksum.json +++ b/third_party/rust/wgpu-core/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"5119648ea52e97ad3fa2f0f24cc30e0b305fe81f710a33396bdadaf7397d41b9","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","src/any_surface.rs":"1afed4e5e2cc1726c9887bfbf8805f9141f859615c1eaf90f4ef3e49850caf06","src/binding_model.rs":"b709658ed6b9af2ed07ff77b8da64912cd26a9d7caaecee26c77a92efdc615d4","src/command/bind.rs":"85bbab812222f9bc11893059304cac850616818b00857fadac4885b978e4cfe2","src/command/bundle.rs":"7836b3740ad32168fdfb4241dbc91839d695c019abd3c38e3decec332b7e82c2","src/command/clear.rs":"8929095abd1508fdbc4b51db1bcfe513f77954fcfb269888c91b47c90b943c03","src/command/compute.rs":"296864d4f9e9a98f368d64910146480e38e2f895eee98a97d947dd593033f87c","src/command/draw.rs":"3687cbde422a29f28c1c3d17e132d912b3b4b2bcc98efca68d1ee0d563a5bf56","src/command/memory_init.rs":"ffe5c301f19a17285523ee8fd5e7bf5abd5e50e9a3716f5713ac99ab135d9f5e","src/command/mod.rs":"9ffa26b0306067ad63fc61fbde985ad98d495a2ad739f51bf54a39f702f45d3a","src/command/query.rs":"f31db3f1282109baa59e6dcd7b2e674c7858a2c64f58fc6eb3a4d0c546935af5","src/command/render.rs":"61a9f34d813700606b49224d9de19773c49eb3dd42fa4027357a334dc63e2579","src/command/transfer.rs":"60969f020bddfb88a0c3b459b72b94d3a9a96cc635d20e88d016765d0fb94ba5","src/conv.rs":"7e3ffe33b47a6fd3617aabf9f11cc68f1ccbee2c7343b8dbbcd0e8f3447e1ad8","src/device/any_device.rs":"2cb2be0fd078d65039692d309d8688cf4a02fb768579cf22c93cfa514d20ad7f","src/device/global.rs":"33c47e5aaa44ad4a485a996af52247e765bedfa18724ab7662ce34c78754448b","src/device/life.rs":"bbda212777bf5156feb9ee4c46d7c7621888c11544903a26bf86e7b708590f5a","src/device/mod.rs":"4ec88e037307e597fc661c85c9fa28f2d70a82a222a5fec5c97c450d33224f37","src/device/queue.rs":"9525b939e49b4c2860928c04a660a4556b34bfbed23e00318635a5ad46bce061","src/device/resource.rs":"a47f4d8b605c477fc6a63058e1340872590631c9a1a7f4e454bbbbe01aada757","src/device/trace.rs":"9a8ec674567a8866a6bd1ed2ad06e474bd2504ed91f228d3040cb6db18fe5f2b","src/error.rs":"32680e922acfb1f1d6842177179768d365c575a8baa402da9d5a43a2357b0dbf","src/global.rs":"9aa9448791477007b850c5eb1584e7c74c14fe43ac47ab3b5f29373850f463ee","src/hal_api.rs":"bb380df266fa9754c93d55c24b1a3535629710eb04bc6858a40c38a5f02aae68","src/hub.rs":"d9435f5b12f47e0b57599dce1d38e6eb4ef2477ab634806cfccefa4c1541f87b","src/id.rs":"0aa4258f93e05f6991385980a553e67892a0f1769e37624ae0466f83161af697","src/identity.rs":"0701f6f41e754dde2bebc567a87c25b353dfab40b79a322990dbfa477739ab8c","src/init_tracker/buffer.rs":"61eb9cfaa312135b7a937ff6a3117f531b5b7323fae6553a41d6de9bc106d7e0","src/init_tracker/mod.rs":"0867f79f83555390d0982d1dc6dcf0d4340e10cb89aa633d3c3ecc45deb3c78c","src/init_tracker/texture.rs":"030fd594bf9948fad391390d85c5e1fec7eaf67b6e812c60f2dd59bc4fda8fd5","src/instance.rs":"46b13911e15310a7ced4e5f13eeaa5d2cde7762b8ffa282a28d0c812e7036458","src/lib.rs":"9408b33250c7062599045cc11dd1f52d6036415f0e5c568b37c73348b330bb7c","src/pipeline.rs":"1d615e582254cfa108dd1925df7b6b0ae0c9845714b1351b8bcd4c7aa4b4dd69","src/present.rs":"1c28d6dbc3125b5eebd12265013618d8585d5c90f3fd1d3529c20e41e1ddecb3","src/registry.rs":"e93369ae372b133649b554a3d0338d74823cfded8b7e84d01bf1f000b670f471","src/resource.rs":"be6b9b648911c2277d9f88ca9e9a2811ec28fdf8118e009a47de0c16179f28aa","src/storage.rs":"6ba6416522ba2f1d2a279c220960aabdfb071c4e0ade888c8cbc2b91325c4203","src/track/buffer.rs":"a6762fad8bf5b257d37fb8844f0ee44ecb04f052c58655404b8af0036ac929e5","src/track/metadata.rs":"f8994ad91db7f3bb1b7f8b8b0f6884753d733ce28238b36f31da2230706f848e","src/track/mod.rs":"5fdef0bcf20999fda97342e261341809394dcad3ee97e2bc2429c5a1e41d48d5","src/track/range.rs":"5bbfed6e103b3234d9de8e42057022da6d628c2cc1db6bb51b88f87f2d8adf8b","src/track/stateless.rs":"65142de8e8425eee26e32bfef8169af3ed0e98455d5e470517717a3c15e8036c","src/track/texture.rs":"d4e92ef3400cf48b2e76d8b7c1e4c6a1cef0d3d060c6abdb46b9a3b386bc9dc9","src/validation.rs":"4bd36b7b02ad0122fda719790d40cc68058e0f8e3ba3cd622f1d76db377320f9"},"package":null} \ No newline at end of file +{"files":{"Cargo.toml":"7d8b06bcc217e1e9a23ad63e2e9d9403f2ef58ab257c222233403c3e57a642e7","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","src/any_surface.rs":"c5e961783be28548681c3c38579ea0b5724c5336848216a423e83a0db2208ece","src/binding_model.rs":"ba1849e89e7dae7cd29635b57dc3140e47389e7aa38732b03c4cad693444680c","src/command/bind.rs":"85bbab812222f9bc11893059304cac850616818b00857fadac4885b978e4cfe2","src/command/bundle.rs":"7836b3740ad32168fdfb4241dbc91839d695c019abd3c38e3decec332b7e82c2","src/command/clear.rs":"8929095abd1508fdbc4b51db1bcfe513f77954fcfb269888c91b47c90b943c03","src/command/compute.rs":"296864d4f9e9a98f368d64910146480e38e2f895eee98a97d947dd593033f87c","src/command/draw.rs":"3687cbde422a29f28c1c3d17e132d912b3b4b2bcc98efca68d1ee0d563a5bf56","src/command/memory_init.rs":"ffe5c301f19a17285523ee8fd5e7bf5abd5e50e9a3716f5713ac99ab135d9f5e","src/command/mod.rs":"9ffa26b0306067ad63fc61fbde985ad98d495a2ad739f51bf54a39f702f45d3a","src/command/query.rs":"f31db3f1282109baa59e6dcd7b2e674c7858a2c64f58fc6eb3a4d0c546935af5","src/command/render.rs":"61a9f34d813700606b49224d9de19773c49eb3dd42fa4027357a334dc63e2579","src/command/transfer.rs":"60969f020bddfb88a0c3b459b72b94d3a9a96cc635d20e88d016765d0fb94ba5","src/conv.rs":"7e3ffe33b47a6fd3617aabf9f11cc68f1ccbee2c7343b8dbbcd0e8f3447e1ad8","src/device/any_device.rs":"2cb2be0fd078d65039692d309d8688cf4a02fb768579cf22c93cfa514d20ad7f","src/device/global.rs":"634619218859faa1dbd789b79a9ae2186cef950c50e3f9b1c4850d36bd1c8f16","src/device/life.rs":"a3d52432d7aff41d9f5bcf3b2da70d73f28847516d5909894328b78d2867b7ee","src/device/mod.rs":"d6a8ce711b8891c469c4b47348a3ce48d84ea4a356c0b05ec7e128d21a440562","src/device/queue.rs":"9525b939e49b4c2860928c04a660a4556b34bfbed23e00318635a5ad46bce061","src/device/resource.rs":"26f2681c2539b0fa6e242690ebafc6664e08a501a98bdf15e13555ac5f8769b1","src/device/trace.rs":"9a8ec674567a8866a6bd1ed2ad06e474bd2504ed91f228d3040cb6db18fe5f2b","src/error.rs":"32680e922acfb1f1d6842177179768d365c575a8baa402da9d5a43a2357b0dbf","src/global.rs":"c0a590e0136bf19a63ddc87dd3f0bbfbe24bcb810d0ccfc6c5f26631750d63ea","src/hal_api.rs":"3ee0f5e66b313fd1b8c79b3d73f0f1dbde88676b651d79518fa2dc5aff0ab856","src/hub.rs":"4cec8de74a661bb628040ff457d38faf8c92d0824c4d5a4955834d56ebd25926","src/id.rs":"76f6fbff7ac094b2d81e98e198b9d8785f11885e42015208fc362c368298c41f","src/identity.rs":"0701f6f41e754dde2bebc567a87c25b353dfab40b79a322990dbfa477739ab8c","src/init_tracker/buffer.rs":"61eb9cfaa312135b7a937ff6a3117f531b5b7323fae6553a41d6de9bc106d7e0","src/init_tracker/mod.rs":"0867f79f83555390d0982d1dc6dcf0d4340e10cb89aa633d3c3ecc45deb3c78c","src/init_tracker/texture.rs":"030fd594bf9948fad391390d85c5e1fec7eaf67b6e812c60f2dd59bc4fda8fd5","src/instance.rs":"e1d4af51bb445850d9e2d7d12b239413bb555f07f95d3a1851cc73443c5c18f0","src/lib.rs":"a7c46d675920b64284bf0494b749a9ffd3661a8c3ce6d4e00c399e5414dbf12d","src/pipeline.rs":"2ae1c803ba37d2114a31aa87a515555e7fc42b337f169f7a1cd7ce4568f92f30","src/present.rs":"1c28d6dbc3125b5eebd12265013618d8585d5c90f3fd1d3529c20e41e1ddecb3","src/registry.rs":"c259ca61dd5f2b632ff2ee871f82727921fa48dee15253872799af1dda77484b","src/resource.rs":"f3ad01be1943793fa2a469056388d0e14b3cf869f610fac11f556f5bc7ee8f86","src/storage.rs":"6ba6416522ba2f1d2a279c220960aabdfb071c4e0ade888c8cbc2b91325c4203","src/track/buffer.rs":"a6762fad8bf5b257d37fb8844f0ee44ecb04f052c58655404b8af0036ac929e5","src/track/metadata.rs":"f8994ad91db7f3bb1b7f8b8b0f6884753d733ce28238b36f31da2230706f848e","src/track/mod.rs":"5fdef0bcf20999fda97342e261341809394dcad3ee97e2bc2429c5a1e41d48d5","src/track/range.rs":"5bbfed6e103b3234d9de8e42057022da6d628c2cc1db6bb51b88f87f2d8adf8b","src/track/stateless.rs":"65142de8e8425eee26e32bfef8169af3ed0e98455d5e470517717a3c15e8036c","src/track/texture.rs":"d4e92ef3400cf48b2e76d8b7c1e4c6a1cef0d3d060c6abdb46b9a3b386bc9dc9","src/validation.rs":"4bd36b7b02ad0122fda719790d40cc68058e0f8e3ba3cd622f1d76db377320f9"},"package":null} \ No newline at end of file diff --git a/third_party/rust/wgpu-core/Cargo.toml b/third_party/rust/wgpu-core/Cargo.toml index 40858e00e4fff..85a5e896e4c40 100644 --- a/third_party/rust/wgpu-core/Cargo.toml +++ b/third_party/rust/wgpu-core/Cargo.toml @@ -83,7 +83,6 @@ package = "wgpu-types" [features] api_log_info = [] default = ["link"] -dx11 = ["hal/dx11"] dx12 = ["hal/dx12"] fragile-send-sync-non-atomic-wasm = [ "hal/fragile-send-sync-non-atomic-wasm", diff --git a/third_party/rust/wgpu-core/src/any_surface.rs b/third_party/rust/wgpu-core/src/any_surface.rs index 757e5c152b864..5ae3295dc1992 100644 --- a/third_party/rust/wgpu-core/src/any_surface.rs +++ b/third_party/rust/wgpu-core/src/any_surface.rs @@ -35,10 +35,6 @@ impl AnySurface { if self.downcast_ref::().is_some() { return Backend::Dx12; } - #[cfg(all(feature = "dx11", windows))] - if self.downcast_ref::().is_some() { - return Backend::Dx11; - } #[cfg(feature = "gles")] if self.downcast_ref::().is_some() { return Backend::Gl; diff --git a/third_party/rust/wgpu-core/src/binding_model.rs b/third_party/rust/wgpu-core/src/binding_model.rs index 826e4c9bc8b2f..1b5cff866847d 100644 --- a/third_party/rust/wgpu-core/src/binding_model.rs +++ b/third_party/rust/wgpu-core/src/binding_model.rs @@ -341,6 +341,7 @@ impl BindingTypeMaxCountValidator { wgt::BindingType::StorageTexture { .. } => { self.storage_textures.add(binding.visibility, count); } + wgt::BindingType::AccelerationStructure => todo!(), } } @@ -460,7 +461,6 @@ pub struct BindGroupLayout { pub(crate) dynamic_count: usize, pub(crate) count_validator: BindingTypeMaxCountValidator, pub(crate) info: ResourceInfo, - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -488,10 +488,7 @@ impl Resource for BindGroupLayout { } fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.label.clone() } } impl BindGroupLayout { diff --git a/third_party/rust/wgpu-core/src/device/global.rs b/third_party/rust/wgpu-core/src/device/global.rs index b043e2106cbf8..7a6caec6c99cd 100644 --- a/third_party/rust/wgpu-core/src/device/global.rs +++ b/third_party/rust/wgpu-core/src/device/global.rs @@ -4,7 +4,7 @@ use crate::{ api_log, binding_model, command, conv, device::{ life::WaitIdleError, map_buffer, queue, DeviceError, DeviceLostClosure, HostMap, - IMPLICIT_FAILURE, + IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL, }, global::Global, hal_api::HalApi, @@ -526,7 +526,7 @@ impl Global { if wait { match device.wait_for_submit(last_submit_index) { Ok(()) => (), - Err(e) => log::error!("Failed to wait for buffer {:?}: {:?}", buffer_id, e), + Err(e) => log::error!("Failed to wait for buffer {:?}: {}", buffer_id, e), } } } @@ -574,7 +574,7 @@ impl Global { return (id, None); }; - log::error!("Device::create_texture error {error:?}"); + log::error!("Device::create_texture error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) @@ -648,7 +648,7 @@ impl Global { return (id, None); }; - log::error!("Device::create_texture error {error:?}"); + log::error!("Device::create_texture error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) @@ -702,7 +702,7 @@ impl Global { return (id, None); }; - log::error!("Device::create_buffer error {error:?}"); + log::error!("Device::create_buffer error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) @@ -790,7 +790,7 @@ impl Global { if wait { match device.wait_for_submit(last_submit_index) { Ok(()) => (), - Err(e) => log::error!("Failed to wait for texture {:?}: {:?}", texture_id, e), + Err(e) => log::error!("Failed to wait for texture {texture_id:?}: {e}"), } } } @@ -835,7 +835,7 @@ impl Global { return (id, None); }; - log::error!("Texture::create_view({texture_id:?}) error {error:?}"); + log::error!("Texture::create_view({texture_id:?}) error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) } @@ -865,11 +865,9 @@ impl Global { if wait { match view.device.wait_for_submit(last_submit_index) { Ok(()) => (), - Err(e) => log::error!( - "Failed to wait for texture view {:?}: {:?}", - texture_view_id, - e - ), + Err(e) => { + log::error!("Failed to wait for texture view {texture_view_id:?}: {e}") + } } } } @@ -1217,7 +1215,7 @@ impl Global { return (id, None); }; - log::error!("Device::create_shader_module error: {error:?}"); + log::error!("Device::create_shader_module error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) @@ -1274,7 +1272,7 @@ impl Global { return (id, None); }; - log::error!("Device::create_shader_module_spirv error: {error:?}"); + log::error!("Device::create_shader_module_spirv error: {error}"); let id = fid.assign_error(desc.label.borrow_or_default()); (id, Some(error)) @@ -1589,16 +1587,16 @@ impl Global { if pipeline_layout_guard.contains(ids.root_id) { pipeline_layout_guard.remove(ids.root_id); } - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { if bgl_guard.contains(bgl_id) { bgl_guard.remove(bgl_id); } - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } - log::error!("Device::create_render_pipeline error {error:?}"); + log::error!("Device::create_render_pipeline error: {error}"); (id, Some(error)) } @@ -1723,12 +1721,12 @@ impl Global { if pipeline_layout_guard.contains(ids.root_id) { pipeline_layout_guard.remove(ids.root_id); } - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { if bgl_guard.contains(bgl_id) { bgl_guard.remove(bgl_id); } - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } (id, Some(error)) @@ -2180,11 +2178,6 @@ impl Global { all_queue_empty = self.poll_device::(force_wait, &mut closures)? && all_queue_empty; } - #[cfg(all(feature = "dx11", windows))] - { - all_queue_empty = - self.poll_device::(force_wait, &mut closures)? && all_queue_empty; - } #[cfg(feature = "gles")] { all_queue_empty = @@ -2321,7 +2314,7 @@ impl Global { if let Some(callback) = operation.callback.take() { callback.call(Err(err.clone())); } - log::error!("Buffer::map_async error {err:?}"); + log::error!("Buffer::map_async error: {err}"); return Err(err); } diff --git a/third_party/rust/wgpu-core/src/device/life.rs b/third_party/rust/wgpu-core/src/device/life.rs index 8b421c11af56d..0193d0987bfa8 100644 --- a/third_party/rust/wgpu-core/src/device/life.rs +++ b/third_party/rust/wgpu-core/src/device/life.rs @@ -930,7 +930,7 @@ impl LifetimeTracker { Ok(()) } Err(e) => { - log::error!("Mapping failed {:?}", e); + log::error!("Mapping failed: {e}"); Err(e) } } diff --git a/third_party/rust/wgpu-core/src/device/mod.rs b/third_party/rust/wgpu-core/src/device/mod.rs index ad34876ebe2ae..b8ebaf46c8e06 100644 --- a/third_party/rust/wgpu-core/src/device/mod.rs +++ b/third_party/rust/wgpu-core/src/device/mod.rs @@ -27,15 +27,15 @@ pub mod resource; pub mod trace; pub use {life::WaitIdleError, resource::Device}; -pub const SHADER_STAGE_COUNT: usize = 3; +pub const SHADER_STAGE_COUNT: usize = hal::MAX_CONCURRENT_SHADER_STAGES; // Should be large enough for the largest possible texture row. This // value is enough for a 16k texture with float4 format. pub(crate) const ZERO_BUFFER_SIZE: BufferAddress = 512 << 10; const CLEANUP_WAIT_MS: u32 = 5000; -const IMPLICIT_FAILURE: &str = "failed implicit"; -const EP_FAILURE: &str = "EP is invalid"; +const IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL: &str = "Implicit BindGroupLayout in the Error State"; +const ENTRYPOINT_FAILURE_ERROR: &str = "The given EntryPoint is Invalid"; pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; diff --git a/third_party/rust/wgpu-core/src/device/resource.rs b/third_party/rust/wgpu-core/src/device/resource.rs index b6ee9aec073d4..815cdd80a9123 100644 --- a/third_party/rust/wgpu-core/src/device/resource.rs +++ b/third_party/rust/wgpu-core/src/device/resource.rs @@ -53,8 +53,8 @@ use std::{ use super::{ life::{self, ResourceMaps}, queue::{self}, - DeviceDescriptor, DeviceError, ImplicitPipelineContext, UserClosures, EP_FAILURE, - IMPLICIT_FAILURE, ZERO_BUFFER_SIZE, + DeviceDescriptor, DeviceError, ImplicitPipelineContext, UserClosures, ENTRYPOINT_FAILURE_ERROR, + IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL, ZERO_BUFFER_SIZE, }; /// Structure describing a logical device. Some members are internally mutable, @@ -268,7 +268,7 @@ impl Device { Some(trace) } Err(e) => { - log::error!("Unable to start a trace in '{:?}': {:?}", path, e); + log::error!("Unable to start a trace in '{path:?}': {e}"); None } })), @@ -1422,7 +1422,6 @@ impl Device { device: self.clone(), interface: Some(interface), info: ResourceInfo::new(desc.label.borrow_or_default()), - #[cfg(debug_assertions)] label: desc.label.borrow_or_default().to_string(), }) } @@ -1464,7 +1463,6 @@ impl Device { device: self.clone(), interface: None, info: ResourceInfo::new(desc.label.borrow_or_default()), - #[cfg(debug_assertions)] label: desc.label.borrow_or_default().to_string(), }) } @@ -1642,6 +1640,7 @@ impl Device { }, ) } + Bt::AccelerationStructure => todo!(), }; // Validate the count parameter @@ -1723,14 +1722,13 @@ impl Device { Ok(BindGroupLayout { raw: Some(raw), device: self.clone(), - info: ResourceInfo::new(label.unwrap_or("")), + info: ResourceInfo::new(label.unwrap_or("")), dynamic_count: entry_map .values() .filter(|b| b.ty.has_dynamic_offset()) .count(), count_validator, entries: entry_map, - #[cfg(debug_assertions)] label: label.unwrap_or_default().to_string(), }) } @@ -2136,6 +2134,7 @@ impl Device { buffers: &hal_buffers, samplers: &hal_samplers, textures: &hal_textures, + acceleration_structures: &[], }; let raw = unsafe { self.raw @@ -2491,10 +2490,10 @@ impl Device { // that are not even in the storage. if let Some(ref ids) = implicit_context { let mut pipeline_layout_guard = hub.pipeline_layouts.write(); - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); let mut bgl_guard = hub.bind_group_layouts.write(); for &bgl_id in ids.group_ids.iter() { - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } @@ -2588,7 +2587,7 @@ impl Device { pipeline::CreateComputePipelineError::Internal(msg) } hal::PipelineError::EntryPoint(_stage) => { - pipeline::CreateComputePipelineError::Internal(EP_FAILURE.to_string()) + pipeline::CreateComputePipelineError::Internal(ENTRYPOINT_FAILURE_ERROR.to_string()) } })?; @@ -2620,9 +2619,9 @@ impl Device { //TODO: only lock mutable if the layout is derived let mut pipeline_layout_guard = hub.pipeline_layouts.write(); let mut bgl_guard = hub.bind_group_layouts.write(); - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } @@ -3146,7 +3145,7 @@ impl Device { hal::PipelineError::EntryPoint(stage) => { pipeline::CreateRenderPipelineError::Internal { stage: hal::auxil::map_naga_stage(stage), - error: EP_FAILURE.to_string(), + error: ENTRYPOINT_FAILURE_ERROR.to_string(), } } })?; @@ -3358,7 +3357,7 @@ impl Device { .unwrap() .wait(fence, current_index, CLEANUP_WAIT_MS) } { - log::error!("failed to wait for the device: {:?}", error); + log::error!("failed to wait for the device: {error}"); } let mut life_tracker = self.lock_life(); let _ = life_tracker.triage_submissions( diff --git a/third_party/rust/wgpu-core/src/global.rs b/third_party/rust/wgpu-core/src/global.rs index 5de766f61f3a3..e1c3d8c6d4b0c 100644 --- a/third_party/rust/wgpu-core/src/global.rs +++ b/third_party/rust/wgpu-core/src/global.rs @@ -22,8 +22,6 @@ pub struct GlobalReport { pub metal: Option, #[cfg(all(feature = "dx12", windows))] pub dx12: Option, - #[cfg(all(feature = "dx11", windows))] - pub dx11: Option, #[cfg(feature = "gles")] pub gl: Option, } @@ -40,8 +38,6 @@ impl GlobalReport { Backend::Metal => self.metal.as_ref().unwrap(), #[cfg(all(feature = "dx12", windows))] Backend::Dx12 => self.dx12.as_ref().unwrap(), - #[cfg(all(feature = "dx11", windows))] - Backend::Dx11 => self.dx11.as_ref().unwrap(), #[cfg(feature = "gles")] Backend::Gl => self.gl.as_ref().unwrap(), _ => panic!("HubReport is not supported on this backend"), @@ -132,12 +128,6 @@ impl Global { } else { None }, - #[cfg(all(feature = "dx11", windows))] - dx11: if self.instance.dx11.is_some() { - Some(self.hubs.dx11.generate_report()) - } else { - None - }, #[cfg(feature = "gles")] gl: if self.instance.gl.is_some() { Some(self.hubs.gl.generate_report()) @@ -167,10 +157,6 @@ impl Drop for Global { { self.hubs.dx12.clear(&surfaces_locked, true); } - #[cfg(all(feature = "dx11", windows))] - { - self.hubs.dx11.clear(&surfaces_locked, true); - } #[cfg(feature = "gles")] { self.hubs.gl.clear(&surfaces_locked, true); diff --git a/third_party/rust/wgpu-core/src/hal_api.rs b/third_party/rust/wgpu-core/src/hal_api.rs index cb3e25b09e2a6..a19b3c4bb7058 100644 --- a/third_party/rust/wgpu-core/src/hal_api.rs +++ b/third_party/rust/wgpu-core/src/hal_api.rs @@ -94,27 +94,6 @@ impl HalApi for hal::api::Dx12 { } } -#[cfg(all(feature = "dx11", windows))] -impl HalApi for hal::api::Dx11 { - const VARIANT: Backend = Backend::Dx11; - fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { - Instance { - name: name.to_owned(), - dx11: Some(hal_instance), - ..Default::default() - } - } - fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { - instance.dx11.as_ref() - } - fn hub(global: &Global) -> &Hub { - &global.hubs.dx11 - } - fn get_surface(surface: &Surface) -> Option<&HalSurface> { - surface.raw.downcast_ref() - } -} - #[cfg(feature = "gles")] impl HalApi for hal::api::Gles { const VARIANT: Backend = Backend::Gl; diff --git a/third_party/rust/wgpu-core/src/hub.rs b/third_party/rust/wgpu-core/src/hub.rs index 6cb9ee64d119f..a2f89f92dfa0b 100644 --- a/third_party/rust/wgpu-core/src/hub.rs +++ b/third_party/rust/wgpu-core/src/hub.rs @@ -308,15 +308,12 @@ pub struct Hubs { pub(crate) metal: Hub, #[cfg(all(feature = "dx12", windows))] pub(crate) dx12: Hub, - #[cfg(all(feature = "dx11", windows))] - pub(crate) dx11: Hub, #[cfg(feature = "gles")] pub(crate) gl: Hub, #[cfg(all( not(all(feature = "vulkan", not(target_arch = "wasm32"))), not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))), not(all(feature = "dx12", windows)), - not(all(feature = "dx11", windows)), not(feature = "gles"), ))] pub(crate) empty: Hub, @@ -331,15 +328,12 @@ impl Hubs { metal: Hub::new(factory), #[cfg(all(feature = "dx12", windows))] dx12: Hub::new(factory), - #[cfg(all(feature = "dx11", windows))] - dx11: Hub::new(factory), #[cfg(feature = "gles")] gl: Hub::new(factory), #[cfg(all( not(all(feature = "vulkan", not(target_arch = "wasm32"))), not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))), not(all(feature = "dx12", windows)), - not(all(feature = "dx11", windows)), not(feature = "gles"), ))] empty: Hub::new(factory), diff --git a/third_party/rust/wgpu-core/src/id.rs b/third_party/rust/wgpu-core/src/id.rs index 9daa0ef56c714..1782172c2ad30 100644 --- a/third_party/rust/wgpu-core/src/id.rs +++ b/third_party/rust/wgpu-core/src/id.rs @@ -131,8 +131,7 @@ where 1 => Backend::Vulkan, 2 => Backend::Metal, 3 => Backend::Dx12, - 4 => Backend::Dx11, - 5 => Backend::Gl, + 4 => Backend::Gl, _ => unreachable!(), } } @@ -156,13 +155,12 @@ where fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let (index, epoch, backend) = self.unzip(); let backend = match backend { + Backend::Empty => "_", Backend::Vulkan => "vk", Backend::Metal => "mtl", Backend::Dx12 => "d3d12", - Backend::Dx11 => "d3d11", Backend::Gl => "gl", Backend::BrowserWebGpu => "webgpu", - Backend::Empty => "_", }; write!(formatter, "Id({index},{epoch},{backend})")?; Ok(()) @@ -280,7 +278,6 @@ fn test_id_backend() { Backend::Vulkan, Backend::Metal, Backend::Dx12, - Backend::Dx11, Backend::Gl, ] { let id: Id<()> = Id::zip(1, 0, b); @@ -300,7 +297,6 @@ fn test_id() { Backend::Vulkan, Backend::Metal, Backend::Dx12, - Backend::Dx11, Backend::Gl, ]; for &i in &indexes { diff --git a/third_party/rust/wgpu-core/src/instance.rs b/third_party/rust/wgpu-core/src/instance.rs index b8340cd659881..7a12d98a6dbdf 100644 --- a/third_party/rust/wgpu-core/src/instance.rs +++ b/third_party/rust/wgpu-core/src/instance.rs @@ -68,8 +68,6 @@ pub struct Instance { pub metal: Option>, #[cfg(all(feature = "dx12", windows))] pub dx12: Option>, - #[cfg(all(feature = "dx11", windows))] - pub dx11: Option>, #[cfg(feature = "gles")] pub gl: Option>, pub flags: wgt::InstanceFlags, @@ -113,8 +111,6 @@ impl Instance { metal: init(hal::api::Metal, &instance_desc), #[cfg(all(feature = "dx12", windows))] dx12: init(hal::api::Dx12, &instance_desc), - #[cfg(all(feature = "dx11", windows))] - dx11: init(hal::api::Dx11, &instance_desc), #[cfg(feature = "gles")] gl: init(hal::api::Gles, &instance_desc), flags: instance_desc.flags, @@ -144,8 +140,6 @@ impl Instance { Backend::Metal => destroy(hal::api::Metal, &self.metal, surface.raw), #[cfg(all(feature = "dx12", windows))] Backend::Dx12 => destroy(hal::api::Dx12, &self.dx12, surface.raw), - #[cfg(all(feature = "dx11", windows))] - Backend::Dx11 => destroy(hal::api::Dx11, &self.dx11, surface.raw), #[cfg(feature = "gles")] Backend::Gl => destroy(hal::api::Gles, &self.gl, surface.raw), _ => unreachable!(), @@ -531,13 +525,6 @@ impl Global { display_handle, window_handle, ); - #[cfg(all(feature = "dx11", windows))] - init::( - &mut hal_surface, - &self.instance.dx11, - display_handle, - window_handle, - ); #[cfg(feature = "gles")] init::( &mut hal_surface, @@ -787,8 +774,6 @@ impl Global { unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present); #[cfg(all(feature = "dx12", windows))] unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present); - #[cfg(all(feature = "dx11", windows))] - unconfigure::<_, hal::api::Dx11>(self, &surface.raw, &present); #[cfg(feature = "gles")] unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present); } @@ -849,8 +834,6 @@ impl Global { ); #[cfg(all(feature = "dx12", windows))] self.enumerate(hal::api::Dx12, &self.instance.dx12, &inputs, &mut adapters); - #[cfg(all(feature = "dx11", windows))] - self.enumerate(hal::api::Dx11, &self.instance.dx11, &inputs, &mut adapters); #[cfg(feature = "gles")] self.enumerate(hal::api::Gles, &self.instance.gl, &inputs, &mut adapters); @@ -960,15 +943,6 @@ impl Global { desc.force_fallback_adapter, &mut device_types, ); - #[cfg(all(feature = "dx11", windows))] - let (id_dx11, adapters_dx11) = gather( - hal::api::Dx11, - self.instance.dx11.as_ref(), - &inputs, - compatible_surface, - desc.force_fallback_adapter, - &mut device_types, - ); #[cfg(feature = "gles")] let (id_gl, adapters_gl) = gather( hal::api::Gles, @@ -1042,10 +1016,6 @@ impl Global { if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) { return Ok(id); } - #[cfg(all(feature = "dx11", windows))] - if let Some(id) = self.select(&mut selected, id_dx11, adapters_dx11) { - return Ok(id); - } #[cfg(feature = "gles")] if let Some(id) = self.select(&mut selected, id_gl, adapters_gl) { return Ok(id); @@ -1076,8 +1046,6 @@ impl Global { Backend::Metal => fid.assign(Adapter::new(hal_adapter)), #[cfg(all(feature = "dx12", windows))] Backend::Dx12 => fid.assign(Adapter::new(hal_adapter)), - #[cfg(all(feature = "dx11", windows))] - Backend::Dx11 => fid.assign(Adapter::new(hal_adapter)), #[cfg(feature = "gles")] Backend::Gl => fid.assign(Adapter::new(hal_adapter)), _ => unreachable!(), @@ -1283,7 +1251,6 @@ impl Global { /// Names: /// - vulkan = "vulkan" or "vk" /// - dx12 = "dx12" or "d3d12" -/// - dx11 = "dx11" or "d3d11" /// - metal = "metal" or "mtl" /// - gles = "opengl" or "gles" or "gl" /// - webgpu = "webgpu" @@ -1293,7 +1260,6 @@ pub fn parse_backends_from_comma_list(string: &str) -> Backends { backends |= match backend.trim() { "vulkan" | "vk" => Backends::VULKAN, "dx12" | "d3d12" => Backends::DX12, - "dx11" | "d3d11" => Backends::DX11, "metal" | "mtl" => Backends::METAL, "opengl" | "gles" | "gl" => Backends::GL, "webgpu" => Backends::BROWSER_WEBGPU, diff --git a/third_party/rust/wgpu-core/src/lib.rs b/third_party/rust/wgpu-core/src/lib.rs index 944d7eff46232..e68debdcb8695 100644 --- a/third_party/rust/wgpu-core/src/lib.rs +++ b/third_party/rust/wgpu-core/src/lib.rs @@ -9,7 +9,6 @@ not(all(feature = "vulkan", not(target_arch = "wasm32"))), not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))), not(all(feature = "dx12", windows)), - not(all(feature = "dx11", windows)), not(feature = "gles"), ), allow(unused, clippy::let_and_return) @@ -67,7 +66,11 @@ pub mod registry; pub mod resource; pub mod storage; mod track; -mod validation; +// This is public for users who pre-compile shaders while still wanting to +// preserve all run-time checks that `wgpu-core` does. +// See , after which this can be +// made private again. +pub mod validation; pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_ATTACHMENTS, MAX_VERTEX_BUFFERS}; @@ -217,7 +220,6 @@ macro_rules! define_backend_caller { define_backend_caller! { gfx_if_vulkan, gfx_if_vulkan_hidden, "vulkan" if all(feature = "vulkan", not(target_arch = "wasm32")) } define_backend_caller! { gfx_if_metal, gfx_if_metal_hidden, "metal" if all(feature = "metal", any(target_os = "macos", target_os = "ios")) } define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden, "dx12" if all(feature = "dx12", windows) } -define_backend_caller! { gfx_if_dx11, gfx_if_dx11_hidden, "dx11" if all(feature = "dx11", windows) } define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "gles" } /// Dispatch on an [`Id`]'s backend to a backend-generic method. @@ -272,7 +274,6 @@ macro_rules! gfx_select { wgt::Backend::Vulkan => $crate::gfx_if_vulkan!($global.$method::<$crate::api::Vulkan>( $($param),* )), wgt::Backend::Metal => $crate::gfx_if_metal!($global.$method::<$crate::api::Metal>( $($param),* )), wgt::Backend::Dx12 => $crate::gfx_if_dx12!($global.$method::<$crate::api::Dx12>( $($param),* )), - wgt::Backend::Dx11 => $crate::gfx_if_dx11!($global.$method::<$crate::api::Dx11>( $($param),* )), wgt::Backend::Gl => $crate::gfx_if_gles!($global.$method::<$crate::api::Gles>( $($param),+ )), other => panic!("Unexpected backend {:?}", other), } diff --git a/third_party/rust/wgpu-core/src/pipeline.rs b/third_party/rust/wgpu-core/src/pipeline.rs index 50b5c91ce8d94..32a0ac880b774 100644 --- a/third_party/rust/wgpu-core/src/pipeline.rs +++ b/third_party/rust/wgpu-core/src/pipeline.rs @@ -48,7 +48,6 @@ pub struct ShaderModule { pub(crate) device: Arc>, pub(crate) interface: Option, pub(crate) info: ResourceInfo, - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -80,10 +79,7 @@ impl Resource for ShaderModule { } fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.label.clone() } } diff --git a/third_party/rust/wgpu-core/src/registry.rs b/third_party/rust/wgpu-core/src/registry.rs index 3e9003621ff05..0fe3b7dd135d9 100644 --- a/third_party/rust/wgpu-core/src/registry.rs +++ b/third_party/rust/wgpu-core/src/registry.rs @@ -88,7 +88,6 @@ impl> FutureId<'_, I, T> { pub fn assign_existing(self, value: &Arc) -> I { let mut data = self.data.write(); - #[cfg(debug_assertions)] debug_assert!(!data.contains(self.id)); data.insert(self.id, value.clone()); self.id diff --git a/third_party/rust/wgpu-core/src/resource.rs b/third_party/rust/wgpu-core/src/resource.rs index 49d36a7acc2ed..db9a376d409ea 100644 --- a/third_party/rust/wgpu-core/src/resource.rs +++ b/third_party/rust/wgpu-core/src/resource.rs @@ -70,7 +70,6 @@ pub struct ResourceInfo { submission_index: AtomicUsize, /// The `label` from the descriptor used to create the resource. - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -90,25 +89,19 @@ impl ResourceInfo { id: None, identity: None, submission_index: AtomicUsize::new(0), - #[cfg(debug_assertions)] label: label.to_string(), } } - #[allow(unused_assignments)] pub(crate) fn label(&self) -> String where Id: Debug, { - let mut label = String::new(); - #[cfg(debug_assertions)] - { - label = format!("[{}] ", self.label); - } if let Some(id) = self.id.as_ref() { - label.push_str(format!("{:?}", id).as_str()); + format!("[{}] {:?}", self.label, id) + } else { + format!("[{}]", self.label) } - label } pub(crate) fn id(&self) -> Id { @@ -139,10 +132,7 @@ pub trait Resource: 'static + WasmNotSendSync { fn as_info(&self) -> &ResourceInfo; fn as_info_mut(&mut self) -> &mut ResourceInfo; fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.as_info().label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.as_info().label.clone() } fn ref_count(self: &Arc) -> usize { Arc::strong_count(self) diff --git a/third_party/rust/wgpu-hal/.cargo-checksum.json b/third_party/rust/wgpu-hal/.cargo-checksum.json index 11b0a2337c73a..f202b89993840 100644 --- a/third_party/rust/wgpu-hal/.cargo-checksum.json +++ b/third_party/rust/wgpu-hal/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"f472b730bbef76aa4770fd53b53535c1d0773145c8a40aac2deb6e7465ff70bc","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","README.md":"099ee611a911dc19330a61bffcde13663929a51b25ac528ee33ea796d695491e","examples/halmark/main.rs":"c74696fd871200a46e3592ce5a662c42d9587c13b7def75c5cac4c34d9685ad5","examples/halmark/shader.wgsl":"26c256ec36d6f0e9a1647431ca772766bee4382d64eaa718ba7b488dcfb6bcca","examples/raw-gles.em.html":"70fbe68394a1a4522192de1dcfaf7d399f60d7bdf5de70b708f9bb0417427546","examples/raw-gles.rs":"81210e7603f5304fa1dc294f984eacf27e18df7d3f228063f6acb0d7985c37cd","src/auxil/dxgi/conv.rs":"3cd184da7712d1cea10cad740afb4c9dbdb40b69d7386d56dbaa15f4853c6ac7","src/auxil/dxgi/exception.rs":"fc68c6211c82a912b454c3004185f46a1416bce38ddc5b0555e0def6539cfb27","src/auxil/dxgi/factory.rs":"65c758d6583c2fdac0b3d48d1a0a2a414ff913efc4f3913a38bd660819c3a2e2","src/auxil/dxgi/mod.rs":"a202564d9ac97530b16a234b87d180cd345aae705e082a9b1177dcde813645f9","src/auxil/dxgi/result.rs":"20c8eb03d738062dff198feca6327addb9882ed0462be842c789eadf7dca0573","src/auxil/dxgi/time.rs":"b6f966b250e9424d5d7e4065f2108cba87197c1e30baae6d87083055d1bc5a4b","src/auxil/mod.rs":"c38f0d3b10804d1c1d7e3b8e4a975fcb87271f8b1904f2f4a3153cceddafb56b","src/auxil/renderdoc.rs":"c2f849f70f576b0c9b0d32dd155b6a6353f74dff59cbeeaa994a12789d047c0f","src/dx11/adapter.rs":"173e99507610282a7858c142ffe2b9755dac0d61bcaed7ae69394002d476c4f6","src/dx11/command.rs":"3a329369bbd9deeb2fbe3c274a5a5d5f0d2da9eeb64b76592e922446e52c5a51","src/dx11/device.rs":"4ee1880b0d48ed054654e936c76b3e7b7e370fbf79c2f0af370f8de350fd94ff","src/dx11/instance.rs":"206b38346de245e315e762b8de81ca26c74d10aad26a488713945d0e1c802e2b","src/dx11/library.rs":"1b4c3575fd8fd30d07a61ce68ec3c930305c4df5aa5dcf54dd1fdd4edff590d4","src/dx11/mod.rs":"1f2e7f04801b4e65aa27183bc0ddeee0dd3aa686bac4056649dbd97ddef142e1","src/dx12/adapter.rs":"33c4b790c22115d68db11883a8fb8da194fba0937636a56cc779b7bf48a5ce44","src/dx12/command.rs":"9c6b24f7a09c54b61ac36d0cbd74b2ff8e5c5474ee834f06f39cf18caf95b7d2","src/dx12/conv.rs":"24d6ac9808f7534f3480ba2eb563f98f1441c8ad2b4c6e86b2700f5ac812e99a","src/dx12/descriptor.rs":"d9e295c48dc7d1759fd121c927c2218c1bde90e9f1b35f2ad01b610b184b614e","src/dx12/device.rs":"6baf4b32df1f91a7d2060b00a14850530b857de1147c8cf1d85abd6f5e90e4c2","src/dx12/instance.rs":"719125a6adb69f16df1a0069c8a1ccb5792169a00abdf2e38cc26b633b15768a","src/dx12/mod.rs":"fe9e7ed1786c7142fa5bf04e9ad2ee729fdd92c926bb734afa75651206cf737d","src/dx12/shader_compilation.rs":"0589ed592cbd939f821d2801c82ee973c28844292682d37db84048ba21e6c72b","src/dx12/suballocation.rs":"eec45b2d23e979f7d7f33d982a89ae2f92e528b22f1bb7d2e5dd52582a25a601","src/dx12/types.rs":"9573736baaa0ef607367c3b72144556d24faf677a26bb8df49a4372a1348e06b","src/dx12/view.rs":"7db9595d0f67c441605ef5830555c27fc2e9c9c6aa0151baf52c9d04fc536617","src/empty.rs":"de72a7dcbd2b562195a3a49a4065008cb4402381b8dbb83ef348398c3f9d920e","src/gles/adapter.rs":"32f658df60a226fb4f3ff242267f442945c9c9670d7a5692301c3f90cdd1f5cf","src/gles/command.rs":"7d6a760c721e759c6c32998b5a42466fe35bcff5ecc109af42b2aaec85e444ea","src/gles/conv.rs":"9cd65b70c1a2f92f22a83dda825e175f367cbb3d6201a31d90e84aaf63e63d9b","src/gles/device.rs":"b19f2437e403e08511ff341efc63e55c78fcdeffa3785d02a892a743a26a3663","src/gles/egl.rs":"89212bdacbb9dc43eebcc7b74fb612a69d35ffc1dfe2b626820c44c61256c4c9","src/gles/emscripten.rs":"19bb73a9d140645f3f32cd48b002151711a9b8456e213eab5f3a2be79239e147","src/gles/mod.rs":"e9a232ffb9331cd3873ea7afd4bd39e07503873d592bacd576efebd58e452323","src/gles/queue.rs":"fe795add7b32ae4cd89e40db93e5bae62b6c7bc5741c71f21d292bd0a511de58","src/gles/shaders/clear.frag":"9133ed8ed97d3641fbb6b5f5ea894a3554c629ccc1b80a5fc9221d7293aa1954","src/gles/shaders/clear.vert":"a543768725f4121ff2e9e1fb5b00644931e9d6f2f946c0ef01968afb5a135abd","src/gles/shaders/srgb_present.frag":"dd9a43c339a2fa4ccf7f6a1854c6f400cabf271a7d5e9230768e9f39d47f3ff5","src/gles/shaders/srgb_present.vert":"6e85d489403d80b81cc94790730bb53b309dfc5eeede8f1ea3412a660f31d357","src/gles/web.rs":"5623c8c78584c5e9182502e0997bd11e627e67ccd23d516e65526f415215de2f","src/gles/wgl.rs":"ec1c958acc903af43c29e60059c2c71257b5735312c15679647daed774ad01a1","src/lib.rs":"072e3f2a781b9cba47d17e7fe3954697d6328cb48ecd2dd0f0f2f500efefe51a","src/metal/adapter.rs":"9ae2496b3a2df3263f2f5a53a6bd4245800c53072673c3444c274c7fffa2a8dc","src/metal/command.rs":"702edebb7aff60acc67d6e183f2dad999f2528b0f00bccc25197fb01911a3b6e","src/metal/conv.rs":"0bce6a8d0ccef16783475803d70d35e03ab7938c19374e22c9d253abe1f8b111","src/metal/device.rs":"d2fb16e8d7cfc0c9e3141dcf1245a1f0ea8a891962c0cd83c0cd4450e7acaf36","src/metal/mod.rs":"e248de570dddfad70a83ef1788d1a15b037b0e861937c8eff00dd0c09dfae82d","src/metal/surface.rs":"01539fa9f22c26fdcca5ee915ca97cf76cecc7fae237347dfc9a813ae13e98cd","src/metal/time.rs":"c32d69f30e846dfcc0e39e01097fb80df63b2bebb6586143bb62494999850246","src/vulkan/adapter.rs":"5a8d9a2757c9ec86ba7f1ac7b79cf577830908c6fd9935ea1af7519457d85562","src/vulkan/command.rs":"5f0da371d3189ce42c141039a3a435717c12077f5d09226af61b5c51e4bde68c","src/vulkan/conv.rs":"ee41a6d5a17c9474296b8e850b5dcb10452c8077e3ff70a68351a374726115b6","src/vulkan/device.rs":"c83be51f540e5a3294eb755ec8c787edc204aaea727d62b66887d7f88775a041","src/vulkan/instance.rs":"d9a084ac91a2b541b14d8ea565a7a581d281e54ec2828b64e5be2989e0113ed7","src/vulkan/mod.rs":"7ed5c34156d70808e7845575d93a8c2a07bfa989d455c3848e93e8ae372b99ff"},"package":null} \ No newline at end of file +{"files":{"Cargo.toml":"e419deb948fdc43d0d9276096822ca6839b8e15b18561037369495879257cfd4","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","README.md":"099ee611a911dc19330a61bffcde13663929a51b25ac528ee33ea796d695491e","examples/halmark/main.rs":"086554cc594cf7b8566bff515fb0cd7fb35d0f6c6e1433ccc96889a123a069b2","examples/halmark/shader.wgsl":"26c256ec36d6f0e9a1647431ca772766bee4382d64eaa718ba7b488dcfb6bcca","examples/raw-gles.em.html":"70fbe68394a1a4522192de1dcfaf7d399f60d7bdf5de70b708f9bb0417427546","examples/raw-gles.rs":"81210e7603f5304fa1dc294f984eacf27e18df7d3f228063f6acb0d7985c37cd","examples/ray-traced-triangle/main.rs":"7d31be49859dee1483ab42b9618af3b0093d5f08b3e6d5a2e7a750c1e132c826","examples/ray-traced-triangle/shader.wgsl":"cc10caf92746724a71f6dd0dbc3a71e57b37c7d1d83278556805a535c0728a9d","src/auxil/dxgi/conv.rs":"3cd184da7712d1cea10cad740afb4c9dbdb40b69d7386d56dbaa15f4853c6ac7","src/auxil/dxgi/exception.rs":"fc68c6211c82a912b454c3004185f46a1416bce38ddc5b0555e0def6539cfb27","src/auxil/dxgi/factory.rs":"65c758d6583c2fdac0b3d48d1a0a2a414ff913efc4f3913a38bd660819c3a2e2","src/auxil/dxgi/mod.rs":"a202564d9ac97530b16a234b87d180cd345aae705e082a9b1177dcde813645f9","src/auxil/dxgi/result.rs":"20c8eb03d738062dff198feca6327addb9882ed0462be842c789eadf7dca0573","src/auxil/dxgi/time.rs":"b6f966b250e9424d5d7e4065f2108cba87197c1e30baae6d87083055d1bc5a4b","src/auxil/mod.rs":"17505dc0a8247546bc1b97341c872f368a1f522e4ff51bb8844255e36b2b5186","src/auxil/renderdoc.rs":"c2f849f70f576b0c9b0d32dd155b6a6353f74dff59cbeeaa994a12789d047c0f","src/dx12/adapter.rs":"33c4b790c22115d68db11883a8fb8da194fba0937636a56cc779b7bf48a5ce44","src/dx12/command.rs":"1596ad0304eafbd7d69d2224329ce95dd7910c87faba8003b4e60dffb20d5596","src/dx12/conv.rs":"94d35f117ae003b07049f3a0bc6c45a0ffda9fb8053233d39c173cfb1b644403","src/dx12/descriptor.rs":"d9e295c48dc7d1759fd121c927c2218c1bde90e9f1b35f2ad01b610b184b614e","src/dx12/device.rs":"811cfef5f08add77f14da1ca0e77791f867afa4a6b9e11424bcd15932c6b64fd","src/dx12/instance.rs":"719125a6adb69f16df1a0069c8a1ccb5792169a00abdf2e38cc26b633b15768a","src/dx12/mod.rs":"d6b5e7b83997f33acc62b90a640621e3512302acf9519c01fa68c37447060bdd","src/dx12/shader_compilation.rs":"0589ed592cbd939f821d2801c82ee973c28844292682d37db84048ba21e6c72b","src/dx12/suballocation.rs":"eec45b2d23e979f7d7f33d982a89ae2f92e528b22f1bb7d2e5dd52582a25a601","src/dx12/types.rs":"9573736baaa0ef607367c3b72144556d24faf677a26bb8df49a4372a1348e06b","src/dx12/view.rs":"7db9595d0f67c441605ef5830555c27fc2e9c9c6aa0151baf52c9d04fc536617","src/empty.rs":"af290b508bc63590b40b94a8e3b163e32f1262f2e20995cab340cfd76386becd","src/gles/adapter.rs":"16bc0c9cc6987269841f7f12023ca12a14e0d746c4bab8d4770abb240a63ed84","src/gles/command.rs":"a544456f3d3ed13bd695a604473af1758ee29b2386872f5663e5395088890177","src/gles/conv.rs":"4c7ce6424cefc2b62b74f1f0f67c2d480f04412a16d27ca83b0471744d7fce96","src/gles/device.rs":"ae7415a7ade56d499b28073492289907edbce13327392cc014812c35ed9effdc","src/gles/egl.rs":"89212bdacbb9dc43eebcc7b74fb612a69d35ffc1dfe2b626820c44c61256c4c9","src/gles/emscripten.rs":"19bb73a9d140645f3f32cd48b002151711a9b8456e213eab5f3a2be79239e147","src/gles/mod.rs":"d02cefb55c78dd496f2eeceb55547b3032b50f31188d20994d90e4a049b2e6a0","src/gles/queue.rs":"53f7184c94f210dd4fb2a264c9a545eac3ccf4ef44e670ff7523a8e9a6c9dd1d","src/gles/shaders/clear.frag":"9133ed8ed97d3641fbb6b5f5ea894a3554c629ccc1b80a5fc9221d7293aa1954","src/gles/shaders/clear.vert":"a543768725f4121ff2e9e1fb5b00644931e9d6f2f946c0ef01968afb5a135abd","src/gles/shaders/srgb_present.frag":"dd9a43c339a2fa4ccf7f6a1854c6f400cabf271a7d5e9230768e9f39d47f3ff5","src/gles/shaders/srgb_present.vert":"6e85d489403d80b81cc94790730bb53b309dfc5eeede8f1ea3412a660f31d357","src/gles/web.rs":"5623c8c78584c5e9182502e0997bd11e627e67ccd23d516e65526f415215de2f","src/gles/wgl.rs":"ec1c958acc903af43c29e60059c2c71257b5735312c15679647daed774ad01a1","src/lib.rs":"3d60e2c9bec5232a75d794f0436de8de53dbfbbb017eb2ce5c48c4c42435773e","src/metal/adapter.rs":"9ae2496b3a2df3263f2f5a53a6bd4245800c53072673c3444c274c7fffa2a8dc","src/metal/command.rs":"661b38a75d4f4cd1b0d6957f1f09db0743ec3a13bbafba9baa931894ee193f48","src/metal/conv.rs":"0bce6a8d0ccef16783475803d70d35e03ab7938c19374e22c9d253abe1f8b111","src/metal/device.rs":"b37d718769134a71a522520ec299ba893435334f813e4386464b8aec241d96b2","src/metal/mod.rs":"662518044d6464410facd58ff06a80a89e2c9c3cd3fdad69a956ed4546777d2a","src/metal/surface.rs":"01539fa9f22c26fdcca5ee915ca97cf76cecc7fae237347dfc9a813ae13e98cd","src/metal/time.rs":"c32d69f30e846dfcc0e39e01097fb80df63b2bebb6586143bb62494999850246","src/vulkan/adapter.rs":"690706eee5ddb5d9697e908c31980886446a63d64c944b9b2c7fb8d8fe55030e","src/vulkan/command.rs":"7c6dd62b1d4a65f8c85b2fada925f9c50b46039ec862b5e700e05e0f546a3288","src/vulkan/conv.rs":"46e49c73ec3803996c4553174e7bd60ba621e333c70968f9e99a3f43b75a7c84","src/vulkan/device.rs":"2cbed6b4efdd6851e27cccb87f31f47cf22eb5f7bca05aaddefb5a57796d0db4","src/vulkan/instance.rs":"d9a084ac91a2b541b14d8ea565a7a581d281e54ec2828b64e5be2989e0113ed7","src/vulkan/mod.rs":"e69c99bc511567587734ffb16af3cbda8a29ec387c8183c930744cb489b3f492"},"package":null} \ No newline at end of file diff --git a/third_party/rust/wgpu-hal/Cargo.toml b/third_party/rust/wgpu-hal/Cargo.toml index 6151e4d7665dc..0195de5ce7883 100644 --- a/third_party/rust/wgpu-hal/Cargo.toml +++ b/third_party/rust/wgpu-hal/Cargo.toml @@ -81,6 +81,7 @@ package = "wgpu-types" [dev-dependencies] cfg-if = "1" env_logger = "0.10" +glam = "0.24.2" [dev-dependencies.naga] version = "0.14.0" @@ -93,17 +94,6 @@ features = ["android-native-activity"] [features] default = ["link"] -dx11 = [ - "naga/hlsl-out", - "d3d12", - "libloading", - "winapi/d3d11", - "winapi/std", - "winapi/d3d11_1", - "winapi/d3d11_2", - "winapi/d3d11sdklayers", - "winapi/dxgi1_6", -] dx12 = [ "naga/hlsl-out", "d3d12", diff --git a/third_party/rust/wgpu-hal/examples/halmark/main.rs b/third_party/rust/wgpu-hal/examples/halmark/main.rs index 60b2c144f274b..ea1e7648e9667 100644 --- a/third_party/rust/wgpu-hal/examples/halmark/main.rs +++ b/third_party/rust/wgpu-hal/examples/halmark/main.rs @@ -442,6 +442,7 @@ impl Example { buffers: &[global_buffer_binding], samplers: &[&sampler], textures: &[texture_binding], + acceleration_structures: &[], entries: &[ hal::BindGroupEntry { binding: 0, @@ -475,6 +476,7 @@ impl Example { buffers: &[local_buffer_binding], samplers: &[], textures: &[], + acceleration_structures: &[], entries: &[hal::BindGroupEntry { binding: 0, resource_index: 0, diff --git a/third_party/rust/wgpu-hal/examples/ray-traced-triangle/main.rs b/third_party/rust/wgpu-hal/examples/ray-traced-triangle/main.rs new file mode 100644 index 0000000000000..7202b35bee955 --- /dev/null +++ b/third_party/rust/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -0,0 +1,1113 @@ +extern crate wgpu_hal as hal; + +use hal::{ + Adapter as _, CommandEncoder as _, Device as _, Instance as _, Queue as _, Surface as _, +}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; + +use glam::{Affine3A, Mat4, Vec3}; +use std::{ + borrow::{Borrow, Cow}, + iter, mem, ptr, + time::Instant, +}; +use winit::window::WindowButtons; + +const COMMAND_BUFFER_PER_CONTEXT: usize = 100; +const DESIRED_FRAMES: u32 = 3; + +/// [D3D12_RAYTRACING_INSTANCE_DESC](https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html#d3d12_raytracing_instance_desc) +/// [VkAccelerationStructureInstanceKHR](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkAccelerationStructureInstanceKHR.html) +#[derive(Clone)] +#[repr(C)] +struct AccelerationStructureInstance { + transform: [f32; 12], + custom_index_and_mask: u32, + shader_binding_table_record_offset_and_flags: u32, + acceleration_structure_reference: u64, +} + +impl std::fmt::Debug for AccelerationStructureInstance { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Instance") + .field("transform", &self.transform) + .field("custom_index()", &self.custom_index()) + .field("mask()", &self.mask()) + .field( + "shader_binding_table_record_offset()", + &self.shader_binding_table_record_offset(), + ) + .field("flags()", &self.flags()) + .field( + "acceleration_structure_reference", + &self.acceleration_structure_reference, + ) + .finish() + } +} + +#[allow(dead_code)] +impl AccelerationStructureInstance { + const LOW_24_MASK: u32 = 0x00ff_ffff; + const MAX_U24: u32 = (1u32 << 24u32) - 1u32; + + #[inline] + fn affine_to_rows(mat: &Affine3A) -> [f32; 12] { + let row_0 = mat.matrix3.row(0); + let row_1 = mat.matrix3.row(1); + let row_2 = mat.matrix3.row(2); + let translation = mat.translation; + [ + row_0.x, + row_0.y, + row_0.z, + translation.x, + row_1.x, + row_1.y, + row_1.z, + translation.y, + row_2.x, + row_2.y, + row_2.z, + translation.z, + ] + } + + #[inline] + fn rows_to_affine(rows: &[f32; 12]) -> Affine3A { + Affine3A::from_cols_array(&[ + rows[0], rows[3], rows[6], rows[9], rows[1], rows[4], rows[7], rows[10], rows[2], + rows[5], rows[8], rows[11], + ]) + } + + pub fn transform_as_affine(&self) -> Affine3A { + Self::rows_to_affine(&self.transform) + } + pub fn set_transform(&mut self, transform: &Affine3A) { + self.transform = Self::affine_to_rows(transform); + } + + pub fn custom_index(&self) -> u32 { + self.custom_index_and_mask & Self::LOW_24_MASK + } + + pub fn mask(&self) -> u8 { + (self.custom_index_and_mask >> 24) as u8 + } + + pub fn shader_binding_table_record_offset(&self) -> u32 { + self.shader_binding_table_record_offset_and_flags & Self::LOW_24_MASK + } + + pub fn flags(&self) -> u8 { + (self.shader_binding_table_record_offset_and_flags >> 24) as u8 + } + + pub fn set_custom_index(&mut self, custom_index: u32) { + debug_assert!( + custom_index <= Self::MAX_U24, + "custom_index uses more than 24 bits! {custom_index} > {}", + Self::MAX_U24 + ); + self.custom_index_and_mask = + (custom_index & Self::LOW_24_MASK) | (self.custom_index_and_mask & !Self::LOW_24_MASK) + } + + pub fn set_mask(&mut self, mask: u8) { + self.custom_index_and_mask = + (self.custom_index_and_mask & Self::LOW_24_MASK) | (u32::from(mask) << 24) + } + + pub fn set_shader_binding_table_record_offset( + &mut self, + shader_binding_table_record_offset: u32, + ) { + debug_assert!(shader_binding_table_record_offset <= Self::MAX_U24, "shader_binding_table_record_offset uses more than 24 bits! {shader_binding_table_record_offset} > {}", Self::MAX_U24); + self.shader_binding_table_record_offset_and_flags = (shader_binding_table_record_offset + & Self::LOW_24_MASK) + | (self.shader_binding_table_record_offset_and_flags & !Self::LOW_24_MASK) + } + + pub fn set_flags(&mut self, flags: u8) { + self.shader_binding_table_record_offset_and_flags = + (self.shader_binding_table_record_offset_and_flags & Self::LOW_24_MASK) + | (u32::from(flags) << 24) + } + + pub fn new( + transform: &Affine3A, + custom_index: u32, + mask: u8, + shader_binding_table_record_offset: u32, + flags: u8, + acceleration_structure_reference: u64, + ) -> Self { + debug_assert!( + custom_index <= Self::MAX_U24, + "custom_index uses more than 24 bits! {custom_index} > {}", + Self::MAX_U24 + ); + debug_assert!( + shader_binding_table_record_offset <= Self::MAX_U24, + "shader_binding_table_record_offset uses more than 24 bits! {shader_binding_table_record_offset} > {}", Self::MAX_U24 + ); + AccelerationStructureInstance { + transform: Self::affine_to_rows(transform), + custom_index_and_mask: (custom_index & Self::MAX_U24) | (u32::from(mask) << 24), + shader_binding_table_record_offset_and_flags: (shader_binding_table_record_offset + & Self::MAX_U24) + | (u32::from(flags) << 24), + acceleration_structure_reference, + } + } +} + +struct ExecutionContext { + encoder: A::CommandEncoder, + fence: A::Fence, + fence_value: hal::FenceValue, + used_views: Vec, + used_cmd_bufs: Vec, + frames_recorded: usize, +} + +impl ExecutionContext { + unsafe fn wait_and_clear(&mut self, device: &A::Device) { + device.wait(&self.fence, self.fence_value, !0).unwrap(); + self.encoder.reset_all(self.used_cmd_bufs.drain(..)); + for view in self.used_views.drain(..) { + device.destroy_texture_view(view); + } + self.frames_recorded = 0; + } +} + +#[allow(dead_code)] +struct Example { + instance: A::Instance, + adapter: A::Adapter, + surface: A::Surface, + surface_format: wgt::TextureFormat, + device: A::Device, + queue: A::Queue, + + contexts: Vec>, + context_index: usize, + extent: [u32; 2], + start: Instant, + pipeline: A::ComputePipeline, + bind_group: A::BindGroup, + bgl: A::BindGroupLayout, + shader_module: A::ShaderModule, + texture_view: A::TextureView, + uniform_buffer: A::Buffer, + pipeline_layout: A::PipelineLayout, + vertices_buffer: A::Buffer, + indices_buffer: A::Buffer, + texture: A::Texture, + instances: [AccelerationStructureInstance; 3], + instances_buffer: A::Buffer, + blas: A::AccelerationStructure, + tlas: A::AccelerationStructure, + scratch_buffer: A::Buffer, + time: f32, +} + +impl Example { + fn init(window: &winit::window::Window) -> Result> { + let instance_desc = hal::InstanceDescriptor { + name: "example", + flags: wgt::InstanceFlags::default(), + dx12_shader_compiler: wgt::Dx12Compiler::Dxc { + dxil_path: None, + dxc_path: None, + }, + gles_minor_version: wgt::Gles3MinorVersion::default(), + }; + let instance = unsafe { A::Instance::init(&instance_desc)? }; + let surface = { + let raw_window_handle = window.window_handle()?.as_raw(); + let raw_display_handle = window.display_handle()?.as_raw(); + + unsafe { + instance + .create_surface(raw_display_handle, raw_window_handle) + .unwrap() + } + }; + + let (adapter, features) = unsafe { + let mut adapters = instance.enumerate_adapters(); + if adapters.is_empty() { + panic!("No adapters found"); + } + let exposed = adapters.swap_remove(0); + dbg!(exposed.features); + (exposed.adapter, exposed.features) + }; + let surface_caps = unsafe { adapter.surface_capabilities(&surface) } + .expect("Surface doesn't support presentation"); + log::info!("Surface caps: {:#?}", surface_caps); + + let hal::OpenDevice { device, queue } = + unsafe { adapter.open(features, &wgt::Limits::default()).unwrap() }; + + let window_size: (u32, u32) = window.inner_size().into(); + dbg!(&surface_caps.formats); + let surface_format = if surface_caps + .formats + .contains(&wgt::TextureFormat::Rgba8Snorm) + { + wgt::TextureFormat::Rgba8Unorm + } else { + *surface_caps.formats.first().unwrap() + }; + let surface_config = hal::SurfaceConfiguration { + swap_chain_size: DESIRED_FRAMES + .max(*surface_caps.swap_chain_sizes.start()) + .min(*surface_caps.swap_chain_sizes.end()), + present_mode: wgt::PresentMode::Fifo, + composite_alpha_mode: wgt::CompositeAlphaMode::Opaque, + format: surface_format, + extent: wgt::Extent3d { + width: window_size.0, + height: window_size.1, + depth_or_array_layers: 1, + }, + usage: hal::TextureUses::COLOR_TARGET | hal::TextureUses::COPY_DST, + view_formats: vec![surface_format], + }; + unsafe { + surface.configure(&device, &surface_config).unwrap(); + }; + + #[allow(dead_code)] + struct Uniforms { + view_inverse: glam::Mat4, + proj_inverse: glam::Mat4, + } + + let bgl_desc = hal::BindGroupLayoutDescriptor { + label: None, + flags: hal::BindGroupLayoutFlags::empty(), + entries: &[ + wgt::BindGroupLayoutEntry { + binding: 0, + visibility: wgt::ShaderStages::COMPUTE, + ty: wgt::BindingType::Buffer { + ty: wgt::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgt::BufferSize::new(mem::size_of::() as _), + }, + count: None, + }, + wgt::BindGroupLayoutEntry { + binding: 1, + visibility: wgt::ShaderStages::COMPUTE, + ty: wgt::BindingType::StorageTexture { + access: wgt::StorageTextureAccess::WriteOnly, + format: wgt::TextureFormat::Rgba8Unorm, + view_dimension: wgt::TextureViewDimension::D2, + }, + count: None, + }, + wgt::BindGroupLayoutEntry { + binding: 2, + visibility: wgt::ShaderStages::COMPUTE, + ty: wgt::BindingType::AccelerationStructure, + count: None, + }, + ], + }; + + let bgl = unsafe { device.create_bind_group_layout(&bgl_desc).unwrap() }; + + let naga_shader = { + let shader_file = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("examples") + .join("ray-traced-triangle") + .join("shader.wgsl"); + let source = std::fs::read_to_string(shader_file).unwrap(); + let module = naga::front::wgsl::Frontend::new().parse(&source).unwrap(); + let info = naga::valid::Validator::new( + naga::valid::ValidationFlags::all(), + naga::valid::Capabilities::RAY_QUERY, + ) + .validate(&module) + .unwrap(); + hal::NagaShader { + module: Cow::Owned(module), + info, + debug_source: None, + } + }; + let shader_desc = hal::ShaderModuleDescriptor { + label: None, + runtime_checks: false, + }; + let shader_module = unsafe { + device + .create_shader_module(&shader_desc, hal::ShaderInput::Naga(naga_shader)) + .unwrap() + }; + + let pipeline_layout_desc = hal::PipelineLayoutDescriptor { + label: None, + flags: hal::PipelineLayoutFlags::empty(), + bind_group_layouts: &[&bgl], + push_constant_ranges: &[], + }; + let pipeline_layout = unsafe { + device + .create_pipeline_layout(&pipeline_layout_desc) + .unwrap() + }; + + let pipeline = unsafe { + device.create_compute_pipeline(&hal::ComputePipelineDescriptor { + label: Some("pipeline"), + layout: &pipeline_layout, + stage: hal::ProgrammableStage { + module: &shader_module, + entry_point: "main", + }, + }) + } + .unwrap(); + + let vertices: [f32; 9] = [1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 0.0]; + + let vertices_size_in_bytes = vertices.len() * 4; + + let indices: [u32; 3] = [0, 1, 2]; + + let indices_size_in_bytes = indices.len() * 4; + + let vertices_buffer = unsafe { + let vertices_buffer = device + .create_buffer(&hal::BufferDescriptor { + label: Some("vertices buffer"), + size: vertices_size_in_bytes as u64, + usage: hal::BufferUses::MAP_WRITE + | hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, + }) + .unwrap(); + + let mapping = device + .map_buffer(&vertices_buffer, 0..vertices_size_in_bytes as u64) + .unwrap(); + ptr::copy_nonoverlapping( + vertices.as_ptr() as *const u8, + mapping.ptr.as_ptr(), + vertices_size_in_bytes, + ); + device.unmap_buffer(&vertices_buffer).unwrap(); + assert!(mapping.is_coherent); + + vertices_buffer + }; + + let indices_buffer = unsafe { + let indices_buffer = device + .create_buffer(&hal::BufferDescriptor { + label: Some("indices buffer"), + size: indices_size_in_bytes as u64, + usage: hal::BufferUses::MAP_WRITE + | hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, + }) + .unwrap(); + + let mapping = device + .map_buffer(&indices_buffer, 0..indices_size_in_bytes as u64) + .unwrap(); + ptr::copy_nonoverlapping( + indices.as_ptr() as *const u8, + mapping.ptr.as_ptr(), + indices_size_in_bytes, + ); + device.unmap_buffer(&indices_buffer).unwrap(); + assert!(mapping.is_coherent); + + indices_buffer + }; + + let blas_triangles = vec![hal::AccelerationStructureTriangles { + vertex_buffer: Some(&vertices_buffer), + first_vertex: 0, + vertex_format: wgt::VertexFormat::Float32x3, + vertex_count: vertices.len() as u32, + vertex_stride: 3 * 4, + indices: Some(hal::AccelerationStructureTriangleIndices { + buffer: Some(&indices_buffer), + format: wgt::IndexFormat::Uint32, + offset: 0, + count: indices.len() as u32, + }), + transform: None, + flags: hal::AccelerationStructureGeometryFlags::OPAQUE, + }]; + let blas_entries = hal::AccelerationStructureEntries::Triangles(blas_triangles); + + let mut tlas_entries = + hal::AccelerationStructureEntries::Instances(hal::AccelerationStructureInstances { + buffer: None, + count: 3, + offset: 0, + }); + + let blas_sizes = unsafe { + device.get_acceleration_structure_build_sizes( + &hal::GetAccelerationStructureBuildSizesDescriptor { + entries: &blas_entries, + flags: hal::AccelerationStructureBuildFlags::PREFER_FAST_TRACE, + }, + ) + }; + + let tlas_flags = hal::AccelerationStructureBuildFlags::PREFER_FAST_TRACE + | hal::AccelerationStructureBuildFlags::ALLOW_UPDATE; + + let tlas_sizes = unsafe { + device.get_acceleration_structure_build_sizes( + &hal::GetAccelerationStructureBuildSizesDescriptor { + entries: &tlas_entries, + flags: tlas_flags, + }, + ) + }; + + let blas = unsafe { + device.create_acceleration_structure(&hal::AccelerationStructureDescriptor { + label: Some("blas"), + size: blas_sizes.acceleration_structure_size, + format: hal::AccelerationStructureFormat::BottomLevel, + }) + } + .unwrap(); + + let tlas = unsafe { + device.create_acceleration_structure(&hal::AccelerationStructureDescriptor { + label: Some("tlas"), + size: tlas_sizes.acceleration_structure_size, + format: hal::AccelerationStructureFormat::TopLevel, + }) + } + .unwrap(); + + let uniforms = { + let view = Mat4::look_at_rh(Vec3::new(0.0, 0.0, 2.5), Vec3::ZERO, Vec3::Y); + let proj = Mat4::perspective_rh(59.0_f32.to_radians(), 1.0, 0.001, 1000.0); + + Uniforms { + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), + } + }; + + let uniforms_size = std::mem::size_of::(); + + let uniform_buffer = unsafe { + let uniform_buffer = device + .create_buffer(&hal::BufferDescriptor { + label: Some("uniform buffer"), + size: uniforms_size as u64, + usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM, + memory_flags: hal::MemoryFlags::PREFER_COHERENT, + }) + .unwrap(); + + let mapping = device + .map_buffer(&uniform_buffer, 0..uniforms_size as u64) + .unwrap(); + ptr::copy_nonoverlapping( + &uniforms as *const Uniforms as *const u8, + mapping.ptr.as_ptr(), + uniforms_size, + ); + device.unmap_buffer(&uniform_buffer).unwrap(); + assert!(mapping.is_coherent); + uniform_buffer + }; + + let texture_desc = hal::TextureDescriptor { + label: None, + size: wgt::Extent3d { + width: 512, + height: 512, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgt::TextureDimension::D2, + format: wgt::TextureFormat::Rgba8Unorm, + usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC, + memory_flags: hal::MemoryFlags::empty(), + view_formats: vec![wgt::TextureFormat::Rgba8Unorm], + }; + let texture = unsafe { device.create_texture(&texture_desc).unwrap() }; + + let view_desc = hal::TextureViewDescriptor { + label: None, + format: texture_desc.format, + dimension: wgt::TextureViewDimension::D2, + usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC, + range: wgt::ImageSubresourceRange::default(), + plane: None, + }; + let texture_view = unsafe { device.create_texture_view(&texture, &view_desc).unwrap() }; + + let bind_group = { + let buffer_binding = hal::BufferBinding { + buffer: &uniform_buffer, + offset: 0, + size: None, + }; + let texture_binding = hal::TextureBinding { + view: &texture_view, + usage: hal::TextureUses::STORAGE_READ_WRITE, + }; + let group_desc = hal::BindGroupDescriptor { + label: Some("bind group"), + layout: &bgl, + buffers: &[buffer_binding], + samplers: &[], + textures: &[texture_binding], + acceleration_structures: &[&tlas], + entries: &[ + hal::BindGroupEntry { + binding: 0, + resource_index: 0, + count: 1, + }, + hal::BindGroupEntry { + binding: 1, + resource_index: 0, + count: 1, + }, + hal::BindGroupEntry { + binding: 2, + resource_index: 0, + count: 1, + }, + ], + }; + unsafe { device.create_bind_group(&group_desc).unwrap() } + }; + + let scratch_buffer = unsafe { + device + .create_buffer(&hal::BufferDescriptor { + label: Some("scratch buffer"), + size: blas_sizes + .build_scratch_size + .max(tlas_sizes.build_scratch_size), + usage: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + memory_flags: hal::MemoryFlags::empty(), + }) + .unwrap() + }; + + let instances = [ + AccelerationStructureInstance::new( + &Affine3A::from_translation(Vec3 { + x: 0.0, + y: 0.0, + z: 0.0, + }), + 0, + 0xff, + 0, + 0, + unsafe { device.get_acceleration_structure_device_address(&blas) }, + ), + AccelerationStructureInstance::new( + &Affine3A::from_translation(Vec3 { + x: -1.0, + y: -1.0, + z: -2.0, + }), + 0, + 0xff, + 0, + 0, + unsafe { device.get_acceleration_structure_device_address(&blas) }, + ), + AccelerationStructureInstance::new( + &Affine3A::from_translation(Vec3 { + x: 1.0, + y: -1.0, + z: -2.0, + }), + 0, + 0xff, + 0, + 0, + unsafe { device.get_acceleration_structure_device_address(&blas) }, + ), + ]; + + let instances_buffer_size = + instances.len() * std::mem::size_of::(); + + let instances_buffer = unsafe { + let instances_buffer = device + .create_buffer(&hal::BufferDescriptor { + label: Some("instances_buffer"), + size: instances_buffer_size as u64, + usage: hal::BufferUses::MAP_WRITE + | hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, + }) + .unwrap(); + + let mapping = device + .map_buffer(&instances_buffer, 0..instances_buffer_size as u64) + .unwrap(); + ptr::copy_nonoverlapping( + instances.as_ptr() as *const u8, + mapping.ptr.as_ptr(), + instances_buffer_size, + ); + device.unmap_buffer(&instances_buffer).unwrap(); + assert!(mapping.is_coherent); + + instances_buffer + }; + + if let hal::AccelerationStructureEntries::Instances(ref mut i) = tlas_entries { + i.buffer = Some(&instances_buffer); + assert!( + instances.len() <= i.count as usize, + "Tlas allocation to small" + ); + } + + let cmd_encoder_desc = hal::CommandEncoderDescriptor { + label: None, + queue: &queue, + }; + let mut cmd_encoder = unsafe { device.create_command_encoder(&cmd_encoder_desc).unwrap() }; + + unsafe { cmd_encoder.begin_encoding(Some("init")).unwrap() }; + + unsafe { + cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::AccelerationStructureUses::empty() + ..hal::AccelerationStructureUses::BUILD_OUTPUT, + }); + + cmd_encoder.build_acceleration_structures( + 1, + [hal::BuildAccelerationStructureDescriptor { + mode: hal::AccelerationStructureBuildMode::Build, + flags: hal::AccelerationStructureBuildFlags::PREFER_FAST_TRACE, + destination_acceleration_structure: &blas, + scratch_buffer: &scratch_buffer, + entries: &blas_entries, + source_acceleration_structure: None, + scratch_buffer_offset: 0, + }], + ); + + let scratch_buffer_barrier = hal::BufferBarrier { + buffer: &scratch_buffer, + usage: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + ..hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }; + cmd_encoder.transition_buffers(iter::once(scratch_buffer_barrier)); + + cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::AccelerationStructureUses::BUILD_OUTPUT + ..hal::AccelerationStructureUses::BUILD_INPUT, + }); + + cmd_encoder.build_acceleration_structures( + 1, + [hal::BuildAccelerationStructureDescriptor { + mode: hal::AccelerationStructureBuildMode::Build, + flags: tlas_flags, + destination_acceleration_structure: &tlas, + scratch_buffer: &scratch_buffer, + entries: &tlas_entries, + source_acceleration_structure: None, + scratch_buffer_offset: 0, + }], + ); + + cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::AccelerationStructureUses::BUILD_OUTPUT + ..hal::AccelerationStructureUses::SHADER_INPUT, + }); + + let texture_barrier = hal::TextureBarrier { + texture: &texture, + range: wgt::ImageSubresourceRange::default(), + usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::STORAGE_READ_WRITE, + }; + + cmd_encoder.transition_textures(iter::once(texture_barrier)); + } + + let init_fence_value = 1; + let fence = unsafe { + let mut fence = device.create_fence().unwrap(); + let init_cmd = cmd_encoder.end_encoding().unwrap(); + queue + .submit(&[&init_cmd], Some((&mut fence, init_fence_value))) + .unwrap(); + device.wait(&fence, init_fence_value, !0).unwrap(); + cmd_encoder.reset_all(iter::once(init_cmd)); + fence + }; + + Ok(Self { + instance, + adapter, + surface, + surface_format: surface_config.format, + device, + queue, + pipeline, + contexts: vec![ExecutionContext { + encoder: cmd_encoder, + fence, + fence_value: init_fence_value + 1, + used_views: Vec::new(), + used_cmd_bufs: Vec::new(), + frames_recorded: 0, + }], + context_index: 0, + extent: [window_size.0, window_size.1], + start: Instant::now(), + pipeline_layout, + bind_group, + texture, + instances, + instances_buffer, + blas, + tlas, + scratch_buffer, + time: 0.0, + indices_buffer, + vertices_buffer, + uniform_buffer, + texture_view, + bgl, + shader_module, + }) + } + + fn update(&mut self, _event: winit::event::WindowEvent) {} + + fn render(&mut self) { + let ctx = &mut self.contexts[self.context_index]; + + let surface_tex = unsafe { self.surface.acquire_texture(None).unwrap().unwrap().texture }; + + let target_barrier0 = hal::TextureBarrier { + texture: surface_tex.borrow(), + range: wgt::ImageSubresourceRange::default(), + usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::COPY_DST, + }; + + let instances_buffer_size = + self.instances.len() * std::mem::size_of::(); + + let tlas_flags = hal::AccelerationStructureBuildFlags::PREFER_FAST_TRACE + | hal::AccelerationStructureBuildFlags::ALLOW_UPDATE; + + self.time += 1.0 / 60.0; + + self.instances[0].set_transform(&Affine3A::from_rotation_y(self.time)); + + unsafe { + let mapping = self + .device + .map_buffer(&self.instances_buffer, 0..instances_buffer_size as u64) + .unwrap(); + ptr::copy_nonoverlapping( + self.instances.as_ptr() as *const u8, + mapping.ptr.as_ptr(), + instances_buffer_size, + ); + self.device.unmap_buffer(&self.instances_buffer).unwrap(); + assert!(mapping.is_coherent); + } + + unsafe { + ctx.encoder.begin_encoding(Some("frame")).unwrap(); + + let instances = hal::AccelerationStructureInstances { + buffer: Some(&self.instances_buffer), + count: self.instances.len() as u32, + offset: 0, + }; + + ctx.encoder + .place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::AccelerationStructureUses::SHADER_INPUT + ..hal::AccelerationStructureUses::BUILD_INPUT, + }); + + ctx.encoder.build_acceleration_structures( + 1, + [hal::BuildAccelerationStructureDescriptor { + mode: hal::AccelerationStructureBuildMode::Update, + flags: tlas_flags, + destination_acceleration_structure: &self.tlas, + scratch_buffer: &self.scratch_buffer, + entries: &hal::AccelerationStructureEntries::Instances(instances), + source_acceleration_structure: Some(&self.tlas), + scratch_buffer_offset: 0, + }], + ); + + ctx.encoder + .place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { + usage: hal::AccelerationStructureUses::BUILD_OUTPUT + ..hal::AccelerationStructureUses::SHADER_INPUT, + }); + + let scratch_buffer_barrier = hal::BufferBarrier { + buffer: &self.scratch_buffer, + usage: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + ..hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }; + ctx.encoder + .transition_buffers(iter::once(scratch_buffer_barrier)); + + ctx.encoder.transition_textures(iter::once(target_barrier0)); + } + + let surface_view_desc = hal::TextureViewDescriptor { + label: None, + format: self.surface_format, + dimension: wgt::TextureViewDimension::D2, + usage: hal::TextureUses::COPY_DST, + range: wgt::ImageSubresourceRange::default(), + plane: None, + }; + let surface_tex_view = unsafe { + self.device + .create_texture_view(surface_tex.borrow(), &surface_view_desc) + .unwrap() + }; + unsafe { + ctx.encoder.begin_compute_pass(&hal::ComputePassDescriptor { + label: None, + timestamp_writes: None, + }); + ctx.encoder.set_compute_pipeline(&self.pipeline); + ctx.encoder + .set_bind_group(&self.pipeline_layout, 0, &self.bind_group, &[]); + ctx.encoder.dispatch([512 / 8, 512 / 8, 1]); + } + + ctx.frames_recorded += 1; + let do_fence = ctx.frames_recorded > COMMAND_BUFFER_PER_CONTEXT; + + let target_barrier1 = hal::TextureBarrier { + texture: surface_tex.borrow(), + range: wgt::ImageSubresourceRange::default(), + usage: hal::TextureUses::COPY_DST..hal::TextureUses::PRESENT, + }; + let target_barrier2 = hal::TextureBarrier { + texture: &self.texture, + range: wgt::ImageSubresourceRange::default(), + usage: hal::TextureUses::STORAGE_READ_WRITE..hal::TextureUses::COPY_SRC, + }; + let target_barrier3 = hal::TextureBarrier { + texture: &self.texture, + range: wgt::ImageSubresourceRange::default(), + usage: hal::TextureUses::COPY_SRC..hal::TextureUses::STORAGE_READ_WRITE, + }; + unsafe { + ctx.encoder.end_compute_pass(); + ctx.encoder.transition_textures(iter::once(target_barrier2)); + ctx.encoder.copy_texture_to_texture( + &self.texture, + hal::TextureUses::COPY_SRC, + surface_tex.borrow(), + std::iter::once(hal::TextureCopy { + src_base: hal::TextureCopyBase { + mip_level: 0, + array_layer: 0, + origin: wgt::Origin3d::ZERO, + aspect: hal::FormatAspects::COLOR, + }, + dst_base: hal::TextureCopyBase { + mip_level: 0, + array_layer: 0, + origin: wgt::Origin3d::ZERO, + aspect: hal::FormatAspects::COLOR, + }, + size: hal::CopyExtent { + width: 512, + height: 512, + depth: 1, + }, + }), + ); + ctx.encoder.transition_textures(iter::once(target_barrier1)); + ctx.encoder.transition_textures(iter::once(target_barrier3)); + } + + unsafe { + let cmd_buf = ctx.encoder.end_encoding().unwrap(); + let fence_param = if do_fence { + Some((&mut ctx.fence, ctx.fence_value)) + } else { + None + }; + self.queue.submit(&[&cmd_buf], fence_param).unwrap(); + self.queue.present(&self.surface, surface_tex).unwrap(); + ctx.used_cmd_bufs.push(cmd_buf); + ctx.used_views.push(surface_tex_view); + }; + + if do_fence { + log::info!("Context switch from {}", self.context_index); + let old_fence_value = ctx.fence_value; + if self.contexts.len() == 1 { + let hal_desc = hal::CommandEncoderDescriptor { + label: None, + queue: &self.queue, + }; + self.contexts.push(unsafe { + ExecutionContext { + encoder: self.device.create_command_encoder(&hal_desc).unwrap(), + fence: self.device.create_fence().unwrap(), + fence_value: 0, + used_views: Vec::new(), + used_cmd_bufs: Vec::new(), + frames_recorded: 0, + } + }); + } + self.context_index = (self.context_index + 1) % self.contexts.len(); + let next = &mut self.contexts[self.context_index]; + unsafe { + next.wait_and_clear(&self.device); + } + next.fence_value = old_fence_value + 1; + } + } + + fn exit(mut self) { + unsafe { + { + let ctx = &mut self.contexts[self.context_index]; + self.queue + .submit(&[], Some((&mut ctx.fence, ctx.fence_value))) + .unwrap(); + } + + for mut ctx in self.contexts { + ctx.wait_and_clear(&self.device); + self.device.destroy_command_encoder(ctx.encoder); + self.device.destroy_fence(ctx.fence); + } + + self.device.destroy_bind_group(self.bind_group); + self.device.destroy_buffer(self.scratch_buffer); + self.device.destroy_buffer(self.instances_buffer); + self.device.destroy_buffer(self.indices_buffer); + self.device.destroy_buffer(self.vertices_buffer); + self.device.destroy_buffer(self.uniform_buffer); + self.device.destroy_acceleration_structure(self.tlas); + self.device.destroy_acceleration_structure(self.blas); + self.device.destroy_texture_view(self.texture_view); + self.device.destroy_texture(self.texture); + self.device.destroy_compute_pipeline(self.pipeline); + self.device.destroy_pipeline_layout(self.pipeline_layout); + self.device.destroy_bind_group_layout(self.bgl); + self.device.destroy_shader_module(self.shader_module); + + self.surface.unconfigure(&self.device); + self.device.exit(self.queue); + self.instance.destroy_surface(self.surface); + drop(self.adapter); + } + } +} + +cfg_if::cfg_if! { + // Apple + Metal + if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] { + type Api = hal::api::Metal; + } + // Wasm + Vulkan + else if #[cfg(all(not(target_arch = "wasm32"), feature = "vulkan"))] { + type Api = hal::api::Vulkan; + } + // Windows + DX12 + else if #[cfg(all(windows, feature = "dx12"))] { + type Api = hal::api::Dx12; + } + // Anything + GLES + else if #[cfg(feature = "gles")] { + type Api = hal::api::Gles; + } + // Fallback + else { + type Api = hal::api::Empty; + } +} + +fn main() { + env_logger::init(); + + let event_loop = winit::event_loop::EventLoop::new().unwrap(); + let window = winit::window::WindowBuilder::new() + .with_title("hal-ray-traced-triangle") + .with_inner_size(winit::dpi::PhysicalSize { + width: 512, + height: 512, + }) + .with_resizable(false) + .with_enabled_buttons(WindowButtons::CLOSE) + .build(&event_loop) + .unwrap(); + + let example_result = Example::::init(&window); + let mut example = Some(example_result.expect("Selected backend is not supported")); + + event_loop + .run(move |event, target| { + let _ = &window; // force ownership by the closure + target.set_control_flow(winit::event_loop::ControlFlow::Poll); + match event { + winit::event::Event::WindowEvent { event, .. } => match event { + winit::event::WindowEvent::CloseRequested => { + target.exit(); + } + winit::event::WindowEvent::KeyboardInput { event, .. } + if event.physical_key + == winit::keyboard::PhysicalKey::Code( + winit::keyboard::KeyCode::Escape, + ) => + { + target.exit(); + } + winit::event::WindowEvent::RedrawRequested => { + let ex = example.as_mut().unwrap(); + ex.render(); + } + _ => { + example.as_mut().unwrap().update(event); + } + }, + winit::event::Event::LoopExiting => { + example.take().unwrap().exit(); + } + winit::event::Event::AboutToWait => { + window.request_redraw(); + } + _ => {} + } + }) + .unwrap(); +} diff --git a/third_party/rust/wgpu-hal/examples/ray-traced-triangle/shader.wgsl b/third_party/rust/wgpu-hal/examples/ray-traced-triangle/shader.wgsl new file mode 100644 index 0000000000000..8d9e475e3eea8 --- /dev/null +++ b/third_party/rust/wgpu-hal/examples/ray-traced-triangle/shader.wgsl @@ -0,0 +1,37 @@ +struct Uniforms { + view_inv: mat4x4, + proj_inv: mat4x4, +}; +@group(0) @binding(0) +var uniforms: Uniforms; + +@group(0) @binding(1) +var output: texture_storage_2d; + +@group(0) @binding(2) +var acc_struct: acceleration_structure; + +@compute @workgroup_size(8, 8) +fn main(@builtin(global_invocation_id) global_id: vec3) { + let target_size = textureDimensions(output); + + let pixel_center = vec2(global_id.xy) + vec2(0.5); + let in_uv = pixel_center / vec2(target_size.xy); + let d = in_uv * 2.0 - 1.0; + + let origin = (uniforms.view_inv * vec4(0.0, 0.0, 0.0, 1.0)).xyz; + let temp = uniforms.proj_inv * vec4(d.x, d.y, 1.0, 1.0); + let direction = (uniforms.view_inv * vec4(normalize(temp.xyz), 0.0)).xyz; + + var rq: ray_query; + rayQueryInitialize(&rq, acc_struct, RayDesc(0u, 0xFFu, 0.1, 200.0, origin, direction)); + rayQueryProceed(&rq); + + var color = vec4(0.0, 0.0, 0.0, 1.0); + let intersection = rayQueryGetCommittedIntersection(&rq); + if intersection.kind != RAY_QUERY_INTERSECTION_NONE { + color = vec4(intersection.barycentrics, 1.0 - intersection.barycentrics.x - intersection.barycentrics.y, 1.0); + } + + textureStore(output, global_id.xy, color); +} \ No newline at end of file diff --git a/third_party/rust/wgpu-hal/src/auxil/mod.rs b/third_party/rust/wgpu-hal/src/auxil/mod.rs index f0aa6a4a8921a..5e45c1f2b6fa4 100644 --- a/third_party/rust/wgpu-hal/src/auxil/mod.rs +++ b/third_party/rust/wgpu-hal/src/auxil/mod.rs @@ -1,4 +1,4 @@ -#[cfg(all(any(feature = "dx11", feature = "dx12"), windows))] +#[cfg(all(feature = "dx12", windows))] pub(super) mod dxgi; #[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] diff --git a/third_party/rust/wgpu-hal/src/dx11/adapter.rs b/third_party/rust/wgpu-hal/src/dx11/adapter.rs deleted file mode 100644 index 3d465ae21f8a6..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/adapter.rs +++ /dev/null @@ -1,303 +0,0 @@ -use std::num::NonZeroU64; - -use winapi::um::{d3d11, d3dcommon}; - -impl crate::Adapter for super::Adapter { - unsafe fn open( - &self, - features: wgt::Features, - limits: &wgt::Limits, - ) -> Result, crate::DeviceError> { - todo!() - } - - unsafe fn texture_format_capabilities( - &self, - format: wgt::TextureFormat, - ) -> crate::TextureFormatCapabilities { - todo!() - } - - unsafe fn surface_capabilities( - &self, - surface: &super::Surface, - ) -> Option { - todo!() - } - - unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { - todo!() - } -} - -impl super::Adapter { - pub(super) fn expose( - instance: &super::library::D3D11Lib, - adapter: d3d12::DxgiAdapter, - ) -> Option> { - use d3dcommon::{ - D3D_FEATURE_LEVEL_10_0 as FL10_0, D3D_FEATURE_LEVEL_10_1 as FL10_1, - D3D_FEATURE_LEVEL_11_0 as FL11_0, D3D_FEATURE_LEVEL_11_1 as FL11_1, - D3D_FEATURE_LEVEL_9_1 as FL9_1, D3D_FEATURE_LEVEL_9_2 as FL9_2, - D3D_FEATURE_LEVEL_9_3 as FL9_3, - }; - - let (device, feature_level) = instance.create_device(adapter)?; - - // - // Query Features from d3d11 - // - - let d3d9_features = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D9_OPTIONS1, - ) - }; - - let d3d10_features = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, - ) - }; - - let d3d11_features = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D11_OPTIONS, - ) - }; - - let d3d11_features1 = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D11_OPTIONS1, - ) - }; - - let d3d11_features2 = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D11_OPTIONS2, - ) - }; - - let d3d11_features3 = unsafe { - device.check_feature_support::( - d3d11::D3D11_FEATURE_D3D11_OPTIONS3, - ) - }; - - // - // Fill out features and downlevel features - // - // TODO(cwfitzgerald): Needed downlevel features: 3D dispatch - - let mut features = wgt::Features::DEPTH_CLIP_CONTROL - | wgt::Features::PUSH_CONSTANTS - | wgt::Features::POLYGON_MODE_LINE - | wgt::Features::CLEAR_TEXTURE - | wgt::Features::TEXTURE_FORMAT_16BIT_NORM - | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO - | wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER; - let mut downlevel = wgt::DownlevelFlags::BASE_VERTEX - | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL - | wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER - | wgt::DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES; - - // Features from queries - downlevel.set( - wgt::DownlevelFlags::NON_POWER_OF_TWO_MIPMAPPED_TEXTURES, - d3d9_features.FullNonPow2TextureSupported == 1, - ); - downlevel.set( - wgt::DownlevelFlags::COMPUTE_SHADERS, - d3d10_features.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x == 1, - ); - - // Features from feature level - if feature_level >= FL9_2 { - downlevel |= wgt::DownlevelFlags::INDEPENDENT_BLEND; - // formally FL9_1 supports aniso 2, but we don't support that level of distinction - downlevel |= wgt::DownlevelFlags::ANISOTROPIC_FILTERING; - // this is actually the first FL that supports u32 at all - downlevel |= wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32; - } - - if feature_level >= FL9_3 { - downlevel |= wgt::DownlevelFlags::COMPARISON_SAMPLERS; - } - - if feature_level >= FL10_0 { - downlevel |= wgt::DownlevelFlags::FRAGMENT_STORAGE; - downlevel |= wgt::DownlevelFlags::FRAGMENT_WRITABLE_STORAGE; - downlevel |= wgt::DownlevelFlags::DEPTH_BIAS_CLAMP; - downlevel |= wgt::DownlevelFlags::VERTEX_STORAGE; - features |= wgt::Features::DEPTH_CLIP_CONTROL; - features |= wgt::Features::TIMESTAMP_QUERY; - features |= wgt::Features::PIPELINE_STATISTICS_QUERY; - features |= wgt::Features::SHADER_PRIMITIVE_INDEX; - features |= wgt::Features::DEPTH32FLOAT_STENCIL8; - features |= wgt::Features::RG11B10UFLOAT_RENDERABLE; - } - - if feature_level >= FL10_1 { - downlevel |= wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES; - downlevel |= wgt::DownlevelFlags::MULTISAMPLED_SHADING; - } - - if feature_level >= FL11_0 { - downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION; - downlevel |= wgt::DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT; - features |= wgt::Features::TEXTURE_COMPRESSION_BC; - } - - if feature_level >= FL11_1 { - features |= wgt::Features::VERTEX_WRITABLE_STORAGE; - } - - // bgra8unorm-storage is never supported on dx11 according to: - // https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/format-support-for-direct3d-11-0-feature-level-hardware#dxgi_format_b8g8r8a8_unormfcs-87 - - // float32-filterable should always be available on dx11 - // https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/format-support-for-direct3d-11-0-feature-level-hardware#dxgi_format_r32g32b32a32_floatfcs-2 - features.set(wgt::Features::FLOAT32_FILTERABLE, true); - - // - // Fill out limits and alignments - // - - let max_texture_dimension_2d = match feature_level { - FL9_1 | FL9_2 => 2048, - FL9_3 => 4096, - FL10_0 | FL10_1 => 8192, - _ => d3d11::D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION, - }; - - let max_texture_dimension_3d = match feature_level { - FL9_1..=FL9_3 => 256, - _ => d3d11::D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION, - }; - let max_vertex_buffers = match feature_level { - FL9_1..=FL9_3 => 16, - _ => 32, - } - .min(crate::MAX_VERTEX_BUFFERS as u32); - let max_compute_workgroup_storage_size = match feature_level { - FL9_1..=FL9_3 => 0, - FL10_0 | FL10_1 => 4096 * 4, // This doesn't have an equiv SM4 constant :\ - _ => d3d11::D3D11_CS_TGSM_REGISTER_COUNT * 4, - }; - let max_workgroup_size_xy = match feature_level { - FL9_1..=FL9_3 => 0, - FL10_0 | FL10_1 => d3d11::D3D11_CS_4_X_THREAD_GROUP_MAX_X, - _ => d3d11::D3D11_CS_THREAD_GROUP_MAX_X, - }; - let max_workgroup_size_z = match feature_level { - FL9_1..=FL9_3 => 0, - FL10_0 | FL10_1 => 1, - _ => d3d11::D3D11_CS_THREAD_GROUP_MAX_Z, - }; - // let max_workgroup_count_z = match feature_level { - // FL9_1..=FL9_3 => 0, - // FL10_0 | FL10_1 => 1, - // _ => d3d11::D3D11_CS_THREAD_GROUP_MAX_Z, - // }; - - let max_sampled_textures = d3d11::D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT; - let max_samplers = d3d11::D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; - let max_constant_buffers = d3d11::D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1; - let max_uavs = if device.as_device1().is_some() { - d3d11::D3D11_1_UAV_SLOT_COUNT - } else { - d3d11::D3D11_PS_CS_UAV_REGISTER_COUNT - }; - let max_output_registers = d3d11::D3D11_VS_OUTPUT_REGISTER_COMPONENTS; - let max_compute_invocations_per_workgroup = - d3d11::D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP; - let max_compute_workgroups_per_dimension = - d3d11::D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION; - - let limits = wgt::Limits { - max_texture_dimension_1d: max_texture_dimension_2d, - max_texture_dimension_2d, - max_texture_dimension_3d, - max_texture_array_layers: max_texture_dimension_3d, - max_bind_groups: u32::MAX, - max_bindings_per_bind_group: 65535, - max_dynamic_uniform_buffers_per_pipeline_layout: max_constant_buffers, - max_dynamic_storage_buffers_per_pipeline_layout: 0, - max_sampled_textures_per_shader_stage: max_sampled_textures, - max_samplers_per_shader_stage: max_samplers, - max_storage_buffers_per_shader_stage: max_uavs, - max_storage_textures_per_shader_stage: max_uavs, - max_uniform_buffers_per_shader_stage: max_constant_buffers, - max_uniform_buffer_binding_size: 1 << 16, - max_storage_buffer_binding_size: u32::MAX, - max_vertex_buffers, - max_vertex_attributes: max_vertex_buffers, - max_vertex_buffer_array_stride: u32::MAX, - max_push_constant_size: 1 << 16, - min_uniform_buffer_offset_alignment: 256, - min_storage_buffer_offset_alignment: 1, - max_inter_stage_shader_components: max_output_registers, - max_compute_workgroup_storage_size, - max_compute_invocations_per_workgroup, - max_compute_workgroup_size_x: max_workgroup_size_xy, - max_compute_workgroup_size_y: max_workgroup_size_xy, - max_compute_workgroup_size_z: max_workgroup_size_z, - max_compute_workgroups_per_dimension, - // D3D11_BUFFER_DESC represents the buffer size as a 32 bit int. - max_buffer_size: u32::MAX as u64, - max_non_sampler_bindings: u32::MAX, - }; - - // - // Other capabilities - // - - let shader_model = match feature_level { - FL9_1..=FL9_3 => wgt::ShaderModel::Sm2, - FL10_0 | FL10_1 => wgt::ShaderModel::Sm4, - _ => wgt::ShaderModel::Sm5, - }; - - let device_info = wgt::AdapterInfo { - name: String::new(), - vendor: 0, - device: 0, - device_type: match d3d11_features2.UnifiedMemoryArchitecture { - 0 => wgt::DeviceType::DiscreteGpu, - 1 => wgt::DeviceType::IntegratedGpu, - _ => unreachable!(), - }, - driver: String::new(), - driver_info: String::new(), - backend: wgt::Backend::Dx11, - }; - - // - // Build up the structs - // - - let api_adapter = super::Adapter { device }; - - let alignments = crate::Alignments { - buffer_copy_offset: NonZeroU64::new(1).unwrap(), // todo - buffer_copy_pitch: NonZeroU64::new(1).unwrap(), // todo - }; - - let capabilities = crate::Capabilities { - limits, - alignments, - downlevel: wgt::DownlevelCapabilities { - flags: downlevel, - limits: wgt::DownlevelLimits {}, - shader_model, - }, - }; - - Some(crate::ExposedAdapter { - adapter: api_adapter, - info: device_info, - features, - capabilities, - }) - } -} diff --git a/third_party/rust/wgpu-hal/src/dx11/command.rs b/third_party/rust/wgpu-hal/src/dx11/command.rs deleted file mode 100644 index e5cc92bff9619..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/command.rs +++ /dev/null @@ -1,271 +0,0 @@ -impl crate::CommandEncoder for super::CommandEncoder { - unsafe fn begin_encoding(&mut self, label: crate::Label) -> Result<(), crate::DeviceError> { - todo!() - } - - unsafe fn discard_encoding(&mut self) { - todo!() - } - - unsafe fn end_encoding(&mut self) -> Result { - todo!() - } - - unsafe fn reset_all(&mut self, command_buffers: I) - where - I: Iterator, - { - todo!() - } - - unsafe fn transition_buffers<'a, T>(&mut self, barriers: T) - where - T: Iterator>, - { - todo!() - } - - unsafe fn transition_textures<'a, T>(&mut self, barriers: T) - where - T: Iterator>, - { - todo!() - } - - unsafe fn clear_buffer(&mut self, buffer: &super::Buffer, range: crate::MemoryRange) { - todo!() - } - - unsafe fn copy_buffer_to_buffer( - &mut self, - src: &super::Buffer, - dst: &super::Buffer, - regions: T, - ) where - T: Iterator, - { - todo!() - } - - unsafe fn copy_texture_to_texture( - &mut self, - src: &super::Texture, - src_usage: crate::TextureUses, - dst: &super::Texture, - regions: T, - ) where - T: Iterator, - { - todo!() - } - - unsafe fn copy_buffer_to_texture( - &mut self, - src: &super::Buffer, - dst: &super::Texture, - regions: T, - ) where - T: Iterator, - { - todo!() - } - - unsafe fn copy_texture_to_buffer( - &mut self, - src: &super::Texture, - src_usage: crate::TextureUses, - dst: &super::Buffer, - regions: T, - ) where - T: Iterator, - { - todo!() - } - - unsafe fn set_bind_group( - &mut self, - layout: &super::PipelineLayout, - index: u32, - group: &super::BindGroup, - dynamic_offsets: &[wgt::DynamicOffset], - ) { - todo!() - } - - unsafe fn set_push_constants( - &mut self, - layout: &super::PipelineLayout, - stages: wgt::ShaderStages, - offset_bytes: u32, - data: &[u32], - ) { - todo!() - } - - unsafe fn insert_debug_marker(&mut self, label: &str) { - todo!() - } - - unsafe fn begin_debug_marker(&mut self, group_label: &str) { - todo!() - } - - unsafe fn end_debug_marker(&mut self) { - todo!() - } - - unsafe fn begin_query(&mut self, set: &super::QuerySet, index: u32) { - todo!() - } - - unsafe fn end_query(&mut self, set: &super::QuerySet, index: u32) { - todo!() - } - - unsafe fn write_timestamp(&mut self, set: &super::QuerySet, index: u32) { - todo!() - } - - unsafe fn reset_queries(&mut self, set: &super::QuerySet, range: std::ops::Range) { - todo!() - } - - unsafe fn copy_query_results( - &mut self, - set: &super::QuerySet, - range: std::ops::Range, - buffer: &super::Buffer, - offset: wgt::BufferAddress, - stride: wgt::BufferSize, - ) { - todo!() - } - - unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor) { - todo!() - } - - unsafe fn end_render_pass(&mut self) { - todo!() - } - - unsafe fn set_render_pipeline(&mut self, pipeline: &super::RenderPipeline) { - todo!() - } - - unsafe fn set_index_buffer<'a>( - &mut self, - binding: crate::BufferBinding<'a, super::Api>, - format: wgt::IndexFormat, - ) { - todo!() - } - - unsafe fn set_vertex_buffer<'a>( - &mut self, - index: u32, - binding: crate::BufferBinding<'a, super::Api>, - ) { - todo!() - } - - unsafe fn set_viewport(&mut self, rect: &crate::Rect, depth_range: std::ops::Range) { - todo!() - } - - unsafe fn set_scissor_rect(&mut self, rect: &crate::Rect) { - todo!() - } - - unsafe fn set_stencil_reference(&mut self, value: u32) { - todo!() - } - - unsafe fn set_blend_constants(&mut self, color: &[f32; 4]) { - todo!() - } - - unsafe fn draw( - &mut self, - first_vertex: u32, - vertex_count: u32, - first_instance: u32, - instance_count: u32, - ) { - todo!() - } - - unsafe fn draw_indexed( - &mut self, - first_index: u32, - index_count: u32, - base_vertex: i32, - first_instance: u32, - instance_count: u32, - ) { - todo!() - } - - unsafe fn draw_indirect( - &mut self, - buffer: &super::Buffer, - offset: wgt::BufferAddress, - draw_count: u32, - ) { - todo!() - } - - unsafe fn draw_indexed_indirect( - &mut self, - buffer: &super::Buffer, - offset: wgt::BufferAddress, - draw_count: u32, - ) { - todo!() - } - - unsafe fn draw_indirect_count( - &mut self, - buffer: &super::Buffer, - offset: wgt::BufferAddress, - count_buffer: &super::Buffer, - count_offset: wgt::BufferAddress, - max_count: u32, - ) { - todo!() - } - - unsafe fn draw_indexed_indirect_count( - &mut self, - buffer: &super::Buffer, - offset: wgt::BufferAddress, - count_buffer: &super::Buffer, - count_offset: wgt::BufferAddress, - max_count: u32, - ) { - todo!() - } - - unsafe fn begin_compute_pass<'a>( - &mut self, - desc: &crate::ComputePassDescriptor<'a, super::Api>, - ) { - todo!() - } - - unsafe fn end_compute_pass(&mut self) { - todo!() - } - - unsafe fn set_compute_pipeline(&mut self, pipeline: &super::ComputePipeline) { - todo!() - } - - unsafe fn dispatch(&mut self, count: [u32; 3]) { - todo!() - } - - unsafe fn dispatch_indirect(&mut self, buffer: &super::Buffer, offset: wgt::BufferAddress) { - todo!() - } -} diff --git a/third_party/rust/wgpu-hal/src/dx11/device.rs b/third_party/rust/wgpu-hal/src/dx11/device.rs deleted file mode 100644 index ce33584e35a0e..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/device.rs +++ /dev/null @@ -1,242 +0,0 @@ -use std::{ffi::c_void, mem}; - -use winapi::um::d3d11; - -use crate::auxil::dxgi::result::HResult; - -impl crate::Device for super::Device { - unsafe fn exit(self, queue: super::Queue) { - todo!() - } - - unsafe fn create_buffer( - &self, - desc: &crate::BufferDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_buffer(&self, buffer: super::Buffer) { - todo!() - } - - unsafe fn map_buffer( - &self, - buffer: &super::Buffer, - range: crate::MemoryRange, - ) -> Result { - todo!() - } - - unsafe fn unmap_buffer(&self, buffer: &super::Buffer) -> Result<(), crate::DeviceError> { - todo!() - } - - unsafe fn flush_mapped_ranges(&self, buffer: &super::Buffer, ranges: I) - where - I: Iterator, - { - todo!() - } - - unsafe fn invalidate_mapped_ranges(&self, buffer: &super::Buffer, ranges: I) - where - I: Iterator, - { - todo!() - } - - unsafe fn create_texture( - &self, - desc: &crate::TextureDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_texture(&self, texture: super::Texture) { - todo!() - } - - unsafe fn create_texture_view( - &self, - texture: &super::Texture, - desc: &crate::TextureViewDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_texture_view(&self, view: super::TextureView) { - todo!() - } - - unsafe fn create_sampler( - &self, - desc: &crate::SamplerDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_sampler(&self, sampler: super::Sampler) { - todo!() - } - - unsafe fn create_command_encoder( - &self, - desc: &crate::CommandEncoderDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_command_encoder(&self, pool: super::CommandEncoder) { - todo!() - } - - unsafe fn create_bind_group_layout( - &self, - desc: &crate::BindGroupLayoutDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_bind_group_layout(&self, bg_layout: super::BindGroupLayout) { - todo!() - } - - unsafe fn create_pipeline_layout( - &self, - desc: &crate::PipelineLayoutDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_pipeline_layout(&self, pipeline_layout: super::PipelineLayout) { - todo!() - } - - unsafe fn create_bind_group( - &self, - desc: &crate::BindGroupDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_bind_group(&self, group: super::BindGroup) { - todo!() - } - - unsafe fn create_shader_module( - &self, - desc: &crate::ShaderModuleDescriptor, - shader: crate::ShaderInput, - ) -> Result { - todo!() - } - - unsafe fn destroy_shader_module(&self, module: super::ShaderModule) { - todo!() - } - - unsafe fn create_render_pipeline( - &self, - desc: &crate::RenderPipelineDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_render_pipeline(&self, pipeline: super::RenderPipeline) { - todo!() - } - - unsafe fn create_compute_pipeline( - &self, - desc: &crate::ComputePipelineDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_compute_pipeline(&self, pipeline: super::ComputePipeline) { - todo!() - } - - unsafe fn create_query_set( - &self, - desc: &wgt::QuerySetDescriptor, - ) -> Result { - todo!() - } - - unsafe fn destroy_query_set(&self, set: super::QuerySet) { - todo!() - } - - unsafe fn create_fence(&self) -> Result { - todo!() - } - - unsafe fn destroy_fence(&self, fence: super::Fence) { - todo!() - } - - unsafe fn get_fence_value( - &self, - fence: &super::Fence, - ) -> Result { - todo!() - } - - unsafe fn wait( - &self, - fence: &super::Fence, - value: crate::FenceValue, - timeout_ms: u32, - ) -> Result { - todo!() - } - - unsafe fn start_capture(&self) -> bool { - todo!() - } - - unsafe fn stop_capture(&self) { - todo!() - } -} - -impl crate::Queue for super::Queue { - unsafe fn submit( - &self, - command_buffers: &[&super::CommandBuffer], - signal_fence: Option<(&mut super::Fence, crate::FenceValue)>, - ) -> Result<(), crate::DeviceError> { - todo!() - } - - unsafe fn present( - &self, - surface: &super::Surface, - texture: super::SurfaceTexture, - ) -> Result<(), crate::SurfaceError> { - todo!() - } - - unsafe fn get_timestamp_period(&self) -> f32 { - todo!() - } -} - -impl super::D3D11Device { - #[allow(trivial_casts)] // come on - pub unsafe fn check_feature_support(&self, feature: d3d11::D3D11_FEATURE) -> T { - unsafe { - let mut value = mem::zeroed::(); - let ret = self.CheckFeatureSupport( - feature, - &mut value as *mut T as *mut c_void, - mem::size_of::() as u32, - ); - assert_eq!(ret.into_result(), Ok(())); - - value - } - } -} diff --git a/third_party/rust/wgpu-hal/src/dx11/instance.rs b/third_party/rust/wgpu-hal/src/dx11/instance.rs deleted file mode 100644 index 7df96ca6bd813..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/instance.rs +++ /dev/null @@ -1,53 +0,0 @@ -use crate::auxil; - -impl crate::Instance for super::Instance { - unsafe fn init(desc: &crate::InstanceDescriptor) -> Result { - profiling::scope!("Init DX11 Backend"); - - let enable_dx11 = match std::env::var("WGPU_UNSTABLE_DX11_BACKEND") { - Ok(string) => string == "1" || string == "true", - Err(_) => false, - }; - - if !enable_dx11 { - return Err(crate::InstanceError::new(String::from( - "DX11 support is unstable; set WGPU_UNSTABLE_DX11_BACKEND=1 to enable anyway", - ))); - } - - let lib_d3d11 = super::library::D3D11Lib::new() - .ok_or_else(|| crate::InstanceError::new(String::from("failed to load d3d11.dll")))?; - - let (lib_dxgi, factory) = auxil::dxgi::factory::create_factory( - auxil::dxgi::factory::DxgiFactoryType::Factory1, - desc.flags, - )?; - - Ok(super::Instance { - lib_d3d11, - lib_dxgi, - factory, - }) - } - - unsafe fn create_surface( - &self, - display_handle: raw_window_handle::RawDisplayHandle, - window_handle: raw_window_handle::RawWindowHandle, - ) -> Result { - todo!() - } - - unsafe fn destroy_surface(&self, surface: super::Surface) { - todo!() - } - - unsafe fn enumerate_adapters(&self) -> Vec> { - let adapters = auxil::dxgi::factory::enumerate_adapters(self.factory.clone()); - - adapters - .into_iter() - .filter_map(|adapter| super::Adapter::expose(&self.lib_d3d11, adapter)) - .collect() - } -} diff --git a/third_party/rust/wgpu-hal/src/dx11/library.rs b/third_party/rust/wgpu-hal/src/dx11/library.rs deleted file mode 100644 index 2b7b1b1c2ae50..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/library.rs +++ /dev/null @@ -1,142 +0,0 @@ -use std::ptr; - -use winapi::{ - shared::{ - dxgi, - minwindef::{HMODULE, UINT}, - winerror, - }, - um::{d3d11, d3d11_1, d3d11_2, d3dcommon}, -}; - -use crate::auxil::dxgi::result::HResult; - -type D3D11CreateDeviceFun = unsafe extern "system" fn( - *mut dxgi::IDXGIAdapter, - d3dcommon::D3D_DRIVER_TYPE, - HMODULE, - UINT, - *const d3dcommon::D3D_FEATURE_LEVEL, - UINT, - UINT, - *mut *mut d3d11::ID3D11Device, - *mut d3dcommon::D3D_FEATURE_LEVEL, - *mut *mut d3d11::ID3D11DeviceContext, -) -> d3d12::HRESULT; - -pub(super) struct D3D11Lib { - // We use the os specific symbol to drop the lifetime parameter. - // - // SAFETY: we must ensure this outlives the Library. - d3d11_create_device: libloading::os::windows::Symbol, - - lib: libloading::Library, -} -impl D3D11Lib { - pub fn new() -> Option { - unsafe { - let lib = libloading::Library::new("d3d11.dll").ok()?; - - let d3d11_create_device = lib - .get::(b"D3D11CreateDevice") - .ok()? - .into_raw(); - - Some(Self { - lib, - d3d11_create_device, - }) - } - } - - pub fn create_device( - &self, - adapter: d3d12::DxgiAdapter, - ) -> Option<(super::D3D11Device, d3dcommon::D3D_FEATURE_LEVEL)> { - let feature_levels = [ - d3dcommon::D3D_FEATURE_LEVEL_11_1, - d3dcommon::D3D_FEATURE_LEVEL_11_0, - d3dcommon::D3D_FEATURE_LEVEL_10_1, - d3dcommon::D3D_FEATURE_LEVEL_10_0, - d3dcommon::D3D_FEATURE_LEVEL_9_3, - d3dcommon::D3D_FEATURE_LEVEL_9_2, - d3dcommon::D3D_FEATURE_LEVEL_9_1, - ]; - - let mut device = d3d12::ComPtr::::null(); - let mut feature_level: d3dcommon::D3D_FEATURE_LEVEL = 0; - - // We need to try this twice. If the first time fails due to E_INVALIDARG - // we are running on a machine without a D3D11.1 runtime, and need to - // retry without the feature level 11_1 feature level. - // - // Why they thought this was a good API, who knows. - - let mut hr = unsafe { - (self.d3d11_create_device)( - adapter.as_mut_ptr() as *mut _, - d3dcommon::D3D_DRIVER_TYPE_UNKNOWN, - ptr::null_mut(), // software implementation DLL??? - 0, // flags - feature_levels.as_ptr(), - feature_levels.len() as u32, - d3d11::D3D11_SDK_VERSION, - device.mut_self(), - &mut feature_level, - ptr::null_mut(), // device context - ) - }; - - // Try again without FL11_1 - if hr == winerror::E_INVALIDARG { - hr = unsafe { - (self.d3d11_create_device)( - adapter.as_mut_ptr() as *mut _, - d3dcommon::D3D_DRIVER_TYPE_UNKNOWN, - ptr::null_mut(), // software implementation DLL??? - 0, // flags - feature_levels[1..].as_ptr(), - feature_levels[1..].len() as u32, - d3d11::D3D11_SDK_VERSION, - device.mut_self(), - &mut feature_level, - ptr::null_mut(), // device context - ) - }; - } - - // Any errors here are real and we should complain about - if let Err(err) = hr.into_result() { - log::error!("Failed to make a D3D11 device: {}", err); - return None; - } - - // We always try to upcast in highest -> lowest order - - // Device -> Device2 - unsafe { - match device.cast::().into_result() { - Ok(device2) => { - return Some((super::D3D11Device::Device2(device2), feature_level)); - } - Err(hr) => { - log::warn!("Failed to cast device to ID3D11Device2: {}", hr) - } - } - } - - // Device -> Device1 - unsafe { - match device.cast::().into_result() { - Ok(device1) => { - return Some((super::D3D11Device::Device1(device1), feature_level)); - } - Err(hr) => { - log::warn!("Failed to cast device to ID3D11Device1: {}", hr) - } - } - } - - Some((super::D3D11Device::Device(device), feature_level)) - } -} diff --git a/third_party/rust/wgpu-hal/src/dx11/mod.rs b/third_party/rust/wgpu-hal/src/dx11/mod.rs deleted file mode 100644 index 203f37cac55d1..0000000000000 --- a/third_party/rust/wgpu-hal/src/dx11/mod.rs +++ /dev/null @@ -1,139 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use winapi::um::{d3d11, d3d11_1, d3d11_2}; - -mod adapter; -mod command; -mod device; -mod instance; -mod library; - -#[derive(Clone, Debug)] -pub struct Api; - -impl crate::Api for Api { - type Instance = Instance; - type Surface = Surface; - type Adapter = Adapter; - type Device = Device; - - type Queue = Queue; - type CommandEncoder = CommandEncoder; - type CommandBuffer = CommandBuffer; - - type Buffer = Buffer; - type Texture = Texture; - type SurfaceTexture = SurfaceTexture; - type TextureView = TextureView; - type Sampler = Sampler; - type QuerySet = QuerySet; - type Fence = Fence; - - type BindGroupLayout = BindGroupLayout; - type BindGroup = BindGroup; - type PipelineLayout = PipelineLayout; - type ShaderModule = ShaderModule; - type RenderPipeline = RenderPipeline; - type ComputePipeline = ComputePipeline; -} - -pub struct Instance { - lib_d3d11: library::D3D11Lib, - lib_dxgi: d3d12::DxgiLib, - factory: d3d12::DxgiFactory, -} - -unsafe impl Send for Instance {} -unsafe impl Sync for Instance {} - -pub struct Surface {} - -pub struct Adapter { - device: D3D11Device, -} - -unsafe impl Send for Adapter {} -unsafe impl Sync for Adapter {} - -d3d12::weak_com_inheritance_chain! { - #[derive(Debug, Clone, PartialEq)] - enum D3D11Device { - Device(d3d11::ID3D11Device), from_device, as_device, device; - Device1(d3d11_1::ID3D11Device1), from_device1, as_device1, unwrap_device1; - Device2(d3d11_2::ID3D11Device2), from_device2, as_device2, unwrap_device2; - } -} - -pub struct Device {} - -unsafe impl Send for Device {} -unsafe impl Sync for Device {} - -pub struct Queue {} - -#[derive(Debug)] -pub struct CommandEncoder {} - -#[derive(Debug)] -pub struct CommandBuffer {} - -#[derive(Debug)] -pub struct Buffer {} -#[derive(Debug)] -pub struct Texture {} -#[derive(Debug)] -pub struct SurfaceTexture {} - -impl std::borrow::Borrow for SurfaceTexture { - fn borrow(&self) -> &Texture { - todo!() - } -} - -#[derive(Debug)] -pub struct TextureView {} -#[derive(Debug)] -pub struct Sampler {} -#[derive(Debug)] -pub struct QuerySet {} -#[derive(Debug)] -pub struct Fence {} - -#[derive(Debug)] -pub struct BindGroupLayout {} -#[derive(Debug)] -pub struct BindGroup {} -#[derive(Debug)] -pub struct PipelineLayout {} -#[derive(Debug)] -pub struct ShaderModule {} -#[derive(Debug)] -pub struct RenderPipeline {} -#[derive(Debug)] -pub struct ComputePipeline {} - -impl crate::Surface for Surface { - unsafe fn configure( - &self, - device: &Device, - config: &crate::SurfaceConfiguration, - ) -> Result<(), crate::SurfaceError> { - todo!() - } - - unsafe fn unconfigure(&self, device: &Device) { - todo!() - } - - unsafe fn acquire_texture( - &self, - _timeout: Option, - ) -> Result>, crate::SurfaceError> { - todo!() - } - - unsafe fn discard_texture(&self, texture: SurfaceTexture) { - todo!() - } -} diff --git a/third_party/rust/wgpu-hal/src/dx12/command.rs b/third_party/rust/wgpu-hal/src/dx12/command.rs index 5bbd0d4ba5cc4..81f0fbccc9645 100644 --- a/third_party/rust/wgpu-hal/src/dx12/command.rs +++ b/third_party/rust/wgpu-hal/src/dx12/command.rs @@ -1192,4 +1192,24 @@ impl crate::CommandEncoder for super::CommandEncoder { ) }; } + + unsafe fn build_acceleration_structures<'a, T>( + &mut self, + _descriptor_count: u32, + _descriptors: T, + ) where + super::Api: 'a, + T: IntoIterator>, + { + // Implement using `BuildRaytracingAccelerationStructure`: + // https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html#buildraytracingaccelerationstructure + todo!() + } + + unsafe fn place_acceleration_structure_barrier( + &mut self, + _barriers: crate::AccelerationStructureBarrier, + ) { + todo!() + } } diff --git a/third_party/rust/wgpu-hal/src/dx12/conv.rs b/third_party/rust/wgpu-hal/src/dx12/conv.rs index f484d1a9e2c4c..2b6c1d959e0d2 100644 --- a/third_party/rust/wgpu-hal/src/dx12/conv.rs +++ b/third_party/rust/wgpu-hal/src/dx12/conv.rs @@ -112,6 +112,7 @@ pub fn map_binding_type(ty: &wgt::BindingType) -> d3d12::DescriptorRangeType { .. } | Bt::StorageTexture { .. } => d3d12::DescriptorRangeType::UAV, + Bt::AccelerationStructure => todo!(), } } diff --git a/third_party/rust/wgpu-hal/src/dx12/device.rs b/third_party/rust/wgpu-hal/src/dx12/device.rs index 90af93661e9e1..9f6133592a0f1 100644 --- a/third_party/rust/wgpu-hal/src/dx12/device.rs +++ b/third_party/rust/wgpu-hal/src/dx12/device.rs @@ -673,6 +673,7 @@ impl crate::Device for super::Device { num_texture_views += count } wgt::BindingType::Sampler { .. } => num_samplers += count, + wgt::BindingType::AccelerationStructure => todo!(), } } @@ -1194,6 +1195,7 @@ impl crate::Device for super::Device { cpu_samplers.as_mut().unwrap().stage.push(data.handle.raw); } } + wgt::BindingType::AccelerationStructure => todo!(), } } @@ -1573,4 +1575,38 @@ impl crate::Device for super::Device { .end_frame_capture(self.raw.as_mut_ptr() as *mut _, ptr::null_mut()) } } + + unsafe fn get_acceleration_structure_build_sizes<'a>( + &self, + _desc: &crate::GetAccelerationStructureBuildSizesDescriptor<'a, super::Api>, + ) -> crate::AccelerationStructureBuildSizes { + // Implement using `GetRaytracingAccelerationStructurePrebuildInfo`: + // https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html#getraytracingaccelerationstructureprebuildinfo + todo!() + } + + unsafe fn get_acceleration_structure_device_address( + &self, + _acceleration_structure: &super::AccelerationStructure, + ) -> wgt::BufferAddress { + // Implement using `GetGPUVirtualAddress`: + // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12resource-getgpuvirtualaddress + todo!() + } + + unsafe fn create_acceleration_structure( + &self, + _desc: &crate::AccelerationStructureDescriptor, + ) -> Result { + // Create a D3D12 resource as per-usual. + todo!() + } + + unsafe fn destroy_acceleration_structure( + &self, + _acceleration_structure: super::AccelerationStructure, + ) { + // Destroy a D3D12 resource as per-usual. + todo!() + } } diff --git a/third_party/rust/wgpu-hal/src/dx12/mod.rs b/third_party/rust/wgpu-hal/src/dx12/mod.rs index c50b0af16520d..4ae224f5fe407 100644 --- a/third_party/rust/wgpu-hal/src/dx12/mod.rs +++ b/third_party/rust/wgpu-hal/src/dx12/mod.rs @@ -82,6 +82,8 @@ impl crate::Api for Api { type ShaderModule = ShaderModule; type RenderPipeline = RenderPipeline; type ComputePipeline = ComputePipeline; + + type AccelerationStructure = AccelerationStructure; } // Limited by D3D12's root signature size of 64. Each element takes 1 or 2 entries. @@ -600,6 +602,9 @@ pub struct ComputePipeline { unsafe impl Send for ComputePipeline {} unsafe impl Sync for ComputePipeline {} +#[derive(Debug)] +pub struct AccelerationStructure {} + impl SwapChain { unsafe fn release_resources(self) -> d3d12::ComPtr { self.raw diff --git a/third_party/rust/wgpu-hal/src/empty.rs b/third_party/rust/wgpu-hal/src/empty.rs index 487d317870892..9fd42bd6f5c53 100644 --- a/third_party/rust/wgpu-hal/src/empty.rs +++ b/third_party/rust/wgpu-hal/src/empty.rs @@ -29,6 +29,7 @@ impl crate::Api for Api { type Sampler = Resource; type QuerySet = Resource; type Fence = Resource; + type AccelerationStructure = Resource; type BindGroupLayout = Resource; type BindGroup = Resource; @@ -236,6 +237,25 @@ impl crate::Device for Context { false } unsafe fn stop_capture(&self) {} + unsafe fn create_acceleration_structure( + &self, + desc: &crate::AccelerationStructureDescriptor, + ) -> DeviceResult { + Ok(Resource) + } + unsafe fn get_acceleration_structure_build_sizes<'a>( + &self, + _desc: &crate::GetAccelerationStructureBuildSizesDescriptor<'a, Api>, + ) -> crate::AccelerationStructureBuildSizes { + Default::default() + } + unsafe fn get_acceleration_structure_device_address( + &self, + _acceleration_structure: &Resource, + ) -> wgt::BufferAddress { + Default::default() + } + unsafe fn destroy_acceleration_structure(&self, _acceleration_structure: Resource) {} } impl crate::CommandEncoder for Encoder { @@ -410,4 +430,20 @@ impl crate::CommandEncoder for Encoder { unsafe fn dispatch(&mut self, count: [u32; 3]) {} unsafe fn dispatch_indirect(&mut self, buffer: &Resource, offset: wgt::BufferAddress) {} + + unsafe fn build_acceleration_structures<'a, T>( + &mut self, + _descriptor_count: u32, + descriptors: T, + ) where + Api: 'a, + T: IntoIterator>, + { + } + + unsafe fn place_acceleration_structure_barrier( + &mut self, + _barriers: crate::AccelerationStructureBarrier, + ) { + } } diff --git a/third_party/rust/wgpu-hal/src/gles/adapter.rs b/third_party/rust/wgpu-hal/src/gles/adapter.rs index 8c35e452c1c45..00db6aba61426 100644 --- a/third_party/rust/wgpu-hal/src/gles/adapter.rs +++ b/third_party/rust/wgpu-hal/src/gles/adapter.rs @@ -219,10 +219,7 @@ impl super::Adapter { log::debug!("Version: {}", version); let full_ver = Self::parse_full_version(&version).ok(); - let es_ver = full_ver - .is_none() - .then_some(()) - .and_then(|_| Self::parse_version(&version).ok()); + let es_ver = full_ver.map_or_else(|| Self::parse_version(&version).ok(), |_| None); let web_gl = cfg!(target_arch = "wasm32"); if let Some(full_ver) = full_ver { @@ -556,6 +553,10 @@ impl super::Adapter { || extensions.contains("OES_texture_float_linear"), ); + if es_ver.is_none() { + features |= wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT; + } + // We *might* be able to emulate bgra8unorm-storage but currently don't attempt to. let mut private_caps = super::PrivateCapabilities::empty(); diff --git a/third_party/rust/wgpu-hal/src/gles/command.rs b/third_party/rust/wgpu-hal/src/gles/command.rs index 28dbf1688de73..fee08f201be2f 100644 --- a/third_party/rust/wgpu-hal/src/gles/command.rs +++ b/third_party/rust/wgpu-hal/src/gles/command.rs @@ -1166,4 +1166,22 @@ impl crate::CommandEncoder for super::CommandEncoder { indirect_offset: offset, }); } + + unsafe fn build_acceleration_structures<'a, T>( + &mut self, + _descriptor_count: u32, + _descriptors: T, + ) where + super::Api: 'a, + T: IntoIterator>, + { + unimplemented!() + } + + unsafe fn place_acceleration_structure_barrier( + &mut self, + _barriers: crate::AccelerationStructureBarrier, + ) { + unimplemented!() + } } diff --git a/third_party/rust/wgpu-hal/src/gles/conv.rs b/third_party/rust/wgpu-hal/src/gles/conv.rs index ebf0c65f5219f..7b3bf6c8f8992 100644 --- a/third_party/rust/wgpu-hal/src/gles/conv.rs +++ b/third_party/rust/wgpu-hal/src/gles/conv.rs @@ -285,18 +285,6 @@ pub fn map_primitive_topology(topology: wgt::PrimitiveTopology) -> u32 { } pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::PrimitiveState { - match state.polygon_mode { - wgt::PolygonMode::Fill => {} - wgt::PolygonMode::Line => panic!( - "{:?} is not enabled for this backend", - wgt::Features::POLYGON_MODE_LINE - ), - wgt::PolygonMode::Point => panic!( - "{:?} is not enabled for this backend", - wgt::Features::POLYGON_MODE_POINT - ), - } - super::PrimitiveState { //Note: we are flipping the front face, so that // the Y-flip in the generated GLSL keeps the same visibility. @@ -311,6 +299,11 @@ pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::Primiti None => 0, }, unclipped_depth: state.unclipped_depth, + polygon_mode: match state.polygon_mode { + wgt::PolygonMode::Fill => glow::FILL, + wgt::PolygonMode::Line => glow::LINE, + wgt::PolygonMode::Point => glow::POINT, + }, } } diff --git a/third_party/rust/wgpu-hal/src/gles/device.rs b/third_party/rust/wgpu-hal/src/gles/device.rs index 35c6f910de6ba..a48fe9dc750cf 100644 --- a/third_party/rust/wgpu-hal/src/gles/device.rs +++ b/third_party/rust/wgpu-hal/src/gles/device.rs @@ -1125,6 +1125,7 @@ impl crate::Device for super::Device { ty: wgt::BufferBindingType::Storage { .. }, .. } => &mut num_storage_buffers, + wgt::BindingType::AccelerationStructure => unimplemented!(), }; binding_to_slot[entry.binding as usize] = *counter; @@ -1211,6 +1212,7 @@ impl crate::Device for super::Device { format: format_desc.internal, }) } + wgt::BindingType::AccelerationStructure => unimplemented!(), }; contents.push(binding); } @@ -1458,6 +1460,25 @@ impl crate::Device for super::Device { .end_frame_capture(ptr::null_mut(), ptr::null_mut()) } } + unsafe fn create_acceleration_structure( + &self, + _desc: &crate::AccelerationStructureDescriptor, + ) -> Result<(), crate::DeviceError> { + unimplemented!() + } + unsafe fn get_acceleration_structure_build_sizes<'a>( + &self, + _desc: &crate::GetAccelerationStructureBuildSizesDescriptor<'a, super::Api>, + ) -> crate::AccelerationStructureBuildSizes { + unimplemented!() + } + unsafe fn get_acceleration_structure_device_address( + &self, + _acceleration_structure: &(), + ) -> wgt::BufferAddress { + unimplemented!() + } + unsafe fn destroy_acceleration_structure(&self, _acceleration_structure: ()) {} } #[cfg(all( diff --git a/third_party/rust/wgpu-hal/src/gles/mod.rs b/third_party/rust/wgpu-hal/src/gles/mod.rs index 9525e45d1395b..7021c3e12d0f8 100644 --- a/third_party/rust/wgpu-hal/src/gles/mod.rs +++ b/third_party/rust/wgpu-hal/src/gles/mod.rs @@ -153,6 +153,7 @@ impl crate::Api for Api { type Sampler = Sampler; type QuerySet = QuerySet; type Fence = Fence; + type AccelerationStructure = (); type BindGroupLayout = BindGroupLayout; type BindGroup = BindGroup; @@ -736,6 +737,7 @@ struct PrimitiveState { front_face: u32, cull_face: u32, unclipped_depth: bool, + polygon_mode: u32, } type InvalidatedAttachments = ArrayVec; diff --git a/third_party/rust/wgpu-hal/src/gles/queue.rs b/third_party/rust/wgpu-hal/src/gles/queue.rs index 0ab88c91cacfd..4ee6fb8e471eb 100644 --- a/third_party/rust/wgpu-hal/src/gles/queue.rs +++ b/third_party/rust/wgpu-hal/src/gles/queue.rs @@ -1330,6 +1330,10 @@ impl super::Queue { unsafe { gl.disable(glow::DEPTH_CLAMP) }; } } + // POLYGON_MODE_LINE also implies POLYGON_MODE_POINT + if self.features.contains(wgt::Features::POLYGON_MODE_LINE) { + unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) }; + } } C::SetBlendConstant(c) => { unsafe { gl.blend_color(c[0], c[1], c[2], c[3]) }; diff --git a/third_party/rust/wgpu-hal/src/lib.rs b/third_party/rust/wgpu-hal/src/lib.rs index 6a03b32a7281e..d312566e520a5 100644 --- a/third_party/rust/wgpu-hal/src/lib.rs +++ b/third_party/rust/wgpu-hal/src/lib.rs @@ -11,7 +11,7 @@ * General design direction is to follow the majority by the following weights: * - wgpu-core: 1.5 * - primary backends (Vulkan/Metal/DX12): 1.0 each - * - secondary backends (DX11/GLES): 0.5 each + * - secondary backend (GLES): 0.5 */ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] @@ -51,9 +51,6 @@ clippy::pattern_type_mismatch, )] -/// DirectX11 API internals. -#[cfg(all(feature = "dx11", windows))] -pub mod dx11; /// DirectX12 API internals. #[cfg(all(feature = "dx12", windows))] pub mod dx12; @@ -71,8 +68,6 @@ pub mod vulkan; pub mod auxil; pub mod api { - #[cfg(all(feature = "dx11", windows))] - pub use super::dx11::Api as Dx11; #[cfg(all(feature = "dx12", windows))] pub use super::dx12::Api as Dx12; pub use super::empty::Api as Empty; @@ -217,6 +212,8 @@ pub trait Api: Clone + fmt::Debug + Sized { type ShaderModule: fmt::Debug + WasmNotSendSync; type RenderPipeline: fmt::Debug + WasmNotSendSync; type ComputePipeline: fmt::Debug + WasmNotSendSync; + + type AccelerationStructure: fmt::Debug + WasmNotSendSync + 'static; } pub trait Instance: Sized + WasmNotSendSync { @@ -390,6 +387,23 @@ pub trait Device: WasmNotSendSync { unsafe fn start_capture(&self) -> bool; unsafe fn stop_capture(&self); + + unsafe fn create_acceleration_structure( + &self, + desc: &AccelerationStructureDescriptor, + ) -> Result; + unsafe fn get_acceleration_structure_build_sizes( + &self, + desc: &GetAccelerationStructureBuildSizesDescriptor, + ) -> AccelerationStructureBuildSizes; + unsafe fn get_acceleration_structure_device_address( + &self, + acceleration_structure: &A::AccelerationStructure, + ) -> wgt::BufferAddress; + unsafe fn destroy_acceleration_structure( + &self, + acceleration_structure: A::AccelerationStructure, + ); } pub trait Queue: WasmNotSendSync { @@ -618,6 +632,26 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { unsafe fn dispatch(&mut self, count: [u32; 3]); unsafe fn dispatch_indirect(&mut self, buffer: &A::Buffer, offset: wgt::BufferAddress); + + /// To get the required sizes for the buffer allocations use `get_acceleration_structure_build_sizes` per descriptor + /// All buffers must be synchronized externally + /// All buffer regions, which are written to may only be passed once per function call, + /// with the exception of updates in the same descriptor. + /// Consequences of this limitation: + /// - scratch buffers need to be unique + /// - a tlas can't be build in the same call with a blas it contains + unsafe fn build_acceleration_structures<'a, T>( + &mut self, + descriptor_count: u32, + descriptors: T, + ) where + A: 'a, + T: IntoIterator>; + + unsafe fn place_acceleration_structure_barrier( + &mut self, + barrier: AccelerationStructureBarrier, + ); } bitflags!( @@ -778,12 +812,15 @@ bitflags::bitflags! { const INDIRECT = 1 << 9; /// A buffer used to store query results. const QUERY_RESOLVE = 1 << 10; + const ACCELERATION_STRUCTURE_SCRATCH = 1 << 11; + const BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 12; + const TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 13; /// The combination of states that a buffer may be in _at the same time_. const INCLUSIVE = Self::MAP_READ.bits() | Self::COPY_SRC.bits() | Self::INDEX.bits() | Self::VERTEX.bits() | Self::UNIFORM.bits() | - Self::STORAGE_READ.bits() | Self::INDIRECT.bits(); + Self::STORAGE_READ.bits() | Self::INDIRECT.bits() | Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits() | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits(); /// The combination of states that a buffer must exclusively be in. - const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits(); + const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits() | Self::ACCELERATION_STRUCTURE_SCRATCH.bits(); /// The combination of all usages that the are guaranteed to be be ordered by the hardware. /// If a usage is ordered, then if the buffer state doesn't change between draw calls, there /// are no barriers needed for synchronization. @@ -1091,6 +1128,7 @@ pub struct BindGroupDescriptor<'a, A: Api> { pub samplers: &'a [&'a A::Sampler], pub textures: &'a [TextureBinding<'a, A>], pub entries: &'a [BindGroupEntry], + pub acceleration_structures: &'a [&'a A::AccelerationStructure], } #[derive(Clone, Debug)] @@ -1422,3 +1460,134 @@ fn test_default_limits() { let limits = wgt::Limits::default(); assert!(limits.max_bind_groups <= MAX_BIND_GROUPS as u32); } + +#[derive(Clone, Debug)] +pub struct AccelerationStructureDescriptor<'a> { + pub label: Label<'a>, + pub size: wgt::BufferAddress, + pub format: AccelerationStructureFormat, +} + +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum AccelerationStructureFormat { + TopLevel, + BottomLevel, +} + +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum AccelerationStructureBuildMode { + Build, + Update, +} + +/// Information of the required size for a corresponding entries struct (+ flags) +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +pub struct AccelerationStructureBuildSizes { + pub acceleration_structure_size: wgt::BufferAddress, + pub update_scratch_size: wgt::BufferAddress, + pub build_scratch_size: wgt::BufferAddress, +} + +/// Updates use source_acceleration_structure if present, else the update will be performed in place. +/// For updates, only the data is allowed to change (not the meta data or sizes). +#[derive(Clone, Debug)] +pub struct BuildAccelerationStructureDescriptor<'a, A: Api> { + pub entries: &'a AccelerationStructureEntries<'a, A>, + pub mode: AccelerationStructureBuildMode, + pub flags: AccelerationStructureBuildFlags, + pub source_acceleration_structure: Option<&'a A::AccelerationStructure>, + pub destination_acceleration_structure: &'a A::AccelerationStructure, + pub scratch_buffer: &'a A::Buffer, + pub scratch_buffer_offset: wgt::BufferAddress, +} + +/// - All buffers, buffer addresses and offsets will be ignored. +/// - The build mode will be ignored. +/// - Reducing the amount of Instances, Triangle groups or AABB groups (or the number of Triangles/AABBs in corresponding groups), +/// may result in reduced size requirements. +/// - Any other change may result in a bigger or smaller size requirement. +#[derive(Clone, Debug)] +pub struct GetAccelerationStructureBuildSizesDescriptor<'a, A: Api> { + pub entries: &'a AccelerationStructureEntries<'a, A>, + pub flags: AccelerationStructureBuildFlags, +} + +/// Entries for a single descriptor +/// * `Instances` - Multiple instances for a top level acceleration structure +/// * `Triangles` - Multiple triangle meshes for a bottom level acceleration structure +/// * `AABBs` - List of list of axis aligned bounding boxes for a bottom level acceleration structure +#[derive(Debug)] +pub enum AccelerationStructureEntries<'a, A: Api> { + Instances(AccelerationStructureInstances<'a, A>), + Triangles(Vec>), + AABBs(Vec>), +} + +/// * `first_vertex` - offset in the vertex buffer (as number of vertices) +/// * `indices` - optional index buffer with attributes +/// * `transform` - optional transform +#[derive(Clone, Debug)] +pub struct AccelerationStructureTriangles<'a, A: Api> { + pub vertex_buffer: Option<&'a A::Buffer>, + pub vertex_format: wgt::VertexFormat, + pub first_vertex: u32, + pub vertex_count: u32, + pub vertex_stride: wgt::BufferAddress, + pub indices: Option>, + pub transform: Option>, + pub flags: AccelerationStructureGeometryFlags, +} + +/// * `offset` - offset in bytes +#[derive(Clone, Debug)] +pub struct AccelerationStructureAABBs<'a, A: Api> { + pub buffer: Option<&'a A::Buffer>, + pub offset: u32, + pub count: u32, + pub stride: wgt::BufferAddress, + pub flags: AccelerationStructureGeometryFlags, +} + +/// * `offset` - offset in bytes +#[derive(Clone, Debug)] +pub struct AccelerationStructureInstances<'a, A: Api> { + pub buffer: Option<&'a A::Buffer>, + pub offset: u32, + pub count: u32, +} + +/// * `offset` - offset in bytes +#[derive(Clone, Debug)] +pub struct AccelerationStructureTriangleIndices<'a, A: Api> { + pub format: wgt::IndexFormat, + pub buffer: Option<&'a A::Buffer>, + pub offset: u32, + pub count: u32, +} + +/// * `offset` - offset in bytes +#[derive(Clone, Debug)] +pub struct AccelerationStructureTriangleTransform<'a, A: Api> { + pub buffer: &'a A::Buffer, + pub offset: u32, +} + +pub use wgt::AccelerationStructureFlags as AccelerationStructureBuildFlags; +pub use wgt::AccelerationStructureGeometryFlags; + +bitflags::bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + pub struct AccelerationStructureUses: u8 { + // For blas used as input for tlas + const BUILD_INPUT = 1 << 0; + // Target for acceleration structure build + const BUILD_OUTPUT = 1 << 1; + // Tlas used in a shader + const SHADER_INPUT = 1 << 2; + } +} + +#[derive(Debug, Clone)] +pub struct AccelerationStructureBarrier { + pub usage: Range, +} diff --git a/third_party/rust/wgpu-hal/src/metal/command.rs b/third_party/rust/wgpu-hal/src/metal/command.rs index b06f46e8a95ee..6f1a0d9c2f243 100644 --- a/third_party/rust/wgpu-hal/src/metal/command.rs +++ b/third_party/rust/wgpu-hal/src/metal/command.rs @@ -1216,6 +1216,24 @@ impl crate::CommandEncoder for super::CommandEncoder { let encoder = self.state.compute.as_ref().unwrap(); encoder.dispatch_thread_groups_indirect(&buffer.raw, offset, self.state.raw_wg_size); } + + unsafe fn build_acceleration_structures<'a, T>( + &mut self, + _descriptor_count: u32, + _descriptors: T, + ) where + super::Api: 'a, + T: IntoIterator>, + { + unimplemented!() + } + + unsafe fn place_acceleration_structure_barrier( + &mut self, + _barriers: crate::AccelerationStructureBarrier, + ) { + unimplemented!() + } } impl Drop for super::CommandEncoder { diff --git a/third_party/rust/wgpu-hal/src/metal/device.rs b/third_party/rust/wgpu-hal/src/metal/device.rs index 475332b76d5e9..6a387dd57b4e6 100644 --- a/third_party/rust/wgpu-hal/src/metal/device.rs +++ b/third_party/rust/wgpu-hal/src/metal/device.rs @@ -637,6 +637,7 @@ impl crate::Device for super::Device { wgt::StorageTextureAccess::ReadWrite => true, }; } + wgt::BindingType::AccelerationStructure => unimplemented!(), } let br = naga::ResourceBinding { @@ -768,6 +769,7 @@ impl crate::Device for super::Device { ); counter.textures += size; } + wgt::BindingType::AccelerationStructure => unimplemented!(), } } } @@ -1218,4 +1220,32 @@ impl crate::Device for super::Device { } shared_capture_manager.stop_capture(); } + + unsafe fn get_acceleration_structure_build_sizes( + &self, + _desc: &crate::GetAccelerationStructureBuildSizesDescriptor, + ) -> crate::AccelerationStructureBuildSizes { + unimplemented!() + } + + unsafe fn get_acceleration_structure_device_address( + &self, + _acceleration_structure: &super::AccelerationStructure, + ) -> wgt::BufferAddress { + unimplemented!() + } + + unsafe fn create_acceleration_structure( + &self, + _desc: &crate::AccelerationStructureDescriptor, + ) -> Result { + unimplemented!() + } + + unsafe fn destroy_acceleration_structure( + &self, + _acceleration_structure: super::AccelerationStructure, + ) { + unimplemented!() + } } diff --git a/third_party/rust/wgpu-hal/src/metal/mod.rs b/third_party/rust/wgpu-hal/src/metal/mod.rs index 8890092d31b2b..39589115e73bc 100644 --- a/third_party/rust/wgpu-hal/src/metal/mod.rs +++ b/third_party/rust/wgpu-hal/src/metal/mod.rs @@ -66,6 +66,8 @@ impl crate::Api for Api { type ShaderModule = ShaderModule; type RenderPipeline = RenderPipeline; type ComputePipeline = ComputePipeline; + + type AccelerationStructure = AccelerationStructure; } pub struct Instance { @@ -844,3 +846,6 @@ pub struct CommandBuffer { unsafe impl Send for CommandBuffer {} unsafe impl Sync for CommandBuffer {} + +#[derive(Debug)] +pub struct AccelerationStructure; diff --git a/third_party/rust/wgpu-hal/src/vulkan/adapter.rs b/third_party/rust/wgpu-hal/src/vulkan/adapter.rs index dc67e85a5ea30..a9eaf8b609bab 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/adapter.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/adapter.rs @@ -35,6 +35,9 @@ pub struct PhysicalDeviceFeatures { vk::PhysicalDeviceShaderFloat16Int8Features, vk::PhysicalDevice16BitStorageFeatures, )>, + acceleration_structure: Option, + buffer_device_address: Option, + ray_query: Option, zero_initialize_workgroup_memory: Option, } @@ -75,6 +78,15 @@ impl PhysicalDeviceFeatures { if let Some(ref mut feature) = self.zero_initialize_workgroup_memory { info = info.push_next(feature); } + if let Some(ref mut feature) = self.acceleration_structure { + info = info.push_next(feature); + } + if let Some(ref mut feature) = self.buffer_device_address { + info = info.push_next(feature); + } + if let Some(ref mut feature) = self.ray_query { + info = info.push_next(feature); + } info } @@ -283,6 +295,37 @@ impl PhysicalDeviceFeatures { } else { None }, + acceleration_structure: if enabled_extensions + .contains(&vk::KhrAccelerationStructureFn::name()) + { + Some( + vk::PhysicalDeviceAccelerationStructureFeaturesKHR::builder() + .acceleration_structure(true) + .build(), + ) + } else { + None + }, + buffer_device_address: if enabled_extensions + .contains(&vk::KhrBufferDeviceAddressFn::name()) + { + Some( + vk::PhysicalDeviceBufferDeviceAddressFeaturesKHR::builder() + .buffer_device_address(true) + .build(), + ) + } else { + None + }, + ray_query: if enabled_extensions.contains(&vk::KhrRayQueryFn::name()) { + Some( + vk::PhysicalDeviceRayQueryFeaturesKHR::builder() + .ray_query(true) + .build(), + ) + } else { + None + }, zero_initialize_workgroup_memory: if device_api_version >= vk::API_VERSION_1_3 || enabled_extensions.contains(&vk::KhrZeroInitializeWorkgroupMemoryFn::name()) { @@ -520,6 +563,18 @@ impl PhysicalDeviceFeatures { features.set(F::DEPTH32FLOAT_STENCIL8, texture_d32_s8); + features.set( + F::RAY_TRACING_ACCELERATION_STRUCTURE, + caps.supports_extension(vk::KhrDeferredHostOperationsFn::name()) + && caps.supports_extension(vk::KhrAccelerationStructureFn::name()) + && caps.supports_extension(vk::KhrBufferDeviceAddressFn::name()), + ); + + features.set( + F::RAY_QUERY, + caps.supports_extension(vk::KhrRayQueryFn::name()), + ); + let rg11b10ufloat_renderable = supports_format( instance, phd, @@ -570,12 +625,13 @@ impl PhysicalDeviceFeatures { } /// Information gathered about a physical device capabilities. -#[derive(Default)] +#[derive(Default, Debug)] pub struct PhysicalDeviceCapabilities { supported_extensions: Vec, properties: vk::PhysicalDeviceProperties, maintenance_3: Option, descriptor_indexing: Option, + acceleration_structure: Option, driver: Option, /// The device API version. /// @@ -706,6 +762,18 @@ impl PhysicalDeviceCapabilities { extensions.push(vk::KhrDrawIndirectCountFn::name()); } + // Require `VK_KHR_deferred_host_operations`, `VK_KHR_acceleration_structure` and `VK_KHR_buffer_device_address` if the feature `RAY_TRACING` was requested + if requested_features.contains(wgt::Features::RAY_TRACING_ACCELERATION_STRUCTURE) { + extensions.push(vk::KhrDeferredHostOperationsFn::name()); + extensions.push(vk::KhrAccelerationStructureFn::name()); + extensions.push(vk::KhrBufferDeviceAddressFn::name()); + } + + // Require `VK_KHR_ray_query` if the associated feature was requested + if requested_features.contains(wgt::Features::RAY_QUERY) { + extensions.push(vk::KhrRayQueryFn::name()); + } + // Require `VK_EXT_conservative_rasterization` if the associated feature was requested if requested_features.contains(wgt::Features::CONSERVATIVE_RASTERIZATION) { extensions.push(vk::ExtConservativeRasterizationFn::name()); @@ -821,6 +889,9 @@ impl super::InstanceShared { >= vk::API_VERSION_1_2 || capabilities.supports_extension(vk::KhrDriverPropertiesFn::name()); + let supports_acceleration_structure = + capabilities.supports_extension(vk::KhrAccelerationStructureFn::name()); + let mut builder = vk::PhysicalDeviceProperties2KHR::builder(); if supports_maintenance3 { capabilities.maintenance_3 = @@ -835,6 +906,13 @@ impl super::InstanceShared { builder = builder.push_next(next); } + if supports_acceleration_structure { + let next = capabilities + .acceleration_structure + .insert(vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default()); + builder = builder.push_next(next); + } + if supports_driver_properties { let next = capabilities .driver @@ -917,6 +995,12 @@ impl super::InstanceShared { builder = builder.push_next(&mut next.0); builder = builder.push_next(&mut next.1); } + if capabilities.supports_extension(vk::KhrAccelerationStructureFn::name()) { + let next = features + .acceleration_structure + .insert(vk::PhysicalDeviceAccelerationStructureFeaturesKHR::default()); + builder = builder.push_next(next); + } // `VK_KHR_zero_initialize_workgroup_memory` is promoted to 1.3 if capabilities.device_api_version >= vk::API_VERSION_1_3 @@ -993,13 +1077,6 @@ impl super::Instance { phd_features.to_wgpu(&info, &self.shared.raw, phd, &phd_capabilities); let mut workarounds = super::Workarounds::empty(); { - // see https://github.com/gfx-rs/gfx/issues/1930 - let _is_windows_intel_dual_src_bug = cfg!(windows) - && phd_capabilities.properties.vendor_id == db::intel::VENDOR - && (phd_capabilities.properties.device_id & db::intel::DEVICE_KABY_LAKE_MASK - == db::intel::DEVICE_KABY_LAKE_MASK - || phd_capabilities.properties.device_id & db::intel::DEVICE_SKY_LAKE_MASK - == db::intel::DEVICE_SKY_LAKE_MASK); // TODO: only enable for particular devices workarounds |= super::Workarounds::SEPARATE_ENTRY_POINTS; workarounds.set( @@ -1259,6 +1336,22 @@ impl super::Adapter { } else { None }; + let ray_tracing_fns = if enabled_extensions.contains(&khr::AccelerationStructure::name()) + && enabled_extensions.contains(&khr::BufferDeviceAddress::name()) + { + Some(super::RayTracingDeviceExtensionFunctions { + acceleration_structure: khr::AccelerationStructure::new( + &self.instance.raw, + &raw_device, + ), + buffer_device_address: khr::BufferDeviceAddress::new( + &self.instance.raw, + &raw_device, + ), + }) + } else { + None + }; let naga_options = { use naga::back::spv; @@ -1307,6 +1400,10 @@ impl super::Adapter { capabilities.push(spv::Capability::StorageImageWriteWithoutFormat); } + if features.contains(wgt::Features::RAY_QUERY) { + capabilities.push(spv::Capability::RayQueryKHR); + } + let mut flags = spv::WriterFlags::empty(); flags.set( spv::WriterFlags::DEBUG, @@ -1374,6 +1471,7 @@ impl super::Adapter { extension_fns: super::DeviceExtensionFunctions { draw_indirect_count: indirect_count_fn, timeline_semaphore: timeline_semaphore_fn, + ray_tracing: ray_tracing_fns, }, vendor_id: self.phd_capabilities.properties.vendor_id, timestamp_period: self.phd_capabilities.properties.limits.timestamp_period, @@ -1428,7 +1526,8 @@ impl super::Adapter { size: memory_heap.size, }) .collect(), - buffer_device_address: false, + buffer_device_address: enabled_extensions + .contains(&khr::BufferDeviceAddress::name()), }; gpu_alloc::GpuAllocator::new(config, properties) }; diff --git a/third_party/rust/wgpu-hal/src/vulkan/command.rs b/third_party/rust/wgpu-hal/src/vulkan/command.rs index c31da9e2c867a..239133bb54852 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/command.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/command.rs @@ -414,6 +414,243 @@ impl crate::CommandEncoder for super::CommandEncoder { }; } + unsafe fn build_acceleration_structures<'a, T>(&mut self, descriptor_count: u32, descriptors: T) + where + super::Api: 'a, + T: IntoIterator>, + { + const CAPACITY_OUTER: usize = 8; + const CAPACITY_INNER: usize = 1; + let descriptor_count = descriptor_count as usize; + + let ray_tracing_functions = self + .device + .extension_fns + .ray_tracing + .as_ref() + .expect("Feature `RAY_TRACING` not enabled"); + + let get_device_address = |buffer: Option<&super::Buffer>| unsafe { + match buffer { + Some(buffer) => ray_tracing_functions + .buffer_device_address + .get_buffer_device_address( + &vk::BufferDeviceAddressInfo::builder().buffer(buffer.raw), + ), + None => panic!("Buffers are required to build acceleration structures"), + } + }; + + // storage to all the data required for cmd_build_acceleration_structures + let mut ranges_storage = smallvec::SmallVec::< + [smallvec::SmallVec<[vk::AccelerationStructureBuildRangeInfoKHR; CAPACITY_INNER]>; + CAPACITY_OUTER], + >::with_capacity(descriptor_count); + let mut geometries_storage = smallvec::SmallVec::< + [smallvec::SmallVec<[vk::AccelerationStructureGeometryKHR; CAPACITY_INNER]>; + CAPACITY_OUTER], + >::with_capacity(descriptor_count); + + // pointers to all the data required for cmd_build_acceleration_structures + let mut geometry_infos = smallvec::SmallVec::< + [vk::AccelerationStructureBuildGeometryInfoKHR; CAPACITY_OUTER], + >::with_capacity(descriptor_count); + let mut ranges_ptrs = smallvec::SmallVec::< + [&[vk::AccelerationStructureBuildRangeInfoKHR]; CAPACITY_OUTER], + >::with_capacity(descriptor_count); + + for desc in descriptors { + let (geometries, ranges) = match *desc.entries { + crate::AccelerationStructureEntries::Instances(ref instances) => { + let instance_data = vk::AccelerationStructureGeometryInstancesDataKHR::builder( + ) + .data(vk::DeviceOrHostAddressConstKHR { + device_address: get_device_address(instances.buffer), + }); + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::INSTANCES) + .geometry(vk::AccelerationStructureGeometryDataKHR { + instances: *instance_data, + }); + + let range = vk::AccelerationStructureBuildRangeInfoKHR::builder() + .primitive_count(instances.count) + .primitive_offset(instances.offset); + + (smallvec::smallvec![*geometry], smallvec::smallvec![*range]) + } + crate::AccelerationStructureEntries::Triangles(ref in_geometries) => { + let mut ranges = smallvec::SmallVec::< + [vk::AccelerationStructureBuildRangeInfoKHR; CAPACITY_INNER], + >::with_capacity(in_geometries.len()); + let mut geometries = smallvec::SmallVec::< + [vk::AccelerationStructureGeometryKHR; CAPACITY_INNER], + >::with_capacity(in_geometries.len()); + for triangles in in_geometries { + let mut triangle_data = + vk::AccelerationStructureGeometryTrianglesDataKHR::builder() + .vertex_data(vk::DeviceOrHostAddressConstKHR { + device_address: get_device_address(triangles.vertex_buffer), + }) + .vertex_format(conv::map_vertex_format(triangles.vertex_format)) + .max_vertex(triangles.vertex_count) + .vertex_stride(triangles.vertex_stride); + + let mut range = vk::AccelerationStructureBuildRangeInfoKHR::builder(); + + if let Some(ref indices) = triangles.indices { + triangle_data = triangle_data + .index_data(vk::DeviceOrHostAddressConstKHR { + device_address: get_device_address(indices.buffer), + }) + .index_type(conv::map_index_format(indices.format)); + + range = range + .primitive_count(indices.count / 3) + .primitive_offset(indices.offset) + .first_vertex(triangles.first_vertex); + } else { + range = range + .primitive_count(triangles.vertex_count) + .first_vertex(triangles.first_vertex); + } + + if let Some(ref transform) = triangles.transform { + let transform_device_address = unsafe { + ray_tracing_functions + .buffer_device_address + .get_buffer_device_address( + &vk::BufferDeviceAddressInfo::builder() + .buffer(transform.buffer.raw), + ) + }; + triangle_data = + triangle_data.transform_data(vk::DeviceOrHostAddressConstKHR { + device_address: transform_device_address, + }); + + range = range.transform_offset(transform.offset); + } + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::TRIANGLES) + .geometry(vk::AccelerationStructureGeometryDataKHR { + triangles: *triangle_data, + }) + .flags(conv::map_acceleration_structure_geomety_flags( + triangles.flags, + )); + + geometries.push(*geometry); + ranges.push(*range); + } + (geometries, ranges) + } + crate::AccelerationStructureEntries::AABBs(ref in_geometries) => { + let mut ranges = smallvec::SmallVec::< + [vk::AccelerationStructureBuildRangeInfoKHR; CAPACITY_INNER], + >::with_capacity(in_geometries.len()); + let mut geometries = smallvec::SmallVec::< + [vk::AccelerationStructureGeometryKHR; CAPACITY_INNER], + >::with_capacity(in_geometries.len()); + for aabb in in_geometries { + let aabbs_data = vk::AccelerationStructureGeometryAabbsDataKHR::builder() + .data(vk::DeviceOrHostAddressConstKHR { + device_address: get_device_address(aabb.buffer), + }) + .stride(aabb.stride); + + let range = vk::AccelerationStructureBuildRangeInfoKHR::builder() + .primitive_count(aabb.count) + .primitive_offset(aabb.offset); + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::AABBS) + .geometry(vk::AccelerationStructureGeometryDataKHR { + aabbs: *aabbs_data, + }) + .flags(conv::map_acceleration_structure_geomety_flags(aabb.flags)); + + geometries.push(*geometry); + ranges.push(*range); + } + (geometries, ranges) + } + }; + + ranges_storage.push(ranges); + geometries_storage.push(geometries); + + let scratch_device_address = unsafe { + ray_tracing_functions + .buffer_device_address + .get_buffer_device_address( + &vk::BufferDeviceAddressInfo::builder().buffer(desc.scratch_buffer.raw), + ) + }; + let ty = match *desc.entries { + crate::AccelerationStructureEntries::Instances(_) => { + vk::AccelerationStructureTypeKHR::TOP_LEVEL + } + _ => vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL, + }; + let mut geometry_info = vk::AccelerationStructureBuildGeometryInfoKHR::builder() + .ty(ty) + .mode(conv::map_acceleration_structure_build_mode(desc.mode)) + .flags(conv::map_acceleration_structure_flags(desc.flags)) + .dst_acceleration_structure(desc.destination_acceleration_structure.raw) + .scratch_data(vk::DeviceOrHostAddressKHR { + device_address: scratch_device_address + desc.scratch_buffer_offset, + }); + + if desc.mode == crate::AccelerationStructureBuildMode::Update { + geometry_info.src_acceleration_structure = desc + .source_acceleration_structure + .unwrap_or(desc.destination_acceleration_structure) + .raw; + } + + geometry_infos.push(*geometry_info); + } + + for (i, geometry_info) in geometry_infos.iter_mut().enumerate() { + geometry_info.geometry_count = geometries_storage[i].len() as u32; + geometry_info.p_geometries = geometries_storage[i].as_ptr(); + ranges_ptrs.push(&ranges_storage[i]); + } + + unsafe { + ray_tracing_functions + .acceleration_structure + .cmd_build_acceleration_structures(self.active, &geometry_infos, &ranges_ptrs); + } + } + + unsafe fn place_acceleration_structure_barrier( + &mut self, + barrier: crate::AccelerationStructureBarrier, + ) { + let (src_stage, src_access) = + conv::map_acceleration_structure_usage_to_barrier(barrier.usage.start); + let (dst_stage, dst_access) = + conv::map_acceleration_structure_usage_to_barrier(barrier.usage.end); + + unsafe { + self.device.raw.cmd_pipeline_barrier( + self.active, + src_stage | vk::PipelineStageFlags::TOP_OF_PIPE, + dst_stage | vk::PipelineStageFlags::BOTTOM_OF_PIPE, + vk::DependencyFlags::empty(), + &[vk::MemoryBarrier::builder() + .src_access_mask(src_access) + .dst_access_mask(dst_access) + .build()], + &[], + &[], + ) + }; + } // render unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor) { diff --git a/third_party/rust/wgpu-hal/src/vulkan/conv.rs b/third_party/rust/wgpu-hal/src/vulkan/conv.rs index 70dbb5714d848..826da91416428 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/conv.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/conv.rs @@ -517,6 +517,16 @@ pub fn map_buffer_usage(usage: crate::BufferUses) -> vk::BufferUsageFlags { if usage.contains(crate::BufferUses::INDIRECT) { flags |= vk::BufferUsageFlags::INDIRECT_BUFFER; } + if usage.contains(crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH) { + flags |= vk::BufferUsageFlags::STORAGE_BUFFER | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS; + } + if usage.intersects( + crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + | crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + ) { + flags |= vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR + | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS; + } flags } @@ -569,6 +579,15 @@ pub fn map_buffer_usage_to_barrier( stages |= vk::PipelineStageFlags::DRAW_INDIRECT; access |= vk::AccessFlags::INDIRECT_COMMAND_READ; } + if usage.intersects( + crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + | crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT + | crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + ) { + stages |= vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR; + access |= vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR + | vk::AccessFlags::ACCELERATION_STRUCTURE_WRITE_KHR; + } (stages, access) } @@ -720,6 +739,7 @@ pub fn map_binding_type(ty: wgt::BindingType) -> vk::DescriptorType { wgt::BindingType::Sampler { .. } => vk::DescriptorType::SAMPLER, wgt::BindingType::Texture { .. } => vk::DescriptorType::SAMPLED_IMAGE, wgt::BindingType::StorageTexture { .. } => vk::DescriptorType::STORAGE_IMAGE, + wgt::BindingType::AccelerationStructure => vk::DescriptorType::ACCELERATION_STRUCTURE_KHR, } } @@ -851,3 +871,95 @@ pub fn map_pipeline_statistics( } flags } + +pub fn map_acceleration_structure_format( + format: crate::AccelerationStructureFormat, +) -> vk::AccelerationStructureTypeKHR { + match format { + crate::AccelerationStructureFormat::TopLevel => vk::AccelerationStructureTypeKHR::TOP_LEVEL, + crate::AccelerationStructureFormat::BottomLevel => { + vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL + } + } +} + +pub fn map_acceleration_structure_build_mode( + format: crate::AccelerationStructureBuildMode, +) -> vk::BuildAccelerationStructureModeKHR { + match format { + crate::AccelerationStructureBuildMode::Build => { + vk::BuildAccelerationStructureModeKHR::BUILD + } + crate::AccelerationStructureBuildMode::Update => { + vk::BuildAccelerationStructureModeKHR::UPDATE + } + } +} + +pub fn map_acceleration_structure_flags( + flags: crate::AccelerationStructureBuildFlags, +) -> vk::BuildAccelerationStructureFlagsKHR { + let mut vk_flags = vk::BuildAccelerationStructureFlagsKHR::empty(); + + if flags.contains(crate::AccelerationStructureBuildFlags::PREFER_FAST_TRACE) { + vk_flags |= vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE; + } + + if flags.contains(crate::AccelerationStructureBuildFlags::PREFER_FAST_BUILD) { + vk_flags |= vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_BUILD; + } + + if flags.contains(crate::AccelerationStructureBuildFlags::ALLOW_UPDATE) { + vk_flags |= vk::BuildAccelerationStructureFlagsKHR::ALLOW_UPDATE; + } + + if flags.contains(crate::AccelerationStructureBuildFlags::LOW_MEMORY) { + vk_flags |= vk::BuildAccelerationStructureFlagsKHR::LOW_MEMORY; + } + + if flags.contains(crate::AccelerationStructureBuildFlags::ALLOW_COMPACTION) { + vk_flags |= vk::BuildAccelerationStructureFlagsKHR::ALLOW_COMPACTION + } + + vk_flags +} + +pub fn map_acceleration_structure_geomety_flags( + flags: crate::AccelerationStructureGeometryFlags, +) -> vk::GeometryFlagsKHR { + let mut vk_flags = vk::GeometryFlagsKHR::empty(); + + if flags.contains(crate::AccelerationStructureGeometryFlags::OPAQUE) { + vk_flags |= vk::GeometryFlagsKHR::OPAQUE; + } + + if flags.contains(crate::AccelerationStructureGeometryFlags::NO_DUPLICATE_ANY_HIT_INVOCATION) { + vk_flags |= vk::GeometryFlagsKHR::NO_DUPLICATE_ANY_HIT_INVOCATION; + } + + vk_flags +} + +pub fn map_acceleration_structure_usage_to_barrier( + usage: crate::AccelerationStructureUses, +) -> (vk::PipelineStageFlags, vk::AccessFlags) { + let mut stages = vk::PipelineStageFlags::empty(); + let mut access = vk::AccessFlags::empty(); + + if usage.contains(crate::AccelerationStructureUses::BUILD_INPUT) { + stages |= vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR; + access |= vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR; + } + if usage.contains(crate::AccelerationStructureUses::BUILD_OUTPUT) { + stages |= vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR; + access |= vk::AccessFlags::ACCELERATION_STRUCTURE_WRITE_KHR; + } + if usage.contains(crate::AccelerationStructureUses::SHADER_INPUT) { + stages |= vk::PipelineStageFlags::VERTEX_SHADER + | vk::PipelineStageFlags::FRAGMENT_SHADER + | vk::PipelineStageFlags::COMPUTE_SHADER; + access |= vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR; + } + + (stages, access) +} diff --git a/third_party/rust/wgpu-hal/src/vulkan/device.rs b/third_party/rust/wgpu-hal/src/vulkan/device.rs index d9aba5028187d..0caf1aa1c2617 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/device.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/device.rs @@ -863,12 +863,21 @@ impl crate::Device for super::Device { desc.memory_flags.contains(crate::MemoryFlags::TRANSIENT), ); + let alignment_mask = if desc.usage.intersects( + crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT + | crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + ) { + 16 + } else { + req.alignment + } - 1; + let block = unsafe { self.mem_allocator.lock().alloc( &*self.shared, gpu_alloc::Request { size: req.size, - align_mask: req.alignment - 1, + align_mask: alignment_mask, usage: alloc_usage, memory_types: req.memory_type_bits & self.valid_ash_memory_types, }, @@ -980,7 +989,7 @@ impl crate::Device for super::Device { wgt_view_formats = desc.view_formats.clone(); wgt_view_formats.push(desc.format); - if self.shared.private_caps.image_format_list { + if self.shared.private_caps.image_format_list && !desc.format.is_multi_planar_format() { vk_view_formats = desc .view_formats .iter() @@ -1256,6 +1265,9 @@ impl crate::Device for super::Device { wgt::BindingType::StorageTexture { .. } => { desc_count.storage_image += count; } + wgt::BindingType::AccelerationStructure => { + desc_count.acceleration_structure += count; + } } } @@ -1430,6 +1442,10 @@ impl crate::Device for super::Device { let mut buffer_infos = Vec::with_capacity(desc.buffers.len()); let mut sampler_infos = Vec::with_capacity(desc.samplers.len()); let mut image_infos = Vec::with_capacity(desc.textures.len()); + let mut acceleration_structure_infos = + Vec::with_capacity(desc.acceleration_structures.len()); + let mut raw_acceleration_structures = + Vec::with_capacity(desc.acceleration_structures.len()); for entry in desc.entries { let (ty, size) = desc.layout.types[entry.binding as usize]; if size == 0 { @@ -1439,6 +1455,9 @@ impl crate::Device for super::Device { .dst_set(*set.raw()) .dst_binding(entry.binding) .descriptor_type(ty); + + let mut extra_descriptor_count = 0; + write = match ty { vk::DescriptorType::SAMPLER => { let index = sampler_infos.len(); @@ -1489,9 +1508,44 @@ impl crate::Device for super::Device { )); write.buffer_info(&buffer_infos[index..]) } + vk::DescriptorType::ACCELERATION_STRUCTURE_KHR => { + let index = acceleration_structure_infos.len(); + let start = entry.resource_index; + let end = start + entry.count; + + let raw_start = raw_acceleration_structures.len(); + + raw_acceleration_structures.extend( + desc.acceleration_structures[start as usize..end as usize] + .iter() + .map(|acceleration_structure| acceleration_structure.raw), + ); + + let acceleration_structure_info = + vk::WriteDescriptorSetAccelerationStructureKHR::builder() + .acceleration_structures(&raw_acceleration_structures[raw_start..]); + + // todo: Dereference the struct to get around lifetime issues. Safe as long as we never resize + // `raw_acceleration_structures`. + let acceleration_structure_info: vk::WriteDescriptorSetAccelerationStructureKHR = *acceleration_structure_info; + + assert!( + index < desc.acceleration_structures.len(), + "Encountered more acceleration structures then expected" + ); + acceleration_structure_infos.push(acceleration_structure_info); + + extra_descriptor_count += 1; + + write.push_next(&mut acceleration_structure_infos[index]) + } _ => unreachable!(), }; - writes.push(write.build()); + + let mut write = write.build(); + write.descriptor_count += extra_descriptor_count; + + writes.push(write); } unsafe { self.shared.raw.update_descriptor_sets(&writes, &[]) }; @@ -2024,6 +2078,231 @@ impl crate::Device for super::Device { } } } + + unsafe fn get_acceleration_structure_build_sizes<'a>( + &self, + desc: &crate::GetAccelerationStructureBuildSizesDescriptor<'a, super::Api>, + ) -> crate::AccelerationStructureBuildSizes { + const CAPACITY: usize = 8; + + let ray_tracing_functions = self + .shared + .extension_fns + .ray_tracing + .as_ref() + .expect("Feature `RAY_TRACING` not enabled"); + + let (geometries, primitive_counts) = match *desc.entries { + crate::AccelerationStructureEntries::Instances(ref instances) => { + let instance_data = vk::AccelerationStructureGeometryInstancesDataKHR::default(); + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::INSTANCES) + .geometry(vk::AccelerationStructureGeometryDataKHR { + instances: instance_data, + }); + + ( + smallvec::smallvec![*geometry], + smallvec::smallvec![instances.count], + ) + } + crate::AccelerationStructureEntries::Triangles(ref in_geometries) => { + let mut primitive_counts = + smallvec::SmallVec::<[u32; CAPACITY]>::with_capacity(in_geometries.len()); + let mut geometries = smallvec::SmallVec::< + [vk::AccelerationStructureGeometryKHR; CAPACITY], + >::with_capacity(in_geometries.len()); + + for triangles in in_geometries { + let mut triangle_data = + vk::AccelerationStructureGeometryTrianglesDataKHR::builder() + .vertex_format(conv::map_vertex_format(triangles.vertex_format)) + .max_vertex(triangles.vertex_count) + .vertex_stride(triangles.vertex_stride); + + let pritive_count = if let Some(ref indices) = triangles.indices { + triangle_data = + triangle_data.index_type(conv::map_index_format(indices.format)); + indices.count / 3 + } else { + triangles.vertex_count + }; + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::TRIANGLES) + .geometry(vk::AccelerationStructureGeometryDataKHR { + triangles: *triangle_data, + }) + .flags(conv::map_acceleration_structure_geomety_flags( + triangles.flags, + )); + + geometries.push(*geometry); + primitive_counts.push(pritive_count); + } + (geometries, primitive_counts) + } + crate::AccelerationStructureEntries::AABBs(ref in_geometries) => { + let mut primitive_counts = + smallvec::SmallVec::<[u32; CAPACITY]>::with_capacity(in_geometries.len()); + let mut geometries = smallvec::SmallVec::< + [vk::AccelerationStructureGeometryKHR; CAPACITY], + >::with_capacity(in_geometries.len()); + for aabb in in_geometries { + let aabbs_data = vk::AccelerationStructureGeometryAabbsDataKHR::builder() + .stride(aabb.stride); + + let geometry = vk::AccelerationStructureGeometryKHR::builder() + .geometry_type(vk::GeometryTypeKHR::AABBS) + .geometry(vk::AccelerationStructureGeometryDataKHR { aabbs: *aabbs_data }) + .flags(conv::map_acceleration_structure_geomety_flags(aabb.flags)); + + geometries.push(*geometry); + primitive_counts.push(aabb.count); + } + (geometries, primitive_counts) + } + }; + + let ty = match *desc.entries { + crate::AccelerationStructureEntries::Instances(_) => { + vk::AccelerationStructureTypeKHR::TOP_LEVEL + } + _ => vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL, + }; + + let geometry_info = vk::AccelerationStructureBuildGeometryInfoKHR::builder() + .ty(ty) + .flags(conv::map_acceleration_structure_flags(desc.flags)) + .geometries(&geometries); + + let raw = unsafe { + ray_tracing_functions + .acceleration_structure + .get_acceleration_structure_build_sizes( + vk::AccelerationStructureBuildTypeKHR::DEVICE, + &geometry_info, + &primitive_counts, + ) + }; + + crate::AccelerationStructureBuildSizes { + acceleration_structure_size: raw.acceleration_structure_size, + update_scratch_size: raw.update_scratch_size, + build_scratch_size: raw.build_scratch_size, + } + } + + unsafe fn get_acceleration_structure_device_address( + &self, + acceleration_structure: &super::AccelerationStructure, + ) -> wgt::BufferAddress { + let ray_tracing_functions = self + .shared + .extension_fns + .ray_tracing + .as_ref() + .expect("Feature `RAY_TRACING` not enabled"); + + unsafe { + ray_tracing_functions + .acceleration_structure + .get_acceleration_structure_device_address( + &vk::AccelerationStructureDeviceAddressInfoKHR::builder() + .acceleration_structure(acceleration_structure.raw), + ) + } + } + + unsafe fn create_acceleration_structure( + &self, + desc: &crate::AccelerationStructureDescriptor, + ) -> Result { + let ray_tracing_functions = self + .shared + .extension_fns + .ray_tracing + .as_ref() + .expect("Feature `RAY_TRACING` not enabled"); + + let vk_buffer_info = vk::BufferCreateInfo::builder() + .size(desc.size) + .usage(vk::BufferUsageFlags::ACCELERATION_STRUCTURE_STORAGE_KHR) + .sharing_mode(vk::SharingMode::EXCLUSIVE); + + unsafe { + let raw_buffer = self.shared.raw.create_buffer(&vk_buffer_info, None)?; + let req = self.shared.raw.get_buffer_memory_requirements(raw_buffer); + + let block = self.mem_allocator.lock().alloc( + &*self.shared, + gpu_alloc::Request { + size: req.size, + align_mask: req.alignment - 1, + usage: gpu_alloc::UsageFlags::FAST_DEVICE_ACCESS, + memory_types: req.memory_type_bits & self.valid_ash_memory_types, + }, + )?; + + self.shared + .raw + .bind_buffer_memory(raw_buffer, *block.memory(), block.offset())?; + + if let Some(label) = desc.label { + self.shared + .set_object_name(vk::ObjectType::BUFFER, raw_buffer, label); + } + + let vk_info = vk::AccelerationStructureCreateInfoKHR::builder() + .buffer(raw_buffer) + .offset(0) + .size(desc.size) + .ty(conv::map_acceleration_structure_format(desc.format)); + + let raw_acceleration_structure = ray_tracing_functions + .acceleration_structure + .create_acceleration_structure(&vk_info, None)?; + + if let Some(label) = desc.label { + self.shared.set_object_name( + vk::ObjectType::ACCELERATION_STRUCTURE_KHR, + raw_acceleration_structure, + label, + ); + } + + Ok(super::AccelerationStructure { + raw: raw_acceleration_structure, + buffer: raw_buffer, + block: Mutex::new(block), + }) + } + } + + unsafe fn destroy_acceleration_structure( + &self, + acceleration_structure: super::AccelerationStructure, + ) { + let ray_tracing_functions = self + .shared + .extension_fns + .ray_tracing + .as_ref() + .expect("Feature `RAY_TRACING` not enabled"); + + unsafe { + ray_tracing_functions + .acceleration_structure + .destroy_acceleration_structure(acceleration_structure.raw, None); + self.shared + .raw + .destroy_buffer(acceleration_structure.buffer, None); + self.mem_allocator + .lock() + .dealloc(&*self.shared, acceleration_structure.block.into_inner()); + } + } } impl From for crate::DeviceError { diff --git a/third_party/rust/wgpu-hal/src/vulkan/mod.rs b/third_party/rust/wgpu-hal/src/vulkan/mod.rs index 843e4ef36fd15..45deda5d5b340 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/mod.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/mod.rs @@ -72,6 +72,7 @@ impl crate::Api for Api { type Sampler = Sampler; type QuerySet = QuerySet; type Fence = Fence; + type AccelerationStructure = AccelerationStructure; type BindGroupLayout = BindGroupLayout; type BindGroup = BindGroup; @@ -193,6 +194,12 @@ enum ExtensionFn { struct DeviceExtensionFunctions { draw_indirect_count: Option, timeline_semaphore: Option>, + ray_tracing: Option, +} + +struct RayTracingDeviceExtensionFunctions { + acceleration_structure: khr::AccelerationStructure, + buffer_device_address: khr::BufferDeviceAddress, } /// Set of internal capabilities, which don't show up in the exposed @@ -358,6 +365,13 @@ pub struct Buffer { block: Option>>, } +#[derive(Debug)] +pub struct AccelerationStructure { + raw: vk::AccelerationStructureKHR, + buffer: vk::Buffer, + block: Mutex>, +} + #[derive(Debug)] pub struct Texture { raw: vk::Image, diff --git a/third_party/rust/wgpu-types/.cargo-checksum.json b/third_party/rust/wgpu-types/.cargo-checksum.json index cb5969179c49d..b27aa2142db6f 100644 --- a/third_party/rust/wgpu-types/.cargo-checksum.json +++ b/third_party/rust/wgpu-types/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"18549fb7d7de2ea2481f30292dca63889856a33bd1b3698e16cee6631ab65df4","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","src/assertions.rs":"3fe98027aa73970c8ab7874a3e13dbfd6faa87df2081beb5c83aeec4c60f372f","src/lib.rs":"61f4f46533468f82e3d22e42d6e8b3d8b68504ccd4f9b4b9ea67b0664c42a34e","src/math.rs":"4d03039736dd6926feb139bc68734cb59df34ede310427bbf059e5c925e0af3b"},"package":null} \ No newline at end of file +{"files":{"Cargo.toml":"18549fb7d7de2ea2481f30292dca63889856a33bd1b3698e16cee6631ab65df4","LICENSE.APACHE":"a6cba85bc92e0cff7a450b1d873c0eaa2e9fc96bf472df0247a26bec77bf3ff9","LICENSE.MIT":"c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4","src/assertions.rs":"3fe98027aa73970c8ab7874a3e13dbfd6faa87df2081beb5c83aeec4c60f372f","src/lib.rs":"b115dcd6a14eac6fe5a2a13ede5c7becdfd741e25695c4cc2c12cfa1202887fd","src/math.rs":"4d03039736dd6926feb139bc68734cb59df34ede310427bbf059e5c925e0af3b"},"package":null} \ No newline at end of file diff --git a/third_party/rust/wgpu-types/src/lib.rs b/third_party/rust/wgpu-types/src/lib.rs index bdef49a60cdae..dd9f906746c33 100644 --- a/third_party/rust/wgpu-types/src/lib.rs +++ b/third_party/rust/wgpu-types/src/lib.rs @@ -102,12 +102,10 @@ pub enum Backend { Metal = 2, /// Direct3D-12 (Windows) Dx12 = 3, - /// Direct3D-11 (Windows) - Dx11 = 4, /// OpenGL ES-3 (Linux, Android) - Gl = 5, + Gl = 4, /// WebGPU in the browser - BrowserWebGpu = 6, + BrowserWebGpu = 5, } impl Backend { @@ -118,7 +116,6 @@ impl Backend { Backend::Vulkan => "vulkan", Backend::Metal => "metal", Backend::Dx12 => "dx12", - Backend::Dx11 => "dx11", Backend::Gl => "gl", Backend::BrowserWebGpu => "webgpu", } @@ -158,8 +155,6 @@ bitflags::bitflags! { const METAL = 1 << Backend::Metal as u32; /// Supported on Windows 10 const DX12 = 1 << Backend::Dx12 as u32; - /// Supported on Windows 7+ - const DX11 = 1 << Backend::Dx11 as u32; /// Supported when targeting the web through webassembly const BROWSER_WEBGPU = 1 << Backend::BrowserWebGpu as u32; /// All the apis that wgpu offers first tier of support for. @@ -172,8 +167,8 @@ bitflags::bitflags! { /// All the apis that wgpu offers second tier of support for. These may /// be unsupported/still experimental. /// - /// OpenGL + DX11 - const SECONDARY = Self::GL.bits() | Self::DX11.bits(); + /// OpenGL + const SECONDARY = Self::GL.bits(); } } @@ -665,7 +660,6 @@ bitflags::bitflags! { /// - DX12 /// - Vulkan /// - Metal - /// - DX11 (emulated with uniforms) /// - OpenGL (emulated with uniforms) /// /// This is a native only feature. @@ -681,7 +675,6 @@ bitflags::bitflags! { /// - DX12 /// - Vulkan /// - Metal - /// - DX11 /// - OpenGL /// /// This is a native only feature. @@ -693,7 +686,6 @@ bitflags::bitflags! { /// - DX12 /// - Vulkan /// - Metal (macOS 10.12+ only) - /// - DX11 /// - OpenGL /// /// This is a native only feature. @@ -772,7 +764,6 @@ bitflags::bitflags! { /// /// This is a native only feature. const VERTEX_ATTRIBUTE_64BIT = 1 << 53; - /// Allows vertex shaders to have outputs which are not consumed /// by the fragment shader. /// @@ -781,7 +772,6 @@ bitflags::bitflags! { /// - Metal /// - OpenGL const SHADER_UNUSED_VERTEX_OUTPUT = 1 << 54; - /// Allows for creation of textures of format [`TextureFormat::NV12`] /// /// Supported platforms: @@ -790,11 +780,25 @@ bitflags::bitflags! { /// /// This is a native only feature. const TEXTURE_FORMAT_NV12 = 1 << 55; + /// Allows for the creation of ray-tracing acceleration structures. + /// + /// Supported platforms: + /// - Vulkan + /// + /// This is a native-only feature. + const RAY_TRACING_ACCELERATION_STRUCTURE = 1 << 56; - // 55..59 available + // 57 available // Shader: + /// Allows for the creation of ray-tracing queries within shaders. + /// + /// Supported platforms: + /// - Vulkan + /// + /// This is a native-only feature. + const RAY_QUERY = 1 << 58; /// Enables 64-bit floating point types in SPIR-V shaders. /// /// Note: even when supported by GPU hardware, 64-bit floating point operations are @@ -820,7 +824,6 @@ bitflags::bitflags! { /// /// Supported platforms: /// - Vulkan - /// - DX11 (feature level 10+) /// - DX12 /// - Metal (some) /// - OpenGL (some) @@ -834,7 +837,6 @@ bitflags::bitflags! { /// /// This is a native only feature. const SHADER_EARLY_DEPTH_TEST = 1 << 62; - /// Allows two outputs from a shader to be used for blending. /// Note that dual-source blending doesn't support multiple render targets. /// @@ -1076,7 +1078,7 @@ pub struct Limits { /// - Vulkan: 128-256 bytes /// - DX12: 256 bytes /// - Metal: 4096 bytes - /// - DX11 & OpenGL don't natively support push constants, and are emulated with uniforms, + /// - OpenGL doesn't natively support push constants, and are emulated with uniforms, /// so this number is less useful but likely 256. pub max_push_constant_size: u32, @@ -1421,13 +1423,13 @@ bitflags::bitflags! { pub struct DownlevelFlags: u32 { /// The device supports compiling and using compute shaders. /// - /// DX11 on FL10 level hardware, WebGL2, and GLES3.0 devices do not support compute. + /// WebGL2, and GLES3.0 devices do not support compute. const COMPUTE_SHADERS = 1 << 0; /// Supports binding storage buffers and textures to fragment shaders. const FRAGMENT_WRITABLE_STORAGE = 1 << 1; /// Supports indirect drawing and dispatching. /// - /// DX11 on FL10 level hardware, WebGL2, GLES 3.0, and Metal on Apple1/Apple2 GPUs do not support indirect. + /// WebGL2, GLES 3.0, and Metal on Apple1/Apple2 GPUs do not support indirect. const INDIRECT_EXECUTION = 1 << 2; /// Supports non-zero `base_vertex` parameter to direct indexed draw calls. /// @@ -2890,6 +2892,11 @@ impl TextureFormat { } } + /// Returns `true` if the format is a multi-planar format + pub fn is_multi_planar_format(&self) -> bool { + matches!(*self, Self::NV12) + } + /// Returns `true` if the format has a color aspect pub fn has_color_aspect(&self) -> bool { !self.is_depth_stencil_format() @@ -4927,7 +4934,7 @@ pub enum PresentMode { /// /// No tearing will be observed. /// - /// Supported on DX11/12 on Windows 10, NVidia on Vulkan and Wayland on Vulkan. + /// Supported on DX12 on Windows 10, NVidia on Vulkan and Wayland on Vulkan. /// /// This is traditionally called "Fast Vsync" Mailbox = 5, @@ -6179,6 +6186,21 @@ pub enum BindingType { /// Dimension of the texture view that is going to be sampled. view_dimension: TextureViewDimension, }, + + /// A ray-tracing acceleration structure binding. + /// + /// Example WGSL syntax: + /// ```rust,ignore + /// @group(0) @binding(0) + /// var as: acceleration_structure; + /// ``` + /// + /// Example GLSL syntax: + /// ```cpp,ignore + /// layout(binding = 0) + /// uniform accelerationStructureEXT as; + /// ``` + AccelerationStructure, } impl BindingType { @@ -6829,6 +6851,36 @@ impl Default for InstanceDescriptor { } } +bitflags::bitflags!( + /// Flags for acceleration structures + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + pub struct AccelerationStructureFlags: u8 { + /// Allow for incremental updates (no change in size) + const ALLOW_UPDATE = 1 << 0; + /// Allow the acceleration structure to be compacted in a copy operation + const ALLOW_COMPACTION = 1 << 1; + /// Optimize for fast ray tracing performance + const PREFER_FAST_TRACE = 1 << 2; + /// Optimize for fast build time + const PREFER_FAST_BUILD = 1 << 3; + /// Optimize for low memory footprint (scratch and output) + const LOW_MEMORY = 1 << 4; + } +); +impl_bitflags!(AccelerationStructureFlags); + +bitflags::bitflags!( + /// Flags for acceleration structure geometries + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] + pub struct AccelerationStructureGeometryFlags: u8 { + /// Is OPAQUE + const OPAQUE = 1 << 0; + /// NO_DUPLICATE_ANY_HIT_INVOCATION + const NO_DUPLICATE_ANY_HIT_INVOCATION = 1 << 1; + } +); +impl_bitflags!(AccelerationStructureGeometryFlags); + pub use send_sync::*; #[doc(hidden)]