From 419503080d91723fc863bd134321ae161d122949 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 21 Nov 2023 12:35:24 +0000 Subject: [PATCH] Bug 1865585 - Update `wgpu` to revision 6e21f7a9291db4395192d6b510d906978ae2d251. r=webgpu-reviewers,supply-chain-reviewers,ErichDonGubler,teoxoy Note: This revision contains the arcanization work # Changelog * #4702 Add `WasmNotSendSync` By daxpedda in https://github.com/gfx-rs/wgpu/pull/4702 * #4707 Add more metal keywords By fornwall in https://github.com/gfx-rs/wgpu/pull/4707 * #4706 [naga] remove `span` and `validate` features By teoxoy in https://github.com/gfx-rs/wgpu/pull/4706 * #4709 [dx12] filter out haswell iGPUs By teoxoy in https://github.com/gfx-rs/wgpu/pull/4709 * #4712 Fix typo in pull request template. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4712 * #4598 Add more lints By daxpedda in https://github.com/gfx-rs/wgpu/pull/4598 * #4713 [naga wgsl-in] Include base when printing pointer and array types. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4713 * #4718 [vk] check that adapters are Vulkan compliant By teoxoy in https://github.com/gfx-rs/wgpu/pull/4718 * #4719 [naga] Let constant evaluation of `As` preserve `Splat` expressions. By jimblandy in https://github.com/gfx-rs/wgpu/pull/4719 * #4725 Corrects typo in examples FrameCounter By cantudo in https://github.com/gfx-rs/wgpu/pull/4725 * #3626 Arcanization of wgpu core resources By gents83 in https://github.com/gfx-rs/wgpu/pull/3626 Differential Revision: https://phabricator.services.mozilla.com/D194048 UltraBlame original commit: eb839abb42abde594497e419517260997fa1fc4d --- .cargo/config.in | 4 +- Cargo.lock | 20 +- gfx/wgpu_bindings/Cargo.toml | 14 +- gfx/wgpu_bindings/moz.yaml | 4 +- supply-chain/audits.toml | 256 + third_party/rust/naga/.cargo-checksum.json | 34 +- third_party/rust/naga/Cargo.toml | 30 - third_party/rust/naga/benches/criterion.rs | 74 - third_party/rust/naga/src/arena.rs | 400 +- .../rust/naga/src/back/msl/keywords.rs | 783 +- third_party/rust/naga/src/back/msl/writer.rs | 1 + third_party/rust/naga/src/block.rs | 196 - .../rust/naga/src/front/wgsl/to_wgsl.rs | 48 +- .../rust/naga/src/proc/constant_evaluator.rs | 163 +- third_party/rust/naga/src/proc/emitter.rs | 11 - third_party/rust/naga/src/span.rs | 261 - third_party/rust/naga/src/valid/analyzer.rs | 33 - third_party/rust/naga/src/valid/compose.rs | 22 - third_party/rust/naga/src/valid/expression.rs | 55 - third_party/rust/naga/src/valid/function.rs | 245 - third_party/rust/naga/src/valid/handles.rs | 110 - third_party/rust/naga/src/valid/interface.rs | 224 - third_party/rust/naga/src/valid/mod.rs | 185 - .../rust/wgpu-core/.cargo-checksum.json | 98 +- third_party/rust/wgpu-core/Cargo.toml | 6 - third_party/rust/wgpu-core/src/any_surface.rs | 1075 + .../rust/wgpu-core/src/binding_model.rs | 1042 +- .../rust/wgpu-core/src/command/bind.rs | 991 +- .../rust/wgpu-core/src/command/bundle.rs | 948 +- .../rust/wgpu-core/src/command/clear.rs | 449 +- .../rust/wgpu-core/src/command/compute.rs | 796 +- .../rust/wgpu-core/src/command/memory_init.rs | 425 +- third_party/rust/wgpu-core/src/command/mod.rs | 1207 +- .../rust/wgpu-core/src/command/query.rs | 348 +- .../rust/wgpu-core/src/command/render.rs | 1557 +- .../rust/wgpu-core/src/command/transfer.rs | 1185 +- third_party/rust/wgpu-core/src/conv.rs | 189 + .../rust/wgpu-core/src/device/any_device.rs | 833 + .../rust/wgpu-core/src/device/global.rs | 20118 ++++++---------- third_party/rust/wgpu-core/src/device/life.rs | 10333 ++++---- third_party/rust/wgpu-core/src/device/mod.rs | 107 +- .../rust/wgpu-core/src/device/queue.rs | 3459 +-- .../rust/wgpu-core/src/device/resource.rs | 4659 ++-- third_party/rust/wgpu-core/src/error.rs | 2 +- third_party/rust/wgpu-core/src/global.rs | 387 +- third_party/rust/wgpu-core/src/hal_api.rs | 232 +- third_party/rust/wgpu-core/src/hub.rs | 5761 +---- third_party/rust/wgpu-core/src/id.rs | 259 +- third_party/rust/wgpu-core/src/identity.rs | 1011 +- .../rust/wgpu-core/src/init_tracker/buffer.rs | 72 +- .../wgpu-core/src/init_tracker/texture.rs | 48 +- third_party/rust/wgpu-core/src/instance.rs | 2637 +- third_party/rust/wgpu-core/src/lib.rs | 1474 +- third_party/rust/wgpu-core/src/pipeline.rs | 735 +- third_party/rust/wgpu-core/src/present.rs | 1049 +- third_party/rust/wgpu-core/src/registry.rs | 1834 +- third_party/rust/wgpu-core/src/resource.rs | 7712 ++++-- third_party/rust/wgpu-core/src/storage.rs | 1451 +- .../rust/wgpu-core/src/track/buffer.rs | 1453 +- .../rust/wgpu-core/src/track/metadata.rs | 584 +- third_party/rust/wgpu-core/src/track/mod.rs | 426 +- .../rust/wgpu-core/src/track/stateless.rs | 828 +- .../rust/wgpu-core/src/track/texture.rs | 1908 +- .../rust/wgpu-hal/.cargo-checksum.json | 50 +- .../rust/wgpu-hal/examples/halmark/main.rs | 5 +- .../rust/wgpu-hal/examples/raw-gles.rs | 1 - .../rust/wgpu-hal/src/auxil/dxgi/factory.rs | 231 +- third_party/rust/wgpu-hal/src/dx11/device.rs | 3 - third_party/rust/wgpu-hal/src/dx11/library.rs | 4 +- third_party/rust/wgpu-hal/src/dx11/mod.rs | 18 +- third_party/rust/wgpu-hal/src/dx12/adapter.rs | 12 + third_party/rust/wgpu-hal/src/dx12/device.rs | 2 +- .../rust/wgpu-hal/src/dx12/instance.rs | 14 +- third_party/rust/wgpu-hal/src/dx12/mod.rs | 134 +- third_party/rust/wgpu-hal/src/empty.rs | 7 - third_party/rust/wgpu-hal/src/gles/adapter.rs | 40 +- third_party/rust/wgpu-hal/src/gles/device.rs | 20 +- third_party/rust/wgpu-hal/src/gles/egl.rs | 87 +- third_party/rust/wgpu-hal/src/gles/mod.rs | 47 +- third_party/rust/wgpu-hal/src/gles/queue.rs | 80 +- third_party/rust/wgpu-hal/src/gles/web.rs | 253 +- third_party/rust/wgpu-hal/src/gles/wgl.rs | 49 +- third_party/rust/wgpu-hal/src/lib.rs | 101 +- third_party/rust/wgpu-hal/src/metal/mod.rs | 26 +- .../rust/wgpu-hal/src/metal/surface.rs | 72 +- .../rust/wgpu-hal/src/vulkan/adapter.rs | 64 +- .../rust/wgpu-hal/src/vulkan/device.rs | 1 - .../rust/wgpu-hal/src/vulkan/instance.rs | 57 +- third_party/rust/wgpu-hal/src/vulkan/mod.rs | 99 +- .../rust/wgpu-types/.cargo-checksum.json | 2 +- third_party/rust/wgpu-types/src/lib.rs | 22 + 91 files changed, 40654 insertions(+), 43708 deletions(-) create mode 100644 third_party/rust/wgpu-core/src/any_surface.rs create mode 100644 third_party/rust/wgpu-core/src/device/any_device.rs diff --git a/.cargo/config.in b/.cargo/config.in index 4a15f82d1727f..5478e2f038ab9 100644 --- a/.cargo/config.in +++ b/.cargo/config.in @@ -292,7 +292,7 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " ] git @@ -315,7 +315,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " replace - diff --git a/Cargo.lock b/Cargo.lock index d8fe5e1a56441..3fbb162e736c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6621,9 +6621,9 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " dependencies = @@ -20757,9 +20757,9 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " dependencies = @@ -35248,9 +35248,9 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " dependencies = @@ -35363,9 +35363,9 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " dependencies = @@ -35536,9 +35536,9 @@ wgpu ? rev = -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " dependencies = diff --git a/gfx/wgpu_bindings/Cargo.toml b/gfx/wgpu_bindings/Cargo.toml index 3e492a63cc150..af3cf58d90630 100644 --- a/gfx/wgpu_bindings/Cargo.toml +++ b/gfx/wgpu_bindings/Cargo.toml @@ -98,7 +98,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " # Note @@ -226,7 +226,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " features = @@ -288,7 +288,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " features = @@ -378,7 +378,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " features = @@ -419,7 +419,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " [ dependencies @@ -453,7 +453,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " [ target @@ -489,7 +489,7 @@ wgpu rev = " -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 " [ target diff --git a/gfx/wgpu_bindings/moz.yaml b/gfx/wgpu_bindings/moz.yaml index 53dd6922dfd32..a08b12ad0ce44 100644 --- a/gfx/wgpu_bindings/moz.yaml +++ b/gfx/wgpu_bindings/moz.yaml @@ -124,7 +124,7 @@ SSS release : commit -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 # Revision to @@ -145,7 +145,7 @@ preferred ) revision : -3ec547cdcaaa14488327d8f1b5f7736278c4178d +6e21f7a9291db4395192d6b510d906978ae2d251 license : [ diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index a81b2b979409a..245b639e61854 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -11053,6 +11053,56 @@ d3d12 who = " +Nicolas +Silva +< +nical +fastmail +. +com +> +" +criteria += +" +safe +- +to +- +deploy +" +delta += +" +0 +. +7 +. +0 +git +: +3ec547cdcaaa14488327d8f1b5f7736278c4178d +- +> +0 +. +7 +. +0 +git +: +6e21f7a9291db4395192d6b510d906978ae2d251 +" +[ +[ +audits +. +d3d12 +] +] +who += +" Teodor Tanasoaia < @@ -22699,6 +22749,56 @@ naga who = " +Nicolas +Silva +< +nical +fastmail +. +com +> +" +criteria += +" +safe +- +to +- +deploy +" +delta += +" +0 +. +14 +. +0 +git +: +3ec547cdcaaa14488327d8f1b5f7736278c4178d +- +> +0 +. +14 +. +0 +git +: +6e21f7a9291db4395192d6b510d906978ae2d251 +" +[ +[ +audits +. +naga +] +] +who += +" Teodor Tanasoaia < @@ -38778,6 +38878,58 @@ core who = " +Nicolas +Silva +< +nical +fastmail +. +com +> +" +criteria += +" +safe +- +to +- +deploy +" +delta += +" +0 +. +18 +. +0 +git +: +3ec547cdcaaa14488327d8f1b5f7736278c4178d +- +> +0 +. +18 +. +0 +git +: +6e21f7a9291db4395192d6b510d906978ae2d251 +" +[ +[ +audits +. +wgpu +- +core +] +] +who += +" Teodor Tanasoaia < @@ -39338,6 +39490,58 @@ hal who = " +Nicolas +Silva +< +nical +fastmail +. +com +> +" +criteria += +" +safe +- +to +- +deploy +" +delta += +" +0 +. +18 +. +0 +git +: +3ec547cdcaaa14488327d8f1b5f7736278c4178d +- +> +0 +. +18 +. +0 +git +: +6e21f7a9291db4395192d6b510d906978ae2d251 +" +[ +[ +audits +. +wgpu +- +hal +] +] +who += +" Teodor Tanasoaia < @@ -39898,6 +40102,58 @@ types who = " +Nicolas +Silva +< +nical +fastmail +. +com +> +" +criteria += +" +safe +- +to +- +deploy +" +delta += +" +0 +. +18 +. +0 +git +: +3ec547cdcaaa14488327d8f1b5f7736278c4178d +- +> +0 +. +18 +. +0 +git +: +6e21f7a9291db4395192d6b510d906978ae2d251 +" +[ +[ +audits +. +wgpu +- +types +] +] +who += +" Teodor Tanasoaia < diff --git a/third_party/rust/naga/.cargo-checksum.json b/third_party/rust/naga/.cargo-checksum.json index d5fd1053b0b40..87e8202f6593d 100644 --- a/third_party/rust/naga/.cargo-checksum.json +++ b/third_party/rust/naga/.cargo-checksum.json @@ -32,7 +32,7 @@ toml " : " -839f25c8882c9f05ce0816d4c75c27c4ef89629e85fc8f653875823ff220b129 +1122c734de573c60738de4d56b11c06376a1ff25412f59caf98a7d7acc39d7b0 " " README @@ -52,7 +52,7 @@ rs " : " -98107330452b14b95fbd513f547c9447d21a6fafb2124f4442098262c3f2e84d +f45e38b26e1323e934d32623572ff5395a53fed06f760eb1e07b22ed07858a38 " " src @@ -63,7 +63,7 @@ rs " : " -debe6414ef822c055b52e808407a1844bf9fb26d682df3df9582d7723de77fdf +33ed2ec7b36429b133ed2a7de6fb9735827f69ea8b6c2ce97f64746a24a5bf36 " " src @@ -241,7 +241,7 @@ rs " : " -64a92abc3be4d4840817c1385d30d9f0401184a94367e604bbd25995e96c0154 +998c0d86a26e5cf031c75f35cde28f2b390fe207a2e7d0eed8516ffdb99c1a8e " " src @@ -286,7 +286,7 @@ rs " : " -ea0750e8f43eb2d9e83ccfe8dadd3467a00db925a9ed97a813766a6898c9ae0d +90b4819ad14240cf92b317c08370d25821f4b9e61018d589dcaf5189102b348d " " src @@ -492,7 +492,7 @@ rs " : " -02776b02303c381d6ed39852059e1cbe575da2c799b2421385280a07f828c77d +c69089e5bbb6de6ba24efb15b21d5d434fcabfbc4d48feae948d2a4da135aae7 " " src @@ -1156,7 +1156,7 @@ rs " : " -0aa5970f3870f67d9ac9656104b0862be49518477a4ffa9decf5e15b537ce255 +b1df60b137f5c7f6106d54f70548b19ddef5d55b1da19f4d28a8970723dc0f4a " " src @@ -1206,7 +1206,7 @@ rs " : " -bda1b65361131c0c253ab0be17d6fe0cd7a3f5658026245d59ec5b5c208b2844 +4a3bfc67e055012036ef850a1f5302c681d41d967156d6fd4c616bd1a3075219 " " src @@ -1219,7 +1219,7 @@ rs " : " -3f0ca32c8bf7e37013e432235cb4d7a9c34a554a56b70420bbaf81a708c54a52 +39ac886c651e2ad33c06a676a7e4826a0e93de0af660c01e8e4b1f7406742f88 " " src @@ -1308,7 +1308,7 @@ rs " : " -c09627f5ae17ed864521f8d42f760d0a2168984e7f63eb676f80c4315512d707 +6560599f20b8bc2de746ee9fd6b05c32bb630af914fce8845d84fdc72f9a636c " " src @@ -1321,7 +1321,7 @@ rs " : " -2309f8fc1cfd83b6fcd402d4211da3c84c20dc194d615734595c571d90ea4f1f +8472b98f16a4a4a0fa7079197db25696f77ef3e1602a7cddea1930daebd27917 " " src @@ -1334,7 +1334,7 @@ rs " : " -73c559aae4c594799d1ebb30f39532e51819c9b447f823b380f40e2b7776a705 +99a910b4d59ad9b62151d39e4f025b9195f832fb19bbab172a0cc907510d79e5 " " src @@ -1347,7 +1347,7 @@ rs " : " -16dd89ba94e81a52cdcee3f804b7fd0ccc6d076d2568dca3ad251a3b1b945213 +8086c82552985cec11b05171cbcd9edfc1415910b9e29ce6dcbab85430cb603d " " src @@ -1360,7 +1360,7 @@ rs " : " -53f197499c36323c15c56357b4f31965f8fff6ad4a2029defb0e5450713653a1 +9782913bb4d3df874ca976aa86b06bffd6c30401b8861440a9430203fef9852a " " src @@ -1373,7 +1373,7 @@ rs " : " -bf15ab0b93910c7ee27a526a734133585d5738fd95860674f902503a89ca06c4 +0878915e67b16d7c41cf8245d9ab3b3f4a604e7d4e87527ea40e03efcbf1f74a " " src @@ -1386,7 +1386,7 @@ rs " : " -26ababe7f89f78884fd8a2f41c30f0ba0379c2816e3f88469c89db8b7624422c +6ddf5f8d5150342d2e8c754a71c92c85d8533fd1d4c6b7a83a05b508e8e8114d " " src @@ -1399,7 +1399,7 @@ rs " : " -e850e5829c258e8b7f909d82c59726471ba07b6331c03172cd7170e5c2f730cf +9e2bafa06bea16db2c5a8f825eed4d008c474b87cda2fc7e82ca7a21229c6f20 " " src diff --git a/third_party/rust/naga/Cargo.toml b/third_party/rust/naga/Cargo.toml index 608e1e879676e..f21d4fac95bb2 100644 --- a/third_party/rust/naga/Cargo.toml +++ b/third_party/rust/naga/Cargo.toml @@ -359,9 +359,6 @@ version . 0 " -optional -= -true [ dependencies . @@ -485,9 +482,6 @@ version . 0 " -optional -= -true [ dependencies . @@ -748,18 +742,6 @@ indexmap serde " ] -span -= -[ -" -codespan -- -reporting -" -" -termcolor -" -] spv - in @@ -781,29 +763,17 @@ out spirv " ] -validate -= -[ -] wgsl - in = [ " -codespan -- -reporting -" -" hexf - parse " " -termcolor -" -" unicode - xid diff --git a/third_party/rust/naga/benches/criterion.rs b/third_party/rust/naga/benches/criterion.rs index 38009ce2bc780..4d3676d79fbe0 100644 --- a/third_party/rust/naga/benches/criterion.rs +++ b/third_party/rust/naga/benches/criterion.rs @@ -1156,17 +1156,6 @@ valid " ) ; -# -[ -cfg -( -feature -= -" -validate -" -) -] group . bench_function @@ -1253,17 +1242,6 @@ unwrap } ) ; -# -[ -cfg -( -feature -= -" -validate -" -) -] group . bench_function @@ -1361,17 +1339,6 @@ mut Criterion ) { -# -[ -cfg -( -feature -= -" -validate -" -) -] let inputs = @@ -1472,47 +1439,6 @@ _ ) } ; -# -[ -cfg -( -not -( -feature -= -" -validate -" -) -) -] -let -inputs -= -Vec -: -: -< -( -naga -: -: -Module -naga -: -: -valid -: -: -ModuleInfo -) -> -: -: -new -( -) -; let mut group diff --git a/third_party/rust/naga/src/arena.rs b/third_party/rust/naga/src/arena.rs index 9062c1db68669..11154c0e9f275 100644 --- a/third_party/rust/naga/src/arena.rs +++ b/third_party/rust/naga/src/arena.rs @@ -1939,17 +1939,6 @@ T > # [ -cfg -( -feature -= -" -span -" -) -] -# -[ cfg_attr ( feature @@ -2099,17 +2088,6 @@ Vec new ( ) -# -[ -cfg -( -feature -= -" -span -" -) -] span_info : Vec @@ -2449,25 +2427,6 @@ Handle T > { -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -let -_ -= -span -; let index = @@ -2488,17 +2447,6 @@ push value ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -2973,18 +2921,6 @@ T > Span { -# -[ -cfg -( -feature -= -" -span -" -) -] -{ * self . @@ -3010,34 +2946,6 @@ default ) ) } -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -{ -let -_ -= -handle -; -Span -: -: -default -( -) -} -} / / / @@ -3478,17 +3386,6 @@ of this iteration . -# -[ -cfg -( -feature -= -" -span -" -) -] if keep { @@ -3521,17 +3418,6 @@ keep } ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -3629,17 +3515,6 @@ deserializer ) ? ; -# -[ -cfg -( -feature -= -" -span -" -) -] let span_info = @@ -3677,17 +3552,6 @@ Ok Self { data -# -[ -cfg -( -feature -= -" -span -" -) -] span_info } ) @@ -4488,17 +4352,6 @@ into this vector . -# -[ -cfg -( -feature -= -" -span -" -) -] span_info : Vec @@ -4547,17 +4400,6 @@ FastIndexSet default ( ) -# -[ -cfg -( -feature -= -" -span -" -) -] span_info : Vec @@ -4659,17 +4501,6 @@ clear ( ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -4718,41 +4549,6 @@ the first insertion . -/ -/ -/ -/ -/ -/ -If -the -span -feature -is -not -enabled -always -return -Span -: -: -default -. -/ -/ -/ -This -can -be -detected -with -[ -Span -: -: -is_defined -] -. pub fn get_span @@ -4770,18 +4566,6 @@ T > Span { -# -[ -cfg -( -feature -= -" -span -" -) -] -{ * self . @@ -4811,34 +4595,6 @@ default [ cfg ( -not -( -feature -= -" -span -" -) -) -] -{ -let -_ -= -handle -; -Span -: -: -default -( -) -} -} -# -[ -cfg -( feature = " @@ -4877,17 +4633,6 @@ drain . . ) -# -[ -cfg -( -feature -= -" -span -" -) -] inner_spans : self @@ -4952,17 +4697,6 @@ Drain a T > -# -[ -cfg -( -feature -= -" -span -" -) -] inner_spans : std @@ -5082,17 +4816,6 @@ unwrap ( ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] let span = @@ -5108,30 +4831,6 @@ unwrap ( ) ; -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -let -span -= -Span -: -: -default -( -) -; Some ( ( @@ -5357,25 +5056,19 @@ value / / / -When -the -span -feature -is -enabled -if +If value is inserted into the -/ -/ -/ arena associate span with +/ +/ +/ it . An @@ -5387,13 +5080,13 @@ can be retrieved with -/ -/ -/ the [ get_span ] +/ +/ +/ method . / @@ -5457,18 +5150,6 @@ insert_full value ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] -{ if added { @@ -5518,29 +5199,6 @@ len ) ) ; -} -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -let -_ -= -( -span -added -) -; Handle : : @@ -6217,17 +5875,6 @@ deserializer ) ? ; -# -[ -cfg -( -feature -= -" -span -" -) -] let span_info = @@ -6265,17 +5912,6 @@ Ok Self { set -# -[ -cfg -( -feature -= -" -span -" -) -] span_info } ) @@ -6396,17 +6032,6 @@ elem ? ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] arena . span_info @@ -6480,17 +6105,6 @@ elem ? ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] arena . span_info diff --git a/third_party/rust/naga/src/back/msl/keywords.rs b/third_party/rust/naga/src/back/msl/keywords.rs index 0f9499d467f33..0dd48974347a4 100644 --- a/third_party/rust/naga/src/back/msl/keywords.rs +++ b/third_party/rust/naga/src/back/msl/keywords.rs @@ -1,11 +1,82 @@ / / -TODO +MSLS +- +Metal +Shading +Language +Specification +: +/ +/ +https +: +/ +/ +developer +. +apple +. +com +/ +metal +/ +Metal +- +Shading +- +Language +- +Specification +. +pdf +/ +/ +/ +/ +C ++ ++ +- +Standard +for +Programming +Language +C ++ ++ +( +N4431 +) +/ +/ +https : -find -a -complete -list +/ +/ +www +. +open +- +std +. +org +/ +jtc1 +/ +sc22 +/ +wg21 +/ +docs +/ +papers +/ +2015 +/ +n4431 +. +pdf pub const RESERVED @@ -20,299 +91,769 @@ str [ / / -control -flow +Standard +for +Programming +Language +C ++ ++ +( +N4431 +) +: +2 +. +5 +Alternative +tokens " -break +and " " -if +bitor " " -else +or " " -continue +xor " " -goto +compl " " -do +bitand " " -while +and_eq " " -for +or_eq " " -switch +xor_eq " " -case +not +" +" +not_eq " / / -types -and -values +Standard +for +Programming +Language +C ++ ++ +( +N4431 +) +: +2 +. +11 +Keywords " -void +alignas " " -unsigned +alignof " " -signed +asm +" +" +auto " " bool " " +break +" +" +case +" +" +catch +" +" char " " -int +char16_t " " -uint +char32_t " " -long +class " " -float +const " " -double +constexpr +" " +const_cast " -char8_t " +continue " -wchar_t " +decltype " -true " +default " -false " +delete " -nullptr " +do " -union " +double " -class " +dynamic_cast " -struct +" +else " " enum " -/ -/ -other " -main +explicit " " -using +export " " -decltype +extern " " -sizeof +false " " -typeof +float " " -typedef +for " " -explicit +friend " " -export +goto " " -friend +if +" +" +inline +" +" +int +" +" +long +" +" +mutable " " namespace " " +new +" +" +noexcept +" +" +nullptr +" +" operator " " +private +" +" +protected +" +" public " " +register +" +" +reinterpret_cast +" +" +return +" +" +short +" +" +signed +" +" +sizeof +" +" +static +" +" +static_assert +" +" +static_cast +" +" +struct +" +" +switch +" +" template " " -typename +this +" +" +thread_local +" +" +throw +" +" +true +" +" +try +" +" +typedef " " typeid " " -co_await +typename " " -co_return +union " " -co_yield +unsigned " " -module +using " " -import +virtual " " -ray_data +void " " -vec_step +volatile " " -visible +wchar_t " " -as_type +while " +/ +/ +Metal +Shading +Language +Specification +: +1 +. +4 +. +4 +Restrictions " -this +main " / / -qualifiers +Metal +Shading +Language +Specification +: +2 +. +1 +Scalar +Data +Types " -mutable +int8_t " " -static +uchar " " -volatile +uint8_t " " -restrict +int16_t " " -const +ushort " " -non -- -temporal +uint16_t +" +" +int32_t +" +" +uint +" +" +uint32_t +" +" +int64_t +" +" +uint64_t +" +" +half " " -dereferenceable +bfloat " " -invariant +size_t +" +" +ptrdiff_t " / / -exceptions +Metal +Shading +Language +Specification +: +2 +. +2 +Vector +Data +Types " -throw +bool2 " " -try +bool3 " " -catch +bool4 +" +" +char2 +" +" +char3 +" +" +char4 +" +" +short2 +" +" +short3 +" +" +short4 +" +" +int2 +" +" +int3 +" +" +int4 +" +" +long2 +" +" +long3 +" +" +long4 +" +" +uchar2 +" +" +uchar3 +" +" +uchar4 +" +" +ushort2 +" +" +ushort3 +" +" +ushort4 +" +" +uint2 +" +" +uint3 +" +" +uint4 +" +" +ulong2 +" +" +ulong3 +" +" +ulong4 +" +" +half2 +" +" +half3 +" +" +half4 +" +" +bfloat2 +" +" +bfloat3 +" +" +bfloat4 +" +" +float2 +" +" +float3 +" +" +float4 +" +" +vec " / / -operators +Metal +Shading +Language +Specification +: +2 +. +2 +. +3 +Packed +Vector +Types " -const_cast +packed_bool2 " " -dynamic_cast +packed_bool3 " " -reinterpret_cast +packed_bool4 " " -static_cast +packed_char2 " " -new +packed_char3 " " -delete +packed_char4 " " -and +packed_short2 " " -and_eq +packed_short3 " " -bitand +packed_short4 " " -bitor +packed_int2 " " -compl +packed_int3 " " -not +packed_int4 " " -not_eq +packed_uchar2 " " -or +packed_uchar3 " " -or_eq +packed_uchar4 " " -xor +packed_ushort2 " " -xor_eq +packed_ushort3 " " -compl +packed_ushort4 +" +" +packed_uint2 +" +" +packed_uint3 +" +" +packed_uint4 +" +" +packed_half2 +" +" +packed_half3 +" +" +packed_half4 +" +" +packed_bfloat2 +" +" +packed_bfloat3 +" +" +packed_bfloat4 +" +" +packed_float2 +" +" +packed_float3 +" +" +packed_float4 +" +" +packed_long2 +" +" +packed_long3 +" +" +packed_long4 +" +" +packed_vec " / / Metal +Shading +Language +Specification +: +2 +. +3 +Matrix +Data +Types +" +half2x2 +" +" +half2x3 +" +" +half2x4 +" +" +half3x2 +" +" +half3x3 +" +" +half3x4 +" +" +half4x2 +" +" +half4x3 +" +" +half4x4 +" +" +float2x2 +" +" +float2x3 +" +" +float2x4 +" +" +float3x2 +" +" +float3x3 +" +" +float3x4 +" +" +float4x2 +" +" +float4x3 +" +" +float4x4 +" +" +matrix +" +/ +/ +Metal +Shading +Language +Specification +: +2 +. +6 +Atomic +Data +Types +" +atomic +" +" +atomic_int +" +" +atomic_uint +" +" +atomic_bool +" +" +atomic_ulong +" +" +atomic_float +" +/ +/ +Metal +Shading +Language +Specification +: +2 +. +20 +Type +Conversions +and +Re - -specific +interpreting +Data " -constant +as_type " +/ +/ +Metal +Shading +Language +Specification +: +4 +Address +Spaces " device " " +constant +" +" +thread +" +" threadgroup " " threadgroup_imageblock " " -kernel +ray_data " " -compute +object_data " +/ +/ +Metal +Shading +Language +Specification +: +5 +. +1 +Functions " vertex " @@ -320,22 +861,47 @@ vertex fragment " " -read_only -" -" -write_only +kernel " +/ +/ +Metal +Shading +Language +Specification +: +6 +. +1 +Namespace +and +Header +Files " -read_write +metal " +/ +/ +C99 +/ +C ++ ++ +extension +: " -auto +restrict " / / Metal reserved types +in +< +metal_types +> +: " llong " @@ -353,8 +919,12 @@ imaginary " / / -Metal -constants +Constants +in +< +metal_types +> +: " CHAR_BIT " @@ -668,9 +1238,6 @@ utilities " DefaultConstructible " -" -clamped_lod_e -" super : : diff --git a/third_party/rust/naga/src/back/msl/writer.rs b/third_party/rust/naga/src/back/msl/writer.rs index 86420eb5c0194..2b8a93ddc7c65 100644 --- a/third_party/rust/naga/src/back/msl/writer.rs +++ b/third_party/rust/naga/src/back/msl/writer.rs @@ -24308,6 +24308,7 @@ RESERVED ] & [ +CLAMPED_LOD_LOAD_PREFIX ] & mut diff --git a/third_party/rust/naga/src/block.rs b/third_party/rust/naga/src/block.rs index 1d43ba012bfc2..a5fce0a58ec8b 100644 --- a/third_party/rust/naga/src/block.rs +++ b/third_party/rust/naga/src/block.rs @@ -110,17 +110,6 @@ Statement > # [ -cfg -( -feature -= -" -span -" -) -] -# -[ cfg_attr ( feature @@ -164,17 +153,6 @@ Vec new ( ) -# -[ -cfg -( -feature -= -" -span -" -) -] span_info : Vec @@ -200,17 +178,6 @@ Statement > Self { -# -[ -cfg -( -feature -= -" -span -" -) -] let span_info = @@ -246,17 +213,6 @@ collect Self { body -# -[ -cfg -( -feature -= -" -span -" -) -] span_info } } @@ -283,17 +239,6 @@ with_capacity ( capacity ) -# -[ -cfg -( -feature -= -" -span -" -) -] span_info : Vec @@ -336,17 +281,6 @@ push end ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -408,17 +342,6 @@ other Self ) { -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -456,17 +379,6 @@ mut Self ) { -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -516,17 +428,6 @@ range R ) { -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -575,17 +476,6 @@ other Self ) { -# -[ -cfg -( -feature -= -" -span -" -) -] self . span_info @@ -637,17 +527,6 @@ Span ) > { -# -[ -cfg -( -feature -= -" -span -" -) -] let span_iter = @@ -659,40 +538,6 @@ iter ( ) ; -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -let -span_iter -= -std -: -: -iter -: -: -repeat_with -( -| -| -& -Span -: -: -UNDEFINED -) -; self . body @@ -734,17 +579,6 @@ Span ) > { -# -[ -cfg -( -feature -= -" -span -" -) -] let span_iter = @@ -761,36 +595,6 @@ map Some ) ; -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -let -span_iter -= -std -: -: -iter -: -: -repeat_with -( -| -| -None -) -; self . body diff --git a/third_party/rust/naga/src/front/wgsl/to_wgsl.rs b/third_party/rust/naga/src/front/wgsl/to_wgsl.rs index 65642b0011d49..4209eab92e89b 100644 --- a/third_party/rust/naga/src/front/wgsl/to_wgsl.rs +++ b/third_party/rust/naga/src/front/wgsl/to_wgsl.rs @@ -429,32 +429,13 @@ base > { let -base -= -& -gctx -. -types -[ -base -] -; -let name = base . -name -. -as_deref -( -) -. -unwrap_or +to_wgsl ( -" -unknown -" +gctx ) ; format @@ -513,32 +494,13 @@ size > { let -member_type -= -& -gctx -. -types -[ -base -] -; -let base = -member_type -. -name -. -as_deref -( -) +base . -unwrap_or +to_wgsl ( -" -unknown -" +gctx ) ; match diff --git a/third_party/rust/naga/src/proc/constant_evaluator.rs b/third_party/rust/naga/src/proc/constant_evaluator.rs index d0e1c7e232b17..797b253d58461 100644 --- a/third_party/rust/naga/src/proc/constant_evaluator.rs +++ b/third_party/rust/naga/src/proc/constant_evaluator.rs @@ -5972,6 +5972,120 @@ Expression : Compose fn +eval_zero_value +( +& +mut +self +expr +: +Handle +< +Expression +> +span +: +Span +) +- +> +Result +< +Handle +< +Expression +> +ConstantEvaluatorError +> +{ +match +self +. +expressions +[ +expr +] +{ +Expression +: +: +ZeroValue +( +ty +) += +> +self +. +eval_zero_value_impl +( +ty +span +) +_ += +> +Ok +( +expr +) +} +} +/ +/ +/ +Lower +[ +ZeroValue +] +expressions +to +[ +Literal +] +and +[ +Compose +] +expressions +. +/ +/ +/ +/ +/ +/ +[ +ZeroValue +] +: +Expression +: +: +ZeroValue +/ +/ +/ +[ +Literal +] +: +Expression +: +: +Literal +/ +/ +/ +[ +Compose +] +: +Expression +: +: +Compose +fn eval_zero_value_impl ( & @@ -6478,7 +6592,7 @@ expr = self . -eval_zero_value_and_splat +eval_zero_value ( expr span @@ -7004,6 +7118,53 @@ ty components } } +Expression +: +: +Splat +{ +size +value +} += +> +{ +let +value_span += +self +. +expressions +. +get_span +( +value +) +; +let +cast_value += +self +. +cast +( +value +target +value_span +) +? +; +Expression +: +: +Splat +{ +size +value +: +cast_value +} +} _ = > diff --git a/third_party/rust/naga/src/proc/emitter.rs b/third_party/rust/naga/src/proc/emitter.rs index 225ab94041fae..934cbd753b181 100644 --- a/third_party/rust/naga/src/proc/emitter.rs +++ b/third_party/rust/naga/src/proc/emitter.rs @@ -226,17 +226,6 @@ range_from start_len ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] for handle in diff --git a/third_party/rust/naga/src/span.rs b/third_party/rust/naga/src/span.rs index e91a07649b37d..c42db262eee5c 100644 --- a/third_party/rust/naga/src/span.rs +++ b/third_party/rust/naga/src/span.rs @@ -987,17 +987,6 @@ E inner : E -# -[ -cfg -( -feature -= -" -span -" -) -] spans : Vec @@ -1200,17 +1189,6 @@ Self Self { inner -# -[ -cfg -( -feature -= -" -span -" -) -] spans : Vec @@ -1327,18 +1305,6 @@ Item SpanContext > { -# -[ -cfg -( -feature -= -" -span -" -) -] -return self . spans @@ -1346,32 +1312,6 @@ spans iter ( ) -; -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -return -std -: -: -iter -: -: -empty -( -) -; } / / @@ -1383,29 +1323,6 @@ span with description . -# -[ -cfg_attr -( -not -( -feature -= -" -span -" -) -allow -( -unused_variables -unused_mut -clippy -: -: -missing_const_for_fn -) -) -] pub fn with_span @@ -1430,17 +1347,6 @@ S : ToString { -# -[ -cfg -( -feature -= -" -span -" -) -] if span . @@ -1630,17 +1536,6 @@ inner into ( ) -# -[ -cfg -( -feature -= -" -span -" -) -] spans : self @@ -1707,24 +1602,6 @@ WithSpan E2 > { -# -[ -cfg_attr -( -not -( -feature -= -" -span -" -) -allow -( -unused_mut -) -) -] let mut res @@ -1736,17 +1613,6 @@ self inner ) ; -# -[ -cfg -( -feature -= -" -span -" -) -] res . spans @@ -1760,17 +1626,6 @@ spans ; res } -# -[ -cfg -( -feature -= -" -span -" -) -] / / / @@ -1836,78 +1691,6 @@ source ) ) } -# -[ -cfg -( -not -( -feature -= -" -span -" -) -) -] -# -[ -allow -( -clippy -: -: -missing_const_for_fn -) -] -/ -/ -/ -Return -a -[ -SourceLocation -] -for -our -first -span -if -we -have -one -. -pub -fn -location -( -& -self -_source -: -& -str -) -- -> -Option -< -SourceLocation -> -{ -None -} -# -[ -cfg -( -feature -= -" -span -" -) -] fn diagnostic ( @@ -2096,17 +1879,6 @@ standard error stream . -# -[ -cfg -( -feature -= -" -span -" -) -] pub fn emit_to_stderr @@ -2147,17 +1919,6 @@ standard error stream . -# -[ -cfg -( -feature -= -" -span -" -) -] pub fn emit_to_stderr_with_path @@ -2288,17 +2049,6 @@ to a string . -# -[ -cfg -( -feature -= -" -span -" -) -] pub fn emit_to_string @@ -2341,17 +2091,6 @@ to a string . -# -[ -cfg -( -feature -= -" -span -" -) -] pub fn emit_to_string_with_path diff --git a/third_party/rust/naga/src/valid/analyzer.rs b/third_party/rust/naga/src/valid/analyzer.rs index 880dbff78770c..8babca6d5f40a 100644 --- a/third_party/rust/naga/src/valid/analyzer.rs +++ b/third_party/rust/naga/src/valid/analyzer.rs @@ -5711,17 +5711,6 @@ uniformity . requirements ; -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -5997,17 +5986,6 @@ programs . / * -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -7328,17 +7306,6 @@ index [ test ] -# -[ -cfg -( -feature -= -" -validate -" -) -] fn uniform_control_flow ( diff --git a/third_party/rust/naga/src/valid/compose.rs b/third_party/rust/naga/src/valid/compose.rs index bcf357ee620dd..6904208f21a12 100644 --- a/third_party/rust/naga/src/valid/compose.rs +++ b/third_party/rust/naga/src/valid/compose.rs @@ -1,14 +1,3 @@ -# -[ -cfg -( -feature -= -" -validate -" -) -] use crate : @@ -140,17 +129,6 @@ index u32 } } -# -[ -cfg -( -feature -= -" -validate -" -) -] pub fn validate_compose diff --git a/third_party/rust/naga/src/valid/expression.rs b/third_party/rust/naga/src/valid/expression.rs index 0060edc0ad658..527462b7bf428 100644 --- a/third_party/rust/naga/src/valid/expression.rs +++ b/third_party/rust/naga/src/valid/expression.rs @@ -1,14 +1,3 @@ -# -[ -cfg -( -feature -= -" -validate -" -) -] use super : @@ -25,17 +14,6 @@ ShaderStages TypeFlags } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use crate : @@ -1758,17 +1736,6 @@ type WidthError ) } -# -[ -cfg -( -feature -= -" -validate -" -) -] struct ExpressionTypeResolver < @@ -1804,17 +1771,6 @@ info a FunctionInfo } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl < ' @@ -1944,17 +1900,6 @@ root } } } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl super : diff --git a/third_party/rust/naga/src/valid/function.rs b/third_party/rust/naga/src/valid/function.rs index e3df992e58a0c..e1d36e07dd322 100644 --- a/third_party/rust/naga/src/valid/function.rs +++ b/third_party/rust/naga/src/valid/function.rs @@ -7,17 +7,6 @@ arena : Handle ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use crate : @@ -30,17 +19,6 @@ Arena UniqueArena } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use super : @@ -73,17 +51,6 @@ span : WithSpan ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use crate : @@ -100,17 +67,6 @@ as _ } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use bit_set : @@ -1672,17 +1628,6 @@ CONTINUE ; } } -# -[ -cfg -( -feature -= -" -validate -" -) -] struct BlockInfo { @@ -1696,17 +1641,6 @@ finished : bool } -# -[ -cfg -( -feature -= -" -validate -" -) -] struct BlockContext < @@ -1813,17 +1747,6 @@ Type > > } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl < ' @@ -2262,17 +2185,6 @@ super : Validator { -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_call ( @@ -2681,17 +2593,6 @@ callee_info available_stages ) } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn emit_expression ( @@ -2775,17 +2676,6 @@ expressions ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_atomic ( @@ -3323,17 +3213,6 @@ Ok ) ) } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_block_impl ( @@ -6491,17 +6370,6 @@ finished } ) } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_block ( @@ -6587,17 +6455,6 @@ Ok info ) } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_local_var ( @@ -6842,24 +6699,6 @@ mod_info : & ModuleInfo -# -[ -cfg_attr -( -not -( -feature -= -" -validate -" -) -allow -( -unused -) -) -] entry_point : bool @@ -6875,24 +6714,6 @@ FunctionError > > { -# -[ -cfg_attr -( -not -( -feature -= -" -validate -" -) -allow -( -unused_mut -) -) -] let mut info @@ -6912,17 +6733,6 @@ capabilities ) ? ; -# -[ -cfg -( -feature -= -" -validate -" -) -] let expression_constness = @@ -6943,17 +6753,6 @@ fun expressions ) ; -# -[ -cfg -( -feature -= -" -validate -" -) -] for ( var_handle @@ -7038,17 +6837,6 @@ local_variables ? ; } -# -[ -cfg -( -feature -= -" -validate -" -) -] for ( index @@ -7279,17 +7067,6 @@ types ; } } -# -[ -cfg -( -feature -= -" -validate -" -) -] if let Some @@ -7437,17 +7214,6 @@ index ) ; } -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -7522,17 +7288,6 @@ expressions } } } -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . diff --git a/third_party/rust/naga/src/valid/handles.rs b/third_party/rust/naga/src/valid/handles.rs index ff620340bb058..93a64075e32e0 100644 --- a/third_party/rust/naga/src/valid/handles.rs +++ b/third_party/rust/naga/src/valid/handles.rs @@ -23,17 +23,6 @@ BadRangeError Handle } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use crate : @@ -43,34 +32,12 @@ Arena UniqueArena } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use super : : ValidationError ; -# -[ -cfg -( -feature -= -" -validate -" -) -] use std : @@ -90,17 +57,6 @@ num NonZeroU32 } ; -# -[ -cfg -( -feature -= -" -validate -" -) -] impl super : @@ -3275,17 +3231,6 @@ Ok ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl From < @@ -3318,17 +3263,6 @@ into ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl From < @@ -3361,17 +3295,6 @@ into ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl From < @@ -3584,17 +3507,6 @@ depends_on_kind static str } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl < T @@ -4122,17 +4034,6 @@ self ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] impl < T @@ -4186,17 +4087,6 @@ self [ test ] -# -[ -cfg -( -feature -= -" -validate -" -) -] fn constant_deps ( diff --git a/third_party/rust/naga/src/valid/interface.rs b/third_party/rust/naga/src/valid/interface.rs index 60434d8626741..23239fd37b7b2 100644 --- a/third_party/rust/naga/src/valid/interface.rs +++ b/third_party/rust/naga/src/valid/interface.rs @@ -54,17 +54,6 @@ bit_set : BitSet ; -# -[ -cfg -( -feature -= -" -validate -" -) -] const MAX_WORKGROUP_SIZE : @@ -1037,17 +1026,6 @@ location_mask BitSet } } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn storage_usage ( @@ -1193,17 +1171,6 @@ BuiltIn capabilities : Capabilities -# -[ -cfg -( -feature -= -" -validate -" -) -] flags : super @@ -2386,17 +2353,6 @@ as usize ) { -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -2825,17 +2781,6 @@ None = > { -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -2872,25 +2817,6 @@ span_context ) ; } -# -[ -cfg -( -not -( -feature -= -" -validate -" -) -) -] -let -_ -= -index -; } Some ( @@ -2929,17 +2855,6 @@ _ = > { -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -2987,17 +2902,6 @@ super : Validator { -# -[ -cfg -( -feature -= -" -validate -" -) -] pub ( super @@ -3945,17 +3849,6 @@ EntryPointError > > { -# -[ -cfg -( -feature -= -" -validate -" -) -] if ep . @@ -4036,17 +3929,6 @@ with_span ; } } -# -[ -cfg -( -feature -= -" -validate -" -) -] if ep . @@ -4129,24 +4011,6 @@ with_span ) ; } -# -[ -cfg_attr -( -not -( -feature -= -" -validate -" -) -allow -( -unused_mut -) -) -] let mut info @@ -4173,17 +4037,6 @@ into_other ) ? ; -# -[ -cfg -( -feature -= -" -validate -" -) -] { use super @@ -4364,17 +4217,6 @@ capabilities self . capabilities -# -[ -cfg -( -feature -= -" -validate -" -) -] flags : self @@ -4503,17 +4345,6 @@ capabilities self . capabilities -# -[ -cfg -( -feature -= -" -validate -" -) -] flags : self @@ -4556,17 +4387,6 @@ with_span ) ? ; -# -[ -cfg -( -feature -= -" -validate -" -) -] if ctx . @@ -4642,17 +4462,6 @@ with_span ; } } -# -[ -cfg -( -feature -= -" -validate -" -) -] if ep . @@ -4718,17 +4527,6 @@ ShaderStage : Vertex { -# -[ -cfg -( -feature -= -" -validate -" -) -] return Err ( @@ -4743,17 +4541,6 @@ with_span ) ; } -# -[ -cfg -( -feature -= -" -validate -" -) -] { let used_push_constants @@ -4894,17 +4681,6 @@ clear ( ) ; -# -[ -cfg -( -feature -= -" -validate -" -) -] for ( var_handle diff --git a/third_party/rust/naga/src/valid/mod.rs b/third_party/rust/naga/src/valid/mod.rs index 5e32059539017..54880ff7591dc 100644 --- a/third_party/rust/naga/src/valid/mod.rs +++ b/third_party/rust/naga/src/valid/mod.rs @@ -315,48 +315,6 @@ all ( ) . -If -Naga -' -s -" -validate -" -feature -is -/ -/ -/ -enabled -this -requests -full -validation -; -otherwise -this -/ -/ -/ -requests -no -validation -. -( -The -" -validate -" -feature -is -disabled -/ -/ -/ -by -default -. -) # [ cfg_attr @@ -415,17 +373,6 @@ u8 / Expressions . -# -[ -cfg -( -feature -= -" -validate -" -) -] const EXPRESSIONS = @@ -440,17 +387,6 @@ blocks of them . -# -[ -cfg -( -feature -= -" -validate -" -) -] const BLOCKS = @@ -469,17 +405,6 @@ that require it . -# -[ -cfg -( -feature -= -" -validate -" -) -] const CONTROL_FLOW_UNIFORMITY = @@ -494,17 +419,6 @@ shareable structure layouts . -# -[ -cfg -( -feature -= -" -validate -" -) -] const STRUCT_LAYOUTS = @@ -515,17 +429,6 @@ STRUCT_LAYOUTS / Constants . -# -[ -cfg -( -feature -= -" -validate -" -) -] const CONSTANTS = @@ -540,17 +443,6 @@ and location attributes . -# -[ -cfg -( -feature -= -" -validate -" -) -] const BINDINGS = @@ -1680,17 +1572,6 @@ crate : TypeInner { -# -[ -cfg -( -feature -= -" -validate -" -) -] const fn is_sized @@ -1856,17 +1737,6 @@ an appropriate coordinate . -# -[ -cfg -( -feature -= -" -validate -" -) -] const fn image_storage_coordinates @@ -2208,17 +2078,6 @@ clear ) ; } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_constant ( @@ -2424,17 +2283,6 @@ len ) ) ; -# -[ -cfg -( -feature -= -" -validate -" -) -] Self : : @@ -2805,17 +2653,6 @@ const_expressions ? } } -# -[ -cfg -( -feature -= -" -validate -" -) -] if self . @@ -2953,17 +2790,6 @@ constants ? } } -# -[ -cfg -( -feature -= -" -validate -" -) -] for ( var_handle @@ -3295,17 +3121,6 @@ mod_info ) } } -# -[ -cfg -( -feature -= -" -validate -" -) -] fn validate_atomic_compare_exchange_struct ( diff --git a/third_party/rust/wgpu-core/.cargo-checksum.json b/third_party/rust/wgpu-core/.cargo-checksum.json index 04628f82ddc0a..e393fc06b8afe 100644 --- a/third_party/rust/wgpu-core/.cargo-checksum.json +++ b/third_party/rust/wgpu-core/.cargo-checksum.json @@ -11,7 +11,7 @@ toml " : " -a01dee48cee8d362ac28b8c920b914d11be2362ca6d7d6036b6d786eca348be2 +bde42e04a69f912ac871368e202df8af116ea0ef010a2f08a62388b6985ca61f " " LICENSE @@ -34,13 +34,24 @@ c7fea58d1cfe49634cd92e54fc10a9d871f4b275321a4cd8c09e449122caaeb4 " src / +any_surface +. +rs +" +: +" +1afed4e5e2cc1726c9887bfbf8805f9141f859615c1eaf90f4ef3e49850caf06 +" +" +src +/ binding_model . rs " : " -f6d9b170a9328751b3109c81d6f1b555a6db1410f1b7e67c59cc596a1fd1d293 +d7add33189aa453ad19acd8ac38465f44e233d0e8da42be5a3aadfc50a87a491 " " src @@ -53,7 +64,7 @@ rs " : " -67b8431a32f403e358b9c1593e6e0d64519f5f0b699059e6ea5374800d5c23d9 +85bbab812222f9bc11893059304cac850616818b00857fadac4885b978e4cfe2 " " src @@ -66,7 +77,7 @@ rs " : " -d5456be31f973fcae55ee01781da963f1c950aa5db7eae4d3c6166d4f1a132ca +7836b3740ad32168fdfb4241dbc91839d695c019abd3c38e3decec332b7e82c2 " " src @@ -79,7 +90,7 @@ rs " : " -9c4c1734705a79b64a31540ddf7ec4e9f10b9d923b6d21783d98314a7b10bb25 +65499812d269e23efb12a12a455f58f52f3014f8db224d02951b7331638f6ad4 " " src @@ -92,7 +103,7 @@ rs " : " -8caa0f5fa1956a3747f0b845fdeec2572b9462a7e98fdb5cf7b562c472bd6c4c +296864d4f9e9a98f368d64910146480e38e2f895eee98a97d947dd593033f87c " " src @@ -118,7 +129,7 @@ rs " : " -b50d3d20dbf659052f19da2e79469ba6435e06370f19d6ef45e1b1128d9900b7 +ffe5c301f19a17285523ee8fd5e7bf5abd5e50e9a3716f5713ac99ab135d9f5e " " src @@ -131,7 +142,7 @@ rs " : " -4eac2ac0283c0cfdcc3512af5439fe38e7004e5f406bf52a66d3017ad1ae7632 +e7c5e83a1b6398e68279b10910f426d7dde1ce3c800752bb88688b37f69b7872 " " src @@ -144,7 +155,7 @@ rs " : " -d39e1b8cb6a054fd31333a916da5d79a6671a724212c90c490c13e55043a1685 +f31db3f1282109baa59e6dcd7b2e674c7858a2c64f58fc6eb3a4d0c546935af5 " " src @@ -157,7 +168,7 @@ rs " : " -c445f52d0b82d80033071025446ca2488ef702d4fd452fe4c67b154392630bab +6553e77c2c5a6cdf496e1316dc67071247ebf118bc238bbf2222f880a458bbf6 " " src @@ -170,7 +181,7 @@ rs " : " -1fc4d8a87eef3241134f0e6d3bb617511629afe10fddb16440f688e17bee7719 +49dd1261e3ad1effc4ebdad1bc3061f4330f991b8291df75591a1e2bc5eaa257 " " src @@ -181,7 +192,20 @@ rs " : " -da95b36b7680ae74ebf810ad8f1decf01bd3eeaff44b3c5af1d4b3c3f0e2059a +7e3ffe33b47a6fd3617aabf9f11cc68f1ccbee2c7343b8dbbcd0e8f3447e1ad8 +" +" +src +/ +device +/ +any_device +. +rs +" +: +" +2cb2be0fd078d65039692d309d8688cf4a02fb768579cf22c93cfa514d20ad7f " " src @@ -194,7 +218,7 @@ rs " : " -2ccbc26fddb9291fecd0fe3c5e85c806cf77319fe2818a8684a81bed3ea7e649 +3be88717a7d164ea73842f90b93c359f8ea06bbae253af9a195734640d5a830d " " src @@ -207,7 +231,7 @@ rs " : " -6a7cbf7d47155fe1171387221141eefab135868196a03b0bba86ab168d9dee58 +6c2b2e7f98f71231c97f19cf19c4d8ff254ee9862a8422f973270656658aed96 " " src @@ -220,7 +244,7 @@ rs " : " -a7627267001bbadb7309f4f0721ecec404dcba06bd6aab4dd6fa17410fc7402b +9bae0d30eaf51af5545eea10d5c8af6ca3ced2518d24c42880ec3c8f1f7664b2 " " src @@ -233,7 +257,7 @@ rs " : " -56cbce0ed748c78d2360e3e042ffade1d941231acbb873d7aab4ac65b938ad06 +aec77faebaa750f843f2f04ea9a2021598098783f16f95e739bc64fabcc29619 " " src @@ -246,7 +270,7 @@ rs " : " -c4173ab900d5332984bb20e5e2733c4c1aa799e06bfe1e975fe55982ec3cdf29 +0e707723d58cecfb402fe35eb9944278de96a95496bd2e62b50a71ef3e44d079 " " src @@ -270,7 +294,7 @@ rs " : " -ca37282283985e2b7d184b2ab7ca6f53f726432d920f8d8477bfff6fab9b34e2 +32680e922acfb1f1d6842177179768d365c575a8baa402da9d5a43a2357b0dbf " " src @@ -281,7 +305,7 @@ rs " : " -cf551de97c3eb5acd0c2710da09ebd92cc863ad0bb0f53c0fd4911bf8cd3ad97 +fd2a7995bdb64f1186fd71c4f6b59f34c543ee695912b1fad7931c88ec024584 " " src @@ -292,7 +316,7 @@ rs " : " -92a2f0cb80f192693530ed61048919bbad446742c2370bf0944c44b1c5df8362 +bb380df266fa9754c93d55c24b1a3535629710eb04bc6858a40c38a5f02aae68 " " src @@ -303,7 +327,7 @@ rs " : " -b4207d0a450da9e1d9edb0abc3c99e495132793ebe26af78ea07397d2e5c0b85 +d9435f5b12f47e0b57599dce1d38e6eb4ef2477ab634806cfccefa4c1541f87b " " src @@ -314,7 +338,7 @@ rs " : " -ef7b3a77110277f4eb2fa1a2ae3d89318023b74d5671181684d2845ef7b7d87a +4684c40d56ad8f49f36455ea84f2901df587fc3574274ac132b8236ece6926a3 " " src @@ -325,7 +349,7 @@ rs " : " -3ce6a3b57c7c4fc0808d13cd342d928c214f32368e45c79d8e2bbf8df887f97f +0701f6f41e754dde2bebc567a87c25b353dfab40b79a322990dbfa477739ab8c " " src @@ -338,7 +362,7 @@ rs " : " -a0ebf54a1e6d269c7b4aa0ac7bb8b04fd2cea3221a1d058ff33cb683b2aea3e9 +61eb9cfaa312135b7a937ff6a3117f531b5b7323fae6553a41d6de9bc106d7e0 " " src @@ -364,7 +388,7 @@ rs " : " -37b6584aaca11c407d91f77002dcbb48d8a4876e27edd1b71b7929ef966f901d +030fd594bf9948fad391390d85c5e1fec7eaf67b6e812c60f2dd59bc4fda8fd5 " " src @@ -375,7 +399,7 @@ rs " : " -37b1d19ebbc03642368c0ef668f5f897a3cac8a6cccc553b50f3de5c800fde8b +643ce09d9a623f00e66e1eb50b2facc4d072f4149c9953343c1b0e8c4a5f6915 " " src @@ -386,7 +410,7 @@ rs " : " -71d42899594be62c2e7074618e03f3639b5ef510b42d6dde660aaa4d5672691e +23ac375edd02c7808ccb901b392bb34960339027b2e068b9009f89d413946515 " " src @@ -397,7 +421,7 @@ rs " : " -4741c36fad7dedb856c3254f7869cad68dcf143aaac280f7f5920009b13c899a +e09adc811a7553daa4d826fd6001be14a7d21222fc8ba76040d4fd5c0f017787 " " src @@ -408,7 +432,7 @@ rs " : " -a81f62ca967825f777a5f0d32defb2febb8793406c527d08c6ab0e129df5a81a +5a15e583ee2b4c1afcf596c8429437a50e9fd1e17f8fbf4fafb482928940815e " " src @@ -419,7 +443,7 @@ rs " : " -4098413de7f48e9ff15d0246793be47a0d54c95b4c8594baf9fafd222a90ba84 +52a52b0ed41abbed3c6a84f0fb01c5f45c75953bacaa7a9b9bdb95a8825eb573 " " src @@ -430,7 +454,7 @@ rs " : " -f140a1071d03dccae9859047c063dcd289e653352d635082dba76ef37a6ca4c3 +14a3fedcf422688dc484c91abc5b2522c388fd5587c61e11a4b0bd882284fb24 " " src @@ -441,7 +465,7 @@ rs " : " -11ccae01252ae68727a256e5db6826f74973cfc753a18dedf7fabf8aef5596cc +343811d28ed0926ef2d7f116d5ad8b4b6b6f530d7dfb5b9afbb90f2bb3ccfbc1 " " src @@ -454,7 +478,7 @@ rs " : " -dd6f632c6f31b15807148d705c516a8a1a8d72d02b137dd3b9d7c939447917cb +2e37fdae4e3b81f4e9d4bc35d71849ce82846afbb55c3de75c5db101c888e216 " " src @@ -467,7 +491,7 @@ rs " : " -a80bd086ce825f7484ce6318a586c482d06fea0efc9c76bfa0124e480cc8b75e +8ef7af1d0152a3a8d706402a416c2e74c9282354cad055d2c0c527486cb3019e " " src @@ -480,7 +504,7 @@ rs " : " -42b791d9a41eb6e62f6d79cae7abb5ab523eeb9e6030b0f95bbb0e26d56ad0ec +028b04676f8a42a1f67bb9f6ffb809f56fa6349596b52561bce5b78c176e51e7 " " src @@ -506,7 +530,7 @@ rs " : " -1d786b5e9558672243ba7d913736561065ef2bd5c6105c935e982486d10841f0 +57f13386f0829cd6e1a894e454f69929eea7494565e530ed9f80bd7d50a4ba2d " " src @@ -519,7 +543,7 @@ rs " : " -7d60dc81ba7f7e2c2819525b90e6e6c7760cb0920e36aeefe98e76cedd49d26e +ea8ba2089e72401dcd37738d0583c411ec100a7436626f738d8d81bc188cbd99 " " src diff --git a/third_party/rust/wgpu-core/Cargo.toml b/third_party/rust/wgpu-core/Cargo.toml index 27786399da852..d11bff8a64c11 100644 --- a/third_party/rust/wgpu-core/Cargo.toml +++ b/third_party/rust/wgpu-core/Cargo.toml @@ -396,12 +396,6 @@ features " clone " -" -span -" -" -validate -" ] [ dependencies diff --git a/third_party/rust/wgpu-core/src/any_surface.rs b/third_party/rust/wgpu-core/src/any_surface.rs new file mode 100644 index 0000000000000..964e41d74c9e0 --- /dev/null +++ b/third_party/rust/wgpu-core/src/any_surface.rs @@ -0,0 +1,1075 @@ +use +wgt +: +: +Backend +; +/ +/ +/ +The +AnySurface +type +: +a +Arc +of +a +HalSurface +< +A +> +for +any +backend +A +. +use +crate +: +: +hal_api +: +: +HalApi +; +use +crate +: +: +instance +: +: +HalSurface +; +use +std +: +: +any +: +: +Any +; +use +std +: +: +fmt +; +use +std +: +: +sync +: +: +Arc +; +/ +/ +/ +A +Arc +of +a +HalSurface +< +A +> +for +any +backend +A +. +/ +/ +/ +/ +/ +/ +Any +AnySurface +is +just +like +an +Arc +< +HalSurface +< +A +> +> +except +that +the +/ +/ +/ +A +type +parameter +is +erased +. +To +access +the +Surface +you +must +/ +/ +/ +downcast +to +a +particular +backend +with +the +\ +[ +downcast_ref +\ +] +or +/ +/ +/ +\ +[ +take +\ +] +methods +. +pub +struct +AnySurface +( +Arc +< +dyn +Any ++ +' +static +> +) +; +impl +AnySurface +{ +/ +/ +/ +Return +an +AnySurface +that +holds +an +owning +Arc +to +HalSurface +. +pub +fn +new +< +A +: +HalApi +> +( +surface +: +HalSurface +< +A +> +) +- +> +AnySurface +{ +AnySurface +( +Arc +: +: +new +( +surface +) +) +} +pub +fn +backend +( +& +self +) +- +> +Backend +{ +# +[ +cfg +( +all +( +feature += +" +vulkan +" +not +( +target_arch += +" +wasm32 +" +) +) +) +] +if +self +. +downcast_ref +: +: +< +hal +: +: +api +: +: +Vulkan +> +( +) +. +is_some +( +) +{ +return +Backend +: +: +Vulkan +; +} +# +[ +cfg +( +all +( +feature += +" +metal +" +any +( +target_os += +" +macos +" +target_os += +" +ios +" +) +) +) +] +if +self +. +downcast_ref +: +: +< +hal +: +: +api +: +: +Metal +> +( +) +. +is_some +( +) +{ +return +Backend +: +: +Metal +; +} +# +[ +cfg +( +all +( +feature += +" +dx12 +" +windows +) +) +] +if +self +. +downcast_ref +: +: +< +hal +: +: +api +: +: +Dx12 +> +( +) +. +is_some +( +) +{ +return +Backend +: +: +Dx12 +; +} +# +[ +cfg +( +all +( +feature += +" +dx11 +" +windows +) +) +] +if +self +. +downcast_ref +: +: +< +hal +: +: +api +: +: +Dx11 +> +( +) +. +is_some +( +) +{ +return +Backend +: +: +Dx11 +; +} +# +[ +cfg +( +feature += +" +gles +" +) +] +if +self +. +downcast_ref +: +: +< +hal +: +: +api +: +: +Gles +> +( +) +. +is_some +( +) +{ +return +Backend +: +: +Gl +; +} +Backend +: +: +Empty +} +/ +/ +/ +If +self +is +an +Arc +< +HalSurface +< +A +> +> +return +a +reference +to +the +/ +/ +/ +HalSurface +. +pub +fn +downcast_ref +< +A +: +HalApi +> +( +& +self +) +- +> +Option +< +& +HalSurface +< +A +> +> +{ +self +. +0 +. +downcast_ref +: +: +< +HalSurface +< +A +> +> +( +) +} +/ +/ +/ +If +self +is +an +Arc +< +HalSurface +< +A +> +> +returns +that +. +pub +fn +take +< +A +: +HalApi +> +( +self +) +- +> +Option +< +Arc +< +HalSurface +< +A +> +> +> +{ +/ +/ +Arc +: +: +downcast +returns +Arc +< +T +> +but +requires +that +T +be +Sync +and +/ +/ +Send +and +this +is +not +the +case +for +HalSurface +in +wasm +builds +. +/ +/ +/ +/ +But +as +far +as +I +can +see +Arc +: +: +downcast +has +no +particular +reason +to +/ +/ +require +that +T +be +Sync +and +Send +; +the +steps +used +here +are +sound +. +if +( +self +. +0 +) +. +is +: +: +< +HalSurface +< +A +> +> +( +) +{ +/ +/ +Turn +the +Arc +which +is +a +pointer +to +an +ArcInner +struct +into +/ +/ +a +pointer +to +the +ArcInner +' +s +data +field +. +Carry +along +the +/ +/ +vtable +from +the +original +Arc +. +let +raw_erased +: +* +const +( +dyn +Any ++ +' +static +) += +Arc +: +: +into_raw +( +self +. +0 +) +; +/ +/ +Remove +the +vtable +and +supply +the +concrete +type +of +the +data +. +let +raw_typed +: +* +const +HalSurface +< +A +> += +raw_erased +. +cast +: +: +< +HalSurface +< +A +> +> +( +) +; +/ +/ +Convert +the +pointer +to +the +data +field +back +into +a +pointer +to +/ +/ +the +ArcInner +and +restore +reference +- +counting +behavior +. +let +arc_typed +: +Arc +< +HalSurface +< +A +> +> += +unsafe +{ +/ +/ +Safety +: +/ +/ +- +We +checked +that +the +dyn +Any +was +indeed +a +HalSurface +< +A +> +above +. +/ +/ +- +We +' +re +calling +Arc +: +: +from_raw +on +the +same +pointer +returned +/ +/ +by +Arc +: +: +into_raw +except +that +we +stripped +off +the +vtable +/ +/ +pointer +. +/ +/ +- +The +pointer +must +still +be +live +because +we +' +ve +borrowed +self +/ +/ +which +holds +another +reference +to +it +. +/ +/ +- +The +format +of +a +ArcInner +< +dyn +Any +> +must +be +the +same +as +/ +/ +that +of +an +ArcInner +< +HalSurface +< +A +> +> +or +else +AnyHalSurface +: +: +new +/ +/ +wouldn +' +t +be +possible +. +Arc +: +: +from_raw +( +raw_typed +) +} +; +Some +( +arc_typed +) +} +else +{ +None +} +} +} +impl +fmt +: +: +Debug +for +AnySurface +{ +fn +fmt +( +& +self +f +: +& +mut +fmt +: +: +Formatter +< +' +_ +> +) +- +> +fmt +: +: +Result +{ +f +. +write_str +( +" +AnySurface +" +) +} +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +Send +for +AnySurface +{ +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +Sync +for +AnySurface +{ +} diff --git a/third_party/rust/wgpu-core/src/binding_model.rs b/third_party/rust/wgpu-core/src/binding_model.rs index e4c3d308a8d8f..36764080c0fd8 100644 --- a/third_party/rust/wgpu-core/src/binding_model.rs +++ b/third_party/rust/wgpu-core/src/binding_model.rs @@ -7,6 +7,7 @@ device : : { +Device DeviceError MissingDownlevelFlags MissingFeatures @@ -27,13 +28,13 @@ id : : { +BindGroupId BindGroupLayoutId BufferId -DeviceId +PipelineLayoutId SamplerId TextureId TextureViewId -Valid } init_tracker : @@ -45,7 +46,11 @@ TextureInitTrackerAction resource : : +{ Resource +ResourceInfo +ResourceType +} track : : @@ -62,9 +67,6 @@ MissingTextureUsageError } FastHashMap Label -LifeGuard -MultiRefCount -Stored } ; use @@ -73,6 +75,12 @@ arrayvec : ArrayVec ; +use +parking_lot +: +: +RwLock +; # [ cfg @@ -120,6 +128,10 @@ ops : : Range +sync +: +: +Arc } ; use @@ -3126,167 +3138,48 @@ pipelines with implicit layouts +# +[ +derive +( +Debug +) +] pub struct BindGroupLayout < A : -hal -: -: -Api +HalApi > { pub ( crate ) -device_id +raw : -Stored +Option < -DeviceId -> -pub -( -crate -) -multi_ref_count +A : -MultiRefCount -/ -/ -When -a -layout -created -and -there -already -exists -a -compatible -layout -the -new -layout -/ -/ -keeps -a -reference -to -the -older -compatible -one -. -In -some -places -we -substitute -the -/ -/ -bind -group -layout -id -with -its -compatible -sibling -. -/ -/ -Since -this -substitution -can -come -at -a -cost -it -is -skipped -when -wgpu -- -core -generates -/ -/ -its -own -resource -IDs -. -pub -( -crate -) -inner : -BglOrDuplicate -< -A +BindGroupLayout > -} pub ( crate ) -enum -BglOrDuplicate -< -A -: -hal -: +device : -Api -> -{ -Inner -( -BindGroupLayoutInner -< -A -> -) -Duplicate -( -Valid +Arc < -BindGroupLayoutId -> -) -} -pub -struct -BindGroupLayoutInner +Device < A -: -hal -: -: -Api > -{ -pub -( -crate -) -raw -: -A -: -: -BindGroupLayout +> pub ( crate @@ -3315,6 +3208,16 @@ crate count_validator : BindingTypeMaxCountValidator +pub +( +crate +) +info +: +ResourceInfo +< +BindGroupLayoutId +> # [ cfg @@ -3334,243 +3237,151 @@ impl < A : -hal -: -: -Api +HalApi > +Drop +for BindGroupLayout < A > { -# -[ -track_caller -] -pub -( -crate -) fn -assume_deduplicated +drop ( & +mut self ) -- -> -& -BindGroupLayoutInner -< -A -> { +log +: +: +info +! +( +" +Destroying +BindGroupLayout +{ +: +? +} +" self . -as_inner -( -) +info . -unwrap +label ( ) -} -pub -( -crate ) -fn -as_inner +; +if +let +Some ( -& -self +raw ) -- -> -Option -< -& -BindGroupLayoutInner -< -A -> -> -{ -match += self . -inner +raw +. +take +( +) { -BglOrDuplicate +unsafe +{ +use +hal : : -Inner +Device +; +self +. +device +. +raw ( -ref -inner ) -= -> -Some +. +destroy_bind_group_layout ( -inner +raw ) -BglOrDuplicate +; +} +} +} +} +impl +< +A : +HalApi +> +Resource +< +BindGroupLayoutId +> +for +BindGroupLayout +< +A +> +{ +const +TYPE : -Duplicate -( -_ -) +ResourceType = -> -None -} -} -pub -( -crate -) +" +BindGroupLayout +" +; fn -into_inner +as_info ( +& self ) - > -Option -< -BindGroupLayoutInner +& +ResourceInfo < -A -> +BindGroupLayoutId > { -match +& self . -inner -{ -BglOrDuplicate -: -: -Inner -( -inner -) -= -> -Some -( -inner -) -BglOrDuplicate -: -: -Duplicate -( -_ -) -= -> -None -} +info } -pub -( -crate -) fn -as_duplicate +as_info_mut ( & +mut self ) - > -Option -< -Valid +& +mut +ResourceInfo < BindGroupLayoutId > -> -{ -match -self -. -inner { -BglOrDuplicate -: -: -Duplicate -( -id -) -= -> -Some -( -id -) -BglOrDuplicate -: -: -Inner -( -_ -) -= -> -None -} -} -} -impl -< -A -: -hal -: -: -Api -> -Resource -for -BindGroupLayout -< -A -> -{ -const -TYPE -: -& -' -static -str -= -" -BindGroupLayout -" -; -fn -life_guard -( & +mut self -) -- -> -& -LifeGuard -{ -unreachable -! -( -) +. +info } fn label @@ -3580,8 +3391,7 @@ self ) - > -& -str +String { # [ @@ -3593,21 +3403,10 @@ debug_assertions return self . -as_inner -( -) +label . -map_or +clone ( -" -" -| -inner -| -& -inner -. -label ) ; # @@ -3621,181 +3420,57 @@ debug_assertions ) ] return -" -" +String +: +: +new +( +) ; } } -/ -/ -If -a -bindgroup -needs -to -be -substitued -with -its -compatible -equivalent -return -the -latter -. -pub -( -crate -) -fn -try_get_bind_group_layout +impl < A : HalApi > -( -layouts -: -& -BindGroupLayouts -< -A -> -id -: -BindGroupLayoutId -) -- -> -Option -< -& BindGroupLayout < A > -> { -let -layout -= -layouts -. -get -( -id -) -. -ok -( -) -? -; -if -let -BglOrDuplicate -: -: -Duplicate -( -original_id -) -= -layout -. -inner -{ -return -Some -( -& -layouts -[ -original_id -] -) -; -} -Some -( -layout -) -} pub ( crate ) fn -get_bind_group_layout -< -A -: -HalApi -> +raw ( -layouts -: & -BindGroupLayouts -< -A -> -id -: -Valid -< -BindGroupLayoutId -> +self ) - > -( -Valid -< -BindGroupLayoutId -> & -BindGroupLayout -< A -> -) +: +: +BindGroupLayout { -let -layout -= -& -layouts -[ -id -] -; -layout +self . -as_duplicate -( -) +raw . -map_or -( +as_ref ( -id -layout ) -| -deduped -| +. +unwrap ( -deduped -& -layouts -[ -deduped -] -) ) } +} # [ derive @@ -4712,10 +4387,7 @@ PipelineLayout < A : -hal -: -: -Api +HalApi > { pub @@ -4724,38 +4396,50 @@ crate ) raw : +Option +< A : : PipelineLayout +> pub ( crate ) -device_id +device : -Stored +Arc +< +Device < -DeviceId +A +> > pub ( crate ) -life_guard +info : -LifeGuard +ResourceInfo +< +PipelineLayoutId +> pub ( crate ) -bind_group_layout_ids +bind_group_layouts : ArrayVec < -Valid +Arc < -BindGroupLayoutId +BindGroupLayout +< +A +> > { hal @@ -4779,22 +4463,133 @@ PushConstantRange { SHADER_STAGE_COUNT } -> +> +} +impl +< +A +: +HalApi +> +Drop +for +PipelineLayout +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +PipelineLayout +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use +hal +: +: +Device +; +self +. +device +. +raw +( +) +. +destroy_pipeline_layout +( +raw +) +; +} +} +} } impl < A : -hal -: -: -Api +HalApi > PipelineLayout < A > { +pub +( +crate +) +fn +raw +( +& +self +) +- +> +& +A +: +: +PipelineLayout +{ +self +. +raw +. +as_ref +( +) +. +unwrap +( +) +} / / / @@ -5409,12 +5204,12 @@ impl < A : -hal -: -: -Api +HalApi > Resource +< +PipelineLayoutId +> for PipelineLayout < @@ -5424,30 +5219,52 @@ A const TYPE : -& -' -static -str +ResourceType = " PipelineLayout " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +PipelineLayoutId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +PipelineLayoutId +> { & +mut self . -life_guard +info } } # @@ -6156,6 +5973,13 @@ min_storage_buffer_offset_alignment ) } } +# +[ +derive +( +Debug +) +] pub struct BindGroup @@ -6171,37 +5995,49 @@ crate ) raw : +Option +< A : : BindGroup +> pub ( crate ) -device_id +device : -Stored +Arc +< +Device < -DeviceId +A +> > pub ( crate ) -layout_id +layout : -Valid +Arc < -BindGroupLayoutId +BindGroupLayout +< +A +> > pub ( crate ) -life_guard +info : -LifeGuard +ResourceInfo +< +BindGroupId +> pub ( crate @@ -6218,9 +6054,15 @@ crate ) used_buffer_ranges : +RwLock +< Vec < BufferInitTrackerAction +< +A +> +> > pub ( @@ -6228,9 +6070,15 @@ crate ) used_texture_ranges : +RwLock +< Vec < TextureInitTrackerAction +< +A +> +> > pub ( @@ -6238,10 +6086,13 @@ crate ) dynamic_binding_info : +RwLock +< Vec < BindGroupDynamicBindingData > +> / / / @@ -6294,6 +6145,90 @@ A : HalApi > +Drop +for +BindGroup +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +BindGroup +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use +hal +: +: +Device +; +self +. +device +. +raw +( +) +. +destroy_bind_group +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi +> BindGroup < A @@ -6304,6 +6239,36 @@ pub crate ) fn +raw +( +& +self +) +- +> +& +A +: +: +BindGroup +{ +self +. +raw +. +as_ref +( +) +. +unwrap +( +) +} +pub +( +crate +) +fn validate_dynamic_bindings ( & @@ -6342,6 +6307,10 @@ self . dynamic_binding_info . +read +( +) +. len ( ) @@ -6370,6 +6339,10 @@ self . dynamic_binding_info . +read +( +) +. len ( ) @@ -6398,6 +6371,10 @@ self . dynamic_binding_info . +read +( +) +. iter ( ) @@ -6536,6 +6513,9 @@ A HalApi > Resource +< +BindGroupId +> for BindGroup < @@ -6545,30 +6525,52 @@ A const TYPE : -& -' -static -str +ResourceType = " BindGroup " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +BindGroupId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +BindGroupId +> { & +mut self . -life_guard +info } } # diff --git a/third_party/rust/wgpu-core/src/command/bind.rs b/third_party/rust/wgpu-core/src/command/bind.rs index af2f57fcf0ab4..0a687b07d63a9 100644 --- a/third_party/rust/wgpu-core/src/command/bind.rs +++ b/third_party/rust/wgpu-core/src/command/bind.rs @@ -1,4 +1,13 @@ use +std +: +: +sync +: +: +Arc +; +use crate : : @@ -8,7 +17,6 @@ binding_model : { BindGroup -BindGroupLayouts LateMinBufferBindingSizeMismatch PipelineLayout } @@ -23,20 +31,15 @@ HalApi id : : -{ BindGroupId -PipelineLayoutId -Valid -} pipeline : : LateSizedBufferGroup -storage +resource : : -Storage -Stored +Resource } ; use @@ -54,6 +57,12 @@ mod compat { use +arrayvec +: +: +ArrayVec +; +use crate : : @@ -61,58 +70,102 @@ crate binding_model : : -BindGroupLayouts -id +BindGroupLayout +hal_api : : -{ -BindGroupLayoutId -Valid -} +HalApi +resource +: +: +Resource } ; use std : : +{ ops : : Range +sync +: +: +Arc +} ; # [ derive ( Debug -Default +Clone ) ] struct Entry +< +A +: +HalApi +> { assigned : Option < -Valid +Arc < -BindGroupLayoutId +BindGroupLayout +< +A +> > > expected : Option < -Valid +Arc +< +BindGroupLayout < -BindGroupLayoutId +A +> > > } impl +< +A +: +HalApi +> Entry +< +A +> +{ +fn +empty +( +) +- +> +Self +{ +Self { +assigned +: +None +expected +: +None +} +} fn is_active ( @@ -142,24 +195,9 @@ is_some } fn is_valid -< -A -: -hal -: -: -Api -> ( & self -bind_group_layouts -: -& -BindGroupLayouts -< -A -> ) - > @@ -173,16 +211,6 @@ expected is_none ( ) -| -| -self -. -expected -= -= -self -. -assigned { return true @@ -192,37 +220,81 @@ if let Some ( -id +expected_bgl ) = self . -assigned -{ -return -bind_group_layouts -[ -id -] +expected . -as_duplicate +as_ref ( ) -= +{ +if +let +Some +( +assigned_bgl +) = self . -expected +assigned +. +as_ref +( +) +{ +if +expected_bgl +. +is_equal +( +assigned_bgl +) +{ +return +true ; } +} +} false } +fn +is_incompatible +( +& +self +) +- +> +bool +{ +self +. +expected +. +is_none +( +) +| +| +! +self +. +is_valid +( +) +} } # [ derive ( Debug +Default ) ] pub @@ -231,20 +303,38 @@ crate ) struct BoundBindGroupLayouts +< +A +: +HalApi +> { entries : -[ +ArrayVec +< Entry -; +< +A +> +{ hal : : MAX_BIND_GROUPS -] +} +> } impl +< +A +: +HalApi +> BoundBindGroupLayouts +< +A +> { pub fn @@ -259,10 +349,30 @@ Self { entries : -Default +( +0 +. +. +hal : : -default +MAX_BIND_GROUPS +) +. +map +( +| +_ +| +Entry +: +: +empty +( +) +) +. +collect ( ) } @@ -307,21 +417,9 @@ e | e . -expected -. -is_none +is_incompatible ( ) -| -| -e -. -assigned -! -= -e -. -expected ) . unwrap_or @@ -356,9 +454,12 @@ expectations : & [ -Valid +Arc < -BindGroupLayoutId +BindGroupLayout +< +A +> > ] ) @@ -390,19 +491,37 @@ position | ( e -& expect ) | +{ e . expected +. +is_none +( +) +| +| ! -= -Some +e +. +expected +. +as_ref +( +) +. +unwrap +( +) +. +is_equal ( expect ) +} ) . unwrap_or @@ -417,7 +536,6 @@ len for ( e -& expect ) in @@ -455,6 +573,10 @@ expected Some ( expect +. +clone +( +) ) ; } @@ -504,9 +626,12 @@ index usize value : -Valid +Arc < -BindGroupLayoutId +BindGroupLayout +< +A +> > ) - @@ -588,428 +713,71 @@ Some ( i ) -} -else -{ -None -} -) -} -pub -fn -invalid_mask -< -A -: -hal -: -: -Api -> -( -& -self -bind_group_layouts -: -& -BindGroupLayouts -< -A -> -) -- -> -super -: -: -BindGroupMask -{ -self -. -entries -. -iter -( -) -. -enumerate -( -) -. -fold -( -0 -| -mask -( -i -entry -) -| -{ -if -entry -. -is_valid -( -bind_group_layouts -) -{ -mask -} -else -{ -mask -| -1u8 -< -< -i -} -} -) -} -} -# -[ -test -] -fn -test_compatibility -( -) -{ -fn -id -( -val -: -u32 -) -- -> -Valid -< -BindGroupLayoutId -> -{ -BindGroupLayoutId -: -: -dummy -( -val -) -} -let -mut -man -= -BoundBindGroupLayouts -: -: -new -( -) -; -man -. -entries -[ -0 -] -= -Entry -{ -expected -: -Some -( -id -( -3 -) -) -assigned -: -Some -( -id -( -2 -) -) -} -; -man -. -entries -[ -1 -] -= -Entry -{ -expected -: -Some -( -id -( -1 -) -) -assigned -: -Some -( -id -( -1 -) -) -} -; -man -. -entries -[ -2 -] -= -Entry -{ -expected -: -Some -( -id -( -4 -) -) -assigned -: -Some -( -id -( -5 -) -) -} -; -/ -/ -check -that -we -rebind -[ -1 -] -after -[ -0 -] -became -compatible -assert_eq -! -( -man -. -assign -( -0 -id -( -3 -) -) -0 -. -. -2 -) -; -/ -/ -check -that -nothing -is -rebound -assert_eq -! -( -man -. -update_expectations -( -& -[ -id -( -3 -) -id -( -2 -) -] -) -1 -. -. -1 -) -; -/ -/ -check -that -[ -1 -] -and -[ -2 -] -are -rebound -on -expectations -change -assert_eq -! -( -man -. -update_expectations -( -& -[ -id -( -3 -) -id -( -1 -) -id -( -5 -) -] -) -1 -. -. -3 -) -; -/ -/ -reset -the -first -two -bindings -assert_eq -! -( -man -. -update_expectations -( -& -[ -id -( -4 -) -id -( -6 -) -id -( -5 -) -] -) -0 -. -. -0 -) -; -/ -/ -check -that -nothing -is -rebound -even -if -there -is -a -match -/ -/ -since -earlier -binding -is -incompatible -. -assert_eq -! -( -man -. -assign -( -1 -id -( -6 +} +else +{ +None +} ) +} +pub +fn +invalid_mask +( +& +self ) -1 +- +> +super +: +: +BindGroupMask +{ +self . +entries . -1 +iter +( ) -; -/ -/ -finally -bind -everything -assert_eq -! +. +enumerate ( -man +) . -assign +fold ( 0 -id +| +mask ( -4 -) +i +entry ) -0 -. +| +{ +if +entry . -3 +is_valid +( ) -; +{ +mask +} +else +{ +mask +| +1u8 +< +< +i +} +} +) +} } } # @@ -1040,7 +808,6 @@ BufferAddress derive ( Debug -Default ) ] pub @@ -1049,18 +816,26 @@ super ) struct EntryPayload +< +A +: +HalApi +> { pub ( super ) -group_id +group : Option < -Stored +Arc < -BindGroupId +BindGroup +< +A +> > > pub @@ -1119,7 +894,68 @@ late_bindings_effective_count usize } impl +< +A +: +HalApi +> +Default +for +EntryPayload +< +A +> +{ +fn +default +( +) +- +> +Self +{ +Self +{ +group +: +None +dynamic_offsets +: +Default +: +: +default +( +) +late_buffer_bindings +: +Default +: +: +default +( +) +late_bindings_effective_count +: +Default +: +: +default +( +) +} +} +} +impl +< +A +: +HalApi +> EntryPayload +< +A +> { fn reset @@ -1131,7 +967,7 @@ self { self . -group_id +group = None ; @@ -1164,6 +1000,7 @@ late_bindings_effective_count derive ( Debug +Default ) ] pub @@ -1172,36 +1009,44 @@ super ) struct Binder +< +A +: +HalApi +> { pub ( super ) -pipeline_layout_id +pipeline_layout : Option < -Valid +Arc +< +PipelineLayout < -PipelineLayoutId +A +> > > -/ -/ -TODO -: -strongly -Stored manager : compat : : BoundBindGroupLayouts +< +A +> payloads : [ EntryPayload +< +A +> ; hal : @@ -1210,7 +1055,15 @@ MAX_BIND_GROUPS ] } impl +< +A +: +HalApi +> Binder +< +A +> { pub ( @@ -1226,7 +1079,7 @@ Self { Self { -pipeline_layout_id +pipeline_layout : None manager @@ -1264,7 +1117,7 @@ self { self . -pipeline_layout_id +pipeline_layout = None ; @@ -1310,9 +1163,6 @@ change_pipeline_layout < ' a -A -: -HalApi > ( & @@ -1320,22 +1170,15 @@ HalApi a mut self -guard +new : & -Storage +Arc < PipelineLayout < A > -PipelineLayoutId -> -new_id -: -Valid -< -PipelineLayoutId > late_sized_buffer_groups : @@ -1353,6 +1196,9 @@ usize a [ EntryPayload +< +A +> ] ) { @@ -1361,21 +1207,16 @@ old_id_opt = self . -pipeline_layout_id +pipeline_layout . replace ( -new_id -) -; -let new -= -& -guard -[ -new_id -] +. +clone +( +) +) ; let mut @@ -1390,7 +1231,7 @@ update_expectations & new . -bind_group_layout_ids +bind_group_layouts ) ; / @@ -1532,20 +1373,11 @@ if let Some ( -old_id +old ) = old_id_opt { -let -old -= -& -guard -[ -old_id -] -; / / root @@ -1595,9 +1427,6 @@ assign_group < ' a -A -: -HalApi > ( & @@ -1608,19 +1437,16 @@ self index : usize -bind_group_id -: -Valid -< -BindGroupId -> bind_group : & +Arc +< BindGroup < A > +> offsets : & @@ -1638,8 +1464,24 @@ DynamicOffset a [ EntryPayload +< +A +> ] { +let +bind_group_id += +bind_group +. +as_info +( +) +. +id +( +) +; log : : @@ -1673,8 +1515,6 @@ A VARIANT bind_group_id . -0 -. backend ( ) @@ -1694,25 +1534,15 @@ index ; payload . -group_id +group = Some ( -Stored -{ -value -: -bind_group_id -ref_count -: bind_group . -life_guard -. -add_ref +clone ( ) -} ) ; payload @@ -1862,7 +1692,11 @@ assign index bind_group . -layout_id +layout +. +clone +( +) ) ; & @@ -1890,11 +1724,8 @@ Iterator < Item = -Valid -< BindGroupId > -> + ' _ @@ -1926,7 +1757,7 @@ payloads index ] . -group_id +group . as_ref ( @@ -1936,7 +1767,13 @@ unwrap ( ) . -value +as_info +( +) +. +id +( +) ) } pub @@ -1945,24 +1782,9 @@ super ) fn invalid_mask -< -A -: -hal -: -: -Api -> ( & self -bind_group_layouts -: -& -BindGroupLayouts -< -A -> ) - > @@ -1974,7 +1796,6 @@ manager . invalid_mask ( -bind_group_layouts ) } / diff --git a/third_party/rust/wgpu-core/src/command/bundle.rs b/third_party/rust/wgpu-core/src/command/bundle.rs index d32d8ceb80dc6..54e5f38c11511 100644 --- a/third_party/rust/wgpu-core/src/command/bundle.rs +++ b/third_party/rust/wgpu-core/src/command/bundle.rs @@ -688,8 +688,10 @@ binding_model : : { -self buffer_binding_type_alignment +BindGroup +BindGroupLayout +PipelineLayout } command : @@ -732,15 +734,14 @@ HalApi hub : : -{ Hub -Token -} id -identity : : -GlobalIdentityHandlerFactory +{ +self +RenderBundleId +} init_tracker : : @@ -755,18 +756,16 @@ pipeline { self PipelineFlags +RenderPipeline } resource : : { -self Resource +ResourceInfo +ResourceType } -storage -: -: -Storage track : : @@ -777,8 +776,6 @@ validation check_buffer_usage Label LabelHelpers -LifeGuard -Stored } ; use @@ -805,6 +802,10 @@ ops : : Range +sync +: +: +Arc } ; use @@ -1874,9 +1875,6 @@ finish A : HalApi -G -: -GlobalIdentityHandlerFactory > ( self @@ -1887,28 +1885,19 @@ RenderBundleDescriptor device : & +Arc +< Device < A > +> hub : & Hub < A -G -> -token -: -& -mut -Token -< -Device -< -A -> > ) - @@ -1923,27 +1912,7 @@ RenderBundleError > { let -( -pipeline_layout_guard -mut -token -) -= -hub -. -pipeline_layouts -. -read -( -token -) -; -let -( bind_group_guard -mut -token -) = hub . @@ -1951,17 +1920,10 @@ bind_groups . read ( -& -mut -token ) ; let -( pipeline_guard -mut -token -) = hub . @@ -1969,17 +1931,10 @@ render_pipelines . read ( -& -mut -token ) ; let -( query_set_guard -mut -token -) = hub . @@ -1987,17 +1942,10 @@ query_sets . read ( -& -mut -token ) ; let -( buffer_guard -mut -token -) = hub . @@ -2005,16 +1953,10 @@ buffers . read ( -& -mut -token ) ; let -( texture_guard -_ -) = hub . @@ -2022,9 +1964,6 @@ textures . read ( -& -mut -token ) ; let @@ -2204,15 +2143,6 @@ bind_group_id ; let bind_group -: -& -binding_model -: -: -BindGroup -< -A -> = state . @@ -2220,6 +2150,10 @@ trackers . bind_groups . +write +( +) +. add_single ( & @@ -2251,9 +2185,13 @@ check_valid_to_use ( bind_group . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -2353,6 +2291,10 @@ bind_group . dynamic_binding_info . +read +( +) +. len ( ) @@ -2385,6 +2327,10 @@ bind_group . dynamic_binding_info . +read +( +) +. len ( ) @@ -2436,6 +2382,10 @@ bind_group . dynamic_binding_info . +read +( +) +. iter ( ) @@ -2497,6 +2447,10 @@ extend_from_slice bind_group . used_buffer_ranges +. +read +( +) ) ; texture_memory_init_actions @@ -2507,6 +2461,10 @@ extend_from_slice bind_group . used_texture_ranges +. +read +( +) ) ; state @@ -2514,10 +2472,24 @@ state set_bind_group ( index +bind_group_guard +. +get +( bind_group_id +) +. +as_ref +( +) +. +unwrap +( +) +& bind_group . -layout_id +layout offsets_range ) ; @@ -2530,9 +2502,6 @@ trackers merge_bind_group ( & -* -texture_guard -& bind_group . used @@ -2592,15 +2561,6 @@ pipeline_id ; let pipeline -: -& -pipeline -: -: -RenderPipeline -< -A -> = state . @@ -2608,6 +2568,10 @@ trackers . render_pipelines . +write +( +) +. add_single ( & @@ -2639,9 +2603,13 @@ check_valid_to_use ( pipeline . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -2736,19 +2704,6 @@ scope ; } let -layout -= -& -pipeline_layout_guard -[ -pipeline -. -layout_id -. -value -] -; -let pipeline_state = PipelineState @@ -2756,9 +2711,7 @@ PipelineState : new ( -pipeline_id pipeline -layout ) ; commands @@ -2807,6 +2760,9 @@ invalidate_bind_groups ( & pipeline_state +& +pipeline +. layout ) ; @@ -2846,15 +2802,6 @@ buffer_id ; let buffer -: -& -resource -: -: -Buffer -< -A -> = state . @@ -2862,6 +2809,10 @@ trackers . buffers . +write +( +) +. merge_single ( & @@ -2889,9 +2840,13 @@ check_valid_to_use ( buffer . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -2955,9 +2910,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -3008,15 +2967,6 @@ buffer_id ; let buffer -: -& -resource -: -: -Buffer -< -A -> = state . @@ -3024,6 +2974,10 @@ trackers . buffers . +write +( +) +. merge_single ( & @@ -3051,9 +3005,13 @@ check_valid_to_use ( buffer . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -3117,9 +3075,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -3187,7 +3149,7 @@ offset size_bytes ; let -pipeline +pipeline_state = state . @@ -3197,18 +3159,11 @@ scope ) ? ; -let -pipeline_layout -= -& -pipeline_layout_guard -[ +pipeline_state +. pipeline . -layout_id -] -; -pipeline_layout +layout . validate_push_constant_ranges ( @@ -3736,15 +3691,6 @@ used_bind_groups ; let buffer -: -& -resource -: -: -Buffer -< -A -> = state . @@ -3752,6 +3698,10 @@ trackers . buffers . +write +( +) +. merge_single ( & @@ -3779,9 +3729,13 @@ check_valid_to_use ( buffer . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -3818,9 +3772,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -3964,15 +3922,6 @@ used_bind_groups ; let buffer -: -& -resource -: -: -Buffer -< -A -> = state . @@ -3980,6 +3929,10 @@ trackers . buffers . +write +( +) +. merge_single ( & @@ -4007,9 +3960,13 @@ check_valid_to_use ( buffer . -device_id +device . -value +info +. +id +( +) ) . map_pass_err @@ -4046,9 +4003,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -4395,31 +4356,13 @@ is_stencil_read_only self . is_stencil_read_only -device_id -: -Stored -{ -value -: -id -: -: -Valid -( -self -. -parent_id -) -ref_count +device : device . -life_guard -. -add_ref +clone ( ) -} used : state @@ -4432,9 +4375,9 @@ context self . context -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -4476,13 +4419,7 @@ device_id id : : -Valid -< -id -: -: DeviceId -> ) - > @@ -4495,8 +4432,6 @@ RenderBundleErrorInner { if device_id -. -0 ! = self @@ -4854,6 +4789,13 @@ indirect command buffer . +# +[ +derive +( +Debug +) +] pub struct RenderBundle @@ -4910,14 +4852,14 @@ pub ( crate ) -device_id +device : -Stored +Arc < -id -: -: -DeviceId +Device +< +A +> > pub ( @@ -4938,6 +4880,9 @@ buffer_memory_init_actions Vec < BufferInitTrackerAction +< +A +> > pub ( @@ -4948,6 +4893,9 @@ texture_memory_init_actions Vec < TextureInitTrackerAction +< +A +> > pub ( @@ -4960,9 +4908,12 @@ pub ( crate ) -life_guard +info : -LifeGuard +ResourceInfo +< +RenderBundleId +> discard_hal_labels : bool @@ -5219,86 +5170,6 @@ A : : CommandEncoder -pipeline_layout_guard -: -& -Storage -< -crate -: -: -binding_model -: -: -PipelineLayout -< -A -> -id -: -: -PipelineLayoutId -> -bind_group_guard -: -& -Storage -< -crate -: -: -binding_model -: -: -BindGroup -< -A -> -id -: -: -BindGroupId -> -pipeline_guard -: -& -Storage -< -crate -: -: -pipeline -: -: -RenderPipeline -< -A -> -id -: -: -RenderPipelineId -> -buffer_guard -: -& -Storage -< -crate -: -: -resource -: -: -Buffer -< -A -> -id -: -: -BufferId -> ) - > @@ -5310,6 +5181,14 @@ ExecutionError > { let +trackers += +& +self +. +used +; +let mut offsets = @@ -5325,21 +5204,18 @@ as_slice ; let mut -pipeline_layout_id +pipeline_layout = None : : < -id -: -: -Valid +Arc < -id -: -: -PipelineLayoutId +PipelineLayout +< +A +> > > ; @@ -5405,9 +5281,20 @@ bind_group_id > { let +bind_groups += +trackers +. +bind_groups +. +read +( +) +; +let bind_group = -bind_group_guard +bind_groups . get ( @@ -5424,22 +5311,25 @@ raw . set_bind_group ( -& -pipeline_layout_guard -[ -pipeline_layout_id +pipeline_layout +. +as_ref +( +) . unwrap ( ) -] . raw +( +) index -& bind_group . raw +( +) & offsets [ @@ -5476,9 +5366,20 @@ pipeline_id > { let +render_pipelines += +trackers +. +render_pipelines +. +read +( +) +; +let pipeline = -pipeline_guard +render_pipelines . get ( @@ -5495,22 +5396,25 @@ raw . set_render_pipeline ( -& pipeline . raw +( +) ) } ; -pipeline_layout_id +pipeline_layout = Some ( pipeline . -layout_id +layout . -value +clone +( +) ) ; } @@ -5528,9 +5432,20 @@ size > { let +buffers += +trackers +. +buffers +. +read +( +) +; +let buffer = -buffer_guard +buffers . get ( @@ -5542,22 +5457,8 @@ unwrap ) . raw -. -as_ref -( -) -. -ok_or -( -ExecutionError -: -: -DestroyedBuffer ( -buffer_id -) ) -? ; let bb @@ -5598,9 +5499,20 @@ size > { let +buffers += +trackers +. +buffers +. +read +( +) +; +let buffer = -buffer_guard +buffers . get ( @@ -5612,22 +5524,8 @@ unwrap ) . raw -. -as_ref ( ) -. -ok_or -( -ExecutionError -: -: -DestroyedBuffer -( -buffer_id -) -) -? ; let bb @@ -5668,23 +5566,18 @@ values_offset > { let -pipeline_layout_id +pipeline_layout = -pipeline_layout_id +pipeline_layout +. +as_ref +( +) . unwrap ( ) ; -let -pipeline_layout -= -& -pipeline_layout_guard -[ -pipeline_layout_id -] -; if let Some @@ -5736,10 +5629,11 @@ raw . set_push_constants ( -& pipeline_layout . raw +( +) stages offset data_slice @@ -5766,10 +5660,11 @@ raw . set_push_constants ( -& pipeline_layout . raw +( +) stages clear_offset clear_data @@ -5855,9 +5750,20 @@ false > { let +buffers += +trackers +. +buffers +. +read +( +) +; +let buffer = -buffer_guard +buffers . get ( @@ -5869,22 +5775,8 @@ unwrap ) . raw -. -as_ref ( ) -. -ok_or -( -ExecutionError -: -: -DestroyedBuffer -( -buffer_id -) -) -? ; unsafe { @@ -5917,9 +5809,20 @@ true > { let +buffers += +trackers +. +buffers +. +read +( +) +; +let buffer = -buffer_guard +buffers . get ( @@ -5931,22 +5834,8 @@ unwrap ) . raw -. -as_ref -( -) -. -ok_or -( -ExecutionError -: -: -DestroyedBuffer ( -buffer_id -) ) -? ; unsafe { @@ -6185,6 +6074,9 @@ A HalApi > Resource +< +RenderBundleId +> for RenderBundle < @@ -6194,30 +6086,52 @@ A const TYPE : -& -' -static -str +ResourceType = " RenderBundle " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +RenderBundleId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +RenderBundleId +> { & +mut self . -life_guard +info } } / @@ -6816,6 +6730,11 @@ Debug ] struct BindState +< +A +: +HalApi +> { / / @@ -6831,12 +6750,15 @@ at this index . -bind_group_id -: -id -: +bind_group : -BindGroupId +Arc +< +BindGroup +< +A +> +> / / / @@ -6845,17 +6767,14 @@ layout of group . -layout_id -: -id -: +layout : -Valid +Arc < -id -: -: -BindGroupLayoutId +BindGroupLayout +< +A +> > / / @@ -7015,45 +6934,25 @@ validation . struct PipelineState +< +A +: +HalApi +> { / / / The pipeline -' -s -id -. -id -: -id -: -: -RenderPipelineId -/ -/ -/ -The -id -of -the pipeline -' -s -layout -. -layout_id -: -id -: : -Valid +Arc < -id -: -: -PipelineLayoutId +RenderPipeline +< +A +> > / / @@ -7136,41 +7035,28 @@ used_bind_groups usize } impl -PipelineState -{ -fn -new < A : HalApi > +PipelineState +< +A +> +{ +fn +new ( -pipeline_id -: -id -: -: -RenderPipelineId pipeline : & -pipeline -: -: +Arc +< RenderPipeline < A > -layout -: -& -binding_model -: -: -PipelineLayout -< -A > ) - @@ -7179,16 +7065,13 @@ Self { Self { -id -: -pipeline_id -layout_id +pipeline : pipeline . -layout_id -. -value +clone +( +) steps : pipeline @@ -7200,6 +7083,8 @@ to_vec ) push_constant_ranges : +pipeline +. layout . push_constant_ranges @@ -7217,9 +7102,11 @@ collect ) used_bind_groups : +pipeline +. layout . -bind_group_layout_ids +bind_group_layouts . len ( @@ -7511,6 +7398,9 @@ pipeline Option < PipelineState +< +A +> > / / @@ -7532,6 +7422,9 @@ ArrayVec Option < BindState +< +A +> > { hal @@ -7684,6 +7577,9 @@ pipeline : & PipelineState +< +A +> ) - > @@ -7900,7 +7796,15 @@ p | p . +pipeline +. +as_info +( +) +. id +( +) ) } / @@ -7935,6 +7839,9 @@ Result < & PipelineState +< +A +> RenderBundleError > { @@ -8025,23 +7932,25 @@ self slot : u32 -bind_group_id -: -id -: -: -BindGroupId -layout_id -: -id -: +bind_group : -Valid +& +Arc < -id -: +BindGroup +< +A +> +> +layout : -BindGroupLayoutId +& +Arc +< +BindGroupLayout +< +A +> > dynamic_offsets : @@ -8116,10 +8025,12 @@ usize if contents . -bind_group_id -= -= -bind_group_id +bind_group +. +is_equal +( +bind_group +) { return ; @@ -8149,8 +8060,20 @@ Some ( BindState { -bind_group_id -layout_id +bind_group +: +bind_group +. +clone +( +) +layout +: +layout +. +clone +( +) dynamic_offsets is_dirty : @@ -8342,12 +8265,12 @@ new : & PipelineState +< +A +> layout : & -binding_model -: -: PipelineLayout < A @@ -8390,12 +8313,15 @@ old if old . -id -= -= +pipeline +. +is_equal +( +& new . -id +pipeline +) { / / @@ -8473,7 +8399,7 @@ zip & layout . -bind_group_layout_ids +bind_group_layouts ) . position @@ -8481,8 +8407,7 @@ position | ( entry -& -layout_id +layout ) | match @@ -8496,12 +8421,15 @@ contents ) = > +! contents . -layout_id -! -= -layout_id +layout +. +is_equal +( +layout +) None = > @@ -8964,7 +8892,15 @@ bind_group_id : contents . -bind_group_id +bind_group +. +as_info +( +) +. +id +( +) num_dynamic_offsets : ( diff --git a/third_party/rust/wgpu-core/src/command/clear.rs b/third_party/rust/wgpu-core/src/command/clear.rs index 9569d11928aab..9001983f0c290 100644 --- a/third_party/rust/wgpu-core/src/command/clear.rs +++ b/third_party/rust/wgpu-core/src/command/clear.rs @@ -2,10 +2,16 @@ use std : : +{ ops : : Range +sync +: +: +Arc +} ; # [ @@ -50,10 +56,6 @@ hal_api : : HalApi -hub -: -: -Token id : : @@ -62,7 +64,6 @@ BufferId CommandEncoderId DeviceId TextureId -Valid } identity : @@ -79,10 +80,10 @@ resource : : { +Resource Texture TextureClearMode } -storage track : : @@ -666,47 +667,14 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -let cmd_buf = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub command_encoder_id ) . @@ -726,20 +694,28 @@ command_encoder_id ? ; let +mut +cmd_buf_data += +cmd_buf +. +data +. +lock ( -buffer_guard -_ ) +; +let +cmd_buf_data = -hub +cmd_buf_data . -buffers +as_mut +( +) . -read +unwrap ( -& -mut -token ) ; # @@ -762,7 +738,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -788,7 +764,44 @@ dst_buffer dst_pending ) = -cmd_buf +{ +let +buffer_guard += +hub +. +buffers +. +read +( +) +; +let +dst_buffer += +buffer_guard +. +get +( +dst +) +. +map_err +( +| +_ +| +ClearError +: +: +InvalidBuffer +( +dst +) +) +? +; +cmd_buf_data . trackers . @@ -796,10 +809,7 @@ buffers . set_single ( -& -* -buffer_guard -dst +dst_buffer hal : : @@ -820,6 +830,7 @@ dst ) ) ? +} ; let dst_raw @@ -1051,7 +1062,7 @@ dest as initialized . -cmd_buf +cmd_buf_data . buffer_memory_init_actions . @@ -1061,9 +1072,14 @@ dst_buffer . initialization_status . +read +( +) +. create_action ( -dst +& +dst_buffer offset . . @@ -1096,6 +1112,7 @@ pending . into_hal ( +& dst_buffer ) ) @@ -1103,7 +1120,7 @@ dst_buffer let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . @@ -1218,65 +1235,14 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -let cmd_buf = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub command_encoder_id ) . @@ -1296,42 +1262,28 @@ command_encoder_id ? ; let -( -_ mut -token -) +cmd_buf_data = -hub +cmd_buf . -buffers +data . -read +lock ( -& -mut -token ) ; -/ -/ -skip -token let -( -texture_guard -_ -) +cmd_buf_data = -hub +cmd_buf_data . -textures +as_mut +( +) . -read +unwrap ( -& -mut -token ) ; # @@ -1354,7 +1306,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -1395,7 +1347,9 @@ MissingClearTextureFeature let dst_texture = -texture_guard +hub +. +textures . get ( @@ -1651,14 +1605,9 @@ let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -1678,24 +1627,35 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) ) ; } -clear_texture +let ( -& -* -texture_guard -Valid +encoder +tracker +) += +cmd_buf_data +. +open_encoder_and_tracker ( -dst ) +; +clear_texture +( +& +dst_texture TextureInitRange { mip_range @@ -1705,28 +1665,27 @@ layer_range : subresource_layer_range } -cmd_buf -. encoder -. -open -( -) & mut -cmd_buf -. -trackers +tracker . textures & device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) } } @@ -1742,25 +1701,15 @@ A HalApi > ( -storage +dst_texture : & -storage -: -: -Storage +Arc < Texture < A > -TextureId -> -dst_texture_id -: -Valid -< -TextureId > range : @@ -1806,35 +1755,49 @@ ClearError > { let -dst_texture +dst_inner = -& -storage -[ -dst_texture_id -] +dst_texture +. +inner +( +) ; let dst_raw = -dst_texture +dst_inner . -inner +as_ref +( +) +. +unwrap +( +) . as_raw ( ) . -ok_or +ok_or_else ( +| +| ClearError : : InvalidTexture ( -dst_texture_id +dst_texture . -0 +as_info +( +) +. +id +( +) ) ) ? @@ -1850,9 +1813,14 @@ let clear_usage = match +* dst_texture . clear_mode +. +read +( +) { TextureClearMode : @@ -1890,6 +1858,15 @@ DEPTH_STENCIL_WRITE TextureClearMode : : +Surface +{ +. +. +} +| +TextureClearMode +: +: RenderPass { is_color @@ -1900,6 +1877,7 @@ true } = > +{ hal : : @@ -1907,6 +1885,7 @@ TextureUses : : COLOR_TARGET +} TextureClearMode : : @@ -1922,9 +1901,15 @@ ClearError : NoValidTextureClearMode ( -dst_texture_id +dst_texture . -0 +as_info +( +) +. +id +( +) ) ) ; @@ -2110,9 +2095,6 @@ texture_tracker set_single ( dst_texture -dst_texture_id -. -0 selector clear_usage ) @@ -2130,7 +2112,15 @@ pending . into_hal ( -dst_texture +dst_inner +. +as_ref +( +) +. +unwrap +( +) ) ) ; @@ -2154,9 +2144,14 @@ Record actual clearing match +* dst_texture . clear_mode +. +read +( +) { TextureClearMode : @@ -2184,6 +2179,26 @@ dst_raw TextureClearMode : : +Surface +{ +. +. +} += +> +{ +clear_texture_via_render_passes +( +dst_texture +range +true +encoder +) +? +} +TextureClearMode +: +: RenderPass { is_color @@ -2217,9 +2232,15 @@ ClearError : NoValidTextureClearMode ( -dst_texture_id +dst_texture . -0 +as_info +( +) +. +id +( +) ) ) ; @@ -2236,10 +2257,7 @@ clear_texture_via_buffer_copies < A : -hal -: -: -Api +HalApi > ( texture_desc @@ -2813,10 +2831,7 @@ clear_texture_via_render_passes < A : -hal -: -: -Api +HalApi > ( dst_texture @@ -2909,6 +2924,18 @@ time . } ; +let +clear_mode += +& +dst_texture +. +clear_mode +. +read +( +) +; for mip_level in @@ -2973,10 +3000,16 @@ Attachment { view : -dst_texture -. +Texture +: +: get_clear_view ( +clear_mode +& +dst_texture +. +desc mip_level depth_or_layer ) @@ -3051,10 +3084,16 @@ Attachment { view : -dst_texture -. +Texture +: +: get_clear_view ( +clear_mode +& +dst_texture +. +desc mip_level depth_or_layer ) diff --git a/third_party/rust/wgpu-core/src/command/compute.rs b/third_party/rust/wgpu-core/src/command/compute.rs index 104bb002d5242..8a80399a153d5 100644 --- a/third_party/rust/wgpu-core/src/command/compute.rs +++ b/third_party/rust/wgpu-core/src/command/compute.rs @@ -2,6 +2,15 @@ use crate : : +resource +: +: +Resource +; +use +crate +: +: { binding_model : @@ -9,7 +18,6 @@ binding_model { BindError BindGroup -BindGroupLayouts LateMinBufferBindingSizeMismatch PushConstantUploadError } @@ -63,10 +71,6 @@ hal_api : HalApi hal_label -hub -: -: -Token id id : @@ -86,8 +90,6 @@ resource : { self -Buffer -Texture } storage : @@ -1856,6 +1858,9 @@ HalApi binder : Binder +< +A +> pipeline : Option @@ -1891,13 +1896,6 @@ is_ready ( & self -bind_group_layouts -: -& -BindGroupLayouts -< -A -> ) - > @@ -1917,7 +1915,6 @@ binder . invalid_mask ( -bind_group_layouts ) ; if @@ -2059,34 +2056,6 @@ id : BindGroupId > -buffer_guard -: -& -Storage -< -Buffer -< -A -> -id -: -: -BufferId -> -texture_guard -: -& -Storage -< -Texture -< -A -> -id -: -: -TextureId -> indirect_buffer : Option @@ -2094,14 +2063,8 @@ Option id : : -Valid -< -id -: -: BufferId > -> ) - > @@ -2131,7 +2094,6 @@ scope . merge_bind_group ( -texture_guard & bind_group_guard [ @@ -2184,7 +2146,6 @@ base_trackers . set_and_remove_from_usage_scope_sparse ( -texture_guard & mut self @@ -2257,8 +2218,6 @@ drain_barriers ( raw_encoder base_trackers -buffer_guard -texture_guard ) ; Ok @@ -2428,105 +2387,14 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -/ -/ -Spell -out -the -type -to -placate -rust -- -analyzer -. -/ -/ -https -: -/ -/ -github -. -com -/ -rust -- -lang -/ -rust -- -analyzer -/ -issues -/ -12247 -let cmd_buf -: -& -mut -CommandBuffer -< -A -> = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub encoder_id ) . @@ -2536,106 +2404,13 @@ init_scope ) ? ; -/ -/ -We -automatically -keep -extending -command -buffers -over -time -and -because -/ -/ -we -want -to -insert -a -command -buffer -_before_ -what -we -' -re -about -to -record -/ -/ -we -need -to -make -sure -to -close -the -previous -one -. -cmd_buf -. -encoder -. -close -( -) -; -/ -/ -We -will -reset -this -to -Recording -if -we -succeed -acts -as -a -fail -- -safe -. -cmd_buf -. -status -= -CommandEncoderStatus -: -: -Error -; -let -raw -= -cmd_buf -. -encoder -. -open -( -) -; let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -2655,11 +2430,15 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) ) . @@ -2669,6 +2448,31 @@ init_scope ) ; } +let +mut +cmd_buf_data += +cmd_buf +. +data +. +lock +( +) +; +let +cmd_buf_data += +cmd_buf_data +. +as_mut +( +) +. +unwrap +( +) +; # [ cfg @@ -2689,7 +2493,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -2732,119 +2536,163 @@ cloned ; } let -( -_ -mut -token -) +encoder = -hub -. -render_bundles -. -read -( & mut -token -) +cmd_buf_data +. +encoder ; let -( -pipeline_layout_guard -mut -token -) +status = -hub -. -pipeline_layouts +& +mut +cmd_buf_data . -read -( +status +; +let +tracker += & mut -token -) +cmd_buf_data +. +trackers ; let -( -bind_group_guard +buffer_memory_init_actions += +& mut -token -) +cmd_buf_data +. +buffer_memory_init_actions +; +let +texture_memory_actions = -hub +& +mut +cmd_buf_data . -bind_groups +texture_memory_actions +; +/ +/ +We +automatically +keep +extending +command +buffers +over +time +and +because +/ +/ +we +want +to +insert +a +command +buffer +_before_ +what +we +' +re +about +to +record +/ +/ +we +need +to +make +sure +to +close +the +previous +one . -read +encoder +. +close ( -& -mut -token ) ; +/ +/ +will +be +reset +to +true +if +recording +is +done +without +errors +* +status += +CommandEncoderStatus +: +: +Error +; let +raw += +encoder +. +open ( -pipeline_guard -mut -token ) +; +let +bind_group_guard = hub . -compute_pipelines +bind_groups . read ( -& -mut -token ) ; let -( -query_set_guard -mut -token -) +pipeline_guard = hub . -query_sets +compute_pipelines . read ( -& -mut -token ) ; let -( -bind_group_layout_guard -mut -token -) +query_set_guard = hub . -bind_group_layouts +query_sets . read ( -& -mut -token ) ; let -( buffer_guard -mut -token -) = hub . @@ -2852,16 +2700,10 @@ buffers . read ( -& -mut -token ) ; let -( texture_guard -_ -) = hub . @@ -2869,9 +2711,6 @@ textures . read ( -& -mut -token ) ; let @@ -2963,9 +2802,7 @@ QuerySet A > = -cmd_buf -. -trackers +tracker . query_sets . @@ -3139,10 +2976,17 @@ raw . reset_queries ( -& query_set . raw +. +as_ref +( +) +. +unwrap +( +) range ) ; @@ -3157,10 +3001,17 @@ ComputePassTimestampWrites { query_set : -& query_set . raw +. +as_ref +( +) +. +unwrap +( +) beginning_of_pass_write_index : tw @@ -3179,9 +3030,7 @@ else None } ; -cmd_buf -. -trackers +tracker . set_size ( @@ -3431,16 +3280,8 @@ usize ; let bind_group -: -& -BindGroup -< -A -> = -cmd_buf -. -trackers +tracker . bind_groups . @@ -3488,8 +3329,6 @@ scope ) ? ; -cmd_buf -. buffer_memory_init_actions . extend @@ -3498,6 +3337,10 @@ bind_group . used_buffer_ranges . +read +( +) +. iter ( ) @@ -3507,37 +3350,21 @@ filter_map | action | -match -buffer_guard -. -get -( +{ action . -id -) -{ -Ok -( -buffer -) -= -> buffer . initialization_status . -check_action +read ( -action ) -Err +. +check_action ( -_ +action ) -= -> -None } ) ) @@ -3549,6 +3376,10 @@ bind_group . used_texture_ranges . +read +( +) +. iter ( ) @@ -3557,27 +3388,27 @@ pending_discard_init_fixups . extend ( -cmd_buf -. texture_memory_actions . register_init_action ( action -& -texture_guard ) ) ; } let -pipeline_layout_id +pipeline_layout = state . binder . -pipeline_layout_id +pipeline_layout +. +clone +( +) ; let entries @@ -3591,13 +3422,6 @@ assign_group index as usize -id -: -: -Valid -( -bind_group_id -) bind_group & temp_offsets @@ -3610,21 +3434,30 @@ entries is_empty ( ) +& +& +pipeline_layout +. +is_some +( +) { let pipeline_layout = -& -pipeline_layout_guard -[ -pipeline_layout_id +pipeline_layout +. +as_ref +( +) . unwrap ( ) -] . raw +( +) ; for ( @@ -3642,28 +3475,29 @@ enumerate ( ) { +if let -raw_bg +Some +( +group +) = -& -bind_group_guard -[ e . -group_id +group . as_ref ( ) +{ +let +raw_bg += +group . -unwrap +raw ( ) -. -value -] -. -raw ; unsafe { @@ -3688,6 +3522,7 @@ dynamic_offsets } } } +} ComputeCommand : : @@ -3730,9 +3565,7 @@ ComputePipeline A > = -cmd_buf -. -trackers +tracker . compute_pipelines . @@ -3767,10 +3600,11 @@ raw . set_compute_pipeline ( -& pipeline . raw +( +) ) ; } @@ -3783,31 +3617,36 @@ state . binder . -pipeline_layout_id -! -= -Some +pipeline_layout +. +is_none ( -pipeline +) +| +| +! +state . -layout_id +binder . -value -) -{ -let pipeline_layout -= +. +as_ref +( +) +. +unwrap +( +) +. +is_equal +( & -pipeline_layout_guard -[ pipeline . -layout_id -. -value -] -; +layout +) +{ let ( start_index @@ -3821,13 +3660,9 @@ binder change_pipeline_layout ( & -* -pipeline_layout_guard pipeline . -layout_id -. -value +layout & pipeline . @@ -3858,28 +3693,29 @@ enumerate ( ) { +if let -raw_bg +Some +( +group +) = -& -bind_group_guard -[ e . -group_id +group . as_ref ( ) +{ +let +raw_bg += +group . -unwrap +raw ( ) -. -value -] -. -raw ; unsafe { @@ -3887,10 +3723,13 @@ raw . set_bind_group ( -& -pipeline_layout +pipeline +. +layout . raw +( +) start_index as u32 @@ -3908,6 +3747,7 @@ dynamic_offsets } } } +} / / Clear @@ -3926,7 +3766,9 @@ bind compute_nonoverlapping_ranges ( & -pipeline_layout +pipeline +. +layout . push_constant_ranges ) @@ -3973,10 +3815,13 @@ raw . set_push_constants ( -& -pipeline_layout +pipeline +. +layout . raw +( +) wgt : : @@ -4056,13 +3901,17 @@ values_end_offset ] ; let -pipeline_layout_id +pipeline_layout = state . binder . -pipeline_layout_id +pipeline_layout +. +as_ref +( +) / / TODO @@ -4098,15 +3947,6 @@ scope ) ? ; -let -pipeline_layout -= -& -pipeline_layout_guard -[ -pipeline_layout_id -] -; pipeline_layout . validate_push_constant_ranges @@ -4134,10 +3974,11 @@ raw . set_push_constants ( -& pipeline_layout . raw +( +) wgt : : @@ -4183,9 +4024,6 @@ state . is_ready ( -& -* -bind_group_layout_guard ) . map_pass_err @@ -4205,12 +4043,6 @@ intermediate_trackers & * bind_group_guard -& -* -buffer_guard -& -* -texture_guard None ) . @@ -4326,9 +4158,6 @@ state . is_ready ( -& -* -bind_group_layout_guard ) . map_pass_err @@ -4358,12 +4187,6 @@ scope ; let indirect_buffer -: -& -Buffer -< -A -> = state . @@ -4511,8 +4334,6 @@ y z group size -cmd_buf -. buffer_memory_init_actions . extend @@ -4521,9 +4342,13 @@ indirect_buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +indirect_buffer offset . . @@ -4550,23 +4375,11 @@ intermediate_trackers & * bind_group_guard -& -* -buffer_guard -& -* -texture_guard Some ( -id -: -: -Valid -( buffer_id ) ) -) . map_pass_err ( @@ -4822,9 +4635,7 @@ QuerySet A > = -cmd_buf -. -trackers +tracker . query_sets . @@ -4901,9 +4712,7 @@ QuerySet A > = -cmd_buf -. -trackers +tracker . query_sets . @@ -5018,8 +4827,7 @@ the error state . -cmd_buf -. +* status = CommandEncoderStatus @@ -5035,8 +4843,6 @@ current command buffer . -cmd_buf -. encoder . close @@ -5080,8 +4886,6 @@ images let transit = -cmd_buf -. encoder . open @@ -5097,12 +4901,8 @@ into_iter ) transit & -texture_guard -& mut -cmd_buf -. -trackers +tracker . textures device @@ -5114,19 +4914,9 @@ CommandBuffer insert_barriers_from_tracker ( transit -& -mut -cmd_buf -. -trackers +tracker & intermediate_trackers -& -* -buffer_guard -& -* -texture_guard ) ; / @@ -5142,8 +4932,6 @@ with the previous . -cmd_buf -. encoder . close_and_swap diff --git a/third_party/rust/wgpu-core/src/command/memory_init.rs b/third_party/rust/wgpu-core/src/command/memory_init.rs index ce14e29870210..e132e42506c9c 100644 --- a/third_party/rust/wgpu-core/src/command/memory_init.rs +++ b/third_party/rust/wgpu-core/src/command/memory_init.rs @@ -14,6 +14,10 @@ ops : : Range +sync +: +: +Arc vec : : @@ -39,13 +43,6 @@ hal_api : : HalApi -id -: -: -{ -self -TextureId -} init_tracker : : @@ -54,13 +51,9 @@ resource : : { -Buffer +Resource Texture } -storage -: -: -Storage track : : @@ -133,11 +126,22 @@ crate ) struct TextureSurfaceDiscard +< +A +: +HalApi +> { pub texture : -TextureId +Arc +< +Texture +< +A +> +> pub mip_level : @@ -153,25 +157,29 @@ crate ) type SurfacesInDiscardState +< +A +> = Vec < TextureSurfaceDiscard +< +A +> > ; -# -[ -derive -( -Default -) -] pub ( crate ) struct CommandBufferTextureMemoryActions +< +A +: +HalApi +> { / / @@ -200,6 +208,9 @@ init_actions Vec < TextureInitTrackerAction +< +A +> > / / @@ -251,10 +262,63 @@ discards Vec < TextureSurfaceDiscard +< +A +> > } impl +< +A +: +HalApi +> +Default +for CommandBufferTextureMemoryActions +< +A +> +{ +fn +default +( +) +- +> +Self +{ +Self +{ +init_actions +: +Default +: +: +default +( +) +discards +: +Default +: +: +default +( +) +} +} +} +impl +< +A +: +HalApi +> +CommandBufferTextureMemoryActions +< +A +> { pub ( @@ -272,6 +336,9 @@ self Drain < TextureInitTrackerAction +< +A +> > { self @@ -297,6 +364,9 @@ self discard : TextureSurfaceDiscard +< +A +> ) { self @@ -358,14 +428,6 @@ crate ) fn register_init_action -< -A -: -hal -: -: -Api -> ( & mut @@ -374,21 +436,16 @@ action : & TextureInitTrackerAction -texture_guard -: -& -Storage -< -Texture < A > -TextureId -> ) - > SurfacesInDiscardState +< +A +> { let mut @@ -496,45 +553,20 @@ init_actions . extend ( -match -texture_guard -. -get -( action . -id -) -{ -Ok -( -texture -) -= -> texture . initialization_status . -check_action +read ( -action ) -Err +. +check_action ( -_ +action ) -= -> -return -immediately_necessary_clears -/ -/ -texture -no -longer -exists -} ) ; / @@ -604,11 +636,27 @@ if discarded_surface . texture +. +as_info +( +) +. +id +( +) = = action . +texture +. +as_info +( +) +. id +( +) & & action @@ -692,11 +740,15 @@ push ( TextureInitTrackerAction { -id +texture : discarded_surface . texture +. +clone +( +) range : TextureInitRange @@ -782,41 +834,23 @@ crate ) fn register_implicit_init -< -A -: -hal -: -: -Api -> ( & mut self -id -: -id -: -: -Valid -< -TextureId -> -range -: -TextureInitRange -texture_guard +texture : & -Storage +Arc < Texture < A > -TextureId > +range +: +TextureInitRange ) { let @@ -829,11 +863,13 @@ register_init_action & TextureInitTrackerAction { -id +texture : -id +texture . -0 +clone +( +) range kind : @@ -842,7 +878,6 @@ MemoryInitKind : ImplicitlyInitialized } -texture_guard ) ; assert @@ -909,6 +944,9 @@ Iterator Item = TextureSurfaceDiscard +< +A +> > > ( @@ -923,17 +961,6 @@ A : : CommandEncoder -texture_guard -: -& -Storage -< -Texture -< -A -> -TextureId -> texture_tracker : & @@ -958,16 +985,10 @@ inits { clear_texture ( -texture_guard -id -: -: -Valid -( +& init . texture -) TextureInitRange { mip_range @@ -1005,10 +1026,17 @@ texture_tracker device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) . unwrap @@ -1070,21 +1098,6 @@ Tracker < A > -buffer_guard -: -& -mut -Storage -< -Buffer -< -A -> -id -: -: -BufferId -> ) - > @@ -1160,30 +1173,18 @@ drain ) { let -buffer +mut +initialization_status = -buffer_guard -. -get_mut -( buffer_use . -id -) +buffer . -map_err -( -| -_ -| -DestroyedBufferError -( -buffer_use +initialization_status . -id -) +write +( ) -? ; / / @@ -1240,8 +1241,6 @@ end_remainder let uninitialized_ranges = -buffer -. initialization_status . drain @@ -1283,7 +1282,15 @@ entry ( buffer_use . +buffer +. +as_info +( +) +. id +( +) ) { Entry @@ -1300,6 +1307,14 @@ e . insert ( +( +buffer_use +. +buffer +. +clone +( +) uninitialized_ranges . collect @@ -1320,6 +1335,7 @@ BufferAddress ( ) ) +) ; } Entry @@ -1339,6 +1355,8 @@ get_mut ( ) . +1 +. extend ( uninitialized_ranges @@ -1352,9 +1370,12 @@ uninitialized_ranges for ( buffer_id +( +buffer mut ranges ) +) in uninitialized_ranges_per_buffer { @@ -1532,8 +1553,8 @@ buffers . set_single ( -buffer_guard -buffer_id +& +buffer hal : : @@ -1550,28 +1571,6 @@ unwrap 1 ; let -buffer -= -buffer_guard -. -get_mut -( -buffer_id -) -. -map_err -( -| -_ -| -DestroyedBufferError -( -buffer_id -) -) -? -; -let raw_buf = buffer @@ -1610,6 +1609,7 @@ pending . into_hal ( +& buffer ) ) @@ -1805,18 +1805,6 @@ Tracker < A > -texture_guard -: -& -mut -Storage -< -Texture -< -A -> -TextureId -> device : & @@ -1862,30 +1850,18 @@ drain_init_actions ) { let -texture +mut +initialization_status = -texture_guard -. -get_mut -( texture_use . -id -) +texture . -map_err -( -| -_ -| -DestroyedTextureError -( -texture_use +initialization_status . -id -) +write +( ) -? ; let use_range @@ -1897,8 +1873,6 @@ range let affected_mip_trackers = -texture -. initialization_status . mips @@ -2062,16 +2036,10 @@ drain { clear_texture ( -texture_guard -id -: -: -Valid -( +& texture_use . -id -) +texture range & mut @@ -2087,10 +2055,17 @@ textures device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) . unwrap @@ -2146,35 +2121,15 @@ iter ( ) { -let -texture -= -texture_guard -. -get_mut -( surface_discard . texture -) . -map_err -( -| -_ -| -DestroyedTextureError -( -surface_discard +initialization_status . -texture -) +write +( ) -? -; -texture -. -initialization_status . discard ( diff --git a/third_party/rust/wgpu-core/src/command/mod.rs b/third_party/rust/wgpu-core/src/command/mod.rs index 5074bb60d5061..65c2f49a187b2 100644 --- a/third_party/rust/wgpu-core/src/command/mod.rs +++ b/third_party/rust/wgpu-core/src/command/mod.rs @@ -31,6 +31,15 @@ std : slice ; +use +std +: +: +sync +: +: +Arc +; pub ( crate @@ -93,6 +102,15 @@ use crate : : +device +: +: +Device +; +use +crate +: +: error : : @@ -105,6 +123,24 @@ use crate : : +hub +: +: +Hub +; +use +crate +: +: +id +: +: +CommandBufferId +; +use +crate +: +: init_tracker : : @@ -114,6 +150,19 @@ use crate : : +resource +: +: +{ +Resource +ResourceInfo +ResourceType +} +; +use +crate +: +: track : : @@ -135,28 +184,12 @@ hal_api : : HalApi -hub -: -: -Token id identity : : GlobalIdentityHandlerFactory -resource -: -: -{ -Buffer -Texture -} -storage -: -: -Storage Label -Stored } ; use @@ -168,6 +201,12 @@ as _ ; use +parking_lot +: +: +Mutex +; +use thiserror : : @@ -220,6 +259,10 @@ derive Debug ) ] +pub +( +crate +) enum CommandEncoderStatus { @@ -227,15 +270,16 @@ Recording Finished Error } +pub +( +crate +) struct CommandEncoder < A : -hal -: -: -Api +HalApi > { raw @@ -274,10 +318,7 @@ impl < A : -hal -: -: -Api +HalApi > CommandEncoder < @@ -576,10 +617,16 @@ buffer_memory_init_actions Vec < BufferInitTrackerAction +< +A +> > texture_memory_actions : CommandBufferTextureMemoryActions +< +A +> } pub ( @@ -611,7 +658,7 @@ TextureId ; pub struct -CommandBuffer +CommandBufferMutable < A : @@ -631,19 +678,6 @@ pub ( crate ) -device_id -: -Stored -< -id -: -: -DeviceId -> -pub -( -crate -) trackers : Tracker @@ -655,10 +689,16 @@ buffer_memory_init_actions Vec < BufferInitTrackerAction +< +A +> > texture_memory_actions : CommandBufferTextureMemoryActions +< +A +> pub ( crate @@ -669,15 +709,6 @@ QueryResetMap < A > -limits -: -wgt -: -: -Limits -support_clear_texture -: -bool # [ cfg @@ -709,7 +740,7 @@ A : HalApi > -CommandBuffer +CommandBufferMutable < A > @@ -719,22 +750,76 @@ pub crate ) fn -new +open_encoder_and_tracker ( -encoder -: +& +mut +self +) +- +> +( +& +mut A : : CommandEncoder -device_id -: -Stored +& +mut +Tracker < -id +A +> +) +{ +let +encoder += +self +. +encoder +. +open +( +) +; +let +tracker += +& +mut +self +. +trackers +; +( +encoder +tracker +) +} +} +pub +struct +CommandBuffer +< +A : +HalApi +> +{ +pub +( +crate +) +device : -DeviceId +Arc +< +Device +< +A +> > limits : @@ -742,72 +827,313 @@ wgt : : Limits -_downlevel -: -wgt -: -: -DownlevelCapabilities -features -: -wgt -: +support_clear_texture : -Features -# -[ -cfg +bool +pub ( -feature -= -" -trace -" +crate ) -] -enable_tracing +info : -bool -label +ResourceInfo +< +CommandBufferId +> +pub +( +crate +) +data : +Mutex +< Option < -String +CommandBufferMutable +< +A > -) -- > -Self -{ +> +} +impl +< +A +: +HalApi +> +Drop +for CommandBuffer +< +A +> { -encoder -: -CommandEncoder +fn +drop +( +& +mut +self +) { -raw -: -encoder -is_open -: -false -list -: -Vec -: -: -new +if +self +. +data +. +lock ( ) -label +. +is_none +( +) +{ +return +; } -status +log +: +: +info +! +( +" +Destroying +CommandBuffer +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +let +mut +baked += +self +. +extract_baked_commands +( +) +; +unsafe +{ +baked +. +encoder +. +reset_all +( +baked +. +list +. +into_iter +( +) +) +; +} +unsafe +{ +use +hal +: +: +Device +; +self +. +device +. +raw +( +) +. +destroy_command_encoder +( +baked +. +encoder +) +; +} +} +} +impl +< +A +: +HalApi +> +CommandBuffer +< +A +> +{ +pub +( +crate +) +fn +new +( +encoder +: +A +: +: +CommandEncoder +device +: +& +Arc +< +Device +< +A +> +> +# +[ +cfg +( +feature += +" +trace +" +) +] +enable_tracing +: +bool +label +: +Option +< +String +> +) +- +> +Self +{ +CommandBuffer +{ +device +: +device +. +clone +( +) +limits +: +device +. +limits +. +clone +( +) +support_clear_texture +: +device +. +features +. +contains +( +wgt +: +: +Features +: +: +CLEAR_TEXTURE +) +info +: +ResourceInfo +: +: +new +( +label +. +as_ref +( +) +. +unwrap_or +( +& +String +: +: +from +( +" +< +CommandBuffer +> +" +) +) +. +as_str +( +) +) +data +: +Mutex +: +: +new +( +Some +( +CommandBufferMutable +{ +encoder +: +CommandEncoder +{ +raw +: +encoder +is_open +: +false +list +: +Vec +: +: +new +( +) +label +} +status : CommandEncoderStatus : : Recording -device_id trackers : Tracker @@ -840,21 +1166,6 @@ QueryResetMap new ( ) -limits -support_clear_texture -: -features -. -contains -( -wgt -: -: -Features -: -: -CLEAR_TEXTURE -) # [ cfg @@ -886,6 +1197,9 @@ else None } } +) +) +} } pub ( @@ -917,34 +1231,6 @@ Tracker < A > -buffer_guard -: -& -Storage -< -Buffer -< -A -> -id -: -: -BufferId -> -texture_guard -: -& -Storage -< -Texture -< -A -> -id -: -: -TextureId -> ) { profiling @@ -976,7 +1262,6 @@ textures . set_from_tracker ( -texture_guard & head . @@ -990,8 +1275,6 @@ drain_barriers ( raw base -buffer_guard -texture_guard ) ; } @@ -1025,34 +1308,6 @@ UsageScope < A > -buffer_guard -: -& -Storage -< -Buffer -< -A -> -id -: -: -BufferId -> -texture_guard -: -& -Storage -< -Texture -< -A -> -id -: -: -TextureId -> ) { profiling @@ -1084,7 +1339,6 @@ textures . set_from_usage_scope ( -texture_guard & head . @@ -1098,8 +1352,6 @@ drain_barriers ( raw base -buffer_guard -texture_guard ) ; } @@ -1126,34 +1378,6 @@ Tracker < A > -buffer_guard -: -& -Storage -< -Buffer -< -A -> -id -: -: -BufferId -> -texture_guard -: -& -Storage -< -Texture -< -A -> -id -: -: -TextureId -> ) { profiling @@ -1174,80 +1398,62 @@ base . buffers . -drain +drain_transitions ( ) -. -map -( -| -pending -| -{ +; let -buf -= -unsafe -{ -& -buffer_guard -. -get_unchecked ( -pending -. -id +transitions +textures ) -} -; -pending += +base . -into_hal +textures +. +drain_transitions ( -buf -) -} ) ; let texture_barriers = -base +transitions . -textures +into_iter +( +) . -drain +enumerate ( ) . map ( | -pending +( +i +p +) | -{ -let -tex -= -unsafe -{ -texture_guard +p . -get_unchecked +into_hal ( -pending +textures +[ +i +] . -id +as_ref +( ) -} -; -pending . -into_hal +unwrap ( -tex ) -} +) ) ; unsafe @@ -1281,19 +1487,14 @@ A > { fn -get_encoder_mut +get_encoder ( -storage +hub : & -mut -Storage +Hub < -Self -id -: -: -CommandEncoderId +A > id : @@ -1306,16 +1507,28 @@ CommandEncoderId > Result < -& -mut +Arc +< Self +> CommandEncoderError > { +let +storage += +hub +. +command_buffers +. +read +( +) +; match storage . -get_mut +get ( id ) @@ -1329,6 +1542,20 @@ cmd_buf match cmd_buf . +data +. +lock +( +) +. +as_ref +( +) +. +unwrap +( +) +. status { CommandEncoderStatus @@ -1340,6 +1567,10 @@ Recording Ok ( cmd_buf +. +clone +( +) ) CommandEncoderStatus : @@ -1397,6 +1628,20 @@ bool match self . +data +. +lock +( +) +. +as_ref +( +) +. +unwrap +( +) +. status { CommandEncoderStatus @@ -1417,8 +1662,10 @@ pub crate ) fn -into_baked +extract_baked_commands ( +& +mut self ) - @@ -1428,37 +1675,144 @@ BakedCommands A > { +log +: +: +info +! +( +" +Extracting BakedCommands +from +CommandBuffer { -encoder : +? +} +" self . +info +. +label +( +) +) +; +let +data += +self +. +data +. +lock +( +) +. +take +( +) +. +unwrap +( +) +; +BakedCommands +{ +encoder +: +data +. encoder . raw list : -self +data . encoder . list trackers : -self +data . trackers buffer_memory_init_actions : -self -. -buffer_memory_init_actions -texture_memory_actions +data +. +buffer_memory_init_actions +texture_memory_actions +: +data +. +texture_memory_actions +} +} +pub +( +crate +) +fn +from_arc_into_baked +( +self +: +Arc +< +Self +> +) +- +> +BakedCommands +< +A +> +{ +if +let +Ok +( +mut +command_buffer +) += +Arc +: : +try_unwrap +( self +) +{ +command_buffer . -texture_memory_actions +extract_baked_commands +( +) +} +else +{ +panic +! +( +" +CommandBuffer +cannot +be +destroyed +because +is +still +in +use +" +) +; } } } @@ -1468,13 +1822,10 @@ A : HalApi > -crate -: -: -resource -: -: Resource +< +CommandBufferId +> for CommandBuffer < @@ -1484,17 +1835,14 @@ A const TYPE : -& -' -static -str +ResourceType = " CommandBuffer " ; fn -life_guard +as_info ( & self @@ -1502,15 +1850,37 @@ self - > & -crate -: -: -LifeGuard +ResourceInfo +< +CommandBufferId +> { -unreachable -! +& +self +. +info +} +fn +as_info_mut ( +& +mut +self ) +- +> +& +mut +ResourceInfo +< +CommandBufferId +> +{ +& +mut +self +. +info } fn label @@ -1520,11 +1890,28 @@ self ) - > -& -str +String { +let +str += +match self . +data +. +lock +( +) +. +as_ref +( +) +. +unwrap +( +) +. encoder . label @@ -1532,21 +1919,31 @@ label as_ref ( ) -. -map_or +{ +Some ( -" -" -| -s -| -s +label +) += +> +label . -as_str +clone ( ) +_ += +> +String +: +: +new +( ) } +; +str +} } # [ @@ -2249,9 +2646,6 @@ Label - > ( -id -: -: CommandBufferId Option < @@ -2285,53 +2679,52 @@ self ) ; let -mut -token +error = -Token -: -: -root +match +hub +. +command_buffers +. +get +( +encoder_id +) +{ +Ok ( +cmd_buf ) -; += +> +{ let -( mut -cmd_buf_guard -_ -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -error +cmd_buf_data = -match -cmd_buf_guard +cmd_buf_data . -get_mut +as_mut ( -encoder_id ) -{ -Ok +. +unwrap ( -cmd_buf ) -= -> +; match -cmd_buf +cmd_buf_data . status { @@ -2342,7 +2735,7 @@ Recording = > { -cmd_buf +cmd_buf_data . encoder . @@ -2350,7 +2743,7 @@ close ( ) ; -cmd_buf +cmd_buf_data . status = @@ -2422,7 +2815,7 @@ Error = > { -cmd_buf +cmd_buf_data . encoder . @@ -2439,6 +2832,7 @@ Invalid ) } } +} Err ( _ @@ -2533,49 +2927,42 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( +hub +encoder_id ) +? ; let -( mut -cmd_buf_guard -_ -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -cmd_buf +cmd_buf_data = -CommandBuffer -: -: -get_encoder_mut +cmd_buf_data +. +as_mut +( +) +. +unwrap ( -& -mut -* -cmd_buf_guard -encoder_id ) -? ; # [ @@ -2597,7 +2984,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -2622,7 +3009,7 @@ to_string let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . @@ -2740,49 +3127,42 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( +hub +encoder_id ) +? ; let -( mut -cmd_buf_guard -_ -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -cmd_buf +cmd_buf_data = -CommandBuffer -: -: -get_encoder_mut +cmd_buf_data +. +as_mut +( +) +. +unwrap ( -& -mut -* -cmd_buf_guard -encoder_id ) -? ; # [ @@ -2804,7 +3184,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -2848,7 +3228,7 @@ DISCARD_HAL_LABELS let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . @@ -2940,49 +3320,42 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( +hub +encoder_id ) +? ; let -( mut -cmd_buf_guard -_ -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -cmd_buf +cmd_buf_data = -CommandBuffer -: -: -get_encoder_mut +cmd_buf_data +. +as_mut +( +) +. +unwrap ( -& -mut -* -cmd_buf_guard -encoder_id ) -? ; # [ @@ -3004,7 +3377,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -3022,7 +3395,7 @@ PopDebugGroup let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . diff --git a/third_party/rust/wgpu-core/src/command/query.rs b/third_party/rust/wgpu-core/src/command/query.rs index c3d9516a1b5e4..499d83098656c 100644 --- a/third_party/rust/wgpu-core/src/command/query.rs +++ b/third_party/rust/wgpu-core/src/command/query.rs @@ -51,10 +51,6 @@ hal_api : : HalApi -hub -: -: -Token id : : @@ -124,10 +120,7 @@ QueryResetMap < A : -hal -: -: -Api +HalApi > { map @@ -154,10 +147,7 @@ impl < A : -hal -: -: -Api +HalApi > QueryResetMap < @@ -554,10 +544,11 @@ raw_encoder . reset_queries ( -& query_set . raw +( +) start . . @@ -1498,10 +1489,11 @@ count } Ok ( -& self . raw +( +) ) } pub @@ -1607,10 +1599,11 @@ raw_encoder . reset_queries ( -& self . raw +( +) query_index . . @@ -1792,10 +1785,17 @@ raw_encoder . reset_queries ( -& self . raw +. +as_ref +( +) +. +unwrap +( +) query_index . . @@ -1977,10 +1977,11 @@ raw_encoder . reset_queries ( -& self . raw +( +) query_index . . @@ -2119,10 +2120,17 @@ raw_encoder . end_query ( -& query_set . raw +. +as_ref +( +) +. +unwrap +( +) query_index ) } @@ -2255,10 +2263,11 @@ raw_encoder . end_query ( -& query_set . raw +( +) query_index ) } @@ -2339,75 +2348,40 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( +hub +command_encoder_id ) +? ; let -( mut -cmd_buf_guard -mut -token -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -( -query_set_guard -_ -) +cmd_buf_data = -hub +cmd_buf_data . -query_sets -. -read -( -& -mut -token -) -; -let -cmd_buf -= -CommandBuffer -: -: -get_encoder_mut +as_mut ( -& -mut -cmd_buf_guard -command_encoder_id ) -? -; -let -raw_encoder -= -cmd_buf . -encoder -. -open +unwrap ( ) ; @@ -2431,7 +2405,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -2451,11 +2425,47 @@ query_index ; } let -query_set +encoder = -cmd_buf +& +mut +cmd_buf_data +. +encoder +; +let +tracker += +& +mut +cmd_buf_data . trackers +; +let +raw_encoder += +encoder +. +open +( +) +; +let +query_set_guard += +hub +. +query_sets +. +read +( +) +; +let +query_set += +tracker . query_sets . @@ -2556,93 +2566,40 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= hub -. -command_buffers -. -write -( -& -mut -token +command_encoder_id ) +? ; let -( -query_set_guard mut -token -) +cmd_buf_data = -hub +cmd_buf . -query_sets +data . -read +lock ( -& -mut -token ) ; let -( -buffer_guard -_ -) +cmd_buf_data = -hub +cmd_buf_data . -buffers -. -read -( -& -mut -token -) -; -let -cmd_buf -= -CommandBuffer -: -: -get_encoder_mut +as_mut ( -& -mut -cmd_buf_guard -command_encoder_id ) -? -; -let -raw_encoder -= -cmd_buf . -encoder -. -open +unwrap ( ) ; @@ -2666,7 +2623,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -2688,6 +2645,42 @@ destination_offset ) ; } +let +encoder += +& +mut +cmd_buf_data +. +encoder +; +let +tracker += +& +mut +cmd_buf_data +. +trackers +; +let +buffer_memory_init_actions += +& +mut +cmd_buf_data +. +buffer_memory_init_actions +; +let +raw_encoder += +encoder +. +open +( +) +; if destination_offset % @@ -2716,11 +2709,20 @@ BufferOffsetAlignment ; } let -query_set +query_set_guard = -cmd_buf +hub . -trackers +query_sets +. +read +( +) +; +let +query_set += +tracker . query_sets . @@ -2750,18 +2752,50 @@ dst_buffer dst_pending ) = -cmd_buf -. -trackers +{ +let +buffer_guard += +hub . buffers . -set_single +read ( -& -* +) +; +let +dst_buffer += buffer_guard +. +get +( destination +) +. +map_err +( +| +_ +| +QueryError +: +: +InvalidBuffer +( +destination +) +) +? +; +tracker +. +buffers +. +set_single +( +dst_buffer hal : : @@ -2782,6 +2816,7 @@ destination ) ) ? +} ; let dst_barrier @@ -2797,6 +2832,7 @@ pending . into_hal ( +& dst_buffer ) ) @@ -3021,8 +3057,6 @@ track initialization state . -cmd_buf -. buffer_memory_init_actions . extend @@ -3031,9 +3065,14 @@ dst_buffer . initialization_status . +read +( +) +. create_action ( -destination +& +dst_buffer buffer_start_offset . . @@ -3062,10 +3101,11 @@ raw_encoder . copy_query_results ( -& query_set . raw +( +) start_query . . @@ -3073,12 +3113,6 @@ end_query dst_buffer . raw -. -as_ref -( -) -. -unwrap ( ) destination_offset diff --git a/third_party/rust/wgpu-core/src/command/render.rs b/third_party/rust/wgpu-core/src/command/render.rs index 00b4dd4090007..73992e90ffcd5 100644 --- a/third_party/rust/wgpu-core/src/command/render.rs +++ b/third_party/rust/wgpu-core/src/command/render.rs @@ -2,14 +2,20 @@ use crate : : +resource +: +: +Resource +; +use +crate +: +: { binding_model : : -{ BindError -BindGroupLayouts -} command : : @@ -72,10 +78,6 @@ hal_api : HalApi hal_label -hub -: -: -Token id identity : @@ -115,6 +117,7 @@ track : { TextureSelector +Tracker UsageConflict UsageScope } @@ -128,7 +131,6 @@ MissingBufferUsageError MissingTextureUsageError } Label -Stored } ; use @@ -224,6 +226,15 @@ use std : : +sync +: +: +Arc +; +use +std +: +: { borrow : @@ -257,6 +268,8 @@ memory_init : TextureSurfaceDiscard CommandBufferTextureMemoryActions +CommandEncoder +QueryResetMap } ; / @@ -2456,13 +2469,7 @@ Option id : : -Valid -< -id -: -: BufferId -> Range < BufferAddress @@ -2965,6 +2972,11 @@ Debug ] struct State +< +A +: +HalApi +> { pipeline_flags : @@ -2972,6 +2984,9 @@ PipelineFlags binder : Binder +< +A +> blend_constant : OptionalState @@ -2998,31 +3013,24 @@ debug_scope_depth u32 } impl -State -{ -fn -is_ready < A : -hal -: -: -Api +HalApi +> +State +< +A > +{ +fn +is_ready ( & self indexed : bool -bind_group_layouts -: -& -BindGroupLayouts -< -A -> ) - > @@ -3113,7 +3121,6 @@ binder . invalid_mask ( -bind_group_layouts ) ; if @@ -4079,6 +4086,9 @@ Not enough memory left +for +render +pass " ) ] @@ -4876,19 +4886,19 @@ RenderAttachment < ' a +A +: +HalApi > { -texture_id +texture : -& -' -a -Stored +Arc < -id -: -: -TextureId +Texture +< +A +> > selector : @@ -4907,10 +4917,7 @@ impl < A : -hal -: -: -Api +HalApi > TextureView < @@ -4932,15 +4939,33 @@ TextureUses - > RenderAttachment +< +A +> { RenderAttachment { -texture_id +texture : -& self . -parent_id +parent +. +read +( +) +. +as_ref +( +) +. +unwrap +( +) +. +clone +( +) selector : & @@ -5017,6 +5042,7 @@ RenderAttachment < ' a +A > > is_depth_read_only @@ -5040,6 +5066,9 @@ A pending_discard_init_fixups : SurfacesInDiscardState +< +A +> divergent_discarded_depth_stencil_aspect : Option @@ -5098,32 +5127,24 @@ texture_memory_actions & mut CommandBufferTextureMemoryActions -view -: -& -TextureView < A > -texture_guard +view : & -Storage -< -Texture +TextureView < A > -id -: -: -TextureId -> pending_discard_init_fixups : & mut SurfacesInDiscardState +< +A +> ) { if @@ -5148,15 +5169,27 @@ register_init_action & TextureInitTrackerAction { -id +texture : view . -parent_id +parent . -value +read +( +) . -0 +as_ref +( +) +. +unwrap +( +) +. +clone +( +) range : TextureInitRange @@ -5192,7 +5225,6 @@ MemoryInitKind : NeedsInitializedMemory } -texture_guard ) ) ; @@ -5220,9 +5252,19 @@ register_implicit_init ( view . -parent_id +parent . -value +read +( +) +. +as_ref +( +) +. +unwrap +( +) TextureInitRange : : @@ -5236,7 +5278,6 @@ clone ( ) ) -texture_guard ) ; } @@ -5298,11 +5339,23 @@ texture : view . -parent_id +parent . -value +read +( +) . -0 +as_ref +( +) +. +unwrap +( +) +. +clone +( +) mip_level : view @@ -5375,11 +5428,35 @@ id : QuerySetId > -cmd_buf +encoder : & mut -CommandBuffer +CommandEncoder +< +A +> +trackers +: +& +mut +Tracker +< +A +> +texture_memory_actions +: +& +mut +CommandBufferTextureMemoryActions +< +A +> +pending_query_resets +: +& +mut +QueryResetMap < A > @@ -5538,6 +5615,9 @@ AttachmentDataVec : < RenderAttachment +< +A +> > : : @@ -6036,8 +6116,6 @@ TextureView A > = -cmd_buf -. trackers . views @@ -6176,13 +6254,8 @@ add_pass_texture_init_actions at . depth -& -mut -cmd_buf -. texture_memory_actions view -texture_guard & mut pending_discard_init_fixups @@ -6214,13 +6287,8 @@ add_pass_texture_init_actions at . stencil -& -mut -cmd_buf -. texture_memory_actions view -texture_guard & mut pending_discard_init_fixups @@ -6459,8 +6527,6 @@ pending_discard_init_fixups . extend ( -cmd_buf -. texture_memory_actions . register_init_action @@ -6468,15 +6534,27 @@ register_init_action & TextureInitTrackerAction { -id +texture : view . -parent_id +parent . -value +read +( +) . -0 +as_ref +( +) +. +unwrap +( +) +. +clone +( +) range : TextureInitRange @@ -6499,7 +6577,6 @@ MemoryInitKind : NeedsInitializedMemory } -texture_guard ) ) ; @@ -6603,17 +6680,25 @@ if ! need_init_beforehand { -cmd_buf -. texture_memory_actions . register_implicit_init ( view . -parent_id +parent . -value +read +( +) +. +as_ref +( +) +. +unwrap +( +) TextureInitRange : : @@ -6627,7 +6712,6 @@ clone ( ) ) -texture_guard ) ; } @@ -6706,11 +6790,23 @@ texture : view . -parent_id -. -value +parent . -0 +read +( +) +. +as_ref +( +) +. +unwrap +( +) +. +clone +( +) mip_level : view @@ -6831,10 +6927,11 @@ Attachment { view : -& view . raw +( +) usage } depth_ops @@ -6929,8 +7026,6 @@ TextureView A > = -cmd_buf -. trackers . views @@ -7032,13 +7127,8 @@ add_pass_texture_init_actions at . channel -& -mut -cmd_buf -. texture_memory_actions color_view -texture_guard & mut pending_discard_init_fixups @@ -7088,8 +7178,6 @@ TextureView A > = -cmd_buf -. trackers . views @@ -7324,17 +7412,25 @@ format ) ; } -cmd_buf -. texture_memory_actions . register_implicit_init ( resolve_view . -parent_id +parent . -value +read +( +) +. +as_ref +( +) +. +unwrap +( +) TextureInitRange : : @@ -7348,7 +7444,6 @@ clone ( ) ) -texture_guard ) ; render_attachments @@ -7380,10 +7475,11 @@ Attachment { view : -& resolve_view . raw +( +) usage : hal @@ -7417,10 +7513,11 @@ Attachment { view : -& color_view . raw +( +) usage : hal @@ -7652,8 +7749,6 @@ timestamp_writes let query_set = -cmd_buf -. trackers . query_sets @@ -7691,8 +7786,6 @@ tw . beginning_of_pass_write_index { -cmd_buf -. pending_query_resets . use_query_set @@ -7716,8 +7809,6 @@ tw . end_of_pass_write_index { -cmd_buf -. pending_query_resets . use_query_set @@ -7739,10 +7830,17 @@ RenderPassTimestampWrites { query_set : -& query_set . raw +. +as_ref +( +) +. +unwrap +( +) beginning_of_pass_write_index : tw @@ -7776,8 +7874,6 @@ occlusion_query_set let query_set = -cmd_buf -. trackers . query_sets @@ -7802,10 +7898,17 @@ occlusion_query_set ; Some ( -& query_set . raw +. +as_ref +( +) +. +unwrap +( +) ) } else @@ -7846,8 +7949,6 @@ occlusion_query_set ; unsafe { -cmd_buf -. encoder . raw @@ -7901,20 +8002,6 @@ A : : CommandEncoder -texture_guard -: -& -Storage -< -Texture -< -A -> -id -: -: -TextureId -> ) - > @@ -7926,6 +8013,9 @@ UsageScope A > SurfacesInDiscardState +< +A +> ) RenderPassErrorInner > @@ -7960,43 +8050,13 @@ self . render_attachments { -if -! -texture_guard -. -contains -( -ra -. -texture_id -. -value -. -0 -) -{ -return -Err -( -RenderPassErrorInner -: -: -SurfaceTextureDropped -) -; -} let texture = & -texture_guard -[ ra . -texture_id -. -value -] +texture ; check_texture_usage ( @@ -8037,12 +8097,7 @@ textures . merge_single ( -texture_guard -ra -. -texture_id -. -value +texture Some ( ra @@ -8053,12 +8108,6 @@ clone ( ) ) -& -ra -. -texture_id -. -ref_count ra . usage @@ -8356,10 +8405,11 @@ Attachment { view : -& view . raw +( +) usage : hal @@ -8671,120 +8721,216 @@ self ) ; let -mut -token +( +scope +pending_discard_init_fixups +) += +{ +let +cmd_buf = -Token +CommandBuffer : : -root +get_encoder +( +hub +encoder_id +) +. +map_pass_err ( +init_scope ) +? ; let -( -device_guard mut -token -) +cmd_buf_data = -hub +cmd_buf . -devices +data . -read +lock ( -& -mut -token ) ; let +cmd_buf_data += +cmd_buf_data +. +as_mut +( +) +. +unwrap ( -scope -pending_discard_init_fixups ) +; +# +[ +cfg +( +feature = -{ +" +trace +" +) +] +if let +Some ( +ref mut -cmb_guard -mut -token +list ) = -hub +cmd_buf_data . -command_buffers +commands +{ +list . -write +push ( -& -mut -token -) -; -/ -/ -Spell -out -the -type -to -placate -rust -- -analyzer -. -/ -/ -https +crate : -/ -/ -github -. -com -/ -rust -- -lang -/ -rust -- -analyzer -/ -issues -/ -12247 -let -cmd_buf : -& -mut -CommandBuffer -< -A -> -= -CommandBuffer +device +: +: +trace +: +: +Command +: +: +RunRenderPass +{ +base +: +BasePass : : -get_encoder_mut +from_ref ( -& -mut -* -cmb_guard -encoder_id +base ) +target_colors +: +color_attachments . -map_pass_err +to_vec ( -init_scope ) -? +target_depth_stencil +: +depth_stencil_attachment +. +cloned +( +) +timestamp_writes +: +timestamp_writes +. +cloned +( +) +occlusion_query_set_id +} +) +; +} +let +device += +& +cmd_buf +. +device +; +if +! +device +. +is_valid +( +) +{ +return +Err +( +DeviceError +: +: +Lost +) +. +map_pass_err +( +init_scope +) +; +} +let +encoder += +& +mut +cmd_buf_data +. +encoder +; +let +status += +& +mut +cmd_buf_data +. +status +; +let +tracker += +& +mut +cmd_buf_data +. +trackers +; +let +buffer_memory_init_actions += +& +mut +cmd_buf_data +. +buffer_memory_init_actions +; +let +texture_memory_actions += +& +mut +cmd_buf_data +. +texture_memory_actions +; +let +pending_query_resets += +& +mut +cmd_buf_data +. +pending_query_resets ; / / @@ -8828,8 +8974,6 @@ the previous one . -cmd_buf -. encoder . close @@ -8854,8 +8998,7 @@ fail - safe . -cmd_buf -. +* status = CommandEncoderStatus @@ -8863,126 +9006,6 @@ CommandEncoderStatus : Error ; -# -[ -cfg -( -feature -= -" -trace -" -) -] -if -let -Some -( -ref -mut -list -) -= -cmd_buf -. -commands -{ -list -. -push -( -crate -: -: -device -: -: -trace -: -: -Command -: -: -RunRenderPass -{ -base -: -BasePass -: -: -from_ref -( -base -) -target_colors -: -color_attachments -. -to_vec -( -) -target_depth_stencil -: -depth_stencil_attachment -. -cloned -( -) -timestamp_writes -: -timestamp_writes -. -cloned -( -) -occlusion_query_set_id -} -) -; -} -let -device_id -= -cmd_buf -. -device_id -. -value -; -let -device -= -& -device_guard -[ -device_id -] -; -if -! -device -. -is_valid -( -) -{ -return -Err -( -DeviceError -: -: -Lost -) -. -map_pass_err -( -init_scope -) -; -} -cmd_buf -. encoder . open_pass @@ -8991,11 +9014,7 @@ label ) ; let -( bundle_guard -mut -token -) = hub . @@ -9003,35 +9022,10 @@ render_bundles . read ( -& -mut -token ) ; let -( -pipeline_layout_guard -mut -token -) -= -hub -. -pipeline_layouts -. -read -( -& -mut -token -) -; -let -( bind_group_guard -mut -token -) = hub . @@ -9039,17 +9033,10 @@ bind_groups . read ( -& -mut -token ) ; let -( render_pipeline_guard -mut -token -) = hub . @@ -9057,17 +9044,10 @@ render_pipelines . read ( -& -mut -token ) ; let -( query_set_guard -mut -token -) = hub . @@ -9075,35 +9055,10 @@ query_sets . read ( -& -mut -token -) -; -let -( -bind_group_layout_guard -mut -token -) -= -hub -. -bind_group_layouts -. -read -( -& -mut -token ) ; let -( buffer_guard -mut -token -) = hub . @@ -9111,17 +9066,10 @@ buffers . read ( -& -mut -token ) ; let -( texture_guard -mut -token -) = hub . @@ -9129,16 +9077,10 @@ textures . read ( -& -mut -token ) ; let -( view_guard -_ -) = hub . @@ -9146,9 +9088,6 @@ texture_views . read ( -& -mut -token ) ; log @@ -9188,7 +9127,10 @@ color_attachments depth_stencil_attachment timestamp_writes occlusion_query_set_id -cmd_buf +encoder +tracker +texture_memory_actions +pending_query_resets & * view_guard @@ -9209,9 +9151,7 @@ init_scope ) ? ; -cmd_buf -. -trackers +tracker . set_size ( @@ -9266,8 +9206,6 @@ raw = & mut -cmd_buf -. encoder . raw @@ -9485,22 +9423,8 @@ usize ; let bind_group -: -& -crate -: -: -binding_model -: -: -BindGroup -< -A -> = -cmd_buf -. -trackers +tracker . bind_groups . @@ -9532,12 +9456,26 @@ scope if bind_group . -device_id +device . -value +as_info +( +) +. +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -9589,9 +9527,6 @@ usage_scope merge_bind_group ( & -* -texture_guard -& bind_group . used @@ -9627,8 +9562,6 @@ bind group itself . -cmd_buf -. buffer_memory_init_actions . extend @@ -9637,6 +9570,10 @@ bind_group . used_buffer_ranges . +read +( +) +. iter ( ) @@ -9647,38 +9584,20 @@ filter_map action | { -match -buffer_guard -. -get -( action . -id -) -{ -Ok -( -buffer -) -= -> buffer . initialization_status . -check_action +read ( -action ) -Err +. +check_action ( -_ +action ) -= -> -None -} } ) ) @@ -9690,6 +9609,10 @@ bind_group . used_texture_ranges . +read +( +) +. iter ( ) @@ -9700,27 +9623,27 @@ pending_discard_init_fixups . extend ( -cmd_buf -. texture_memory_actions . register_init_action ( action -& -texture_guard ) ) ; } let -pipeline_layout_id +pipeline_layout = state . binder . -pipeline_layout_id +pipeline_layout +. +clone +( +) ; let entries @@ -9734,13 +9657,6 @@ assign_group index as usize -id -: -: -Valid -( -bind_group_id -) bind_group & temp_offsets @@ -9753,21 +9669,30 @@ entries is_empty ( ) +& +& +pipeline_layout +. +is_some +( +) { let pipeline_layout = -& -pipeline_layout_guard -[ -pipeline_layout_id +pipeline_layout +. +as_ref +( +) . unwrap ( ) -] . raw +( +) ; for ( @@ -9785,28 +9710,29 @@ enumerate ( ) { +if let -raw_bg +Some +( +group +) = -& -bind_group_guard -[ e . -group_id +group . as_ref ( ) +{ +let +raw_bg += +group . -unwrap +raw ( ) -. -value -] -. -raw ; unsafe { @@ -9831,6 +9757,7 @@ dynamic_offsets } } } +} RenderCommand : : @@ -9892,9 +9819,7 @@ RenderPipeline A > = -cmd_buf -. -trackers +tracker . render_pipelines . @@ -9926,12 +9851,26 @@ scope if pipeline . -device_id +device . -value +as_info +( +) +. +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -10066,10 +10005,11 @@ raw . set_render_pipeline ( -& pipeline . raw +( +) ) ; } @@ -10108,31 +10048,36 @@ state . binder . -pipeline_layout_id -! -= -Some +pipeline_layout +. +is_none ( -pipeline +) +| +| +! +state . -layout_id +binder . -value -) -{ -let pipeline_layout -= +. +as_ref +( +) +. +unwrap +( +) +. +is_equal +( & -pipeline_layout_guard -[ pipeline . -layout_id -. -value -] -; +layout +) +{ let ( start_index @@ -10146,13 +10091,9 @@ binder change_pipeline_layout ( & -* -pipeline_layout_guard pipeline . -layout_id -. -value +layout & pipeline . @@ -10183,28 +10124,29 @@ enumerate ( ) { +if let -raw_bg +Some +( +group +) = -& -bind_group_guard -[ e . -group_id +group . as_ref ( ) +{ +let +raw_bg += +group . -unwrap +raw ( ) -. -value -] -. -raw ; unsafe { @@ -10212,10 +10154,13 @@ raw . set_bind_group ( -& -pipeline_layout +pipeline +. +layout . raw +( +) start_index as u32 @@ -10233,6 +10178,7 @@ dynamic_offsets } } } +} / / Clear @@ -10251,7 +10197,9 @@ bind compute_nonoverlapping_ranges ( & -pipeline_layout +pipeline +. +layout . push_constant_ranges ) @@ -10298,10 +10246,13 @@ raw . set_push_constants ( -& -pipeline_layout +pipeline +. +layout . raw +( +) range . stages @@ -10549,12 +10500,6 @@ buffer_id ; let buffer -: -& -Buffer -< -A -> = info . @@ -10586,12 +10531,26 @@ scope if buffer . -device_id +device +. +as_info +( +) . -value +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -10689,13 +10648,7 @@ bound_buffer_view Some ( ( -id -: -: -Valid -( buffer_id -) offset . . @@ -10722,8 +10675,6 @@ update_limit ( ) ; -cmd_buf -. buffer_memory_init_actions . extend @@ -10732,9 +10683,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -10821,12 +10776,6 @@ buffer_id ; let buffer -: -& -Buffer -< -A -> = info . @@ -10858,12 +10807,26 @@ scope if buffer . -device_id +device . -value +as_info +( +) +. +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -11076,8 +11039,6 @@ bound = true ; -cmd_buf -. buffer_memory_init_actions . extend @@ -11086,9 +11047,13 @@ buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +buffer offset . . @@ -11606,13 +11571,17 @@ values_end_offset ] ; let -pipeline_layout_id +pipeline_layout = state . binder . -pipeline_layout_id +pipeline_layout +. +as_ref +( +) . ok_or ( @@ -11628,15 +11597,6 @@ scope ) ? ; -let -pipeline_layout -= -& -pipeline_layout_guard -[ -pipeline_layout_id -] -; pipeline_layout . validate_push_constant_ranges @@ -11666,10 +11626,11 @@ raw . set_push_constants ( -& pipeline_layout . raw +( +) stages offset data_slice @@ -11874,15 +11835,8 @@ pipeline state . is_ready -: -: -< -A -> ( indexed -& -bind_group_layout_guard ) . map_pass_err @@ -12069,16 +12023,8 @@ pipeline state . is_ready -: -: -< -A -> ( indexed -& -* -bind_group_layout_guard ) . map_pass_err @@ -12272,20 +12218,12 @@ state . pipeline } -; -state -. -is_ready -: -: -< -A -> +; +state +. +is_ready ( indexed -& -* -bind_group_layout_guard ) . map_pass_err @@ -12384,12 +12322,6 @@ scope ; let indirect_buffer -: -& -Buffer -< -A -> = info . @@ -12526,8 +12458,6 @@ scope ) ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -12536,9 +12466,13 @@ indirect_buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +indirect_buffer offset . . @@ -12666,16 +12600,8 @@ pipeline state . is_ready -: -: -< -A -> ( indexed -& -* -bind_group_layout_guard ) . map_pass_err @@ -12768,12 +12694,6 @@ scope ; let indirect_buffer -: -& -Buffer -< -A -> = info . @@ -12849,12 +12769,6 @@ scope ; let count_buffer -: -& -Buffer -< -A -> = info . @@ -12973,8 +12887,6 @@ scope ) ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -12983,9 +12895,13 @@ indirect_buffer . initialization_status . +read +( +) +. create_action ( -buffer_id +indirect_buffer offset . . @@ -13040,8 +12956,6 @@ scope ) ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -13050,9 +12964,13 @@ count_buffer . initialization_status . +read +( +) +. create_action ( -count_buffer_id +count_buffer count_buffer_offset . . @@ -13405,9 +13323,7 @@ scope let query_set = -cmd_buf -. -trackers +tracker . query_sets . @@ -13447,7 +13363,7 @@ Some ( & mut -cmd_buf +cmd_buf_data . pending_query_resets ) @@ -13517,9 +13433,7 @@ scope let query_set = -cmd_buf -. -trackers +tracker . query_sets . @@ -13559,7 +13473,7 @@ Some ( & mut -cmd_buf +cmd_buf_data . pending_query_resets ) @@ -13666,9 +13580,7 @@ BeginPipelineStatisticsQuery let query_set = -cmd_buf -. -trackers +tracker . query_sets . @@ -13708,7 +13620,7 @@ Some ( & mut -cmd_buf +cmd_buf_data . pending_query_resets ) @@ -13820,9 +13732,7 @@ RenderBundle A > = -cmd_buf -. -trackers +tracker . bundles . @@ -13854,12 +13764,26 @@ scope if bundle . -device_id +device . -value +as_info +( +) +. +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -13969,8 +13893,6 @@ scope ) ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -13988,37 +13910,21 @@ filter_map | action | -match -buffer_guard -. -get -( +{ action . -id -) -{ -Ok -( -buffer -) -= -> buffer . initialization_status . -check_action +read ( -action ) -Err +. +check_action ( -_ +action ) -= -> -None } ) ) @@ -14040,15 +13946,11 @@ pending_discard_init_fixups . extend ( -cmd_buf -. texture_memory_actions . register_init_action ( action -& -texture_guard ) ) ; @@ -14060,18 +13962,6 @@ bundle execute ( raw -& -* -pipeline_layout_guard -& -* -bind_group_guard -& -* -render_pipeline_guard -& -* -buffer_guard ) } . @@ -14137,9 +14027,6 @@ usage_scope merge_render_bundle ( & -* -texture_guard -& bundle . used @@ -14151,9 +14038,7 @@ scope ) ? ; -cmd_buf -. -trackers +tracker . add_from_render_bundle ( @@ -14210,9 +14095,6 @@ info finish ( raw -& -* -texture_guard ) . map_pass_err @@ -14221,8 +14103,6 @@ init_scope ) ? ; -cmd_buf -. encoder . close @@ -14236,97 +14116,88 @@ pending_discard_init_fixups } ; let -( -mut -cmb_guard -mut -token -) +query_set_guard = hub . -command_buffers +query_sets . -write +read ( -& -mut -token ) ; let -( -query_set_guard -mut -token -) +cmd_buf = hub . -query_sets +command_buffers . -read +get +( +encoder_id +) +. +unwrap ( -& -mut -token ) ; let -( -buffer_guard mut -token -) +cmd_buf_data = -hub +cmd_buf . -buffers +data . -read +lock ( -& -mut -token ) ; let -( -texture_guard -_ -) +cmd_buf_data = -hub +cmd_buf_data . -textures +as_mut +( +) . -read +unwrap ( +) +; +let +encoder += & mut -token -) +cmd_buf_data +. +encoder ; let -cmd_buf +status = -cmb_guard +& +mut +cmd_buf_data . -get_mut -( -encoder_id -) +status +; +let +tracker += +& +mut +cmd_buf_data . -unwrap -( -) +trackers ; { let transit = -cmd_buf -. encoder . open @@ -14342,26 +14213,17 @@ into_iter ) transit & -texture_guard -& mut -cmd_buf -. -trackers +tracker . textures & -device_guard -[ cmd_buf . -device_id -. -value -] +device ) ; -cmd_buf +cmd_buf_data . pending_query_resets . @@ -14372,11 +14234,13 @@ transit query_set_guard cmd_buf . -device_id +device . -value +info . -0 +id +( +) . backend ( @@ -14409,24 +14273,13 @@ CommandBuffer insert_barriers_from_scope ( transit -& -mut -cmd_buf -. -trackers +tracker & scope -& -* -buffer_guard -& -* -texture_guard ) ; } -cmd_buf -. +* status = CommandEncoderStatus @@ -14434,8 +14287,6 @@ CommandEncoderStatus : Recording ; -cmd_buf -. encoder . close_and_swap diff --git a/third_party/rust/wgpu-core/src/command/transfer.rs b/third_party/rust/wgpu-core/src/command/transfer.rs index 6e7a235562655..6cec70cd47e15 100644 --- a/third_party/rust/wgpu-core/src/command/transfer.rs +++ b/third_party/rust/wgpu-core/src/command/transfer.rs @@ -59,10 +59,6 @@ hal_api : : HalApi -hub -: -: -Token id : : @@ -71,7 +67,6 @@ BufferId CommandEncoderId DeviceId TextureId -Valid } identity : @@ -90,6 +85,7 @@ resource : : { +Resource Texture TextureErrorDimension } @@ -100,7 +96,10 @@ Storage track : : +{ TextureSelector +Tracker +} } ; use @@ -140,6 +139,18 @@ std : iter ; +use +super +: +: +{ +memory_init +: +: +CommandBufferTextureMemoryActions +CommandEncoder +} +; pub type ImageCopyBuffer @@ -1524,10 +1535,7 @@ extract_texture_selector < A : -hal -: -: -Api +HalApi > ( copy_texture @@ -3004,11 +3012,27 @@ HalApi init_kind : MemoryInitKind -cmd_buf +encoder : & mut -CommandBuffer +CommandEncoder +< +A +> +trackers +: +& +mut +Tracker +< +A +> +texture_memory_actions +: +& +mut +CommandBufferTextureMemoryActions < A > @@ -3041,15 +3065,33 @@ TextureId ) { let +texture += +texture_guard +. +get +( +copy_texture +. +texture +) +. +unwrap +( +) +; +let init_action = TextureInitTrackerAction { -id +texture : -copy_texture -. texture +. +clone +( +) range : TextureInitRange @@ -3102,8 +3144,6 @@ action let immediate_inits = -cmd_buf -. texture_memory_actions . register_init_action @@ -3112,7 +3152,6 @@ register_init_action { init_action } -texture_guard ) ; / @@ -3145,8 +3184,6 @@ is_empty let cmd_buf_raw = -cmd_buf -. encoder . open @@ -3160,13 +3197,10 @@ immediate_inits { clear_texture ( -texture_guard -Valid -( +& init . texture -) TextureInitRange { mip_range @@ -3201,8 +3235,6 @@ layer cmd_buf_raw & mut -cmd_buf -. trackers . textures @@ -3210,10 +3242,17 @@ textures device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) . unwrap @@ -3274,11 +3313,27 @@ A HalApi > ( -cmd_buf +encoder : & mut -CommandBuffer +CommandEncoder +< +A +> +trackers +: +& +mut +Tracker +< +A +> +texture_memory_actions +: +& +mut +CommandBufferTextureMemoryActions < A > @@ -3353,7 +3408,9 @@ MemoryInitKind : : NeedsInitializedMemory -cmd_buf +encoder +trackers +texture_memory_actions device source copy_size @@ -3417,11 +3474,27 @@ A HalApi > ( -cmd_buf +encoder : & mut -CommandBuffer +CommandEncoder +< +A +> +trackers +: +& +mut +Tracker +< +A +> +texture_memory_actions +: +& +mut +CommandBufferTextureMemoryActions < A > @@ -3578,7 +3651,9 @@ ImplicitlyInitialized handle_texture_init ( dst_init_kind -cmd_buf +encoder +trackers +texture_memory_actions device destination copy_size @@ -3687,98 +3762,50 @@ self ) ; let -mut -token +cmd_buf = -Token +CommandBuffer : : -root +get_encoder ( -) -; -let -( -device_guard -mut -token -) -= hub -. -devices -. -read -( -& -mut -token +command_encoder_id ) +? ; let -( mut -cmd_buf_guard -mut -token -) +cmd_buf_data = -hub +cmd_buf . -command_buffers +data . -write +lock ( -& -mut -token ) ; let -cmd_buf +cmd_buf_data = -CommandBuffer -: -: -get_encoder_mut -( -& -mut -* -cmd_buf_guard -command_encoder_id -) -? -; -let +cmd_buf_data +. +as_mut ( -buffer_guard -_ ) -= -hub -. -buffers . -read +unwrap ( -& -mut -token ) ; let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -3798,11 +3825,15 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) . into @@ -3831,7 +3862,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -3867,7 +3898,44 @@ src_buffer src_pending ) = -cmd_buf +{ +let +buffer_guard += +hub +. +buffers +. +read +( +) +; +let +src_buffer += +buffer_guard +. +get +( +source +) +. +map_err +( +| +_ +| +TransferError +: +: +InvalidBuffer +( +source +) +) +? +; +cmd_buf_data . trackers . @@ -3875,10 +3943,7 @@ buffers . set_single ( -& -* -buffer_guard -source +src_buffer hal : : @@ -3899,6 +3964,7 @@ source ) ) ? +} ; let src_raw @@ -3972,6 +4038,7 @@ pending . into_hal ( +& src_buffer ) ) @@ -3982,19 +4049,53 @@ dst_buffer dst_pending ) = -cmd_buf -. -trackers +{ +let +buffer_guard += +hub . buffers . -set_single +read ( -& -* +) +; +let +dst_buffer += buffer_guard +. +get +( destination -hal +) +. +map_err +( +| +_ +| +TransferError +: +: +InvalidBuffer +( +destination +) +) +? +; +cmd_buf_data +. +trackers +. +buffers +. +set_single +( +dst_buffer +hal : : BufferUses @@ -4014,6 +4115,7 @@ destination ) ) ? +} ; let dst_raw @@ -4087,6 +4189,7 @@ pending . into_hal ( +& dst_buffer ) ) @@ -4447,7 +4550,7 @@ dest as initialized . -cmd_buf +cmd_buf_data . buffer_memory_init_actions . @@ -4457,9 +4560,14 @@ dst_buffer . initialization_status . +read +( +) +. create_action ( -destination +& +dst_buffer destination_offset . . @@ -4475,7 +4583,7 @@ ImplicitlyInitialized ) ) ; -cmd_buf +cmd_buf_data . buffer_memory_init_actions . @@ -4485,9 +4593,14 @@ src_buffer . initialization_status . +read +( +) +. create_action ( -source +& +src_buffer source_offset . . @@ -4538,7 +4651,7 @@ unwrap let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . @@ -4648,116 +4761,25 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -let cmd_buf = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub command_encoder_id ) ? ; let -( -buffer_guard -mut -token -) -= -hub -. -buffers -. -read -( -& -mut -token -) -; -let -( -texture_guard -_ -) -= -hub -. -textures -. -read -( -& -mut -token -) -; -let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -4777,11 +4799,15 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) . into @@ -4790,6 +4816,31 @@ into ) ; } +let +mut +cmd_buf_data += +cmd_buf +. +data +. +lock +( +) +; +let +cmd_buf_data += +cmd_buf_data +. +as_mut +( +) +. +unwrap +( +) +; # [ cfg @@ -4810,7 +4861,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -4839,6 +4890,53 @@ copy_size ) ; } +let +encoder += +& +mut +cmd_buf_data +. +encoder +; +let +tracker += +& +mut +cmd_buf_data +. +trackers +; +let +buffer_memory_init_actions += +& +mut +cmd_buf_data +. +buffer_memory_init_actions +; +let +texture_memory_actions += +& +mut +cmd_buf_data +. +texture_memory_actions +; +let +texture_guard += +hub +. +textures +. +read +( +) +; if copy_size . @@ -4991,7 +5089,9 @@ cases . handle_dst_texture_init ( -cmd_buf +encoder +tracker +texture_memory_actions device destination copy_size @@ -5006,20 +5106,54 @@ src_buffer src_pending ) = -cmd_buf -. -trackers +{ +let +buffer_guard += +hub . buffers . -set_single +read ( -& -* +) +; +let +src_buffer += buffer_guard +. +get +( source . buffer +) +. +map_err +( +| +_ +| +TransferError +: +: +InvalidBuffer +( +source +. +buffer +) +) +? +; +tracker +. +buffers +. +set_single +( +src_buffer hal : : @@ -5042,6 +5176,7 @@ buffer ) ) ? +} ; let src_raw @@ -5110,6 +5245,7 @@ pending . into_hal ( +& src_buffer ) ) @@ -5117,18 +5253,13 @@ src_buffer let dst_pending = -cmd_buf -. -trackers +tracker . textures . set_single ( dst_texture -destination -. -texture dst_range hal : @@ -5154,11 +5285,26 @@ texture ? ; let -dst_raw +dst_inner = dst_texture . inner +( +) +; +let +dst_raw += +dst_inner +. +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -5231,7 +5377,15 @@ pending . into_hal ( -dst_texture +dst_inner +. +as_ref +( +) +. +unwrap +( +) ) ) ; @@ -5370,8 +5524,6 @@ from ? ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -5380,11 +5532,14 @@ src_buffer . initialization_status . -create_action +read ( -source +) . -buffer +create_action +( +& +src_buffer source . layout @@ -5477,8 +5632,6 @@ hal_copy_size let cmd_buf_raw = -cmd_buf -. encoder . open @@ -5587,116 +5740,25 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -let cmd_buf = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub command_encoder_id ) ? ; let -( -buffer_guard -mut -token -) -= -hub -. -buffers -. -read -( -& -mut -token -) -; -let -( -texture_guard -_ -) -= -hub -. -textures -. -read -( -& -mut -token -) -; -let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -5716,11 +5778,15 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) . into @@ -5729,6 +5795,31 @@ into ) ; } +let +mut +cmd_buf_data += +cmd_buf +. +data +. +lock +( +) +; +let +cmd_buf_data += +cmd_buf_data +. +as_mut +( +) +. +unwrap +( +) +; # [ cfg @@ -5749,7 +5840,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -5778,6 +5869,53 @@ copy_size ) ; } +let +encoder += +& +mut +cmd_buf_data +. +encoder +; +let +tracker += +& +mut +cmd_buf_data +. +trackers +; +let +buffer_memory_init_actions += +& +mut +cmd_buf_data +. +buffer_memory_init_actions +; +let +texture_memory_actions += +& +mut +cmd_buf_data +. +texture_memory_actions +; +let +texture_guard += +hub +. +textures +. +read +( +) +; if copy_size . @@ -5930,7 +6068,9 @@ cases . handle_src_texture_init ( -cmd_buf +encoder +tracker +texture_memory_actions device source copy_size @@ -5942,18 +6082,13 @@ texture_guard let src_pending = -cmd_buf -. -trackers +tracker . textures . set_single ( src_texture -source -. -texture src_range hal : @@ -5979,11 +6114,26 @@ texture ? ; let -src_raw +src_inner = src_texture . inner +( +) +; +let +src_raw += +src_inner +. +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -6114,36 +6264,78 @@ src_pending map ( | -pending +pending +| +pending +. +into_hal +( +src_inner +. +as_ref +( +) +. +unwrap +( +) +) +) +; +let +( +dst_buffer +dst_pending +) += +{ +let +buffer_guard += +hub +. +buffers +. +read +( +) +; +let +dst_buffer += +buffer_guard +. +get +( +destination +. +buffer +) +. +map_err +( +| +_ | -pending -. -into_hal +TransferError +: +: +InvalidBuffer ( -src_texture +destination +. +buffer ) ) +? ; -let -( -dst_buffer -dst_pending -) -= -cmd_buf -. -trackers +tracker . buffers . set_single ( -& -* -buffer_guard -destination -. -buffer +dst_buffer hal : : @@ -6166,6 +6358,7 @@ buffer ) ) ? +} ; let dst_raw @@ -6243,6 +6436,7 @@ pending . into_hal ( +& dst_buffer ) ) @@ -6382,8 +6576,6 @@ from ? ; } -cmd_buf -. buffer_memory_init_actions . extend @@ -6392,11 +6584,14 @@ dst_buffer . initialization_status . -create_action +read ( -destination +) . -buffer +create_action +( +& +dst_buffer destination . layout @@ -6489,8 +6684,6 @@ hal_copy_size let cmd_buf_raw = -cmd_buf -. encoder . open @@ -6606,120 +6799,25 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -mut -cmd_buf_guard -mut -token -) -= -hub -. -command_buffers -. -write -( -& -mut -token -) -; -let cmd_buf = CommandBuffer : : -get_encoder_mut +get_encoder ( -& -mut -* -cmd_buf_guard +hub command_encoder_id ) ? ; let -( -_ -mut -token -) -= -hub -. -buffers -. -read -( -& -mut -token -) -; -/ -/ -skip -token -let -( -texture_guard -_ -) -= -hub -. -textures -. -read -( -& -mut -token -) -; -let device = & -device_guard -[ cmd_buf . -device_id -. -value -] +device ; if ! @@ -6739,11 +6837,15 @@ InvalidDevice ( cmd_buf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ) . into @@ -6752,6 +6854,31 @@ into ) ; } +let +mut +cmd_buf_data += +cmd_buf +. +data +. +lock +( +) +; +let +cmd_buf_data += +cmd_buf_data +. +as_mut +( +) +. +unwrap +( +) +; # [ cfg @@ -6772,7 +6899,7 @@ mut list ) = -cmd_buf +cmd_buf_data . commands { @@ -6801,6 +6928,44 @@ copy_size ) ; } +let +encoder += +& +mut +cmd_buf_data +. +encoder +; +let +tracker += +& +mut +cmd_buf_data +. +trackers +; +let +texture_memory_actions += +& +mut +cmd_buf_data +. +texture_memory_actions +; +let +texture_guard += +hub +. +textures +. +read +( +) +; if copy_size . @@ -6878,6 +7043,15 @@ texture ? ; let +src_inner += +src_texture +. +inner +( +) +; +let dst_texture = texture_guard @@ -6906,6 +7080,15 @@ texture ) ? ; +let +dst_inner += +dst_texture +. +inner +( +) +; / / src @@ -7179,7 +7362,9 @@ cases . handle_src_texture_init ( -cmd_buf +encoder +tracker +texture_memory_actions device source copy_size @@ -7190,7 +7375,9 @@ texture_guard ; handle_dst_texture_init ( -cmd_buf +encoder +tracker +texture_memory_actions device destination copy_size @@ -7202,7 +7389,7 @@ texture_guard let src_pending = -cmd_buf +cmd_buf_data . trackers . @@ -7211,9 +7398,6 @@ textures set_single ( src_texture -source -. -texture src_range hal : @@ -7241,9 +7425,15 @@ texture let src_raw = -src_texture +src_inner . -inner +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -7344,7 +7534,15 @@ pending . into_hal ( -src_texture +src_inner +. +as_ref +( +) +. +unwrap +( +) ) ) . @@ -7355,7 +7553,7 @@ collect let dst_pending = -cmd_buf +cmd_buf_data . trackers . @@ -7364,9 +7562,6 @@ textures set_single ( dst_texture -destination -. -texture dst_range hal : @@ -7394,9 +7589,15 @@ texture let dst_raw = -dst_texture +dst_inner . -inner +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -7470,7 +7671,15 @@ pending . into_hal ( -dst_texture +dst_inner +. +as_ref +( +) +. +unwrap +( +) ) ) ) @@ -7588,7 +7797,7 @@ hal_copy_size let cmd_buf_raw = -cmd_buf +cmd_buf_data . encoder . diff --git a/third_party/rust/wgpu-core/src/conv.rs b/third_party/rust/wgpu-core/src/conv.rs index 608efde047093..03454f131a6f2 100644 --- a/third_party/rust/wgpu-core/src/conv.rs +++ b/third_party/rust/wgpu-core/src/conv.rs @@ -1,8 +1,20 @@ use +wgt +: +: +TextureFormatFeatures +; +use crate : : resource +: +: +{ +self +TextureDescriptor +} ; pub fn @@ -864,6 +876,183 @@ u } pub fn +map_texture_usage_for_texture +( +desc +: +& +TextureDescriptor +format_features +: +& +TextureFormatFeatures +) +- +> +hal +: +: +TextureUses +{ +/ +/ +Enforce +having +COPY_DST +/ +DEPTH_STENCIL_WRITE +/ +COLOR_TARGET +otherwise +we +/ +/ +wouldn +' +t +be +able +to +initialize +the +texture +. +map_texture_usage +( +desc +. +usage +desc +. +format +. +into +( +) +) +| +if +desc +. +format +. +is_depth_stencil_format +( +) +{ +hal +: +: +TextureUses +: +: +DEPTH_STENCIL_WRITE +} +else +if +desc +. +usage +. +contains +( +wgt +: +: +TextureUsages +: +: +COPY_DST +) +{ +hal +: +: +TextureUses +: +: +COPY_DST +/ +/ +( +set +already +) +} +else +{ +/ +/ +Use +COPY_DST +only +if +we +can +' +t +use +COLOR_TARGET +if +format_features +. +allowed_usages +. +contains +( +wgt +: +: +TextureUsages +: +: +RENDER_ATTACHMENT +) +& +& +desc +. +dimension += += +wgt +: +: +TextureDimension +: +: +D2 +/ +/ +Render +targets +dimension +must +be +2d +{ +hal +: +: +TextureUses +: +: +COLOR_TARGET +} +else +{ +hal +: +: +TextureUses +: +: +COPY_DST +} +} +} +pub +fn map_texture_usage_from_hal ( uses diff --git a/third_party/rust/wgpu-core/src/device/any_device.rs b/third_party/rust/wgpu-core/src/device/any_device.rs new file mode 100644 index 0000000000000..b31ca3026c813 --- /dev/null +++ b/third_party/rust/wgpu-core/src/device/any_device.rs @@ -0,0 +1,833 @@ +use +super +: +: +Device +; +/ +/ +/ +The +AnyDevice +type +: +a +pointer +to +a +Device +< +A +> +for +any +backend +A +. +use +crate +: +: +hal_api +: +: +HalApi +; +use +std +: +: +any +: +: +Any +; +use +std +: +: +fmt +; +use +std +: +: +sync +: +: +Arc +; +/ +/ +/ +A +pointer +to +a +Device +< +A +> +for +any +backend +A +. +/ +/ +/ +/ +/ +/ +Any +AnyDevice +is +just +like +an +Arc +< +Device +< +A +> +> +except +that +the +/ +/ +/ +A +type +parameter +is +erased +. +To +access +the +Device +you +must +/ +/ +/ +downcast +to +a +particular +backend +with +the +\ +[ +downcast_ref +\ +] +or +/ +/ +/ +\ +[ +downcast_clone +\ +] +methods +. +pub +struct +AnyDevice +( +Arc +< +dyn +Any ++ +' +static +> +) +; +impl +AnyDevice +{ +/ +/ +/ +Return +an +AnyDevice +that +holds +an +owning +Arc +pointer +to +device +. +pub +fn +new +< +A +: +HalApi +> +( +device +: +Arc +< +Device +< +A +> +> +) +- +> +AnyDevice +{ +AnyDevice +( +device +) +} +/ +/ +/ +If +self +is +an +Arc +< +Device +< +A +> +> +return +a +reference +to +the +/ +/ +/ +device +. +pub +fn +downcast_ref +< +A +: +HalApi +> +( +& +self +) +- +> +Option +< +& +Device +< +A +> +> +{ +self +. +0 +. +downcast_ref +: +: +< +Device +< +A +> +> +( +) +} +/ +/ +/ +If +self +is +an +Arc +< +Device +< +A +> +> +return +a +clone +of +that +. +pub +fn +downcast_clone +< +A +: +HalApi +> +( +& +self +) +- +> +Option +< +Arc +< +Device +< +A +> +> +> +{ +/ +/ +Arc +: +: +downcast +returns +Arc +< +T +> +but +requires +that +T +be +Sync +and +/ +/ +Send +and +this +is +not +the +case +for +Device +in +wasm +builds +. +/ +/ +/ +/ +But +as +far +as +I +can +see +Arc +: +: +downcast +has +no +particular +reason +to +/ +/ +require +that +T +be +Sync +and +Send +; +the +steps +used +here +are +sound +. +if +( +self +. +0 +) +. +is +: +: +< +Device +< +A +> +> +( +) +{ +/ +/ +Get +an +owned +Arc +. +let +clone += +self +. +0 +. +clone +( +) +; +/ +/ +Turn +the +Arc +which +is +a +pointer +to +an +ArcInner +struct +into +/ +/ +a +pointer +to +the +ArcInner +' +s +data +field +. +Carry +along +the +/ +/ +vtable +from +the +original +Arc +. +let +raw_erased +: +* +const +( +dyn +Any ++ +' +static +) += +Arc +: +: +into_raw +( +clone +) +; +/ +/ +Remove +the +vtable +and +supply +the +concrete +type +of +the +data +. +let +raw_typed +: +* +const +Device +< +A +> += +raw_erased +. +cast +: +: +< +Device +< +A +> +> +( +) +; +/ +/ +Convert +the +pointer +to +the +data +field +back +into +a +pointer +to +/ +/ +the +ArcInner +and +restore +reference +- +counting +behavior +. +let +arc_typed +: +Arc +< +Device +< +A +> +> += +unsafe +{ +/ +/ +Safety +: +/ +/ +- +We +checked +that +the +dyn +Any +was +indeed +a +Device +< +A +> +above +. +/ +/ +- +We +' +re +calling +Arc +: +: +from_raw +on +the +same +pointer +returned +/ +/ +by +Arc +: +: +into_raw +except +that +we +stripped +off +the +vtable +/ +/ +pointer +. +/ +/ +- +The +pointer +must +still +be +live +because +we +' +ve +borrowed +self +/ +/ +which +holds +another +reference +to +it +. +/ +/ +- +The +format +of +a +ArcInner +< +dyn +Any +> +must +be +the +same +as +/ +/ +that +of +an +ArcInner +< +Device +< +A +> +> +or +else +AnyDevice +: +: +new +/ +/ +wouldn +' +t +be +possible +. +Arc +: +: +from_raw +( +raw_typed +) +} +; +Some +( +arc_typed +) +} +else +{ +None +} +} +} +impl +fmt +: +: +Debug +for +AnyDevice +{ +fn +fmt +( +& +self +f +: +& +mut +fmt +: +: +Formatter +< +' +_ +> +) +- +> +fmt +: +: +Result +{ +f +. +write_str +( +" +AnyDevice +" +) +} +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +Send +for +AnyDevice +{ +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +Sync +for +AnyDevice +{ +} diff --git a/third_party/rust/wgpu-core/src/device/global.rs b/third_party/rust/wgpu-core/src/device/global.rs index ac0853e52c073..b787253e50dc6 100644 --- a/third_party/rust/wgpu-core/src/device/global.rs +++ b/third_party/rust/wgpu-core/src/device/global.rs @@ -24,12 +24,6 @@ crate : { binding_model -: -: -{ -self -BindGroupLayout -} command conv device @@ -42,10 +36,10 @@ life WaitIdleError map_buffer queue -Device DeviceError DeviceLostClosure HostMap +IMPLICIT_FAILURE } global : @@ -55,10 +49,6 @@ hal_api : : HalApi -hub -: -: -Token id : : @@ -66,6 +56,7 @@ id self AdapterId DeviceId +QueueId SurfaceId } identity @@ -94,9 +85,7 @@ resource : { self -Buffer BufferAccessResult -BufferMapState } resource : @@ -104,12 +93,8 @@ resource { BufferAccessError BufferMapOperation -TextureClearMode +Resource } -storage -: -: -InvalidId validation : : @@ -119,27 +104,21 @@ Label LabelHelpers as _ -Stored } ; use hal : : -{ -CommandEncoder -as -_ Device as _ -} ; use -smallvec +parking_lot : : -SmallVec +RwLock ; use wgt @@ -160,12 +139,18 @@ borrow : Cow iter -mem ops : : Range ptr +sync +: +: +atomic +: +: +Ordering } ; use @@ -173,11 +158,9 @@ super : : { -BufferMapPendingClosure ImplicitPipelineIds InvalidDevice UserClosures -IMPLICIT_FAILURE } ; impl @@ -232,22 +215,7 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( surface_guard -mut -token -) = self . @@ -255,17 +223,10 @@ surfaces . read ( -& -mut -token ) ; let -( adapter_guard -mut -_token -) = hub . @@ -273,9 +234,6 @@ adapters . read ( -& -mut -token ) ; let @@ -538,22 +496,7 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( surface_guard -mut -token -) = self . @@ -561,17 +504,10 @@ surfaces . read ( -& -mut -token ) ; let -( adapter_guard -mut -_token -) = hub . @@ -579,9 +515,6 @@ adapters . read ( -& -mut -token ) ; let @@ -678,38 +611,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) +device = hub . devices . -read -( -& -mut -token -) -; -let -device -= -device_guard -. get ( device_id @@ -728,7 +635,9 @@ if ! device . -valid +is_valid +( +) { return Err @@ -782,38 +691,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) +device = hub . devices . -read -( -& -mut -token -) -; -let -device -= -device_guard -. get ( device_id @@ -832,7 +715,9 @@ if ! device . -valid +is_valid +( +) { return Err @@ -890,38 +775,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) +device = hub . devices . -read -( -& -mut -token -) -; -let -device -= -device_guard -. get ( device_id @@ -940,7 +799,9 @@ if ! device . -valid +is_valid +( +) { return Err @@ -1034,17 +895,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -1052,29 +902,16 @@ hub buffers . prepare +: +: +< +G +> ( id_in ) ; let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let error = loop @@ -1083,7 +920,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -1103,6 +942,7 @@ _ ) = > +{ break DeviceError : @@ -1112,13 +952,17 @@ Invalid into ( ) +; +} } ; if ! device . -valid +is_valid +( +) { break DeviceError @@ -1150,7 +994,27 @@ not be zero . -break +let +id += +fid +. +assign_error +( +desc +. +label +. +borrow_or_default +( +) +) +; +return +( +id +Some +( resource : : @@ -1163,6 +1027,8 @@ desc . usage ) +) +) ; } # @@ -1181,12 +1047,18 @@ let Some ( ref +mut trace ) = +* device . trace +. +lock +( +) { let mut @@ -1201,6 +1073,9 @@ clone let mapped_at_creation = +std +: +: mem : : @@ -1250,10 +1125,6 @@ COPY_DST } trace . -lock -( -) -. add ( trace @@ -1275,7 +1146,6 @@ desc ; } let -mut buffer = match @@ -1283,7 +1153,6 @@ device . create_buffer ( -device_id desc false ) @@ -1301,25 +1170,75 @@ e ) = > -break -e -} -; +{ let -ref_count +id = -buffer +fid +. +assign_error +( +desc . -life_guard +label . -add_ref +borrow_or_default +( +) +) +; +return +( +id +Some ( +e ) +) +; +} +} ; let -buffer_use +( +id +resource +) = -if +fid +. +assign +( +buffer +) +; +log +: +: +info +! +( +" +Created +Buffer +{ +: +? +} +with +{ +: +? +} +" +id +desc +) +; +let +buffer_use += +if ! desc . @@ -1368,7 +1287,7 @@ start let map_size = -buffer +resource . size ; @@ -1399,13 +1318,13 @@ else match map_buffer ( -& device . raw +( +) & -mut -buffer +resource 0 map_size HostMap @@ -1428,24 +1347,10 @@ e = > { -let -raw -= -buffer -. -raw -. -unwrap -( -) -; device . lock_life ( -& -mut -token ) . schedule_resource_destruction @@ -1458,26 +1363,53 @@ TempResource : Buffer ( -raw +resource ) ! 0 ) ; -break +hub +. +buffers +. +force_replace_with_error +( +id +desc +. +label +. +borrow_or_default +( +) +) +; +return +( +id +Some +( e . into ( ) +) +) ; } } } ; -buffer +* +resource . map_state +. +lock +( +) = resource : @@ -1577,7 +1509,6 @@ false } ; let -mut stage = match @@ -1585,7 +1516,6 @@ device . create_buffer ( -device_id & stage_desc true @@ -1605,24 +1535,10 @@ e = > { -let -raw -= -buffer -. -raw -. -unwrap -( -) -; device . lock_life ( -& -mut -token ) . schedule_resource_destruction @@ -1635,27 +1551,59 @@ TempResource : Buffer ( -raw +resource ) ! 0 ) ; -break +hub +. +buffers +. +force_replace_with_error +( +id +desc +. +label +. +borrow_or_default +( +) +) +; +return +( +id +Some +( e +) +) ; } } ; let -stage_buffer +stage_fid = -stage +hub . -raw +buffers . -unwrap +request +( +) +; +let +stage += +stage_fid +. +init ( +stage ) ; let @@ -1667,11 +1615,16 @@ unsafe device . raw +( +) . map_buffer ( -& -stage_buffer +stage +. +raw +( +) 0 . . @@ -1696,17 +1649,6 @@ e > { let -raw -= -buffer -. -raw -. -unwrap -( -) -; -let mut life_lock = @@ -1714,9 +1656,6 @@ device . lock_life ( -& -mut -token ) ; life_lock @@ -1731,7 +1670,7 @@ TempResource : Buffer ( -raw +resource ) ! 0 @@ -1749,13 +1688,33 @@ TempResource : Buffer ( -stage_buffer +stage ) ! 0 ) ; -break +hub +. +buffers +. +force_replace_with_error +( +id +desc +. +label +. +borrow_or_default +( +) +) +; +return +( +id +Some +( DeviceError : : @@ -1767,6 +1726,8 @@ e into ( ) +) +) ; } } @@ -1774,7 +1735,7 @@ into assert_eq ! ( -buffer +resource . size % @@ -1834,7 +1795,7 @@ as_ptr ( ) 0 -buffer +resource . size as @@ -1842,16 +1803,20 @@ usize ) } ; -buffer +resource . initialization_status . +write +( +) +. drain ( 0 . . -buffer +resource . size ) @@ -1860,19 +1825,28 @@ stage . initialization_status . +write +( +) +. drain ( 0 . . -buffer +resource . size ) ; -buffer +* +resource . map_state +. +lock +( +) = resource : @@ -1894,6 +1868,8 @@ mapping . is_coherent stage_buffer +: +stage } ; hal @@ -1905,42 +1881,6 @@ BufferUses COPY_DST } ; -let -id -= -fid -. -assign -( -buffer -& -mut -token -) -; -log -: -: -trace -! -( -" -Device -: -: -create_buffer -- -> -{ -: -? -} -" -id -. -0 -) -; device . trackers @@ -1954,15 +1894,13 @@ buffers insert_single ( id -ref_count +resource buffer_use ) ; return ( id -. -0 None ) ; @@ -1982,9 +1920,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -2420,17 +2355,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -2438,6 +2362,11 @@ hub buffers . prepare +: +: +< +G +> ( id_in ) @@ -2451,9 +2380,6 @@ label borrow_or_default ( ) -& -mut -token ) ; } @@ -2495,17 +2421,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -2513,28 +2428,15 @@ hub render_bundles . prepare +: +: +< +G +> ( id_in ) ; -let -( -_ -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; fid . assign_error @@ -2544,9 +2446,6 @@ label borrow_or_default ( ) -& -mut -token ) ; } @@ -2614,17 +2513,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -2632,6 +2520,11 @@ hub textures . prepare +: +: +< +G +> ( id_in ) @@ -2645,9 +2538,6 @@ label borrow_or_default ( ) -& -mut -token ) ; } @@ -2704,43 +2594,11 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let last_submission = { let -( buffer_guard -_ -) = hub . @@ -2748,9 +2606,6 @@ buffers . write ( -& -mut -token ) ; match @@ -2769,9 +2624,9 @@ buffer > buffer . -life_guard +info . -life_count +submission_index ( ) Err @@ -2789,7 +2644,9 @@ Ok } } ; -device_guard +hub +. +devices . get ( @@ -2811,9 +2668,6 @@ Invalid wait_for_submit ( last_submission -& -mut -token ) } # @@ -2883,57 +2737,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) +device = hub . devices . -read -( -& -mut -token -) -; -let -( -mut -buffer_guard -_ -) -= -hub -. -buffers -. -write -( -& -mut -token -) -; -let -device -= -device_guard -. get ( device_id @@ -2955,7 +2764,9 @@ if ! device . -valid +is_valid +( +) { return Err @@ -2974,9 +2785,11 @@ into let buffer = -buffer_guard +hub +. +buffers . -get_mut +get ( buffer_id ) @@ -3039,23 +2852,19 @@ let Some ( ref +mut trace ) = +* device . trace -{ -let -mut -trace -= -trace . lock ( ) -; +{ let data_path = @@ -3114,12 +2923,6 @@ raw_buf buffer . raw -. -as_ref -( -) -. -unwrap ( ) ; @@ -3131,6 +2934,8 @@ mapping device . raw +( +) . map_buffer ( @@ -3191,6 +2996,8 @@ is_coherent device . raw +( +) . flush_mapped_ranges ( @@ -3219,6 +3026,8 @@ u64 device . raw +( +) . unmap_buffer ( @@ -3309,57 +3118,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) +device = hub . devices . -read -( -& -mut -token -) -; -let -( -mut -buffer_guard -_ -) -= -hub -. -buffers -. -write -( -& -mut -token -) -; -let -device -= -device_guard -. get ( device_id @@ -3381,7 +3145,9 @@ if ! device . -valid +is_valid +( +) { return Err @@ -3400,9 +3166,11 @@ into let buffer = -buffer_guard +hub . -get_mut +buffers +. +get ( buffer_id ) @@ -3455,12 +3223,6 @@ raw_buf buffer . raw -. -as_ref -( -) -. -unwrap ( ) ; @@ -3472,6 +3234,8 @@ mapping device . raw +( +) . map_buffer ( @@ -3508,6 +3272,8 @@ is_coherent device . raw +( +) . invalidate_mapped_ranges ( @@ -3560,6 +3326,8 @@ len device . raw +( +) . unmap_buffer ( @@ -3664,19 +3432,6 @@ destroy ) ; let -map_closure -; -/ -/ -Restrict -the -locks -to -this -scope -. -{ -let hub = A @@ -3687,75 +3442,30 @@ hub self ) ; -let -mut -token -= -Token +log : : -root -( -) -; -/ -/ -TODO -: -lock -pending -writes -separately -keep -the -device -read -- -only -let -( -mut -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -log -: -: -trace -! +debug +! ( " Buffer -: -: -destroy { -buffer_id : ? } +is +asked +to +be +dropped " +buffer_id ) ; let -( mut buffer_guard -_ -) = hub . @@ -3763,9 +3473,6 @@ buffers . write ( -& -mut -token ) ; let @@ -3793,168 +3500,137 @@ Invalid ) ? ; -let -device -= -& -mut -device_guard -[ buffer . -device_id -. -value -] -; -map_closure -= -match +destroy +( +) +} +pub +fn +buffer_drop +< +A +: +HalApi +> +( & -buffer -. -map_state +self +buffer_id +: +id +: +: +BufferId +wait +: +bool +) { -& -BufferMapState +profiling : : -Waiting +scope +! ( -. -. -) -/ -/ -To -get -the -proper -callback -behavior -. -| -& -BufferMapState +" +Buffer : : -Init -{ -. -. -} -| -& -BufferMapState +drop +" +) +; +log : : -Active +debug +! +( +" +Buffer { -. -. +: +? } -= -> -{ -self -. -buffer_unmap_inner -( +is +asked +to +be +dropped +" buffer_id -buffer -device -) -. -unwrap_or -( -None ) -} -_ -= -> -None -} ; -# -[ -cfg -( -feature +let +hub = -" -trace -" +A +: +: +hub +( +self ) -] +; if let Some ( -ref -trace +buffer ) = -device +hub . -trace -{ -trace +buffers . -lock +unregister ( +buffer_id ) +{ +if +buffer . -add +ref_count ( -trace -: -: -Action -: -: -FreeBuffer +) += += +1 +{ +buffer +. +destroy ( -buffer_id ) +. +ok +( ) ; } let -raw +last_submit_index = buffer . -raw -. -take -( -) +info . -ok_or +submission_index ( -resource -: -: -DestroyError -: -: -AlreadyDestroyed ) -? ; let -temp +device = -queue -: -: -TempResource -: -: -Buffer +buffer +. +device +. +clone ( -raw ) ; if @@ -3962,9 +3638,21 @@ device . pending_writes . +lock +( +) +. +as_ref +( +) +. +unwrap +( +) +. dst_buffers . -contains +contains_key ( & buffer_id @@ -3972,97 +3660,93 @@ buffer_id { device . -pending_writes +lock_life +( +) . -temp_resources +future_suspected_buffers . push ( -temp +buffer ) ; } else { -let -last_submit_index -= -buffer -. -life_guard -. -life_count -( -) -; -drop -( -buffer_guard -) -; device . lock_life ( -& -mut -token ) . -schedule_resource_destruction +suspected_resources +. +insert ( -temp -last_submit_index +buffer_id +buffer ) ; } -} -/ -/ -Note -: -outside -the -scope -where -locks -are -held -when -calling -the -callback if -let -Some +wait +{ +match +device +. +wait_for_submit +( +last_submit_index +) +{ +Ok ( ( -operation -status ) ) = -map_closure -{ -operation -. -callback -. -call +> ( -status ) -; -} -Ok -( +Err ( +e ) += +> +log +: +: +error +! +( +" +Failed +to +wait +for +buffer +{ +: +? +} +: +{ +: +? +} +" +buffer_id +e ) } +} +} +} pub fn -buffer_drop +device_create_texture < A : @@ -4071,47 +3755,54 @@ HalApi ( & self -buffer_id +device_id : -id +DeviceId +desc : +& +resource : -BufferId -wait : -bool -) -{ -profiling +TextureDescriptor +id_in : +Input +< +G +id : -scope -! +: +TextureId +> +) +- +> ( -" -Buffer +id : : -drop -" +TextureId +Option +< +resource +: +: +CreateTextureError +> ) -; -log +{ +profiling : : -trace +scope ! ( " -Buffer -: +Device : -drop -{ -buffer_id : -? -} +create_texture " ) ; @@ -4127,283 +3818,305 @@ self ) ; let -mut -token +fid = -Token +hub +. +textures +. +prepare : : -root +< +G +> ( +id_in ) ; let -( -ref_count -last_submit_index -device_id -) +error = +loop { let -( -mut -buffer_guard -_ -) +device = +match hub . -buffers -. -write -( -& -mut -token -) -; -match -buffer_guard +devices . -get_occupied_or_destroyed_mut +get ( -buffer_id +device_id ) { Ok ( -buffer +device ) = > -{ -let -ref_count -= -buffer -. -life_guard -. -ref_count -. -take -( -) -. -unwrap +device +Err ( +_ ) -; -let -last_submit_index = -buffer -. -life_guard +> +break +DeviceError +: +: +Invalid . -life_count +into ( ) +} ; -( -ref_count -last_submit_index -buffer -. -device_id +if +! +device . -value -) -} -Err +is_valid ( -InvalidId ) -= -> { -hub -. -buffers +break +DeviceError +: +: +Lost . -unregister_locked +into ( -buffer_id -& -mut -* -buffer_guard ) ; -return -; } -} -} -; -let +# +[ +cfg ( -device_guard -mut -token -) +feature = -hub -. -devices -. -read -( -& -mut -token +" +trace +" ) -; -let -device -= -& -device_guard -[ -device_id ] -; -{ +if let -mut -life_lock -= -device -. -lock_life +Some ( -& +ref mut -token +trace ) -; -if += +* device . -pending_writes -. -dst_buffers +trace . -contains +lock ( -& -buffer_id ) { -life_lock -. -future_suspected_buffers +trace . -push +add ( -Stored -{ -value +trace : -id +: +Action : : -Valid +CreateTexture ( -buffer_id -) -ref_count -} -) -; -} -else -{ -drop +fid +. +id ( -ref_count ) -; -life_lock -. -suspected_resources -. -buffers +desc . -push -( -id -: -: -Valid +clone ( -buffer_id +) ) ) ; } -} -if -wait -{ +let +texture += match device . -wait_for_submit +create_texture ( -last_submit_index & -mut -token +device +. +adapter +desc ) { Ok ( -( -) +texture ) = > -( -) +texture Err ( -e +error ) = > +break +error +} +; +let +( +id +resource +) += +fid +. +assign +( +texture +) +; log : : -error +info ! ( " -Failed -to -wait -for -buffer +Created +Texture { : ? } -: +with { : ? } " -buffer_id -e +id +desc ) +; +device +. +trackers +. +lock +( +) +. +textures +. +insert_single +( +id +resource +hal +: +: +TextureUses +: +: +UNINITIALIZED +) +; +return +( +id +None +) +; } +; +let +id += +fid +. +assign_error +( +desc +. +label +. +borrow_or_default +( +) +) +; +( +id +Some +( +error +) +) } -} +/ +/ +/ +# +Safety +/ +/ +/ +/ +/ +/ +- +hal_texture +must +be +created +from +device_id +corresponding +raw +handle +. +/ +/ +/ +- +hal_texture +must +be +created +respecting +desc +/ +/ +/ +- +hal_texture +must +be +initialized pub +unsafe fn -device_create_texture +create_texture_from_hal < A : @@ -4412,6 +4125,12 @@ HalApi ( & self +hal_texture +: +A +: +: +Texture device_id : DeviceId @@ -4459,7 +4178,7 @@ scope Device : : -create_texture +create_texture_from_hal " ) ; @@ -4475,17 +4194,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -4493,47 +4201,16 @@ hub textures . prepare +: +: +< +G +> ( id_in ) ; let -( -adapter_guard -mut -token -) -= -hub -. -adapters -. -read -( -& -mut -token -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let error = loop @@ -4542,7 +4219,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -4577,7 +4256,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -4590,6 +4271,27 @@ into ) ; } +/ +/ +NB +: +Any +change +done +through +the +raw +texture +handle +will +not +be +/ +/ +recorded +in +the +replay # [ cfg @@ -4606,18 +4308,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -4644,38 +4348,49 @@ clone ; } let -adapter +format_features = +match +device +. +describe_format_features +( & -adapter_guard -[ device . -adapter_id +adapter +desc . -value -] -; -let -texture -= -match -device +format +) . -create_texture +map_err +( +| +error +| +resource +: +: +CreateTextureError +: +: +MissingFeatures ( -device_id -adapter desc +. +format +error +) ) { Ok ( -texture +features ) = > -texture +features Err ( error @@ -4687,50 +4402,126 @@ error } ; let -ref_count +mut +texture = +device +. +create_texture_from_hal +( +hal_texture +conv +: +: +map_texture_usage +( +desc +. +usage +desc +. +format +. +into +( +) +) +desc +format_features +resource +: +: +TextureClearMode +: +: +None +) +; +if +desc +. +usage +. +contains +( +wgt +: +: +TextureUsages +: +: +COPY_DST +) +{ texture . -life_guard +hal_usage +| += +hal +: +: +TextureUses +: +: +COPY_DST +; +} +texture . -add_ref +initialization_status += +RwLock +: +: +new +( +TextureInitTracker +: +: +new ( +desc +. +mip_level_count +0 +) ) ; let +( id +resource +) = fid . assign ( texture -& -mut -token ) ; log : : -trace +info ! ( " -Device -: +Created +Texture +{ : -create_texture -- -> +? +} +with { : ? } " id -. -0 +desc ) ; device @@ -4746,9 +4537,7 @@ textures insert_single ( id -. -0 -ref_count +resource hal : : @@ -4761,8 +4550,6 @@ UNINITIALIZED return ( id -. -0 None ) ; @@ -4782,9 +4569,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -4807,7 +4591,7 @@ Safety / / - -hal_texture +hal_buffer must be created @@ -4821,7 +4605,7 @@ handle / / - -hal_texture +hal_buffer must be created @@ -4831,14 +4615,14 @@ desc / / - -hal_texture +hal_buffer must be initialized pub unsafe fn -create_texture_from_hal +create_buffer_from_hal < A : @@ -4847,12 +4631,12 @@ HalApi ( & self -hal_texture +hal_buffer : A : : -Texture +Buffer device_id : DeviceId @@ -4862,7 +4646,7 @@ desc resource : : -TextureDescriptor +BufferDescriptor id_in : Input @@ -4871,7 +4655,7 @@ G id : : -TextureId +BufferId > ) - @@ -4880,13 +4664,13 @@ TextureId id : : -TextureId +BufferId Option < resource : : -CreateTextureError +CreateBufferError > ) { @@ -4900,7 +4684,7 @@ scope Device : : -create_texture_from_hal +create_buffer " ) ; @@ -4916,52 +4700,29 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -fid +fid = hub . -textures +buffers . prepare +: +: +< +G +> ( id_in ) ; let -( -adapter_guard -mut -token -) +error = -hub -. -adapters -. -read -( -& -mut -token -) -; +loop +{ let -( device_guard -mut -token -) = hub . @@ -4969,17 +4730,9 @@ devices . read ( -& -mut -token ) ; let -error -= -loop -{ -let device = match @@ -5018,7 +4771,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -5041,7 +4796,7 @@ done through the raw -texture +buffer handle will not @@ -5067,20 +4822,23 @@ if let Some ( -ref trace ) = device . trace -{ -trace . lock ( ) . +as_mut +( +) +{ +trace +. add ( trace @@ -5089,7 +4847,7 @@ trace Action : : -CreateTexture +CreateBuffer ( fid . @@ -5106,193 +4864,50 @@ clone ; } let -adapter -= -& -adapter_guard -[ -device -. -adapter_id -. -value -] -; -let -format_features -= -match -device -. -describe_format_features -( -adapter -desc -. -format -) -. -map_err -( -| -error -| -resource -: -: -CreateTextureError -: -: -MissingFeatures -( -desc -. -format -error -) -) -{ -Ok -( -features -) -= -> -features -Err -( -error -) -= -> -break -error -} -; -let -mut -texture +buffer = device . -create_texture_from_hal -( -hal_texture -conv -: -: -map_texture_usage -( -desc -. -usage -desc -. -format -. -into -( -) -) -device_id -desc -format_features -TextureClearMode -: -: -None -) -; -if -desc -. -usage -. -contains -( -wgt -: -: -TextureUsages -: -: -COPY_DST -) -{ -texture -. -hal_usage -| -= -hal -: -: -TextureUses -: -: -COPY_DST -; -} -texture -. -initialization_status -= -TextureInitTracker -: -: -new +create_buffer_from_hal ( +hal_buffer desc -. -mip_level_count -0 ) ; let -ref_count -= -texture -. -life_guard -. -add_ref ( -) -; -let id +buffer +) = fid . assign ( -texture -& -mut -token +buffer ) ; log : : -trace +info ! ( " -Device -: +Created +buffer +{ : -create_texture -- -> +? +} +with { : ? } " id -. -0 +desc ) ; device @@ -5303,28 +4918,26 @@ lock ( ) . -textures +buffers . insert_single ( id -. -0 -ref_count +buffer hal : : -TextureUses +BufferUses : : -UNINITIALIZED +empty +( +) ) ; return ( id -. -0 None ) ; @@ -5344,9 +4957,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -5357,50 +4967,9 @@ error ) ) } -/ -/ -/ -# -Safety -/ -/ -/ -/ -/ -/ -- -hal_buffer -must -be -created -from -device_id -corresponding -raw -handle -. -/ -/ -/ -- -hal_buffer -must -be -created -respecting -desc -/ -/ -/ -- -hal_buffer -must -be -initialized pub -unsafe fn -create_buffer_from_hal +texture_label < A : @@ -5409,48 +4978,61 @@ HalApi ( & self -hal_buffer -: -A +id : +id : -Buffer -device_id : -DeviceId -desc +TextureId +) +- +> +String +{ +A : -& -resource : +hub +( +self +) +. +textures +. +label_for_resource +( +id +) +} +pub +fn +texture_destroy +< +A : -BufferDescriptor -id_in +HalApi +> +( +& +self +texture_id : -Input -< -G id : : -BufferId -> +TextureId ) - > -( -id -: -: -BufferId -Option +Result < +( +) resource : : -CreateBufferError +DestroyError > -) { profiling : @@ -5459,10 +5041,29 @@ scope ! ( " -Device +Texture : : -create_buffer +destroy +" +) +; +log +: +: +trace +! +( +" +Texture +: +: +destroy +{ +texture_id +: +? +} " ) ; @@ -5477,125 +5078,69 @@ hub self ) ; -let -mut -token -= -Token +log : : -root -( -) -; -let -fid -= -hub -. -buffers -. -prepare +debug +! ( -id_in +" +Texture +{ +: +? +} +is +destroyed +" +texture_id ) ; let -( -device_guard mut -token -) +texture_guard = hub . -devices +textures . -read +write ( -& -mut -token ) ; let -error -= -loop -{ -let -device +texture = -match -device_guard +texture_guard . -get -( -device_id -) -{ -Ok +get_and_mark_destroyed ( -device +texture_id ) -= -> -device -Err +. +map_err ( +| _ -) -= -> -break -DeviceError +| +resource +: +: +DestroyError : : Invalid -. -into -( ) -} +? ; -if -! +let device += +& +texture . -valid -{ -break -DeviceError -: -: -Lost -. -into -( -) +device ; -} -/ -/ -NB -: -Any -change -done -through -the -raw -buffer -handle -will -not -be -/ -/ -recorded -in -the -replay # [ cfg @@ -5612,18 +5157,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -5633,209 +5180,171 @@ trace Action : : -CreateBuffer -( -fid -. -id -( -) -desc -. -clone +FreeTexture ( -) +texture_id ) ) ; } let -mut -buffer +last_submit_index = -device +texture . -create_buffer_from_hal -( -hal_buffer -device_id -desc +info +. +submission_index +( ) ; -/ -/ -Assume -external -buffers -are -initialized -buffer -. -initialization_status -= -crate -: -: -init_tracker +if +let +resource : : -BufferInitTracker +TextureInner : : -new -( -0 -) -; -let -ref_count +Native +{ +ref +raw +} = -buffer +* +texture . -life_guard +inner +( +) . -add_ref +as_ref ( ) -; -let -id -= -fid . -assign +unwrap ( -buffer -& -mut -token ) -; -log -: -: -trace +{ +if ! +raw +. +is_none ( -" -Device +) +{ +let +temp += +queue : : -create_buffer -- -> -{ +TempResource : -? -} -" -id +: +Texture +( +texture . -0 +clone +( +) ) ; +let +mut +guard += device . -trackers +pending_writes . lock ( ) +; +let +pending_writes += +guard . -buffers -. -insert_single -( -id -ref_count -hal -: -: -BufferUses -: -: -empty +as_mut ( ) -) -; -return -( -id . -0 -None +unwrap +( ) ; -} -; -let -id -= -fid +if +pending_writes . -assign_error +dst_textures +. +contains_key ( -desc +& +texture_id +) +{ +pending_writes . -label +temp_resources . -borrow_or_default +push ( -) -& -mut -token +temp ) ; +} +else +{ +drop ( -id -Some +guard +) +; +device +. +lock_life ( -error ) +. +schedule_resource_destruction +( +temp +last_submit_index ) +; } -pub -fn -texture_label -< -A -: -HalApi -> +} +else +{ +return +Err ( -& -self -id -: -id +resource : : -TextureId -) -- -> -String -{ -A +DestroyError : : -hub -( -self +AlreadyDestroyed ) -. -textures -. -label_for_resource +; +} +} +Ok +( ( -id +) ) } pub fn -texture_destroy +texture_drop < A : @@ -5850,18 +5359,10 @@ id : : TextureId -) -- -> -Result -< -( -) -resource -: +wait : -DestroyError -> +bool +) { profiling : @@ -5873,27 +5374,29 @@ scope Texture : : -destroy +drop " ) ; log : : -trace +debug ! ( " Texture -: -: -destroy { -texture_id : ? } +is +asked +to +be +dropped " +texture_id ) ; let @@ -5907,375 +5410,172 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -/ -/ -TODO -: -lock -pending -writes -separately -keep -the -device -read -- -only -let +Some ( -mut -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -let -( -mut -texture_guard -_ +texture ) = hub . textures . -write +unregister ( -& -mut -token +texture_id ) -; +{ let -texture +last_submit_index = -texture_guard +texture . -get_and_mark_destroyed -( -texture_id -) +info . -map_err +submission_index ( -| -_ -| -resource -: -: -DestroyError -: -: -Invalid ) -? ; let device = & -mut -device_guard -[ texture . -device_id -. -value -] +device ; -# -[ -cfg -( -feature -= -" -trace -" -) -] +{ if -let -Some -( -ref -trace -) -= device . -trace -{ -trace +pending_writes . lock ( ) . -add -( -trace -: -: -Action -: -: -FreeTexture +as_ref ( -texture_id ) -) -; -} -let -last_submit_index -= -texture -. -life_guard . -life_count +unwrap ( ) -; -let -clear_views -= -match -std -: -: -mem -: -: -replace -( -& -mut -texture . -clear_mode -TextureClearMode -: -: -None -) -{ -TextureClearMode -: -: -BufferCopy -= -> -SmallVec -: -: -new +dst_textures +. +contains_key ( +& +texture_id ) -TextureClearMode -: -: -RenderPass { -clear_views -. +device . -} -= -> -clear_views -TextureClearMode -: -: -None -= -> -SmallVec -: -: -new +lock_life ( ) -} -; -match -texture . -inner -{ -resource -: -: -TextureInner -: -: -Native -{ -ref -mut -raw -} -= -> -{ -let -raw -= -raw +future_suspected_textures . -take +push ( -) +texture . -ok_or +clone ( -resource -: -: -DestroyError -: -: -AlreadyDestroyed ) -? -; -let -temp -= -queue -: -: -TempResource -: -: -Texture -( -raw -clear_views ) ; -if +} +else +{ device . -pending_writes +lock_life +( +) . -dst_textures +suspected_resources . -contains +insert ( -& texture_id +texture +. +clone +( +) ) +; +} +} +if +wait { +match device . -pending_writes -. -temp_resources -. -push +wait_for_submit ( -temp +last_submit_index ) -; -} -else { -drop +Ok +( ( -texture_guard ) -; -device -. -lock_life +) += +> ( -& -mut -token ) -. -schedule_resource_destruction +Err ( -temp -last_submit_index +e ) -; -} -} -resource += +> +log : : -TextureInner +error +! +( +" +Failed +to +wait +for +texture +{ : +? +} : -Surface { -. -. +: +? } -= -> -{ -for -clear_view -in -clear_views -{ -unsafe -{ -device -. -raw -. -destroy_texture_view -( -clear_view +" +texture_id +e ) -; } } -/ -/ -TODO -? } } -Ok -( +# +[ +allow ( +unused_unsafe ) -) -} +] pub fn -texture_drop +texture_create_view < A : @@ -6290,41 +5590,51 @@ id : : TextureId -wait +desc : -bool -) -{ -profiling +& +resource : : -scope -! +TextureViewDescriptor +id_in +: +Input +< +G +id +: +: +TextureViewId +> +) +- +> ( -" -Texture +id : : -drop -" +TextureViewId +Option +< +resource +: +: +CreateTextureViewError +> ) -; -log +{ +profiling : : -trace +scope ! ( " Texture : : -drop -{ -texture_id -: -? -} +create_view " ) ; @@ -6340,46 +5650,36 @@ self ) ; let -mut -token +fid = -Token +hub +. +texture_views +. +prepare : : -root +< +G +> ( +id_in ) ; let -( -ref_count -last_submit_index -device_id -) +error = +loop { let -( -mut -texture_guard -_ -) +texture = +match hub . textures . -write -( -& -mut -token -) -; -match -texture_guard -. -get_occupied_or_destroyed_mut +get ( texture_id ) @@ -6390,202 +5690,180 @@ texture ) = > -{ +texture +Err +( +_ +) += +> +break +resource +: +: +CreateTextureViewError +: +: +InvalidTexture +} +; let -ref_count +device = +& texture . -life_guard -. -ref_count -. -take +device +; +# +[ +cfg ( +feature += +" +trace +" ) -. -unwrap +] +if +let +Some ( +ref +mut +trace ) -; -let -last_submit_index = -texture +* +device . -life_guard +trace . -life_count +lock ( ) -; +{ +trace +. +add ( -ref_count -last_submit_index -texture +trace +: +: +Action +: +: +CreateTextureView +{ +id +: +fid . -device_id +id +( +) +parent_id +: +texture_id +desc +: +desc . -value +clone +( ) } -Err -( -InvalidId ) +; +} +let +view = -> +match +unsafe { -hub -. -textures +device . -unregister_locked +create_texture_view ( -texture_id & -mut -* -texture_guard +texture +desc ) -; -return -; -} } -} -; -let +{ +Ok ( -device_guard -mut -token +view ) = -hub -. -devices -. -read +> +view +Err ( -& -mut -token +e ) -; -let -device = -& -device_guard -[ -device_id -] +> +break +e +} ; -{ let -mut -life_lock -= -device -. -lock_life ( -& -mut -token +id +resource ) -; -if -device -. -pending_writes -. -dst_textures += +fid . -contains +assign ( -& -texture_id +view ) -{ -life_lock -. -future_suspected_textures -. -push -( -Stored -{ -value -: -id +; +log : : -Valid +info +! ( -texture_id -) -ref_count +" +Created +TextureView +{ +: +? } +" +id ) ; -} -else -{ -drop +device +. +trackers +. +lock ( -ref_count ) -; -life_lock -. -suspected_resources . -textures +views . -push +insert_single ( id -: -: -Valid -( -texture_id -) +resource ) ; -} -} -if -wait -{ -match -device -. -wait_for_submit -( -last_submit_index -& -mut -token -) -{ -Ok -( -( -) -) -= -> -( -) -Err +return ( -e +id +None ) -= -> +; +} +; log : : @@ -6593,30 +5871,51 @@ error ! ( " -Failed -to -wait -for -texture +Texture +: +: +create_view { : ? } -: +error { : ? } " texture_id -e +error +) +; +let +id += +fid +. +assign_error +( +desc +. +label +. +borrow_or_default +( +) +) +; +( +id +Some +( +error +) ) -} -} } pub fn -texture_create_view +texture_view_label < A : @@ -6625,45 +5924,64 @@ HalApi ( & self -texture_id +id : id : : -TextureId -desc +TextureViewId +) +- +> +String +{ +A : -& -resource : +hub +( +self +) +. +texture_views +. +label_for_resource +( +id +) +} +pub +fn +texture_view_drop +< +A : -TextureViewDescriptor -id_in +HalApi +> +( +& +self +texture_view_id : -Input -< -G id : : TextureViewId -> +wait +: +bool ) - > -( -id -: -: -TextureViewId -Option +Result < +( +) resource : : -CreateTextureViewError +TextureViewDestroyError > -) { profiling : @@ -6672,11 +5990,32 @@ scope ! ( " -Texture +TextureView : : -create_view +drop +" +) +; +log +: +: +debug +! +( +" +TextureView +{ +: +? +} +is +asked +to +be +dropped " +texture_view_id ) ; let @@ -6690,63 +6029,204 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root +Some ( +view ) -; -let -fid = hub . texture_views . -prepare +unregister ( -id_in +texture_view_id ) -; +{ let +last_submit_index += +view +. +info +. +submission_index ( -device_guard -mut -token ) -= -hub +; +view . -devices +device . -read +lock_life +( +) +. +suspected_resources +. +insert +( +texture_view_id +view +. +clone +( +) +) +; +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 +) +} +} +} +Ok +( +( +) +) +} +pub +fn +device_create_sampler +< +A +: +HalApi +> ( & -mut -token +self +device_id +: +DeviceId +desc +: +& +resource +: +: +SamplerDescriptor +id_in +: +Input +< +G +id +: +: +SamplerId +> +) +- +> +( +id +: +: +SamplerId +Option +< +resource +: +: +CreateSamplerError +> +) +{ +profiling +: +: +scope +! +( +" +Device +: +: +create_sampler +" ) ; let +hub += +A +: +: +hub ( -texture_guard -mut -token +self ) +; +let +fid = hub . -textures +samplers . -read +prepare +: +: +< +G +> ( -& -mut -token +id_in ) ; let @@ -6755,23 +6235,25 @@ error loop { let -texture +device = match -texture_guard +hub +. +devices . get ( -texture_id +device_id ) { Ok ( -texture +device ) = > -texture +device Err ( _ @@ -6779,28 +6261,35 @@ _ = > break -resource -: -: -CreateTextureViewError +DeviceError : : -InvalidTexture +Invalid +. +into +( +) } ; -let +if +! device -= -& -device_guard -[ -texture . -device_id +is_valid +( +) +{ +break +DeviceError +: +: +Lost . -value -] +into +( +) ; +} # [ cfg @@ -6817,18 +6306,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -6838,49 +6329,40 @@ trace Action : : -CreateTextureView -{ -id -: +CreateSampler +( fid . id ( ) -parent_id -: -texture_id -desc -: desc . clone ( ) -} +) ) ; } let -view +sampler = match device . -create_texture_view +create_sampler ( -texture -texture_id desc ) { Ok ( -view +sampler ) = > -view +sampler Err ( e @@ -6892,108 +6374,59 @@ e } ; let -ref_count -= -view -. -life_guard -. -add_ref ( -) -; -let id +resource +) = fid . assign ( -view -& -mut -token -) -; -device -. -trackers -. -lock -( -) -. -views -. -insert_single -( -id -ref_count +sampler ) ; log : : -trace +info ! ( " -Texture -: -: -create_view -{ -: -? -} -- -> +Created +Sampler { : ? } " -texture_id id +) +; +device . -0 +trackers +. +lock +( +) +. +samplers +. +insert_single +( +id +resource ) ; return ( id -. -0 None ) ; } ; -log -: -: -error -! -( -" -Texture -: -: -create_view -{ -: -? -} -error -{ -: -? -} -" -texture_id -error -) -; let id = @@ -7008,9 +6441,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -7023,7 +6453,7 @@ error } pub fn -texture_view_label +sampler_label < A : @@ -7037,7 +6467,7 @@ id id : : -TextureViewId +SamplerId ) - > @@ -7051,7 +6481,7 @@ hub self ) . -texture_views +samplers . label_for_resource ( @@ -7060,7 +6490,7 @@ id } pub fn -texture_view_drop +sampler_drop < A : @@ -7069,27 +6499,13 @@ HalApi ( & self -texture_view_id +sampler_id : id : : -TextureViewId -wait -: -bool -) -- -> -Result -< -( +SamplerId ) -resource -: -: -TextureViewDestroyError -> { profiling : @@ -7098,7 +6514,7 @@ scope ! ( " -TextureView +Sampler : : drop @@ -7108,20 +6524,22 @@ drop log : : -trace +debug ! ( " -TextureView -: -: -drop +Sampler { : ? } +is +asked +to +be +dropped " -texture_view_id +sampler_id ) ; let @@ -7135,243 +6553,52 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -let -( -last_submit_index -device_id -) -= -{ -let +Some ( -mut -texture_view_guard -_ +sampler ) = hub . -texture_views -. -write -( -& -mut -token -) -; -match -texture_view_guard +samplers . -get_mut -( -texture_view_id -) -{ -Ok +unregister ( -view +sampler_id ) -= -> { -let -_ref_count -= -view -. -life_guard -. -ref_count -. -take -( -) -; -let -last_submit_index -= -view +sampler . -life_guard +device . -life_count +lock_life ( ) -; -( -last_submit_index -view . -device_id +suspected_resources . -value -) -} -Err +insert ( -InvalidId -) -= -> -{ -hub -. -texture_views +sampler_id +sampler . -unregister_locked -( -texture_view_id -& -mut -* -texture_view_guard -) -; -return -Ok -( +clone ( ) ) ; } } -} -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -device -= -& -device_guard -[ -device_id -] -; -device -. -lock_life -( -& -mut -token -) -. -suspected_resources -. -texture_views -. -push -( -id -: -: -Valid -( -texture_view_id -) -) -; -if -wait -{ -match -device -. -wait_for_submit -( -last_submit_index -& -mut -token -) -{ -Ok -( -( -) -) -= -> -( -) -Err -( -e -) -= -> -log -: -: -error -! -( -" -Failed -to -wait -for -texture -view -{ -: -? -} -: -{ -: -? -} -" -texture_view_id -e -) -} -} -Ok -( -( -) -) -} -pub -fn -device_create_sampler -< -A -: -HalApi -> +pub +fn +device_create_bind_group_layout +< +A +: +HalApi +> ( & self @@ -7381,10 +6608,10 @@ DeviceId desc : & -resource +binding_model : : -SamplerDescriptor +BindGroupLayoutDescriptor id_in : Input @@ -7393,7 +6620,7 @@ G id : : -SamplerId +BindGroupLayoutId > ) - @@ -7402,13 +6629,13 @@ SamplerId id : : -SamplerId +BindGroupLayoutId Option < -resource +binding_model : : -CreateSamplerError +CreateBindGroupLayoutError > ) { @@ -7422,7 +6649,7 @@ scope Device : : -create_sampler +create_bind_group_layout " ) ; @@ -7438,56 +6665,37 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub . -samplers +bind_group_layouts . prepare +: +: +< +G +> ( id_in ) ; let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let error = +' +outer +: loop { let device = match -device_guard +hub +. +devices . get ( @@ -7522,7 +6730,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -7551,18 +6761,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -7572,7 +6784,7 @@ trace Action : : -CreateSampler +CreateBindGroupLayout ( fid . @@ -7589,108 +6801,262 @@ clone ; } let -sampler -= -match -device -. -create_sampler -( -device_id -desc -) -{ -Ok -( -sampler -) +mut +entry_map = -> -sampler -Err +FastHashMap +: +: +default ( -e ) -= -> -break -e -} ; -let -ref_count -= -sampler +for +entry +in +desc . -life_guard +entries . -add_ref +iter ( ) -; -let -id -= -fid +{ +if +entry . -assign -( -sampler -& -mut -token -) -; +binding +> device . -trackers -. -lock -( -) -. -samplers +limits . -insert_single -( -id -ref_count -) -; -log +max_bindings_per_bind_group +{ +break +' +outer +binding_model : : -trace -! -( -" -Device +CreateBindGroupLayoutError : : -create_sampler -- -> +InvalidBindingIndex { +binding : -? -} -" -id +entry . -0 +binding +maximum +: +device +. +limits +. +max_bindings_per_bind_group +} +; +} +if +entry_map +. +insert +( +entry +. +binding +* +entry +) +. +is_some +( +) +{ +break +' +outer +binding_model +: +: +CreateBindGroupLayoutError +: +: +ConflictBinding +( +entry +. +binding +) +; +} +} +if +let +Some +( +( +id +layout +) +) += +{ +let +bgl_guard += +hub +. +bind_group_layouts +. +read +( +) +; +device +. +deduplicate_bind_group_layout +( +& +entry_map +& +* +bgl_guard +) +} +{ +log +: +: +info +! +( +" +Reusing +BindGroupLayout +{ +layout +: +? +} +- +> +{ +: +? +} +" +id +) +; +let +id += +fid +. +assign_existing +( +& +layout ) ; return ( id +None +) +; +} +let +layout += +match +device . -0 +create_bind_group_layout +( +& +desc +. +label +entry_map +) +{ +Ok +( +layout +) += +> +layout +Err +( +e +) += +> +break +e +} +; +let +( +id +_layout +) += +fid +. +assign +( +layout +) +; +log +: +: +info +! +( +" +Created +BindGroupLayout +{ +: +? +} +" +id +) +; +return +( +id None ) ; } ; let +fid += +hub +. +bind_group_layouts +. +prepare +: +: +< +G +> +( +id_in +) +; +let id = fid @@ -7704,9 +7070,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -7719,7 +7082,7 @@ error } pub fn -sampler_label +bind_group_layout_label < A : @@ -7733,7 +7096,7 @@ id id : : -SamplerId +BindGroupLayoutId ) - > @@ -7747,7 +7110,7 @@ hub self ) . -samplers +bind_group_layouts . label_for_resource ( @@ -7756,7 +7119,7 @@ id } pub fn -sampler_drop +bind_group_layout_drop < A : @@ -7765,12 +7128,12 @@ HalApi ( & self -sampler_id +bind_group_layout_id : id : : -SamplerId +BindGroupLayoutId ) { profiling @@ -7780,7 +7143,7 @@ scope ! ( " -Sampler +BindGroupLayout : : drop @@ -7790,20 +7153,22 @@ drop log : : -trace +debug ! ( " -Sampler -: -: -drop +BindGroupLayout { -sampler_id : ? } +is +asked +to +be +dropped " +bind_group_layout_id ) ; let @@ -7817,145 +7182,47 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -let -device_id -= -{ -let +Some ( -mut -sampler_guard -_ +layout ) = hub . -samplers +bind_group_layouts . -write +unregister ( -& -mut -token +bind_group_layout_id ) -; -match -sampler_guard +{ +layout +. +device . -get_mut +lock_life ( -sampler_id -) -{ -Ok -( -sampler ) -= -> -{ -sampler . -life_guard -. -ref_count +suspected_resources . -take +insert ( -) -; -sampler -. -device_id +bind_group_layout_id +layout . -value -} -Err +clone ( -InvalidId ) -= -> -{ -hub -. -samplers -. -unregister_locked -( -sampler_id -& -mut -* -sampler_guard ) ; -return -; } } -} -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -device_guard -[ -device_id -] -. -lock_life -( -& -mut -token -) -. -suspected_resources -. -samplers -. -push -( -id -: -: -Valid -( -sampler_id -) -) -; -} pub fn -device_create_bind_group_layout +device_create_pipeline_layout < A : @@ -7973,7 +7240,7 @@ desc binding_model : : -BindGroupLayoutDescriptor +PipelineLayoutDescriptor id_in : Input @@ -7982,7 +7249,7 @@ G id : : -BindGroupLayoutId +PipelineLayoutId > ) - @@ -7991,13 +7258,13 @@ BindGroupLayoutId id : : -BindGroupLayoutId +PipelineLayoutId Option < binding_model : : -CreateBindGroupLayoutError +CreatePipelineLayoutError > ) { @@ -8011,22 +7278,11 @@ scope Device : : -create_bind_group_layout +create_pipeline_layout " ) ; let -mut -token -= -Token -: -: -root -( -) -; -let hub = A @@ -8042,9 +7298,14 @@ fid = hub . -bind_group_layouts +pipeline_layouts . prepare +: +: +< +G +> ( id_in ) @@ -8052,35 +7313,16 @@ id_in let error = -' -outer -: loop { let -( -device_guard -mut -token -) +device = +match hub . devices . -read -( -& -mut -token -) -; -let -device -= -match -device_guard -. get ( device_id @@ -8114,7 +7356,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -8143,18 +7387,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -8164,7 +7410,7 @@ trace Action : : -CreateBindGroupLayout +CreatePipelineLayout ( fid . @@ -8181,266 +7427,77 @@ clone ; } let -mut -entry_map +layout = -FastHashMap -: -: -default -( -) -; -for -entry -in -desc +{ +let +bgl_guard += +hub . -entries +bind_group_layouts . -iter +read ( ) -{ -if -entry -. -binding -> -device -. -limits -. -max_bindings_per_bind_group -{ -break -' -outer -binding_model -: -: -CreateBindGroupLayoutError -: -: -InvalidBindingIndex -{ -binding -: -entry -. -binding -maximum -: -device -. -limits -. -max_bindings_per_bind_group -} ; -} -if -entry_map +match +device . -insert +create_pipeline_layout ( -entry -. -binding +desc +& * -entry +bgl_guard ) -. -is_some +{ +Ok ( +layout ) -{ -break -' -outer -binding_model -: -: -CreateBindGroupLayoutError -: -: -ConflictBinding += +> +layout +Err ( -entry -. -binding +e ) -; += +> +break +e } } -let -mut -compatible_layout -= -None ; let -layout -= -{ -let ( -bgl_guard +id _ ) = -hub -. -bind_group_layouts +fid . -read -( -& -mut -token -) -; -if -let -Some -( -id -) -= -Device -: -: -deduplicate_bind_group_layout +assign ( -device_id -& -entry_map -& -* -bgl_guard -) -{ -/ -/ -If -there -is -an -equivalent -BGL -just -bump -the -refcount -and -return -it -. -/ -/ -This -is -only -applicable -if -ids -are -generated -in -wgpu -. -In -practice -: -/ -/ -- -wgpu -users -take -this -branch -and -return -the -existing -/ -/ -id -without -using -the -indirection -layer -in -BindGroupLayout -. -/ -/ -- -Other -users -like -gecko -or -the -replay -tool -use -don -' -t -take -/ -/ -the -branch -and -instead -rely -on -the -indirection -to -use -the -/ -/ -proper -bind -group layout -id -. -if -G -: -: -ids_are_generated_in_wgpu -( ) -{ +; log : : -trace +info ! ( " -Device -: -: -create_bind_group_layout -( -duplicate -of +Created +PipelineLayout { -id : ? } -) " +id ) ; return @@ -8450,232 +7507,174 @@ None ) ; } -compatible_layout +; +let +id = -Some +fid +. +assign_error ( -id -: -: -Valid +desc +. +label +. +borrow_or_default ( -id ) ) ; -} -if -let +( +id Some ( -original_id +error ) -= -compatible_layout -{ -let -original -= +) +} +pub +fn +pipeline_layout_label +< +A +: +HalApi +> +( & -bgl_guard -[ -original_id -] -; -BindGroupLayout +self +id +: +id +: +: +PipelineLayoutId +) +- +> +String { -device_id +A +: : -original +hub +( +self +) . -device_id +pipeline_layouts . -clone +label_for_resource ( +id ) -inner -: -crate +} +pub +fn +pipeline_layout_drop +< +A : +HalApi +> +( +& +self +pipeline_layout_id : -binding_model +id : : -BglOrDuplicate +PipelineLayoutId +) +{ +profiling : : -Duplicate +scope +! ( -original_id +" +PipelineLayout +: +: +drop +" ) -multi_ref_count +; +log : -crate : +debug +! +( +" +PipelineLayout +{ : -MultiRefCount +? +} +is +asked +to +be +dropped +" +pipeline_layout_id +) +; +let +hub += +A : : -new +hub ( +self ) -} -} -else -{ -match -device -. -create_bind_group_layout +; +if +let +Some ( -device_id -& -desc -. -label -entry_map -) -{ -Ok -( -layout -) -= -> layout -Err -( -e ) = -> -break -e -} -} -} -; -let -id -= -fid +hub . -assign -( -layout -& -mut -token -) -; -if -let -Some -( -dupe -) -= -compatible_layout -{ -log -: -: -trace -! -( -" -Device -: -: -create_bind_group_layout +pipeline_layouts +. +unregister ( -duplicate -of -{ -dupe -: -? -} +pipeline_layout_id ) -- -> { -: -? -} -" -id +layout . -0 -) -; -} -else -{ -log -: -: -trace -! -( -" -Device -: -: -create_bind_group_layout -- -> -{ -: -? -} -" -id +device . -0 -) -; -} -return +lock_life ( -id -. -0 -None ) -; -} -; -let -id -= -fid . -assign_error -( -desc +suspected_resources . -label +insert +( +pipeline_layout_id +layout . -borrow_or_default +clone ( ) -& -mut -token ) ; -( -id -Some -( -error -) -) +} } pub fn -bind_group_layout_label +device_create_bind_group < A : @@ -8684,49 +7683,41 @@ HalApi ( & self -id +device_id +: +DeviceId +desc : +& +binding_model +: +: +BindGroupDescriptor +id_in +: +Input +< +G id : : -BindGroupLayoutId +BindGroupId +> ) - > -String -{ -A -: -: -hub -( -self -) -. -bind_group_layouts -. -label_for_resource ( id -) -} -pub -fn -bind_group_layout_drop -< -A : -HalApi -> -( -& -self -bind_group_layout_id : -id +BindGroupId +Option +< +binding_model : : -BindGroupLayoutId +CreateBindGroupError +> ) { profiling @@ -8736,30 +7727,11 @@ scope ! ( " -BindGroupLayout -: -: -drop -" -) -; -log -: -: -trace -! -( -" -BindGroupLayout -: +Device : -drop -{ : -? -} +create_bind_group " -bind_group_layout_id ) ; let @@ -8774,269 +7746,50 @@ self ) ; let -mut -token +fid = -Token +hub +. +bind_groups +. +prepare : : -root +< +G +> ( +id_in ) ; let -device_id +error = +loop { let -( -mut -bind_group_layout_guard -_ -) +device = +match hub . -bind_group_layouts -. -write -( -& -mut -token -) -; -match -bind_group_layout_guard +devices . -get_mut +get ( -bind_group_layout_id +device_id ) { Ok ( -layout +device ) = > -layout -. -device_id -. -value +device Err ( -InvalidId -) -= -> -{ -hub -. -bind_group_layouts -. -unregister_locked -( -bind_group_layout_id -& -mut -* -bind_group_layout_guard -) -; -return -; -} -} -} -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -device_guard -[ -device_id -] -. -lock_life -( -& -mut -token -) -. -suspected_resources -. -bind_group_layouts -. -push -( -id -: -: -Valid -( -bind_group_layout_id -) -) -; -} -pub -fn -device_create_pipeline_layout -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -desc -: -& -binding_model -: -: -PipelineLayoutDescriptor -id_in -: -Input -< -G -id -: -: -PipelineLayoutId -> -) -- -> -( -id -: -: -PipelineLayoutId -Option -< -binding_model -: -: -CreatePipelineLayoutError -> -) -{ -profiling -: -: -scope -! -( -" -Device -: -: -create_pipeline_layout -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -fid -= -hub -. -pipeline_layouts -. -prepare -( -id_in -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -error -= -loop -{ -let -device -= -match -device_guard -. -get -( -device_id -) -{ -Ok -( -device -) -= -> -device -Err -( -_ +_ ) = > @@ -9055,7 +7808,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -9084,18 +7839,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -9105,7 +7862,7 @@ trace Action : : -CreatePipelineLayout +CreateBindGroup ( fid . @@ -9122,14 +7879,7 @@ clone ; } let -layout -= -{ -let -( -bgl_guard -_ -) +bind_group_layout_guard = hub . @@ -9137,21 +7887,19 @@ bind_group_layouts . read ( -& -mut -token ) ; +let +bind_group_layout += match -device +bind_group_layout_guard . -create_pipeline_layout +get ( -device_id desc -& -* -bgl_guard +. +layout ) { Ok @@ -9163,56 +7911,135 @@ layout layout Err ( -e +. +. ) = > break -e -} +binding_model +: +: +CreateBindGroupError +: +: +InvalidLayout } ; -let +if +bind_group_layout +. +device +. +as_info +( +) +. id +( +) +! = -fid +device . -assign +as_info ( -layout -& -mut -token +) +. +id +( +) +{ +break +DeviceError +: +: +WrongDevice +. +into +( +) +; +} +let +bind_group += +match +device +. +create_bind_group +( +bind_group_layout +desc +hub +) +{ +Ok +( +bind_group +) += +> +bind_group +Err +( +e +) += +> +break +e +} +; +let +( +id +resource +) += +fid +. +assign +( +bind_group ) ; log : : -trace +info ! ( " -Device -: -: -create_pipeline_layout -- -> +Created +BindGroup { : ? } " id +) +; +device . -0 +trackers +. +lock +( +) +. +bind_groups +. +insert_single +( +id +resource ) ; return ( id -. -0 None ) ; @@ -9232,9 +8059,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -9247,7 +8071,7 @@ error } pub fn -pipeline_layout_label +bind_group_label < A : @@ -9261,7 +8085,7 @@ id id : : -PipelineLayoutId +BindGroupId ) - > @@ -9275,7 +8099,7 @@ hub self ) . -pipeline_layouts +bind_groups . label_for_resource ( @@ -9284,7 +8108,7 @@ id } pub fn -pipeline_layout_drop +bind_group_drop < A : @@ -9293,12 +8117,12 @@ HalApi ( & self -pipeline_layout_id +bind_group_id : id : : -PipelineLayoutId +BindGroupId ) { profiling @@ -9308,7 +8132,7 @@ scope ! ( " -PipelineLayout +BindGroup : : drop @@ -9318,20 +8142,22 @@ drop log : : -trace +debug ! ( " -PipelineLayout -: -: -drop +BindGroup { : ? } +is +asked +to +be +dropped " -pipeline_layout_id +bind_group_id ) ; let @@ -9345,157 +8171,47 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_id -ref_count -) -= -{ -let +Some ( -mut -pipeline_layout_guard -_ +bind_group ) = hub . -pipeline_layouts -. -write -( -& -mut -token -) -; -match -pipeline_layout_guard -. -get_mut -( -pipeline_layout_id -) -{ -Ok -( -layout -) -= -> -( -layout -. -device_id -. -value -layout -. -life_guard -. -ref_count -. -take -( -) +bind_groups . -unwrap -( -) -) -Err +unregister ( -InvalidId +bind_group_id ) -= -> { -hub -. -pipeline_layouts -. -unregister_locked -( -pipeline_layout_id -& -mut -* -pipeline_layout_guard -) -; -return -; -} -} -} -; -let -( -device_guard -mut -token -) -= -hub -. -devices +bind_group . -read -( -& -mut -token -) -; -device_guard -[ -device_id -] +device . lock_life ( -& -mut -token ) . suspected_resources . -pipeline_layouts -. -push +insert ( -Stored -{ -value -: -id -: -: -Valid +bind_group_id +bind_group +. +clone ( -pipeline_layout_id ) -ref_count -} ) ; } +} pub fn -device_create_bind_group +device_create_shader_module < A : @@ -9510,10 +8226,16 @@ DeviceId desc : & -binding_model +pipeline : : -BindGroupDescriptor +ShaderModuleDescriptor +source +: +pipeline +: +: +ShaderModuleSource id_in : Input @@ -9522,7 +8244,7 @@ G id : : -BindGroupId +ShaderModuleId > ) - @@ -9531,13 +8253,13 @@ BindGroupId id : : -BindGroupId +ShaderModuleId Option < -binding_model +pipeline : : -CreateBindGroupError +CreateShaderModuleError > ) { @@ -9551,7 +8273,7 @@ scope Device : : -create_bind_group +create_shader_module " ) ; @@ -9567,65 +8289,23 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub . -bind_groups +shader_modules . prepare +: +: +< +G +> ( id_in ) ; let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -bind_group_layout_guard -mut -token -) -= -hub -. -bind_group_layouts -. -read -( -& -mut -token -) -; -let error = loop @@ -9634,7 +8314,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -9669,7 +8351,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -9698,18 +8382,150 @@ let Some ( ref +mut trace ) = +* device . trace +. +lock +( +) +{ +let +data += +match +source +{ +# +[ +cfg +( +feature += +" +wgsl +" +) +] +pipeline +: +: +ShaderModuleSource +: +: +Wgsl +( +ref +code +) += +> { trace . -lock +make_binary +( +" +wgsl +" +code +. +as_bytes +( +) +) +} +pipeline +: +: +ShaderModuleSource +: +: +Naga +( +ref +module +) += +> +{ +let +string += +ron +: +: +ser +: +: +to_string_pretty +( +module +ron +: +: +ser +: +: +PrettyConfig +: +: +default +( +) +) +. +unwrap +( +) +; +trace +. +make_binary +( +" +ron +" +string +. +as_bytes +( +) +) +} +pipeline +: +: +ShaderModuleSource +: +: +Dummy ( +_ +) += +> +{ +panic +! +( +" +found +ShaderModuleSource +: +: +Dummy +" ) +} +} +; +trace . add ( @@ -9719,226 +8535,96 @@ trace Action : : -CreateBindGroup -( +CreateShaderModule +{ +id +: fid . id ( ) desc +: +desc . clone ( ) -) +data +} ) ; } +; let -mut -bind_group_layout +shader = match -bind_group_layout_guard +device . -get +create_shader_module ( desc -. -layout +source ) { Ok ( -layout +shader ) = > -layout +shader Err ( -. -. +e ) = > break -binding_model -: -: -CreateBindGroupError -: -: -InvalidLayout +e } ; -if -bind_group_layout -. -device_id -. -value -. -0 -! +let +( +id +_ +) = -device_id -{ -break -DeviceError -: -: -WrongDevice +fid . -into +assign ( -) -; -} -let -mut -layout_id -= -id -: -: -Valid -( -desc -. -layout -) -; -if -let -Some -( -id -) -= -bind_group_layout -. -as_duplicate -( -) -{ -layout_id -= -id -; -bind_group_layout -= -& -bind_group_layout_guard -[ -id -] -; -} -let -bind_group -= -match -device -. -create_bind_group -( -device_id -bind_group_layout -layout_id -desc -hub -& -mut -token -) -{ -Ok -( -bind_group -) -= -> -bind_group -Err -( -e -) -= -> -break -e -} -; -let -ref_count -= -bind_group -. -life_guard -. -add_ref -( -) -; -let -id -= -fid -. -assign -( -bind_group -& -mut -token +shader ) ; log : : -trace +info ! ( " -Device -: +Created +ShaderModule +{ : -create_bind_group -- -> +? +} +with { : ? } " id -. -0 -) -; -device -. -trackers -. -lock -( -) -. -bind_groups -. -insert_single -( -id -ref_count +desc ) ; return ( id -. -0 None ) ; @@ -9958,9 +8644,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -9971,9 +8654,72 @@ error ) ) } +/ +/ +Unsafe +- +ness +of +internal +calls +has +little +to +do +with +unsafe +- +ness +of +this +. +# +[ +allow +( +unused_unsafe +) +] +/ +/ +/ +# +Safety +/ +/ +/ +/ +/ +/ +This +function +passes +SPIR +- +V +binary +to +the +backend +as +- +is +and +can +potentially +result +in +a +/ +/ +/ +driver +crash +. pub +unsafe fn -bind_group_label +device_create_shader_module_spirv < A : @@ -9982,283 +8728,49 @@ HalApi ( & self -id +device_id : -id +DeviceId +desc : +& +pipeline : -BindGroupId -) -- +: +ShaderModuleDescriptor +source +: +Cow +< +[ +u32 +] > -String -{ -A +id_in : +Input +< +G +id : -hub -( -self +: +ShaderModuleId +> ) -. -bind_groups -. -label_for_resource +- +> ( id -) -} -pub -fn -bind_group_drop -< -A : -HalApi -> -( -& -self -bind_group_id : -id +ShaderModuleId +Option +< +pipeline : : -BindGroupId -) -{ -profiling -: -: -scope -! -( -" -BindGroup -: -: -drop -" -) -; -log -: -: -trace -! -( -" -BindGroup -: -: -drop -{ -: -? -} -" -bind_group_id -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -device_id -= -{ -let -( -mut -bind_group_guard -_ -) -= -hub -. -bind_groups -. -write -( -& -mut -token -) -; -match -bind_group_guard -. -get_mut -( -bind_group_id -) -{ -Ok -( -bind_group -) -= -> -{ -bind_group -. -life_guard -. -ref_count -. -take -( -) -; -bind_group -. -device_id -. -value -} -Err -( -InvalidId -) -= -> -{ -hub -. -bind_groups -. -unregister_locked -( -bind_group_id -& -mut -* -bind_group_guard -) -; -return -; -} -} -} -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -device_guard -[ -device_id -] -. -lock_life -( -& -mut -token -) -. -suspected_resources -. -bind_groups -. -push -( -id -: -: -Valid -( -bind_group_id -) -) -; -} -pub -fn -device_create_shader_module -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -desc -: -& -pipeline -: -: -ShaderModuleDescriptor -source -: -pipeline -: -: -ShaderModuleSource -id_in -: -Input -< -G -id -: -: -ShaderModuleId -> -) -- -> -( -id -: -: -ShaderModuleId -Option -< -pipeline -: -: -CreateShaderModuleError -> +CreateShaderModuleError +> ) { profiling @@ -10287,17 +8799,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -10305,29 +8806,16 @@ hub shader_modules . prepare +: +: +< +G +> ( id_in ) ; let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let error = loop @@ -10336,7 +8824,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -10371,7 +8861,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -10400,152 +8892,58 @@ let Some ( ref +mut trace ) = +* device . trace -{ -let -mut -trace -= -trace . lock ( ) -; +{ let data = -match -source -{ -# -[ -cfg -( -feature -= -" -wgsl -" -) -] -pipeline -: -: -ShaderModuleSource -: -: -Wgsl -( -ref -code -) -= -> -{ trace . make_binary ( " -wgsl +spv " -code -. -as_bytes -( -) -) -} -pipeline -: -: -ShaderModuleSource -: -: -Naga -( -ref -module -) -= -> +unsafe { -let -string -= -ron -: -: -ser -: -: -to_string_pretty -( -module -ron -: -: -ser +std : : -PrettyConfig +slice : : -default +from_raw_parts ( -) -) +source . -unwrap +as_ptr ( ) -; -trace -. -make_binary -( -" -ron -" -string +as +* +const +u8 +source . -as_bytes +len ( ) +* +4 ) } -pipeline -: -: -ShaderModuleSource -: -: -Dummy -( -_ ) -= -> -{ -panic -! -( -" -found -ShaderModuleSource -: -: -Dummy -" -) -} -} ; trace . @@ -10583,14 +8981,17 @@ let shader = match +unsafe +{ device . -create_shader_module +create_shader_module_spirv ( -device_id desc +& source ) +} { Ok ( @@ -10610,46 +9011,44 @@ e } ; let +( id +_ +) = fid . assign ( shader -& -mut -token ) ; log : : -trace +info ! ( " -Device -: +Created +ShaderModule +{ : -create_shader_module -- -> +? +} +with { : ? } " id -. -0 +desc ) ; return ( id -. -0 None ) ; @@ -10669,9 +9068,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -10682,72 +9078,9 @@ error ) ) } -/ -/ -Unsafe -- -ness -of -internal -calls -has -little -to -do -with -unsafe -- -ness -of -this -. -# -[ -allow -( -unused_unsafe -) -] -/ -/ -/ -# -Safety -/ -/ -/ -/ -/ -/ -This -function -passes -SPIR -- -V -binary -to -the -backend -as -- -is -and -can -potentially -result -in -a -/ -/ -/ -driver -crash -. pub -unsafe fn -device_create_shader_module_spirv +shader_module_label < A : @@ -10756,49 +9089,49 @@ HalApi ( & self -device_id -: -DeviceId -desc -: -& -pipeline -: -: -ShaderModuleDescriptor -source -: -Cow -< -[ -u32 -] -> -id_in +id : -Input -< -G id : : ShaderModuleId -> ) - > -( -id +String +{ +A : : -ShaderModuleId -Option -< -pipeline -: +hub +( +self +) +. +shader_modules +. +label_for_resource +( +id +) +} +pub +fn +shader_module_drop +< +A : -CreateShaderModuleError +HalApi > +( +& +self +shader_module_id +: +id +: +: +ShaderModuleId ) { profiling @@ -10808,63 +9141,143 @@ scope ! ( " -Device +ShaderModule : : -create_shader_module +drop " ) ; -let -hub -= -A +log : : -hub +debug +! ( -self +" +ShaderModule +{ +: +? +} +is +asked +to +be +dropped +" +shader_module_id ) ; let -mut -token +hub = -Token +A : : -root +hub ( +self ) ; -let -fid -= hub . shader_modules . -prepare +unregister +( +shader_module_id +) +; +} +pub +fn +device_create_command_encoder +< +A +: +HalApi +> ( +& +self +device_id +: +DeviceId +desc +: +& +wgt +: +: +CommandEncoderDescriptor +< +Label +> id_in +: +Input +< +G +id +: +: +CommandEncoderId +> +) +- +> +( +id +: +: +CommandEncoderId +Option +< +DeviceError +> +) +{ +profiling +: +: +scope +! +( +" +Device +: +: +create_command_encoder +" ) ; let +hub += +A +: +: +hub ( -device_guard -mut -token +self ) +; +let +fid = hub . -devices +command_buffers . -read +prepare +: +: +< +G +> ( -& -mut -token +id_in ) ; let @@ -10876,7 +9289,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -10901,186 +9316,225 @@ DeviceError : : Invalid -. -into -( -) } ; if ! device . -valid +is_valid +( +) { break DeviceError : : Lost -. -into -( -) ; } -# -[ -cfg -( -feature -= -" -trace -" -) -] -if let -Some -( -ref -trace -) +queue = +match +hub +. +queues +. +get +( device . -trace -{ -let -mut -trace -= -trace +queue_id . -lock +read ( ) -; -let -data -= -trace . -make_binary +unwrap ( -" -spv -" -unsafe +) +) { -std -: -: -slice +Ok +( +queue +) += +> +queue +Err +( +_ +) += +> +break +DeviceError : : -from_raw_parts +InvalidQueueId +} +; +let +encoder += +match +device +. +command_allocator +. +lock ( -source +) . -as_ptr +as_mut ( ) -as -* -const -u8 -source . -len +unwrap ( ) -* -4 -) -} -) -; -trace . -add +acquire_encoder ( -trace -: -: -Action -: -: -CreateShaderModule -{ -id -: -fid +device . -id +raw ( ) -desc -: -desc +queue . -clone +raw +. +as_ref ( ) -data -} -) -; -} -; -let -shader -= -match -unsafe -{ -device . -create_shader_module_spirv +unwrap ( -device_id -desc -& -source ) -} +) { Ok ( -shader +raw ) = > -shader +raw Err ( -e +_ ) = > break -e +DeviceError +: +: +OutOfMemory } ; let +command_buffer += +command +: +: +CommandBuffer +: +: +new +( +encoder +& +device +# +[ +cfg +( +feature += +" +trace +" +) +] +device +. +trace +. +lock +( +) +. +is_some +( +) +desc +. +label +. +to_hal +( +device +. +instance_flags +) +. +map +( +| +s +| +s +. +to_string +( +) +) +) +; +let +( id +_ +) = fid . assign ( -shader -& -mut -token +command_buffer +) +; +log +: +: +info +! +( +" +Created +CommandBuffer +{ +: +? +} +with +{ +: +? +} +" +id +desc ) ; return ( id -. -0 None ) ; @@ -11100,9 +9554,6 @@ label borrow_or_default ( ) -& -mut -token ) ; ( @@ -11115,7 +9566,7 @@ error } pub fn -shader_module_label +command_buffer_label < A : @@ -11129,7 +9580,7 @@ id id : : -ShaderModuleId +CommandBufferId ) - > @@ -11143,7 +9594,7 @@ hub self ) . -shader_modules +command_buffers . label_for_resource ( @@ -11152,7 +9603,7 @@ id } pub fn -shader_module_drop +command_encoder_drop < A : @@ -11161,12 +9612,12 @@ HalApi ( & self -shader_module_id +command_encoder_id : id : : -ShaderModuleId +CommandEncoderId ) { profiling @@ -11176,7 +9627,7 @@ scope ! ( " -ShaderModule +CommandEncoder : : drop @@ -11186,20 +9637,22 @@ drop log : : -trace +debug ! ( " -ShaderModule -: -: -drop +CommandEncoder { : ? } +is +asked +to +be +dropped " -shader_module_id +command_encoder_id ) ; let @@ -11213,143 +9666,119 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -let +Some ( -device_guard -mut -token +cmd_buf ) = hub . -devices +command_buffers . -read -( -& -mut -token -) -; -let +unregister ( -module -_ +command_encoder_id ) -= -hub +{ +cmd_buf . -shader_modules +device . -unregister +untrack ( -shader_module_id & -mut -token -) -; -if -let -Some +cmd_buf +. +data +. +lock ( -module ) -= -module -{ -let -device -= -& -device_guard -[ -module . -device_id +as_ref +( +) . -value -] -; -# -[ -cfg +unwrap ( -feature -= -" -trace -" ) -] -if -let -Some -( -ref -trace -) -= -device -. -trace -{ -trace . -lock -( +trackers ) -. -add +; +} +} +pub +fn +command_buffer_drop +< +A +: +HalApi +> ( -trace +& +self +command_buffer_id +: +id : : -Action +CommandBufferId +) +{ +profiling : : -DestroyShaderModule +scope +! ( -shader_module_id -) +" +CommandBuffer +: +: +drop +" ) ; -} -unsafe +log +: +: +debug +! +( +" +CommandBuffer { -device -. -raw +: +? +} +is +asked +to +be +dropped +" +command_buffer_id +) +; +self . -destroy_shader_module +command_encoder_drop +: +: +< +A +> ( -module -. -raw +command_buffer_id ) -; -} -} } pub fn -device_create_command_encoder -< -A -: -HalApi -> +device_create_render_bundle_encoder ( & self @@ -11359,23 +9788,10 @@ DeviceId desc : & -wgt -: -: -CommandEncoderDescriptor -< -Label -> -id_in -: -Input -< -G -id +command : : -CommandEncoderId -> +RenderBundleEncoderDescriptor ) - > @@ -11383,10 +9799,13 @@ CommandEncoderId id : : -CommandEncoderId +RenderBundleEncoderId Option < -DeviceError +command +: +: +CreateRenderBundleError > ) { @@ -11400,328 +9819,98 @@ scope Device : : -create_command_encoder +create_render_bundle_encoder " ) ; -let -hub -= -A +log : : -hub +trace +! ( -self -) -; -let -mut -token -= -Token +" +Device : : -root -( -) -; -let -fid -= -hub -. -command_buffers -. -prepare -( -id_in +device_create_render_bundle_encoder +" ) ; let ( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let +encoder error -= -loop -{ -let -device +) = match -device_guard -. -get +command +: +: +RenderBundleEncoder +: +: +new ( +desc device_id +None ) { Ok ( -device +encoder ) = > -device +( +encoder +None +) Err ( -_ +e ) = > -break -DeviceError -: -: -Invalid -} -; -if -! -device -. -valid -{ -break -DeviceError -: +( +command : -Lost -; -} -let -dev_stored -= -Stored -{ -value : -id +RenderBundleEncoder : : -Valid +dummy ( device_id ) -ref_count -: -device -. -life_guard -. -add_ref +Some ( +e +) ) } ; -let -encoder -= -match -device -. -command_allocator -. -lock ( -) -. -acquire_encoder +Box +: +: +into_raw ( -& -device -. -raw -& -device -. -queue -) -{ -Ok -( -raw -) -= -> -raw -Err -( -_ -) -= -> -break -DeviceError -: -: -OutOfMemory -} -; -let -command_buffer -= -command -: -: -CommandBuffer +Box : : new ( encoder -dev_stored -device -. -limits -. -clone -( -) -device -. -downlevel -. -clone -( -) -device -. -features -# -[ -cfg -( -feature -= -" -trace -" -) -] -device -. -trace -. -is_some -( -) -desc -. -label -. -to_hal -( -device -. -instance_flags -) -. -map -( -| -s -| -s -. -to_string -( -) -) -) -; -let -id -= -fid -. -assign -( -command_buffer -& -mut -token -) -; -log -: -: -trace -! -( -" -Device -: -: -create_command_encoder -- -> -{ -: -? -} -" -id -. -0 -) -; -return -( -id -. -0 -None -) -; -} -; -let -id -= -fid -. -assign_error -( -desc -. -label -. -borrow_or_default -( ) -& -mut -token ) -; -( -id -Some -( error ) -) } pub fn -command_buffer_label +render_bundle_encoder_finish < A : @@ -11730,49 +9919,44 @@ HalApi ( & self -id +bundle_encoder +: +command +: +: +RenderBundleEncoder +desc +: +& +command +: +: +RenderBundleDescriptor +id_in : +Input +< +G id : : -CommandBufferId +RenderBundleId +> ) - > -String -{ -A -: -: -hub -( -self -) -. -command_buffers -. -label_for_resource ( id -) -} -pub -fn -command_encoder_drop -< -A : -HalApi -> -( -& -self -command_encoder_id : -id +RenderBundleId +Option +< +command : : -CommandEncoderId +RenderBundleError +> ) { profiling @@ -11782,30 +9966,11 @@ scope ! ( " -CommandEncoder -: -: -drop -" -) -; -log -: -: -trace -! -( -" -CommandEncoder -: +RenderBundleEncoder : -drop -{ : -? -} +finish " -command_encoder_id ) ; let @@ -11820,303 +9985,318 @@ self ) ; let -mut -token +fid = -Token +hub +. +render_bundles +. +prepare : : -root +< +G +> ( +id_in ) ; let -( -mut -device_guard -mut -token -) +error += +loop +{ +let +device = +match hub . devices . -write -( -& -mut -token -) -; -let +get ( -cmdbuf -_ -) -= -hub -. -command_buffers +bundle_encoder . -unregister +parent ( -command_encoder_id -& -mut -token ) -; -if -let -Some -( -cmdbuf ) -= -cmdbuf { -let +Ok +( device +) = -& -mut -device_guard -[ -cmdbuf -. -device_id -. -value -] -; -device -. -untrack -: -: -< -G > -( -hub -& -cmdbuf -. -trackers -& -mut -token -) -; device -. -destroy_command_buffer +Err ( -cmdbuf +_ ) -; -} -} -pub -fn -command_buffer_drop -< -A -: -HalApi += > -( -& -self -command_buffer_id -: -id +break +command : : -CommandBufferId -) -{ -profiling +RenderBundleError : : -scope +INVALID_DEVICE +} +; +if ! +device +. +is_valid ( -" -CommandBuffer -: -: -drop -" ) -; -log -: +{ +break +command : -trace -! -( -" -CommandBuffer : +RenderBundleError : -drop -{ : -? +INVALID_DEVICE +; } +# +[ +cfg +( +feature += +" +trace " -command_buffer_id ) -; -self -. -command_encoder_drop -: -: -< -A -> +] +if +let +Some ( -command_buffer_id +ref +mut +trace ) -} -pub -fn -device_create_render_bundle_encoder += +* +device +. +trace +. +lock ( -& -self -device_id -: -DeviceId -desc -: -& -command -: -: -RenderBundleEncoderDescriptor ) -- -> +{ +trace +. +add ( -id +trace : : -RenderBundleEncoderId -Option -< -command +Action : : -CreateRenderBundleError -> -) +CreateRenderBundle { -profiling -: +id : -scope -! +fid +. +id ( -" -Device -: -: -create_render_bundle_encoder -" ) -; -log -: +desc : trace -! -( -" -Device : : -device_create_render_bundle_encoder -" +new_render_bundle_encoder_descriptor +( +desc +. +label +. +clone +( ) -; -let +& +bundle_encoder +. +context +bundle_encoder +. +is_depth_read_only +bundle_encoder +. +is_stencil_read_only +) +base +: +bundle_encoder +. +to_base_pass ( -encoder -error ) +} +) +; +} +let +render_bundle = match -command -: -: -RenderBundleEncoder -: -: -new +bundle_encoder +. +finish ( desc -device_id -None +& +device +hub ) { Ok ( -encoder +bundle ) = > -( -encoder -None -) -Err +bundle +Err ( e ) = > +break +e +} +; +let ( -command -: +id +resource +) += +fid +. +assign +( +render_bundle +) +; +log : -RenderBundleEncoder : +info +! +( +" +Created +RenderBundle +{ : -dummy +? +} +" +id +) +; +device +. +trackers +. +lock ( -device_id ) -Some +. +bundles +. +insert_single ( -e +id +resource ) +; +return +( +id +None ) +; } ; +let +id += +fid +. +assign_error ( -Box -: +desc +. +label +. +borrow_or_default +( +) +) +; +( +id +Some +( +error +) +) +} +pub +fn +render_bundle_label +< +A : -into_raw +HalApi +> ( -Box +& +self +id : +id : -new -( -encoder +: +RenderBundleId ) +- +> +String +{ +A +: +: +hub +( +self ) -error +. +render_bundles +. +label_for_resource +( +id ) } pub fn -render_bundle_encoder_finish +render_bundle_drop < A : @@ -12125,19 +10305,119 @@ HalApi ( & self -bundle_encoder +render_bundle_id : -command +id : : -RenderBundleEncoder +RenderBundleId +) +{ +profiling +: +: +scope +! +( +" +RenderBundle +: +: +drop +" +) +; +log +: +: +debug +! +( +" +RenderBundle +{ +: +? +} +is +asked +to +be +dropped +" +render_bundle_id +) +; +let +hub += +A +: +: +hub +( +self +) +; +if +let +Some +( +bundle +) += +hub +. +render_bundles +. +unregister +( +render_bundle_id +) +{ +bundle +. +device +. +lock_life +( +) +. +suspected_resources +. +insert +( +render_bundle_id +bundle +. +clone +( +) +) +; +} +} +pub +fn +device_create_query_set +< +A +: +HalApi +> +( +& +self +device_id +: +DeviceId desc : & -command +resource : : -RenderBundleDescriptor +QuerySetDescriptor id_in : Input @@ -12146,7 +10426,7 @@ G id : : -RenderBundleId +QuerySetId > ) - @@ -12155,13 +10435,13 @@ RenderBundleId id : : -RenderBundleId +QuerySetId Option < -command +resource : : -RenderBundleError +CreateQuerySetError > ) { @@ -12172,10 +10452,10 @@ scope ! ( " -RenderBundleEncoder +Device : : -finish +create_query_set " ) ; @@ -12191,47 +10471,23 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub . -render_bundles +query_sets . prepare +: +: +< +G +> ( id_in ) ; let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let error = loop @@ -12240,15 +10496,13 @@ let device = match -device_guard +hub . -get -( -bundle_encoder +devices . -parent +get ( -) +device_id ) { Ok @@ -12265,29 +10519,33 @@ _ = > break -command -: -: -RenderBundleError +DeviceError : : -INVALID_DEVICE +Invalid +. +into +( +) } ; if ! device . -valid +is_valid +( +) { break -command -: -: -RenderBundleError +DeviceError : : -INVALID_DEVICE +Lost +. +into +( +) ; } # @@ -12306,18 +10564,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -12327,7 +10587,7 @@ trace Action : : -CreateRenderBundle +CreateQuerySet { id : @@ -12338,153 +10598,92 @@ id ) desc : -trace -: -: -new_render_bundle_encoder_descriptor -( desc . -label -. clone ( ) -& -bundle_encoder -. -context -bundle_encoder -. -is_depth_read_only -bundle_encoder -. -is_stencil_read_only -) -base -: -bundle_encoder -. -to_base_pass -( -) } ) ; } let -render_bundle +query_set = match -bundle_encoder +device . -finish +create_query_set ( desc -device -hub -& -mut -token ) { Ok ( -bundle +query_set ) = > -bundle +query_set Err ( -e +err ) = > break -e +err } ; -log -: -: -debug -! -( -" -Render -bundle -" -) -; let -ref_count -= -render_bundle -. -life_guard -. -add_ref ( -) -; -let id +resource +) = fid . assign ( -render_bundle -& -mut -token -) -; -device -. -trackers -. -lock -( -) -. -bundles -. -insert_single -( -id -ref_count +query_set ) ; log : : -trace +info ! ( " -RenderBundleEncoder -: -: -finish -- -> +Created +QuerySet { : ? } " id +) +; +device . -0 +trackers +. +lock +( +) +. +query_sets +. +insert_single +( +id +resource ) ; return ( id -. -0 None ) ; @@ -12497,16 +10696,8 @@ fid . assign_error ( -desc -. -label -. -borrow_or_default -( -) -& -mut -token +" +" ) ; ( @@ -12519,44 +10710,7 @@ error } pub fn -render_bundle_label -< -A -: -HalApi -> -( -& -self -id -: -id -: -: -RenderBundleId -) -- -> -String -{ -A -: -: -hub -( -self -) -. -render_bundles -. -label_for_resource -( -id -) -} -pub -fn -render_bundle_drop +query_set_drop < A : @@ -12565,12 +10719,12 @@ HalApi ( & self -render_bundle_id +query_set_id : id : : -RenderBundleId +QuerySetId ) { profiling @@ -12580,7 +10734,7 @@ scope ! ( " -RenderBundle +QuerySet : : drop @@ -12590,20 +10744,22 @@ drop log : : -trace +debug ! ( " -RenderBundle -: -: -drop +QuerySet { : ? } +is +asked +to +be +dropped " -render_bundle_id +query_set_id ) ; let @@ -12617,145 +10773,136 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root -( -) -; -let +Some ( -device_guard -mut -token +query_set ) = hub . -devices +query_sets . -read +unregister ( -& -mut -token +query_set_id ) -; -let -device_id -= { let -( -mut -bundle_guard -_ -) +device = -hub -. -render_bundles -. -write -( & -mut -token -) -; -match -bundle_guard +query_set . -get_mut +device +; +# +[ +cfg ( -render_bundle_id +feature += +" +trace +" ) -{ -Ok +] +if +let +Some ( -bundle +ref +mut +trace ) = -> -{ -bundle -. -life_guard -. -ref_count -. -take -( -) -; -bundle +* +device . -device_id +trace . -value -} -Err +lock ( -InvalidId ) -= -> { -hub -. -render_bundles +trace . -unregister_locked +add ( -render_bundle_id -& -mut -* -bundle_guard +trace +: +: +Action +: +: +DestroyQuerySet +( +query_set_id +) ) ; -return -; -} -} } -; -device_guard -[ -device_id -] +device . lock_life ( -& -mut -token ) . suspected_resources . -render_bundles +insert +( +query_set_id +query_set . -push +clone +( +) +) +; +} +} +pub +fn +query_set_label +< +A +: +HalApi +> ( +& +self +id +: id : : -Valid +QuerySetId +) +- +> +String +{ +A +: +: +hub ( -render_bundle_id +self ) +. +query_sets +. +label_for_resource +( +id ) -; } pub fn -device_create_query_set +device_create_render_pipeline < A : @@ -12770,10 +10917,10 @@ DeviceId desc : & -resource +pipeline : : -QuerySetDescriptor +RenderPipelineDescriptor id_in : Input @@ -12782,7 +10929,16 @@ G id : : -QuerySetId +RenderPipelineId +> +implicit_pipeline_ids +: +Option +< +ImplicitPipelineIds +< +G +> > ) - @@ -12791,13 +10947,13 @@ QuerySetId id : : -QuerySetId +RenderPipelineId Option < -resource +pipeline : : -CreateQuerySetError +CreateRenderPipelineError > ) { @@ -12811,7 +10967,7 @@ scope Device : : -create_query_set +create_render_pipeline " ) ; @@ -12827,44 +10983,47 @@ self ) ; let -mut -token +fid = -Token +hub +. +render_pipelines +. +prepare : : -root +< +G +> ( +id_in ) ; let -fid +implicit_context = -hub +implicit_pipeline_ids . -query_sets +map +( +| +ipi +| +ipi . prepare ( -id_in +hub +) ) ; let -( -device_guard -mut -token -) +implicit_error_context = -hub -. -devices +implicit_context . -read +clone ( -& -mut -token ) ; let @@ -12876,7 +11035,9 @@ let device = match -device_guard +hub +. +devices . get ( @@ -12911,7 +11072,9 @@ if ! device . -valid +is_valid +( +) { break DeviceError @@ -12940,18 +11103,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -12961,7 +11126,7 @@ trace Action : : -CreateQuerySet +CreateRenderPipeline { id : @@ -12977,61 +11142,85 @@ desc clone ( ) +implicit_context +: +implicit_context +. +clone +( +) } ) ; } let -query_set +pipeline = match device . -create_query_set +create_render_pipeline ( -device_id +& +device +. +adapter desc +implicit_context +hub ) { Ok ( -query_set +pair ) = > -query_set +pair Err ( -err +e ) = > break -err +e } ; let -ref_count -= -query_set -. -life_guard -. -add_ref ( -) -; -let id +resource +) = fid . assign ( -query_set -& -mut -token +pipeline +) +; +log +: +: +info +! +( +" +Created +RenderPipeline +{ +: +? +} +with +{ +: +? +} +" +id +desc ) ; device @@ -13042,19 +11231,17 @@ lock ( ) . -query_sets +render_pipelines . insert_single ( id -ref_count +resource ) ; return ( id -. -0 None ) ; @@ -13067,305 +11254,190 @@ fid . assign_error ( -" -" -& -mut -token -) -; -log -: -: -trace -! -( -" -Device -: -: -create_query_set -- -> -{ -: -? -} -" -id -) -; -( -id -Some -( -error -) -) -} -pub -fn -query_set_drop -< -A -: -HalApi -> -( -& -self -query_set_id -: -id -: -: -QuerySetId -) -{ -profiling -: -: -scope -! -( -" -QuerySet -: -: -drop -" -) -; -log -: -: -trace -! +desc +. +label +. +borrow_or_default ( -" -QuerySet -: -: -drop -{ -query_set_id -: -? -} -" ) -; -let -hub -= -A -: -: -hub -( -self ) ; +/ +/ +We +also +need +to +assign +errors +to +the +implicit +pipeline +layout +and +the +/ +/ +implicit +bind +group +layout +. +We +have +to +remove +any +existing +entries +first +. let mut -token +pipeline_layout_guard = -Token -: -: -root +hub +. +pipeline_layouts +. +write ( ) ; let -device_id -= -{ -let -( mut -query_set_guard -_ -) +bgl_guard = hub . -query_sets +bind_group_layouts . write ( -& -mut -token ) ; +if let -query_set +Some +( +ref +ids +) = -query_set_guard +implicit_error_context +{ +if +pipeline_layout_guard . -get_mut +contains ( -query_set_id +ids +. +root_id ) +{ +pipeline_layout_guard . -unwrap +remove ( +ids +. +root_id ) ; -query_set -. -life_guard -. -ref_count +} +pipeline_layout_guard . -take +insert_error ( +ids +. +root_id +IMPLICIT_FAILURE ) ; -query_set +for +& +bgl_id +in +ids . -device_id +group_ids . -value -} -; -let +iter ( -device_guard -mut -token ) -= -hub +{ +if +bgl_guard . -devices +contains +( +bgl_id +) +{ +bgl_guard . -read +remove ( -& -mut -token +bgl_id ) ; -let -device -= -& -device_guard -[ -device_id -] -; -# -[ -cfg -( -feature -= -" -trace -" -) -] -if -let -Some -( -ref -trace -) -= -device -. -trace -{ -trace -. -lock -( -) +} +bgl_guard . -add -( -trace -: -: -Action -: -: -DestroyQuerySet +insert_error ( -query_set_id -) +bgl_id +IMPLICIT_FAILURE ) ; } -device -. -lock_life -( -& -mut -token -) -. -suspected_resources -. -query_sets -. -push +} ( id -: -: -Valid +Some ( -query_set_id +error ) ) -; } -pub -fn -query_set_label -< -A -: -HalApi -> -( -& -self -id -: -id -: -: -QuerySetId -) -- -> -String -{ -A -: -: -hub -( -self -) +/ +/ +/ +Get +an +ID +of +one +of +the +bind +group +layouts . -query_sets +The +ID +adds +a +refcount +/ +/ +/ +which +needs +to +be +released +by +calling +bind_group_layout_drop . -label_for_resource -( -id -) -} pub fn -device_create_render_pipeline +render_pipeline_get_bind_group_layout < A : @@ -13374,16 +11446,15 @@ HalApi ( & self -device_id +pipeline_id : -DeviceId -desc +id : -& -pipeline : +RenderPipelineId +index : -RenderPipelineDescriptor +u32 id_in : Input @@ -13392,16 +11463,7 @@ G id : : -RenderPipelineId -> -implicit_pipeline_ids -: -Option -< -ImplicitPipelineIds -< -G -> +BindGroupLayoutId > ) - @@ -13410,30 +11472,16 @@ G id : : -RenderPipelineId +BindGroupLayoutId Option < -pipeline +binding_model : : -CreateRenderPipelineError +GetBindGroupLayoutError > ) { -profiling -: -: -scope -! -( -" -Device -: -: -create_render_pipeline -" -) -; let hub = @@ -13446,941 +11494,820 @@ self ) ; let -mut -token +error = -Token -: -: -root -( -) -; +loop +{ let -fid +pipeline = +match hub . render_pipelines . -prepare +get ( -id_in +pipeline_id ) -; -let -implicit_context -= -implicit_pipeline_ids -. -map -( -| -ipi -| -ipi -. -prepare +{ +Ok ( -hub -) +pipeline ) -; -let -implicit_error_context = -implicit_context -. -clone +> +pipeline +Err ( +_ ) += +> +break +binding_model +: +: +GetBindGroupLayoutError +: +: +InvalidPipeline +} ; let -( -adapter_guard -mut -token -) +id = -hub +match +pipeline . -adapters +layout . -read +bind_group_layouts +. +get ( -& -mut -token +index +as +usize ) -; -let +{ +Some ( -device_guard -mut -token +bg ) = +> hub . -devices +bind_group_layouts . -read +prepare +: +: +< +G +> ( -& -mut -token +id_in ) -; -let -error -= -loop -{ -let -device -= -match -device_guard . -get -( -device_id -) -{ -Ok -( -device -) -= -> -device -Err +assign_existing ( -_ +bg ) +None = > break -DeviceError +binding_model : : -Invalid -. -into +GetBindGroupLayoutError +: +: +InvalidGroupIndex ( +index ) } ; -if -! -device -. -valid -{ -break -DeviceError -: -: -Lost -. -into +return ( +id +None ) ; } +; let -adapter +id = -& -adapter_guard -[ -device +hub . -adapter_id +bind_group_layouts . -value -] -; -# -[ -cfg +prepare +: +: +< +G +> +( +id_in +) +. +assign_error ( -feature -= " -trace +< +derived +> " ) -] -if -let +; +( +id Some ( -ref -trace +error ) -= -device -. -trace -{ -trace -. -lock -( ) -. -add -( -trace +} +pub +fn +render_pipeline_label +< +A : +HalApi +> +( +& +self +id : -Action +id : : -CreateRenderPipeline +RenderPipelineId +) +- +> +String { -id +A : -fid +: +hub +( +self +) . -id +render_pipelines +. +label_for_resource ( +id ) -desc +} +pub +fn +render_pipeline_drop +< +A : -desc -. -clone +HalApi +> ( +& +self +render_pipeline_id +: +id +: +: +RenderPipelineId ) -implicit_context +{ +profiling : -implicit_context -. -clone +: +scope +! ( +" +RenderPipeline +: +: +drop +" ) +; +log +: +: +debug +! +( +" +RenderPipeline +{ +: +? } +is +asked +to +be +dropped +" +render_pipeline_id ) ; -} let -pipeline +hub = -match -device -. -create_render_pipeline -( -device_id -adapter -desc -implicit_context +A +: +: hub -& -mut -token +( +self ) -{ -Ok +; +if +let +Some ( -pair +pipeline ) = -> -pair -Err +hub +. +render_pipelines +. +unregister ( -e +render_pipeline_id ) -= -> -break -e -} -; +{ let -ref_count +layout_id = pipeline . -life_guard +layout +. +as_info +( +) . -add_ref +id ( ) ; let -id +device = -fid -. -assign -( -pipeline & +pipeline +. +device +; +let mut -token +life_lock += +device +. +lock_life +( ) ; -log -: -: -trace -! +life_lock +. +suspected_resources +. +insert ( -" -Device -: -: -create_render_pipeline -- -> -{ -: -? -} -" -id +render_pipeline_id +pipeline . -0 +clone +( +) ) ; -device +life_lock . -trackers +suspected_resources . -lock +insert ( -) +layout_id +pipeline . -render_pipelines +layout . -insert_single +clone ( -id -ref_count ) -; -return -( -id -. -0 -None ) ; } -; -let -id -= -fid -. -assign_error +} +pub +fn +device_create_compute_pipeline +< +A +: +HalApi +> ( +& +self +device_id +: +DeviceId desc -. -label -. -borrow_or_default +: +& +pipeline +: +: +ComputePipelineDescriptor +id_in +: +Input +< +G +id +: +: +ComputePipelineId +> +implicit_pipeline_ids +: +Option +< +ImplicitPipelineIds +< +G +> +> +) +- +> ( +id +: +: +ComputePipelineId +Option +< +pipeline +: +: +CreateComputePipelineError +> ) -& -mut -token +{ +profiling +: +: +scope +! +( +" +Device +: +: +create_compute_pipeline +" ) ; -/ -/ -We -also -need -to -assign -errors -to -the -implicit -pipeline -layout -and -the -/ -/ -implicit -bind -group -layout -. -We -have -to -remove -any -existing -entries -first -. let +hub += +A +: +: +hub ( -mut -pipeline_layout_guard -mut -token +self ) +; +let +fid = hub . -pipeline_layouts +compute_pipelines . -write +prepare +: +: +< +G +> ( -& -mut -token +id_in ) ; let -( -mut -bgl_guard -_token -) +implicit_context = -hub +implicit_pipeline_ids . -bind_group_layouts +map +( +| +ipi +| +ipi . -write +prepare ( -& -mut -token +hub +) ) ; -if let -Some +implicit_error_context += +implicit_context +. +clone ( -ref -ids ) +; +let +error = -implicit_error_context +loop { -if -pipeline_layout_guard +let +device += +match +hub . -contains -( -ids +devices . -root_id +get +( +device_id ) { -pipeline_layout_guard -. -remove +Ok ( -ids -. -root_id +device ) -; -} -pipeline_layout_guard -. -insert_error += +> +device +Err ( -ids -. -root_id -IMPLICIT_FAILURE +_ ) -; -for -& -bgl_id -in -ids -. -group_ids += +> +break +DeviceError +: +: +Invalid . -iter +into ( ) -{ +} +; if -bgl_guard +! +device . -contains +is_valid ( -bgl_id ) { -bgl_guard +break +DeviceError +: +: +Lost . -remove +into ( -bgl_id ) ; } -bgl_guard -. -insert_error +# +[ +cfg ( -bgl_id -IMPLICIT_FAILURE +feature += +" +trace +" ) -; -} -} -( -id +] +if +let Some ( -error -) +ref +mut +trace ) -} -/ -/ -/ -Get -an -ID -of -one -of -the -bind -group -layouts += +* +device . -The -ID -adds -a -refcount -/ -/ -/ -which -needs -to -be -released -by -calling -bind_group_layout_drop +trace . -pub -fn -render_pipeline_get_bind_group_layout -< -A -: -HalApi -> +lock ( -& -self -pipeline_id -: -id -: -: -RenderPipelineId -index -: -u32 -id_in -: -Input -< -G -id -: -: -BindGroupLayoutId -> ) -- -> +{ +trace +. +add ( -id +trace : : -BindGroupLayoutId -Option -< -binding_model +Action : : -GetBindGroupLayoutError -> -) +CreateComputePipeline { -let -hub -= -A -: +id : -hub +fid +. +id ( -self ) -; -let -mut -token -= -Token +desc : +desc +. +clone +( +) +implicit_context : -root +implicit_context +. +clone ( ) +} +) ; +} let -error -= -loop -{ -let -device_id -; -let -id -; -{ -let -( -pipeline_layout_guard -mut -token -) +pipeline = -hub -. -pipeline_layouts +match +device . -read +create_compute_pipeline ( -& -mut -token +desc +implicit_context +hub ) -; -let +{ +Ok ( -bgl_guard -mut -token +pair ) = -hub -. -bind_group_layouts -. -read +> +pair +Err ( -& -mut -token +e ) += +> +break +e +} ; let ( -_ -mut -token +id +resource ) = -hub -. -bind_groups +fid . -read +assign ( -& -mut -token +pipeline ) ; -let -( -pipeline_guard -_ -) -= -hub -. -render_pipelines -. -read -( -& -mut -token -) -; -let -pipeline -= -match -pipeline_guard -. -get -( -pipeline_id -) -{ -Ok -( -pipeline -) -= -> -pipeline -Err -( -_ -) -= -> -break -binding_model -: -: -GetBindGroupLayoutError +log : : -InvalidPipeline -} -; -id -= -match -pipeline_layout_guard -[ -pipeline -. -layout_id -. -value -] -. -bind_group_layout_ids -. -get +info +! ( -index -as -usize -) +" +Created +ComputePipeline { -Some -( -id -) -= -> -* -id -None -= -> -break -binding_model -: -: -GetBindGroupLayoutError : +? +} +with +{ : -InvalidGroupIndex -( -index -) +? } -; -let -layout -= -& -bgl_guard -[ +" id -] +desc +) ; -layout +device . -multi_ref_count +trackers . -inc +lock ( ) -; -if -G -: -: -ids_are_generated_in_wgpu +. +compute_pipelines +. +insert_single ( +id +resource ) -{ +; return ( id -. -0 None ) ; } -device_id +; +let +id = -layout +fid . -device_id +assign_error +( +desc . -clone +label +. +borrow_or_default ( ) +) ; -} / / -The -ID -is -provided -externally -so -we -must -create -a -new -bind -group +We +also +need +to +assign +errors +to +the +implicit +pipeline layout +and +the / / -with -the -given -ID -as -a -duplicate -of -the +implicit +bind +group +layout +. +We +have +to +remove +any existing -one +entries +first . let -new_layout +mut +pipeline_layout_guard = -BindGroupLayout -{ -device_id -inner -: -crate -: -: -binding_model -: -: -BglOrDuplicate -: -: -< -A -> -: -: -Duplicate -( -id -) -multi_ref_count -: -crate -: -: -MultiRefCount -: -: -new +hub +. +pipeline_layouts +. +write ( ) -} ; let -fid +mut +bgl_guard = hub . bind_group_layouts . -prepare +write ( -id_in ) ; +if let -id +Some +( +ref +ids +) = -fid +implicit_error_context +{ +if +pipeline_layout_guard . -assign +contains ( -new_layout -& -mut -token +ids +. +root_id ) -; -return +{ +pipeline_layout_guard +. +remove ( -id +ids . -0 -None +root_id ) ; } -; -let -id -= -hub +pipeline_layout_guard . -bind_group_layouts +insert_error +( +ids . -prepare +root_id +IMPLICIT_FAILURE +) +; +for +& +bgl_id +in +ids +. +group_ids +. +iter ( -id_in ) +{ +if +bgl_guard . -assign_error +contains ( -" -< -derived -> -" -& -mut -token +bgl_id +) +{ +bgl_guard +. +remove +( +bgl_id +) +; +} +bgl_guard +. +insert_error +( +bgl_id +IMPLICIT_FAILURE ) ; +} +} ( id Some @@ -14389,9 +12316,40 @@ error ) ) } +/ +/ +/ +Get +an +ID +of +one +of +the +bind +group +layouts +. +The +ID +adds +a +refcount +/ +/ +/ +which +needs +to +be +released +by +calling +bind_group_layout_drop +. pub fn -render_pipeline_label +compute_pipeline_get_bind_group_layout < A : @@ -14400,84 +12358,42 @@ HalApi ( & self -id +pipeline_id : id : : -RenderPipelineId -) -- -> -String -{ -A +ComputePipelineId +index : +u32 +id_in : -hub -( -self -) -. -render_pipelines -. -label_for_resource -( -id -) -} -pub -fn -render_pipeline_drop +Input < -A -: -HalApi -> -( -& -self -render_pipeline_id -: +G id : : -RenderPipelineId +BindGroupLayoutId +> ) -{ -profiling -: -: -scope -! +- +> ( -" -RenderPipeline -: -: -drop -" -) -; -log -: +id : -trace -! -( -" -RenderPipeline : +BindGroupLayoutId +Option +< +binding_model : -drop -{ : -? -} -" -render_pipeline_id +GetBindGroupLayoutError +> ) -; +{ let hub = @@ -14490,65 +12406,30 @@ self ) ; let -mut -token +error = -Token -: -: -root -( -) -; +loop +{ let -( -device_guard -mut -token -) +pipeline_guard = hub . -devices +compute_pipelines . read ( -& -mut -token ) ; let -( -device_id -layout_id -) -= -{ -let -( -mut -pipeline_guard -_ -) +pipeline = -hub -. -render_pipelines -. -write -( -& -mut -token -) -; match pipeline_guard . -get_mut +get ( -render_pipeline_id +pipeline_id ) { Ok @@ -14557,106 +12438,125 @@ pipeline ) = > -{ pipeline -. -life_guard -. -ref_count -. -take +Err ( +_ ) += +> +break +binding_model +: +: +GetBindGroupLayoutError +: +: +InvalidPipeline +} ; -( +let +id += +match pipeline . -device_id -. -value -pipeline +layout . -layout_id +bind_group_layouts . -clone +get ( +index +as +usize ) -) -} -Err +{ +Some ( -InvalidId +bg ) = > -{ hub . -render_pipelines +bind_group_layouts . -unregister_locked -( -render_pipeline_id -& -mut -* -pipeline_guard +prepare +: +: +< +G +> +( +id_in +) +. +assign_existing +( +bg +) +None += +> +break +binding_model +: +: +GetBindGroupLayoutError +: +: +InvalidGroupIndex +( +index ) +} ; return +( +id +None +) ; } -} -} ; let -mut -life_lock +id = -device_guard -[ -device_id -] -. -lock_life -( -& -mut -token -) -; -life_lock -. -suspected_resources +hub . -render_pipelines +bind_group_layouts . -push -( -id +prepare : : -Valid +< +G +> ( -render_pipeline_id -) +id_in ) -; -life_lock -. -suspected_resources -. -pipeline_layouts . -push +assign_error ( -layout_id +" +< +derived +> +" ) ; +( +id +Some +( +error +) +) } pub fn -device_create_compute_pipeline +compute_pipeline_label < A : @@ -14665,50 +12565,49 @@ HalApi ( & self -device_id -: -DeviceId -desc -: -& -pipeline -: -: -ComputePipelineDescriptor -id_in +id : -Input -< -G id : : ComputePipelineId -> -implicit_pipeline_ids -: -Option -< -ImplicitPipelineIds -< -G -> -> ) - > +String +{ +A +: +: +hub +( +self +) +. +compute_pipelines +. +label_for_resource ( id +) +} +pub +fn +compute_pipeline_drop +< +A : +HalApi +> +( +& +self +compute_pipeline_id : -ComputePipelineId -Option -< -pipeline +id : : -CreateComputePipelineError -> +ComputePipelineId ) { profiling @@ -14718,11 +12617,32 @@ scope ! ( " -Device +ComputePipeline : : -create_compute_pipeline +drop +" +) +; +log +: +: +debug +! +( " +ComputePipeline +{ +: +? +} +is +asked +to +be +dropped +" +compute_pipeline_id ) ; let @@ -14736,1008 +12656,900 @@ hub self ) ; +if let -mut -token -= -Token -: -: -root +Some ( +pipeline ) -; -let -fid = hub . compute_pipelines . -prepare +unregister ( -id_in +compute_pipeline_id ) -; +{ let -implicit_context +layout_id = -implicit_pipeline_ids +pipeline . -map -( -| -ipi -| -ipi +layout . -prepare +as_info ( -hub ) +. +id +( ) ; let -implicit_error_context +device = -implicit_context +& +pipeline . -clone -( -) +device ; let -( -device_guard mut -token -) +life_lock = -hub -. -devices +device . -read +lock_life ( -& -mut -token ) ; -let -error -= -loop -{ -let -device -= -match -device_guard +life_lock . -get +suspected_resources +. +insert ( -device_id -) -{ -Ok +compute_pipeline_id +pipeline +. +clone ( -device ) -= -> -device -Err -( -_ ) -= -> -break -DeviceError -: -: -Invalid +; +life_lock . -into +suspected_resources +. +insert ( -) -} -; -if -! -device +layout_id +pipeline . -valid -{ -break -DeviceError -: -: -Lost +layout . -into +clone ( ) +) ; } -# -[ -cfg -( -feature -= -" -trace -" -) -] -if -let -Some -( -ref -trace -) -= -device -. -trace -{ -trace -. -lock +} +pub +fn +surface_configure +< +A +: +HalApi +> ( +& +self +surface_id +: +SurfaceId +device_id +: +DeviceId +config +: +& +wgt +: +: +SurfaceConfiguration +< +Vec +< +TextureFormat +> +> ) -. -add -( -trace +- +> +Option +< +present : : -Action +ConfigureSurfaceError +> +{ +use +hal : : -CreateComputePipeline { -id +Adapter +as +_ +Surface +as +_ +} +; +use +present : -fid -. -id -( -) -desc : -desc -. -clone -( -) -implicit_context +ConfigureSurfaceError +as +E +; +profiling : -implicit_context -. -clone +: +scope +! ( -) -} +" +surface_configure +" ) ; -} -let -pipeline -= -match -device -. -create_compute_pipeline +fn +validate_surface_configuration ( -device_id -desc -implicit_context -hub +config +: & mut -token -) -{ -Ok -( -pair +hal +: +: +SurfaceConfiguration +caps +: +& +hal +: +: +SurfaceCapabilities ) -= +- > -pair -Err +Result +< ( -e ) -= +E > -break -e -} -; +{ let -ref_count +width = -pipeline +config . -life_guard +extent . -add_ref -( -) +width ; let -id +height = -fid +config . -assign -( -pipeline -& -mut -token -) -; -log -: -: -trace -! -( -" -Device -: -: -create_compute_pipeline -- -> -{ -: -? -} -" -id +extent . -0 -) +height ; -device +if +width +< +caps . -trackers +extents . -lock +start ( ) . -compute_pipelines +width +| +| +width +> +caps . -insert_single +extents +. +end ( -id -ref_count ) -; -return -( -id . -0 -None -) -; -} -; -let -id -= -fid -. -assign_error -( -desc +width +| +| +height +< +caps . -label +extents . -borrow_or_default +start ( ) -& -mut -token -) -; -/ -/ -We -also -need -to -assign -errors -to -the -implicit -pipeline -layout -and -the -/ -/ -implicit -bind -group -layout . -We -have -to -remove -any -existing -entries -first -. -let -( -mut -pipeline_layout_guard -mut -token -) -= -hub +height +| +| +height +> +caps . -pipeline_layouts +extents . -write -( -& -mut -token -) -; -let +end ( -mut -bgl_guard -_token ) -= -hub -. -bind_group_layouts . -write -( -& -mut -token -) -; -if -let -Some -( -ref -ids -) -= -implicit_error_context +height { -if -pipeline_layout_guard -. -contains +log +: +: +warn +! ( -ids -. -root_id -) +" +Requested +size { -pipeline_layout_guard -. -remove -( -ids +} +x +{ +} +is +outside +of +the +supported +range +: +{ +: +? +} +" +width +height +caps . -root_id +extents ) ; } -pipeline_layout_guard +if +! +caps . -insert_error -( -ids +present_modes . -root_id -IMPLICIT_FAILURE -) -; -for +contains +( & -bgl_id -in -ids -. -group_ids +config . -iter -( +present_mode ) { -if -bgl_guard -. -contains -( -bgl_id -) +let +new_mode += +' +b +: +loop { -bgl_guard -. -remove -( -bgl_id -) -; -} -bgl_guard -. -insert_error -( -bgl_id -IMPLICIT_FAILURE -) -; -} -} -( -id -Some -( -error -) -) -} -/ / / -Get -an -ID -of -one -of -the -bind -group -layouts +Automatic +present +mode +checks . -The -ID -adds -a -refcount / / / -which -needs -to -be -released +/ +The +" +Automatic +" +modes +are +never +supported by -calling -bind_group_layout_drop +the +backends . -pub -fn -compute_pipeline_get_bind_group_layout -< -A -: -HalApi -> -( +let +fallbacks += +match +config +. +present_mode +{ +wgt +: +: +PresentMode +: +: +AutoVsync += +> +{ & -self -pipeline_id +[ +wgt : -id : +PresentMode : -ComputePipelineId -index : -u32 -id_in +FifoRelaxed +wgt : -Input -< -G -id : +PresentMode : -BindGroupLayoutId -> -) -- +: +Fifo +] +[ +. +. +] +} +/ +/ +Always +end +in +FIFO +to +make +sure +it +' +s +always +supported +wgt +: +: +PresentMode +: +: +AutoNoVsync += > -( -id +& +[ +wgt : : -BindGroupLayoutId -Option -< -binding_model +PresentMode : : -GetBindGroupLayoutError +Immediate +wgt +: +: +PresentMode +: +: +Mailbox +wgt +: +: +PresentMode +: +: +Fifo +] +[ +. +. +] +_ += > -) { -let -hub -= -A +return +Err +( +E : : -hub -( -self -) -; -let -mut -token -= -Token +UnsupportedPresentMode +{ +requested : +config +. +present_mode +available : -root +caps +. +present_modes +. +clone ( ) +} +) ; -let -error -= -loop -{ -let -device_id -; -let -id +} +} ; +for +& +fallback +in +fallbacks { -let -( -pipeline_layout_guard -mut -token -) -= -hub +if +caps . -pipeline_layouts +present_modes . -read +contains ( & -mut -token +fallback ) +{ +break +' +b +fallback ; -let +} +} +unreachable +! ( -bgl_guard -mut -token -) -= -hub +" +Fallback +system +failed +to +choose +present +mode . -bind_group_layouts +This +is +a +bug . -read -( +Mode +: +{ +: +? +} +Options +: +{ +: +? +} +" +config +. +present_mode & -mut -token +caps +. +present_modes ) ; -let +} +; +log +: +: +info +! ( -_ -mut -token -) -= -hub +" +Automatically +choosing +presentation +mode +by +rule +{ +: +? +} . -bind_groups +Chose +{ +new_mode +: +? +} +" +config . -read -( -& -mut -token +present_mode ) ; -let -( -pipeline_guard -_ -) +config +. +present_mode = -hub +new_mode +; +} +if +! +caps . -compute_pipelines +formats . -read +contains ( & -mut -token -) -; -let -pipeline -= -match -pipeline_guard +config . -get -( -pipeline_id +format ) { -Ok -( -pipeline -) -= -> -pipeline +return Err ( -_ -) -= -> -break -binding_model -: -: -GetBindGroupLayoutError +E : : -InvalidPipeline -} -; -id -= -match -pipeline_layout_guard -[ -pipeline -. -layout_id -. -value -] -. -bind_group_layout_ids -. -get -( -index -as -usize -) +UnsupportedFormat { -Some -( -id -) -= -> -* -id -None -= -> -break -binding_model -: -: -GetBindGroupLayoutError +requested : +config +. +format +available : -InvalidGroupIndex -( -index -) -} -; -let -layout -= -& -bgl_guard -[ -id -] -; -layout +caps . -multi_ref_count +formats . -inc -( -) -; -if -G -: -: -ids_are_generated_in_wgpu +clone ( ) -{ -return -( -id -. -0 -None +} ) ; } -device_id -= -layout +if +! +caps . -device_id +composite_alpha_modes . -clone +contains ( +& +config +. +composite_alpha_mode ) -; -} -/ -/ -The -ID -is -provided -externally -so -we -must -create -a -new -bind -group -layout +{ +let +new_alpha_mode += +' +alpha +: +loop +{ / / -with -the -given -ID -as -a -duplicate -of -the -existing -one +Automatic +alpha +mode +checks . let -new_layout +fallbacks = -BindGroupLayout +match +config +. +composite_alpha_mode { -device_id -inner +wgt : -crate +: +CompositeAlphaMode : : -binding_model +Auto += +> +& +[ +wgt : : -BglOrDuplicate +CompositeAlphaMode : : -< -A -> +Opaque +wgt : : -Duplicate -( -id -) -multi_ref_count +CompositeAlphaMode : -crate +: +Inherit +] +[ +. +. +] +_ += +> +{ +return +Err +( +E : : -MultiRefCount +UnsupportedAlphaMode +{ +requested : +config +. +composite_alpha_mode +available : -new +caps +. +composite_alpha_modes +. +clone ( ) } +) ; -let -fid -= -hub +} +} +; +for +& +fallback +in +fallbacks +{ +if +caps . -bind_group_layouts +composite_alpha_modes . -prepare +contains ( -id_in -) -; -let -id -= -fid -. -assign -( -new_layout & -mut -token -) -; -return -( -id -. -0 -None +fallback ) +{ +break +' +alpha +fallback ; } -; -let -id -= -hub -. -bind_group_layouts -. -prepare -( -id_in -) -. -assign_error +} +unreachable +! ( " -< -derived -> +Fallback +system +failed +to +choose +alpha +mode +. +This +is +a +bug +. +\ +AlphaMode +: +{ +: +? +} +Options +: +{ +: +? +} " +config +. +composite_alpha_mode & -mut -token +caps +. +composite_alpha_modes ) ; -( -id -Some -( -error -) -) } -pub -fn -compute_pipeline_label -< -A -: -HalApi -> -( -& -self -id -: -id +; +log : : -ComputePipelineId -) -- -> -String +info +! +( +" +Automatically +choosing +alpha +mode +by +rule { -A : +? +} +. +Chose +{ +new_alpha_mode : -hub -( -self +? +} +" +config +. +composite_alpha_mode ) +; +config . -compute_pipelines +composite_alpha_mode += +new_alpha_mode +; +} +if +! +caps . -label_for_resource +usage +. +contains ( -id +config +. +usage ) -} -pub -fn -compute_pipeline_drop -< -A -: -HalApi -> +{ +return +Err ( -& -self -compute_pipeline_id -: -id +E : : -ComputePipelineId +UnsupportedUsage ) +; +} +if +width += += +0 +| +| +height += += +0 { -profiling -: -: -scope -! +return +Err ( -" -ComputePipeline +E : : -drop -" +ZeroArea ) ; +} +Ok +( +( +) +) +} log : : -trace +debug ! ( " -ComputePipeline -: -: -drop +configuring +surface +with { : ? } " -compute_pipeline_id +config ) ; let +error += +' +outer +: +loop +{ +/ +/ +User +callbacks +must +not +be +called +while +we +are +holding +locks +. +let +user_callbacks +; +{ +let hub = A @@ -15749,22 +13561,18 @@ self ) ; let -mut -token +surface_guard = -Token -: -: -root +self +. +surfaces +. +read ( ) ; let -( device_guard -mut -token -) = hub . @@ -15772,1088 +13580,1001 @@ devices . read ( -& -mut -token ) ; let -( -device_id -layout_id -) -= -{ -let -( -mut -pipeline_guard -_ -) +device = -hub -. -compute_pipelines -. -write -( -& -mut -token -) -; match -pipeline_guard +device_guard . -get_mut +get ( -compute_pipeline_id +device_id ) { Ok ( -pipeline +device ) = > -{ -pipeline -. -life_guard -. -ref_count -. -take +device +Err ( +_ ) -; -( -pipeline -. -device_id -. -value -pipeline -. -layout_id += +> +break +DeviceError +: +: +Invalid . -clone +into ( ) -) } -Err +; +if +! +device +. +is_valid ( -InvalidId ) -= -> { -hub -. -compute_pipelines +break +DeviceError +: +: +Lost . -unregister_locked +into ( -compute_pipeline_id -& -mut -* -pipeline_guard ) ; -return -; -} -} } -; -let -mut -life_lock -= -device_guard +# [ -device_id +cfg +( +feature += +" +trace +" +) ] -. -lock_life +if +let +Some ( -& +ref mut -token +trace ) -; -life_lock += +* +device . -suspected_resources +trace . -compute_pipelines +lock +( +) +{ +trace . -push +add ( -id +trace +: +: +Action : : -Valid +ConfigureSurface ( -compute_pipeline_id -) -) -; -life_lock -. -suspected_resources -. -pipeline_layouts +surface_id +config . -push +clone ( -layout_id +) +) ) ; } -pub -fn -surface_configure -< -A -: -HalApi -> +let +surface += +match +surface_guard +. +get ( -& -self surface_id -: -SurfaceId -device_id -: -DeviceId -config -: -& -wgt -: -: -SurfaceConfiguration -< -Vec -< -TextureFormat -> -> ) -- +{ +Ok +( +surface +) += > -Option -< -present -: -: -ConfigureSurfaceError +surface +Err +( +_ +) += > -{ -use -hal +break +E : : -{ -Adapter -as -_ -Surface -as -_ +InvalidSurface } ; -use -present -: -: -ConfigureSurfaceError -as -E -; -profiling +let +caps += +unsafe +{ +let +suf += +A : : -scope -! +get_surface ( -" -surface_configure -" +surface ) ; -fn -validate_surface_configuration -( -config -: -& -mut -hal -: -: -SurfaceConfiguration -caps -: +let +adapter += & -hal -: -: -SurfaceCapabilities -) -- -> -Result -< -( -) -E -> -{ -let -width -= -config -. -extent +device . -width +adapter ; -let -height -= -config +match +adapter . -extent +raw . -height -; -if -width -< -caps +adapter . -extents +surface_capabilities +( +suf . -start +unwrap ( ) . -width -| -| -width -> -caps -. -extents +raw . -end +as_ref ( ) -. -width -| -| -height -< +) +{ +Some +( +caps +) += +> caps +None += +> +break +E +: +: +UnsupportedQueueFamily +} +} +; +let +mut +hal_view_formats += +vec +! +[ +] +; +for +format +in +config . -extents +view_formats . -start +iter ( ) +{ +if +* +format += += +config . -height -| -| -height -> +format +{ +continue +; +} +if +! caps . -extents +formats . -end +contains ( -) +& +config . -height +format +) { -log +break +' +outer +E : : -warn -! -( -" -Requested -size -{ -} -x +UnsupportedFormat { -} -is -outside -of -the -supported -range +requested : -{ +config +. +format +available : -? -} -" -width -height caps . -extents -) +formats +} ; } if -! -caps +config . -present_modes +format . -contains +remove_srgb_suffix ( -& -config +) +! += +format . -present_mode +remove_srgb_suffix +( ) { -let -new_mode -= +break ' -b +outer +E : -loop -{ -/ -/ -Automatic -present -mode -checks +: +InvalidViewFormat +( +* +format +config . -/ -/ -/ -/ -The -" -Automatic -" -modes -are -never -supported -by -the -backends +format +) +; +} +hal_view_formats +. +push +( +* +format +) +; +} +if +! +hal_view_formats . +is_empty +( +) +{ +if let -fallbacks +Err +( +missing_flag +) = -match -config +device . -present_mode -{ +require_downlevel_flags +( wgt : : -PresentMode +DownlevelFlags : : -AutoVsync -= -> +SURFACE_VIEW_FORMATS +) { -& -[ -wgt -: -: -PresentMode -: -: -FifoRelaxed -wgt +break +' +outer +E : : -PresentMode +MissingDownlevelFlags +( +missing_flag +) +; +} +} +let +num_frames += +present : : -Fifo -] -[ +DESIRED_NUM_FRAMES . +clamp +( +* +caps +. +swap_chain_sizes +. +start +( +) +* +caps +. +swap_chain_sizes . -] -} -/ -/ -Always end -in -FIFO -to -make -sure -it -' -s -always -supported -wgt -: +( +) +) +; +let +mut +hal_config += +hal : -PresentMode : +SurfaceConfiguration +{ +swap_chain_size : -AutoNoVsync -= -> -& -[ -wgt +num_frames +present_mode : +config +. +present_mode +composite_alpha_mode : -PresentMode +config +. +alpha_mode +format : +config +. +format +extent : -Immediate wgt : : -PresentMode +Extent3d +{ +width : +config +. +width +height : -Mailbox -wgt +config +. +height +depth_or_array_layers : +1 +} +usage : -PresentMode +conv : : -Fifo -] -[ -. -. -] -_ -= -> -{ -return -Err +map_texture_usage ( -E +config +. +usage +hal : : -UnsupportedPresentMode -{ -requested +FormatAspects : -config -. -present_mode -available : -caps -. -present_modes -. -clone -( -) -} +COLOR ) -; -} +view_formats +: +hal_view_formats } ; -for -& -fallback -in -fallbacks -{ if -caps -. -present_modes -. -contains +let +Err +( +error +) += +validate_surface_configuration ( & -fallback +mut +hal_config +& +caps ) { break -' -b -fallback +error ; } -} -unreachable -! -( -" -Fallback -system -failed +/ +/ +Wait +for +all +work to -choose -present -mode -. -This -is -a -bug +finish +before +configuring +the +surface . -Mode -: -{ -: -? -} -Options -: -{ -: -? -} -" -config +let +fence += +device . -present_mode -& -caps +fence . -present_modes +read +( ) ; -} +let +fence += +fence +. +as_ref +( +) +. +unwrap +( +) ; -log +match +device +. +maintain +( +hub +fence +wgt : : -info -! +Maintain +: +: +Wait +) +{ +Ok ( -" -Automatically -choosing -presentation -mode -by -rule +( +closures +_ +) +) += +> { -: -? +user_callbacks += +closures +; } -. -Chose +Err +( +e +) += +> { -new_mode -: -? -} -" -config +break +e . -present_mode +into +( ) ; -config -. -present_mode -= -new_mode -; } +} +/ +/ +All +textures +must +be +destroyed +before +the +surface +can +be +re +- +configured +. if -! -caps +let +Some +( +present +) += +surface . -formats +presentation . -contains +lock ( -& -config +) . -format +take +( ) { -return -Err +if +present +. +acquired_texture +. +is_some ( +) +{ +break E : : -UnsupportedFormat -{ -requested +PreviousOutputExists +; +} +} +/ +/ +TODO : -config +Texture +views +may +still +be +alive +that +point +to +the +texture . -format -available -: -caps +/ +/ +this +will +allow +the +user +to +render +to +the +surface +texture +long +after +/ +/ +it +has +been +removed . -formats +/ +/ +/ +/ +https +: +/ +/ +github . -clone +com +/ +gfx +- +rs +/ +wgpu +/ +issues +/ +4105 +match +unsafe +{ +A +: +: +get_surface ( +surface ) -} +. +unwrap +( ) -; -} -if -! -caps . -composite_alpha_modes +raw . -contains +configure ( -& -config +device . -composite_alpha_mode +raw +( ) +& +hal_config +) +} { -let -new_alpha_mode +Ok +( +( +) +) = -' -alpha -: -loop -{ -/ -/ -Automatic -alpha -mode -checks -. -let -fallbacks +> +( +) +Err +( +error +) = +> +{ +break match -config -. -composite_alpha_mode +error { -wgt +hal : : -CompositeAlphaMode +SurfaceError : : -Auto -= -> -& -[ -wgt +Outdated +| +hal : : -CompositeAlphaMode +SurfaceError : : -Opaque -wgt +Lost += +> +{ +E : : -CompositeAlphaMode +InvalidSurface +} +hal : : -Inherit -] -[ -. -. -] -_ +SurfaceError +: +: +Device +( +error +) = > -{ -return -Err -( E : : -UnsupportedAlphaMode -{ -requested -: -config -. -composite_alpha_mode -available -: -caps -. -composite_alpha_modes +Device +( +error . -clone +into ( ) -} ) -; -} -} -; -for -& -fallback -in -fallbacks -{ -if -caps -. -composite_alpha_modes -. -contains +hal +: +: +SurfaceError +: +: +Other ( -& -fallback +message ) += +> { -break -' -alpha -fallback -; -} -} -unreachable +log +: +: +error ! ( " -Fallback -system +surface +configuration failed -to -choose -alpha -mode -. -This -is -a -bug -. -\ -AlphaMode : { -: -? } -Options +" +message +) +; +E : -{ : -? +InvalidSurface } -" -config +} +} +} +let +mut +presentation += +surface . -composite_alpha_mode -& -caps +presentation . -composite_alpha_modes +lock +( ) ; -} -; -log +* +presentation += +Some +( +present : : -info -! -( -" -Automatically -choosing -alpha -mode -by -rule +Presentation { +device : -? -} -. -Chose -{ -new_alpha_mode +super : -? -} -" -config +: +any_device +: +: +AnyDevice +: +: +new +( +device . -composite_alpha_mode +clone +( +) ) -; config -. -composite_alpha_mode -= -new_alpha_mode -; -} -if -! -caps -. -usage -. -contains -( +: config . -usage -) -{ -return -Err +clone ( -E -: +) +num_frames +acquired_texture : -UnsupportedUsage +None +} ) ; } -if -width -= -= -0 -| -| -height -= -= -0 -{ -return -Err +user_callbacks +. +fire ( -E -: -: -ZeroArea ) ; +return +None +; } -Ok -( +; +Some ( -) +error ) } -log -: -: -info -! +# +[ +cfg ( +feature += " -configuring -surface -with -{ -: -? -} +replay " -config ) -; -let -error -= -' -outer -: -loop -{ +] / / -User -callbacks -must -not -be -called -while -we -are -holding -locks +/ +Only +triange +suspected +resource +IDs . -let -user_callbacks -; -{ -let -hub -= +This +helps +us +to +avoid +ID +collisions +/ +/ +/ +upon +creating +new +resources +when +re +- +playing +a +trace +. +pub +fn +device_maintain_ids +< A : -: -hub +HalApi +> ( +& self +device_id +: +DeviceId ) -; +- +> +Result +< +( +) +InvalidDevice +> +{ let -mut -token +hub = -Token +A : : -root -( -) -; -let +hub ( -mut -surface_guard -mut -token -) -= self -. -surfaces -. -write -( -& -mut -token ) ; let -( -adapter_guard -mut -token -) +device = hub . -adapters +devices . -read -( -& -mut -token -) -; -let +get ( -device_guard -mut -token +device_id ) -= -hub -. -devices . -read +map_err ( -& -mut -token +| +_ +| +InvalidDevice ) +? ; -let +if +! device -= -match -device_guard . -get +is_valid ( -device_id ) { -Ok +return +Err ( -device +InvalidDevice ) -= -> +; +} device -Err +. +lock_life ( -_ ) -= -> -break -DeviceError -: -: -Invalid . -into +triage_suspected ( -) -} -; -if -! +hub +& device . -valid -{ -break -DeviceError -: -: -Lost -. -into -( -) -; -} +trackers # [ cfg @@ -16865,819 +14586,814 @@ trace " ) ] -if -let -Some -( -ref -trace +None ) -= -device -. -trace -{ -trace -. -lock +; +Ok ( +( +) ) +} +/ +/ +/ +Check +device_id +for +freeable +resources +and +completed +buffer +mappings . -add +/ +/ +/ +/ +/ +/ +Return +queue_empty +indicating +whether +there +are +more +queue +submissions +still +in +flight +. +pub +fn +device_poll +< +A +: +HalApi +> ( -trace +& +self +device_id : +DeviceId +maintain : -Action +wgt : : -ConfigureSurface -( -surface_id -config -. -clone -( -) -) +Maintain +< +queue +: +: +WrappedSubmissionIndex +> ) -; -} -let -surface -= -match -surface_guard -. -get_mut -( -surface_id -) -{ -Ok -( -surface -) -= +- > -surface -Err -( -_ -) -= +Result +< +bool +WaitIdleError > -break -E +{ +log : : -InvalidSurface -} +trace +! +( +" +Device +: +: +poll +" +) ; let -caps +( +closures +queue_empty +) = -unsafe { +if let -suf -= -A +wgt : : -get_surface +Maintain +: +: +WaitForSubmissionIndex ( -surface +submission_index ) -; -let -adapter = -& -adapter_guard -[ -device -. -adapter_id -. -value -] -; -match -adapter -. -raw -. -adapter +maintain +{ +if +submission_index . -surface_capabilities +queue_id +! += +device_id +{ +return +Err ( -& -suf -. -unwrap +WaitIdleError +: +: +WrongSubmissionIndex ( -) +submission_index . -raw +queue_id +device_id ) -{ -Some -( -caps ) +; +} +} +let +hub = -> -caps -None -= -> -break -E +A : : -UnsupportedQueueFamily -} -} +hub +( +self +) ; let -mut -hal_view_formats +device = -vec -! -[ -] -; -for -format -in -config +hub . -view_formats +devices . -iter +get ( +device_id ) -{ -if -* -format -= -= -config -. -format -{ -continue -; -} -if -! -caps -. -formats . -contains +map_err ( -& -config -. -format -) -{ -break -' -outer -E -: -: -UnsupportedFormat -{ -requested +| +_ +| +DeviceError : -config -. -format -available : -caps -. -formats -} +Invalid +) +? ; -} -if -config +let +fence += +device . -format +fence . -remove_srgb_suffix +read ( ) -! +; +let +fence = -format +fence . -remove_srgb_suffix +as_ref ( ) -{ -break -' -outer -E -: -: -InvalidViewFormat -( -* -format -config . -format +unwrap +( ) ; -} -hal_view_formats +device . -push +maintain ( -* -format +hub +fence +maintain ) -; +? } -if -! -hal_view_formats +; +closures . -is_empty +fire ( ) -{ -if -let -Err +; +Ok ( -missing_flag +queue_empty ) -= -device -. -require_downlevel_flags -( -wgt -: -: -DownlevelFlags -: -: -SURFACE_VIEW_FORMATS +} +/ +/ +/ +Poll +all +devices +belonging +to +the +backend +A +. +/ +/ +/ +/ +/ +/ +If +force_wait +is +true +block +until +all +buffer +mappings +are +done +. +/ +/ +/ +/ +/ +/ +Return +all_queue_empty +indicating +whether +there +are +more +queue +/ +/ +/ +submissions +still +in +flight +. +fn +poll_device +< +A +: +HalApi +> +( +& +self +force_wait +: +bool +closures +: +& +mut +UserClosures ) +- +> +Result +< +bool +WaitIdleError +> { -break -' -outer -E +profiling : : -MissingDownlevelFlags +scope +! ( -missing_flag +" +poll_device +" ) ; -} -} let -num_frames +hub = -present +A : : -DESIRED_NUM_FRAMES -. -clamp -( -* -caps -. -swap_chain_sizes -. -start -( -) -* -caps -. -swap_chain_sizes -. -end +hub ( -) +self ) ; let mut -hal_config +all_queue_empty = -hal -: -: -SurfaceConfiguration +true +; { -swap_chain_size -: -num_frames -present_mode -: -config +let +device_guard += +hub . -present_mode -composite_alpha_mode -: -config +devices . -alpha_mode -format -: -config +read +( +) +; +for +( +_id +device +) +in +device_guard . -format -extent -: -wgt +iter +( +A : : -Extent3d +VARIANT +) { -width -: -config -. -width -height -: -config -. -height -depth_or_array_layers -: -1 -} -usage +let +maintain += +if +force_wait +{ +wgt : -conv : +Maintain : -map_texture_usage -( -config -. -usage -hal : +Wait +} +else +{ +wgt : -FormatAspects : +Maintain : -COLOR -) -view_formats : -hal_view_formats +Poll } ; -if let -Err +fence += +device +. +fence +. +read ( -error ) +; +let +fence = -validate_surface_configuration +fence +. +as_ref ( -& -mut -hal_config -& -caps ) -{ -break -error -; -} -/ -/ -Wait -for -all -work -to -finish -before -configuring -the -surface . -match +unwrap +( +) +; +let +( +cbs +queue_empty +) += device . maintain ( hub -wgt -: -: -Maintain -: -: -Wait -& -mut -token -) -{ -Ok -( -( -closures -_ -) +fence +maintain ) -= -> -{ -user_callbacks -= -closures +? ; -} -Err -( -e -) +all_queue_empty = -> -{ -break -e +all_queue_empty +& +& +queue_empty +; +closures . -into +extend ( +cbs ) ; } } -/ -/ -All -textures -must -be -destroyed -before -the -surface -can -be -re -- -configured -. -if -let -Some -( -present -) -= -surface -. -presentation -. -take -( -) -{ -if -present -. -acquired_texture -. -is_some +Ok ( +all_queue_empty ) -{ -break -E -: -: -PreviousOutputExists -; -} } / / -TODO -: -Texture -views -may -still -be -alive -that -point -to -the -texture +/ +Poll +all +devices +on +all +backends . / / -this -will -allow -the -user -to -render -to -the -surface -texture -long -after / / -it -has -been -removed -. / / +This +is +the +implementation +of +wgpu +: +: +Instance +: +: +poll_all +. +/ / / -https -: / / -github -. -com / -gfx -- -rs +Return +all_queue_empty +indicating +whether +there +are +more +queue / -wgpu / -issues / -4105 -match -unsafe -{ -A -: -: -get_surface_mut -( -surface -) -. -unwrap -( -) -. -raw +submissions +still +in +flight . -configure +pub +fn +poll_all_devices ( & -device -. -raw -& -hal_config +self +force_wait +: +bool ) -} +- +> +Result +< +bool +WaitIdleError +> { -Ok -( +let +mut +closures += +UserClosures +: +: +default ( ) -) +; +let +mut +all_queue_empty = -> +true +; +# +[ +cfg ( -) -Err +all ( -error -) +feature = -> -{ -break -match -error +" +vulkan +" +not +( +target_arch += +" +wasm32 +" +) +) +) +] { -hal -: -: -SurfaceError +all_queue_empty += +self +. +poll_device : : -Outdated -| +< hal : : -SurfaceError +api : : -Lost -= +Vulkan > +( +force_wait +& +mut +closures +) +? +& +& +all_queue_empty +; +} +# +[ +cfg +( +all +( +feature += +" +metal +" +any +( +target_os += +" +macos +" +target_os += +" +ios +" +) +) +) +] { -E +all_queue_empty += +self +. +poll_device : : -InvalidSurface -} +< hal : : -SurfaceError +api : : -Device +Metal +> ( -error +force_wait +& +mut +closures ) -= -> -E -: -: -Device +? +& +& +all_queue_empty +; +} +# +[ +cfg ( -error -. -into +all ( +feature += +" +dx12 +" +windows ) ) +] +{ +all_queue_empty += +self +. +poll_device +: +: +< hal : : -SurfaceError +api : : -Other +Dx12 +> ( -message +force_wait +& +mut +closures ) -= -> -{ -log -: -: -error -! +? +& +& +all_queue_empty +; +} +# +[ +cfg +( +all ( +feature += " -surface -configuration -failed -: -{ -} +dx11 " -message +windows ) -; -E -: -: -InvalidSurface -} -} -} -} -surface -. -presentation +) +] +{ +all_queue_empty = -Some -( -present -: +self +. +poll_device : -Presentation -{ -device_id : -Stored -{ -value +< +hal : -id : +api : -Valid -( -device_id -) -ref_count : -device -. -life_guard -. -add_ref +Dx11 +> ( +force_wait +& +mut +closures ) +? +& +& +all_queue_empty +; } -config -: -config -. -clone +# +[ +cfg ( +feature += +" +gles +" ) -num_frames -acquired_texture +] +{ +all_queue_empty += +self +. +poll_device : -None -} +: +< +hal +: +: +api +: +: +Gles +> +( +force_wait +& +mut +closures ) +? +& +& +all_queue_empty ; } -user_callbacks +closures . fire ( ) ; -return -None -; -} -; -Some +Ok ( -error +all_queue_empty ) } -# -[ -cfg +pub +fn +device_label +< +A +: +HalApi +> ( -feature -= -" -replay -" -) -] -/ -/ -/ -Only -triange -suspected -resource -IDs -. -This -helps -us -to -avoid -ID -collisions -/ -/ -/ -upon -creating -new -resources -when -re +& +self +id +: +DeviceId +) - -playing -a -trace +> +String +{ +A +: +: +hub +( +self +) +. +devices . +label_for_resource +( +id +) +} pub fn -device_maintain_ids +device_start_capture < A : @@ -17686,165 +15402,81 @@ HalApi ( & self -device_id +id : DeviceId ) -- -> -Result -< -( -) -InvalidDevice -> { -let -hub -= -A +log : : -hub +trace +! ( -self +" +Device +: +: +start_capture +" ) ; let -mut -token +hub = -Token +A : : -root +hub ( +self ) ; +if let +Ok ( -device_guard -mut -token +device ) = hub . devices . -read -( -& -mut -token -) -; -let -device -= -device_guard -. get ( -device_id -) -. -map_err -( -| -_ -| -InvalidDevice +id ) -? -; +{ if ! device . -valid -{ -return -Err +is_valid ( -InvalidDevice ) +{ +return ; } +unsafe +{ device . -lock_life +raw ( -& -mut -token ) . -triage_suspected -( -hub -& -device -. -trackers -# -[ -cfg +start_capture ( -feature -= -" -trace -" -) -] -None -& -mut -token ) +} ; -Ok -( -( -) -) } -/ -/ -/ -Check -device_id -for -freeable -resources -and -completed -buffer -mappings -. -/ -/ -/ -/ -/ -/ -Return -queue_empty -indicating -whether -there -are -more -queue -submissions -still -in -flight -. +} pub fn -device_poll +device_stop_capture < A : @@ -17853,29 +15485,10 @@ HalApi ( & self -device_id +id : DeviceId -maintain -: -wgt -: -: -Maintain -< -queue -: -: -WrappedSubmissionIndex -> ) -- -> -Result -< -bool -WaitIdleError -> { log : @@ -17887,57 +15500,114 @@ trace Device : : -poll +stop_capture " ) ; let +hub += +A +: +: +hub ( -closures -queue_empty +self ) -= -{ +; if let -wgt -: -: -Maintain -: -: -WaitForSubmissionIndex +Ok ( -submission_index +device ) = -maintain +hub +. +devices +. +get +( +id +) { if -submission_index -. -queue_id ! -= -device_id +device +. +is_valid +( +) { return -Err +; +} +unsafe +{ +device +. +raw ( -WaitIdleError -: +) +. +stop_capture +( +) +} +; +} +} +pub +fn +device_drop +< +A : -WrongSubmissionIndex +HalApi +> ( -submission_index -. -queue_id +& +self device_id +: +DeviceId ) +{ +profiling +: +: +scope +! +( +" +Device +: +: +drop +" ) ; +log +: +: +debug +! +( +" +Device +{ +: +? } -} +is +asked +to +be +dropped +" +device_id +) +; let hub = @@ -17949,130 +15619,133 @@ hub self ) ; +if let -mut -token +Some +( +device +) = -Token +hub +. +devices +. +unregister +( +device_id +) +{ +/ +/ +The +things +Device : : -root +prepare_to_die +takes +care +are +mostly +/ +/ +unnecessary +here +. +We +know +our +queue +is +empty +so +we +don +' +t +/ +/ +need +to +wait +for +submissions +or +triage +them +. +We +know +we +were +/ +/ +just +polled +so +life_tracker +. +free_resources +is +empty +. +debug_assert +! +( +device +. +lock_life +( +) +. +queue_empty ( ) +) ; +{ let -( -device_guard mut -token -) +pending_writes = -hub +device . -devices +pending_writes . -read +lock ( -& -mut -token ) ; -device_guard -. -get -( -device_id -) +let +pending_writes += +pending_writes . -map_err +as_mut ( -| -_ -| -DeviceError -: -: -Invalid ) -? . -maintain +unwrap ( -hub -maintain -& -mut -token ) -? -} ; -closures +pending_writes . -fire +deactivate ( ) ; -Ok +} +drop ( -queue_empty +device ) +; } -/ -/ -/ -Poll -all -devices -belonging -to -the -backend -A -. -/ -/ -/ -/ -/ -/ -If -force_wait -is -true -block -until -all -buffer -mappings -are -done -. -/ -/ -/ -/ -/ -/ -Return -all_queue_empty -indicating -whether -there -are -more -queue -/ -/ -/ -submissions -still -in -flight -. +} +pub fn -poll_devices +device_set_device_lost_closure < A : @@ -18081,34 +15754,14 @@ HalApi ( & self -force_wait +device_id : -bool -closures +DeviceId +device_lost_closure : -& -mut -UserClosures +DeviceLostClosure ) -- -> -Result -< -bool -WaitIdleError -> { -profiling -: -: -scope -! -( -" -poll_devices -" -) -; let hub = @@ -18120,2453 +15773,633 @@ hub self ) ; +if let -mut -devices_to_drop -= -vec -! -[ -] -; -let -mut -all_queue_empty -= -true -; -{ -let -mut -token -= -Token -: -: -root -( -) -; -let +Ok ( -device_guard -mut -token +device ) = hub . devices . -read +get ( -& -mut -token +device_id ) -; -for -( -id +{ +let +mut +life_tracker += device +. +lock_life +( ) -in -device_guard +; +life_tracker . -iter +device_lost_closure += +Some ( +device_lost_closure +) +; +} +} +pub +fn +device_destroy +< A : +HalApi +> +( +& +self +device_id : -VARIANT +DeviceId ) { -let -maintain -= -if -force_wait -{ -wgt +log : : -Maintain +trace +! +( +" +Device : : -Wait -} -else +destroy { -wgt -: +device_id : -Maintain +? +} +" +) +; +let +hub += +A : : -Poll -} +hub +( +self +) ; +if let +Ok ( -cbs -queue_empty +device ) = -device +hub . -maintain +devices +. +get ( -hub -maintain -& -mut -token +device_id ) -? -; -all_queue_empty -= -all_queue_empty -& -& -queue_empty -; +{ / / -If +Follow the -device +steps +at +/ +/ +https +: +/ +/ +gpuweb +. +github +. +io +/ +gpuweb +/ +# +dom +- +gpudevice +- +destroy +. +/ +/ +It ' s -own -RefCount -clone -is +legal +to +call +destroy +multiple +times +but +if the -only -one -left -and +device / / -its -submission -queue is -empty -then -it -can -be -freed +already +invalid +there +' +s +nothing +more +to +do +. +There +' +s +also +/ +/ +no +need +to +return +an +error . if -queue_empty -& -& +! device . -ref_count -. -load -( -) -= -= -1 -{ -devices_to_drop -. -push -( -id -) -; -} -closures -. -extend +is_valid ( -cbs ) -; -} -} -for -device_id -in -devices_to_drop { -self -. -exit_device -: -: -< -A -> -( -device_id -) +return ; } -Ok -( -all_queue_empty -) -} -/ / / -Poll -all -devices -on -all -backends +The +last +part +of +destroy +is +to +lose +the +device . +The +spec +says / / +delay +that +until +all +" +currently +- +enqueued +operations +on +any / / -/ -/ +queue +on +this +device +are +completed +. +" This is -the -implementation -of -wgpu -: -: -Instance -: -: -poll_all -. -/ -/ -/ +accomplished +by / / +setting +valid +to +false +and +then +relying +upon +maintain +to / -Return -all_queue_empty -indicating -whether -there -are -more -queue / +check +for +empty +queues +and +a +DeviceLostClosure +. +At +that +time / / -submissions -still -in -flight -. -pub -fn -poll_all_devices -( -& -self -force_wait -: -bool -) -- -> -Result -< -bool -WaitIdleError -> -{ -let -mut -closures -= -UserClosures -: -: -default -( -) -; -let -mut -all_queue_empty -= -true -; -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not -( -target_arch -= -" -wasm32 -" -) -) -) -] -{ -all_queue_empty -= -self -. -poll_devices -: -: -< -hal -: -: -api -: -: -Vulkan -> -( -force_wait -& -mut -closures -) -? -& -& -all_queue_empty -; -} -# -[ -cfg -( -all -( -feature -= -" -metal -" -any -( -target_os -= -" -macos -" -target_os -= +the +DeviceLostClosure +will +be +called +with " -ios +destroyed " -) -) -) -] -{ -all_queue_empty -= -self +as +the +/ +/ +reason . -poll_devices -: -: -< -hal -: -: -api -: -: -Metal -> -( -force_wait -& -mut -closures -) -? -& -& -all_queue_empty -; -} -# -[ -cfg -( -all -( -feature -= -" -dx12 -" -windows -) -) -] -{ -all_queue_empty -= -self -. -poll_devices -: -: -< -hal -: -: -api -: -: -Dx12 -> -( -force_wait -& -mut -closures -) -? -& -& -all_queue_empty -; -} -# -[ -cfg -( -all -( -feature -= -" -dx11 -" -windows -) -) -] -{ -all_queue_empty -= -self -. -poll_devices -: -: -< -hal -: -: -api -: -: -Dx11 -> -( -force_wait -& -mut -closures -) -? -& -& -all_queue_empty -; -} -# -[ -cfg -( -feature -= -" -gles -" -) -] -{ -all_queue_empty -= -self -. -poll_devices -: -: -< -hal -: -: -api -: -: -Gles -> -( -force_wait -& -mut -closures -) -? -& -& -all_queue_empty -; -} -closures -. -fire -( -) -; -Ok -( -all_queue_empty -) -} -pub -fn -device_label -< -A -: -HalApi -> -( -& -self -id -: -DeviceId -) -- -> -String -{ -A -: -: -hub -( -self -) -. -devices -. -label_for_resource -( -id -) -} -pub -fn -device_start_capture -< -A -: -HalApi -> -( -& -self -id -: -DeviceId -) -{ -log -: -: -trace -! -( -" -Device -: -: -start_capture -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get -( -id -) -{ -if -! -device -. -valid -{ -return -; -} -unsafe -{ -device -. -raw -. -start_capture -( -) -} -; -} -} -pub -fn -device_stop_capture -< -A -: -HalApi -> -( -& -self -id -: -DeviceId -) -{ -log -: -: -trace -! -( -" -Device -: -: -stop_capture -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get -( -id -) -{ -if -! -device -. -valid -{ -return -; -} -unsafe -{ -device -. -raw -. -stop_capture -( -) -} -; -} -} -pub -fn -device_drop -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -) -{ -profiling -: -: -scope -! -( -" -Device -: -: -drop -" -) -; -log -: -: -trace -! -( -" -Device -: -: -drop -{ -device_id -: -? -} -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -/ -/ -For -now -just -drop -the -RefCount -in -device -. -life_guard -which -/ -/ -stands -for -the -user -' -s -reference -to -the -device -. -We -' -ll -take -care -of -/ -/ -cleaning -up -the -device -when -we -' -re -polled -once -its -queue -submissions -/ -/ -have -completed -and -it -is -no -longer -needed -by -other -resources -. -let -( -mut -device_guard -_ -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get_mut -( -device_id -) -{ -device -. -life_guard -. -ref_count -. -take -( -) -. -unwrap -( -) -; -} -} -pub -fn -device_set_device_lost_closure -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -device_lost_closure -: -DeviceLostClosure -) -{ -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get_mut -( -device_id -) -{ -let -mut -life_tracker -= -device -. -lock_life -( -& -mut -token -) -; -life_tracker -. -device_lost_closure -= -Some -( -device_lost_closure -) -; -} -} -pub -fn -device_destroy -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -) -{ -log -: -: -trace -! -( -" -Device -: -: -destroy -{ -device_id -: -? -} -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -_ -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get_mut -( -device_id -) -{ -/ -/ -Follow -the -steps -at -/ -/ -https -: -/ -/ -gpuweb -. -github -. -io -/ -gpuweb -/ -# -dom -- -gpudevice -- -destroy -. -/ -/ -The -last -part -of -destroy -is -to -lose -the -device -. -The -spec -says -/ -/ -delay -that -until -all -" -currently -- -enqueued -operations -on -any -/ -/ -queue -on -this -device -are -completed -. -" -This -is -accomplished -by -/ -/ -setting -valid -to -false -and -then -relying -upon -maintain -to -/ -/ -check -for -empty -queues -and -a -DeviceLostClosure -. -At -that -time -/ -/ -the -DeviceLostClosure -will -be -called -with -" -destroyed -" -as -the -/ -/ -reason -. -device -. -valid -= -false -; -} -} -pub -fn -device_mark_lost -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -message -: -& -str -) -{ -log -: -: -trace -! -( -" -Device -: -: -mark_lost -{ -device_id -: -? -} -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -if -let -Ok -( -device -) -= -device_guard -. -get_mut -( -device_id -) -{ -device -. -lose -( -& -mut -token -message -) -; -} -} -/ -/ -/ -Exit -the -unreferenced -inactive -device -device_id -. -fn -exit_device -< -A -: -HalApi -> -( -& -self -device_id -: -DeviceId -) -{ -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -mut -free_adapter_id -= -None -; -{ -let -( -device -mut -_token -) -= -hub -. -devices -. -unregister -( -device_id -& -mut -token -) -; -if -let -Some -( -mut -device -) -= -device -{ -/ -/ -The -things -Device -: -: -prepare_to_die -takes -care -are -mostly -/ -/ -unnecessary -here -. -We -know -our -queue -is -empty -so -we -don -' -t -/ -/ -need -to -wait -for -submissions -or -triage -them -. -We -know -we -were -/ -/ -just -polled -so -life_tracker -. -free_resources -is -empty -. -debug_assert -! -( -device -. -lock_life -( -& -mut -_token -) -. -queue_empty -( -) -) -; -device -. -pending_writes -. -deactivate -( -) -; -/ -/ -Adapter -is -only -referenced -by -the -device -and -itself -. -/ -/ -This -isn -' -t -a -robust -way -to -destroy -them -we -should -find -a -better -one -. -if -device -. -adapter_id -. -ref_count -. -load -( -) -= -= -1 -{ -free_adapter_id -= -Some -( -device -. -adapter_id -. -value -. -0 -) -; -} -device -. -dispose -( -) -; -} -} -/ -/ -Free -the -adapter -now -that -we -' -ve -dropped -the -Device -token -. -if -let -Some -( -free_adapter_id -) -= -free_adapter_id -{ -let -_ -= -hub -. -adapters -. -unregister -( -free_adapter_id -& -mut -token -) -; -} -} -pub -fn -buffer_map_async -< -A -: -HalApi -> -( -& -self -buffer_id -: -id -: -: -BufferId -range -: -Range -< -BufferAddress -> -op -: -BufferMapOperation -) -- -> -BufferAccessResult -{ -log -: -: -trace -! -( -" -Buffer -: -: -map_async -{ -buffer_id -: -? -} -" -) -; -/ -/ -User -callbacks -must -not -be -called -while -holding -buffer_map_async_inner -' -s -locks -so -we -/ -/ -defer -the -error -callback -if -it -needs -to -be -called -immediately -( -typically -when -running -/ -/ -into -errors -) -. -if -let -Err -( -( -op -err -) -) -= -self -. -buffer_map_async_inner -: -: -< -A -> -( -buffer_id -range -op -) -{ -op -. -callback -. -call -( -Err -( -err -. -clone -( -) -) -) -; -return -Err -( -err -) -; -} -Ok -( -( -) -) -} -/ -/ -Returns -the -mapping -callback -in -case -of -error -so -that -the -callback -can -be -fired -outside -/ -/ -of -the -locks -that -are -held -in -this -function -. -fn -buffer_map_async_inner -< -A -: -HalApi -> -( -& -self -buffer_id -: -id -: -: -BufferId -range -: -Range -< -BufferAddress -> -op -: -BufferMapOperation -) -- -> -Result -< -( -) -( -BufferMapOperation -BufferAccessError -) -> -{ -profiling -: -: -scope -! -( -" -Buffer -: -: -map_async -" -) -; -let -hub -= -A -: -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= -hub -. -devices -. -read -( -& -mut -token -) -; -let -( -pub_usage -internal_use -) -= -match -op -. -host -{ -HostMap -: -: -Read -= -> -( -wgt -: -: -BufferUsages -: -: -MAP_READ -hal -: -: -BufferUses -: -: -MAP_READ -) -HostMap -: -: -Write -= -> -( -wgt -: -: -BufferUsages -: -: -MAP_WRITE -hal -: -: -BufferUses -: -: -MAP_WRITE -) -} -; -if -range -. -start -% -wgt -: -: -MAP_ALIGNMENT -! -= -0 -| -| -range -. -end -% -wgt -: -: -COPY_BUFFER_ALIGNMENT -! -= -0 -{ -return -Err -( -( -op -BufferAccessError -: -: -UnalignedRange -) -) -; -} -let -( -device_id -ref_count -) -= -{ -let -( -mut -buffer_guard -_ -) -= -hub -. -buffers -. -write -( -& -mut -token -) -; -let -buffer -= -buffer_guard -. -get_mut -( -buffer_id -) -. -map_err -( -| -_ -| -BufferAccessError -: -: -Invalid -) -; -let -buffer -= -match -buffer -{ -Ok +device +. +valid +. +store ( -b +false +Ordering +: +: +Relaxed ) -= +; +} +} +pub +fn +device_mark_lost +< +A +: +HalApi > -b -Err ( -e +& +self +device_id +: +DeviceId +message +: +& +str ) -= -> { -return -Err -( +log +: +: +trace +! ( -op -e -) -) -; -} +" +Device +: +: +mark_lost +{ +device_id +: +? } +" +) ; let -device +hub = -& -device_guard -[ -buffer -. -device_id -. -value -] -; -if -! -device -. -valid -{ -return -Err -( -( -op -DeviceError +A : : -Lost -. -into +hub ( -) -) +self ) ; -} if let -Err +Ok ( -e +device ) = -check_buffer_usage -( -buffer +hub . -usage -pub_usage +devices +. +get +( +device_id ) { -return -Err -( -( -op -e +device . -into +lose ( -) -) +message ) ; } -if -range -. -start +} +pub +fn +queue_drop +< +A +: +HalApi > -range -. -end -{ -return -Err -( ( -op -BufferAccessError -: -: -NegativeRange -{ -start -: -range -. -start -end +& +self +queue_id : -range -. -end -} -) +QueueId ) -; -} -if -range -. -end -> -buffer -. -size { -return -Err -( -( -op -BufferAccessError +profiling : : -OutOfBoundsOverrun -{ -index +scope +! +( +" +Queue : -range -. -end -max : -buffer -. -size -} -) +drop +" ) ; -} -buffer -. -map_state -= -match -buffer -. -map_state -{ -resource -: -: -BufferMapState +log : : -Init +debug +! +( +" +Queue { -. -. -} -| -resource : -: -BufferMapState -: -: -Active -{ -. -. +? } -= -> -{ -return -Err -( -( -op -BufferAccessError -: -: -AlreadyMapped -) +is +asked +to +be +dropped +" +queue_id ) ; -} -resource -: -: -BufferMapState +let +hub += +A : : -Waiting +hub +( +self +) +; +if +let +Some ( -_ +queue ) = -> -{ -return -Err -( +hub +. +queues +. +unregister ( -op -BufferAccessError -: -: -MapAlreadyPending +queue_id ) +{ +drop +( +queue ) ; } -resource -: -: -BufferMapState -: +} +pub +fn +buffer_map_async +< +A : -Idle -= +HalApi > -{ -resource -: -: -BufferMapState -: -: -Waiting ( -resource +& +self +buffer_id : +id : -BufferPendingMapping -{ +: +BufferId range +: +Range +< +BufferAddress +> op -_parent_ref_count : -buffer -. -life_guard -. -add_ref -( -) -} +BufferMapOperation ) -} -} -; +- +> +BufferAccessResult +{ log : : -debug +trace ! ( " Buffer +: +: +map_async { +buffer_id : ? } -map -state -- -> -Waiting " -buffer_id ) ; -let -ret -= +/ +/ +User +callbacks +must +not +be +called +while +holding +buffer_map_async_inner +' +s +locks +so +we +/ +/ +defer +the +error +callback +if +it +needs +to +be +called +immediately ( -buffer -. -device_id -. -value -buffer -. -life_guard +typically +when +running +/ +/ +into +errors +) . -add_ref +if +let +Err +( ( +mut +operation +err ) ) -; -let -mut -trackers = -device -. -trackers -. -lock -( -) -; -trackers -. -buffers +self . -set_single +buffer_map_async_inner +: +: +< +A +> ( -& -* -buffer_guard buffer_id -internal_use +range +op ) -; -trackers -. -buffers -. -drain +{ +if +let +Some ( +callback ) -; -ret -} -; -let -device = -& -device_guard -[ -device_id -] -; -/ -/ -Validity -of -device -was -confirmed -in -the -code -block -that -set -device_id +operation . -device +callback . -lock_life +take ( -& -mut -token ) +{ +callback . -map +call ( -id -: -: -Valid +Err +( +err +. +clone ( -buffer_id ) -ref_count +) +) +; +} +return +Err +( +err ) ; +} Ok ( ( ) ) } -pub +/ +/ +Returns +the +mapping +callback +in +case +of +error +so +that +the +callback +can +be +fired +outside +/ +/ +of +the +locks +that +are +held +in +this +function +. fn -buffer_get_mapped_range +buffer_map_async_inner < A : @@ -20581,27 +16414,26 @@ id : : BufferId -offset -: -BufferAddress -size +range : -Option +Range < BufferAddress > +op +: +BufferMapOperation ) - > Result < ( -* -mut -u8 -u64 ) +( +BufferMapOperation BufferAccessError +) > { profiling @@ -20614,26 +16446,7 @@ scope Buffer : : -get_mapped_range -" -) -; -log -: -: -trace -! -( -" -Buffer -: -: -get_mapped_range -{ -buffer_id -: -? -} +map_async " ) ; @@ -20649,904 +16462,808 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -buffer_guard -_ -) -= -hub -. -buffers -. -read -( -& -mut -token -) -; -let -buffer -= -buffer_guard -. -get -( -buffer_id -) -. -map_err -( -| -_ -| -BufferAccessError -: -: -Invalid -) -? -; -let -range_size -= -if -let -Some -( -size -) -= -size -{ -size -} -else -if -offset -> -buffer -. -size -{ -0 -} -else -{ -buffer -. -size -- -offset -} -; -if -offset -% -wgt -: -: -MAP_ALIGNMENT -! -= -0 -{ -return -Err -( -BufferAccessError -: -: -UnalignedOffset -{ -offset -} -) -; -} -if -range_size -% -wgt -: -: -COPY_BUFFER_ALIGNMENT -! -= -0 -{ -return -Err -( -BufferAccessError -: -: -UnalignedRangeSize -{ -range_size -} -) -; -} -match -buffer -. -map_state -{ -resource -: -: -BufferMapState -: -: -Init -{ -ptr -. -. -} -= -> -{ -/ -/ -offset -( -u64 -) -can -not -be -< -0 -so -no -need -to -validate -the -lower -bound -if -offset -+ -range_size -> -buffer -. -size -{ -return -Err -( -BufferAccessError -: -: -OutOfBoundsOverrun -{ -index -: -offset -+ -range_size -- -1 -max -: -buffer -. -size -} -) -; -} -unsafe -{ -Ok -( -( -ptr -. -as_ptr ( +pub_usage +internal_use ) += +match +op . -offset +host +{ +HostMap +: +: +Read += +> ( -offset -as -isize -) -range_size -) -) -} -} -resource +wgt : : -BufferMapState +BufferUsages : : -Active -{ -ptr -ref -range -. -. -} +MAP_READ +hal +: +: +BufferUses +: +: +MAP_READ +) +HostMap +: +: +Write = > -{ -if -offset -< -range -. -start -{ -return -Err ( -BufferAccessError +wgt : : -OutOfBoundsUnderrun -{ -index +BufferUsages : -offset -min : -range -. -start -} +MAP_WRITE +hal +: +: +BufferUses +: +: +MAP_WRITE ) -; } +; if -offset -+ -range_size -> +range +. +start +% +wgt +: +: +MAP_ALIGNMENT +! += +0 +| +| range . end +% +wgt +: +: +COPY_BUFFER_ALIGNMENT +! += +0 { return Err ( +( +op BufferAccessError : : -OutOfBoundsOverrun -{ -index -: -offset -+ -range_size -- -1 -max -: -range -. -end -} +UnalignedRange +) ) ; } -/ -/ -ptr -points -to -the -beginning -of -the -range -we -mapped -in -map_async -/ -/ -rather -thant -the -beginning -of -the +let buffer -. += +{ let -relative_offset +buffer = +hub +. +buffers +. +get ( -offset -- -range +buffer_id +) . -start +map_err +( +| +_ +| +BufferAccessError +: +: +Invalid ) -as -isize ; -unsafe +let +buffer += +match +buffer { Ok ( +b +) += +> +b +Err ( -ptr +e +) += +> +{ +return +Err +( +( +op +e +) +) +; +} +} +; +let +device += +& +buffer . -as_ptr +device +; +if +! +device +. +is_valid ( ) +{ +return +Err +( +( +op +DeviceError +: +: +Lost . -offset +into ( -relative_offset ) -range_size ) ) +; } -} -resource -: -: -BufferMapState -: -: -Idle -| -resource -: -: -BufferMapState -: -: -Waiting +if +let +Err ( -_ +e +) += +check_buffer_usage +( +buffer +. +usage +pub_usage ) -= -> { +return Err ( -BufferAccessError -: -: -NotMapped +( +op +e +. +into +( ) +) +) +; } -} -} -fn -buffer_unmap_inner -< -A -: -HalApi +if +range +. +start > +range +. +end +{ +return +Err ( -& -self -buffer_id -: -id +( +op +BufferAccessError : : -BufferId -buffer +NegativeRange +{ +start : -& -mut -Buffer -< -A -> -device +range +. +start +end : -& -mut -Device -< -A -> +range +. +end +} ) -- -> -Result -< -Option -< -BufferMapPendingClosure -> -BufferAccessError +) +; +} +if +range +. +end > +buffer +. +size { -log +return +Err +( +( +op +BufferAccessError : : -debug -! -( -" -Buffer +OutOfBoundsOverrun { +index : -? +range +. +end +max +: +buffer +. +size } -map -state -- -> -Idle -" -buffer_id +) ) ; -match -mem -: -: -replace -( +} +{ +let +map_state += & mut +* buffer . map_state +. +lock +( +) +; +* +map_state += +match +* +map_state +{ resource : : BufferMapState : : -Idle -) +Init { +. +. +} +| resource : : BufferMapState : : -Init +Active { -ptr -stage_buffer -needs_flush +. +. } = > { -# -[ -cfg +return +Err ( -feature -= -" -trace -" -) -] -if -let -Some ( -ref -trace +op +BufferAccessError +: +: +AlreadyMapped ) -= -device -. -trace -{ -let -mut -trace -= -trace -. -lock -( ) ; -let -data -= -trace -. -make_binary -( -" -bin -" -unsafe -{ -std +} +resource : : -slice +BufferMapState : : -from_raw_parts -( -ptr -. -as_ptr +Waiting ( +_ ) -buffer -. -size -as -usize += +> +{ +return +Err +( +( +op +BufferAccessError +: +: +MapAlreadyPending ) -} ) ; -trace -. -add -( -trace +} +resource +: +: +BufferMapState +: +: +Idle += +> +{ +resource +: +: +BufferMapState : : -Action +Waiting +( +resource : : -WriteBuffer +BufferPendingMapping { -id -: -buffer_id -data range +op +_parent_buffer : -0 -. -. buffer . -size -queued -: -true +clone +( +) } ) -; } -let -_ -= -ptr +} ; -if -needs_flush -{ -unsafe -{ -device -. -raw -. -flush_mapped_ranges -( -& -stage_buffer -iter +} +log : : -once +debug +! ( -0 -. -. -buffer -. -size -) +" +Buffer +{ +: +? +} +map +state +- +> +Waiting +" +buffer_id ) ; -} -} +{ let -raw_buf +mut +trackers = buffer . -raw +device . as_ref ( ) . -ok_or +trackers +. +lock ( -BufferAccessError -: -: -Destroyed ) -? ; -buffer +trackers . -life_guard +buffers . -use_at +set_single ( -device -. -active_submission_index -+ -1 +& +buffer +internal_use ) ; +/ +/ +TODO +: +Check +if +draining +ALL +buffers +is +correct +! let -region +_ = -wgt -: -: -BufferSize -: -: -new +trackers +. +buffers +. +drain_transitions ( +) +; +} +buffer +} +; buffer . -size +device +. +lock_life +( ) . map ( -| -size -| -hal +& +buffer +) +; +Ok +( +( +) +) +} +pub +fn +buffer_get_mapped_range +< +A : +HalApi +> +( +& +self +buffer_id : -BufferCopy -{ -src_offset +id : -0 -dst_offset : -0 -size -} -) -; -let -transition_src -= -hal +BufferId +offset : +BufferAddress +size : -BufferBarrier +Option +< +BufferAddress +> +) +- +> +Result +< +( +* +mut +u8 +u64 +) +BufferAccessError +> { -buffer -: -& -stage_buffer -usage +profiling : -hal : +scope +! +( +" +Buffer : -BufferUses : +get_mapped_range +" +) +; +log : -MAP_WRITE -. -. -hal : +trace +! +( +" +Buffer : -BufferUses : +get_mapped_range +{ +buffer_id : -COPY_SRC +? } +" +) ; let -transition_dst +hub = -hal -: -: -BufferBarrier -{ -buffer -: -raw_buf -usage -: -hal -: -: -BufferUses +A : : -empty +hub ( +self ) -. -. -hal -: -: -BufferUses -: -: -COPY_DST -} ; let -encoder +buffer = -device -. -pending_writes +hub . -activate -( -) -; -unsafe -{ -encoder +buffers . -transition_buffers -( -iter -: -: -once +get ( -transition_src +buffer_id ) . -chain +map_err ( -iter +| +_ +| +BufferAccessError : : -once -( -transition_dst -) -) +Invalid ) +? ; +let +range_size += +if +let +Some +( +size +) += +size +{ +size +} +else if +offset +> buffer . size -> +{ 0 +} +else { -encoder -. -copy_buffer_to_buffer -( -& -stage_buffer -raw_buf -region +buffer . -into_iter +size +- +offset +} +; +if +offset +% +wgt +: +: +MAP_ALIGNMENT +! += +0 +{ +return +Err ( -) +BufferAccessError +: +: +UnalignedOffset +{ +offset +} ) ; } -} -device -. -pending_writes -. -consume_temp -( -queue +if +range_size +% +wgt : : -TempResource +COPY_BUFFER_ALIGNMENT +! += +0 +{ +return +Err +( +BufferAccessError : : -Buffer -( -stage_buffer -) +UnalignedRangeSize +{ +range_size +} ) ; -device -. -pending_writes +} +let +map_state += +& +* +buffer . -dst_buffers +map_state . -insert +lock ( -buffer_id ) ; -} +match +* +map_state +{ resource : : BufferMapState : : -Idle +Init +{ +ref +ptr +. +. +} = > { +/ +/ +offset +( +u64 +) +can +not +be +< +0 +so +no +need +to +validate +the +lower +bound +if +offset ++ +range_size +> +buffer +. +size +{ return Err ( BufferAccessError : : -NotMapped -) -; -} -resource -: -: -BufferMapState +OutOfBoundsOverrun +{ +index : +offset ++ +range_size +- +1 +max : -Waiting -( -pending +buffer +. +size +} ) -= -> +; +} +unsafe { -return Ok ( -Some -( ( -pending +ptr . -op -Err +as_ptr ( -BufferAccessError -: -: -MapAborted ) +. +offset +( +offset +as +isize ) +range_size ) ) -; +} } resource : @@ -21556,174 +17273,163 @@ BufferMapState : Active { -ptr -range -host -} -= -> -{ -if -host -= -= -HostMap -: -: -Write -{ -# -[ -cfg -( -feature -= -" -trace -" -) -] -if -let -Some -( ref -trace -) -= -device -. -trace -{ -let -mut -trace -= -trace -. -lock -( -) -; -let -size -= +ptr +ref range . -end -- -range . -start -; -let -data +} = -trace +> +{ +if +offset +< +range . -make_binary -( -" -bin -" -unsafe +start { -std +return +Err +( +BufferAccessError : : -slice +OutOfBoundsUnderrun +{ +index : +offset +min : -from_raw_parts -( -ptr +range . -as_ptr -( -) -size -as -usize -) +start } ) ; -trace +} +if +offset ++ +range_size +> +range . -add +end +{ +return +Err ( -trace -: -: -Action +BufferAccessError : : -WriteBuffer +OutOfBoundsOverrun { -id +index : -buffer_id -data -range +offset ++ +range_size +- +1 +max : range . -clone -( -) -queued -: -false +end } ) ; } +/ +/ +ptr +points +to +the +beginning +of +the +range +we +mapped +in +map_async +/ +/ +rather +thant +the +beginning +of +the +buffer +. let -_ +relative_offset = ( -ptr +offset +- range +. +start ) +as +isize ; -} unsafe { -device -. -raw -. -unmap_buffer +Ok ( -buffer -. -raw +( +ptr . -as_ref +as_ptr ( ) . -unwrap +offset ( +relative_offset +) +range_size ) ) -. -map_err +} +} +resource +: +: +BufferMapState +: +: +Idle +| +resource +: +: +BufferMapState +: +: +Waiting ( -DeviceError +_ +) += +> +{ +Err +( +BufferAccessError : : -from +NotMapped ) -? -} -; } } -Ok -( -None -) } pub fn @@ -21805,59 +17511,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) -= -hub -. -devices -. -write -( -& -mut -token -) -; -let -( -mut -buffer_guard -_ -) +buffer = hub . buffers . -write -( -& -mut -token -) -; -let -buffer -= -buffer_guard -. -get_mut +get ( buffer_id ) @@ -21874,25 +17534,15 @@ Invalid ) ? ; -let -device -= -& -mut -device_guard -[ -buffer -. -device_id -. -value -] -; if ! +buffer +. device . -valid +is_valid +( +) { return Err @@ -21910,13 +17560,10 @@ into } closure = -self +buffer . buffer_unmap_inner ( -buffer_id -buffer -device ) } / @@ -21939,6 +17586,7 @@ let Some ( ( +mut operation status ) @@ -21947,16 +17595,30 @@ status closure ? { +if +let +Some +( +callback +) += operation . callback . +take +( +) +{ +callback +. call ( status ) ; } +} Ok ( ( diff --git a/third_party/rust/wgpu-core/src/device/life.rs b/third_party/rust/wgpu-core/src/device/life.rs index ec04c99742421..a745b1a14e597 100644 --- a/third_party/rust/wgpu-core/src/device/life.rs +++ b/third_party/rust/wgpu-core/src/device/life.rs @@ -23,6 +23,18 @@ crate : : { +binding_model +: +: +{ +BindGroup +BindGroupLayout +PipelineLayout +} +command +: +: +RenderBundle device : : @@ -45,26 +57,58 @@ HalApi hub : : -{ Hub -Token -} id -identity : : -GlobalIdentityHandlerFactory +{ +self +BindGroupId +BindGroupLayoutId +BufferId +ComputePipelineId +PipelineLayoutId +QuerySetId +RenderBundleId +RenderPipelineId +SamplerId +StagingBufferId +TextureId +TextureViewId +} +pipeline +: +: +{ +ComputePipeline +RenderPipeline +} +registry +: +: +Registry resource +: +: +{ +self +Buffer +QuerySet +Resource +ResourceType +Sampler +StagingBuffer +Texture +TextureView +} track : : { -BindGroupStates -RenderBundleScope +ResourceTracker Tracker } -RefCount -Stored +FastHashMap SubmissionIndex } ; @@ -75,14 +119,6 @@ smallvec SmallVec ; use -hal -: -: -Device -as -_ -; -use parking_lot : : @@ -95,11 +131,227 @@ thiserror Error ; use +wgt +: +: +WasmNotSendSync +; +use std : : -mem +{ +any +: +: +Any +sync +: +: +Arc +} +; +pub +( +crate +) +trait +ResourceMap +: +Any ++ +WasmNotSendSync +{ +fn +as_any +( +& +self +) +- +> +& +dyn +Any +; +fn +as_any_mut +( +& +mut +self +) +- +> +& +mut +dyn +Any +; +fn +clear_map +( +& +mut +self +) +; +fn +extend_map +( +& +mut +self +maps +: +& +mut +ResourceMaps +) +; +} +impl +< +Id +R +> +ResourceMap +for +FastHashMap +< +Id +Arc +< +R +> +> +where +Id +: +id +: +: +TypedId +R +: +Resource +< +Id +> +{ +fn +as_any +( +& +self +) +- +> +& +dyn +Any +{ +self +} +fn +as_any_mut +( +& +mut +self +) +- +> +& +mut +dyn +Any +{ +self +} +fn +clear_map +( +& +mut +self +) +{ +self +. +clear +( +) +} +fn +extend_map +( +& +mut +self +r +: +& +mut +ResourceMaps +) +{ +if +let +Some +( +other +) += +r +. +maps +. +get_mut +( +R +: +: +TYPE +) +{ +if +let +Some +( +other +) += +other +. +as_any_mut +( +) +. +downcast_mut +: +: +< +Self +> +( +) +{ +self +. +extend +( +other +. +drain +( +) +) ; +} +} +} +} / / / @@ -123,2112 +375,2328 @@ user [ derive ( -Debug Default ) ] pub ( -super +crate ) struct -SuspectedResources +ResourceMaps { pub ( -super +crate ) -buffers +maps : -Vec +FastHashMap < -id -: -: -Valid +ResourceType +Box < -id -: -: -BufferId +dyn +ResourceMap > > -pub +} +impl +ResourceMaps +{ +fn +add_type +< +Id +R +> ( -super +& +mut +self ) -textures -: -Vec -< -id -: +- +> +& +mut +Self +where +Id : -Valid -< id : : -TextureId -> -> -pub -( -super -) -texture_views +TypedId +R : -Vec +Resource < -id +Id +> +{ +let +map += +FastHashMap : : -Valid < -id -: -: -TextureViewId +Id +Arc +< +R > > -pub +: +: +default ( -super ) -samplers -: -Vec -< -id +; +self +. +maps +. +insert +( +R : : -Valid -< -id +TYPE +Box : : -SamplerId -> -> -pub +new ( -super +map ) -bind_groups -: -Vec -< -id -: -: -Valid +) +; +self +} +fn +map < -id -: -: -BindGroupId +Id +R > -> -pub ( -super +& +self ) -compute_pipelines -: -Vec +- +> +& +FastHashMap < -id -: -: -Valid +Id +Arc < -id -: -: -ComputePipelineId +R > > -pub -( -super -) -render_pipelines +where +Id : -Vec -< id : : -Valid +TypedId +R +: +Resource < -id +Id +> +{ +let +map += +self +. +maps +. +get +( +R : : -RenderPipelineId -> -> -pub +TYPE +) +. +unwrap ( -super ) -bind_group_layouts -: -Vec -< -id +; +let +any_map += +map +. +as_ref +( +) +. +as_any +( +) +; +let +map += +any_map +. +downcast_ref : : -Valid < -id -: -: -BindGroupLayoutId +FastHashMap +< +Id +Arc +< +R +> > > -pub ( -super ) -pipeline_layouts -: -Vec -< -Stored +. +unwrap +( +) +; +map +} +fn +map_mut < -id -: -: -PipelineLayoutId +Id +R > -> -pub ( -super +& +mut +self ) -render_bundles -: -Vec +- +> +& +mut +FastHashMap < -id -: -: -Valid +Id +Arc < -id -: -: -RenderBundleId +R > > -pub -( -super -) -query_sets +where +Id : -Vec -< id : : -Valid -< -id -: +TypedId +R : -QuerySetId -> +Resource +< +Id > -} -impl -SuspectedResources -{ -pub -( -super -) -fn -clear -( -& -mut -self -) { +let +map += self . -buffers +maps . -clear +entry ( +R +: +: +TYPE ) -; -self -. -textures . -clear +or_insert_with +( +| +| +Box +: +: +< +FastHashMap +< +Id +Arc +< +R +> +> +> +: +: +default ( ) +) ; -self -. -texture_views +let +any_map += +map . -clear +as_mut ( ) -; -self -. -samplers . -clear +as_any_mut ( ) ; -self +let +map += +any_map . -bind_groups +downcast_mut +: +: +< +FastHashMap +< +Id +Arc +< +R +> +> +> +( +) . -clear +unwrap ( ) ; -self +map +} +pub +( +crate +) +fn +new +< +A +: +HalApi +> +( +) +- +> +Self +{ +let +mut +maps += +Self +: +: +default +( +) +; +maps . -compute_pipelines +add_type +: +: +< +BufferId +Buffer +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +StagingBufferId +StagingBuffer +< +A +> +> ( ) ; -self +maps . -render_pipelines +add_type +: +: +< +TextureId +Texture +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +TextureViewId +TextureView +< +A +> +> ( ) ; -self +maps . -bind_group_layouts +add_type +: +: +< +SamplerId +Sampler +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +BindGroupId +BindGroup +< +A +> +> ( ) ; -self +maps . -pipeline_layouts +add_type +: +: +< +BindGroupLayoutId +BindGroupLayout +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +RenderPipelineId +RenderPipeline +< +A +> +> ( ) ; -self +maps . -render_bundles +add_type +: +: +< +ComputePipelineId +ComputePipeline +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +PipelineLayoutId +PipelineLayout +< +A +> +> ( ) ; -self +maps . -query_sets +add_type +: +: +< +RenderBundleId +RenderBundle +< +A +> +> +( +) +; +maps . -clear +add_type +: +: +< +QuerySetId +QuerySet +< +A +> +> ( ) ; +maps } pub ( -super +crate ) fn -extend +clear ( & mut self -other -: -& -Self ) { self . -buffers +maps . -extend_from_slice +iter_mut ( -& -other -. -buffers ) -; -self . -textures -. -extend_from_slice +for_each ( -& -other +| +( +_t +map +) +| +map . -textures +clear_map +( +) ) ; -self -. -texture_views -. -extend_from_slice +} +pub +( +crate +) +fn +extend ( & +mut +self +mut other -. -texture_views +: +Self ) -; +{ self . -samplers +maps . -extend_from_slice +iter_mut ( -& -other -. -samplers ) -; -self -. -bind_groups . -extend_from_slice +for_each ( -& -other -. -bind_groups -) -; -self -. -compute_pipelines -. -extend_from_slice -( -& -other -. -compute_pipelines -) -; -self -. -render_pipelines -. -extend_from_slice -( -& -other -. -render_pipelines -) -; -self -. -bind_group_layouts -. -extend_from_slice -( -& -other -. -bind_group_layouts -) -; -self -. -pipeline_layouts -. -extend_from_slice +| ( -& -other -. -pipeline_layouts +_t +map ) -; -self -. -render_bundles +| +{ +map . -extend_from_slice +extend_map ( & +mut other -. -render_bundles ) ; -self -. -query_sets -. -extend_from_slice -( -& -other -. -query_sets +} ) ; } pub ( -super +crate ) fn -add_render_bundle_scope +insert < -A -: -HalApi +Id +R > ( & mut self -trackers +id : -& -RenderBundleScope +Id +r +: +Arc < -A +R > ) +- +> +& +mut +Self +where +Id +: +id +: +: +TypedId +R +: +Resource +< +Id +> { self . -buffers -. -extend -( -trackers -. -buffers -. -used -( -) -) -; -self -. -textures -. -extend -( -trackers -. -textures -. -used -( -) -) -; -self -. -bind_groups -. -extend -( -trackers -. -bind_groups -. -used +map_mut ( ) -) -; -self -. -render_pipelines -. -extend -( -trackers -. -render_pipelines . -used +insert ( -) +id +r ) ; self -. -query_sets -. -extend -( -trackers -. -query_sets -. -used -( -) -) -; } pub ( -super +crate ) fn -add_bind_group_states +contains < -A -: -HalApi +Id +R > ( & mut self -trackers +id : & -BindGroupStates +Id +) +- +> +bool +where +Id +: +id +: +: +TypedId +R +: +Resource < -A +Id > -) { self . -buffers -. -extend -( -trackers -. -buffers -. -used -( -) -) -; -self -. -textures -. -extend -( -trackers -. -textures -. -used -( -) -) -; -self -. -texture_views -. -extend -( -trackers -. -views -. -used +map +: +: +< +Id +R +> ( ) -) -; -self -. -samplers -. -extend -( -trackers -. -samplers . -used +contains_key ( +id ) -) -; } } / / / -Raw -backend -resources -that -should +Resources +used +by +a +queue +submission +and +work +to be -freed -shortly +done +once +it +completes . -# -[ -derive -( -Debug -) -] struct -NonReferencedResources +ActiveSubmission < A : -hal -: -: -Api +HalApi > { -buffers -: -Vec -< -A -: -: -Buffer -> -textures -: -Vec -< -A +/ +/ +/ +The +index +of +the +submission +we +track +. +/ +/ +/ +/ +/ +/ +When +Device : : -Texture -> -texture_views +fence +' +s +value +is +greater +than +or +equal +to +this +our +queue +/ +/ +/ +submission +has +completed +. +index : -Vec -< -A +SubmissionIndex +/ +/ +/ +Resources +to +be +freed +once +this +queue +submission +has +completed +. +/ +/ +/ +/ +/ +/ +When +the +device +is +polled +for +completed +submissions +/ +/ +/ +triage_submissions +merges +these +into +/ +/ +/ +LifetimeTracker : : -TextureView -> -samplers +free_resources +. +From +there +/ +/ +/ +LifetimeTracker : -Vec -< -A : +cleanup +passes +them +to +the +hal +to +be +freed +. +/ +/ +/ +/ +/ +/ +This +includes +things +like +temporary +resources +and +resources +that +are +/ +/ +/ +used +by +submitted +commands +but +have +been +dropped +by +the +user +( +meaning +that +/ +/ +/ +this +submission +is +their +last +reference +. +) +last_resources : -Sampler -> -bind_groups +ResourceMaps +/ +/ +/ +Buffers +to +be +mapped +once +this +submission +has +completed +. +mapped : Vec < -A -: -: -BindGroup -> -compute_pipes -: -Vec +Arc < -A -: -: -ComputePipeline -> -render_pipes -: -Vec +Buffer < A -: -: -RenderPipeline > -bind_group_layouts -: -Vec -< -A -: -: -BindGroupLayout > -pipeline_layouts -: -Vec -< -A -: -: -PipelineLayout > -query_sets +encoders : Vec < -A -: -: -QuerySet -> -} -impl -< -A -: -hal -: -: -Api -> -NonReferencedResources +EncoderInFlight < A > -{ -fn -new -( -) -- > -Self -{ -Self -{ -buffers -: -Vec -: +/ +/ +/ +List +of +queue +" +on_submitted_work_done +" +closures +to +be +called +once +this +/ +/ +/ +submission +has +completed +. +work_done_closures : -new +SmallVec +< +[ +SubmittedWorkDoneClosure +; +1 +] +> +} +# +[ +derive ( +Clone +Debug +Error ) -textures -: -Vec -: -: -new +] +# +[ +non_exhaustive +] +pub +enum +WaitIdleError +{ +# +[ +error ( +transparent ) -texture_views -: -Vec -: -: -new +] +Device ( +# +[ +from +] +DeviceError ) -samplers -: -Vec -: -: -new +# +[ +error ( -) -bind_groups -: -Vec +" +Tried +to +wait +using +a +submission +index +from +the +wrong +device +. +Submission +index +is +from +device +{ +0 : +? +} +. +Called +poll +on +device +{ +1 : -new -( +? +} +. +" ) -compute_pipes -: -Vec -: -: -new +] +WrongSubmissionIndex ( -) -render_pipes -: -Vec -: +id : -new -( -) -bind_group_layouts : -Vec +QueueId +id : : -new -( +DeviceId ) -pipeline_layouts -: -Vec -: -: -new +# +[ +error ( -) -query_sets -: -Vec -: +" +GPU +got +stuck : -new ( +" ) +] +StuckGpu } -} -fn -extend -( -& -mut -self -other -: -Self -) -{ -self -. -buffers -. -extend -( -other +/ +/ +/ +Resource +tracking +for +a +device . +/ +/ +/ +/ +/ +/ +# +# +Host +mapping buffers -) -; -self -. -textures -. -extend -( -other -. -textures -) -; -self -. -texture_views -. -extend -( -other -. -texture_views -) -; -self -. -samplers +/ +/ +/ +/ +/ +/ +A +buffer +cannot +be +mapped +until +all +active +queue +submissions +that +use +it +/ +/ +/ +have +completed . -extend -( -other +To +that +end +: +/ +/ +/ +/ +/ +/ +- +Each +buffer +' +s +ResourceInfo +: +: +submission_index +records +the +index +of +the +/ +/ +/ +most +recent +queue +submission +that +uses +that +buffer . -samplers -) -; +/ +/ +/ +/ +/ +/ +- +Calling +Global +: +: +buffer_map_async +adds +the +buffer +to +/ +/ +/ self . -bind_groups -. -extend -( -other +mapped +and +changes +Buffer +: +: +map_state +to +prevent +it +/ +/ +/ +from +being +used +in +any +new +submissions . -bind_groups +/ +/ +/ +/ +/ +/ +- +When +the +device +is +polled +the +following +LifetimeTracker +methods +decide +/ +/ +/ +what +should +happen +next +: +/ +/ +/ +/ +/ +/ +1 ) -; +triage_mapped +drains self . -compute_pipes -. -extend -( -other +mapped +checking +the +submission +index +/ +/ +/ +of +each +buffer +against +the +queue +submissions +that +have +finished +/ +/ +/ +execution . -compute_pipes -) -; +Buffers +used +by +submissions +still +in +flight +go +in +/ +/ +/ self . -render_pipes -. -extend -( -other +active +[ +index +] . -render_pipes -) -; +mapped +and +the +rest +go +into +/ +/ +/ self . -query_sets -. -extend -( -other +ready_to_map . -query_sets +/ +/ +/ +/ +/ +/ +2 ) -; -assert -! -( -other -. -bind_group_layouts +triage_submissions +moves +entries +in +self . -is_empty -( -) -) -; -assert -! -( -other +active +[ +i +] +for +completed +/ +/ +/ +submissions +to +self . -pipeline_layouts +ready_to_map . -is_empty -( -) -) -; -} -unsafe -fn -clean -( -& -mut +At +this +point +both +/ +/ +/ self -device -: -& -A -: -: -Device -) -{ -if -! +. +active +and self . -buffers +ready_to_map +are +up +to +date +with +the +given +/ +/ +/ +submission +index . -is_empty -( -) -{ -profiling -: -: -scope -! -( -" -destroy_buffers -" +/ +/ +/ +/ +/ +/ +3 ) -; -for -raw -in +handle_mapping +drains self . +ready_to_map +and +actually +maps +the +/ +/ +/ buffers +collecting +a +list +of +notification +closures +to +call . -drain -( -. -. -) -{ -unsafe -{ -device -. -destroy_buffer -( -raw -) -} -; -} -} -if -! +But +any +/ +/ +/ +buffers +that +were +dropped +by +the +user +get +moved +to +/ +/ +/ self . -textures +free_resources . -is_empty -( +/ +/ +/ +/ +/ +/ +4 ) -{ -profiling +cleanup +frees +everything +in +free_resources +. +/ +/ +/ +/ +/ +/ +Only +calling +Global : : -scope -! -( -" -destroy_textures -" -) -; +buffer_map_async +clones +a +new +Arc for -raw -in -self +the +/ +/ +/ +buffer . -textures +This +new +Arc +is +only +dropped +by +handle_mapping . -drain +pub ( -. -. +crate ) +struct +LifetimeTracker +< +A +: +HalApi +> { -unsafe -{ -device -. -destroy_texture -( -raw -) -} -; -} -} -if -! -self -. -texture_views +/ +/ +/ +Resources +that +the +user +has +requested +be +mapped +but +which +are +used +by +/ +/ +/ +queue +submissions +still +in +flight . -is_empty -( -) -{ -profiling -: +mapped : -scope -! +Vec +< +Arc +< +Buffer +< +A +> +> +> +/ +/ +/ +Buffers +can +be +used +in +a +submission +that +is +yet +to +be +made +by +the +/ +/ +/ +means +of +write_buffer ( -" -destroy_texture_views -" ) -; +so +we +have +a +special +place for -raw -in -self -. -texture_views -. -drain -( +them . -. -) -{ -unsafe -{ -device -. -destroy_texture_view -( -raw -) -} -; -} -} -if -! -self -. -samplers -. -is_empty -( -) -{ -profiling -: +pub +future_suspected_buffers : -scope -! -( -" -destroy_samplers -" -) -; -for -raw +Vec +< +Arc +< +Buffer +< +A +> +> +> +/ +/ +/ +Textures +can +be +used in -self -. -samplers +the +upcoming +submission +by +write_texture . -drain +pub +future_suspected_textures +: +Vec +< +Arc +< +Texture +< +A +> +> +> +/ +/ +/ +Resources +whose +user +handle +has +died ( +i . +e . +drop +/ +destroy +has +been +called ) -{ -unsafe -{ -device -. -destroy_sampler -( -raw -) -} -; -} -} -if -! -self -. -bind_groups +/ +/ +/ +and +will +likely +be +ready +for +destruction +soon . -is_empty -( -) -{ -profiling -: +pub +suspected_resources : -scope -! -( -" -destroy_bind_groups -" -) -; -for -raw +ResourceMaps +/ +/ +/ +Resources +used +by +queue +submissions +still in -self -. -bind_groups -. -drain -( -. -. -) -{ -unsafe -{ -device -. -destroy_bind_group -( -raw -) -} -; -} -} -if -! -self +flight . -compute_pipes +One +entry +per +/ +/ +/ +submission +with +older +submissions +appearing +before +younger . -is_empty -( -) -{ -profiling +/ +/ +/ +/ +/ +/ +Entries +are +added +by +track_submission +and +drained +by +/ +/ +/ +LifetimeTracker : : -scope -! -( -" -destroy_compute_pipelines -" -) -; -for -raw -in -self -. -compute_pipes +triage_submissions . -drain -( +Lots +of +methods +contribute +data +/ +/ +/ +to +particular +entries . +active +: +Vec +< +ActiveSubmission +< +A +> +> +/ +/ +/ +Raw +backend +resources +that +are +neither +referenced +nor +used . -) -{ -unsafe -{ -device -. -destroy_compute_pipeline -( -raw -) -} -; -} -} -if -! -self -. -render_pipes -. -is_empty -( -) -{ -profiling -: -: -scope -! -( -" -destroy_render_pipelines -" -) -; -for -raw -in -self -. -render_pipes -. -drain -( -. -. -) -{ -unsafe -{ -device -. -destroy_render_pipeline -( -raw -) -} -; -} -} -if -! -self -. -bind_group_layouts -. -is_empty -( -) -{ -profiling +/ +/ +/ +/ +/ +/ +These +are +freed +by +LifeTracker : : -scope -! -( -" -destroy_bind_group_layouts -" -) -; -for -raw -in -self -. -bind_group_layouts -. -drain -( -. -. -) -{ -unsafe -{ -device -. -destroy_bind_group_layout -( -raw -) -} -; -} -} -if -! -self -. -pipeline_layouts -. -is_empty -( -) -{ -profiling +cleanup +which +is +called +from +periodic +/ +/ +/ +maintenance +functions +like +Global : : -scope -! -( -" -destroy_pipeline_layouts -" -) -; -for -raw -in -self -. -pipeline_layouts -. -drain -( -. -. -) -{ -unsafe -{ +device_poll +and +when +a device +is +/ +/ +/ +destroyed . -destroy_pipeline_layout -( -raw -) -} -; -} -} -if -! -self -. -query_sets -. -is_empty -( -) -{ -profiling -: +free_resources : -scope -! -( -" -destroy_query_sets -" -) -; -for -raw -in -self -. -query_sets -. -drain -( -. -. -) -{ -unsafe -{ -device -. -destroy_query_set -( -raw -) -} -; -} -} -} -} +ResourceMaps / / / -Resources +Buffers +the +user +has +asked +us +to +map +and +which +are +not used by -a +any +/ +/ +/ queue submission -and -work -to -be -done -once -it -completes +still +in +flight . -struct -ActiveSubmission +ready_to_map +: +Vec +< +Arc +< +Buffer < A -: -hal -: -: -Api > -{ +> +> / / / -The -index -of -the -submission -we -track -. -/ -/ -/ -/ -/ -/ -When -Device -: -: -fence -' -s -value +Queue +" +on_submitted_work_done +" +closures +that +were +initiated +for +while +there is -greater -than -or -equal -to -this -our -queue +no / / / -submission -has -completed +currently +pending +submissions . -index -: -SubmissionIndex -/ -/ -/ -Resources -to +These +cannot be -freed -once -this -queue -submission -has -completed -. +immeidately +invoked +as +they / / / +must +happen +_after_ +all +mapped +buffer +callbacks +are +mapped +so +we +defer +them / / / -When +here +until +the +next +time the device is -polled -for -completed -submissions -/ -/ -/ -triage_submissions -merges -these -into -/ -/ -/ -LifetimeTracker -: -: -free_resources +maintained . -From -there +work_done_closures +: +SmallVec +< +[ +SubmittedWorkDoneClosure +; +1 +] +> / / / -LifetimeTracker -: -: -cleanup -passes -them -to -the -hal +Closure to be -freed +called +on +" +lose +the +device +" . -/ -/ -/ -/ -/ -/ This -includes -things -like -temporary -resources -and -resources -that -are +is +invoked +directly +by / / / -used -by -submitted -commands -but -have -been -dropped +device +. +lose +or by the -user -( -meaning -that +UserCallbacks +returned +from +maintain +when +the +device / / / -this -submission -is -their -last -reference +has +been +destroyed +and +its +queues +are +empty . -) -last_resources +pub +device_lost_closure : -NonReferencedResources +Option +< +DeviceLostClosure +> +} +impl < A +: +HalApi > -/ -/ -/ -Buffers -to -be -mapped -once -this -submission -has -completed -. +LifetimeTracker +< +A +> +{ +pub +fn +new +( +) +- +> +Self +{ +Self +{ mapped : Vec -< -id : : -Valid -< -id +new +( +) +future_suspected_buffers : +Vec : -BufferId -> -> -encoders +: +new +( +) +future_suspected_textures : Vec -< -EncoderInFlight -< -A -> -> -/ -/ -/ -List -of -queue -" -on_submitted_work_done -" -closures -to -be -called -once -this -/ -/ -/ -submission -has -completed -. -work_done_closures : -SmallVec -< -[ -SubmittedWorkDoneClosure -; -1 -] -> -} -# -[ -derive -( -Clone -Debug -Error -) -] -# -[ -non_exhaustive -] -pub -enum -WaitIdleError -{ -# -[ -error +: +new ( -transparent ) -] -Device +suspected_resources +: +ResourceMaps +: +: +new +: +: +< +A +> ( -# -[ -from -] -DeviceError ) -# -[ -error -( -" -Tried -to -wait -using -a -submission -index -from -the -wrong -device -. -Submission -index -is -from -device -{ -0 +active : -? -} -. -Called -poll -on -device -{ -1 +Vec : -? -} -. -" -) -] -WrongSubmissionIndex +: +new ( -id +) +free_resources : +ResourceMaps : -QueueId -id +: +new : : -DeviceId +< +A +> +( ) -# -[ -error +ready_to_map +: +Vec +: +: +new ( -" -GPU -got -stuck +) +work_done_closures +: +SmallVec +: : +new ( -" ) -] -StuckGpu +device_lost_closure +: +None +} } / / / -Resource -tracking -for -a -device -. -/ -/ -/ -/ -/ -/ -# -# -Host -mapping -buffers -/ -/ -/ -/ -/ -/ -A -buffer -cannot -be -mapped -until -all -active +Return +true +if +there +are +no queue submissions -that -use -it -/ -/ -/ -have -completed +still +in +flight . -To -that -end -: -/ -/ -/ -/ -/ -/ +pub +fn +queue_empty +( +& +self +) - -Each -buffer -' -s -LifeGuard -: -: -submission_index -records -the -index -of -the +> +bool +{ +self +. +active +. +is_empty +( +) +} / / / -most -recent +Start +tracking +resources +associated +with +a +new queue submission -that -uses -that -buffer . -/ -/ -/ -/ -/ -/ -- -Calling -map_async -adds -the -buffer -to +pub +fn +track_submission +( +& +mut self -. -mapped -and -changes -/ -/ -/ -Buffer +index +: +SubmissionIndex +temp_resources +: +impl +Iterator +< +Item += +TempResource +< +A +> +> +encoders +: +Vec +< +EncoderInFlight +< +A +> +> +) +{ +let +mut +last_resources += +ResourceMaps : : -map_state -to -prevent -it -from -being -used -in -any new -/ -/ -/ -submissions +: +: +< +A +> +( +) +; +for +res +in +temp_resources +{ +match +res +{ +TempResource +: +: +Buffer +( +raw +) += +> +{ +last_resources . -/ -/ -/ -/ -/ -/ -- -When -the -device -is -polled -the -following -LifetimeTracker -methods -decide -/ -/ -/ -what -should -happen -next +insert +( +raw +. +as_info +( +) +. +id +( +) +raw +) +; +} +TempResource : -/ -/ -/ -/ -/ -/ -1 +: +StagingBuffer +( +raw ) -triage_mapped -drains -self += +> +{ +last_resources . -mapped -checking -the -submission -index -/ -/ -/ -of -each -buffer -against -the -queue -submissions -that -have -finished -/ -/ -/ -execution +insert +( +raw . -Buffers -used -by -submissions -still -in -flight -go -in -/ -/ -/ -self +as_info +( +) . -active -[ -index -] +id +( +) +raw +) +; +} +TempResource +: +: +Texture +( +raw +) += +> +{ +last_resources . -mapped -and -the -rest -go -into -/ -/ -/ -self +insert +( +raw . -ready_to_map +as_info +( +) . -/ -/ -/ -/ -/ -/ -2 +id +( ) -triage_submissions -moves -entries -in +raw +) +; +} +} +} self . active -[ -i -] -for -completed -/ -/ -/ -submissions -to +. +push +( +ActiveSubmission +{ +index +last_resources +mapped +: +Vec +: +: +new +( +) +encoders +work_done_closures +: +SmallVec +: +: +new +( +) +} +) +; +} +pub +fn +post_submit +( +& +mut +self +) +{ +for +v +in self . -ready_to_map +future_suspected_buffers . -At -this -point -both -/ -/ -/ +drain +( +. +. +) +. +take +( +1 +) +{ self . -active -and +suspected_resources +. +insert +( +v +. +as_info +( +) +. +id +( +) +v +) +; +} +for +v +in self . -ready_to_map -are -up -to -date -with -the -given +future_suspected_textures +. +drain +( +. +. +) +. +take +( +1 +) +{ +self +. +suspected_resources +. +insert +( +v +. +as_info +( +) +. +id +( +) +v +) +; +} +} +pub +( +crate +) +fn +map +( +& +mut +self +value +: +& +Arc +< +Buffer +< +A +> +> +) +{ +self +. +mapped +. +push +( +value +. +clone +( +) +) +; +} / / / -submission -index +Sort +out +the +consequences +of +completed +submissions . / / @@ -2236,65 +2704,73 @@ index / / / -3 -) -handle_mapping -drains -self +Assume +that +all +submissions +up +through +last_done +have +completed . -ready_to_map -and -actually -maps -the / / / -buffers -collecting -a -list -of -notification -closures -to -call -. -But -any / / / -buffers -that -were -dropped +- +Buffers +used by -the -user -get -moved +those +submissions +are +now +ready to +map +if / / / -self -. -free_resources +requested . +Add +any +buffers +in +the +submission +' +s +[ +mapped +] +list +to / / / +[ +self +. +ready_to_map +] +where +[ +LifetimeTracker +: +: +handle_mapping +] +will +find / / / -4 -) -cleanup -frees -everything -in -free_resources +them . / / @@ -2302,420 +2778,172 @@ free_resources / / / -Only -self -. -mapped -holds -a -RefCount -for -the -buffer -; -it -is -dropped -by -/ -/ -/ -triage_mapped -. -pub -( -super -) -struct -LifetimeTracker -< -A -: -hal -: -: -Api -> -{ -/ -/ -/ +- Resources -that -the -user -has -requested -be -mapped -but -which +whose +final +use +was +in +those +submissions are -used -by +now +ready +to / / / -queue -submissions -still -in -flight +free . -mapped -: -Vec -< -Stored -< -id -: -: -BufferId -> -> -/ -/ -/ -Buffers -can -be -used +Add +any +resources in -a -submission -that -is -yet -to -be -made -by the +submission +' +s +[ +last_resources +] +table / / / -means -of -write_buffer -( -) -so -we -have -a -special -place -for -them +to +[ +self . -pub -future_suspected_buffers -: -Vec -< -Stored -< -id +free_resources +] +where +[ +LifetimeTracker : : -BufferId -> -> +cleanup +] +will +find / / / -Textures -can -be -used -in -the -upcoming -submission -by -write_texture +them . -pub -future_suspected_textures -: -Vec -< -Stored -< -id -: -: -TextureId -> -> / / / -Resources -whose -user -handle -has -died -( -i -. -e -. -drop -/ -destroy -has -been -called -) / / / -and -will -likely -be -ready -for -destruction -soon +Return +a +list +of +[ +SubmittedWorkDoneClosure +] +s +to +run . -pub -suspected_resources -: -SuspectedResources / / / -Resources -used -by -queue -submissions -still -in -flight -. -One -entry -per / / / -submission -with -older -submissions -appearing -before -younger -. +[ +mapped +] +: +ActiveSubmission +: +: +mapped / / / +[ +self +. +ready_to_map +] +: +LifetimeTracker +: +: +ready_to_map / / / -Entries -are -added -by -track_submission -and -drained -by +[ +last_resources +] +: +ActiveSubmission +: +: +last_resources / / / +[ +self +. +free_resources +] +: LifetimeTracker : : -triage_submissions -. -Lots -of -methods -contribute -data +free_resources / / / -to -particular -entries -. -active -: -Vec -< -ActiveSubmission -< -A -> -> -/ -/ -/ -Raw -backend -resources -that -are -neither -referenced -nor -used -. -/ -/ -/ -/ -/ -/ -These -are -freed -by -LifeTracker -: +[ +SubmittedWorkDoneClosure +] : -cleanup -which -is -called -from -periodic -/ -/ -/ -maintenance -functions -like -Global +crate : : -device_poll -and -when -a device -is -/ -/ -/ -destroyed -. -free_resources : -NonReferencedResources -< -A -> -/ -/ -/ -Buffers -the -user -has -asked -us -to -map -and -which -are -not -used -by -any -/ -/ -/ +: queue -submission -still -in -flight -. -ready_to_map : -Vec -< -id : +SubmittedWorkDoneClosure +# +[ +must_use +] +pub +fn +triage_submissions +( +& +mut +self +last_done +: +SubmissionIndex +command_allocator : -Valid -< -id +& +mut +super : : -BufferId +CommandAllocator +< +A > +) +- > -/ -/ -/ -Queue -" -on_submitted_work_done -" -closures -that -were -initiated -for -while -there -is -no -/ -/ -/ -currently -pending -submissions -. -These -cannot -be -immeidately -invoked -as -they -/ -/ -/ -must -happen -_after_ -all -mapped -buffer -callbacks -are -mapped -so -we -defer -them -/ -/ -/ -here -until -the -next -time -the -device -is -maintained -. -work_done_closures -: SmallVec < [ @@ -2724,253 +2952,291 @@ SubmittedWorkDoneClosure 1 ] > -/ -/ -/ -Closure -to -be -called -on +{ +profiling +: +: +scope +! +( " -lose -the -device +triage_submissions " -. -This -is -invoked -directly -by -/ +) +; / / -device -. -lose -or -by -the -UserCallbacks -returned -from -maintain +TODO +: +enable when -the -device -/ +is_sorted_by_key +is +stable / / -has -been -destroyed -and -its -queues -are -empty +debug_assert +! +( +self . -pub -device_lost_closure -: -Option -< -DeviceLostClosure -> -} -impl -< -A -: -hal -: -: -Api -> -LifetimeTracker -< -A -> -{ -pub -fn -new +active +. +is_sorted_by_key ( +| +a +| +a +. +index ) -- -> -Self -{ -Self -{ -mapped -: -Vec -: -: -new +) +; +let +done_count += +self +. +active +. +iter ( ) -future_suspected_buffers -: -Vec -: -: -new +. +position ( +| +a +| +a +. +index +> +last_done ) -future_suspected_textures -: -Vec -: -: -new +. +unwrap_or +( +self +. +active +. +len ( ) -suspected_resources -: -SuspectedResources -: +) +; +let +mut +work_done_closures : -default +SmallVec +< +_ +> += +self +. +work_done_closures +. +drain +( +. +. +) +. +collect ( ) +; +for +a +in +self +. active -: -Vec +. +drain +( +. +. +done_count +) +{ +log : : -new +info +! ( +" +Active +submission +{ +} +is +done +" +a +. +index ) +; +self +. free_resources -: -NonReferencedResources -: -: -new +. +extend ( +a +. +last_resources ) +; +self +. ready_to_map -: -Vec -: -: -new +. +extend ( +a +. +mapped ) -work_done_closures -: -SmallVec -: -: -new +; +for +encoder +in +a +. +encoders +{ +let +raw += +unsafe +{ +encoder +. +land ( ) -device_lost_closure -: -None } +; +command_allocator +. +release_encoder +( +raw +) +; } -/ -/ -/ -Return -true -if -there -are -no -queue -submissions -still -in -flight +work_done_closures +. +extend +( +a . +work_done_closures +) +; +} +work_done_closures +} pub fn -queue_empty +cleanup ( & +mut self ) -- -> -bool { +profiling +: +: +scope +! +( +" +LifetimeTracker +: +: +cleanup +" +) +; self . -active +free_resources . -is_empty +clear ( ) +; } -/ -/ -/ -Start -tracking -resources -associated -with -a -new -queue -submission -. pub fn -track_submission +schedule_resource_destruction ( & mut self -index +temp_resource : -SubmissionIndex -temp_resources -: -impl -Iterator -< -Item -= TempResource < A > -> -encoders +last_submit_index : -Vec -< -EncoderInFlight -< -A -> -> +SubmissionIndex ) { let -mut -last_resources +resources = -NonReferencedResources -: -: -new +self +. +active +. +iter_mut +( +) +. +find +( +| +a +| +a +. +index += += +last_submit_index +) +. +map_or ( +& +mut +self +. +free_resources +| +a +| +& +mut +a +. +last_resources ) ; -for -res -in -temp_resources -{ match -res +temp_resource { TempResource : @@ -2981,540 +3247,620 @@ raw ) = > -last_resources +{ +resources . -buffers +insert +( +raw . -push +as_info +( +) +. +id ( +) raw ) +; +} TempResource : : -Texture +StagingBuffer ( raw -views ) = > { -last_resources -. -textures +resources . -push +insert ( raw -) -; -last_resources . -texture_views +as_info +( +) . -extend +id ( -views +) +raw ) ; } -} -} -self -. -active -. -push -( -ActiveSubmission -{ -index -last_resources -mapped -: -Vec +TempResource : : -new +Texture ( +raw ) -encoders -work_done_closures -: -SmallVec -: -: -new += +> +{ +resources +. +insert +( +raw +. +as_info ( ) -} +. +id +( +) +raw ) ; } +} +} pub fn -post_submit +add_work_done_closure ( & mut self +closure +: +SubmittedWorkDoneClosure ) { +match self . -suspected_resources -. -buffers +active . -extend +last_mut ( -self -. -future_suspected_buffers -. -drain +) +{ +Some ( -. -. +active ) += +> +{ +active . -map -( -| -stored -| -stored +work_done_closures . -value -) +push +( +closure ) ; -self -. -suspected_resources +} +/ +/ +We +must +defer +the +closure +until +all +previously +occuring +map_async +closures +/ +/ +have +fired . -textures +This +is +required +by +the +spec . -extend -( +None += +> +{ self . -future_suspected_textures -. -drain -( -. -. -) +work_done_closures . -map +push ( -| -stored -| -stored -. -value -) +closure ) ; } -pub -( -crate -) +} +} +} +impl +< +A +: +HalApi +> +LifetimeTracker +< +A +> +{ fn -map +triage_resources +< +Id +R +F +T +> ( +resources_map +: & mut -self -value -: -id -: -: -Valid +FastHashMap < +Id +Arc +< +R +> +> +active +: +& +mut +[ +ActiveSubmission +< +A +> +] +free_resources +: +& +mut +ResourceMaps +trackers +: +& +mut +impl +ResourceTracker +< +Id +R +> +registry +: +& +Registry +< +Id +R +> +count_fn +: +F +mut +on_remove +: +T +) +- +> +Vec +< +Arc +< +R +> +> +where +Id +: id : : -BufferId +TypedId +R +: +Resource +< +Id +> +F +: +Fn +( +u64 +& +[ +ActiveSubmission +< +A +> +] +& +Id +) +- +> +usize +T +: +FnMut +( +& +Id +& +Arc +< +R > -ref_count +) +{ +let +mut +removed_resources += +Vec : -RefCount +: +new +( ) +; +resources_map +. +retain +( +| +& +id +resource +| { -self +let +submit_index += +resource . -mapped +as_info +( +) . -push +submission_index ( -Stored -{ -value -ref_count -} ) ; -} -/ -/ -/ -Sort -out -the -consequences -of -completed -submissions +let +mut +count += +1 +; +count ++ += +count_fn +( +submit_index +active +& +id +) +; +count ++ += +registry . -/ -/ -/ -/ -/ -/ -Assume -that -all -submissions -up -through -last_done -have -completed +contains +( +id +) +as +usize +; +let +non_referenced_resources += +active . -/ -/ -/ -/ -/ -/ -- -Buffers -used -by -those -submissions -are -now -ready -to -map -if -/ -/ -/ -requested +iter_mut +( +) . -Add -any -buffers -in -the -submission -' -s -[ -mapped -] -list -to -/ -/ -/ -[ -self +find +( +| +a +| +a . -ready_to_map -] -where -[ -LifetimeTracker +index += += +submit_index +) +. +map_or +( +& +mut +* +free_resources +| +a +| +& +mut +a +. +last_resources +) +; +count ++ += +non_referenced_resources +. +contains : : -handle_mapping -] -will -find -/ -/ -/ -them +< +Id +R +> +( +& +id +) +as +usize +; +let +is_removed += +trackers . -/ -/ -/ -/ -/ -/ -- -Resources -whose -final -use -was -in -those -submissions -are -now -ready -to -/ -/ -/ -free -. -Add -any -resources -in -the -submission -' -s -[ -last_resources -] -table -/ -/ -/ -to -[ -self -. -free_resources -] -where -[ -LifetimeTracker -: -: -cleanup -] -will -find -/ -/ -/ -them +remove_abandoned +( +id +count +) +; +if +is_removed +{ +on_remove +( +& +id +resource +) +; +removed_resources . -/ -/ -/ -/ -/ -/ -Return -a -list -of -[ -SubmittedWorkDoneClosure -] -s -to -run +push +( +resource . -/ -/ -/ -/ -/ -/ -[ -mapped -] -: -ActiveSubmission -: -: -mapped -/ -/ -/ -[ -self +clone +( +) +) +; +non_referenced_resources . -ready_to_map -] -: -LifetimeTracker -: -: -ready_to_map -/ -/ -/ -[ -last_resources -] -: -ActiveSubmission -: -: -last_resources -/ -/ -/ -[ -self +insert +( +id +resource . -free_resources -] -: -LifetimeTracker -: -: -free_resources -/ -/ -/ -[ -SubmittedWorkDoneClosure -] -: -crate -: -: -device -: -: -queue -: -: -SubmittedWorkDoneClosure -# -[ -must_use -] -pub +clone +( +) +) +; +} +! +is_removed +} +) +; +removed_resources +} fn -triage_submissions +triage_suspected_render_bundles ( & mut self -last_done +hub : -SubmissionIndex -command_allocator +& +Hub +< +A +> +trackers : & Mutex < -super -: -: -CommandAllocator +Tracker < A > > -) -- -> -SmallVec -< +# [ -SubmittedWorkDoneClosure -; -1 -] -> -{ -profiling -: -: -scope -! +cfg ( +feature += " -triage_submissions +trace " ) -; -/ -/ -TODO +] +trace : -enable -when -is_sorted_by_key -is -stable -/ -/ -debug_assert -! +& +mut +Option +< +& +mut +trace +: +: +Trace +> +) +- +> +& +mut +Self +{ +let +mut +trackers += +trackers +. +lock ( +) +; +let +resource_map += self . -active +suspected_resources . -is_sorted_by_key +map_mut ( -| -a -| -a -. -index -) ) ; let -done_count +mut +removed_resources = +Self +: +: +triage_resources +( +resource_map self . active . -iter +as_mut_slice ( ) +& +mut +self . -position -( +free_resources +& +mut +trackers +. +bundles +& +hub +. +render_bundles | -a +_submit_index +_active +_id | -a -. -index -> -last_done +0 +| +_bundle_id +_bundle +| +{ +# +[ +cfg +( +feature += +" +trace +" ) -. -unwrap_or +] +if +let +Some ( -self -. -active +ref +mut +t +) += +* +trace +{ +t . -len +add +( +trace +: +: +Action +: +: +DestroyRenderBundle ( +* +_bundle_id ) ) ; -let -mut -work_done_closures -: -SmallVec -< -_ -> -= -self -. -work_done_closures +} +} +) +; +removed_resources . drain ( @@ -3522,826 +3868,199 @@ drain . ) . -collect +for_each ( -) -; +| +bundle +| +{ for -a +v in -self +bundle . -active -. -drain -( +used . +buffers . -done_count -) -{ -log -: -: -trace -! +write ( -" -Active -submission -{ -} -is -done -" -a +) . -index +drain_resources +( ) -; +{ self . -free_resources +suspected_resources . -extend +insert ( -a +v . -last_resources +as_info +( ) -; -self -. -ready_to_map . -extend +id ( -a -. -mapped +) +v ) ; +} for -encoder +v in -a +bundle . -encoders -{ -let -raw -= -unsafe -{ -encoder +used . -land -( -) -} -; -command_allocator +textures . -lock +write ( ) . -release_encoder +drain_resources ( -raw ) -; -} -work_done_closures +{ +self . -extend +suspected_resources +. +insert ( -a +v . -work_done_closures -) -; -} -work_done_closures -} -pub -fn -cleanup +as_info ( -& -mut -self -device -: -& -A -: -: -Device ) -{ -profiling -: -: -scope -! +. +id ( -" -LifetimeTracker -: -: -cleanup -" +) +v ) ; -unsafe -{ -self +} +for +v +in +bundle . -free_resources +used +. +bind_groups . -clean +write ( -device ) -; -} -} -pub -fn -schedule_resource_destruction +. +drain_resources ( -& -mut -self -temp_resource -: -TempResource -< -A -> -last_submit_index -: -SubmissionIndex ) { -let -resources -= self . -active +suspected_resources . -iter_mut +insert ( -) +v . -find +as_info ( -| -a -| -a -. -index -= -= -last_submit_index -) -. -map_or -( -& -mut -self -. -free_resources -| -a -| -& -mut -a -. -last_resources -) -; -match -temp_resource -{ -TempResource -: -: -Buffer -( -raw -) -= -> -resources -. -buffers -. -push -( -raw -) -TempResource -: -: -Texture -( -raw -views -) -= -> -{ -resources -. -texture_views -. -extend -( -views -) -; -resources -. -textures -. -push -( -raw -) -; -} -} -} -pub -fn -add_work_done_closure -( -& -mut -self -closure -: -SubmittedWorkDoneClosure -) -{ -match -self -. -active -. -last_mut -( -) -{ -Some -( -active -) -= -> -{ -active -. -work_done_closures -. -push -( -closure -) -; -} -/ -/ -We -must -defer -the -closure -until -all -previously -occuring -map_async -closures -/ -/ -have -fired -. -This -is -required -by -the -spec -. -None -= -> -{ -self -. -work_done_closures -. -push -( -closure -) -; -} -} -} -} -impl -< -A -: -HalApi -> -LifetimeTracker -< -A -> -{ -/ -/ -/ -Identify -resources -to -free -according -to -trackers -and -self -. -suspected_resources -. -/ -/ -/ -/ -/ -/ -Given -trackers -the -[ -Tracker -] -belonging -to -same -[ -Device -] -as -/ -/ -/ -self -and -hub -the -[ -Hub -] -to -which -that -Device -belongs -: -/ -/ -/ -/ -/ -/ -Remove -from -trackers -each -resource -mentioned -in -/ -/ -/ -[ -self -. -suspected_resources -] -. -If -trackers -held -the -final -reference -to -/ -/ -/ -that -resource -add -it -to -the -appropriate -free -list -to -be -destroyed -by -/ -/ -/ -the -hal -: -/ -/ -/ -/ -/ -/ -- -Add -resources -used -by -queue -submissions -still -in -flight -to -the -/ -/ -/ -[ -last_resources -] -table -of -the -last -such -submission -' -s -entry -in -/ -/ -/ -[ -self -. -active -] -. -When -that -submission -has -finished -execution -. -the -/ -/ -/ -[ -triage_submissions -] -method -will -move -them -to -/ -/ -/ -[ -self -. -free_resources -] -. -/ -/ -/ -/ -/ -/ -- -Add -resources -that -can -be -freed -right -now -to -[ -self -. -free_resources -] -/ -/ -/ -directly -. -[ -LifetimeTracker -: -: -cleanup -] -will -take -care -of -them -as -/ -/ -/ -part -of -this -poll -. -/ -/ -/ -/ -/ -/ -# -# -Entrained -resources -/ -/ -/ -/ -/ -/ -This -function -finds -resources -that -are -used -only -by -other -resources -/ -/ -/ -ready -to -be -freed -and -adds -those -to -the -free -lists -as -well -. -For -/ -/ -/ -example -if -there -' -s -some -texture -T -used -only -by -some -texture -view -/ -/ -/ -TV -then -if -TV -can -be -freed -T -gets -added -to -the -free -lists -too -. -/ -/ -/ -/ -/ -/ -Since -wgpu -- -core -resource -ownership -patterns -are -acyclic -we -can -visit -/ -/ -/ -each -type -that -can -be -owned -after -all -types -that -could -possibly -own -/ -/ -/ -it -. -This -way -we -can -detect -all -free -- -able -objects -in -a -single -pass -/ -/ -/ -simply -by -starting -with -types -that -are -roots -of -the -ownership -DAG -( -like -/ -/ -/ -render -bundles ) -and -working -our -way -towards -leaf -types +. +id ( -like -buffers ) +v +) +; +} +for +v +in +bundle . -/ -/ -/ -/ -/ -/ -[ -Device -] -: -super -: -: -Device -/ -/ -/ -[ +used +. +render_pipelines +. +write +( +) +. +drain_resources +( +) +{ self . suspected_resources -] -: -LifetimeTracker -: -: -suspected_resources -/ -/ -/ -[ -last_resources -] -: -ActiveSubmission -: -: -last_resources -/ -/ -/ -[ -self . -active -] -: -LifetimeTracker -: -: -active -/ -/ -/ -[ -triage_submissions -] -: -LifetimeTracker -: -: -triage_submissions -/ -/ -/ -[ +insert +( +v +. +as_info +( +) +. +id +( +) +v +) +; +} +for +v +in +bundle +. +used +. +query_sets +. +write +( +) +. +drain_resources +( +) +{ self . -free_resources -] -: -LifetimeTracker -: -: -free_resources -pub +suspected_resources +. +insert ( -super +v +. +as_info +( +) +. +id +( +) +v +) +; +} +} ) +; +self +} fn -triage_suspected -< -G -: -GlobalIdentityHandlerFactory -> +triage_suspected_bind_groups ( & mut @@ -4352,7 +4071,6 @@ hub Hub < A -G > trackers : @@ -4377,128 +4095,87 @@ trace ] trace : +& +mut Option < & -Mutex -< +mut trace : : Trace > +) +- > -token -: & mut -Token -< -super -: -: -Device -< -A -> -> -) -{ -profiling -: -: -scope -! -( -" -triage_suspected -" -) -; -if -! -self -. -suspected_resources -. -render_bundles -. -is_empty -( -) +Self { let -( mut -guard -_ -) +trackers = -hub -. -render_bundles +trackers . -write +lock ( -token ) ; let -mut -trackers +resource_map = -trackers +self . -lock +suspected_resources +. +map_mut ( ) ; -while let -Some -( -id -) +mut +removed_resource = +Self +: +: +triage_resources +( +resource_map self . -suspected_resources -. -render_bundles +active . -pop +as_mut_slice ( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -bundles +bind_groups +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Bundle -{ -: -? -} -will -be -destroyed -" -id -) -; +bind_groups +| +_submit_index +_active +_id +| +0 +| +_bind_group_id +_bind_group +| +{ # [ cfg @@ -4514,17 +4191,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -4533,81 +4209,289 @@ trace Action : : -DestroyRenderBundle +DestroyBindGroup ( -id -. -0 +* +_bind_group_id ) ) ; } -if -let -Some +} +) +; +removed_resource +. +drain ( -res +. +. ) -= -hub . -render_bundles +for_each +( +| +bind_group +| +{ +for +v +in +bind_group +. +used +. +buffers +. +drain_resources +( +) +{ +self +. +suspected_resources . -unregister_locked +insert ( +v +. +as_info +( +) +. id +( +) +v +) +; +} +for +v +in +bind_group . -0 -& -mut -* -guard +used +. +textures +. +drain_resources +( ) { self . suspected_resources . -add_render_bundle_scope +insert ( -& -res +v . -used +as_info +( +) +. +id +( +) +v ) ; } -} -} -} -if -! +for +v +in +bind_group +. +used +. +views +. +drain_resources +( +) +{ self . suspected_resources . -bind_groups +insert +( +v . -is_empty +as_info +( +) +. +id +( +) +v +) +; +} +for +v +in +bind_group +. +used +. +samplers +. +drain_resources ( ) { -let +self +. +suspected_resources +. +insert +( +v +. +as_info ( -mut -guard -_ ) -= -hub . -bind_groups +id +( +) +v +) +; +} +/ +/ +Releasing +safely +unused +resources +to +decrement +refcount +bind_group +. +used_buffer_ranges +. +write +( +) +. +clear +( +) +; +bind_group +. +used_texture_ranges +. +write +( +) +. +clear +( +) +; +bind_group +. +dynamic_binding_info . write ( -token +) +. +clear +( +) +; +self +. +suspected_resources +. +insert +( +bind_group +. +layout +. +as_info +( +) +. +id +( +) +bind_group +. +layout +. +clone +( +) +) +; +} ) ; +self +} +fn +triage_suspected_texture_views +( +& +mut +self +hub +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg +( +feature += +" +trace +" +) +] +trace +: +& +mut +Option +< +& +mut +trace +: +: +Trace +> +) +- +> +& +mut +Self +{ let mut trackers @@ -4618,53 +4502,59 @@ lock ( ) ; -while let -Some +resource_map += +self +. +suspected_resources +. +map_mut ( -id ) +; +let +mut +removed_resources = +Self +: +: +triage_resources +( +resource_map self . -suspected_resources -. -bind_groups +active . -pop +as_mut_slice ( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -bind_groups +views +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Bind -group +texture_views +| +_submit_index +_active +_id +| +0 +| +_texture_view_id +_texture_view +| { -: -? -} -will -be -destroyed -" -id -) -; # [ cfg @@ -4680,17 +4570,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -4699,152 +4588,134 @@ trace Action : : -DestroyBindGroup +DestroyTextureView ( -id -. -0 +* +_texture_view_id ) ) ; } -if -let -Some -( -res +} ) -= -hub -. -bind_groups +; +removed_resources . -unregister_locked +drain ( -id -. -0 -& -mut -* -guard -) -{ -self . -suspected_resources -. -add_bind_group_states -( -& -res . -used ) -; -self . -suspected_resources +for_each +( +| +texture_view +| +{ +let +mut +lock += +texture_view . -bind_group_layouts +parent . -push +write ( -res -. -layout_id ) ; +if let -submit_index +Some +( +parent_texture +) = -res -. -life_guard +lock . -life_count +take ( ) -; +{ self . -active +suspected_resources . -iter_mut +insert ( -) +parent_texture . -find +as_info ( -| -a -| -a -. -index -= -= -submit_index ) . -map_or +id ( -& -mut -self -. -free_resources -| -a -| -& -mut -a -. -last_resources ) -. -bind_groups -. -push -( -res -. -raw +parent_texture ) ; } } -} -} -if -! -self -. -suspected_resources -. -texture_views -. -is_empty -( ) -{ -let +; +self +} +fn +triage_suspected_textures ( +& mut -guard -_ -) -= +self hub -. -texture_views -. -write +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg ( -token +feature += +" +trace +" ) -; +] +trace +: +& +mut +Option +< +& +mut +trace +: +: +Trace +> +) +- +> +& +mut +Self +{ let mut trackers @@ -4856,64 +4727,54 @@ lock ) ; let -mut -list +resource_map = -mem -: -: -take -( -& -mut self . suspected_resources . -texture_views +map_mut +( ) ; -for -id -in -list -. -drain +Self +: +: +triage_resources ( +resource_map +self . +active . +as_mut_slice +( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -views +textures +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Texture -view +textures +| +_submit_index +_active +_id +| +0 +| +_texture_id +_texture +| { -: -? -} -will -be -destroyed -" -id -) -; # [ cfg @@ -4929,17 +4790,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -4948,150 +4808,73 @@ trace Action : : -DestroyTextureView +DestroyTexture ( -id -. -0 +* +_texture_id ) ) ; } -if -let -Some -( -res +} ) -= -hub -. -texture_views -. -unregister_locked +; +self +} +fn +triage_suspected_samplers ( -id -. -0 & mut -* -guard -) -{ -self -. -suspected_resources -. -textures -. -push -( -res -. -parent_id -. -value -) -; -let -submit_index -= -res -. -life_guard -. -life_count -( -) -; self -. -active -. -iter_mut -( -) -. -find +hub +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg ( -| -a -| -a -. -index -= +feature = -submit_index +" +trace +" ) -. -map_or -( +] +trace +: & mut -self -. -free_resources -| -a -| +Option +< & mut -a -. -last_resources -) -. -texture_views -. -push -( -res -. -raw -) -; -} -} -} -self -. -suspected_resources -. -texture_views -= -list -; -} -if -! -self -. -suspected_resources -. -textures -. -is_empty -( +trace +: +: +Trace +> ) -{ -let -( +- +> +& mut -guard -_ -) -= -hub -. -textures -. -write -( -token -) -; +Self +{ let mut trackers @@ -5102,50 +4885,55 @@ lock ( ) ; -for -id -in +let +resource_map += self . suspected_resources . -textures -. -drain +map_mut +( +) +; +Self +: +: +triage_resources ( +resource_map +self . +active . +as_mut_slice +( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -textures +samplers +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Texture +samplers +| +_submit_index +_active +_id +| +0 +| +_sampler_id +_sampler +| { -: -? -} -will -be -destroyed -" -id -) -; # [ cfg @@ -5161,17 +4949,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -5180,88 +4967,143 @@ trace Action : : -DestroyTexture +DestroySampler ( -id -. -0 +* +_sampler_id ) ) ; } -if -let -Some -( -res +} ) -= +; +self +} +fn +triage_suspected_buffers +( +& +mut +self hub -. -textures -. -unregister_locked +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg ( -id -. -0 +feature += +" +trace +" +) +] +trace +: & mut -* -guard +Option +< +& +mut +trace +: +: +Trace +> ) +- +> +& +mut +Self { let -submit_index +mut +trackers = -res -. -life_guard +trackers . -life_count +lock ( ) ; let -raw +resource_map = -match -res +self . -inner -{ -resource -: -: -TextureInner -: +suspected_resources +. +map_mut +( +) +; +let +mut +removed_resources += +Self : -Native -{ -raw : -Some +triage_resources +( +resource_map +self +. +active +. +as_mut_slice ( -raw ) -} -= -> -raw -_ +& +mut +self +. +free_resources +& +mut +trackers +. +buffers +& +hub +. +buffers +| +submit_index +active +buffer_id +| +{ +let +mut +count = -> -continue -} +0 ; let -non_referenced_resources +mapped = -self -. active . -iter_mut +iter ( ) . @@ -5281,148 +5123,61 @@ submit_index map_or ( & -mut self . -free_resources +mapped | a | & -mut a . -last_resources -) -; -non_referenced_resources -. -textures -. -push -( -raw -) -; -if -let -resource -: -: -TextureClearMode -: -: -RenderPass -{ -clear_views -. -. -} -= -res -. -clear_mode -{ -non_referenced_resources -. -texture_views -. -extend -( -clear_views -. -into_iter -( -) -) -; -} -} -} -} -} -if -! -self -. -suspected_resources -. -samplers -. -is_empty -( -) -{ -let -( -mut -guard -_ -) -= -hub -. -samplers -. -write -( -token +mapped ) ; -let -mut -trackers -= -trackers +mapped . -lock +iter ( ) -; -for -id -in -self -. -suspected_resources . -samplers -. -drain +for_each ( -. -. -) +| +b +| { if -trackers -. -samplers +b . -remove_abandoned +as_info ( -id ) -{ -log -: -: -debug -! +. +id ( -" -Sampler +) += += +* +buffer_id { -: -? +count ++ += +1 +; +} } -will -be -destroyed -" -id ) ; +count +} +| +_buffer_id +_buffer +| +{ # [ cfg @@ -5438,17 +5193,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -5457,127 +5211,138 @@ trace Action : : -DestroySampler +DestroyBuffer ( -id -. -0 +* +_buffer_id ) ) ; } -if -let -Some -( -res +} ) -= -hub -. -samplers +; +removed_resources . -unregister_locked +drain ( -id . -0 -& -mut -* -guard +. ) +. +for_each +( +| +buffer +| { +if let -submit_index +resource +: +: +BufferMapState +: +: +Init +{ +ref +stage_buffer +. +. +} = -res +* +buffer . -life_guard +map_state . -life_count +lock ( ) -; +{ self . -active +free_resources . -iter_mut +insert ( -) +stage_buffer . -find +as_info ( -| -a -| -a -. -index -= -= -submit_index ) . -map_or +id ( -& -mut -self -. -free_resources -| -a -| -& -mut -a -. -last_resources ) +stage_buffer . -samplers -. -push +clone ( -res -. -raw +) ) ; } } -} -} -if -! -self -. -suspected_resources -. -buffers -. -is_empty -( ) -{ -let +; +self +} +fn +triage_suspected_compute_pipelines ( +& mut -guard -_ -) -= +self hub -. -buffers -. -write +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg ( -token +feature += +" +trace +" ) -; +] +trace +: +& +mut +Option +< +& +mut +trace +: +: +Trace +> +) +- +> +& +mut +Self +{ let mut trackers @@ -5588,50 +5353,59 @@ lock ( ) ; -for -id -in +let +resource_map += self . suspected_resources . -buffers -. -drain +map_mut +( +) +; +let +mut +removed_resources += +Self +: +: +triage_resources ( +resource_map +self . +active . +as_mut_slice +( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -buffers +compute_pipelines +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Buffer +compute_pipelines +| +_submit_index +_active +_id +| +0 +| +_compute_pipeline_id +_compute_pipeline +| { -: -? -} -will -be -destroyed -" -id -) -; # [ cfg @@ -5647,17 +5421,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -5666,158 +5439,116 @@ trace Action : : -DestroyBuffer +DestroyComputePipeline ( -id -. -0 +* +_compute_pipeline_id ) ) ; } -if -let -Some -( -res +} ) -= -hub -. -buffers +; +removed_resources . -unregister_locked +drain ( -id -. -0 -& -mut -* -guard -) -{ -let -submit_index -= -res . -life_guard . -life_count -( ) -; -if -let -resource -: -: -BufferMapState -: -: -Init -{ -stage_buffer -. -. -} -= -res . -map_state +for_each +( +| +compute_pipeline +| { self . -free_resources -. -buffers +suspected_resources . -push +insert ( -stage_buffer -) -; -} -self -. -active +compute_pipeline . -iter_mut -( -) +layout . -find +as_info ( -| -a -| -a -. -index -= -= -submit_index ) . -map_or +id ( -& -mut -self -. -free_resources -| -a -| -& -mut -a -. -last_resources ) +compute_pipeline . -buffers +layout . -extend +clone ( -res -. -raw +) ) ; } -} -} -} -if -! -self -. -suspected_resources -. -compute_pipelines -. -is_empty -( ) -{ -let +; +self +} +fn +triage_suspected_render_pipelines ( +& mut -guard -_ -) -= +self hub -. -compute_pipelines -. -write +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +# +[ +cfg ( -token +feature += +" +trace +" ) -; +] +trace +: +& +mut +Option +< +& +mut +trace +: +: +Trace +> +) +- +> +& +mut +Self +{ let mut trackers @@ -5828,51 +5559,59 @@ lock ( ) ; -for -id -in +let +resource_map += self . suspected_resources . -compute_pipelines -. -drain +map_mut +( +) +; +let +mut +removed_resources += +Self +: +: +triage_resources ( +resource_map +self . +active . +as_mut_slice +( ) -{ -if +& +mut +self +. +free_resources +& +mut trackers . -compute_pipelines +render_pipelines +& +hub . -remove_abandoned -( -id -) -{ -log -: -: -debug -! -( -" -Compute -pipeline -{ -: -? -} -will -be -destroyed -" -id -) -; +render_pipelines +| +_submit_index +_active +_id +| +0 +| +_render_pipeline_id +_render_pipeline +| +{ # [ cfg @@ -5888,17 +5627,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -5907,182 +5645,134 @@ trace Action : : -DestroyComputePipeline +DestroyRenderPipeline ( -id -. -0 +* +_render_pipeline_id ) ) ; } -if -let -Some -( -res +} ) -= -hub -. -compute_pipelines +; +removed_resources . -unregister_locked +drain ( -id . -0 -& -mut -* -guard -) -{ -let -submit_index -= -res . -life_guard +) . -life_count +for_each ( -) -; +| +render_pipeline +| +{ self . -active +suspected_resources . -iter_mut +insert ( -) +render_pipeline . -find -( -| -a -| -a +layout . -index -= -= -submit_index +as_info +( ) . -map_or +id ( -& -mut -self -. -free_resources -| -a -| -& -mut -a -. -last_resources ) +render_pipeline . -compute_pipes +layout . -push +clone ( -res -. -raw +) ) ; } +) +; +self } -} -} -if -! +fn +triage_suspected_pipeline_layouts +( +& +mut self -. -suspected_resources -. -render_pipelines -. -is_empty +# +[ +cfg ( +feature += +" +trace +" ) -{ -let -( +] +trace +: +& mut -guard -_ -) -= -hub -. -render_pipelines -. -write -( -token +Option +< +& +mut +trace +: +: +Trace +> ) -; +- +> +& +mut +Self +{ let mut -trackers +removed_resources = -trackers -. -lock +Vec +: +: +new ( ) ; -for -id -in self . suspected_resources . -render_pipelines -. -drain +map_mut +: +: +< +PipelineLayoutId +PipelineLayout +< +A +> +> ( -. -. ) -{ -if -trackers . -render_pipelines -. -remove_abandoned -( -id -) -{ -log -: -: -debug -! +retain ( -" -Render -pipeline +| +_pipeline_layout_id +pipeline_layout +| { -: -? -} -will -be -destroyed -" -id -) -; # [ cfg @@ -6098,17 +5788,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -6117,147 +5806,139 @@ trace Action : : -DestroyRenderPipeline +DestroyPipelineLayout ( -id -. -0 +* +_pipeline_layout_id ) ) ; } -if -let -Some -( -res -) -= -hub -. -render_pipelines +removed_resources . -unregister_locked +push ( -id -. -0 -& -mut -* -guard -) -{ -let -submit_index -= -res -. -life_guard +pipeline_layout . -life_count +clone ( ) +) ; -self -. -active -. -iter_mut -( +false +} ) +; +removed_resources . -find +drain ( -| -a -| -a . -index -= -= -submit_index +. ) . -map_or +for_each ( -& -mut -self -. -free_resources | -a +pipeline_layout | +{ +for +bgl +in & -mut -a +pipeline_layout . -last_resources -) +bind_group_layouts +{ +self . -render_pipes +suspected_resources . -push +insert ( -res +bgl . -raw +as_info +( +) +. +id +( +) +bgl +. +clone +( +) ) ; } } +) +; +self } -} -if -! +fn +triage_suspected_bind_group_layouts +( +& +mut self -. -suspected_resources -. -pipeline_layouts -. -is_empty +# +[ +cfg ( +feature += +" +trace +" ) -{ -let -( +] +trace +: +& mut -guard -_ -) -= -hub -. -pipeline_layouts -. -write -( -token +Option +< +& +mut +trace +: +: +Trace +> ) -; -for -Stored +- +> +& +mut +Self { -value -: -id -ref_count -} -in self . suspected_resources . -pipeline_layouts -. -drain +map_mut +: +: +< +BindGroupLayoutId +BindGroupLayout +< +A +> +> ( -. -. ) +. +retain +( +| +bind_group_layout_id +bind_group_layout +| { / / @@ -6274,36 +5955,49 @@ suspected pipelines are destroyed -if -ref_count -. -load -( -) -= -= -1 -{ -log -: +/ +/ +Note : -debug -! -( -" -Pipeline -layout -{ +nothing +else +can +bump +the +refcount +since +the +guard +is +locked +exclusively +/ +/ +Note : -? -} -will -be -destroyed -" -id -) -; +same +BGL +can +appear +multiple +times +in +the +list +but +only +the +last +/ +/ +encounter +could +drop +the +refcount +to +0 +. # [ cfg @@ -6319,17 +6013,16 @@ if let Some ( +ref +mut t ) = +* trace { t . -lock -( -) -. add ( trace @@ -6338,264 +6031,676 @@ trace Action : : -DestroyPipelineLayout +DestroyBindGroupLayout +( +* +bind_group_layout_id +) +) +; +} +self +. +free_resources +. +insert +( +* +bind_group_layout_id +bind_group_layout +. +clone +( +) +) +; +false +} +) +; +self +} +fn +triage_suspected_query_sets +( +& +mut +self +hub +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> +) +- +> +& +mut +Self +{ +let +mut +trackers += +trackers +. +lock +( +) +; +let +resource_map += +self +. +suspected_resources +. +map_mut +( +) +; +Self +: +: +triage_resources ( -id +resource_map +self . -0 -) -) -; -} -if -let -Some +active +. +as_mut_slice ( -lay ) -= -hub +& +mut +self . -pipeline_layouts +free_resources +& +mut +trackers . -unregister_locked -( -id +query_sets +& +hub . +query_sets +| +_submit_index +_active +_id +| 0 +| +_query_set_id +_query_set +| +{ +} +) +; +self +} +fn +triage_suspected_staging_buffers +( & mut -* -guard +self ) +- +> +& +mut +Self { self . suspected_resources . -bind_group_layouts -. -extend_from_slice +map_mut +: +: +< +StagingBufferId +StagingBuffer +< +A +> +> ( -& -lay -. -bind_group_layout_ids ) -; +. +retain +( +| +staging_buffer_id +staging_buffer +| +{ self . free_resources . -pipeline_layouts -. -push +insert ( -lay +* +staging_buffer_id +staging_buffer . -raw +clone +( +) ) ; +false } +) +; +self } -} -} -if -! +/ +/ +/ +Identify +resources +to +free +according +to +trackers +and self . suspected_resources . -bind_group_layouts -. -is_empty -( -) -{ -let -( -mut -guard -_ -) -= +/ +/ +/ +/ +/ +/ +Given +trackers +the +[ +Tracker +] +belonging +to +same +[ +Device +] +as +/ +/ +/ +self +and hub +the +[ +Hub +] +to +which +that +Device +belongs +: +/ +/ +/ +/ +/ +/ +Remove +from +trackers +each +resource +mentioned +in +/ +/ +/ +[ +self . -bind_group_layouts +suspected_resources +] . -write -( -token -) -; -for -id +If +trackers +held +the +final +reference +to +/ +/ +/ +that +resource +add +it +to +the +appropriate +free +list +to +be +destroyed +by +/ +/ +/ +the +hal +: +/ +/ +/ +/ +/ +/ +- +Add +resources +used +by +queue +submissions +still +in +flight +to +the +/ +/ +/ +[ +last_resources +] +table +of +the +last +such +submission +' +s +entry in +/ +/ +/ +[ self . -suspected_resources +active +] . -bind_group_layouts +When +that +submission +has +finished +execution +. +the +/ +/ +/ +[ +triage_submissions +] +method +will +move +them +to +/ +/ +/ +[ +self . -drain -( +free_resources +] . +/ +/ +/ +/ +/ +/ +- +Add +resources +that +can +be +freed +right +now +to +[ +self . -) -{ +free_resources +] / / -Note +/ +directly +. +[ +LifetimeTracker : +: +cleanup +] +will +take +care +of +them +as +/ +/ +/ +part +of this -has +poll +. +/ +/ +/ +/ +/ +/ +# +# +Entrained +resources +/ +/ +/ +/ +/ +/ +This +function +finds +resources +that +are +used +only +by +other +resources +/ +/ +/ +ready +to +be +freed +and +adds +those to -happen -after -all the -suspected -pipelines -are -destroyed +free +lists +as +well +. +For / / -Note -: -nothing -else +/ +example +if +there +' +s +some +texture +T +used +only +by +some +texture +view +/ +/ +/ +TV +then +if +TV can -bump -the -refcount -since +be +freed +T +gets +added +to the -guard -is -locked -exclusively +free +lists +too +. / / -Note -: -same -BGL +/ +/ +/ +/ +Since +wgpu +- +core +resource +ownership +patterns +are +acyclic +we can -appear -multiple -times -in -the -list -but -only -the -last +visit / / -encounter +/ +each +type +that +can +be +owned +after +all +types +that could -drop -the -refcount -to -0 +possibly +own +/ +/ +/ +it . -let -mut -bgl_to_check -= -Some -( -id -) -; -while -let -Some +This +way +we +can +detect +all +free +- +able +objects +in +a +single +pass +/ +/ +/ +simply +by +starting +with +types +that +are +roots +of +the +ownership +DAG ( -id +like +/ +/ +/ +render +bundles ) -= -bgl_to_check -. -take +and +working +our +way +towards +leaf +types ( +like +buffers ) -{ -let -bgl -= -& -guard +. +/ +/ +/ +/ +/ +/ [ -id +Device ] -; -if -bgl -. -multi_ref_count +: +super +: +: +Device +/ +/ +/ +[ +self . -dec_and_check_empty -( -) -{ +suspected_resources +] +: +LifetimeTracker +: +: +suspected_resources / / -If -This -layout -points -to -a -compatible -one -go -over -the -latter +/ +[ +last_resources +] +: +ActiveSubmission +: +: +last_resources / / -to -decrement -the -ref -count -and -potentially -destroy -it +/ +[ +self . -bgl_to_check -= -bgl +active +] +: +LifetimeTracker +: +: +active +/ +/ +/ +[ +triage_submissions +] +: +LifetimeTracker +: +: +triage_submissions +/ +/ +/ +[ +self . -as_duplicate -( -) -; -log +free_resources +] : +LifetimeTracker : -debug -! -( -" -Bind -group -layout -{ : -? -} -will -be -destroyed -" -id +free_resources +pub +( +crate ) -; +fn +triage_suspected +( +& +mut +self +hub +: +& +Hub +< +A +> +trackers +: +& +Mutex +< +Tracker +< +A +> +> # [ cfg @@ -6607,177 +6712,140 @@ trace " ) ] -if -let -Some -( -t -) -= +mut trace -{ -t -. -lock -( -) -. -add -( +: +Option +< +& +mut trace : : -Action +Trace +> +) +{ +profiling : : -DestroyBindGroupLayout +scope +! ( -id -. -0 -) +" +triage_suspected +" ) ; -} -if -let -Some -( -lay -) -= -hub -. -bind_group_layouts +/ +/ +NOTE +: +the +order +is +important +to +release +resources +that +depends +between +each +other +! +self . -unregister_locked +triage_suspected_render_bundles ( -id -. -0 -& -mut -* -guard -) -{ -if -let -Some +hub +trackers +# +[ +cfg ( -inner -) +feature = -lay -. -into_inner -( +" +trace +" ) -{ -self -. -free_resources -. -bind_group_layouts -. -push -( -inner -. -raw +] +& +mut +trace ) ; -} -} -} -} -} -} -if -! self . -suspected_resources -. -query_sets -. -is_empty +triage_suspected_compute_pipelines +( +hub +trackers +# +[ +cfg ( +feature += +" +trace +" ) -{ -let -( +] +& mut -guard -_ +trace ) -= -hub -. -query_sets +; +self . -write +triage_suspected_render_pipelines ( -token -) -; -let -mut -trackers -= +hub trackers -. -lock +# +[ +cfg ( +feature += +" +trace +" +) +] +& +mut +trace ) ; -for -id -in self . -suspected_resources -. -query_sets -. -drain +triage_suspected_bind_groups ( -. -. -) -{ -if +hub trackers -. -query_sets -. -remove_abandoned -( -id -) -{ -log -: -: -debug -! +# +[ +cfg ( +feature += " -Query -set -{ -: -? -} -will -be -destroyed +trace " -id +) +] +& +mut +trace ) ; -/ -/ +self +. +triage_suspected_pipeline_layouts +( # [ cfg @@ -6789,122 +6857,133 @@ trace " ) ] -/ -/ +& +mut trace -. -map -( -| -t -| -t -. -lock -( ) +; +self . -add +triage_suspected_bind_group_layouts ( -trace -: -: -Action -: -: -DestroyComputePipeline +# +[ +cfg ( -id -. -0 -) +feature += +" +trace +" ) +] +& +mut +trace ) ; -if -let -Some +self +. +triage_suspected_query_sets ( -res -) -= hub +trackers +) +; +self . -query_sets -. -unregister_locked +triage_suspected_samplers ( -id -. -0 +hub +trackers +# +[ +cfg +( +feature += +" +trace +" +) +] & mut -* -guard +trace ) -{ -let -submit_index -= -res -. -life_guard +; +self . -life_count +triage_suspected_staging_buffers ( ) ; self . -active -. -iter_mut +triage_suspected_texture_views ( -) -. -find +hub +trackers +# +[ +cfg ( -| -a -| -a -. -index -= +feature = -submit_index +" +trace +" ) -. -map_or -( +] & mut +trace +) +; self . -free_resources -| -a -| +triage_suspected_textures +( +hub +trackers +# +[ +cfg +( +feature += +" +trace +" +) +] & mut -a -. -last_resources +trace ) +; +self . -query_sets -. -push +triage_suspected_buffers ( -res -. -raw +hub +trackers +# +[ +cfg +( +feature += +" +trace +" ) -; -} -} -} -} +] +& +mut +trace +) +; } / / @@ -6945,41 +7024,14 @@ details . pub ( -super +crate ) fn triage_mapped -< -G -: -GlobalIdentityHandlerFactory -> ( & mut self -hub -: -& -Hub -< -A -G -> -token -: -& -mut -Token -< -super -: -: -Device -< -A -> -> ) { if @@ -6994,23 +7046,8 @@ is_empty return ; } -let -( -buffer_guard -_ -) -= -hub -. -buffers -. -read -( -token -) -; for -stored +buffer in self . @@ -7023,49 +7060,13 @@ drain ) { let -resource_id -= -stored -. -value -; -/ -/ -The -buffer -may -have -been -destroyed -since -the -map -request -. -if -let -Ok -( -buf -) -= -buffer_guard -. -get -( -resource_id -. -0 -) -{ -let submit_index = -buf +buffer . -life_guard +info . -life_count +submission_index ( ) ; @@ -7097,7 +7098,13 @@ active ? } " -resource_id +buffer +. +info +. +id +( +) submit_index self . @@ -7161,12 +7168,11 @@ mapped . push ( -resource_id +buffer ) ; } } -} / / / @@ -7215,15 +7221,10 @@ must_use ] pub ( -super +crate ) fn handle_mapping -< -G -: -GlobalIdentityHandlerFactory -> ( & mut @@ -7234,7 +7235,6 @@ hub Hub < A -G > raw : @@ -7253,20 +7253,6 @@ Tracker A > > -token -: -& -mut -Token -< -super -: -: -Device -< -A -> -> ) - > @@ -7297,22 +7283,6 @@ new ; } let -( -mut -buffer_guard -_ -) -= -hub -. -buffers -. -write -( -token -) -; -let mut pending_callbacks : @@ -7338,18 +7308,8 @@ len ) ) ; -let -mut -trackers -= -trackers -. -lock -( -) -; for -buffer_id +buffer in self . @@ -7362,63 +7322,50 @@ drain ) { let -buffer -= -match -buffer_guard -. -get_occupied_or_destroyed_mut -( buffer_id -. -0 -) -{ -Ok -( -buf -) = -> -buf -Err -( +buffer . +info . +id +( ) +; +let +is_removed = -> { -/ -/ -The -buffer -may -have -been -destroyed -since -the -map -request +let +mut +trackers += +trackers . -continue +lock +( +) ; -} -} +let +mut +count += +1 ; -if -buffer -. -life_guard +count ++ += +hub . -ref_count +buffers . -is_none +contains ( +buffer_id ) -& -& +as +usize +; trackers . buffers @@ -7426,11 +7373,21 @@ buffers remove_abandoned ( buffer_id +count ) +} +; +if +is_removed { +* buffer . map_state +. +lock +( +) = resource : @@ -7443,60 +7400,41 @@ Idle log : : -debug +info ! ( " -Mapping -request -is -dropped -because -the -buffer +Buffer +ready +to +map +{ +: +? +} is -destroyed -. +not +tracked +anymore " -) -; -if -let -Some -( -buf -) -= -hub -. -buffers -. -unregister_locked -( buffer_id -. -0 -& -mut -* -buffer_guard ) -{ +; self . free_resources . -buffers -. -extend +insert ( -buf +buffer_id +buffer . -raw +clone +( +) ) ; } -} else { let @@ -7513,9 +7451,14 @@ replace ( & mut +* buffer . map_state +. +lock +( +) resource : : @@ -7590,9 +7533,14 @@ Active = > { +* buffer . map_state +. +lock +( +) = active ; @@ -7683,6 +7631,7 @@ super map_buffer ( raw +& buffer mapping . @@ -7700,9 +7649,14 @@ ptr = > { +* buffer . map_state +. +lock +( +) = resource : @@ -7771,9 +7725,14 @@ e } else { +* buffer . map_state +. +lock +( +) = resource : diff --git a/third_party/rust/wgpu-core/src/device/mod.rs b/third_party/rust/wgpu-core/src/device/mod.rs index 97a4a18129a5a..30a6ba4770176 100644 --- a/third_party/rust/wgpu-core/src/device/mod.rs +++ b/third_party/rust/wgpu-core/src/device/mod.rs @@ -13,6 +13,11 @@ hub : Hub id +: +: +{ +self +} identity : : @@ -101,6 +106,10 @@ ptr ; pub mod +any_device +; +pub +mod global ; mod @@ -1299,6 +1308,7 @@ callback . for ( +mut operation status ) @@ -1307,16 +1317,30 @@ self . mappings { +if +let +Some +( +callback +) += operation . callback . +take +( +) +{ +callback +. call ( status ) ; } +} for closure in @@ -1878,10 +1902,7 @@ map_buffer < A : -hal -: -: -Api +HalApi > ( raw @@ -1894,7 +1915,6 @@ Device buffer : & -mut Buffer < A @@ -1935,12 +1955,6 @@ map_buffer buffer . raw -. -as_ref -( -) -. -unwrap ( ) offset @@ -1961,9 +1975,14 @@ from ? } ; +* buffer . sync_mapped_writes +. +lock +( +) = match kind @@ -1988,12 +2007,6 @@ invalidate_mapped_ranges buffer . raw -. -as_ref -( -) -. -unwrap ( ) iter @@ -2258,6 +2271,10 @@ buffer . sync_mapped_writes . +lock +( +) +. is_none ( ) @@ -2295,6 +2312,10 @@ buffer . initialization_status . +write +( +) +. drain ( offset @@ -2379,12 +2400,6 @@ flush_mapped_ranges buffer . raw -. -as_ref -( -) -. -unwrap ( ) iter @@ -2406,15 +2421,16 @@ mapping ptr ) } +pub +( +crate +) struct CommandAllocator < A : -hal -: -: -Api +HalApi > { free_encoders @@ -2431,10 +2447,7 @@ impl < A : -hal -: -: -Api +HalApi > CommandAllocator < @@ -2636,6 +2649,10 @@ Debug Error ) ] +# +[ +non_exhaustive +] pub enum DeviceError @@ -2710,6 +2727,18 @@ ResourceCreationFailed error ( " +QueueId +is +invalid +" +) +] +InvalidQueueId +# +[ +error +( +" Attempt to use @@ -3030,7 +3059,6 @@ hub Hub < A -G > ) - @@ -3046,6 +3074,11 @@ hub pipeline_layouts . prepare +: +: +< +G +> ( self . @@ -3075,12 +3108,14 @@ hub bind_group_layouts . prepare +: +: +< +G +> ( +* id_in -. -clone -( -) ) . into_id diff --git a/third_party/rust/wgpu-core/src/device/queue.rs b/third_party/rust/wgpu-core/src/device/queue.rs index 7cc3878720353..21c3a8b7f187c 100644 --- a/third_party/rust/wgpu-core/src/device/queue.rs +++ b/third_party/rust/wgpu-core/src/device/queue.rs @@ -44,6 +44,10 @@ device : : { +life +: +: +ResourceMaps DeviceError WaitIdleError } @@ -57,11 +61,13 @@ hal_api : HalApi hal_label -hub +id : : -Token -id +{ +self +QueueId +} identity : : @@ -80,13 +86,18 @@ resource : : { +Buffer BufferAccessError BufferMapState +Resource +ResourceInfo +ResourceType StagingBuffer +Texture TextureInner } track -FastHashSet +FastHashMap SubmissionIndex } ; @@ -113,12 +124,6 @@ parking_lot Mutex ; use -smallvec -: -: -SmallVec -; -use std : : @@ -126,6 +131,16 @@ std iter mem ptr +sync +: +: +{ +atomic +: +: +Ordering +Arc +} } ; use @@ -134,6 +149,174 @@ thiserror : Error ; +use +super +: +: +Device +; +pub +struct +Queue +< +A +: +HalApi +> +{ +pub +device +: +Option +< +Arc +< +Device +< +A +> +> +> +pub +raw +: +Option +< +A +: +: +Queue +> +pub +info +: +ResourceInfo +< +QueueId +> +} +impl +< +A +: +HalApi +> +Resource +< +QueueId +> +for +Queue +< +A +> +{ +const +TYPE +: +ResourceType += +" +Queue +" +; +fn +as_info +( +& +self +) +- +> +& +ResourceInfo +< +QueueId +> +{ +& +self +. +info +} +fn +as_info_mut +( +& +mut +self +) +- +> +& +mut +ResourceInfo +< +QueueId +> +{ +& +mut +self +. +info +} +} +impl +< +A +: +HalApi +> +Drop +for +Queue +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +let +queue += +self +. +raw +. +take +( +) +. +unwrap +( +) +; +self +. +device +. +as_ref +( +) +. +unwrap +( +) +. +release_queue +( +queue +) +; +} +} / / / @@ -659,9 +842,6 @@ WrappedSubmissionIndex pub queue_id : -id -: -: QueueId pub index @@ -812,35 +992,37 @@ TempResource < A : -hal -: -: -Api +HalApi > { Buffer ( -A -: -: +Arc +< Buffer +< +A +> +> ) -Texture +StagingBuffer ( +Arc +< +StagingBuffer +< A -: -: +> +> +) +Texture +( +Arc +< Texture -SmallVec < -[ A -: -: -TextureView -; -1 -] +> > ) } @@ -858,17 +1040,14 @@ encoder . pub ( -super +crate ) struct EncoderInFlight < A : -hal -: -: -Api +HalApi > { raw @@ -891,10 +1070,7 @@ impl < A : -hal -: -: -Api +HalApi > EncoderInFlight < @@ -903,7 +1079,7 @@ A { pub ( -super +crate ) unsafe fn @@ -1093,6 +1269,40 @@ commands / / / +Important +: +/ +/ +/ +When +locking +pending_writes +be +sure +that +tracker +is +not +locked +/ +/ +/ +and +try +to +lock +trackers +for +the +minimum +timespan +possible +/ +/ +/ +/ +/ +/ All uses of @@ -1120,10 +1330,7 @@ PendingWrites < A : -hal -: -: -Api +HalApi > { pub @@ -1150,22 +1357,36 @@ A pub dst_buffers : -FastHashSet +FastHashMap < id : : BufferId +Arc +< +Buffer +< +A +> +> > pub dst_textures : -FastHashSet +FastHashMap < id : : TextureId +Arc +< +Texture +< +A +> +> > pub executing_command_buffers @@ -1182,10 +1403,7 @@ impl < A : -hal -: -: -Api +HalApi > PendingWrites < @@ -1223,7 +1441,7 @@ new ) dst_buffers : -FastHashSet +FastHashMap : : default @@ -1231,7 +1449,7 @@ default ) dst_textures : -FastHashSet +FastHashMap : : default @@ -1303,75 +1521,15 @@ command_encoder ) ; } -for -resource -in self . temp_resources -{ -match -resource -{ -TempResource -: -: -Buffer -( -buffer -) -= -> -unsafe -{ -device -. -destroy_buffer -( -buffer -) -; -} -TempResource -: -: -Texture -( -texture -views -) -= -> -unsafe -{ -for -view -in -views -. -into_iter -( -) -{ -device . -destroy_texture_view -( -view -) -; -} -device -. -destroy_texture +clear ( -texture ) ; } -} -} -} pub fn consume_temp @@ -1405,10 +1563,13 @@ mut self buffer : +Arc +< StagingBuffer < A > +> ) { self @@ -1420,11 +1581,9 @@ push TempResource : : -Buffer +StagingBuffer ( buffer -. -raw ) ) ; @@ -1531,8 +1690,7 @@ self command_allocator : & -Mutex -< +mut super : : @@ -1540,7 +1698,6 @@ CommandAllocator < A > -> device : & @@ -1583,10 +1740,6 @@ new_encoder = command_allocator . -lock -( -) -. acquire_encoder ( device @@ -1742,11 +1895,13 @@ HalApi device : & -mut -A -: -: +Arc +< Device +< +A +> +> size : wgt @@ -1847,6 +2002,10 @@ unsafe { device . +raw +( +) +. create_buffer ( & @@ -1862,6 +2021,10 @@ unsafe { device . +raw +( +) +. map_buffer ( & @@ -1881,8 +2044,37 @@ StagingBuffer { raw : +Mutex +: +: +new +( +Some +( buffer +) +) +device +: +device +. +clone +( +) size +info +: +ResourceInfo +: +: +new +( +" +< +StagingBuffer +> +" +) is_coherent : mapping @@ -1908,10 +2100,7 @@ impl < A : -hal -: -: -Api +HalApi > StagingBuffer < @@ -1953,10 +2142,21 @@ device . flush_mapped_ranges ( -& self . raw +. +lock +( +) +. +as_ref +( +) +. +unwrap +( +) iter : : @@ -1979,10 +2179,21 @@ device . unmap_buffer ( -& self . raw +. +lock +( +) +. +as_ref +( +) +. +unwrap +( +) ) ? } @@ -2285,9 +2496,6 @@ HalApi self queue_id : -id -: -: QueueId buffer_id : @@ -2343,41 +2551,13 @@ self ) ; let -root_token -= -& -mut -Token -: -: -root -( -) -; -let -( -mut -device_guard -ref -mut -device_token -) +queue = hub . -devices -. -write -( -root_token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -2390,11 +2570,26 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; let +device += +queue +. +device +. +as_ref +( +) +. +unwrap +( +) +; +let data_size = data @@ -2424,23 +2619,19 @@ let Some ( ref +mut trace ) = +* device . trace -{ -let -mut -trace -= -trace . lock ( ) -; +{ let data_path = @@ -2555,11 +2746,7 @@ staging_buffer_ptr = prepare_staging_buffer ( -& -mut device -. -raw data_size device . @@ -2567,40 +2754,86 @@ instance_flags ) ? ; -if let -Err -( -flush_error -) +mut +pending_writes = -unsafe -{ -profiling -: -: -scope -! +device +. +pending_writes +. +lock ( -" -copy -" ) ; -ptr -: -: -copy_nonoverlapping -( -data +let +pending_writes += +pending_writes . -as_ptr +as_mut ( ) -staging_buffer_ptr -data . -len +unwrap +( +) +; +let +stage_fid += +hub +. +staging_buffers +. +request +( +) +; +let +staging_buffer += +stage_fid +. +init +( +staging_buffer +) +; +if +let +Err +( +flush_error +) += +unsafe +{ +profiling +: +: +scope +! +( +" +copy +" +) +; +ptr +: +: +copy_nonoverlapping +( +data +. +as_ptr +( +) +staging_buffer_ptr +data +. +len ( ) ) @@ -2609,15 +2842,14 @@ staging_buffer . flush ( -& device . raw +( +) ) } { -device -. pending_writes . consume @@ -2643,17 +2875,14 @@ self . queue_write_staging_buffer_impl ( -queue_id device -device_token +pending_writes & staging_buffer buffer_id buffer_offset ) ; -device -. pending_writes . consume @@ -2676,9 +2905,6 @@ HalApi self queue_id : -id -: -: QueueId buffer_size : @@ -2739,41 +2965,13 @@ self ) ; let -root_token -= -& -mut -Token -: -: -root -( -) -; -let -( -mut -device_guard -ref -mut -device_token -) +queue = hub . -devices -. -write -( -root_token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -2786,11 +2984,26 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; let +device += +queue +. +device +. +as_ref +( +) +. +unwrap +( +) +; +let ( staging_buffer staging_buffer_ptr @@ -2798,11 +3011,7 @@ staging_buffer_ptr = prepare_staging_buffer ( -& -mut device -. -raw buffer_size . get @@ -2822,27 +3031,49 @@ hub staging_buffers . prepare +: +: +< +G +> ( id_in ) ; let +( id +_ +) = fid . assign ( staging_buffer -device_token +) +; +log +: +: +info +! +( +" +Created +StagingBuffer +{ +: +? +} +" +id ) ; Ok ( ( id -. -0 staging_buffer_ptr ) ) @@ -2860,9 +3091,6 @@ HalApi self queue_id : -id -: -: QueueId buffer_id : @@ -2918,41 +3146,13 @@ self ) ; let -root_token -= -& -mut -Token -: -: -root -( -) -; -let -( -mut -device_guard -ref -mut -device_token -) +queue = hub . -devices -. -write -( -root_token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -2965,11 +3165,26 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; let +device += +queue +. +device +. +as_ref +( +) +. +unwrap +( +) +; +let staging_buffer = hub @@ -2979,12 +3194,22 @@ staging_buffers unregister ( staging_buffer_id -device_token ) +; +if +staging_buffer . -0 -. -ok_or +is_none +( +) +{ +return +Err +( +QueueWriteError +: +: +Transfer ( TransferError : @@ -2994,7 +3219,42 @@ InvalidBuffer buffer_id ) ) -? +) +; +} +let +staging_buffer += +staging_buffer +. +unwrap +( +) +; +let +mut +pending_writes += +device +. +pending_writes +. +lock +( +) +; +let +pending_writes += +pending_writes +. +as_mut +( +) +. +unwrap +( +) ; / / @@ -3059,15 +3319,14 @@ staging_buffer . flush ( -& device . raw +( +) ) } { -device -. pending_writes . consume @@ -3093,17 +3352,14 @@ self . queue_write_staging_buffer_impl ( -queue_id device -device_token +pending_writes & staging_buffer buffer_id buffer_offset ) ; -device -. pending_writes . consume @@ -3126,9 +3382,6 @@ HalApi self _queue_id : -id -: -: QueueId buffer_id : @@ -3178,59 +3431,18 @@ self ) ; let -root_token +buffer = -& -mut -Token -: -: -root +hub +. +buffers +. +get ( +buffer_id ) -; -let -( -_ -ref -mut -device_token -) -= -hub -. -devices -. -read -( -root_token -) -; -let -buffer_guard -= -hub -. -buffers -. -read -( -device_token -) -. -0 -; -let -buffer -= -buffer_guard -. -get -( -buffer_id -) -. -map_err +. +map_err ( | _ @@ -3249,6 +3461,7 @@ self . queue_validate_write_buffer_impl ( +& buffer buffer_id buffer_offset @@ -3275,12 +3488,6 @@ self buffer : & -crate -: -: -resource -: -: Buffer < A @@ -3445,37 +3652,21 @@ HalApi ( & self -device_id -: -id -: -: -DeviceId device : & -mut -super -: -: Device < A > -device_token +pending_writes : & mut -Token -< -super -: -: -Device +PendingWrites < A > -> staging_buffer : & @@ -3514,6 +3705,13 @@ self ) ; let +( +dst +transition +) += +{ +let buffer_guard = hub @@ -3522,10 +3720,32 @@ buffers . read ( -device_token +) +; +let +dst += +buffer_guard +. +get +( +buffer_id ) . -0 +map_err +( +| +_ +| +TransferError +: +: +InvalidBuffer +( +buffer_id +) +) +? ; let mut @@ -3539,21 +3759,13 @@ lock ( ) ; -let -( -dst -transition -) -= trackers . buffers . set_single ( -& -buffer_guard -buffer_id +dst hal : : @@ -3574,6 +3786,7 @@ buffer_id ) ) ? +} ; let dst_raw @@ -3601,14 +3814,26 @@ buffer_id if dst . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -device_id +device +. +as_info +( +) +. +id +( +) { return Err @@ -3635,6 +3860,7 @@ self . queue_validate_write_buffer_impl ( +& dst buffer_id buffer_offset @@ -3644,13 +3870,21 @@ src_buffer_size ; dst . -life_guard +info . use_at ( device . active_submission_index +. +load +( +Ordering +: +: +Relaxed +) + 1 ) @@ -3690,6 +3924,17 @@ size ) ; let +inner_buffer += +staging_buffer +. +raw +. +lock +( +) +; +let barriers = iter @@ -3704,10 +3949,15 @@ BufferBarrier { buffer : -& -staging_buffer +inner_buffer . -raw +as_ref +( +) +. +unwrap +( +) usage : hal @@ -3742,6 +3992,7 @@ pending . into_hal ( +& dst ) ) @@ -3750,8 +4001,6 @@ dst let encoder = -device -. pending_writes . activate @@ -3771,10 +4020,15 @@ encoder . copy_buffer_to_buffer ( -& -staging_buffer +inner_buffer . -raw +as_ref +( +) +. +unwrap +( +) dst_raw region . @@ -3784,8 +4038,22 @@ into_iter ) ; } -device +let +dst += +hub +. +buffers +. +get +( +buffer_id +) . +unwrap +( +) +; pending_writes . dst_buffers @@ -3793,6 +4061,11 @@ dst_buffers insert ( buffer_id +dst +. +clone +( +) ) ; / @@ -3823,43 +4096,13 @@ or binding . { -drop -( -buffer_guard -) -; -let -mut -buffer_guard -= -hub -. -buffers -. -write -( -device_token -) -. -0 -; -let dst -= -buffer_guard . -get_mut -( -buffer_id -) +initialization_status . -unwrap +write ( ) -; -dst -. -initialization_status . drain ( @@ -3893,9 +4136,6 @@ HalApi self queue_id : -id -: -: QueueId destination : @@ -3957,41 +4197,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) +queue = hub . -devices -. -write -( -& -mut -token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -4004,10 +4216,25 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; +let +device += +queue +. +device +. +as_ref +( +) +. +unwrap +( +) +; # [ cfg @@ -4024,23 +4251,19 @@ let Some ( ref +mut trace ) = +* device . trace -{ -let -mut -trace -= -trace . lock ( ) -; +{ let data_path = @@ -4130,50 +4353,13 @@ Ok ; } let -( -mut -texture_guard -_ -) +dst = hub . textures . -write -( -& -mut -token -) -; -/ -/ -For -clear -we -need -write -access -to -the -texture -. -TODO -: -Can -we -acquire -write -lock -later -? -let -dst -= -texture_guard -. -get_mut +get ( destination . @@ -4200,11 +4386,15 @@ texture if dst . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = queue_id @@ -4328,6 +4518,7 @@ extract_texture_selector ( destination size +& dst ) ? @@ -4661,21 +4852,32 @@ u64 ; let mut -trackers +pending_writes = device . -trackers +pending_writes . lock ( ) ; let -encoder +pending_writes = -device +pending_writes +. +as_mut +( +) . +unwrap +( +) +; +let +encoder += pending_writes . activate @@ -4805,11 +5007,21 @@ size depth_or_array_layers } ; -if +let +mut +dst_initialization_status += dst . initialization_status . +write +( +) +; +if +dst_initialization_status +. mips [ destination @@ -4848,9 +5060,7 @@ desc for layer_range in -dst -. -initialization_status +dst_initialization_status . mips [ @@ -4887,6 +5097,18 @@ u32 ( ) { +let +mut +trackers += +device +. +trackers +. +lock +( +) +; crate : : @@ -4896,17 +5118,7 @@ command clear_texture ( & -* -texture_guard -id -: -: -Valid -( -destination -. -texture -) +dst TextureInitRange { mip_range @@ -4935,10 +5147,17 @@ textures device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) . map_err @@ -4954,9 +5173,7 @@ from } else { -dst -. -initialization_status +dst_initialization_status . mips [ @@ -4993,7 +5210,7 @@ the / texture_guard . -get_mut +get above ends in @@ -5038,7 +5255,9 @@ unwrap let dst = -texture_guard +hub +. +textures . get ( @@ -5051,62 +5270,48 @@ unwrap ( ) ; -let -transition -= -trackers +dst . -textures +info . -set_single +use_at ( -dst -destination +device . -texture -selector -hal -: -: -TextureUses -: -: -COPY_DST -) +active_submission_index . -ok_or +load ( -TransferError +Ordering : : -InvalidTexture -( -destination -. -texture +Relaxed ) ++ +1 ) -? ; +let +dst_inner += dst . -life_guard -. -use_at +inner ( -device -. -active_submission_index -+ -1 ) ; let dst_raw = -dst +dst_inner . -inner +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -5182,11 +5387,7 @@ staging_buffer_ptr = prepare_staging_buffer ( -& -mut device -. -raw stage_size device . @@ -5194,6 +5395,27 @@ instance_flags ) ? ; +let +stage_fid += +hub +. +staging_buffers +. +request +( +) +; +let +staging_buffer += +stage_fid +. +init +( +staging_buffer +) +; if stage_bytes_per_row = @@ -5385,15 +5607,14 @@ staging_buffer . flush ( -& device . raw +( +) ) } { -device -. pending_writes . consume @@ -5491,6 +5712,18 @@ hal_copy_size } ) ; +{ +let +inner_buffer += +staging_buffer +. +raw +. +lock +( +) +; let barrier = @@ -5501,10 +5734,15 @@ BufferBarrier { buffer : -& -staging_buffer +inner_buffer . -raw +as_ref +( +) +. +unwrap +( +) usage : hal @@ -5525,27 +5763,82 @@ BufferUses COPY_SRC } ; -unsafe -{ -encoder +let +mut +trackers += +device . -transition_textures +trackers +. +lock ( +) +; +let transition += +trackers . -map -( -| -pending -| -pending +textures . -into_hal +set_single ( +& dst +selector +hal +: +: +TextureUses +: +: +COPY_DST +) +. +ok_or +( +TransferError +: +: +InvalidTexture +( +destination +. +texture +) +) +? +; +unsafe +{ +encoder +. +transition_textures +( +transition +. +map +( +| +pending +| +pending +. +into_hal +( +dst_inner +. +as_ref +( +) +. +unwrap +( +) +) +) ) -) -) ; encoder . @@ -5564,17 +5857,21 @@ encoder . copy_buffer_to_texture ( -& -staging_buffer +inner_buffer . -raw +as_ref +( +) +. +unwrap +( +) dst_raw regions ) ; } -device -. +} pending_writes . consume @@ -5582,8 +5879,6 @@ consume staging_buffer ) ; -device -. pending_writes . dst_textures @@ -5593,6 +5888,11 @@ insert destination . texture +dst +. +clone +( +) ) ; Ok @@ -5636,9 +5936,6 @@ HalApi self queue_id : -id -: -: QueueId source : @@ -5698,41 +5995,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) +queue = hub . -devices -. -write -( -& -mut -token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -5745,10 +6014,25 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; +let +device += +queue +. +device +. +as_ref +( +) +. +unwrap +( +) +; if size . @@ -5954,50 +6238,13 @@ height ) ; let -( -mut -texture_guard -_ -) +dst = hub . textures . -write -( -& -mut -token -) -; -/ -/ -For -clear -we -need -write -access -to -the -texture -. -TODO -: -Can -we -acquire -write -lock -later -? -let -dst -= -texture_guard -. -get_mut +get ( destination . @@ -6455,17 +6702,18 @@ to_untagged ) & size +& dst ) ? ; let mut -trackers +pending_writes = device . -trackers +pending_writes . lock ( @@ -6474,10 +6722,16 @@ lock let encoder = -device -. pending_writes . +as_mut +( +) +. +unwrap +( +) +. activate ( ) @@ -6605,11 +6859,21 @@ size depth_or_array_layers } ; -if +let +mut +dst_initialization_status += dst . initialization_status . +write +( +) +; +if +dst_initialization_status +. mips [ destination @@ -6649,9 +6913,7 @@ desc for layer_range in -dst -. -initialization_status +dst_initialization_status . mips [ @@ -6688,6 +6950,18 @@ u32 ( ) { +let +mut +trackers += +device +. +trackers +. +lock +( +) +; crate : : @@ -6697,17 +6971,7 @@ command clear_texture ( & -* -texture_guard -id -: -: -Valid -( -destination -. -texture -) +dst TextureInitRange { mip_range @@ -6736,10 +7000,17 @@ textures device . alignments -& device . zero_buffer +. +as_ref +( +) +. +unwrap +( +) ) . map_err @@ -6755,9 +7026,7 @@ from } else { -dst -. -initialization_status +dst_initialization_status . mips [ @@ -6775,81 +7044,51 @@ init_layer_range ; } } -let dst -= -texture_guard . -get +info +. +use_at ( -destination +device . -texture +active_submission_index +. +load +( +Ordering +: +: +Relaxed +) ++ +1 ) +; +let +dst_inner += +dst . -unwrap +inner ( ) ; let -transitions +dst_raw = -trackers +dst_inner . -textures +as_ref +( +) . -set_single +unwrap ( -dst -destination +) . -texture -selector -hal -: -: -TextureUses -: -: -COPY_DST -) -. -ok_or -( -TransferError -: -: -InvalidTexture -( -destination -. -texture -) -) -? -; -dst -. -life_guard -. -use_at -( -device -. -active_submission_index -+ -1 -) -; -let -dst_raw -= -dst -. -inner -. -as_raw -( +as_raw +( ) . ok_or @@ -6915,6 +7154,53 @@ hal_copy_size ; unsafe { +let +mut +trackers += +device +. +trackers +. +lock +( +) +; +let +transitions += +trackers +. +textures +. +set_single +( +& +dst +selector +hal +: +: +TextureUses +: +: +COPY_DST +) +. +ok_or +( +TransferError +: +: +InvalidTexture +( +destination +. +texture +) +) +? +; encoder . transition_textures @@ -6930,7 +7216,15 @@ pending . into_hal ( -dst +dst_inner +. +as_ref +( +) +. +unwrap +( +) ) ) ) @@ -6973,9 +7267,6 @@ HalApi self queue_id : -id -: -: QueueId command_buffer_ids : @@ -7047,41 +7338,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -device_guard -mut -token -) +queue = hub . -devices -. -write -( -& -mut -token -) -; -let -device -= -device_guard +queues . -get_mut +get ( queue_id ) @@ -7094,24 +7357,49 @@ _ DeviceError : : -Invalid +InvalidQueueId ) ? ; +let device += +queue . -temp_suspected +device . -clear +as_ref +( +) +. +unwrap ( ) ; +let +mut +fence += device . -active_submission_index -+ +fence +. +write +( +) +; +let +fence = -1 +fence +. +as_mut +( +) +. +unwrap +( +) ; let submit_index @@ -7119,6 +7407,17 @@ submit_index device . active_submission_index +. +fetch_add +( +1 +Ordering +: +: +Relaxed +) ++ +1 ; let mut @@ -7147,12 +7446,8 @@ new ; { let -( mut command_buffer_guard -mut -token -) = hub . @@ -7160,9 +7455,6 @@ command_buffers . write ( -& -mut -token ) ; if @@ -7184,255 +7476,93 @@ prepare " ) ; +/ +/ +TODO +: +if +multiple +command +buffers +are +submitted +we +can +re +- +use +the +last +/ +/ +native +command +buffer +of +the +previous +chain +instead +of +always +creating +/ +/ +a +temporary +one +since +the +chains +are +not +finished +. let -( -render_bundle_guard mut -token -) +temp_suspected = -hub +device . -render_bundles +temp_suspected . -read +lock ( -& -mut -token ) ; +{ let -( -_ mut -token -) +suspected = -hub -. -pipeline_layouts +temp_suspected . -read +replace ( -& -mut -token -) -; -let +ResourceMaps +: +: +new +: +: +< +A +> ( -bind_group_guard -mut -token ) -= -hub -. -bind_groups +) . -read +unwrap ( -& -mut -token ) ; -let -( -compute_pipe_guard -mut -token -) -= -hub +suspected . -compute_pipelines -. -read +clear ( -& -mut -token ) ; -let -( -render_pipe_guard -mut -token -) -= -hub -. -render_pipelines -. -read -( -& -mut -token -) -; -let -( -mut -buffer_guard -mut -token -) -= -hub -. -buffers -. -write -( -& -mut -token -) -; -let -( -mut -texture_guard -mut -token -) -= -hub -. -textures -. -write -( -& -mut -token -) -; -let -( -texture_view_guard -mut -token -) -= -hub -. -texture_views -. -read -( -& -mut -token -) -; -let -( -sampler_guard -mut -token -) -= -hub -. -samplers -. -read -( -& -mut -token -) -; -let -( -query_set_guard -_ -) -= -hub -. -query_sets -. -read -( -& -mut -token -) -; -/ -/ -Note -: -locking -the -trackers -has -to -be -done -after -the -storages -let -mut -trackers -= -device -. -trackers -. -lock -( -) -; -/ -/ -TODO -: -if -multiple -command -buffers -are -submitted -we -can -re -- -use -the -last -/ -/ -native -command -buffer -of -the -previous -chain -instead -of -always -creating -/ -/ -a -temporary -one -since -the -chains -are -not -finished -. +} / / finish @@ -7474,7 +7604,13 @@ used_surface_textures . set_size ( -texture_guard +hub +. +textures +. +read +( +) . len ( @@ -7541,11 +7677,15 @@ continue if cmdbuf . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = queue_id @@ -7580,18 +7720,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -7603,6 +7745,20 @@ Submit submit_index cmdbuf . +data +. +lock +( +) +. +as_mut +( +) +. +unwrap +( +) +. commands . take @@ -7624,6 +7780,21 @@ is_finished ( ) { +if +let +Ok +( +cmdbuf +) += +Arc +: +: +try_unwrap +( +cmdbuf +) +{ device . destroy_command_buffer @@ -7631,6 +7802,27 @@ destroy_command_buffer cmdbuf ) ; +} +else +{ +panic +! +( +" +Command +buffer +cannot +be +destroyed +because +is +still +in +use +" +) +; +} continue ; } @@ -7650,49 +7842,78 @@ optimize ( ) ; +{ +let +cmd_buf_data += +cmdbuf +. +data +. +lock +( +) +; +let +cmd_buf_trackers += +& +cmd_buf_data +. +as_ref +( +) +. +unwrap +( +) +. +trackers +; / / update submission IDs for -id +buffer in -cmdbuf -. -trackers +cmd_buf_trackers . buffers . -used +used_resources ( ) { let -buffer +id = -match -buffer_guard +buffer . -get -( -id +info . -0 +id +( ) +; +let +raw_buf += +match +buffer +. +raw { -Ok +Some ( -buf +ref +raw ) = > -buf -Err -( -. -. -) +raw +None = > { @@ -7705,62 +7926,26 @@ QueueSubmitError DestroyedBuffer ( id -. -0 ) ) ; } } ; -/ -/ -get -fails -if -the -buffer -is -invalid -or -destroyed -so -we -can -assume -/ -/ -the -raw buffer -is -not -None . -let -raw_buf -= -buffer -. -raw +info . -as_ref -( -) -. -unwrap +use_at ( +submit_index ) ; if -! buffer . -life_guard -. -use_at +is_unique ( -submit_index ) { if @@ -7774,9 +7959,14 @@ Active . } = +* buffer . map_state +. +lock +( +) { log : @@ -7800,6 +7990,8 @@ unsafe device . raw +( +) . unmap_buffer ( @@ -7817,24 +8009,38 @@ from ? ; } -device -. temp_suspected . -buffers +as_mut +( +) . -push +unwrap +( +) +. +insert ( id +buffer +. +clone +( +) ) ; } else { match +* buffer . map_state +. +lock +( +) { BufferMapState : @@ -7856,78 +8062,51 @@ QueueSubmitError BufferStillMapped ( id -. -0 ) ) } } } for -id +texture in -cmdbuf -. -trackers +cmd_buf_trackers . textures . -used +used_resources ( ) { let -texture -= -match -texture_guard -. -get_mut -( id -. -0 -) -{ -Ok -( -tex -) = -> -tex -Err -( +texture . +info . -) -= -> -{ -return -Err -( -QueueSubmitError -: -: -DestroyedTexture -( id -. -0 -) +( ) ; -} -} -; let should_extend = match +* texture . inner +( +) +. +as_ref +( +) +. +unwrap +( +) { TextureInner : @@ -7941,9 +8120,16 @@ None = > { -unreachable -! +return +Err ( +QueueSubmitError +: +: +DestroyedTexture +( +id +) ) ; } @@ -7968,7 +8154,6 @@ TextureInner Surface { ref -mut has_work . . @@ -7976,35 +8161,55 @@ has_work = > { -* has_work -= +. +store +( true +Ordering +: +: +Relaxed +) ; true } } ; -if -! texture . -life_guard +info . use_at ( submit_index ) -{ -device +; +if +texture . +is_unique +( +) +{ temp_suspected . -textures +as_mut +( +) . -push +unwrap +( +) +. +insert ( id +texture +. +clone +( +) ) ; } @@ -8013,30 +8218,13 @@ should_extend { unsafe { -let -ref_count -= -cmdbuf -. -trackers -. -textures -. -get_ref_count -( -id -) -; used_surface_textures . merge_single ( & -* -texture_guard -id +texture None -ref_count hal : : @@ -8055,90 +8243,83 @@ unwrap } } for -id +texture_view in -cmdbuf -. -trackers +cmd_buf_trackers . views . -used +used_resources ( ) { -if -! -texture_view_guard -[ -id -] +texture_view . -life_guard +info . use_at ( submit_index ) -{ -device +; +if +texture_view . +is_unique +( +) +{ temp_suspected . -texture_views +as_mut +( +) +. +unwrap +( +) +. +insert +( +texture_view . -push +as_info ( +) +. id +( +) +texture_view +. +clone +( +) ) ; } } +{ for -id +bg in -cmdbuf -. -trackers +cmd_buf_trackers . bind_groups . -used +used_resources ( ) { -let -bg -= -& -bind_group_guard -[ -id -] -; -if -! bg . -life_guard +info . use_at ( submit_index ) -{ -device -. -temp_suspected -. -bind_groups -. -push -( -id -) ; -} / / We @@ -8185,7 +8366,7 @@ of scope . for -sub_id +view in bg . @@ -8193,16 +8374,13 @@ used . views . -used +used_resources ( ) { -texture_view_guard -[ -sub_id -] +view . -life_guard +info . use_at ( @@ -8211,7 +8389,7 @@ submit_index ; } for -sub_id +sampler in bg . @@ -8219,16 +8397,13 @@ used . samplers . -used +used_resources ( ) { -sampler_guard -[ -sub_id -] +sampler . -life_guard +info . use_at ( @@ -8236,15 +8411,50 @@ submit_index ) ; } +if +bg +. +is_unique +( +) +{ +temp_suspected +. +as_mut +( +) +. +unwrap +( +) +. +insert +( +bg +. +as_info +( +) +. +id +( +) +bg +. +clone +( +) +) +; +} +} } / / assert ! ( -cmdbuf -. -trackers +cmd_buf_trackers . samplers . @@ -8254,170 +8464,196 @@ is_empty ) ; for -id +compute_pipeline in -cmdbuf -. -trackers +cmd_buf_trackers . compute_pipelines . -used +used_resources ( ) { -if -! -compute_pipe_guard -[ -id -] +compute_pipeline . -life_guard +info . use_at ( submit_index ) -{ -device +; +if +compute_pipeline . +is_unique +( +) +{ temp_suspected . -compute_pipelines +as_mut +( +) . -push +unwrap ( +) +. +insert +( +compute_pipeline +. +as_info +( +) +. id +( +) +compute_pipeline +. +clone +( +) ) ; } } for -id +render_pipeline in -cmdbuf -. -trackers +cmd_buf_trackers . render_pipelines . -used +used_resources ( ) { -if -! -render_pipe_guard -[ -id -] +render_pipeline . -life_guard +info . use_at ( submit_index ) -{ -device +; +if +render_pipeline . +is_unique +( +) +{ temp_suspected . -render_pipelines +as_mut +( +) . -push +unwrap +( +) +. +insert ( +render_pipeline +. +as_info +( +) +. id +( +) +render_pipeline +. +clone +( +) ) ; } } for -id +query_set in -cmdbuf -. -trackers +cmd_buf_trackers . query_sets . -used +used_resources ( ) { -if -! -query_set_guard -[ -id -] +query_set . -life_guard +info . use_at ( submit_index ) -{ -device +; +if +query_set . +is_unique +( +) +{ temp_suspected . -query_sets +as_mut +( +) +. +unwrap +( +) +. +insert +( +query_set +. +as_info +( +) +. +id +( +) +query_set . -push +clone ( -id +) ) ; } } for -id +bundle in -cmdbuf -. -trackers +cmd_buf_trackers . bundles . -used +used_resources ( ) { -let -bundle -= -& -render_bundle_guard -[ -id -] -; -if -! bundle . -life_guard +info . use_at ( submit_index ) -{ -device -. -temp_suspected -. -render_bundles -. -push -( -id -) ; -} / / We @@ -8465,7 +8701,7 @@ of scope . for -sub_id +render_pipeline in bundle . @@ -8473,16 +8709,17 @@ used . render_pipelines . -used +read +( +) +. +used_resources ( ) { -render_pipe_guard -[ -sub_id -] +render_pipeline . -life_guard +info . use_at ( @@ -8491,7 +8728,7 @@ submit_index ; } for -sub_id +query_set in bundle . @@ -8499,16 +8736,17 @@ used . query_sets . -used +read +( +) +. +used_resources ( ) { -query_set_guard -[ -sub_id -] +query_set . -life_guard +info . use_at ( @@ -8516,6 +8754,43 @@ submit_index ) ; } +if +bundle +. +is_unique +( +) +{ +temp_suspected +. +as_mut +( +) +. +unwrap +( +) +. +insert +( +bundle +. +as_info +( +) +. +id +( +) +bundle +. +clone +( +) +) +; +} +} } let mut @@ -8523,7 +8798,7 @@ baked = cmdbuf . -into_baked +from_arc_into_baked ( ) ; @@ -8588,6 +8863,32 @@ submission cmb_id ) ; +/ +/ +Note +: +locking +the +trackers +has +to +be +done +after +the +storages +let +mut +trackers += +device +. +trackers +. +lock +( +) +; baked . initialize_buffer_memory @@ -8596,10 +8897,6 @@ initialize_buffer_memory mut * trackers -& -mut -* -buffer_guard ) . map_err @@ -8627,10 +8924,6 @@ initialize_texture_memory mut * trackers -& -mut -* -texture_guard device ) . @@ -8688,12 +8981,6 @@ trackers baked . trackers -& -* -buffer_guard -& -* -texture_guard ) ; let @@ -8819,51 +9106,61 @@ textures set_from_usage_scope ( & -* -texture_guard -& used_surface_textures ) ; let -texture_barriers +( +transitions +textures +) = trackers . textures . -drain +drain_transitions +( +) +; +let +texture_barriers += +transitions +. +into_iter +( +) +. +enumerate ( ) . map ( | -pending +( +i +p +) | -{ -let -tex -= -unsafe -{ -texture_guard +p . -get_unchecked +into_hal ( -pending +textures +[ +i +] . -id +as_ref +( ) -} -; -pending . -into_hal +unwrap ( -tex ) -} +) ) ; let @@ -8955,151 +9252,42 @@ submit_index ) ; } -let -super -: -: -Device -{ -ref -mut -pending_writes -ref -mut -queue -ref -mut -fence -. -. } -= -* -device -; -{ -/ -/ -TODO -: -These -blocks -have -a -few -organizational -issues -and -/ -/ -should -be -refactored -. -/ -/ -/ -/ -1 -) -It -' -s -similar -to -the -code -we -have -per -- -command -- -buffer -/ -/ -( -at -the -begin -and -end -) -Maybe -we -can -merge -some -? -/ -/ -/ -/ -2 -) -It -' -s -doing -the -extra -locking -unconditionally -. -Maybe -we -/ -/ -can -only -do -so -if -any -surfaces -are -being -written -to -? let -( -_ mut -token -) +pending_writes = -hub +device . -buffers +pending_writes . -read +lock ( -& -mut -token ) ; -/ -/ -skip -token let +pending_writes += +pending_writes +. +as_mut +( +) +. +unwrap ( -mut -texture_guard -_ ) +; +{ +let +texture_guard = hub . textures . -write +read ( -& -mut -token ) ; used_surface_textures @@ -9114,8 +9302,11 @@ len ) ; for +( & id +texture +) in pending_writes . @@ -9125,24 +9316,21 @@ iter ( ) { -let +match +* texture -= -texture_guard . -get_mut +inner ( -id ) . -unwrap +as_ref ( ) -; -match -texture . -inner +unwrap +( +) { TextureInner : @@ -9191,7 +9379,6 @@ TextureInner Surface { ref -mut has_work . . @@ -9199,20 +9386,15 @@ has_work = > { -* has_work -= -true -; -let -ref_count -= -texture . -life_guard -. -add_ref +store ( +true +Ordering +: +: +Relaxed ) ; unsafe @@ -9221,19 +9403,8 @@ used_surface_textures . merge_single ( -& -* -texture_guard -id -: -: -Valid -( -id -) +texture None -& -ref_count hal : : @@ -9278,51 +9449,61 @@ textures set_from_usage_scope ( & -* -texture_guard -& used_surface_textures ) ; let -texture_barriers +( +transitions +textures +) = trackers . textures . -drain +drain_transitions +( +) +; +let +texture_barriers += +transitions +. +into_iter +( +) +. +enumerate ( ) . map ( | -pending +( +i +p +) | -{ -let -tex -= -unsafe -{ -texture_guard +p . -get_unchecked +into_hal ( -pending +textures +[ +i +] . -id +as_ref +( ) -} -; -pending . -into_hal +unwrap ( -tex ) -} +) ) ; unsafe @@ -9392,6 +9573,16 @@ unsafe { queue . +raw +. +as_ref +( +) +. +unwrap +( +) +. submit ( & @@ -9415,7 +9606,6 @@ from ? ; } -} profiling : : @@ -9434,24 +9624,41 @@ Some pending_execution ) = -device -. pending_writes . post_submit ( -& device . command_allocator -& -device . -raw -& +lock +( +) +. +as_mut +( +) +. +unwrap +( +) device . +raw +( +) queue +. +raw +. +as_ref +( +) +. +unwrap +( +) ) { active_executions @@ -9486,8 +9693,6 @@ take ( & mut -device -. pending_writes . temp_resources @@ -9497,9 +9702,6 @@ device . lock_life ( -& -mut -token ) . track_submission @@ -9556,6 +9758,7 @@ device maintain ( hub +fence wgt : : @@ -9563,9 +9766,6 @@ Maintain : : Poll -& -mut -token ) { Ok @@ -9656,8 +9856,6 @@ its heap allocation . -device -. pending_writes . temp_resources @@ -9666,19 +9864,8 @@ pending_write_resources ; device . -temp_suspected -. -clear -( -) -; -device -. lock_life ( -& -mut -token ) . post_submit @@ -9731,9 +9918,6 @@ HalApi self queue_id : -id -: -: QueueId ) - @@ -9755,36 +9939,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -_ -) -= +match hub . -devices -. -read -( -& -mut -token -) -; -match -device_guard +queues . get ( @@ -9793,7 +9951,7 @@ queue_id { Ok ( -device +queue ) = > @@ -9801,10 +9959,18 @@ Ok ( unsafe { -device -. queue . +raw +. +as_ref +( +) +. +unwrap +( +) +. get_timestamp_period ( ) @@ -9835,9 +10001,6 @@ HalApi self queue_id : -id -: -: QueueId closure : @@ -9889,37 +10052,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -device_guard -mut -token -) -= +match hub . -devices -. -read -( -& -mut -token -) -; -match -device_guard +queues . get ( @@ -9928,17 +10064,24 @@ queue_id { Ok ( -device +queue ) = > +queue +. device . +as_ref +( +) +. +unwrap +( +) +. lock_life ( -& -mut -token ) . add_work_done_closure diff --git a/third_party/rust/wgpu-core/src/device/resource.rs b/third_party/rust/wgpu-core/src/device/resource.rs index f34a0c80e1ccb..327dcdbb43470 100644 --- a/third_party/rust/wgpu-core/src/device/resource.rs +++ b/third_party/rust/wgpu-core/src/device/resource.rs @@ -28,10 +28,8 @@ binding_model : { self -get_bind_group_layout -try_get_bind_group_layout -BglOrDuplicate -BindGroupLayoutInner +BindGroupLayout +BindGroupLayoutEntryError } command conv @@ -41,7 +39,17 @@ device life : : +{ +LifetimeTracker WaitIdleError +} +device +: +: +queue +: +: +PendingWrites device : : @@ -62,15 +70,15 @@ hal_label hub : : -{ Hub -Token -} id -identity : : -GlobalIdentityHandlerFactory +{ +self +DeviceId +QueueId +} init_tracker : : @@ -87,12 +95,26 @@ instance : Adapter pipeline +registry +: +: +Registry +resource +: +: +ResourceInfo resource : : { self Buffer +QuerySet +Resource +ResourceType +Sampler +Texture +TextureView TextureViewNotRenderableReason } storage @@ -119,10 +141,6 @@ FastHashMap LabelHelpers as _ -LifeGuard -MultiRefCount -RefCount -Stored SubmissionIndex } ; @@ -152,6 +170,7 @@ parking_lot { Mutex MutexGuard +RwLock } ; use @@ -191,6 +210,20 @@ num : : NonZeroU32 +sync +: +: +{ +atomic +: +: +{ +AtomicBool +AtomicU64 +Ordering +} +Arc +} } ; use @@ -199,7 +232,18 @@ super : { life +: +: +{ +self +ResourceMaps +} queue +: +: +{ +self +} DeviceDescriptor DeviceError ImplicitPipelineContext @@ -249,13 +293,8 @@ these / / / -mem_allocator -desc_allocator life_tracker trackers -/ -/ -/ render_passes pending_writes trace @@ -316,6 +355,172 @@ last ( unenforced ) +/ +/ +/ +/ +/ +/ +Right +now +avoid +locking +twice +same +resource +or +registry +in +a +call +execution +/ +/ +/ +and +minimize +the +locking +to +the +minimum +scope +possibile +/ +/ +/ +Unless +otherwise +specified +no +lock +may +be +acquired +while +holding +another +lock +. +/ +/ +/ +This +means +that +you +must +inspect +function +calls +made +while +a +lock +is +held +/ +/ +/ +to +see +what +locks +the +callee +may +try +to +acquire +. +/ +/ +/ +/ +/ +/ +As +far +as +this +point +: +/ +/ +/ +device_maintain_ids +locks +Device +: +: +lifetime_tracker +and +calls +. +. +. +/ +/ +/ +triage_suspected +locks +Device +: +: +trackers +and +calls +. +. +. +/ +/ +/ +Registry +: +: +unregister +locks +Registry +: +: +storage +/ +/ +/ +/ +/ +/ +Important +: +/ +/ +/ +When +locking +pending_writes +please +check +that +trackers +is +not +locked +/ +/ +/ +trackers +should +be +locked +only +when +needed +for +the +shortest +time +possible pub struct Device @@ -325,92 +530,92 @@ A HalApi > { -pub -( -crate -) raw : +Option +< A : : Device +> pub ( crate ) -adapter_id +adapter : -Stored +Arc < -id -: -: -AdapterId +Adapter +< +A +> > pub ( crate ) -queue +queue_id +: +RwLock +< +Option +< +QueueId +> +> +queue_to_drop : +RwLock +< +Option +< A : : Queue +> +> pub ( crate ) zero_buffer : +Option +< A : : Buffer -/ -/ +> pub ( crate ) -cmd_allocator -: -command -: +info : -CommandAllocator +ResourceInfo < -A +DeviceId > -/ -/ -mem_allocator +pub +( +crate +) +command_allocator : Mutex < -alloc -: -: -MemoryAllocator -< -A -> -> -/ -/ -desc_allocator -: -Mutex +Option < -descriptor -: -: -DescriptorAllocator +CommandAllocator < A > > +> / / Note @@ -432,102 +637,28 @@ pub ( crate ) -life_guard +active_submission_index : -LifeGuard -/ +AtomicU64 / / +SubmissionIndex +pub +( +crate +) +fence +: +RwLock +< +Option +< A -clone -of -life_guard -. -ref_count -. -/ -/ -/ -/ -/ -/ -Holding -a -separate -clone -of -the -RefCount -here -lets -us -tell -whether -the -/ -/ -/ -device -is -referenced -by -other -resources -even -if -life_guard -. -ref_count -/ -/ -/ -was -set -to -None -by -a -call -to -device_drop -. -pub -( -super -) -ref_count : -RefCount -pub -( -super -) -command_allocator : -Mutex -< -CommandAllocator -< -A +Fence > > -pub -( -crate -) -active_submission_index -: -SubmissionIndex -pub -( -super -) -fence -: -A -: -: -Fence / / / @@ -718,7 +849,7 @@ crate ) valid : -bool +AtomicBool / / / @@ -748,6 +879,13 @@ only locked last ) +/ +/ +/ +and +never +before +pending_writes pub ( crate @@ -781,9 +919,6 @@ life_tracker : Mutex < -life -: -: LifetimeTracker < A @@ -818,14 +953,17 @@ occurs . pub ( -super +crate ) temp_suspected : -life -: -: -SuspectedResources +Mutex +< +Option +< +ResourceMaps +> +> pub ( crate @@ -876,51 +1014,22 @@ wgt : : InstanceFlags -/ -/ -TODO -: -move -this -behind -another -mutex -. -This -would -allow -several -methods -to -/ -/ -switch -to -borrow -Device -immutably -such -as -write_buffer -write_texture -/ -/ -and -buffer_unmap -. pub ( -super +crate ) pending_writes : -queue -: -: +Mutex +< +Option +< PendingWrites < A > +> +> # [ cfg @@ -938,10 +1047,10 @@ crate ) trace : -Option -< Mutex < +Option +< trace : : @@ -949,123 +1058,443 @@ Trace > > } -# -[ -derive -( -Clone -Debug -Error -) -] -# -[ -non_exhaustive -] -pub -enum -CreateDeviceError -{ -# -[ -error -( -" -Not -enough -memory -left -" -) -] -OutOfMemory -# -[ -error -( -" -Failed -to -create -internal -buffer -for -initializing -textures -" -) -] -FailedToCreateZeroBuffer -( -# -[ -from -] -DeviceError -) -} impl < A : HalApi > +std +: +: +fmt +: +: +Debug +for Device < A > { -pub -( -crate -) fn -require_features +fmt ( & self -feature +f : -wgt +& +mut +std : : -Features +fmt +: +: +Formatter +< +' +_ +> ) - > +std +: +: +fmt +: +: Result -< -( -) -MissingFeatures -> { -if -self -. -features +f . -contains +debug_struct ( -feature +" +Device +" ) -{ -Ok +. +field ( +" +adapter +" +& +self +. +adapter +. +info +. +label ( ) ) -} -else -{ -Err -( -MissingFeatures +. +field ( -feature -) -) -} +" +limits +" +& +self +. +limits +) +. +field +( +" +features +" +& +self +. +features +) +. +field +( +" +downlevel +" +& +self +. +downlevel +) +. +finish +( +) +} +} +impl +< +A +: +HalApi +> +Drop +for +Device +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +Device +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +let +raw += +self +. +raw +. +take +( +) +. +unwrap +( +) +; +let +pending_writes += +self +. +pending_writes +. +lock +( +) +. +take +( +) +. +unwrap +( +) +; +pending_writes +. +dispose +( +& +raw +) +; +self +. +command_allocator +. +lock +( +) +. +take +( +) +. +unwrap +( +) +. +dispose +( +& +raw +) +; +unsafe +{ +raw +. +destroy_buffer +( +self +. +zero_buffer +. +take +( +) +. +unwrap +( +) +) +; +raw +. +destroy_fence +( +self +. +fence +. +write +( +) +. +take +( +) +. +unwrap +( +) +) +; +let +queue += +self +. +queue_to_drop +. +write +( +) +. +take +( +) +. +unwrap +( +) +; +raw +. +exit +( +queue +) +; +} +} +} +# +[ +derive +( +Clone +Debug +Error +) +] +pub +enum +CreateDeviceError +{ +# +[ +error +( +" +Not +enough +memory +left +to +create +device +" +) +] +OutOfMemory +# +[ +error +( +" +Failed +to +create +internal +buffer +for +initializing +textures +" +) +] +FailedToCreateZeroBuffer +( +# +[ +from +] +DeviceError +) +} +impl +< +A +: +HalApi +> +Device +< +A +> +{ +pub +( +crate +) +fn +raw +( +& +self +) +- +> +& +A +: +: +Device +{ +self +. +raw +. +as_ref +( +) +. +unwrap +( +) +} +pub +( +crate +) +fn +require_features +( +& +self +feature +: +wgt +: +: +Features +) +- +> +Result +< +( +) +MissingFeatures +> +{ +if +self +. +features +. +contains +( +feature +) +{ +Ok +( +( +) +) +} +else +{ +Err +( +MissingFeatures +( +feature +) +) +} } pub ( @@ -1140,23 +1569,28 @@ crate fn new ( -open +raw_device : -hal +A : : -OpenDevice -< +Device +raw_queue +: +& A -> -adapter_id : -Stored -< -id : +Queue +adapter : -AdapterId +& +Arc +< +Adapter +< +A +> > alignments : @@ -1248,9 +1682,7 @@ fence = unsafe { -open -. -device +raw_device . create_fence ( @@ -1293,13 +1725,8 @@ com_alloc acquire_encoder ( & -open -. -device -& -open -. -queue +raw_device +raw_queue ) . map_err @@ -1349,9 +1776,7 @@ zero_buffer = unsafe { -open -. -device +raw_device . create_buffer ( @@ -1532,10 +1957,50 @@ COPY_SRC ) ; } -let -life_guard -= -LifeGuard +Ok +( +Self +{ +raw +: +Some +( +raw_device +) +adapter +: +adapter +. +clone +( +) +queue_id +: +RwLock +: +: +new +( +None +) +queue_to_drop +: +RwLock +: +: +new +( +None +) +zero_buffer +: +Some +( +zero_buffer +) +info +: +ResourceInfo : : new @@ -1546,34 +2011,6 @@ device > " ) -; -let -ref_count -= -life_guard -. -add_ref -( -) -; -Ok -( -Self -{ -raw -: -open -. -device -adapter_id -queue -: -open -. -queue -zero_buffer -life_guard -ref_count command_allocator : Mutex @@ -1581,15 +2018,41 @@ Mutex : new ( +Some +( com_alloc ) +) active_submission_index : +AtomicU64 +: +: +new +( 0 +) fence +: +RwLock +: +: +new +( +Some +( +fence +) +) valid : +AtomicBool +: +: +new +( true +) trackers : Mutex @@ -1623,15 +2086,29 @@ new ) temp_suspected : +Mutex +: +: +new +( +Some +( life : : -SuspectedResources +ResourceMaps : : -default +new +: +: +< +A +> ( ) +) +) # [ cfg @@ -1645,6 +2122,11 @@ trace ] trace : +Mutex +: +: +new +( trace_path . and_then @@ -1702,14 +2184,8 @@ VARIANT ; Some ( -Mutex -: -: -new -( trace ) -) } Err ( @@ -1751,6 +2227,7 @@ None } } ) +) alignments limits : @@ -1769,6 +2246,17 @@ features downlevel instance_flags pending_writes +: +Mutex +: +: +new +( +Some +( +pending_writes +) +) } ) } @@ -1786,63 +2274,68 @@ bool self . valid +. +load +( +Ordering +: +: +Acquire +) } pub ( -super +crate ) fn -lock_life -< -' -this -' -token -: -' -this -> +release_queue ( & -' -this self -/ -/ -TODO +queue : -fix -this -- -the -token -has -to -be -borrowed -for -the -lock -_token +A : -& -mut -Token +: +Queue +) +{ +self +. +queue_to_drop +. +write +( +) +. +replace +( +queue +) +; +} +pub +( +crate +) +fn +lock_life < ' -token -Self +a > +( +& +' +a +self ) - > MutexGuard < ' -this -life -: -: +a LifetimeTracker < A @@ -1995,21 +2488,13 @@ callers ) pub ( -super +crate ) fn maintain < ' this -' -token -: -' -this -G -: -GlobalIdentityHandlerFactory > ( & @@ -2022,8 +2507,14 @@ hub Hub < A -G > +fence +: +& +A +: +: +Fence maintain : wgt @@ -2036,16 +2527,6 @@ queue : WrappedSubmissionIndex > -token -: -& -mut -Token -< -' -token -Self -> ) - > @@ -2072,17 +2553,7 @@ maintain " ) ; -let -mut -life_tracker -= -self -. -lock_life -( -token -) -; +{ / / Normally @@ -2139,15 +2610,52 @@ in / temp_suspected . +let +temp_suspected += +self +. +temp_suspected +. +lock +( +) +. +replace +( +ResourceMaps +: +: +new +: +: +< +A +> +( +) +) +. +unwrap +( +) +; +let +mut +life_tracker += +self +. +lock_life +( +) +; life_tracker . suspected_resources . extend ( -& -self -. temp_suspected ) ; @@ -2175,20 +2683,22 @@ self . trace . -as_ref +lock +( +) +. +as_mut ( ) -token ) ; life_tracker . triage_mapped ( -hub -token ) ; +} let last_done_index = @@ -2257,6 +2767,14 @@ _ self . active_submission_index +. +load +( +Ordering +: +: +Relaxed +) } ; unsafe @@ -2265,11 +2783,16 @@ self . raw . -wait +as_ref ( -& -self +) +. +unwrap +( +) . +wait +( fence index_to_wait_for CLEANUP_WAIT_MS @@ -2295,11 +2818,16 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. get_fence_value ( -& -self -. fence ) . @@ -2315,6 +2843,16 @@ from } ; let +mut +life_tracker += +self +. +lock_life +( +) +; +let submission_closures = life_tracker @@ -2322,10 +2860,21 @@ life_tracker triage_submissions ( last_done_index -& self . command_allocator +. +lock +( +) +. +as_mut +( +) +. +unwrap +( +) ) ; let @@ -2336,25 +2885,32 @@ life_tracker handle_mapping ( hub -& self . raw +( +) & self . trackers -token ) ; +/ +/ +Cleaning +up +resources +and +released +all +unused +suspected +ones life_tracker . cleanup ( -& -self -. -raw ) ; / @@ -2443,7 +2999,9 @@ if ! self . -valid +is_valid +( +) & & life_tracker @@ -2526,36 +3084,13 @@ queue_empty } pub ( -super +crate ) fn untrack -< -' -this -' -token -: -' -this -G -: -GlobalIdentityHandlerFactory -> ( & -' -this -mut self -hub -: -& -Hub -< -A -G -> trackers : & @@ -2563,20 +3098,39 @@ Tracker < A > -token -: -& +) +{ +let mut -Token +temp_suspected += +self +. +temp_suspected +. +lock +( +) +. +replace +( +ResourceMaps +: +: +new +: +: < -' -token -Self +A > +( +) ) -{ -self . +unwrap +( +) +; temp_suspected . clear @@ -2613,511 +3167,322 @@ GC pass . { -let -( -bind_group_guard -mut -token -) -= -hub -. -bind_groups -. -read -( -token -) -; -let -( -compute_pipe_guard -mut -token -) -= -hub -. -compute_pipelines -. -read -( -& -mut -token -) -; -let -( -render_pipe_guard -mut -token -) -= -hub -. -render_pipelines -. -read -( -& -mut -token -) -; -let -( -query_set_guard -mut -token -) -= -hub -. -query_sets -. -read -( -& -mut -token -) -; -let -( -buffer_guard -mut -token -) -= -hub -. -buffers -. -read -( -& -mut -token -) -; -let -( -texture_guard -mut -token -) -= -hub -. -textures -. -read -( -& -mut -token -) -; -let -( -texture_view_guard -mut -token -) -= -hub -. -texture_views -. -read -( -& -mut -token -) -; -let -( -sampler_guard -_ -) -= -hub -. -samplers -. -read -( -& -mut -token -) -; for -id +resource in trackers . buffers . -used +used_resources ( ) { if -buffer_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self . -temp_suspected -. -buffers +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . textures . -used +used_resources +( +) +{ +if +resource +. +is_unique ( ) { -if -texture_guard +temp_suspected . -get_occupied_or_destroyed +insert ( -id -. -0 -) +resource . -unwrap +as_info ( ) . -life_guard -. -ref_count -. -is_none +id ( ) -{ -self -. -temp_suspected -. -textures +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . views . -used +used_resources ( ) { if -texture_view_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self -. -temp_suspected . -texture_views +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . bind_groups . -used +used_resources ( ) { if -bind_group_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self . -temp_suspected -. -bind_groups +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . samplers . -used +used_resources ( ) { if -sampler_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self -. -temp_suspected . -samplers +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . compute_pipelines . -used +used_resources ( ) { if -compute_pipe_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self -. -temp_suspected . -compute_pipelines +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . render_pipelines . -used +used_resources ( ) { if -render_pipe_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self . -temp_suspected -. -render_pipelines +id +( +) +resource . -push +clone ( -id +) ) ; } } for -id +resource in trackers . query_sets . -used +used_resources ( ) { if -query_set_guard +resource . -get_occupied_or_destroyed +is_unique ( -id -. -0 ) +{ +temp_suspected . -unwrap +insert ( -) -. -life_guard -. -ref_count +resource . -is_none +as_info ( ) -{ -self -. -temp_suspected . -query_sets +id +( +) +resource . -push +clone ( -id +) ) ; } @@ -3127,43 +3492,30 @@ self . lock_life ( -token ) . suspected_resources . extend ( -& -self -. -temp_suspected -) -; -self -. temp_suspected -. -clear -( ) ; } pub ( -super +crate ) fn create_buffer ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> desc : & @@ -3192,7 +3544,15 @@ CreateBufferError debug_assert_eq ! ( -self_id +self +. +as_info +( +) +. +id +( +) . backend ( @@ -3765,6 +4125,8 @@ unsafe self . raw +( +) . create_buffer ( @@ -3792,29 +4154,13 @@ Some ( buffer ) -device_id -: -Stored -{ -value -: -id -: -: -Valid -( -self_id -) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} usage : desc @@ -3827,6 +4173,11 @@ desc size initialization_status : +RwLock +: +: +new +( BufferInitTracker : : @@ -3836,11 +4187,23 @@ desc . size ) +) sync_mapped_writes : +Mutex +: +: +new +( None +) map_state : +Mutex +: +: +new +( resource : : @@ -3848,9 +4211,10 @@ BufferMapState : : Idle -life_guard +) +info : -LifeGuard +ResourceInfo : : new @@ -3868,13 +4232,18 @@ borrow_or_default } pub ( -super +crate ) fn create_texture_from_hal ( -& self +: +& +Arc +< +Self +> hal_texture : A @@ -3887,12 +4256,6 @@ hal : : TextureUses -self_id -: -id -: -: -DeviceId desc : & @@ -3918,9 +4281,6 @@ A ) - > -resource -: -: Texture < A @@ -3929,7 +4289,15 @@ A debug_assert_eq ! ( -self_id +self +. +as_info +( +) +. +id +( +) . backend ( @@ -3940,13 +4308,17 @@ A VARIANT ) ; -resource -: -: Texture { inner : +RwLock +: +: +new +( +Some +( resource : : @@ -3962,29 +4334,15 @@ Some hal_texture ) } -device_id -: -Stored -{ -value -: -id -: -: -Valid -( -self_id ) -ref_count +) +device : self . -life_guard -. -add_ref +clone ( ) -} desc : desc @@ -4001,6 +4359,11 @@ hal_usage format_features initialization_status : +RwLock +: +: +new +( TextureInitTracker : : @@ -4015,6 +4378,7 @@ array_layer_count ( ) ) +) full_range : TextureSelector @@ -4038,9 +4402,9 @@ array_layer_count ( ) } -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -4054,26 +4418,33 @@ borrow_or_default ) ) clear_mode +: +RwLock +: +: +new +( +clear_mode +) } } pub fn create_buffer_from_hal ( -& self +: +& +Arc +< +Self +> hal_buffer : A : : Buffer -self_id -: -id -: -: -DeviceId desc : & @@ -4092,7 +4463,15 @@ A debug_assert_eq ! ( -self_id +self +. +as_info +( +) +. +id +( +) . backend ( @@ -4111,29 +4490,13 @@ Some ( hal_buffer ) -device_id -: -Stored -{ -value -: -id -: -: -Valid -( -self_id -) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} usage : desc @@ -4146,6 +4509,11 @@ desc size initialization_status : +RwLock +: +: +new +( BufferInitTracker : : @@ -4153,11 +4521,23 @@ new ( 0 ) +) sync_mapped_writes : +Mutex +: +: +new +( None +) map_state : +Mutex +: +: +new +( resource : : @@ -4165,9 +4545,10 @@ BufferMapState : : Idle -life_guard +) +info : -LifeGuard +ResourceInfo : : new @@ -4184,19 +4565,18 @@ borrow_or_default } pub ( -super +crate ) fn create_texture ( -& self -self_id -: -id -: : -DeviceId +& +Arc +< +Self +> adapter : & @@ -4216,9 +4596,6 @@ TextureDescriptor > Result < -resource -: -: Texture < A @@ -4959,238 +5336,88 @@ format = = * -format -{ -continue -; -} -if -desc -. -format -. -remove_srgb_suffix -( -) -! -= -format -. -remove_srgb_suffix -( -) -{ -return -Err -( -CreateTextureError -: -: -InvalidViewFormat -( -* -format -desc -. -format -) -) -; -} -hal_view_formats -. -push -( -* -format -) -; -} -if -! -hal_view_formats -. -is_empty -( -) -{ -self -. -require_downlevel_flags -( -wgt -: -: -DownlevelFlags -: -: -VIEW_FORMATS -) -? -; -} -/ -/ -Enforce -having -COPY_DST -/ -DEPTH_STENCIL_WRITE -/ -COLOR_TARGET -otherwise -we -/ -/ -wouldn -' -t -be -able -to -initialize -the -texture -. -let -hal_usage -= -conv -: -: -map_texture_usage -( -desc -. -usage -desc -. -format -. -into -( -) -) -| -if -desc -. -format -. -is_depth_stencil_format -( -) -{ -hal -: -: -TextureUses -: -: -DEPTH_STENCIL_WRITE +format +{ +continue +; } -else if desc . -usage +format . -contains +remove_srgb_suffix +( +) +! += +format +. +remove_srgb_suffix ( -wgt -: -: -TextureUsages -: -: -COPY_DST ) { -hal -: -: -TextureUses +return +Err +( +CreateTextureError : : -COPY_DST -/ -/ +InvalidViewFormat ( -set -already +* +format +desc +. +format ) +) +; } -else -{ -/ -/ -Use -COPY_DST -only -if -we -can -' -t -use -COLOR_TARGET -if -format_features +hal_view_formats . -allowed_usages +push +( +* +format +) +; +} +if +! +hal_view_formats . -contains +is_empty ( -wgt -: -: -TextureUsages -: -: -RENDER_ATTACHMENT ) -& -& -desc +{ +self . -dimension -= -= +require_downlevel_flags +( wgt : : -TextureDimension -: -: -D2 -/ -/ -Render -targets -dimension -must -be -2d -{ -hal -: -: -TextureUses +DownlevelFlags : : -COLOR_TARGET +VIEW_FORMATS +) +? +; } -else -{ -hal -: -: -TextureUses +let +hal_usage += +conv : : -COPY_DST -} -} +map_texture_usage_for_texture +( +desc +& +format_features +) ; let hal_desc @@ -5265,6 +5492,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_texture ( & @@ -5515,11 +5750,15 @@ clear_views . push ( +Some +( unsafe { self . raw +( +) . create_texture_view ( @@ -5539,6 +5778,7 @@ from ) ? ) +) ; } } @@ -5575,7 +5815,6 @@ create_texture_from_hal ( raw_texture hal_usage -self_id desc format_features clear_mode @@ -5594,29 +5833,28 @@ texture } pub ( -super +crate ) fn create_texture_view ( -& self -texture : & -resource -: +Arc +< +Self +> +texture : +& +Arc +< Texture < A > -texture_id -: -id -: -: -TextureId +> desc : & @@ -5629,9 +5867,6 @@ TextureViewDescriptor > Result < -resource -: -: TextureView < A @@ -5643,11 +5878,26 @@ CreateTextureViewError > { let -texture_raw +inner = texture . inner +( +) +; +let +texture_raw += +inner +. +as_ref +( +) +. +unwrap +( +) . as_raw ( @@ -6935,7 +7185,15 @@ to ? } " -texture_id +texture +. +as_info +( +) +. +id +( +) usage ) ; @@ -7059,6 +7317,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_texture_view ( texture_raw @@ -7111,40 +7377,33 @@ array_layer_end ; Ok ( -resource -: -: TextureView { raw -parent_id : -Stored -{ -value +Some +( +raw +) +parent : -id +RwLock : : -Valid +new +( +Some ( -texture_id -) -ref_count -: texture . -life_guard -. -add_ref +clone ( ) -} -device_id +) +) +device : -texture -. -device_id +self . clone ( @@ -7180,9 +7439,9 @@ desc . sample_count selector -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -7200,19 +7459,18 @@ borrow_or_default } pub ( -super +crate ) fn create_sampler ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> desc : & @@ -7225,9 +7483,6 @@ SamplerDescriptor > Result < -resource -: -: Sampler < A @@ -7709,6 +7964,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_sampler ( & @@ -7727,38 +7990,24 @@ from ; Ok ( -resource -: -: -Sampler -{ -raw -device_id -: -Stored -{ -value -: -id -: +Sampler +{ +raw : -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -7813,7 +8062,7 @@ Linear } pub ( -super +crate ) fn create_shader_module @@ -7822,14 +8071,13 @@ create_shader_module a > ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> desc : & @@ -8747,6 +8995,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_shader_module ( & @@ -8854,35 +9110,39 @@ pipeline ShaderModule { raw -device_id -: -Stored -{ -value : -id -: -: -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} interface : Some ( interface ) +info +: +ResourceInfo +: +: +new +( +desc +. +label +. +borrow_or_default +( +) +) # [ cfg @@ -8915,7 +9175,7 @@ unused_unsafe ] pub ( -super +crate ) unsafe fn @@ -8925,14 +9185,13 @@ create_shader_module_spirv a > ( -& self -self_id -: -id -: : -DeviceId +& +Arc +< +Self +> desc : & @@ -9039,6 +9298,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_shader_module ( & @@ -9146,32 +9413,36 @@ pipeline ShaderModule { raw -device_id -: -Stored -{ -value -: -id -: : -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} interface : None +info +: +ResourceInfo +: +: +new +( +desc +. +label +. +borrow_or_default +( +) +) # [ cfg @@ -9197,20 +9468,27 @@ to_string } pub ( -super +crate ) fn deduplicate_bind_group_layout +< +' +a +> ( -self_id -: -id -: +self : -DeviceId +& +Arc +< +Self +> entry_map : & +' +a binding_model : : @@ -9218,11 +9496,10 @@ BindEntryMap guard : & +' +a Storage < -binding_model -: -: BindGroupLayout < A @@ -9237,17 +9514,34 @@ BindGroupLayoutId > Option < +( id : : BindGroupLayoutId +Arc +< +BindGroupLayout +< +A +> +> +) > { guard . iter ( -self_id +self +. +as_info +( +) +. +id +( +) . backend ( @@ -9266,36 +9560,33 @@ bgl { bgl . -device_id +device . -value +info . -0 +id +( +) = = -self_id -& -& -bgl +self . -as_inner +as_info ( ) . -map_or +id ( -false -| -inner -| -inner +) +& +& +bgl . entries = = * entry_map -) } ) . @@ -9304,22 +9595,23 @@ map | ( id -value +resource ) | -{ -value -. -multi_ref_count +( +id +resource . -inc +clone ( ) -; -id -} +) ) } +pub +( +crate +) fn get_introspection_bind_group_layouts < @@ -9330,32 +9622,15 @@ a pipeline_layout : & -binding_model -: -: -PipelineLayout -< -A -> -bgl_guard -: -& ' a -Storage -< binding_model : : -BindGroupLayout +PipelineLayout < A > -id -: -: -BindGroupLayoutId -> ) - > @@ -9378,7 +9653,7 @@ MAX_BIND_GROUPS { pipeline_layout . -bind_group_layout_ids +bind_group_layouts . iter ( @@ -9387,25 +9662,12 @@ iter map ( | -& -id +layout | -{ & -get_bind_group_layout -( -bgl_guard -id -) -. -1 -. -assume_deduplicated -( -) +layout . entries -} ) . collect @@ -9440,12 +9702,12 @@ in some way ? +pub +( +crate +) fn make_late_sized_buffer_groups -< -' -a -> ( shader_binding_sizes : @@ -9471,25 +9733,6 @@ PipelineLayout < A > -bgl_guard -: -& -' -a -Storage -< -binding_model -: -: -BindGroupLayout -< -A -> -id -: -: -BindGroupLayoutId -> ) - > @@ -9542,7 +9785,7 @@ min_binding_size . layout . -bind_group_layout_ids +bind_group_layouts . iter ( @@ -9557,28 +9800,17 @@ map | ( group_index -& -bgl_id +bgl ) | pipeline : -: -LateSizedBufferGroup -{ -shader_sizes -: -get_bind_group_layout -( -bgl_guard -bgl_id -) -. -1 -. -assume_deduplicated -( -) +: +LateSizedBufferGroup +{ +shader_sizes +: +bgl . entries . @@ -9681,19 +9913,18 @@ collect } pub ( -super +crate ) fn create_bind_group_layout ( -& self -self_id -: -id -: : -DeviceId +& +Arc +< +Self +> label : & @@ -9712,9 +9943,6 @@ BindEntryMap > Result < -binding_model -: -: BindGroupLayout < A @@ -10001,9 +10229,6 @@ entry binding error : -binding_model -: -: BindGroupLayoutEntryError : : @@ -10091,9 +10316,6 @@ entry binding error : -binding_model -: -: BindGroupLayoutEntryError : : @@ -10162,9 +10384,6 @@ entry binding error : -binding_model -: -: BindGroupLayoutEntryError : : @@ -10293,9 +10512,6 @@ array_feature . ok_or ( -binding_model -: -: BindGroupLayoutEntryError : : @@ -10477,9 +10693,6 @@ required_features . map_err ( -binding_model -: -: BindGroupLayoutEntryError : : @@ -10518,9 +10731,6 @@ required_downlevel_flags . map_err ( -binding_model -: -: BindGroupLayoutEntryError : : @@ -10590,6 +10800,18 @@ _ ( ) ; +let +label += +label +. +to_hal +( +self +. +instance_flags +) +; hal_bindings . sort_by_key @@ -10611,15 +10833,6 @@ hal BindGroupLayoutDescriptor { label -: -label -. -to_hal -( -self -. -instance_flags -) flags : bgl_flags @@ -10638,6 +10851,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_bind_group_layout ( & @@ -10736,52 +10957,39 @@ TooManyBindings ; Ok ( -binding_model -: -: BindGroupLayout { -device_id -: -Stored -{ -value -: -id -: +raw : -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} -multi_ref_count +info : -MultiRefCount +ResourceInfo : : new ( -) -inner -: -BglOrDuplicate -: -: -Inner +label +. +unwrap_or ( -BindGroupLayoutInner -{ -raw +" +< +BindGroupLayoyt +> +" +) +) dynamic_count : entry_map @@ -10822,7 +11030,7 @@ label : label . -borrow_or_default +unwrap_or_default ( ) . @@ -10832,8 +11040,10 @@ to_string } ) } +pub +( +crate ) -} fn create_buffer_binding < @@ -10841,12 +11051,6 @@ create_buffer_binding a > ( -device_id -: -id -: -: -DeviceId bb : & @@ -10871,6 +11075,9 @@ mut Vec < BufferInitTrackerAction +< +A +> > dynamic_binding_info : @@ -11178,32 +11385,6 @@ buffer_id ) ? ; -if -buffer -. -device_id -. -value -. -0 -! -= -device_id -{ -return -Err -( -DeviceError -: -: -WrongDevice -. -into -( -) -) -; -} check_buffer_usage ( buffer @@ -11519,11 +11700,13 @@ buffer . initialization_status . -create_action +read ( -bb +) . -buffer_id +create_action +( +buffer bb . offset @@ -11564,42 +11747,20 @@ size } ) } +pub +( +crate +) fn create_texture_binding ( -device_id -: -id -: -: -DeviceId view : & -resource -: -: TextureView < A > -texture_guard -: -& -Storage -< -resource -: -: -Texture -< -A -> -id -: -: -TextureId -> internal_use : hal @@ -11627,6 +11788,9 @@ mut Vec < TextureInitTrackerAction +< +A +> > ) - @@ -11641,6 +11805,38 @@ binding_model CreateBindGroupError > { +let +texture += +view +. +parent +. +read +( +) +; +let +texture_id += +texture +. +as_ref +( +) +. +unwrap +( +) +. +as_info +( +) +. +id +( +) +; / / Careful @@ -11675,21 +11871,13 @@ textures . add_single ( -texture_guard -view -. -parent_id -. -value -. -0 -view -. -parent_id +texture . -ref_count +as_ref +( +) . -clone +unwrap ( ) Some @@ -11715,13 +11903,7 @@ CreateBindGroupError : InvalidTexture ( -view -. -parent_id -. -value -. -0 +texture_id ) ) ? @@ -11729,14 +11911,28 @@ value if texture . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -device_id +view +. +device +. +as_info +( +) +. +id +( +) { return Err @@ -11769,15 +11965,13 @@ push ( TextureInitTrackerAction { -id +texture : -view -. -parent_id -. -value +texture . -0 +clone +( +) range : TextureInitRange @@ -11857,45 +12051,27 @@ beforehand . pub ( -super +crate ) fn -create_bind_group -< -G -: -GlobalIdentityHandlerFactory -> +create_bind_group ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> layout : & -binding_model -: -: +Arc +< BindGroupLayout < A > -layout_id -: -id -: -: -Valid -< -id -: -: -BindGroupLayoutId > desc : @@ -11910,21 +12086,6 @@ hub Hub < A -G -> -token -: -& -mut -Token -< -binding_model -: -: -BindGroupLayout -< -A -> > ) - @@ -11999,10 +12160,6 @@ expected = layout . -assume_deduplicated -( -) -. entries . len @@ -12131,11 +12288,7 @@ new ) ; let -( buffer_guard -mut -token -) = hub . @@ -12143,37 +12296,10 @@ buffers . read ( -token -) -; -let -( -texture_guard -mut -token -) -= -hub -. -textures -. -read -( -& -mut -token ) ; -/ -/ -skip -token let -( texture_view_guard -mut -token -) = hub . @@ -12181,16 +12307,10 @@ texture_views . read ( -& -mut -token ) ; let -( sampler_guard -_ -) = hub . @@ -12198,9 +12318,6 @@ samplers . read ( -& -mut -token ) ; let @@ -12308,10 +12425,6 @@ decl = layout . -assume_deduplicated -( -) -. entries . get @@ -12362,7 +12475,6 @@ Self : create_buffer_binding ( -self_id bb binding decl @@ -12470,7 +12582,6 @@ Self : create_buffer_binding ( -self_id bb binding decl @@ -12567,14 +12678,26 @@ id if sampler . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -12733,10 +12856,11 @@ hal_samplers . push ( -& sampler . raw +( +) ) ; ( @@ -12856,14 +12980,26 @@ id if sampler . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -12883,10 +13019,11 @@ hal_samplers . push ( -& sampler . raw +( +) ) ; } @@ -12960,10 +13097,7 @@ Self : create_texture_binding ( -self_id view -& -texture_guard internal_use pub_usage & @@ -12995,10 +13129,11 @@ TextureBinding { view : -& view . raw +( +) usage : internal_use @@ -13119,10 +13254,7 @@ Self : create_texture_binding ( -self_id view -& -texture_guard internal_use pub_usage & @@ -13145,10 +13277,11 @@ TextureBinding { view : -& view . raw +( +) usage : internal_use @@ -13258,15 +13391,6 @@ binding } } let -layout_inner -= -layout -. -assume_deduplicated -( -) -; -let hal_desc = hal @@ -13288,10 +13412,11 @@ instance_flags ) layout : -& -layout_inner +layout . raw +( +) entries : & @@ -13319,6 +13444,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_bind_group ( & @@ -13335,22 +13468,6 @@ from ? } ; -/ -/ -manually -add -a -dependency -on -BGL -layout -. -multi_ref_count -. -inc -( -) -; Ok ( binding_model @@ -13359,33 +13476,28 @@ binding_model BindGroup { raw -device_id -: -Stored -{ -value -: -id -: : -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard +clone +( +) +layout +: +layout . -add_ref +clone ( ) -} -layout_id -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -13400,8 +13512,32 @@ borrow_or_default ) used used_buffer_ranges +: +RwLock +: +: +new +( +used_buffer_ranges +) +used_texture_ranges +: +RwLock +: +: +new +( used_texture_ranges +) +dynamic_binding_info +: +RwLock +: +: +new +( dynamic_binding_info +) / / collect @@ -13413,7 +13549,7 @@ BGL iteration late_buffer_binding_sizes : -layout_inner +layout . entries . @@ -13444,6 +13580,10 @@ collect } ) } +pub +( +crate +) fn check_array_binding ( @@ -13607,6 +13747,10 @@ Ok ) ) } +pub +( +crate +) fn texture_use_parameters ( @@ -13623,12 +13767,6 @@ BindGroupLayoutEntry view : & -crate -: -: -resource -: -: TextureView < A @@ -14376,19 +14514,18 @@ expected } pub ( -super +crate ) fn create_pipeline_layout ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> desc : & @@ -14401,9 +14538,6 @@ bgl_guard & Storage < -binding_model -: -: BindGroupLayout < A @@ -14733,14 +14867,15 @@ iter ) { let -Some +Ok ( bind_group_layout ) = -try_get_bind_group_layout -( bgl_guard +. +get +( id ) else @@ -14762,14 +14897,26 @@ id if bind_group_layout . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -14792,10 +14939,6 @@ merge & bind_group_layout . -assume_deduplicated -( -) -. count_validator ) ; @@ -14836,11 +14979,10 @@ map & id | -{ -& -try_get_bind_group_layout -( bgl_guard +. +get +( id ) . @@ -14848,12 +14990,9 @@ unwrap ( ) . -assume_deduplicated +raw ( ) -. -raw -} ) . collect @@ -14921,6 +15060,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_pipeline_layout ( & @@ -14945,32 +15092,21 @@ binding_model PipelineLayout { raw -device_id -: -Stored -{ -value -: -id -: : -Valid +Some ( -self_id +raw ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -14983,7 +15119,7 @@ borrow_or_default ( ) ) -bind_group_layout_ids +bind_group_layouts : desc . @@ -14999,43 +15135,20 @@ map & id | -{ -/ -/ -manually -add -a -dependency -to -BGL -let -( -id -layout -) -= -get_bind_group_layout -( bgl_guard -id -: -: -Valid +. +get ( id ) -) -; -layout . -multi_ref_count +unwrap +( +) . -inc +clone ( ) -; -id -} ) . collect @@ -15088,17 +15201,20 @@ pipeline layout ) . +pub +( +crate +) fn derive_pipeline_layout ( -& self -self_id -: -id -: : -DeviceId +& +Arc +< +Self +> implicit_context : Option @@ -15121,30 +15237,29 @@ hal MAX_BIND_GROUPS } > -bgl_guard +bgl_registry : & -mut -Storage +Registry < -binding_model +id : : +BindGroupLayoutId BindGroupLayout < A > -id -: -: -BindGroupLayoutId > -pipeline_layout_guard +pipeline_layout_registry : & -mut -Storage +Registry < +id +: +: +PipelineLayoutId binding_model : : @@ -15152,10 +15267,6 @@ PipelineLayout < A > -id -: -: -PipelineLayoutId > ) - @@ -15317,21 +15428,30 @@ zip derived_group_layouts ) { +let +bgl += match -Device -: -: +self +. deduplicate_bind_group_layout ( -self_id & map -bgl_guard +& +bgl_registry +. +read +( +) ) { Some ( +( dedup_id +_ +) ) = > @@ -15341,26 +15461,35 @@ bgl_id = dedup_id ; +None } None = > -{ -let -bgl -= +Some +( self . create_bind_group_layout ( -self_id & None map ) ? +) +} ; -bgl_guard +if +let +Some +( +bgl +) += +bgl +{ +bgl_registry . force_replace ( @@ -15371,8 +15500,6 @@ bgl ; } } -; -} let layout_desc = @@ -15425,14 +15552,18 @@ self . create_pipeline_layout ( -self_id & layout_desc -bgl_guard +& +bgl_registry +. +read +( +) ) ? ; -pipeline_layout_guard +pipeline_layout_registry . force_replace ( @@ -15451,24 +15582,18 @@ root_id } pub ( -super +crate ) fn create_compute_pipeline -< -G -: -GlobalIdentityHandlerFactory -> ( -& self -self_id -: -id -: : -DeviceId +& +Arc +< +Self +> desc : & @@ -15488,15 +15613,6 @@ hub Hub < A -G -> -token -: -& -mut -Token -< -Self > ) - @@ -15518,54 +15634,6 @@ CreateComputePipelineError { / / -TODO -: -only -lock -mutable -if -the -layout -is -derived -let -( -mut -pipeline_layout_guard -mut -token -) -= -hub -. -pipeline_layouts -. -write -( -token -) -; -let -( -mut -bgl_guard -mut -token -) -= -hub -. -bind_group_layouts -. -write -( -& -mut -token -) -; -/ -/ This has to @@ -15601,6 +15669,18 @@ ids = implicit_context { +let +mut +pipeline_layout_guard += +hub +. +pipeline_layouts +. +write +( +) +; pipeline_layout_guard . insert_error @@ -15611,6 +15691,18 @@ root_id IMPLICIT_FAILURE ) ; +let +mut +bgl_guard += +hub +. +bind_group_layouts +. +write +( +) +; for & bgl_id @@ -15697,27 +15789,12 @@ default ) ; let -( -shader_module_guard -_ -) +shader_module = hub . shader_modules . -read -( -& -mut -token -) -; -let -shader_module -= -shader_module_guard -. get ( desc @@ -15745,14 +15822,26 @@ InvalidModule if shader_module . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -15781,6 +15870,17 @@ ShaderStages COMPUTE ; let +pipeline_layout_guard += +hub +. +pipeline_layouts +. +read +( +) +; +let provided_layouts = match @@ -15822,9 +15922,6 @@ CreateComputePipelineError InvalidLayout ) ? -& -* -bgl_guard ) ) None @@ -15941,22 +16038,32 @@ self . derive_pipeline_layout ( -self_id implicit_context derived_group_layouts & -mut -* -bgl_guard +hub +. +bind_group_layouts & -mut -* -pipeline_layout_guard +hub +. +pipeline_layouts ) ? } ; let +pipeline_layout_guard += +hub +. +pipeline_layouts +. +read +( +) +; +let layout = pipeline_layout_guard @@ -15984,14 +16091,26 @@ InvalidLayout if layout . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -16018,9 +16137,6 @@ make_late_sized_buffer_groups & shader_binding_sizes layout -& -* -bgl_guard ) ; let @@ -16045,10 +16161,11 @@ instance_flags ) layout : -& layout . raw +( +) stage : hal @@ -16069,10 +16186,11 @@ as_ref ) module : -& shader_module . raw +( +) } } ; @@ -16085,6 +16203,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_compute_pipeline ( & @@ -16194,56 +16320,32 @@ pipeline ComputePipeline { raw -layout_id -: -Stored -{ -value -: -id -: : -Valid +Some ( -pipeline_layout_id +raw ) -ref_count +layout : layout . -life_guard -. -add_ref -( -) -} -device_id -: -Stored -{ -value -: -id -: -: -Valid +clone ( -self_id ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} +_shader_module +: +shader_module late_sized_buffer_groups -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -16265,24 +16367,18 @@ pipeline } pub ( -super +crate ) fn create_render_pipeline -< -G -: -GlobalIdentityHandlerFactory -> ( -& self -self_id -: -id : -: -DeviceId +& +Arc +< +Self +> adapter : & @@ -16309,15 +16405,6 @@ hub Hub < A -G -> -token -: -& -mut -Token -< -Self > ) - @@ -16345,52 +16432,15 @@ TextureFormatFeatureFlags as Tfff ; -/ -/ -TODO -: -only -lock -mutable -if -the -layout -is -derived -let -( -mut -pipeline_layout_guard -mut -token -) -= -hub -. -pipeline_layouts -. -write -( -token -) -; let -( mut -bgl_guard -mut -token -) +shader_modules = -hub -. -bind_group_layouts -. -write +Vec +: +: +new ( -& -mut -token ) ; / @@ -16430,6 +16480,42 @@ ids = implicit_context { +/ +/ +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 @@ -16704,7 +16790,7 @@ blend log : : -info +debug ! ( " @@ -18311,10 +18397,7 @@ sc } ; let -( shader_module_guard -_ -) = hub . @@ -18322,9 +18405,6 @@ shader_modules . read ( -& -mut -token ) ; let @@ -18398,14 +18478,26 @@ InvalidModule if shader_module . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -18421,6 +18513,28 @@ into ) ; } +shader_modules +. +push +( +shader_module +. +clone +( +) +) +; +let +pipeline_layout_guard += +hub +. +pipeline_layouts +. +read +( +) +; let provided_layouts = @@ -18464,14 +18578,26 @@ InvalidLayout if pipeline_layout . -device_id +device . -value +as_info +( +) . -0 +id +( +) ! = -self_id +self +. +as_info +( +) +. +id +( +) { return Err @@ -18495,9 +18621,6 @@ Device get_introspection_bind_group_layouts ( pipeline_layout -& -* -bgl_guard ) ) } @@ -18607,10 +18730,11 @@ ProgrammableStage { module : -& shader_module . raw +( +) entry_point : stage @@ -18691,7 +18815,29 @@ StageError InvalidModule } ) -? +? +; +shader_modules +. +push +( +shader_module +. +clone +( +) +) +; +let +pipeline_layout_guard += +hub +. +pipeline_layouts +. +read +( +) ; let provided_layouts @@ -18721,6 +18867,10 @@ get pipeline_layout_id ) . +as_ref +( +) +. map_err ( | @@ -18735,9 +18885,6 @@ CreateRenderPipelineError InvalidLayout ) ? -& -* -bgl_guard ) ) None @@ -18911,10 +19058,11 @@ ProgrammableStage { module : -& shader_module . raw +( +) entry_point : fragment @@ -19084,7 +19232,7 @@ _ log : : -info +warn ! ( " @@ -19222,17 +19370,16 @@ self . derive_pipeline_layout ( -self_id implicit_context derived_group_layouts & -mut -* -bgl_guard +hub +. +bind_group_layouts & -mut -* -pipeline_layout_guard +hub +. +pipeline_layouts ) ? } @@ -19240,6 +19387,18 @@ pipeline_layout_guard let layout = +{ +let +pipeline_layout_guard += +hub +. +pipeline_layouts +. +read +( +) +; pipeline_layout_guard . get @@ -19261,6 +19420,11 @@ CreateRenderPipelineError InvalidLayout ) ? +. +clone +( +) +} ; / / @@ -19384,10 +19548,8 @@ make_late_sized_buffer_groups ( & shader_binding_sizes -layout & -* -bgl_guard +layout ) ; let @@ -19412,10 +19574,11 @@ instance_flags ) layout : -& layout . raw +( +) vertex_buffers : & @@ -19458,6 +19621,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. create_render_pipeline ( & @@ -19829,53 +20000,29 @@ pipeline RenderPipeline { raw -layout_id -: -Stored -{ -value -: -id -: : -Valid +Some ( -pipeline_layout_id +raw ) -ref_count +layout : layout . -life_guard -. -add_ref -( -) -} -device_id -: -Stored -{ -value -: -id -: -: -Valid +clone ( -self_id ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} pass_context +_shader_modules +: +shader_modules flags strip_index_format : @@ -19886,9 +20033,9 @@ primitive strip_index_format vertex_steps late_sized_buffer_groups -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -19910,7 +20057,7 @@ pipeline } pub ( -super +crate ) fn describe_format_features @@ -20043,7 +20190,7 @@ features } pub ( -super +crate ) fn wait_for_submit @@ -20053,14 +20200,6 @@ self submission_index : SubmissionIndex -token -: -& -mut -Token -< -Self -> ) - > @@ -20072,6 +20211,30 @@ WaitIdleError > { let +guard += +self +. +fence +. +read +( +) +; +let +fence += +guard +. +as_ref +( +) +. +unwrap +( +) +; +let last_done_index = unsafe @@ -20080,11 +20243,16 @@ self . raw . -get_fence_value +as_ref ( -& -self +) +. +unwrap +( +) . +get_fence_value +( fence ) . @@ -20127,11 +20295,16 @@ self . raw . -wait +as_ref ( -& -self +) +. +unwrap +( +) . +wait +( fence submission_index ! @@ -20148,6 +20321,11 @@ from ? } ; +drop +( +guard +) +; let closures = @@ -20155,16 +20333,26 @@ self . lock_life ( -token ) . triage_submissions ( submission_index -& self . command_allocator +. +lock +( +) +. +as_mut +( +) +. +unwrap +( +) ) ; assert @@ -20196,19 +20384,18 @@ Ok } pub ( -super +crate ) fn create_query_set ( -& self -self_id : -id -: -: -DeviceId +& +Arc +< +Self +> desc : & @@ -20221,9 +20408,6 @@ QuerySetDescriptor > Result < -resource -: -: QuerySet < A @@ -20386,18 +20570,19 @@ instance_flags ; Ok ( -resource -: -: QuerySet { raw : +Some +( unsafe { self . raw +( +) . create_query_set ( @@ -20409,32 +20594,17 @@ unwrap ( ) } -device_id -: -Stored -{ -value -: -id -: -: -Valid -( -self_id ) -ref_count +device : self . -life_guard -. -add_ref +clone ( ) -} -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -20463,31 +20633,9 @@ crate ) fn lose -< -' -this -' -token -: -' -this -> ( & -' -this -mut self -token -: -& -mut -Token -< -' -token -Self -> message : & @@ -20547,8 +20695,15 @@ submitted self . valid -= +. +store +( false +Ordering +: +: +Release +) ; / / @@ -20563,40 +20718,29 @@ lost promise . let -mut -life_tracker +closure = self . lock_life ( -token -) -; -if -life_tracker -. -device_lost_closure -. -is_some -( ) -{ -let -device_lost_closure -= -life_tracker . device_lost_closure . take ( ) -. -unwrap +; +if +let +Some ( +device_lost_closure ) -; += +closure +{ device_lost_closure . call @@ -20708,52 +20852,11 @@ pub crate ) fn -destroy_buffer -( -& -self -buffer -: -Buffer -< -A -> -) -{ -if -let -Some -( -raw -) -= -buffer -. -raw -{ -unsafe -{ -self -. -raw -. -destroy_buffer -( -raw -) -; -} -} -} -pub -( -crate -) -fn destroy_command_buffer ( & self +mut cmd_buf : command @@ -20771,7 +20874,7 @@ baked = cmd_buf . -into_baked +extract_baked_commands ( ) ; @@ -20799,6 +20902,14 @@ self . raw . +as_ref +( +) +. +unwrap +( +) +. destroy_command_encoder ( baked @@ -20832,7 +20943,6 @@ fn prepare_to_die ( & -mut self ) { @@ -20840,19 +20950,19 @@ self . pending_writes . -deactivate +lock ( ) -; -let -mut -life_tracker -= -self . -life_tracker +as_mut +( +) . -lock +unwrap +( +) +. +deactivate ( ) ; @@ -20862,6 +20972,14 @@ current_index self . active_submission_index +. +load +( +Ordering +: +: +Relaxed +) ; if let @@ -20872,15 +20990,44 @@ error = unsafe { +let +fence += self . -raw +fence . -wait +read ( -& +) +; +let +fence += +fence +. +as_ref +( +) +. +unwrap +( +) +; self . +raw +. +as_ref +( +) +. +unwrap +( +) +. +wait +( fence current_index CLEANUP_WAIT_MS @@ -20911,6 +21058,16 @@ error ; } let +mut +life_tracker += +self +. +lock_life +( +) +; +let _ = life_tracker @@ -20918,20 +21075,27 @@ life_tracker triage_submissions ( current_index -& self . command_allocator +. +lock +( +) +. +as_mut +( +) +. +unwrap +( +) ) ; life_tracker . cleanup ( -& -self -. -raw ) ; # @@ -20946,86 +21110,16 @@ trace ) ] { +* self . trace -= -None -; -} -} -pub -( -crate -) -fn -dispose -( -self -) -{ -self -. -pending_writes -. -dispose -( -& -self -. -raw -) -; -self -. -command_allocator -. -into_inner -( -) -. -dispose -( -& -self -. -raw -) -; -unsafe -{ -self -. -raw -. -destroy_buffer -( -self -. -zero_buffer -) -; -self -. -raw -. -destroy_fence -( -self -. -fence -) -; -self -. -raw . -exit +lock ( -self -. -queue ) += +None ; } } @@ -21036,13 +21130,10 @@ A : HalApi > -crate -: -: -resource -: -: Resource +< +DeviceId +> for Device < @@ -21052,29 +21143,51 @@ A const TYPE : -& -' -static -str +ResourceType = " Device " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +DeviceId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +DeviceId +> { & +mut self . -life_guard +info } } diff --git a/third_party/rust/wgpu-core/src/error.rs b/third_party/rust/wgpu-core/src/error.rs index 018969060f18f..00e1eb9a3b333 100644 --- a/third_party/rust/wgpu-core/src/error.rs +++ b/third_party/rust/wgpu-core/src/error.rs @@ -162,7 +162,7 @@ str label_value : & -str +String ) { if diff --git a/third_party/rust/wgpu-core/src/global.rs b/third_party/rust/wgpu-core/src/global.rs index bc1cc6260a354..c773b366d7a8a 100644 --- a/third_party/rust/wgpu-core/src/global.rs +++ b/third_party/rust/wgpu-core/src/global.rs @@ -1,4 +1,25 @@ use +std +: +: +{ +marker +: +: +PhantomData +sync +: +: +Arc +} +; +use +wgt +: +: +Backend +; +use crate : : @@ -15,6 +36,9 @@ HubReport Hubs } id +: +: +SurfaceId identity : : @@ -29,14 +53,14 @@ Surface registry : : +{ Registry +RegistryReport +} storage : : -{ Element -StorageReport -} } ; # @@ -44,6 +68,8 @@ StorageReport derive ( Debug +PartialEq +Eq ) ] pub @@ -53,7 +79,7 @@ GlobalReport pub surfaces : -StorageReport +RegistryReport # [ cfg @@ -180,6 +206,238 @@ Option HubReport > } +impl +GlobalReport +{ +pub +fn +surfaces +( +& +self +) +- +> +& +RegistryReport +{ +& +self +. +surfaces +} +pub +fn +hub_report +( +& +self +backend +: +Backend +) +- +> +& +HubReport +{ +match +backend +{ +# +[ +cfg +( +all +( +feature += +" +vulkan +" +not +( +target_arch += +" +wasm32 +" +) +) +) +] +Backend +: +: +Vulkan += +> +self +. +vulkan +. +as_ref +( +) +. +unwrap +( +) +# +[ +cfg +( +all +( +feature += +" +metal +" +any +( +target_os += +" +macos +" +target_os += +" +ios +" +) +) +) +] +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 +" +) +} +} +} pub struct Global @@ -198,12 +456,8 @@ surfaces : Registry < -Surface -id -: -: SurfaceId -G +Surface > pub ( @@ -212,6 +466,9 @@ crate hubs : Hubs +_phantom +: +PhantomData < G > @@ -284,9 +541,6 @@ without_backend ( & factory -" -Surface -" ) hubs : @@ -298,6 +552,9 @@ new & factory ) +_phantom +: +PhantomData } } / @@ -387,9 +644,6 @@ without_backend ( & factory -" -Surface -" ) hubs : @@ -401,6 +655,9 @@ new & factory ) +_phantom +: +PhantomData } } / @@ -527,9 +784,6 @@ without_backend ( & factory -" -Surface -" ) hubs : @@ -541,6 +795,9 @@ new & factory ) +_phantom +: +PhantomData } } pub @@ -561,20 +818,6 @@ _dummy ) { let -mut -surface_guard -= -self -. -surfaces -. -data -. -write -( -) -; -let hub = A @@ -585,6 +828,17 @@ hub self ) ; +let +surfaces_locked += +self +. +surfaces +. +read +( +) +; / / this @@ -601,8 +855,7 @@ hub clear ( & -mut -surface_guard +surfaces_locked false ) ; @@ -626,12 +879,6 @@ self . surfaces . -data -. -read -( -) -. generate_report ( ) @@ -920,21 +1167,19 @@ info ! ( " -Dropping +Destroying Global " ) ; let mut -surface_guard +surfaces_locked = self . surfaces . -data -. write ( ) @@ -980,8 +1225,7 @@ vulkan clear ( & -mut -surface_guard +surfaces_locked true ) ; @@ -1023,8 +1267,7 @@ metal clear ( & -mut -surface_guard +surfaces_locked true ) ; @@ -1054,8 +1297,7 @@ dx12 clear ( & -mut -surface_guard +surfaces_locked true ) ; @@ -1085,8 +1327,7 @@ dx11 clear ( & -mut -surface_guard +surfaces_locked true ) ; @@ -1112,8 +1353,7 @@ gl clear ( & -mut -surface_guard +surfaces_locked true ) ; @@ -1125,7 +1365,7 @@ surfaces for element in -surface_guard +surfaces_locked . map . @@ -1142,12 +1382,27 @@ Element : Occupied ( -surface +arc_surface _ ) = element { +if +let +Ok +( +surface +) += +Arc +: +: +try_unwrap +( +arc_surface +) +{ self . instance @@ -1158,6 +1413,26 @@ surface ) ; } +else +{ +panic +! +( +" +Surface +cannot +be +destroyed +because +is +still +in +use +" +) +; +} +} } } } diff --git a/third_party/rust/wgpu-core/src/hal_api.rs b/third_party/rust/wgpu-core/src/hal_api.rs index 746cbe21956f4..9cef42b58424e 100644 --- a/third_party/rust/wgpu-core/src/hal_api.rs +++ b/third_party/rust/wgpu-core/src/hal_api.rs @@ -2,7 +2,10 @@ use wgt : : +{ Backend +WasmNotSendSync +} ; use crate @@ -39,6 +42,11 @@ hal : : Api ++ +' +static ++ +WasmNotSendSync { const VARIANT @@ -104,7 +112,6 @@ G Hub < Self -G > ; fn @@ -126,27 +133,6 @@ Self > > ; -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -; } impl HalApi @@ -248,7 +234,6 @@ G Hub < Self -G > { unimplemented @@ -290,37 +275,6 @@ api " ) } -fn -get_surface_mut -( -_ -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -unimplemented -! -( -" -called -empty -api -" -) -} } # [ @@ -457,7 +411,6 @@ G Hub < Self -G > { & @@ -488,38 +441,9 @@ Self { surface . -vulkan +raw . -as_ref -( -) -} -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -surface -. -vulkan -. -as_mut +downcast_ref ( ) } @@ -664,7 +588,6 @@ G Hub < Self -G > { & @@ -695,38 +618,9 @@ Self { surface . -metal -. -as_ref -( -) -} -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -surface -. -metal +raw . -as_mut +downcast_ref ( ) } @@ -859,7 +753,6 @@ G Hub < Self -G > { & @@ -890,38 +783,9 @@ Self { surface . -dx12 -. -as_ref -( -) -} -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -surface -. -dx12 +raw . -as_mut +downcast_ref ( ) } @@ -1054,7 +918,6 @@ G Hub < Self -G > { & @@ -1085,38 +948,9 @@ Self { surface . -dx11 +raw . -as_ref -( -) -} -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -surface -. -dx11 -. -as_mut +downcast_ref ( ) } @@ -1255,7 +1089,6 @@ G Hub < Self -G > { & @@ -1286,38 +1119,9 @@ Self { surface . -gl -. -as_ref -( -) -} -fn -get_surface_mut -( -surface -: -& -mut -Surface -) -- -> -Option -< -& -mut -HalSurface -< -Self -> -> -{ -surface -. -gl +raw . -as_mut +downcast_ref ( ) } diff --git a/third_party/rust/wgpu-core/src/hub.rs b/third_party/rust/wgpu-core/src/hub.rs index b54250ef1ed71..d9ec97d036127 100644 --- a/third_party/rust/wgpu-core/src/hub.rs +++ b/third_party/rust/wgpu-core/src/hub.rs @@ -97,9 +97,7 @@ denotes but also a -[ Backend -] indicating which wgpu @@ -462,259 +460,34 @@ job of an [ -IdentityHandler -] -implementation -which -has -an -associated -type -[ -Input -] -saying -what -type -of -id_in -values -it -accepts -and -a -[ -process -] -method -that -turns -such -values -into -true -identifiers -of -type -I -. -There -are -two -kinds -of -IdentityHandler -s +crate +: +: +identity +: : -- -Users -that -want -wgpu_core -to -assign -ids -generally -use -[ IdentityManager ] -( -[ -wrapped -in -a -mutex -] -) -. -Its -Input -type -is -( -) -and -it -tracks -assigned -ids -and -generation -numbers -as -necessary -. -( -This -is -what -wgpu -does -. -) -- -Users -that -want -to -assign -ids -themselves -use -an -IdentityHandler -whose -Input -type -is -I -itself -and -whose -process -method -simply -passes -the -id_in -argument -through -unchanged -. -For -example -the -player -crate -uses -an -IdentityPassThrough -type -whose -process -method -simply -adjusts -the -id -' -s -backend -( -since -recordings -can -be -replayed -on -a -different -backend -than -the -one -they -were -created -on -) but -passes -the -rest -of -the -id -' -s -content -through -unchanged -. -Because -an -IdentityHandler -< -I -> -can only +if +the +IdentityHandlerFactory create +it +and +then +generated +by +it +otherwise ids -for -a -single -resource -type -I -constructing -a -[ -Global -] -entails -constructing -a -separate -IdentityHandler -< -I -> -for -each -resource -type -I -that -the -Global will -manage -: -an -IdentityHandler -< -DeviceId -> -an -IdentityHandler -< -TextureId -> -and -so -on -. -The -[ -Global -: -: -new -] -function -could -simply -take -a -large -collection -of -IdentityHandler -< -I -> -implementations -as -arguments -but -that -would be -ungainly +received +from +outside . -Instead Global : : @@ -733,6 +506,12 @@ trait which extends [ +crate +: +: +identity +: +: IdentityHandlerFactory < I @@ -756,120 +535,30 @@ method that constructs an -IdentityHandler -< -I -> +crate +: +: +identity +: +: +IdentityManager for the Global to use -. -What -this -means -is -that -the -types -of -resource -creation -functions -' -id_in -arguments -depend -on -the -Global -' -s -G -type -parameter -. -A -Global -< -G -> -' -s -IdentityHandler -< -I -> -implementation -is -: -ignore -< -G -as -IdentityHandlerFactory -< -I -> -> -: -: -Filter -where -Filter -is -an -associated -type -of -the -IdentityHandlerFactory -trait -. -Thus -its -id_in -type -is -: -ignore -< -< -G -as -IdentityHandlerFactory -< -I -> -> -: -: -Filter -as -IdentityHandler -< -I -> -> -: -: -Input -The -[ -Input -< -G -I -> -] -type -is -an -alias -for -this -construction +if +ids +should +be +generated +by +wgpu +or +will +return +None +otherwise . # # @@ -1188,42 +877,6 @@ as well . [ -Backend -] -: -wgt -: -: -Backend -[ -Global -] -: -crate -: -: -global -: -: -Global -[ -Global -: -: -new -] -: -crate -: -: -global -: -: -Global -: -: -new -[ gfx_select ] : @@ -1232,17 +885,6 @@ crate : gfx_select [ -IdentityHandler -] -: -crate -: -: -identity -: -: -IdentityHandler -[ Input ] : @@ -1252,7 +894,7 @@ crate identity : : -IdentityHandler +IdentityHandlerFactory : : Input @@ -1266,7 +908,7 @@ crate identity : : -IdentityHandler +IdentityManager : : process @@ -1291,11 +933,6 @@ a mutex ] : -. -. -/ -identity -/ trait . IdentityHandler @@ -1335,46 +972,6 @@ TR / webgpu / -[ -IdentityManager -] -: -crate -: -: -identity -: -: -IdentityManager -[ -Input -< -G -I -> -] -: -crate -: -: -identity -: -: -Input -[ -IdentityHandlerFactory -< -I -> -] -: -crate -: -: -identity -: -: -IdentityHandlerFactory * / use @@ -1400,7 +997,13 @@ RenderBundle device : : +{ +queue +: +: +Queue Device +} hal_api : : @@ -1416,7 +1019,6 @@ instance { Adapter HalSurface -Instance Surface } pipeline @@ -1430,7 +1032,10 @@ ShaderModule registry : : +{ Registry +RegistryReport +} resource : : @@ -1440,7 +1045,6 @@ QuerySet Sampler StagingBuffer Texture -TextureClearMode TextureView } storage @@ -1449,73 +1053,150 @@ storage { Element Storage -StorageReport } } ; use -wgt +std : : -{ -strict_assert_eq -strict_assert_ne -} +fmt +: +: +Debug ; # [ -cfg -( -any +derive ( -debug_assertions -feature -= -" -strict_asserts -" -) +Debug +PartialEq +Eq ) ] -use -std +pub +struct +HubReport +{ +pub +adapters : +RegistryReport +pub +devices : -cell +RegistryReport +pub +queues : +RegistryReport +pub +pipeline_layouts : -Cell -; -use -std +RegistryReport +pub +shader_modules : +RegistryReport +pub +bind_group_layouts : -{ -fmt +RegistryReport +pub +bind_groups : +RegistryReport +pub +command_buffers : -Debug -marker +RegistryReport +pub +render_bundles +: +RegistryReport +pub +render_pipelines +: +RegistryReport +pub +compute_pipelines +: +RegistryReport +pub +query_sets +: +RegistryReport +pub +buffers +: +RegistryReport +pub +textures +: +RegistryReport +pub +texture_views : +RegistryReport +pub +samplers : -PhantomData +RegistryReport } -; -/ -/ -/ -Type -system -for -enforcing -the -lock -order -on +impl +HubReport +{ +pub +fn +is_empty +( +& +self +) +- +> +bool +{ +self +. +adapters +. +is_empty +( +) +} +} +# [ -Hub +allow +( +rustdoc +: +: +private_intra_doc_links +) +] +/ +/ +/ +All +the +resources +for +a +particular +backend +in +a +[ +crate +: +: +global +: +: +Global ] -fields . / / @@ -1523,32 +1204,33 @@ fields / / / -If +To +obtain +global +' +s +Hub +for +some +[ +HalApi +] +backend type A -implements -Access -< -B -> -that -means -we -are -allowed -to / / / -proceed -with -locking -resource -B -after -we -lock +call +[ A +: +: +hub +( +global +) +] . / / @@ -1556,320 +1238,163 @@ A / / / -The -implementations -of -Access -basically -describe -the -edges -in -an -/ -/ -/ -acyclic -directed -graph -of -lock -transitions -. -As -long -as -it -doesn -' -t -have +# +# +Locking / / / -cycles -any -number -of -threads -can -acquire -locks -along -paths -through / / / -the -graph -without -deadlock -. -That +Each +field +in +Hub is -if -you -look -at -each -thread -' -s -/ -/ -/ -lock -acquisitions -as -steps -along a -path -in +[ +Registry +] +holding +all the -graph -then -because +values +of +a / / / -there -are -no -cycles -in -the -graph -there -must -always -be -some -thread +particular +type +of +resource +all +protected +by +a +single +RwLock +. / / / -that -is -able +So +for +example to +access +any +[ +Buffer +] +you +must acquire -its -next -lock -or -that -is -about -to -release +a +read / / / -a lock -. -( -Assume -that -no -thread -just -sits on -its -locks -forever +the +Hub +s +entire +buffers +registry . -) -/ -/ -/ +The +lock +guard / / / -Locks -must -be -acquired -in +gives +you +access +to the -following -order -: -/ -/ -/ -/ -/ -/ -- +Registry +' +s [ -Adapter +Storage ] +which +you +can / / / -- -[ -Device -] +then +index +with +the +buffer +' +s +id +. +( +Yes +this +design +causes / / / -- +contention +; +see [ -CommandBuffer +# +2272 ] +. +) / / / -- -[ -RenderBundle -] -/ -/ -/ -- -[ -PipelineLayout -] -/ -/ -/ -- -[ -BindGroupLayout -] -/ -/ -/ -- -[ -BindGroup -] -/ -/ -/ -- -[ -ComputePipeline -] -/ -/ -/ -- -[ -RenderPipeline -] -/ -/ -/ -- -[ -ShaderModule -] -/ -/ -/ -- -[ -Buffer -] -/ -/ -/ -- -[ -StagingBuffer -] -/ -/ -/ -- -[ -Texture -] -/ -/ -/ -- -[ -TextureView -] -/ -/ -/ -- -[ -Sampler -] -/ -/ -/ -- -[ -QuerySet -] / / / +But +most +wgpu +operations +require +access +to +several +different / / / -That -is +kinds +of +resource +so you -may -only -acquire -a -new -lock +often +need +to +hold +locks on -a -Hub -field -if -it +several / / / -appears -in -the -list -after -all -the -other +different fields -you -' -re -already -/ -/ -/ -holding -locks -for -. -When -you -are -holding -no -locks -you -can -start -/ -/ -/ -anywhere +of +your +[ +Hub +] +simultaneously . / / @@ -1877,367 +1402,305 @@ anywhere / / / -It -' -s -fine -to -add -more -Access -implementations -as -needed -as -long -/ -/ -/ -as -you -do -not -introduce -a -cycle -. -In -other -words -as -long -as +Inside +the +Registry there +are +Arc +< +T +> +where +T +is +a +Resource / / / -is -some -ordering -you -can -put +Lock +of +Registry +happens +only +when +accessing +to +get the +specific resource -types -in -that -respects / / / -the -extant -Access -implementations -that -' -s -fine -. / / / / / / -See -the -documentation -for [ -Hub +A +: +: +hub +( +global +) ] -for -more -details -. +: +HalApi +: +: +hub pub -trait -Access +struct +Hub < A +: +HalApi > { -} pub -enum -Root -{ -} -/ -/ -These -impls -are -arranged -so -that -the -target -types -( -that -is -the -T -/ -/ -in -Access +adapters +: +Registry < -T -> -) -appear -in -locking -order -. -/ -/ -/ -/ -TODO +id : -establish -an -order -instead -of -declaring -all -the -pairs -. -impl -Access +: +AdapterId +Adapter < -Instance +A > -for -Root -{ -} -impl -Access -< -Surface -> -for -Root -{ -} -impl -Access -< -Surface > -for -Instance -{ -} -impl -< -A +pub +devices : -HalApi -> -Access +Registry < -Adapter +id +: +: +DeviceId +Device < A > > -for -Root -{ -} -impl -< -A +pub +queues : -HalApi -> -Access +Registry < -Adapter +id +: +: +QueueId +Queue < A > > -for -Surface -{ -} -impl -< -A +pub +pipeline_layouts : -HalApi -> -Access +Registry < -Device +id +: +: +PipelineLayoutId +PipelineLayout < A > > -for -Root -{ -} -impl -< -A +pub +shader_modules : -HalApi -> -Access +Registry < -Device +id +: +: +ShaderModuleId +ShaderModule < A > > -for -Surface -{ -} -impl -< -A +pub +bind_group_layouts : -HalApi -> -Access +Registry < -Device +id +: +: +BindGroupLayoutId +BindGroupLayout < A > > -for -Adapter +pub +bind_groups +: +Registry < -A -> -{ -} -impl +id +: +: +BindGroupId +BindGroup < A -: -HalApi > -Access +> +pub +command_buffers +: +Registry < +id +: +: +CommandBufferId CommandBuffer < A > > -for -Root -{ -} -impl -< -A +pub +render_bundles : -HalApi -> -Access +Registry < -CommandBuffer +id +: +: +RenderBundleId +RenderBundle < A > > -for -Device +pub +render_pipelines +: +Registry < -A -> -{ -} -impl +id +: +: +RenderPipelineId +RenderPipeline < A -: -HalApi > -Access +> +pub +compute_pipelines +: +Registry < -RenderBundle +id +: +: +ComputePipelineId +ComputePipeline < A > > -for -Device +pub +query_sets +: +Registry < -A -> -{ -} -impl +id +: +: +QuerySetId +QuerySet < A -: -HalApi > -Access +> +pub +buffers +: +Registry < -RenderBundle +id +: +: +BufferId +Buffer < A > > -for -CommandBuffer +pub +staging_buffers +: +Registry < -A -> -{ -} -impl +id +: +: +StagingBufferId +StagingBuffer < A -: -HalApi > -Access +> +pub +textures +: +Registry < -PipelineLayout +id +: +: +TextureId +Texture < A > > -for -Root -{ -} -impl -< -A +pub +texture_views : -HalApi -> -Access +Registry < -PipelineLayout +id +: +: +TextureViewId +TextureView < A > > -for -Device +pub +samplers +: +Registry +< +id +: +: +SamplerId +Sampler < A > -{ +> } impl < @@ -2245,3496 +1708,337 @@ A : HalApi > -Access -< -PipelineLayout -< -A -> -> -for -RenderBundle -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroupLayout -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroupLayout -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroupLayout -< -A -> -> -for -PipelineLayout -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroupLayout -< -A -> -> -for -QuerySet -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroup -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroup -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroup -< -A -> -> -for -BindGroupLayout -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroup -< -A -> -> -for -PipelineLayout -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -BindGroup -< -A -> -> -for -CommandBuffer -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -ComputePipeline -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -ComputePipeline -< -A -> -> -for -BindGroup +Hub < A > { -} -impl +fn +new < -A +F : -HalApi -> -Access -< -RenderPipeline -< -A -> -> -for -Device -< -A +GlobalIdentityHandlerFactory > -{ -} -impl -< -A +( +factory : -HalApi -> -Access -< -RenderPipeline -< -A -> -> -for -BindGroup -< -A +& +F +) +- > +Self { -} -impl -< -A -: -HalApi -> -Access -< -RenderPipeline -< -A -> -> -for -ComputePipeline -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -ShaderModule -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -ShaderModule -< -A -> -> -for -BindGroupLayout -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -BindGroupLayout -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -BindGroup -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -CommandBuffer -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -ComputePipeline -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -RenderPipeline -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Buffer -< -A -> -> -for -QuerySet -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -StagingBuffer -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Texture -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -Texture -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Texture -< -A -> -> -for -Buffer -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -TextureView -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -TextureView -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -TextureView -< -A -> -> -for -Texture -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Sampler -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -Sampler -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -Sampler -< -A -> -> -for -TextureView -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -Root -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -Device -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -CommandBuffer -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -RenderPipeline -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -ComputePipeline -< -A -> -{ -} -impl -< -A -: -HalApi -> -Access -< -QuerySet -< -A -> -> -for -Sampler -< -A -> -{ -} -# -[ -cfg -( -any -( -debug_assertions -feature -= -" -strict_asserts -" -) -) -] -thread_local -! -{ -/ -/ -/ -Per -- -thread -state -checking -Token -< -Root -> -creation -in -debug -builds -. -/ -/ -/ -/ -/ -/ -This -is -the -number -of -Token -values -alive -on -the -current -/ -/ -/ -thread -. -Since -Token -creation -respects -the -[ -Access -] -graph -/ -/ -/ -there -can -never -be -more -tokens -alive -than -there -are -fields -of -/ -/ -/ -[ -Hub -] -so -a -u8 -is -plenty -. -static -ACTIVE_TOKEN -: -Cell -< -u8 -> -= -Cell -: -: -new -( -0 -) -; -} -/ -/ -/ -A -zero -- -size -permission -token -to -lock -some -fields -of -[ -Hub -] -. -/ -/ -/ -/ -/ -/ -Access -to -a -Token -< -T -> -grants -permission -to -lock -any -field -of -/ -/ -/ -[ -Hub -] -following -the -one -of -type -[ -Registry -< -T -. -. -. -> -] -where -/ -/ -/ -" -following -" -is -as -defined -by -the -[ -Access -] -implementations -. -/ -/ -/ -/ -/ -/ -Calling -[ -Token -: -: -root -( -) -] -returns -a -Token -< -Root -> -which -grants -/ -/ -/ -permission -to -lock -any -field -. -Dynamic -checks -ensure -that -each -/ -/ -/ -thread -has -at -most -one -Token -< -Root -> -live -at -a -time -in -debug -/ -/ -/ -builds -. -/ -/ -/ -/ -/ -/ -The -locking -methods -on -Registry -< -T -. -. -. -> -take -a -& -' -t -mut -/ -/ -/ -Token -< -A -> -and -return -a -fresh -Token -< -' -t -T -> -and -a -lock -guard -with -/ -/ -/ -lifetime -' -t -so -the -caller -cannot -access -their -Token -< -A -> -again -/ -/ -/ -until -they -have -dropped -both -the -Token -< -T -> -and -the -lock -guard -. -/ -/ -/ -/ -/ -/ -Tokens -are -! -Send -so -one -thread -can -' -t -send -its -permissions -to -/ -/ -/ -another -. -pub -( -crate -) -struct -Token -< -' -a -T -: -' -a -> -{ -/ -/ -The -* -const -makes -us -! -Send -and -! -Sync -. -level -: -PhantomData -< -& -' -a -* -const -T -> -} -impl -< -' -a -T -> -Token -< -' -a -T -> -{ -/ -/ -/ -Return -a -new -token -for -a -locked -field -. -/ -/ -/ -/ -/ -/ -This -should -only -be -used -by -Registry -locking -methods -. -pub -( -crate -) -fn -new -( -) -- -> -Self -{ -# -[ -cfg -( -any -( -debug_assertions -feature -= -" -strict_asserts -" -) -) -] -ACTIVE_TOKEN -. -with -( -| -active -| -{ -let -old -= -active -. -get -( -) -; -strict_assert_ne -! -( -old -0 -" -Root -token -was -dropped -" -) -; -active -. -set -( -old -+ -1 -) -; -} -) -; -Self -{ -level -: -PhantomData -} -} -} -impl -Token -< -' -static -Root -> -{ -/ -/ -/ -Return -a -Token -< -Root -> -granting -permission -to -lock -any -[ -Hub -] -field -. -/ -/ -/ -/ -/ -/ -Debug -builds -check -dynamically -that -each -thread -has -at -most -/ -/ -/ -one -root -token -at -a -time -. -pub -fn -root -( -) -- -> -Self -{ -# -[ -cfg -( -any -( -debug_assertions -feature -= -" -strict_asserts -" -) -) -] -ACTIVE_TOKEN -. -with -( -| -active -| -{ -strict_assert_eq -! -( -0 -active -. -replace -( -1 -) -" -Root -token -is -already -active -" -) -; -} -) -; -Self -{ -level -: -PhantomData -} -} -} -impl -< -' -a -T -> -Drop -for -Token -< -' -a -T -> -{ -fn -drop -( -& -mut -self -) -{ -# -[ -cfg -( -any -( -debug_assertions -feature -= -" -strict_asserts -" -) -) -] -ACTIVE_TOKEN -. -with -( -| -active -| -{ -let -old -= -active -. -get -( -) -; -active -. -set -( -old -- -1 -) -; -} -) -; -} -} -# -[ -derive -( -Debug -) -] -pub -struct -HubReport -{ -pub -adapters -: -StorageReport -pub -devices -: -StorageReport -pub -pipeline_layouts -: -StorageReport -pub -shader_modules -: -StorageReport -pub -bind_group_layouts -: -StorageReport -pub -bind_groups -: -StorageReport -pub -command_buffers -: -StorageReport -pub -render_bundles -: -StorageReport -pub -render_pipelines -: -StorageReport -pub -compute_pipelines -: -StorageReport -pub -query_sets -: -StorageReport -pub -buffers -: -StorageReport -pub -textures -: -StorageReport -pub -texture_views -: -StorageReport -pub -samplers -: -StorageReport -} -impl -HubReport -{ -pub -fn -is_empty -( -& -self -) -- -> -bool -{ -self -. -adapters -. -is_empty -( -) -} -} -# -[ -allow -( -rustdoc -: -: -private_intra_doc_links -) -] -/ -/ -/ -All -the -resources -for -a -particular -backend -in -a -[ -Global -] -. -/ -/ -/ -/ -/ -/ -To -obtain -global -' -s -Hub -for -some -[ -HalApi -] -backend -type -A -/ -/ -/ -call -[ -A -: -: -hub -( -global -) -] -. -/ -/ -/ -/ -/ -/ -# -# -Locking -/ -/ -/ -/ -/ -/ -Each -field -in -Hub -is -a -[ -Registry -] -holding -all -the -values -of -a -/ -/ -/ -particular -type -of -resource -all -protected -by -a -single -[ -RwLock -] -. -/ -/ -/ -So -for -example -to -access -any -[ -Buffer -] -you -must -acquire -a -read -/ -/ -/ -lock -on -the -Hub -s -entire -[ -buffers -] -registry -. -The -lock -guard -/ -/ -/ -gives -you -access -to -the -Registry -' -s -[ -Storage -] -which -you -can -/ -/ -/ -then -index -with -the -buffer -' -s -id -. -( -Yes -this -design -causes -/ -/ -/ -contention -; -see -[ -# -2272 -] -. -) -/ -/ -/ -/ -/ -/ -But -most -wgpu -operations -require -access -to -several -different -/ -/ -/ -kinds -of -resource -so -you -often -need -to -hold -locks -on -several -/ -/ -/ -different -fields -of -your -[ -Hub -] -simultaneously -. -To -avoid -/ -/ -/ -deadlock -there -is -an -ordering -imposed -on -the -fields -and -you -may -/ -/ -/ -only -acquire -new -locks -on -fields -that -come -* -after -* -all -those -you -/ -/ -/ -are -already -holding -locks -on -in -this -ordering -. -( -The -ordering -is -/ -/ -/ -described -in -the -documentation -for -the -[ -Access -] -trait -. -) -/ -/ -/ -/ -/ -/ -We -use -Rust -' -s -type -system -to -statically -check -that -wgpu_core -can -/ -/ -/ -only -ever -acquire -locks -in -the -correct -order -: -/ -/ -/ -/ -/ -/ -- -A -value -of -type -[ -Token -< -T -> -] -represents -proof -that -the -owner -/ -/ -/ -only -holds -locks -on -the -Hub -fields -holding -resources -of -type -/ -/ -/ -T -or -earlier -in -the -lock -ordering -. -A -special -value -of -type -/ -/ -/ -Token -< -Root -> -obtained -by -calling -[ -Token -: -: -root -] -represents -/ -/ -/ -proof -that -no -Hub -field -locks -are -held -. -/ -/ -/ -/ -/ -/ -- -To -lock -the -Hub -field -holding -resources -of -type -T -you -must -/ -/ -/ -call -its -[ -read -] -or -[ -write -] -methods -. -These -require -you -to -/ -/ -/ -pass -in -a -& -mut -Token -< -A -> -for -some -A -that -implements -/ -/ -/ -[ -Access -< -T -> -] -. -This -implementation -exists -only -if -T -follows -A -/ -/ -/ -in -the -field -ordering -which -statically -ensures -that -you -are -/ -/ -/ -indeed -allowed -to -lock -this -new -Hub -field -. -/ -/ -/ -/ -/ -/ -- -The -locking -methods -return -both -an -[ -RwLock -] -guard -that -you -can -/ -/ -/ -use -to -access -the -field -' -s -resources -and -a -new -Token -< -T -> -value -. -/ -/ -/ -These -both -borrow -from -the -lifetime -of -your -Token -< -A -> -so -since -/ -/ -/ -you -passed -that -by -mutable -reference -you -cannot -access -it -again -/ -/ -/ -until -you -drop -the -new -token -and -lock -guard -. -/ -/ -/ -/ -/ -/ -Because -a -thread -only -ever -has -access -to -the -Token -< -T -> -for -the -/ -/ -/ -last -resource -type -T -it -holds -a -lock -for -and -the -Access -trait -/ -/ -/ -implementations -only -permit -acquiring -locks -for -types -U -that -/ -/ -/ -follow -T -in -the -lock -ordering -it -is -statically -impossible -for -a -/ -/ -/ -program -to -violate -the -locking -order -. -/ -/ -/ -/ -/ -/ -This -does -assume -that -threads -cannot -call -Token -< -Root -> -when -they -/ -/ -/ -already -hold -locks -( -dynamically -enforced -in -debug -builds -) -and -that -/ -/ -/ -threads -cannot -send -their -Token -s -to -other -threads -( -enforced -by -/ -/ -/ -making -Token -neither -Send -nor -Sync -) -. -/ -/ -/ -/ -/ -/ -[ -Global -] -: -crate -: -: -global -: -: -Global -/ -/ -/ -[ -A -: -: -hub -( -global -) -] -: -HalApi -: -: -hub -/ -/ -/ -[ -RwLock -] -: -parking_lot -: -: -RwLock -/ -/ -/ -[ -buffers -] -: -Hub -: -: -buffers -/ -/ -/ -[ -read -] -: -Registry -: -: -read -/ -/ -/ -[ -write -] -: -Registry -: -: -write -/ -/ -/ -[ -Token -< -T -> -] -: -Token -/ -/ -/ -[ -Access -< -T -> -] -: -Access -/ -/ -/ -[ -# -2272 -] -: -https -: -/ -/ -github -. -com -/ -gfx -- -rs -/ -wgpu -/ -pull -/ -2272 -pub -struct -Hub -< -A -: -HalApi -F -: -GlobalIdentityHandlerFactory -> -{ -pub -adapters -: -Registry -< -Adapter -< -A -> -id -: -: -AdapterId -F -> -pub -devices -: -Registry -< -Device -< -A -> -id -: -: -DeviceId -F -> -pub -pipeline_layouts -: -Registry -< -PipelineLayout -< -A -> -id -: -: -PipelineLayoutId -F -> -pub -shader_modules -: -Registry -< -ShaderModule -< -A -> -id -: -: -ShaderModuleId -F -> -pub -bind_group_layouts -: -Registry -< -BindGroupLayout -< -A -> -id -: -: -BindGroupLayoutId -F -> -pub -bind_groups -: -Registry -< -BindGroup -< -A -> -id -: -: -BindGroupId -F -> -pub -command_buffers -: -Registry -< -CommandBuffer -< -A -> -id -: -: -CommandBufferId -F -> -pub -render_bundles -: -Registry -< -RenderBundle -< -A -> -id -: -: -RenderBundleId -F -> -pub -render_pipelines -: -Registry -< -RenderPipeline -< -A -> -id -: -: -RenderPipelineId -F -> -pub -compute_pipelines -: -Registry -< -ComputePipeline -< -A -> -id -: -: -ComputePipelineId -F -> -pub -query_sets -: -Registry -< -QuerySet -< -A -> -id -: -: -QuerySetId -F -> -pub -buffers -: -Registry -< -Buffer -< -A -> -id -: -: -BufferId -F -> -pub -staging_buffers -: -Registry -< -StagingBuffer -< -A -> -id -: -: -StagingBufferId -F -> -pub -textures -: -Registry -< -Texture -< -A -> -id -: -: -TextureId -F -> -pub -texture_views -: -Registry -< -TextureView -< -A -> -id -: -: -TextureViewId -F -> -pub -samplers -: -Registry -< -Sampler -< -A -> -id -: -: -SamplerId -F -> -} -impl -< -A -: -HalApi -F -: -GlobalIdentityHandlerFactory -> -Hub -< -A -F -> -{ -fn -new -( -factory -: -& -F -) -- -> -Self -{ -Self -{ -adapters -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -devices -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -pipeline_layouts -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -shader_modules -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -bind_group_layouts -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -bind_groups -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -command_buffers -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -render_bundles -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -render_pipelines -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -compute_pipelines -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -query_sets -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -buffers -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -staging_buffers -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -textures -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -texture_views -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -samplers -: -Registry -: -: -new -( -A -: -: -VARIANT -factory -) -} -} -/ -/ -TODO -: -instead -of -having -a -hacky -with_adapters -parameter -/ -/ -we -should -have -clear_device -( -device_id -) -that -specifically -destroys -/ -/ -everything -related -to -a -logical -device -. -pub -( -crate -) -fn -clear -( -& -self -surface_guard -: -& -mut -Storage -< -Surface -id -: -: -SurfaceId -> -with_adapters -: -bool -) -{ -use -crate -: -: -resource -: -: -TextureInner -; -use -hal -: -: -{ -Device -as -_ -Surface -as -_ -} -; -let -mut -devices -= -self -. -devices -. -data -. -write -( -) -; -for -element -in -devices -. -map -. -iter_mut -( -) -{ -if -let -Element -: -: -Occupied -( -ref -mut -device -_ -) -= -* -element -{ -device -. -prepare_to_die -( -) -; -} -} -/ -/ -destroy -command -buffers -first -since -otherwise -DX12 -isn -' -t -happy -for -element -in -self -. -command_buffers -. -data -. -write -( -) -. -map -. -drain -( -. -. -) -{ -if -let -Element -: -: -Occupied -( -command_buffer -_ -) -= -element -{ -let -device -= -& -devices -[ -command_buffer -. -device_id -. -value -] -; -device -. -destroy_command_buffer +Self +{ +adapters +: +Registry +: +: +new ( -command_buffer +A +: +: +VARIANT +factory ) -; -} -} -for -element -in -self -. -samplers -. -data -. -write +devices +: +Registry +: +: +new ( +A +: +: +VARIANT +factory ) -. -map -. -drain +queues +: +Registry +: +: +new ( -. -. +A +: +: +VARIANT +factory ) -{ -if -let -Element +pipeline_layouts : +Registry : -Occupied +: +new ( -sampler -_ +A +: +: +VARIANT +factory ) -= -element -{ -unsafe -{ -devices -[ -sampler -. -device_id -. -value -] -. -raw -. -destroy_sampler +shader_modules +: +Registry +: +: +new ( -sampler -. -raw +A +: +: +VARIANT +factory ) -; -} -} -} -for -element -in -self -. -texture_views -. -data -. -write +bind_group_layouts +: +Registry +: +: +new ( +A +: +: +VARIANT +factory ) -. -map -. -drain +bind_groups +: +Registry +: +: +new ( -. -. +A +: +: +VARIANT +factory ) -{ -if -let -Element +command_buffers +: +Registry : : -Occupied +new ( -texture_view -_ +A +: +: +VARIANT +factory ) -= -element -{ -let -device -= -& -devices -[ -texture_view -. -device_id -. -value -] -; -unsafe -{ -device -. -raw -. -destroy_texture_view +render_bundles +: +Registry +: +: +new ( -texture_view -. -raw +A +: +: +VARIANT +factory ) -; -} -} -} -for -element -in -self -. -textures -. -data -. -write +render_pipelines +: +Registry +: +: +new ( +A +: +: +VARIANT +factory ) -. -map -. -drain +compute_pipelines +: +Registry +: +: +new ( -. -. +A +: +: +VARIANT +factory ) -{ -if -let -Element +query_sets : +Registry : -Occupied +: +new ( -texture -_ +A +: +: +VARIANT +factory ) -= -element -{ -let -device -= -& -devices -[ -texture -. -device_id -. -value -] -; -if -let -TextureInner +buffers : +Registry : -Native -{ -raw : -Some -( -raw -) -} -= -texture -. -inner -{ -unsafe -{ -device -. -raw -. -destroy_texture +new ( -raw +A +: +: +VARIANT +factory ) -; -} -} -if -let -TextureClearMode +staging_buffers : +Registry : -RenderPass -{ -clear_views -. -. -} -= -texture -. -clear_mode -{ -for -view -in -clear_views -{ -unsafe -{ -device -. -raw -. -destroy_texture_view +: +new ( -view +A +: +: +VARIANT +factory ) -; -} -} -} -} -} -for -element -in -self -. -buffers -. -data -. -write +textures +: +Registry +: +: +new ( +A +: +: +VARIANT +factory ) -. -map -. -drain +texture_views +: +Registry +: +: +new ( -. -. +A +: +: +VARIANT +factory ) -{ -if -let -Element +samplers +: +Registry : : -Occupied +new ( -buffer -_ +A +: +: +VARIANT +factory ) -= -element -{ +} +} / / TODO : -unmap -if -needed -devices -[ -buffer -. -device_id -. -value -] -. -destroy_buffer +instead +of +having +a +hacky +with_adapters +parameter +/ +/ +we +should +have +clear_device ( -buffer +device_id ) -; -} -} -for -element -in -self -. -bind_groups -. -data +that +specifically +destroys +/ +/ +everything +related +to +a +logical +device . -write +pub ( +crate ) -. -map -. -drain +fn +clear ( -. -. -) -{ -if -let -Element +& +self +surface_guard +: +& +Storage +< +Surface +id : : -Occupied -( -bind_group -_ +SurfaceId +> +with_adapters +: +bool ) -= -element { +use +hal +: +: +Surface +; let -device -= -& +mut devices -[ -bind_group -. -device_id -. -value -] -; -unsafe -{ -device += +self . -raw +devices . -destroy_bind_group +write ( -bind_group -. -raw ) ; -} -} -} for element in -self -. -shader_modules -. -data -. -write -( -) +devices . map . -drain +iter ( -. -. ) { if @@ -5744,49 +2048,25 @@ Element : Occupied ( -module +ref +device _ ) = -element -{ -let -device -= -& -devices -[ -module -. -device_id -. -value -] -; -unsafe +* +element { device . -raw -. -destroy_shader_module +prepare_to_die ( -module -. -raw ) ; } } -} -for -element -in self . -bind_group_layouts -. -data +command_buffers . write ( @@ -5794,76 +2074,41 @@ write . map . -drain +clear ( +) +; +self . +samplers . -) -{ -if -let -Element -: -: -Occupied +write ( -bgl -_ ) -= -element -{ -let -device -= -& -devices -[ -bgl . -device_id +map . -value -] -; -if -let -Some +clear ( -inner ) -= -bgl +; +self +. +texture_views . -into_inner +write ( ) -{ -unsafe -{ -device . -raw +map . -destroy_bind_group_layout +clear ( -inner -. -raw ) ; -} -} -} -} -for -element -in self . -pipeline_layouts -. -data +textures . write ( @@ -5871,62 +2116,41 @@ write . map . -drain +clear ( +) +; +self . +buffers . -) -{ -if -let -Element -: -: -Occupied +write ( -pipeline_layout -_ ) -= -element -{ -let -device -= -& -devices -[ -pipeline_layout . -device_id +map . -value -] +clear +( +) ; -unsafe -{ -device +self . -raw +bind_groups . -destroy_pipeline_layout +write ( -pipeline_layout +) . -raw +map +. +clear +( ) ; -} -} -} -for -element -in self . -compute_pipelines -. -data +shader_modules . write ( @@ -5934,62 +2158,41 @@ write . map . -drain +clear ( +) +; +self . +bind_group_layouts . -) -{ -if -let -Element -: -: -Occupied +write ( -pipeline -_ ) -= -element -{ -let -device -= -& -devices -[ -pipeline . -device_id +map . -value -] +clear +( +) ; -unsafe -{ -device +self . -raw +pipeline_layouts . -destroy_compute_pipeline +write ( -pipeline +) . -raw +map +. +clear +( ) ; -} -} -} -for -element -in self . -render_pipelines -. -data +compute_pipelines . write ( @@ -5997,54 +2200,38 @@ write . map . -drain +clear ( +) +; +self . +render_pipelines . -) -{ -if -let -Element -: -: -Occupied +write ( -pipeline -_ ) -= -element -{ -let -device -= -& -devices -[ -pipeline . -device_id +map . -value -] +clear +( +) ; -unsafe -{ -device +self . -raw +query_sets . -destroy_render_pipeline +write ( -pipeline +) . -raw +map +. +clear +( ) ; -} -} -} for element in @@ -6052,7 +2239,7 @@ surface_guard . map . -iter_mut +iter ( ) { @@ -6064,55 +2251,19 @@ Element Occupied ( ref -mut -surface -_epoch -) -= -* -element -{ -if surface -. -presentation -. -as_ref -( -) -. -map_or -( -wgt -: -: -Backend -: -: -Empty -| -p -| -p -. -backend -( -) +_epoch ) -! = -A -: -: -VARIANT +* +element { -continue -; -} if let Some ( +ref +mut present ) = @@ -6120,30 +2271,41 @@ surface . presentation . +lock +( +) +. take ( ) { +if let +Some +( device +) = -& -devices -[ present . -device_id +device . -value -] -; +downcast_ref +: +: +< +A +> +( +) +{ let suf = A : : -get_surface_mut +get_surface ( surface ) @@ -6160,10 +2322,11 @@ raw . unconfigure ( -& device . raw +( +) ) ; / @@ -6180,14 +2343,10 @@ here } } } -for -element -in +} self . -query_sets -. -data +queues . write ( @@ -6195,88 +2354,18 @@ write . map . -drain -( -. -. -) -{ -if -let -Element -: -: -Occupied -( -query_set -_ -) -= -element -{ -let -device -= -& -devices -[ -query_set -. -device_id -. -value -] -; -unsafe -{ -device -. -raw -. -destroy_query_set +clear ( -query_set -. -raw ) ; -} -} -} -for -element -in devices . map . -drain -( -. -. -) -{ -if -let -Element -: -: -Occupied -( -device -_ -) -= -element -{ -device -. -dispose +clear ( ) ; -} -} if with_adapters { @@ -6289,8 +2378,6 @@ self . adapters . -data -. write ( ) @@ -6312,70 +2399,41 @@ surface_unconfigure ( & self -device_id -: -id -: +device : -Valid +& +Device < -id -: -: -DeviceId +A > surface : & -mut HalSurface < A > ) { +unsafe +{ use hal : : Surface -as -_ -; -let -devices -= -self -. -devices -. -data -. -read -( -) -; -let -device -= -& -devices -[ -device_id -] ; -unsafe -{ surface . raw . unconfigure ( -& device . raw +( +) ) ; } @@ -6399,12 +2457,6 @@ self . adapters . -data -. -read -( -) -. generate_report ( ) @@ -6414,11 +2466,14 @@ self . devices . -data -. -read +generate_report ( ) +queues +: +self +. +queues . generate_report ( @@ -6429,12 +2484,6 @@ self . pipeline_layouts . -data -. -read -( -) -. generate_report ( ) @@ -6444,12 +2493,6 @@ self . shader_modules . -data -. -read -( -) -. generate_report ( ) @@ -6459,12 +2502,6 @@ self . bind_group_layouts . -data -. -read -( -) -. generate_report ( ) @@ -6474,12 +2511,6 @@ self . bind_groups . -data -. -read -( -) -. generate_report ( ) @@ -6489,12 +2520,6 @@ self . command_buffers . -data -. -read -( -) -. generate_report ( ) @@ -6504,12 +2529,6 @@ self . render_bundles . -data -. -read -( -) -. generate_report ( ) @@ -6519,12 +2538,6 @@ self . render_pipelines . -data -. -read -( -) -. generate_report ( ) @@ -6534,12 +2547,6 @@ self . compute_pipelines . -data -. -read -( -) -. generate_report ( ) @@ -6549,12 +2556,6 @@ self . query_sets . -data -. -read -( -) -. generate_report ( ) @@ -6564,12 +2565,6 @@ self . buffers . -data -. -read -( -) -. generate_report ( ) @@ -6579,12 +2574,6 @@ self . textures . -data -. -read -( -) -. generate_report ( ) @@ -6594,12 +2583,6 @@ self . texture_views . -data -. -read -( -) -. generate_report ( ) @@ -6609,12 +2592,6 @@ self . samplers . -data -. -read -( -) -. generate_report ( ) @@ -6624,11 +2601,6 @@ generate_report pub struct Hubs -< -F -: -GlobalIdentityHandlerFactory -> { # [ @@ -6667,7 +2639,6 @@ api : : Vulkan -F > # [ @@ -6711,7 +2682,6 @@ api : : Metal -F > # [ @@ -6743,7 +2713,6 @@ api : : Dx12 -F > # [ @@ -6775,7 +2744,6 @@ api : : Dx11 -F > # [ @@ -6803,7 +2771,6 @@ api : : Gles -F > # [ @@ -6904,19 +2871,10 @@ api : : Empty -F > } impl -< -F -: -GlobalIdentityHandlerFactory -> Hubs -< -F -> { pub ( @@ -6924,6 +2882,11 @@ crate ) fn new +< +F +: +GlobalIdentityHandlerFactory +> ( factory : diff --git a/third_party/rust/wgpu-core/src/id.rs b/third_party/rust/wgpu-core/src/id.rs index e7098c4c0f6a9..430c5c42f6a52 100644 --- a/third_party/rust/wgpu-core/src/id.rs +++ b/third_party/rust/wgpu-core/src/id.rs @@ -12,11 +12,25 @@ std : : { +any +: +: +Any cmp : : Ordering fmt +: +: +{ +self +Debug +} +hash +: +: +Hash marker : : @@ -27,7 +41,10 @@ use wgt : : +{ Backend +WasmNotSendSync +} ; # [ @@ -751,6 +768,11 @@ struct Id < T +: +' +static ++ +WasmNotSendSync > ( NonZeroId @@ -866,6 +888,13 @@ T > for SerialId +where +T +: +' +static ++ +WasmNotSendSync { fn from @@ -929,6 +958,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn from @@ -975,6 +1011,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { / / @@ -1036,13 +1079,8 @@ u32 ) - > -Valid -< Self -> { -Valid -( Id : : @@ -1055,7 +1093,39 @@ Backend : Empty ) +} +# +[ +allow +( +dead_code +) +] +pub +( +crate +) +fn +is_valid +( +& +self +) +- +> +bool +{ +self +. +backend +( ) +! += +Backend +: +: +Empty } pub fn @@ -1145,6 +1215,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { } impl @@ -1157,6 +1234,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn clone @@ -1176,15 +1260,19 @@ impl < T > -fmt -: -: Debug for Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn fmt @@ -1265,18 +1353,19 @@ impl < T > -std -: -: -hash -: -: Hash for Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn hash @@ -1322,6 +1411,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn eq @@ -1357,6 +1453,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { } impl @@ -1369,6 +1472,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn partial_cmp @@ -1410,6 +1520,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn cmp @@ -1441,100 +1558,6 @@ other / / / -An -internal -ID -that -has -been -checked -to -point -to -/ -/ -/ -a -valid -object -in -the -storages -. -# -[ -repr -( -transparent -) -] -# -[ -derive -( -Clone -Copy -Debug -Eq -Hash -PartialEq -PartialOrd -Ord -) -] -# -[ -cfg_attr -( -feature -= -" -trace -" -derive -( -serde -: -: -Serialize -) -) -] -# -[ -cfg_attr -( -feature -= -" -replay -" -derive -( -serde -: -: -Deserialize -) -) -] -pub -( -crate -) -struct -Valid -< -I -> -( -pub -I -) -; -/ -/ -/ Trait carrying methods @@ -1597,6 +1620,19 @@ trait TypedId : Copy ++ +Debug ++ +Any ++ +' +static ++ +WasmNotSendSync ++ +Eq ++ +Hash { fn zip @@ -1655,6 +1691,13 @@ Id < T > +where +T +: +' +static ++ +WasmNotSendSync { fn zip diff --git a/third_party/rust/wgpu-core/src/identity.rs b/third_party/rust/wgpu-core/src/identity.rs index 349360b82e9d7..7fbcf366d58ab 100644 --- a/third_party/rust/wgpu-core/src/identity.rs +++ b/third_party/rust/wgpu-core/src/identity.rs @@ -16,7 +16,13 @@ crate : { id +: +: +{ +self +} Epoch +FastHashMap Index } ; @@ -24,10 +30,20 @@ use std : : +{ fmt : : Debug +marker +: +: +PhantomData +sync +: +: +Arc +} ; / / @@ -328,135 +344,42 @@ Default ) ] pub -struct -IdentityManager -{ -/ -/ -/ -Available -index -values -. -If -empty -then -epochs -. -len ( +super ) -is -the -next -index -/ -/ -/ -to -allocate -. +struct +IdentityValues +{ free : Vec < +( Index +Epoch +) > / / -/ -The -next -or -currently -- -live -epoch -value -associated -with -each -Id -index -. -/ -/ -/ -/ -/ -/ -If -there -is -a -live -id -with -index -i -then -epochs -[ -i -] -is -its -epoch -; -any -/ -/ -/ -id -with -the -same -index -but -an -older -epoch -is -dead -. -/ -/ -/ -/ -/ -/ -If -index -i -is -currently -unused -epochs -[ -i -] -is -the -epoch -to -use -in -its -/ -/ -/ -next -Id -. -epochs +sorted +by +Index +used : -Vec +FastHashMap < Epoch +Vec +< +Index +> > +count +: +usize } impl -IdentityManager +IdentityValues { / / @@ -526,6 +449,13 @@ Backend > I { +self +. +count ++ += +1 +; match self . @@ -537,7 +467,10 @@ pop { Some ( +( index +epoch +) ) = > @@ -547,14 +480,9 @@ I zip ( index -self -. -epochs -[ -index -as -usize -] +epoch ++ +1 backend ) None @@ -567,39 +495,150 @@ epoch 1 ; let -id +used = -I +self +. +used +. +entry +( +epoch +) +. +or_insert_with +( +Default : : -zip +default +) +; +let +index += +if +let +Some ( -self +i +) += +used . -epochs +iter +( +) . -len +max_by_key ( +| +v +| +* +v ) -as -Index +{ +i ++ +1 +} +else +{ +0 +} +; +used +. +push +( +index +) +; +I +: +: +zip +( +index epoch backend ) +} +} +} +pub +fn +mark_as_used +< +I +: +id +: +: +TypedId +> +( +& +mut +self +id +: +I +) +- +> +I +{ +self +. +count ++ += +1 +; +let +( +index +epoch +_backend +) += +id +. +unzip +( +) ; +let +used += self . -epochs +used . -push +entry ( epoch ) +. +or_insert_with +( +Default +: +: +default +) +; +used +. +push +( +index +) ; id } -} -} / / / @@ -617,7 +656,7 @@ again . pub fn -free +release < I : @@ -625,8 +664,6 @@ id : : TypedId -+ -Debug > ( & @@ -650,283 +687,77 @@ unzip ( ) ; -let -pe -= -& -mut self . -epochs -[ -index -as -usize -] -; -assert_eq -! +free +. +push ( -* -pe +( +index epoch ) +) ; -/ -/ -If -the -epoch -reaches -EOL -the -index -doesn -' -t -go -/ -/ -into -the -free -list -will -never -be -reused -again +self . -if -epoch -< -id -: -: -EPOCH_MASK -{ -* -pe +count +- = -epoch -+ 1 ; -self -. -free -. -push +} +pub +fn +count ( -index +& +self ) -; -} -} -} -/ -/ -/ -A -type -that -can -build -true -ids -from -proto -- -ids -and -free -true -ids -. -/ -/ -/ -/ -/ -/ -For -some -implementations -the -true -id -is -based -on -the -proto -- -id -. -/ -/ -/ -The -caller -is -responsible -for -providing -well - -allocated -proto -- -ids +> +usize +{ +self . -/ -/ -/ -/ -/ -/ -For -other -implementations -the -proto -- -id -carries -no -information -/ -/ -/ -( -it -' -s +count +} +} +# +[ +derive ( +Debug ) -say -) -and -this -IdentityHandler -type -takes -care -of -/ -/ -/ -allocating -a -fresh -true -id -. -/ -/ -/ -/ -/ -/ -See -the -module -- -level -documentation -for -details -. +] pub -trait -IdentityHandler +struct +IdentityManager < I -> -: -Debug -{ -/ -/ -/ -The -type -of -proto -- -id -consumed -by -this -filter -to -produce -a -true -id -. -type -Input : -Clone -+ -Debug -; -/ -/ -/ -Given -a -proto -- -id -value -id -return -a -true id -for -backend -. -fn -process -( -& -self -id -: -Self : : -Input -backend -: -Backend -) -- +TypedId > -I -; -/ -/ -/ -Free -the -true -id -id -. -fn -free +{ +pub ( -& -self -id +super +) +values : +Mutex +< +IdentityValues +> +_phantom +: +PhantomData +< I -) -; +> } impl < @@ -936,36 +767,18 @@ id : : TypedId -+ -Debug > -IdentityHandler +IdentityManager < I > -for -Mutex -< -IdentityManager -> { -type -Input -= -( -) -; +pub fn process ( & self -_id -: -Self -: -: -Input backend : Backend @@ -976,6 +789,8 @@ I { self . +values +. lock ( ) @@ -985,6 +800,34 @@ alloc backend ) } +pub +fn +mark_as_used +( +& +self +id +: +I +) +- +> +I +{ +self +. +values +. +lock +( +) +. +mark_as_used +( +id +) +} +pub fn free ( @@ -992,19 +835,66 @@ free self id : -I -) -{ -self -. -lock +I +) +{ +self +. +values +. +lock +( +) +. +release +( +id +) +} +} +impl +< +I +: +id +: +: +TypedId +> +IdentityManager +< +I +> +{ +pub +fn +new +( +) +- +> +Self +{ +Self +{ +values +: +Mutex +: +: +new +( +IdentityValues +: +: +default ( ) -. -free -( -id ) +_phantom +: +PhantomData +} } } / @@ -1016,7 +906,7 @@ that can produce [ -IdentityHandler +IdentityManager ] filters for @@ -1045,62 +935,17 @@ trait IdentityHandlerFactory < I +: +id +: +: +TypedId > { -/ -/ -/ -The -type -of -filter -this -factory -constructs -. -/ -/ -/ -/ -/ -/ -" -Filter -" -and -" -handler -" -seem -to -both -mean -the -same -thing -here -: -/ -/ -/ -something -that -can -produce -true -ids -from -proto -- -ids -. type -Filter +Input : -IdentityHandler -< -I -> +Copy ; / / @@ -1108,7 +953,7 @@ I Create an [ -IdentityHandler +IdentityManager < I > @@ -1132,17 +977,39 @@ I / / / +It +can +return +None +if +ids +are +passed +from +outside +/ +/ +/ +and +are +not +generated +by +wgpu +/ +/ +/ / / / [ -IdentityHandler +IdentityManager < I > ] : -IdentityHandler +IdentityManager fn spawn ( @@ -1151,10 +1018,48 @@ self ) - > +Arc +< +IdentityManager +< +I +> +> +{ +Arc +: +: +new +( +IdentityManager +: +: +new +( +) +) +} +fn +autogenerate_ids +( +) +- +> +bool +; +fn +input_to_id +( +id_in +: Self : : -Filter +Input +) +- +> +I ; } / @@ -1242,8 +1147,6 @@ id : : TypedId -+ -Debug > IdentityHandlerFactory < @@ -1253,37 +1156,45 @@ for IdentityManagerFactory { type -Filter +Input = -Mutex -< -IdentityManager -> +( +) ; fn -spawn +autogenerate_ids ( -& -self ) - > -Self -: -: -Filter +bool { -Mutex -: -: -new +true +} +fn +input_to_id ( -IdentityManager +_id_in : +Self : -default -( +: +Input ) +- +> +I +{ +unreachable +! +( +" +It +should +not +be +called +" ) } } @@ -1296,7 +1207,7 @@ that can build [ -IdentityHandler +IdentityManager ] s for @@ -1447,30 +1358,12 @@ id SurfaceId > { -fn -ids_are_generated_in_wgpu -( -) -- -> -bool -; } impl GlobalIdentityHandlerFactory for IdentityManagerFactory { -fn -ids_are_generated_in_wgpu -( -) -- -> -bool -{ -true -} } pub type @@ -1481,7 +1374,6 @@ I > = < -< G as IdentityHandlerFactory @@ -1491,15 +1383,6 @@ I > : : -Filter -as -IdentityHandler -< -I -> -> -: -: Input ; # @@ -1520,34 +1403,57 @@ as _ ; let -mut man = IdentityManager : : -default +< +id +: +: +BufferId +> +: +: +new ( ) ; +let +forced_id += man . -epochs -. -push +mark_as_used ( id : : -EPOCH_MASK +BufferId +: +: +zip +( +0 +1 +Backend +: +: +Empty +) ) ; -man -. -free +assert_eq +! +( +forced_id . -push +unzip ( +) +. +0 0 ) ; @@ -1556,15 +1462,7 @@ id1 = man . -alloc -: -: -< -id -: -: -BufferId -> +process ( Backend : @@ -1582,7 +1480,7 @@ unzip ) . 0 -0 +1 ) ; man @@ -1597,15 +1495,7 @@ id2 = man . -alloc -: -: -< -id -: -: -BufferId -> +process ( Backend : @@ -1618,8 +1508,8 @@ Empty confirm that the -index -0 +epoch +1 is no longer @@ -1639,4 +1529,17 @@ unzip 1 ) ; +assert_eq +! +( +id2 +. +unzip +( +) +. +1 +2 +) +; } diff --git a/third_party/rust/wgpu-core/src/init_tracker/buffer.rs b/third_party/rust/wgpu-core/src/init_tracker/buffer.rs index f3c31d4b4e760..1d277028d10eb 100644 --- a/third_party/rust/wgpu-core/src/init_tracker/buffer.rs +++ b/third_party/rust/wgpu-core/src/init_tracker/buffer.rs @@ -11,19 +11,31 @@ use crate : : -id +{ +hal_api +: +: +HalApi +resource : : -BufferId +Buffer +} ; use std : : +{ ops : : Range +sync +: +: +Arc +} ; # [ @@ -39,11 +51,22 @@ crate ) struct BufferInitTrackerAction +< +A +: +HalApi +> { pub -id +buffer : -BufferId +Arc +< +Buffer +< +A +> +> pub range : @@ -109,6 +132,11 @@ crate ) fn check_action +< +A +: +HalApi +> ( & self @@ -116,21 +144,28 @@ action : & BufferInitTrackerAction +< +A +> ) - > Option < BufferInitTrackerAction +< +A +> > { self . create_action ( +& action . -id +buffer action . range @@ -175,12 +210,24 @@ crate ) fn create_action +< +A +: +HalApi +> ( & self -id +buffer : -BufferId +& +Arc +< +Buffer +< +A +> +> query_range : Range @@ -199,6 +246,9 @@ MemoryInitKind Option < BufferInitTrackerAction +< +A +> > { self @@ -215,7 +265,13 @@ range | BufferInitTrackerAction { -id +buffer +: +buffer +. +clone +( +) range kind } diff --git a/third_party/rust/wgpu-core/src/init_tracker/texture.rs b/third_party/rust/wgpu-core/src/init_tracker/texture.rs index bb86c27b06673..15e92d6e2969b 100644 --- a/third_party/rust/wgpu-core/src/init_tracker/texture.rs +++ b/third_party/rust/wgpu-core/src/init_tracker/texture.rs @@ -12,10 +12,14 @@ crate : : { -id +hal_api : : -TextureId +HalApi +resource +: +: +Texture track : : @@ -32,10 +36,16 @@ use std : : +{ ops : : Range +sync +: +: +Arc +} ; # [ @@ -285,14 +295,25 @@ crate ) struct TextureInitTrackerAction +< +A +: +HalApi +> { pub ( crate ) -id +texture : -TextureId +Arc +< +Texture +< +A +> +> pub ( crate @@ -410,6 +431,11 @@ crate ) fn check_action +< +A +: +HalApi +> ( & self @@ -417,12 +443,18 @@ action : & TextureInitTrackerAction +< +A +> ) - > Option < TextureInitTrackerAction +< +A +> > { let @@ -593,11 +625,15 @@ Some ( TextureInitTrackerAction { -id +texture : action . -id +texture +. +clone +( +) range : TextureInitRange diff --git a/third_party/rust/wgpu-core/src/instance.rs b/third_party/rust/wgpu-core/src/instance.rs index 2175133c50a03..1889df18d4eac 100644 --- a/third_party/rust/wgpu-core/src/instance.rs +++ b/third_party/rust/wgpu-core/src/instance.rs @@ -1,12 +1,32 @@ use +std +: +: +sync +: +: +Arc +; +use crate : : { +any_surface +: +: +AnySurface device : : { +queue +: +: +Queue +resource +: +: Device DeviceDescriptor } @@ -18,18 +38,14 @@ hal_api : : HalApi -hub -: -: -Token id : : { AdapterId DeviceId +QueueId SurfaceId -Valid } identity : @@ -42,13 +58,25 @@ present : : Presentation +resource +: +: +{ +Resource +ResourceInfo +ResourceType +} LabelHelpers -LifeGuard -Stored DOWNLEVEL_WARNING_MESSAGE } ; use +parking_lot +: +: +Mutex +; +use wgt : : @@ -69,6 +97,7 @@ _ Instance as _ +OpenDevice } ; use @@ -113,36 +142,31 @@ TODO : remove this +# +[ +derive +( +Clone +) +] pub struct HalSurface < A : -hal -: -: -Api +HalApi > { pub raw : -A -: -: -Surface -/ -/ -pub -acquired_texture -: -Option +Arc < A : : -SurfaceTexture +Surface > } # @@ -958,13 +982,7 @@ Instance > surface : -Option -< -HalSurface -< -A -> -> +AnySurface ) { unsafe @@ -973,10 +991,51 @@ if let Some ( +surface +) += +surface +. +take +: +: +< +A +> +( +) +{ +if +let +Ok +( suf ) = +Arc +: +: +try_unwrap +( surface +) +{ +if +let +Ok +( +raw +) += +Arc +: +: +try_unwrap +( +suf +. +raw +) { instance . @@ -990,14 +1049,61 @@ unwrap . destroy_surface ( -suf -. raw ) ; } +else +{ +panic +! +( +" +Surface +cannot +be +destroyed +because +is +still +in +use +" +) +; +} +} +else +{ +panic +! +( +" +Surface +cannot +be +destroyed +because +is +still +in +use +" +) +; +} +} } } +match +surface +. +raw +. +backend +( +) +{ # [ cfg @@ -1020,6 +1126,12 @@ wasm32 ) ) ] +Backend +: +: +Vulkan += +> destroy ( hal @@ -1035,9 +1147,8 @@ self vulkan surface . -vulkan +raw ) -; # [ cfg @@ -1065,6 +1176,12 @@ ios ) ) ] +Backend +: +: +Metal += +> destroy ( hal @@ -1080,9 +1197,8 @@ self metal surface . -metal +raw ) -; # [ cfg @@ -1098,6 +1214,12 @@ windows ) ) ] +Backend +: +: +Dx12 += +> destroy ( hal @@ -1113,9 +1235,8 @@ self dx12 surface . -dx12 +raw ) -; # [ cfg @@ -1131,6 +1252,12 @@ windows ) ) ] +Backend +: +: +Dx11 += +> destroy ( hal @@ -1146,9 +1273,8 @@ self dx11 surface . -dx11 +raw ) -; # [ cfg @@ -1160,6 +1286,12 @@ gles " ) ] +Backend +: +: +Gl += +> destroy ( hal @@ -1175,9 +1307,16 @@ self gl surface . -gl +raw ) -; +_ += +> +unreachable +! +( +) +} } } pub @@ -1190,219 +1329,88 @@ crate ) presentation : +Mutex +< Option < Presentation > -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not +> +pub ( -target_arch -= -" -wasm32 -" -) -) +crate ) -] -pub -vulkan +info : -Option -< -HalSurface +ResourceInfo < -hal -: -: -api -: -: -Vulkan -> +SurfaceId > -# -[ -cfg -( -all +pub ( -feature +crate +) +raw +: +AnySurface +} +impl +Resource +< +SurfaceId +> +for +Surface +{ +const +TYPE +: +ResourceType = " -metal +Surface " -any -( -target_os -= -" -macos -" -target_os -= -" -ios -" -) -) -) -] -pub -metal -: -Option -< -HalSurface -< -hal -: -: -api -: -: -Metal -> -> -# -[ -cfg -( -all -( -feature -= -" -dx12 -" -windows -) -) -] -pub -dx12 -: -Option -< -HalSurface -< -hal -: -: -api -: -: -Dx12 -> -> -# -[ -cfg -( -all +; +fn +as_info ( -feature -= -" -dx11 -" -windows -) +& +self ) -] -pub -dx11 -: -Option -< -HalSurface -< -hal -: -: -api -: -: -Dx11 -> +- > -# -[ -cfg -( -feature -= -" -gles -" -) -] -pub -gl -: -Option -< -HalSurface +& +ResourceInfo < -hal -: -: -api -: -: -Gles -> +SurfaceId > -} -impl -crate -: -: -resource -: -: -Resource -for -Surface { -const -TYPE -: & -' -static -str -= -" -Surface -" -; +self +. +info +} fn -life_guard +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +SurfaceId +> { -unreachable -! -( -) +& +mut +self +. +info } fn label @@ -1412,14 +1420,19 @@ self ) - > -& -str +String { +String +: +: +from +( " < Surface > " +) } } impl @@ -1527,10 +1540,7 @@ Adapter < A : -hal -: -: -Api +HalApi > { pub @@ -1546,9 +1556,16 @@ ExposedAdapter < A > -life_guard +pub +( +crate +) +info : -LifeGuard +ResourceInfo +< +AdapterId +> } impl < @@ -1640,9 +1657,9 @@ MIN_BUFFER_OFFSET_ALIGNMENT_LOWER_BOUND Self { raw -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -2135,17 +2152,16 @@ flags } } fn -create_device_from_hal +create_device_and_queue_from_hal ( -& self -self_id -: -AdapterId -open -: -hal : +& +Arc +< +Self +> +hal_device : OpenDevice < @@ -2179,17 +2195,23 @@ Path > Result < +( Device < A > +Queue +< +A +> +) RequestDeviceError > { log : : -trace +info ! ( " @@ -2210,30 +2232,26 @@ raw . capabilities ; +if +let +Ok +( +device +) += Device : : new ( -open -Stored -{ -value -: -Valid -( -self_id -) -ref_count -: -self +hal_device . -life_guard +device +& +hal_device . -add_ref -( -) -} +queue +self caps . alignments @@ -2252,26 +2270,66 @@ desc trace_path instance_flags ) -. -or -( -Err -( -RequestDeviceError +{ +let +queue += +Queue +{ +device : +None +raw : -OutOfMemory -) -) -} -fn -create_device +Some ( -& -self -self_id +hal_device +. +queue +) +info : -AdapterId +ResourceInfo +: +: +new +( +" +< +Queue +> +" +) +} +; +return +Ok +( +( +device +queue +) +) +; +} +Err +( +RequestDeviceError +: +: +OutOfMemory +) +} +fn +create_device_and_queue +( +self +: +& +Arc +< +Self +> desc : & @@ -2300,10 +2358,16 @@ Path > Result < +( Device < A > +Queue +< +A +> +) RequestDeviceError > { @@ -2445,7 +2509,7 @@ DOWNLEVEL_WARNING_MESSAGE log : : -info +warn ! ( " @@ -2659,9 +2723,8 @@ Internal ; self . -create_device_from_hal +create_device_and_queue_from_hal ( -self_id open desc instance_flags @@ -2673,18 +2736,12 @@ impl < A : -hal -: -: -Api +HalApi > -crate -: -: -resource -: -: Resource +< +AdapterId +> for Adapter < @@ -2694,30 +2751,52 @@ A const TYPE : -& -' -static -str +ResourceType = " Adapter " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +AdapterId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +AdapterId +> { & +mut self . -life_guard +info } } # @@ -2929,6 +3008,9 @@ Not enough memory left +to +request +device " ) ] @@ -3001,7 +3083,7 @@ impl < I : -Clone +Copy > AdapterInputs < @@ -3061,7 +3143,7 @@ id b ) . -cloned +copied ( ) Self @@ -3302,12 +3384,17 @@ init < A : -hal -: -: -Api +HalApi > ( +any_surface +: +& +mut +Option +< +AnySurface +> inst : & @@ -3331,16 +3418,21 @@ raw_window_handle : RawWindowHandle ) -- -> -Option -< -HalSurface -< -A -> -> { +if +any_surface +. +is_none +( +) +{ +if +let +Some +( +surface +) += inst . as_ref @@ -3372,13 +3464,21 @@ raw Some ( HalSurface +: +: +< +A +> { raw -/ -/ -acquired_texture : -None +Arc +: +: +new +( +raw +) } ) Err @@ -3410,15 +3510,30 @@ None } } ) +{ +* +any_surface += +Some +( +AnySurface +: +: +new +( +surface +) +) +; +} +} } let -surface +mut +hal_surface = -Surface -{ -presentation -: None +; # [ cfg @@ -3441,8 +3556,6 @@ wasm32 ) ) ] -vulkan -: init : : @@ -3457,6 +3570,9 @@ Vulkan > ( & +mut +hal_surface +& self . instance @@ -3465,6 +3581,7 @@ vulkan display_handle window_handle ) +; # [ cfg @@ -3492,8 +3609,6 @@ ios ) ) ] -metal -: init : : @@ -3508,6 +3623,9 @@ Metal > ( & +mut +hal_surface +& self . instance @@ -3516,6 +3634,7 @@ metal display_handle window_handle ) +; # [ cfg @@ -3531,8 +3650,6 @@ windows ) ) ] -dx12 -: init : : @@ -3547,6 +3664,9 @@ Dx12 > ( & +mut +hal_surface +& self . instance @@ -3555,6 +3675,7 @@ dx12 display_handle window_handle ) +; # [ cfg @@ -3570,8 +3691,6 @@ windows ) ) ] -dx11 -: init : : @@ -3586,6 +3705,9 @@ Dx11 > ( & +mut +hal_surface +& self . instance @@ -3594,6 +3716,7 @@ dx11 display_handle window_handle ) +; # [ cfg @@ -3605,8 +3728,6 @@ gles " ) ] -gl -: init : : @@ -3621,6 +3742,9 @@ Gles > ( & +mut +hal_surface +& self . instance @@ -3629,27 +3753,59 @@ gl display_handle window_handle ) -} ; let -mut -token +surface = -Token +Surface +{ +presentation +: +Mutex +: +: +new +( +None +) +info +: +ResourceInfo : : -root +new +( +" +< +Surface +> +" +) +raw +: +hal_surface +. +unwrap ( ) +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -3657,14 +3813,9 @@ id_in assign ( surface -& -mut -token ) ; id -. -0 } / / @@ -3762,9 +3913,43 @@ Surface { presentation : +Mutex +: +: +new +( None -metal +) +info +: +ResourceInfo +: +: +new +( +" +< +Surface +> +" +) +raw +: +{ +let +hal_surface +: +HalSurface +< +hal +: +: +api : +: +Metal +> += self . instance @@ -3784,7 +3969,11 @@ HalSurface { raw : -{ +Arc +: +: +new +( / / we @@ -3828,7 +4017,7 @@ layer ) } ) -} +) / / acquired_texture @@ -3836,66 +4025,37 @@ acquired_texture None } ) -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not -( -target_arch -= -" -wasm32 -" -) -) -) -] -vulkan -: -None -# -[ -cfg +. +unwrap ( -feature -= -" -gles -" ) -] -gl -: -None -} ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -3903,14 +4063,9 @@ id_in assign ( surface -& -mut -token ) ; id -. -0 } # [ @@ -3991,9 +4146,43 @@ Surface { presentation : +Mutex +: +: +new +( None -gl +) +info +: +ResourceInfo +: +: +new +( +" +< +Surface +> +" +) +raw +: +{ +let +hal_surface +: +HalSurface +< +hal +: : +api +: +: +Gles +> += self . instance @@ -4010,19 +4199,30 @@ map inst | { +let +raw_surface += +inst +. +create_surface_from_canvas +( +canvas +) +? +; Ok ( HalSurface { raw : -inst -. -create_surface_from_canvas +Arc +: +: +new ( -canvas +raw_surface ) -? } ) } @@ -4032,27 +4232,37 @@ transpose ( ) ? -} +. +unwrap +( +) ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -4060,16 +4270,11 @@ id_in assign ( surface -& -mut -token ) ; Ok ( id -. -0 ) } # @@ -4151,9 +4356,43 @@ Surface { presentation : +Mutex +: +: +new +( None -gl +) +info +: +ResourceInfo +: +: +new +( +" +< +Surface +> +" +) +raw +: +{ +let +hal_surface +: +HalSurface +< +hal +: +: +api : +: +Gles +> += self . instance @@ -4170,19 +4409,30 @@ map inst | { +let +raw_surface += +inst +. +create_surface_from_offscreen_canvas +( +canvas +) +? +; Ok ( HalSurface { raw : -inst -. -create_surface_from_offscreen_canvas +Arc +: +: +new ( -canvas +raw_surface ) -? } ) } @@ -4192,27 +4442,37 @@ transpose ( ) ? -} +. +unwrap +( +) ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -4220,16 +4480,11 @@ id_in assign ( surface -& -mut -token ) ; Ok ( id -. -0 ) } # @@ -4325,49 +4580,43 @@ Surface { presentation : -None -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not +Mutex +: +: +new ( -target_arch -= -" -wasm32 -" -) -) +None ) -] -vulkan +info : -None -# -[ -cfg -( -all +ResourceInfo +: +: +new ( -feature -= " -dx12 +< +Surface +> " -windows ) -) -] -dx12 +raw +: +{ +let +hal_surface +: +HalSurface +< +hal +: : +api +: +: +Dx12 +> += self . instance @@ -4387,6 +4636,11 @@ HalSurface { raw : +Arc +: +: +new +( unsafe { inst @@ -4398,61 +4652,40 @@ as _ ) } -} -) -# -[ -cfg -( -all -( -feature -= -" -dx11 -" -windows ) +} ) -] -dx11 -: -None -# -[ -cfg +. +unwrap ( -feature -= -" -gles -" ) -] -gl -: -None -} ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -4460,14 +4693,9 @@ id_in assign ( surface -& -mut -token ) ; id -. -0 } # [ @@ -4562,49 +4790,43 @@ Surface { presentation : -None -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not +Mutex +: +: +new ( -target_arch -= -" -wasm32 -" -) -) +None ) -] -vulkan +info : -None -# -[ -cfg -( -all +ResourceInfo +: +: +new ( -feature -= " -dx12 +< +Surface +> " -windows -) ) -] -dx12 +raw +: +{ +let +hal_surface +: +HalSurface +< +hal : +: +api +: +: +Dx12 +> += self . instance @@ -4624,6 +4846,11 @@ HalSurface { raw : +Arc +: +: +new +( unsafe { inst @@ -4633,61 +4860,40 @@ create_surface_from_surface_handle surface_handle ) } -} -) -# -[ -cfg -( -all -( -feature -= -" -dx11 -" -windows ) +} ) -] -dx11 -: -None -# -[ -cfg +. +unwrap ( -feature -= -" -gles -" ) -] -gl -: -None -} ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -4695,14 +4901,9 @@ id_in assign ( surface -& -mut -token ) ; id -. -0 } # [ @@ -4797,49 +4998,43 @@ Surface { presentation : -None -# -[ -cfg -( -all -( -feature -= -" -vulkan -" -not +Mutex +: +: +new ( -target_arch -= -" -wasm32 -" -) -) +None ) -] -vulkan +info : -None -# -[ -cfg -( -all +ResourceInfo +: +: +new ( -feature -= " -dx12 +< +Surface +> " -windows ) -) -] -dx12 +raw +: +{ +let +hal_surface +: +HalSurface +< +hal +: +: +api : +: +Dx12 +> += self . instance @@ -4859,6 +5054,11 @@ HalSurface { raw : +Arc +: +: +new +( unsafe { inst @@ -4870,61 +5070,40 @@ as _ ) } -} -) -# -[ -cfg -( -all -( -feature -= -" -dx11 -" -windows ) +} ) -] -dx11 -: -None -# -[ -cfg +. +unwrap ( -feature -= -" -gles -" ) -] -gl -: -None -} ; -let -mut -token -= -Token +AnySurface : : -root +new ( +hal_surface ) +} +} ; let +( id +_ +) = self . surfaces . prepare +: +: +< +G +> ( id_in ) @@ -4932,14 +5111,9 @@ id_in assign ( surface -& -mut -token ) ; id -. -0 } pub fn @@ -4969,7 +5143,7 @@ drop log : : -trace +info ! ( " @@ -4985,45 +5159,6 @@ id " ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -surface -_ -) -= -self -. -surfaces -. -unregister -( -id -& -mut -token -) -; -let -mut -surface -= -surface -. -unwrap -( -) -; fn unconfigure < @@ -5045,11 +5180,7 @@ G surface : & -mut -HalSurface -< -A -> +AnySurface present : & @@ -5067,19 +5198,86 @@ hub global ) ; -hub +if +let +Some +( +hal_surface +) += +surface . -surface_unconfigure +downcast_ref +: +: +< +A +> ( +) +{ +if +let +Some +( +device +) += present . -device_id +device . -value -surface +downcast_ref +: +: +< +A +> +( +) +{ +hub +. +surface_unconfigure +( +device +hal_surface ) ; } +} +} +let +surface += +self +. +surfaces +. +unregister +( +id +) +; +if +let +Ok +( +surface +) += +Arc +: +: +try_unwrap +( +surface +. +unwrap +( +) +) +{ if let Some @@ -5091,14 +5289,11 @@ surface . presentation . -take +lock ( ) -{ -match -present . -backend +take ( ) { @@ -5124,29 +5319,29 @@ wasm32 ) ) ] -Backend +unconfigure +: +: +< +_ +hal +: +: +api : : Vulkan -= > -unconfigure ( self +& surface . -vulkan -. -as_mut -( -) -. -unwrap -( -) +raw & present ) +; # [ cfg @@ -5174,29 +5369,29 @@ ios ) ) ] -Backend +unconfigure +: +: +< +_ +hal +: +: +api : : Metal -= > -unconfigure ( self +& surface . -metal -. -as_mut -( -) -. -unwrap -( -) +raw & present ) +; # [ cfg @@ -5212,29 +5407,29 @@ windows ) ) ] -Backend +unconfigure +: +: +< +_ +hal +: +: +api : : Dx12 -= > -unconfigure ( self +& surface . -dx12 -. -as_mut -( -) -. -unwrap -( -) +raw & present ) +; # [ cfg @@ -5250,29 +5445,29 @@ windows ) ) ] -Backend +unconfigure +: +: +< +_ +hal +: +: +api : : Dx11 -= > -unconfigure ( self +& surface . -dx11 -. -as_mut -( -) -. -unwrap -( -) +raw & present ) +; # [ cfg @@ -5284,37 +5479,29 @@ gles " ) ] -Backend +unconfigure : : -Gl -= +< +_ +hal +: +: +api +: +: +Gles > -unconfigure ( self +& surface . -gl -. -as_mut -( -) -. -unwrap -( -) +raw & present ) -_ -= -> -unreachable -! -( -) -} +; } self . @@ -5326,6 +5513,26 @@ surface ) ; } +else +{ +panic +! +( +" +Surface +cannot +be +destroyed +because +is +still +in +use +" +) +; +} +} fn enumerate < @@ -5457,17 +5664,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let hal_adapters = unsafe @@ -5524,27 +5720,28 @@ info ) ; let +( id +_ +) = hub . adapters . prepare +: +: +< +G +> ( id_backend -. -clone -( -) ) . assign ( adapter -& -mut -token ) ; list @@ -5552,8 +5749,6 @@ list push ( id -. -0 ) ; } @@ -5910,17 +6105,6 @@ None > { let -mut -token -= -Token -: -: -root -( -) -; -let adapter = Adapter @@ -5966,7 +6150,10 @@ info ) ; let +( id +_ +) = HalApi : @@ -5979,6 +6166,11 @@ self adapters . prepare +: +: +< +G +> ( new_id . @@ -5990,16 +6182,11 @@ unwrap assign ( adapter -& -mut -token ) ; Some ( id -. -0 ) } } @@ -6069,7 +6256,7 @@ A HalApi I : -Clone +Copy > ( _ @@ -6325,34 +6512,6 @@ new } } let -mut -token -= -Token -: -: -root -( -) -; -let -( -surface_guard -_ -) -= -self -. -surfaces -. -read -( -& -mut -token -) -; -let compatible_surface = desc @@ -6365,7 +6524,9 @@ map id | { -surface_guard +self +. +surfaces . get ( @@ -6394,6 +6555,27 @@ transpose ? ; let +compatible_surface += +compatible_surface +. +as_ref +( +) +. +map +( +| +surface +| +surface +. +as_ref +( +) +) +; +let mut device_types = @@ -6669,28 +6851,6 @@ mut device_types ) ; -/ -/ -need -to -free -the -token -to -be -used -by -select -drop -( -surface_guard -) -; -drop -( -token -) -; if device_types . @@ -7416,17 +7576,6 @@ create_adapter_from_hal ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = A @@ -7440,10 +7589,50 @@ self adapters . prepare +: +: +< +G +> ( input ) ; +let +( +id +_adapter +) +: +( +crate +: +: +id +: +: +Id +< +Adapter +< +hal +: +: +empty +: +: +Api +> +> +Arc +< +Adapter +< +A +> +> +) += match A : @@ -7489,12 +7678,7 @@ new ( hal_adapter ) -& -mut -token ) -. -0 # [ cfg @@ -7539,12 +7723,7 @@ new ( hal_adapter ) -& -mut -token ) -. -0 # [ cfg @@ -7577,12 +7756,7 @@ new ( hal_adapter ) -& -mut -token ) -. -0 # [ cfg @@ -7615,12 +7789,7 @@ new ( hal_adapter ) -& -mut -token ) -. -0 # [ cfg @@ -7649,12 +7818,7 @@ new ( hal_adapter ) -& -mut -token ) -. -0 _ = > @@ -7663,6 +7827,25 @@ unreachable ( ) } +; +log +: +: +info +! +( +" +Created +Adapter +{ +: +? +} +" +id +) +; +id } pub fn @@ -7701,36 +7884,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) -= hub . adapters . -read -( -& -mut -token -) -; -adapter_guard -. get ( adapter_id @@ -7803,36 +7960,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) -= hub . adapters . -read -( -& -mut -token -) -; -adapter_guard -. get ( adapter_id @@ -7896,36 +8027,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) -= hub . adapters . -read -( -& -mut -token -) -; -adapter_guard -. get ( adapter_id @@ -7988,36 +8093,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) -= hub . adapters . -read -( -& -mut -token -) -; -adapter_guard -. get ( adapter_id @@ -8086,36 +8165,10 @@ hub self ) ; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) -= hub . adapters . -read -( -& -mut -token -) -; -adapter_guard -. get ( adapter_id @@ -8185,38 +8238,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -adapter_guard -_ -) +adapter = hub . adapters . -read -( -& -mut -token -) -; -let -adapter -= -adapter_guard -. get ( adapter_id @@ -8309,21 +8336,7 @@ self ; let mut -token -= -Token -: -: -root -( -) -; -let -( -mut -adapter_guard -_ -) +adapters_locked = hub . @@ -8331,18 +8344,15 @@ adapters . write ( -& -mut -token ) ; let free = match -adapter_guard +adapters_locked . -get_mut +get ( adapter_id ) @@ -8353,22 +8363,12 @@ adapter ) = > -adapter -. -life_guard -. -ref_count -. -take -( -) -. -unwrap -( -) -. -load +Arc +: +: +strong_count ( +adapter ) = = @@ -8395,7 +8395,7 @@ adapter_id & mut * -adapter_guard +adapters_locked ) ; } @@ -8443,18 +8443,26 @@ path : Path > -id_in +device_id_in : Input < G DeviceId > +queue_id_in +: +Input +< +G +QueueId +> ) - > ( DeviceId +QueueId Option < RequestDeviceError @@ -8501,26 +8509,37 @@ self ) ; let -mut -token +device_fid = -Token +hub +. +devices +. +prepare : : -root +< +G +> ( +device_id_in ) ; let -fid +queue_fid = hub . -devices +queues . prepare +: +: +< +G +> ( -id_in +queue_id_in ) ; let @@ -8529,29 +8548,13 @@ error loop { let -( -adapter_guard -mut -token -) +adapter = +match hub . adapters . -read -( -& -mut -token -) -; -let -adapter -= -match -adapter_guard -. get ( adapter_id @@ -8578,67 +8581,180 @@ InvalidAdapter } ; let +( +device +mut +queue +) += +match +adapter +. +create_device_and_queue +( +desc +self +. +instance +. +flags +trace_path +) +{ +Ok +( +( +device +queue +) +) += +> +( +device +queue +) +Err +( +e +) += +> +break +e +} +; +let +( +device_id +_ +) += +device_fid +. +assign +( +device +) +; +log +: +: +info +! +( +" +Created +Device +{ +: +? +} +" +device_id +) +; +let device = -match -adapter -. -create_device -( -adapter_id -desc -self +hub . -instance +devices . -flags -trace_path +get +( +device_id ) -{ -Ok +. +unwrap ( -device ) +; +queue +. +device = -> +Some +( device -Err +. +clone ( -e ) -= -> -break -e -} +) ; let -id +( +queue_id +_ +) = -fid +queue_fid . assign ( +queue +) +; +log +: +: +info +! +( +" +Created +Queue +{ +: +? +} +" +queue_id +) +; device -& -mut -token +. +queue_id +. +write +( +) +. +replace +( +queue_id ) ; return ( -id -. -0 +device_id +queue_id None ) ; } ; let -id +device_id = -fid +device_fid +. +assign_error +( +desc +. +label +. +borrow_or_default +( +) +) +; +let +queue_id += +queue_fid . assign_error ( @@ -8649,13 +8765,11 @@ label borrow_or_default ( ) -& -mut -token ) ; ( -id +device_id +queue_id Some ( error @@ -8717,9 +8831,6 @@ adapter_id AdapterId hal_device : -hal -: -: OpenDevice < A @@ -8741,18 +8852,26 @@ path : Path > -id_in +device_id_in : Input < G DeviceId > +queue_id_in +: +Input +< +G +QueueId +> ) - > ( DeviceId +QueueId Option < RequestDeviceError @@ -8766,7 +8885,7 @@ scope ! ( " -Adapter +Global : : create_device_from_hal @@ -8785,26 +8904,37 @@ self ) ; let -mut -token +devices_fid = -Token +hub +. +devices +. +prepare : : -root +< +G +> ( +device_id_in ) ; let -fid +queues_fid = hub . -devices +queues . prepare +: +: +< +G +> ( -id_in +queue_id_in ) ; let @@ -8813,29 +8943,13 @@ error loop { let -( -adapter_guard -mut -token -) +adapter = +match hub . adapters . -read -( -& -mut -token -) -; -let -adapter -= -match -adapter_guard -. get ( adapter_id @@ -8862,14 +8976,17 @@ InvalidAdapter } ; let +( device +mut +queue +) = match adapter . -create_device_from_hal +create_device_and_queue_from_hal ( -adapter_id hal_device desc self @@ -8898,32 +9015,120 @@ e } ; let -id +( +device_id +_ +) = -fid +devices_fid . assign ( device -& -mut -token ) ; -return +log +: +: +info +! ( -id +" +Created +Device +{ +: +? +} +" +device_id +) +; +let +device += +hub . -0 +devices +. +get +( +device_id +) +. +unwrap +( +) +; +queue +. +device += +Some +( +device +. +clone +( +) +) +; +let +( +queue_id +_ +) += +queues_fid +. +assign +( +queue +) +; +log +: +: +info +! +( +" +Created +Queue +{ +: +? +} +" +queue_id +) +; +device +. +queue_id +. +write +( +) +. +replace +( +queue_id +) +; +return +( +device_id +queue_id None ) ; } ; let -id +device_id = -fid +devices_fid . assign_error ( @@ -8934,13 +9139,27 @@ label borrow_or_default ( ) -& -mut -token ) ; +let +queue_id += +queues_fid +. +assign_error ( -id +desc +. +label +. +borrow_or_default +( +) +) +; +( +device_id +queue_id Some ( error diff --git a/third_party/rust/wgpu-core/src/lib.rs b/third_party/rust/wgpu-core/src/lib.rs index 017bf6129d7b0..9f0a810519d17 100644 --- a/third_party/rust/wgpu-core/src/lib.rs +++ b/third_party/rust/wgpu-core/src/lib.rs @@ -374,6 +374,10 @@ pattern_type_mismatch ] pub mod +any_surface +; +pub +mod binding_model ; pub @@ -457,15 +461,6 @@ MAX_VERTEX_BUFFERS } ; use -atomic -: -: -{ -AtomicUsize -Ordering -} -; -use std : : @@ -481,11 +476,6 @@ raw : : c_char -ptr -sync -: -: -atomic } ; / @@ -563,1362 +553,251 @@ trait LabelHelpers < ' -a -> -{ -fn -borrow_option -( -& -' -a -self -) -- -> -Option -< -& -' -a -str -> -; -fn -to_hal -( -& -' -a -self -flags -: -wgt -: -: -InstanceFlags -) -- -> -Option -< -& -' -a -str -> -; -fn -borrow_or_default -( -& -' -a -self -) -- -> -& -' -a -str -; -} -impl -< -' -a -> -LabelHelpers -< -' -a -> -for -Label -< -' -a -> -{ -fn -borrow_option -( -& -' -a -self -) -- -> -Option -< -& -' -a -str -> -{ -self -. -as_ref -( -) -. -map -( -| -cow -| -cow -. -as_ref -( -) -) -} -fn -to_hal -( -& -' -a -self -flags -: -wgt -: -: -InstanceFlags -) -- -> -Option -< -& -' -a -str -> -{ -if -flags -. -contains -( -wgt -: -: -InstanceFlags -: -: -DISCARD_HAL_LABELS -) -{ -return -None -; -} -self -. -as_ref -( -) -. -map -( -| -cow -| -cow -. -as_ref -( -) -) -} -fn -borrow_or_default -( -& -' -a -self -) -- -> -& -' -a -str -{ -self -. -borrow_option -( -) -. -unwrap_or_default -( -) -} -} -pub -fn -hal_label -( -opt -: -Option -< -& -str -> -flags -: -wgt -: -: -InstanceFlags -) -- -> -Option -< -& -str -> -{ -if -flags -. -contains -( -wgt -: -: -InstanceFlags -: -: -DISCARD_HAL_LABELS -) -{ -return -None -; -} -opt -} -/ -/ -/ -Reference -count -object -that -is -1 -: -1 -with -each -reference -. -/ -/ -/ -/ -/ -/ -All -the -clones -of -a -given -RefCount -point -to -the -same -/ -/ -/ -heap -- -allocated -atomic -reference -count -. -When -the -count -drops -to -/ -/ -/ -zero -only -the -count -is -freed -. -No -other -automatic -cleanup -takes -/ -/ -/ -place -; -this -is -just -a -reference -count -not -a -smart -pointer -. -/ -/ -/ -/ -/ -/ -RefCount -values -are -created -only -by -[ -LifeGuard -: -: -new -] -and -by -/ -/ -/ -Clone -so -every -RefCount -is -implicitly -tied -to -some -/ -/ -/ -[ -LifeGuard -] -. -# -[ -derive -( -Debug -) -] -struct -RefCount -( -ptr -: -: -NonNull -< -AtomicUsize -> -) -; -unsafe -impl -Send -for -RefCount -{ -} -unsafe -impl -Sync -for -RefCount -{ -} -impl -RefCount -{ -const -MAX -: -usize -= -1 -< -< -24 -; -/ -/ -/ -Construct -a -new -RefCount -with -an -initial -count -of -1 -. -fn -new -( -) -- -> -RefCount -{ -let -bx -= -Box -: -: -new -( -AtomicUsize -: -: -new -( -1 -) -) -; -Self -( -unsafe -{ -ptr -: -: -NonNull -: -: -new_unchecked -( -Box -: -: -into_raw -( -bx -) -) -} -) -} -fn -load -( -& -self -) -- -> -usize -{ -unsafe -{ -self -. -0 -. -as_ref -( -) -} -. -load -( -Ordering -: -: -Acquire -) -} -} -impl -Clone -for -RefCount -{ -fn -clone -( -& -self -) -- -> -Self -{ -let -old_size -= -unsafe -{ -self -. -0 -. -as_ref -( -) -} -. -fetch_add -( -1 -Ordering -: -: -AcqRel -) -; -assert -! -( -old_size -< -Self -: -: -MAX -) -; -Self -( -self -. -0 -) -} -} -impl -Drop -for -RefCount -{ -fn -drop -( -& -mut -self -) -{ -unsafe -{ -if -self -. -0 -. -as_ref -( -) -. -fetch_sub -( -1 -Ordering -: -: -AcqRel -) -= -= -1 -{ -drop -( -Box -: -: -from_raw -( -self -. -0 -. -as_ptr -( -) -) -) -; -} -} -} -} -/ -/ -/ -Reference -count -object -that -tracks -multiple -references -. -/ -/ -/ -Unlike -RefCount -it -' -s -manually -inc -( -) -/ -dec -( -) -called -. -# -[ -derive -( -Debug -) -] -struct -MultiRefCount -( -AtomicUsize -) -; -impl -MultiRefCount -{ -fn -new -( -) -- -> -Self -{ -Self -( -AtomicUsize -: -: -new -( -1 -) -) -} -fn -inc -( -& -self -) -{ -self -. -0 -. -fetch_add -( -1 -Ordering -: -: -AcqRel -) -; -} -fn -dec_and_check_empty -( -& -self -) -- -> -bool -{ -self -. -0 -. -fetch_sub -( -1 -Ordering -: -: -AcqRel -) -= -= -1 -} -} -/ -/ -/ -Information -needed -to -decide -when -it -' -s -safe -to -free -some -wgpu -- -core -/ -/ -/ -resource -. -/ -/ -/ -/ -/ -/ -Each -type -representing -a -wgpu -- -core -resource -like -[ -Device -] -/ -/ -/ -[ -Buffer -] -etc -. -contains -a -LifeGuard -which -indicates -whether -/ -/ -/ -it -is -safe -to -free -. -/ -/ -/ -/ -/ -/ -A -resource -may -need -to -be -retained -for -any -of -several -reasons -: -/ -/ -/ -/ -/ -/ -- -The -user -may -hold -a -reference -to -it -( -via -a -wgpu -: -: -Buffer -say -) -. -/ -/ -/ -/ -/ -/ -- -Other -resources -may -depend -on -it -( -a -texture -view -' -s -backing -/ -/ -/ -texture -for -example -) -. -/ -/ -/ -/ -/ -/ -- -It -may -be -used -by -commands -sent -to -the -GPU -that -have -not -yet -/ -/ -/ -finished -execution -. -/ -/ -/ -/ -/ -/ -[ -Device -] -: -device -: -: -Device -/ -/ -/ -[ -Buffer -] -: -resource -: -: -Buffer -# -[ -derive -( -Debug -) -] -pub -struct -LifeGuard -{ -/ -/ -/ -RefCount -for -the -user -' -s -reference -to -this -resource -. -/ -/ -/ -/ -/ -/ -When -the -user -first -creates -a -wgpu -- -core -resource -this -RefCount -is -/ -/ -/ -created -along -with -the -resource -' -s -LifeGuard -. -When -the -user -drops -the -/ -/ -/ -resource -we -swap -this -out -for -None -. -Note -that -the -resource -may -/ -/ -/ -still -be -held -alive -by -other -resources -. -/ -/ -/ -/ -/ -/ -Any -Stored -< -T -> -value -holds -a -clone -of -this -RefCount -along -with -the -id -/ -/ -/ -of -a -T -resource -. -ref_count -: -Option -< -RefCount -> -/ -/ -/ -The -index -of -the -last -queue -submission -in -which -the -resource -/ -/ -/ -was -used -. -/ -/ -/ -/ -/ -/ -Each -queue -submission -is -fenced -and -assigned -an -index -number -/ -/ -/ -sequentially -. -Thus -when -a -queue -submission -completes -we -know -any -/ -/ -/ -resources -used -in -that -submission -and -any -lower -- -numbered -submissions -are -/ -/ -/ -no -longer -in -use -by -the -GPU -. -submission_index -: -AtomicUsize -/ -/ -/ -The -label -from -the -descriptor -used -to -create -the -resource -. -# -[ -cfg -( -debug_assertions -) -] -pub -( -crate -) -label -: -String -} -impl -LifeGuard +a +> { -# -[ -allow -( -unused_variables -) -] fn -new +borrow_option ( -label -: & -str +' +a +self ) - > -Self -{ -Self -{ -ref_count -: -Some -( -RefCount -: -: -new +Option +< +& +' +a +str +> +; +fn +to_hal ( -) -) -submission_index +& +' +a +self +flags : -AtomicUsize +wgt : : -new -( -0 -) -# -[ -cfg -( -debug_assertions +InstanceFlags ) -] -label -: -label -. -to_string +- +> +Option +< +& +' +a +str +> +; +fn +borrow_or_default ( +& +' +a +self ) +- +> +& +' +a +str +; } -} +impl +< +' +a +> +LabelHelpers +< +' +a +> +for +Label +< +' +a +> +{ fn -add_ref +borrow_option ( & +' +a self ) - > -RefCount +Option +< +& +' +a +str +> { self . -ref_count -. -clone +as_ref ( ) . -unwrap +map +( +| +cow +| +cow +. +as_ref ( ) +) } -/ -/ -/ -Record -that -this -resource -will -be -used -by -the -queue -submission -with -the -/ -/ -/ -given -index -. -/ -/ -/ -/ -/ -/ -Returns -true -if -the -resource -is -still -held -by -the -user -. fn -use_at +to_hal ( & +' +a self -submit_index +flags : -SubmissionIndex +wgt +: +: +InstanceFlags ) - > -bool +Option +< +& +' +a +str +> { -self -. -submission_index +if +flags . -store +contains ( -submit_index -as -_ -Ordering +wgt : : -Release +InstanceFlags +: +: +DISCARD_HAL_LABELS ) +{ +return +None ; +} self . -ref_count +as_ref +( +) +. +map +( +| +cow +| +cow . -is_some +as_ref ( ) +) } fn -life_count +borrow_or_default ( & +' +a self ) - > -SubmissionIndex +& +' +a +str { self . -submission_index +borrow_option +( +) . -load +unwrap_or_default ( -Ordering -: -: -Acquire ) -as -_ } } -# -[ -derive +pub +fn +hal_label ( -Clone -Debug -) -] -struct -Stored +opt +: +Option < -T +& +str > -{ -value +flags : -id +wgt : : -Valid +InstanceFlags +) +- +> +Option < -T +& +str > -ref_count +{ +if +flags +. +contains +( +wgt +: +: +InstanceFlags +: : -RefCount +DISCARD_HAL_LABELS +) +{ +return +None +; +} +opt } const DOWNLEVEL_WARNING_MESSAGE @@ -3299,10 +2178,7 @@ device_create_buffer < A : -hal -: -: -Api +HalApi > ( & @@ -3386,7 +2262,7 @@ that is specific to -global +hub : : Global diff --git a/third_party/rust/wgpu-core/src/pipeline.rs b/third_party/rust/wgpu-core/src/pipeline.rs index 78230298fe889..f6398b74abb71 100644 --- a/third_party/rust/wgpu-core/src/pipeline.rs +++ b/third_party/rust/wgpu-core/src/pipeline.rs @@ -1,3 +1,23 @@ +# +[ +cfg +( +feature += +" +trace +" +) +] +use +crate +: +: +device +: +: +trace +; use crate : @@ -9,6 +29,7 @@ binding_model { CreateBindGroupLayoutError CreatePipelineLayoutError +PipelineLayout } command : @@ -18,27 +39,35 @@ device : : { +Device DeviceError MissingDownlevelFlags MissingFeatures RenderPassContext } +hal_api +: +: +HalApi id : : { -DeviceId +ComputePipelineId PipelineLayoutId +RenderPipelineId ShaderModuleId } resource : : +{ Resource +ResourceInfo +ResourceType +} validation Label -LifeGuard -Stored } ; use @@ -69,6 +98,10 @@ num : : NonZeroU32 +sync +: +: +Arc } ; use @@ -343,10 +376,7 @@ ShaderModule < A : -hal -: -: -Api +HalApi > { pub @@ -355,19 +385,25 @@ crate ) raw : +Option +< A : : ShaderModule +> pub ( crate ) -device_id +device : -Stored +Arc +< +Device < -DeviceId +A +> > pub ( @@ -382,6 +418,16 @@ validation : Interface > +pub +( +crate +) +info +: +ResourceInfo +< +ShaderModuleId +> # [ cfg @@ -401,12 +447,150 @@ impl < A : +HalApi +> +Drop +for +ShaderModule +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +ShaderModule +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +# +[ +cfg +( +feature += +" +trace +" +) +] +if +let +Some +( +ref +mut +trace +) += +* +self +. +device +. +trace +. +lock +( +) +{ +trace +. +add +( +trace +: +: +Action +: +: +DestroyShaderModule +( +self +. +info +. +id +( +) +) +) +; +} +unsafe +{ +use hal : : -Api +Device +; +self +. +device +. +raw +( +) +. +destroy_shader_module +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi > Resource +< +ShaderModuleId +> for ShaderModule < @@ -416,17 +600,14 @@ A const TYPE : -& -' -static -str +ResourceType = " ShaderModule " ; fn -life_guard +as_info ( & self @@ -434,12 +615,37 @@ self - > & -LifeGuard +ResourceInfo +< +ShaderModuleId +> { -unreachable -! +& +self +. +info +} +fn +as_info_mut ( +& +mut +self ) +- +> +& +mut +ResourceInfo +< +ShaderModuleId +> +{ +& +mut +self +. +info } fn label @@ -449,8 +655,7 @@ self ) - > -& -str +String { # [ @@ -460,10 +665,13 @@ debug_assertions ) ] return -& self . label +. +clone +( +) ; # [ @@ -476,11 +684,57 @@ debug_assertions ) ] return -" -" +String +: +: +new +( +) ; } } +impl +< +A +: +HalApi +> +ShaderModule +< +A +> +{ +pub +( +crate +) +fn +raw +( +& +self +) +- +> +& +A +: +: +ShaderModule +{ +self +. +raw +. +as_ref +( +) +. +unwrap +( +) +} +} # [ derive @@ -1675,10 +1929,7 @@ ComputePipeline < A : -hal -: -: -Api +HalApi > { pub @@ -1687,29 +1938,51 @@ crate ) raw : +Option +< A : : ComputePipeline +> pub ( crate ) -layout_id +layout : -Stored +Arc < -PipelineLayoutId +PipelineLayout +< +A +> > pub ( crate ) -device_id +device : -Stored +Arc < -DeviceId +Device +< +A +> +> +pub +( +crate +) +_shader_module +: +Arc +< +ShaderModule +< +A +> > pub ( @@ -1729,22 +2002,109 @@ MAX_BIND_GROUPS > pub ( -crate +crate +) +info +: +ResourceInfo +< +ComputePipelineId +> +} +impl +< +A +: +HalApi +> +Drop +for +ComputePipeline +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +ComputePipeline +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use +hal +: +: +Device +; +self +. +device +. +raw +( ) -life_guard -: -LifeGuard +. +destroy_compute_pipeline +( +raw +) +; +} +} +} } impl < A : -hal -: -: -Api +HalApi > Resource +< +ComputePipelineId +> for ComputePipeline < @@ -1754,30 +2114,94 @@ A const TYPE : -& -' -static -str +ResourceType = " ComputePipeline " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +ComputePipelineId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +ComputePipelineId +> +{ +& +mut +self +. +info +} +} +impl +< +A +: +HalApi +> +ComputePipeline +< +A +> { +pub +( +crate +) +fn +raw +( +& +self +) +- +> & +A +: +: +ComputePipeline +{ self . -life_guard +raw +. +as_ref +( +) +. +unwrap +( +) } } / @@ -3780,10 +4204,7 @@ RenderPipeline < A : -hal -: -: -Api +HalApi > { pub @@ -3792,29 +4213,54 @@ crate ) raw : +Option +< A : : RenderPipeline +> pub ( crate ) -layout_id +device : -Stored +Arc < -PipelineLayoutId +Device +< +A +> +> +pub +( +crate +) +layout +: +Arc +< +PipelineLayout +< +A +> > pub ( crate ) -device_id +_shader_modules : -Stored +Vec +< +Arc < -DeviceId +ShaderModule +< +A +> +> > pub ( @@ -3873,20 +4319,107 @@ pub ( crate ) -life_guard +info : -LifeGuard +ResourceInfo +< +RenderPipelineId +> } impl < A : +HalApi +> +Drop +for +RenderPipeline +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +RenderPipeline +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use hal : : -Api +Device +; +self +. +device +. +raw +( +) +. +destroy_render_pipeline +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi > Resource +< +RenderPipelineId +> for RenderPipeline < @@ -3896,29 +4429,93 @@ A const TYPE : -& -' -static -str +ResourceType = " RenderPipeline " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +RenderPipelineId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +RenderPipelineId +> +{ +& +mut +self +. +info +} +} +impl +< +A +: +HalApi +> +RenderPipeline +< +A +> { +pub +( +crate +) +fn +raw +( +& +self +) +- +> & +A +: +: +RenderPipeline +{ self . -life_guard +raw +. +as_ref +( +) +. +unwrap +( +) } } diff --git a/third_party/rust/wgpu-core/src/present.rs b/third_party/rust/wgpu-core/src/present.rs index af39522d0ef0a..1e66b7c5ad30b 100644 --- a/third_party/rust/wgpu-core/src/present.rs +++ b/third_party/rust/wgpu-core/src/present.rs @@ -78,10 +78,22 @@ use std : : +{ borrow : : Borrow +sync +: +: +atomic +: +: +{ +AtomicBool +Ordering +} +} ; # [ @@ -115,6 +127,13 @@ conv device : : +any_device +: +: +AnyDevice +device +: +: { DeviceError MissingDownlevelFlags @@ -129,18 +148,12 @@ hal_api : HalApi hal_label -hub -: -: -Token id : : { -DeviceId SurfaceId TextureId -Valid } identity : @@ -154,9 +167,13 @@ init_tracker : TextureInitTracker resource +: +: +{ +self +ResourceInfo +} track -LifeGuard -Stored } ; use @@ -173,6 +190,12 @@ _ } ; use +parking_lot +: +: +RwLock +; +use thiserror : : @@ -219,12 +242,9 @@ pub ( crate ) -device_id +device : -Stored -< -DeviceId -> +AnyDevice pub ( crate @@ -266,54 +286,8 @@ acquired_texture : Option < -Stored -< TextureId > -> -} -impl -Presentation -{ -pub -( -crate -) -fn -backend -( -& -self -) -- -> -wgt -: -: -Backend -{ -crate -: -: -id -: -: -TypedId -: -: -unzip -( -self -. -device_id -. -value -. -0 -) -. -2 -} } # [ @@ -914,17 +888,6 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let fid = hub @@ -932,35 +895,23 @@ hub textures . prepare +: +: +< +G +> ( texture_id_in ) ; let -( -mut -surface_guard -mut -token -) +surface = self . surfaces . -write -( -& -mut -token -) -; -let -surface -= -surface_guard -. -get_mut +get ( surface_id ) @@ -979,54 +930,48 @@ Invalid ; let ( -device_guard -mut -token +device +config ) = -hub -. -devices -. -read -( -& -mut -token -) -; +if let +Some ( -device -config +ref +present ) = -match +* surface . presentation +. +lock +( +) +{ +match +present +. +device +. +downcast_clone +: +: +< +A +> +( +) { Some ( -ref -present +device ) = > { -let -device -= -& -device_guard -[ -present -. -device_id -. -value -] -; if ! device @@ -1072,6 +1017,19 @@ SurfaceError NotConfigured ) } +} +else +{ +return +Err +( +SurfaceError +: +: +NotConfigured +) +; +} ; # [ @@ -1089,18 +1047,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -1148,9 +1108,13 @@ suf A : : -get_surface_mut +get_surface ( surface +. +as_ref +( +) ) ; let @@ -1204,36 +1168,44 @@ ast > { let -clear_view_desc +texture_desc = -hal +wgt : : -TextureViewDescriptor +TextureDescriptor { label : -hal_label -( -Some -( -" ( -wgpu -internal -) -clear -surface -texture -view -" ) -self +size +: +wgt +: +: +Extent3d +{ +width +: +config . -instance +width +height +: +config . -flags -) +height +depth_or_array_layers +: +1 +} +sample_count +: +1 +mip_level_count +: +1 format : config @@ -1244,52 +1216,150 @@ dimension wgt : : -TextureViewDimension +TextureDimension : : D2 usage : -hal -: -: -TextureUses -: -: -COLOR_TARGET -range -: -wgt -: -: -ImageSubresourceRange -: +config +. +usage +view_formats : -default -( -) +config +. +view_formats } ; let -mut -clear_views +hal_usage = -smallvec -: -: -SmallVec +conv : : -new +map_texture_usage ( -) -; -clear_views +config . -push +usage +config +. +format +. +into ( -unsafe -{ +) +) +; +let +format_features += +wgt +: +: +TextureFormatFeatures +{ +allowed_usages +: +wgt +: +: +TextureUsages +: +: +RENDER_ATTACHMENT +flags +: +wgt +: +: +TextureFormatFeatureFlags +: +: +MULTISAMPLE_X4 +| +wgt +: +: +TextureFormatFeatureFlags +: +: +MULTISAMPLE_RESOLVE +} +; +let +clear_view_desc += +hal +: +: +TextureViewDescriptor +{ +label +: +hal_label +( +Some +( +" +( +wgpu +internal +) +clear +surface +texture +view +" +) +self +. +instance +. +flags +) +format +: +config +. +format +dimension +: +wgt +: +: +TextureViewDimension +: +: +D2 +usage +: +hal +: +: +TextureUses +: +: +COLOR_TARGET +range +: +wgt +: +: +ImageSubresourceRange +: +: +default +( +) +} +; +let +clear_view += +unsafe +{ hal : : @@ -1298,10 +1368,11 @@ Device : create_texture_view ( -& device . raw +( +) ast . texture @@ -1322,15 +1393,24 @@ DeviceError from ) ? -) ; let -present +mut +presentation = surface . presentation . +lock +( +) +; +let +present += +presentation +. as_mut ( ) @@ -1349,6 +1429,13 @@ Texture { inner : +RwLock +: +: +new +( +Some +( resource : : @@ -1359,145 +1446,46 @@ Surface { raw : +Some +( ast . texture +) parent_id : -Valid -( surface_id -) has_work : +AtomicBool +: +: +new +( false +) } -device_id +) +) +device : -present -. -device_id +device . clone ( ) desc : -wgt -: -: -TextureDescriptor -{ -label -: -( -) -size -: -wgt -: -: -Extent3d -{ -width -: -config -. -width -height -: -config -. -height -depth_or_array_layers -: -1 -} -sample_count -: -1 -mip_level_count -: -1 -format -: -config -. -format -dimension -: -wgt -: -: -TextureDimension -: -: -D2 -usage -: -config -. -usage -view_formats -: -config -. -view_formats -} +texture_desc hal_usage -: -conv -: -: -map_texture_usage -( -config -. -usage -config -. -format -. -into -( -) -) format_features +initialization_status : -wgt -: -: -TextureFormatFeatures -{ -allowed_usages -: -wgt -: -: -TextureUsages -: -: -RENDER_ATTACHMENT -flags -: -wgt -: -: -TextureFormatFeatureFlags -: -: -MULTISAMPLE_X4 -| -wgt -: -: -TextureFormatFeatureFlags -: +RwLock : -MULTISAMPLE_RESOLVE -} -initialization_status : +new +( TextureInitTracker : : @@ -1506,6 +1494,7 @@ new 1 1 ) +) full_range : track @@ -1526,9 +1515,9 @@ mips . 1 } -life_guard +info : -LifeGuard +ResourceInfo : : new @@ -1541,43 +1530,59 @@ Surface ) clear_mode : +RwLock +: +: +new +( resource : : TextureClearMode : : -RenderPass +Surface { -clear_views -is_color +clear_view : -true +Some +( +clear_view +) } +) } ; let -ref_count -= -texture -. -life_guard -. -add_ref ( -) -; -let id +resource +) = fid . assign ( texture -& -mut -token +) +; +log +: +: +info +! +( +" +Created +CURRENT +Surface +Texture +{ +: +? +} +" +id ) ; { @@ -1610,13 +1615,7 @@ textures insert_single ( id -. -0 -ref_count -. -clone -( -) +resource hal : : @@ -1652,13 +1651,7 @@ acquired_texture = Some ( -Stored -{ -value -: id -ref_count -} ) ; let @@ -1686,8 +1679,6 @@ Good Some ( id -. -0 ) status ) @@ -1868,41 +1859,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -surface_guard -mut -token -) +surface = self . surfaces . -write -( -& -mut -token -) -; -let -surface -= -surface_guard -. -get_mut +get ( surface_id ) @@ -1920,36 +1883,29 @@ Invalid ? ; let -( -mut -device_guard mut -token -) +presentation = -hub +surface . -devices +presentation . -write +lock ( -& -mut -token ) ; let present = match -surface -. presentation +. +as_mut +( +) { Some ( -ref -mut present ) = @@ -1971,39 +1927,76 @@ NotConfigured let device = -& -mut -device_guard -[ present . -device_id +device . -value -] +downcast_ref +: +: +< +A +> +( +) +. +unwrap +( +) ; if ! device . -is_valid +is_valid +( +) +{ +return +Err +( +DeviceError +: +: +Lost +. +into +( +) +) +; +} +let +queue_id += +device +. +queue_id +. +read ( ) -{ -return -Err +. +unwrap ( -DeviceError -: -: -Lost +) +; +let +queue += +hub . -into +queues +. +get ( +queue_id ) +. +unwrap +( ) ; -} # [ cfg @@ -2020,18 +2013,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -2114,8 +2109,6 @@ device tracker " texture_id -. -value ) ; device @@ -2131,15 +2124,10 @@ textures remove ( texture_id -. -value ) ; let -( texture -_ -) = hub . @@ -2148,13 +2136,6 @@ textures unregister ( texture_id -. -value -. -0 -& -mut -token ) ; if @@ -2166,32 +2147,43 @@ texture = texture { -texture -. -clear_mode -. -destroy_clear_views -( -& -device -. -raw -) -; let suf = A : : -get_surface_mut +get_surface ( +& surface ) ; -match +let +mut +inner += texture . +inner_mut +( +) +; +let +inner += +inner +. +as_mut +( +) +. +unwrap +( +) +; +match +* inner { resource @@ -2202,8 +2194,12 @@ TextureInner : Surface { +ref +mut raw +ref parent_id +ref has_work } = @@ -2213,9 +2209,8 @@ if surface_id ! = +* parent_id -. -0 { log : @@ -2249,6 +2244,14 @@ else if ! has_work +. +load +( +Ordering +: +: +Relaxed +) { log : @@ -2281,6 +2284,14 @@ raw discard_texture ( raw +. +take +( +) +. +unwrap +( +) ) } ; @@ -2299,14 +2310,21 @@ else { unsafe { -device -. queue . +raw +. +as_ref +( +) +. +unwrap +( +) +. present ( & -mut suf . unwrap @@ -2315,21 +2333,19 @@ unwrap . raw raw +. +take +( +) +. +unwrap +( +) ) } } } -resource -: -: -TextureInner -: -: -Native -{ -. -. -} +_ = > unreachable @@ -2548,41 +2564,13 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -surface_guard -mut -token -) +surface = self . surfaces . -write -( -& -mut -token -) -; -let -surface -= -surface_guard -. -get_mut +get ( surface_id ) @@ -2600,36 +2588,29 @@ Invalid ? ; let -( mut -device_guard -mut -token -) +presentation = -hub +surface . -devices +presentation . -write +lock ( -& -mut -token ) ; let present = match -surface -. presentation +. +as_mut +( +) { Some ( -ref -mut present ) = @@ -2651,16 +2632,22 @@ NotConfigured let device = -& -mut -device_guard -[ present . -device_id +device . -value -] +downcast_ref +: +: +< +A +> +( +) +. +unwrap +( +) ; if ! @@ -2700,18 +2687,20 @@ let Some ( ref +mut trace ) = +* device . trace -{ -trace . lock ( ) +{ +trace . add ( @@ -2791,8 +2780,6 @@ device tracker " texture_id -. -value ) ; device @@ -2808,15 +2795,10 @@ textures remove ( texture_id -. -value ) ; let -( texture -_ -) = hub . @@ -2825,13 +2807,6 @@ textures unregister ( texture_id -. -value -. -0 -& -mut -token ) ; if @@ -2843,34 +2818,44 @@ texture = texture { -texture -. -clear_mode -. -destroy_clear_views -( -& -device -. -raw -) -; let suf = A : : -get_surface_mut +get_surface ( +& surface ) ; match +* texture . -inner +inner_mut +( +) +. +as_mut +( +) +. +take +( +) +. +as_mut +( +) +. +unwrap +( +) { +& +mut resource : : @@ -2879,7 +2864,10 @@ TextureInner : Surface { +ref +mut raw +ref parent_id has_work : @@ -2892,9 +2880,8 @@ if surface_id = = +* parent_id -. -0 { unsafe { @@ -2909,6 +2896,14 @@ raw discard_texture ( raw +. +take +( +) +. +unwrap +( +) ) } ; @@ -2931,17 +2926,7 @@ outdated ; } } -resource -: -: -TextureInner -: -: -Native -{ -. -. -} +_ = > unreachable diff --git a/third_party/rust/wgpu-core/src/registry.rs b/third_party/rust/wgpu-core/src/registry.rs index 7da1418b3716a..44e3318acac7d 100644 --- a/third_party/rust/wgpu-core/src/registry.rs +++ b/third_party/rust/wgpu-core/src/registry.rs @@ -2,10 +2,10 @@ use std : : -marker +sync : : -PhantomData +Arc ; use parking_lot @@ -28,20 +28,13 @@ crate : : { -hub -: -: -{ -Access -Token -} id identity : : { -IdentityHandler IdentityHandlerFactory +IdentityManager } resource : @@ -50,13 +43,197 @@ Resource storage : : +{ +Element +InvalidId Storage } +} ; # [ derive ( +Copy +Clone +Debug +Default +PartialEq +Eq +) +] +pub +struct +RegistryReport +{ +pub +num_allocated +: +usize +pub +num_kept_from_user +: +usize +pub +num_released_from_user +: +usize +pub +num_destroyed_from_user +: +usize +pub +num_error +: +usize +pub +element_size +: +usize +} +impl +RegistryReport +{ +pub +fn +is_empty +( +& +self +) +- +> +bool +{ +self +. +num_allocated ++ +self +. +num_kept_from_user += += +0 +} +} +/ +/ +/ +Registry +is +the +primary +holder +of +each +resource +type +/ +/ +/ +Every +resource +is +now +arcanized +so +the +last +arc +released +/ +/ +/ +will +in +the +end +free +the +memory +and +release +the +inner +raw +resource +/ +/ +/ +/ +/ +/ +Registry +act +as +the +main +entry +point +to +keep +resource +alive +/ +/ +/ +when +created +and +released +from +user +land +code +/ +/ +/ +/ +/ +/ +A +resource +may +still +be +alive +when +released +from +user +land +code +/ +/ +/ +if +it +' +s +used +in +active +submission +or +anyway +kept +alive +from +/ +/ +/ +any +other +dependent +resource +/ +/ +/ +# +[ +derive +( Debug ) ] @@ -64,18 +241,15 @@ pub struct Registry < -T -: -Resource I : id : : TypedId -F +T : -IdentityHandlerFactory +Resource < I > @@ -83,15 +257,14 @@ I { identity : -F -: -: -Filter -pub -( -crate -) -data +Arc +< +IdentityManager +< +I +> +> +storage : RwLock < @@ -107,27 +280,23 @@ Backend } impl < -T -: -Resource I : id : : TypedId -F +T : -IdentityHandlerFactory +Resource < I > > Registry < -T I -F +T > { pub @@ -136,6 +305,14 @@ crate ) fn new +< +F +: +IdentityHandlerFactory +< +I +> +> ( backend : @@ -158,7 +335,7 @@ factory spawn ( ) -data +storage : RwLock : @@ -166,25 +343,11 @@ RwLock new ( Storage -{ -map -: -Vec : : new ( ) -kind -: -T -: -: -TYPE -_phantom -: -PhantomData -} ) backend } @@ -195,61 +358,35 @@ crate ) fn without_backend +< +F +: +IdentityHandlerFactory +< +I +> +> ( factory : & F -kind -: -& -' -static -str ) - > Self { Self -{ -identity -: -factory -. -spawn -( -) -data -: -RwLock -: -: -new -( -Storage -{ -map -: -Vec : : new ( -) -kind -_phantom -: -PhantomData -} -) -backend -: Backend : : Empty -} +factory +) } } # @@ -272,11 +409,25 @@ id : TypedId T +: +Resource +< +I +> > { id : I +identity +: +Arc +< +IdentityManager +< +I +> +> data : & @@ -302,6 +453,11 @@ TypedId + Copy T +: +Resource +< +I +> > FutureId < @@ -313,13 +469,9 @@ T { # [ -cfg +allow ( -feature -= -" -trace -" +dead_code ) ] pub @@ -353,43 +505,70 @@ id } pub fn -assign -< -' -a -A -: -Access -< -T -> -> +init ( +& self +mut value : T -_ -: -& -' -a -mut -Token -< -A -> ) - > -id +Arc +< +T +> +{ +value +. +as_info_mut +( +) +. +set_id +( +self +. +id +& +self +. +identity +) +; +Arc : : -Valid -< +new +( +value +) +} +pub +fn +assign +( +self +value +: +T +) +- +> +( I +Arc +< +T > +) { +let +mut +data += self . data @@ -397,54 +576,121 @@ data write ( ) +; +data . insert ( self . id +self +. +init +( value ) +) ; +( +self +. id -: -: -Valid +data +. +get ( self . id ) +. +unwrap +( +) +. +clone +( +) +) } pub fn -assign_error -< -' -a -A +assign_existing +( +self +value : -Access +& +Arc < T > +) +- > +I +{ +let +mut +data += +self +. +data +. +write +( +) +; +# +[ +cfg +( +debug_assertions +) +] +debug_assert +! +( +! +data +. +contains +( +self +. +id +) +) +; +data +. +insert +( +self +. +id +value +. +clone +( +) +) +; +self +. +id +} +pub +fn +assign_error ( self label : & str -_ -: -& -' -a -mut -Token -< -A -> ) - > @@ -473,29 +719,23 @@ id } impl < -T -: -Resource I : id : : TypedId -+ -Copy -F +T : -IdentityHandlerFactory +Resource < I > > Registry < -T I -F +T > { pub @@ -504,25 +744,100 @@ crate ) fn prepare +< +F +> ( & self id_in : -< F : : -Filter -as -IdentityHandler +Input +) +- +> +FutureId < I +T > +where +F +: +IdentityHandlerFactory +< +I > +{ +FutureId +{ +id : +if +F : -Input +: +autogenerate_ids +( +) +{ +self +. +identity +. +process +( +self +. +backend +) +} +else +{ +self +. +identity +. +mark_as_used +( +F +: +: +input_to_id +( +id_in +) +) +} +identity +: +self +. +identity +. +clone +( +) +data +: +& +self +. +storage +} +} +pub +( +crate +) +fn +request +( +& +self ) - > @@ -542,501 +857,189 @@ identity . process ( -id_in self . backend ) +identity +: +self +. +identity +. +clone +( +) data : & self . -data +storage } } -/ -/ -/ -Acquire -read -access -to -this -Registry -' -s -contents -. -/ -/ -/ -/ -/ -/ -The -caller -must -present -a -mutable -reference -to -a -Token -< -A -> -/ -/ -/ -for -some -type -A -that -comes -before -this -Registry -' -s -resource -/ -/ -/ -type -T -in -the -lock -ordering -. -A -Token -< -Root -> -grants -/ -/ -/ -permission -to -lock -any -field -; -see -[ -Token -: +pub +( +crate +) +fn +contains +( +& +self +id : -root -] -. -/ -/ -/ -/ -/ -/ -Once -the -read -lock -is -acquired -return -a -new -Token -< -T +I +) +- > -along -/ -/ -/ -with -a +bool +{ +self +. read -guard -for -this -Registry -' -s -[ -Storage -] -which -can -/ -/ -/ -be -indexed -by -id -to -get -at -the -actual -resources +( +) . -/ -/ -/ -/ -/ -/ -The -borrow -checker -ensures -that -the -caller -cannot -again -access -/ -/ -/ -its -Token -< -A +contains +( +id +) +} +pub +( +crate +) +fn +try_get +( +& +self +id +: +I +) +- > -until -it -has -dropped -both -the -guard -and -the -/ -/ -/ -Token +Result +< +Option +< +Arc < T > +> +InvalidId +> +{ +self . -/ -/ -/ -/ -/ -/ -See -the -[ -Hub -] -type -for -more -details -on -locking +read +( +) . -/ -/ -/ -/ -/ -/ -[ -Hub -] -: -crate -: -: -hub -: -: -Hub +try_get +( +id +) +. +map +( +| +o +| +o +. +cloned +( +) +) +} pub ( crate ) fn -read -< -' -a -A -: -Access -< -T -> -> +get ( & -' -a self -_token +id : -& -' -a -mut -Token -< -A -> +I ) - > -( -RwLockReadGuard +Result < -' -a -Storage +Arc < T -I -> > -Token -< -' -a -T +InvalidId > -) { -( self . -data -. read ( ) -Token -: -: -new +. +get +( +id +) +. +map +( +| +v +| +v +. +clone ( ) ) } -/ -/ -/ -Acquire -write -access -to -this -Registry +pub +( +crate +) +fn +read +< ' -s -contents -. -/ -/ -/ -/ -/ -/ -The -caller -must -present a -mutable -reference -to -a -Token -< -A > -/ -/ -/ -for -some -type -A -that -comes -before -this -Registry +( +& ' -s -resource -/ -/ -/ -type -T -in -the -lock -ordering -. -A -Token -< -Root -> -grants -/ -/ -/ -permission -to -lock -any -field -; -see -[ -Token -: -: -root -] -. -/ -/ -/ -/ -/ -/ -Once -the -lock -is -acquired -return a -new -Token -< -T +self +) +- > -along -with -/ -/ -/ -a -write -guard -for -this -Registry +RwLockReadGuard +< ' -s -[ +a Storage -] -which -can -be -/ -/ -/ -indexed -by -id -to -get -at -the -actual -resources -. -/ -/ -/ -/ -/ -/ -The -borrow -checker -ensures -that -the -caller -cannot -again -access -/ -/ -/ -its -Token -< -A -> -until -it -has -dropped -both -the -guard -and -the -/ -/ -/ -Token < T +I +> > +{ +self . -/ -/ -/ -/ -/ -/ -See -the -[ -Hub -] -type -for -more -details -on -locking +storage . -/ -/ -/ -/ -/ -/ -[ -Hub -] -: -crate -: -: -hub -: -: -Hub +read +( +) +} pub ( crate @@ -1046,32 +1049,15 @@ write < ' a -A -: -Access -< -T -> > ( & ' a self -_token -: -& -' -a -mut -Token -< -A -> ) - > -( RwLockWriteGuard < ' @@ -1082,98 +1068,15 @@ T I > > -Token -< -' -a -T -> -) { -( self . -data +storage . write ( ) -Token -: -: -new -( -) -) } -/ -/ -/ -Unregister -the -resource -at -id -. -/ -/ -/ -/ -/ -/ -The -caller -must -prove -that -it -already -holds -a -write -lock -for -/ -/ -/ -this -Registry -by -passing -a -mutable -reference -to -this -/ -/ -/ -Registry -' -s -storage -obtained -from -the -write -guard -returned -/ -/ -/ -by -a -previous -call -to -[ -write -] -as -the -guard -parameter -. pub fn unregister_locked @@ -1183,7 +1086,7 @@ self id : I -guard +storage : & mut @@ -1197,325 +1100,141 @@ I > Option < +Arc +< T > +> { -let -value -= -guard +storage . remove ( id -) -; -/ -/ -Note -: -careful -about -the -order -here -! -self -. -identity -. -free -( -id -) -; -/ -/ -Returning -None -is -legal -if -it -' -s -an -error -ID -value -} -/ -/ -/ -Unregister -the -resource -at -id -and -return -its -value -if -any -. -/ -/ -/ -/ -/ -/ -The -caller -must -present -a -mutable -reference -to -a -Token -< -A -> -/ -/ -/ -for -some -type -A -that -comes -before -this -Registry -' -s -resource -/ -/ -/ -type -T -in -the -lock -ordering -. -/ -/ -/ -/ -/ -/ -This -returns -a -Token -< -T -> -but -it -' -s -almost -useless -because -it -/ -/ -/ -doesn -' -t -return -a -lock -guard -to -go -with -it -: -its -only -effect -is -/ -/ -/ -to -make -the -token -you -passed -to -this -function -inaccessible -. -/ -/ -/ -However -the -Token -< -T -> -can -be -used -to -satisfy -some -functions -' -/ -/ -/ -bureacratic -expectations -that -you -will -have -one -available -. -/ -/ -/ -/ -/ -/ -The -borrow -checker -ensures -that -the -caller -cannot -again -access -/ -/ -/ -its -Token -< -A -> -until -it -has -dropped -both -the -guard -and -the -/ -/ -/ -Token -< -T -> -. -/ -/ -/ -/ -/ -/ -See -the -[ -Hub -] -type -for -more -details -on -locking -. -/ -/ -/ -/ -/ -/ -[ -Hub -] -: -crate +) +} +pub +fn +force_replace +( +& +self +id : +I +mut +value : -hub +T +) +{ +let +mut +storage += +self +. +storage +. +write +( +) +; +value +. +as_info_mut +( +) +. +set_id +( +id +& +self +. +identity +) +; +storage +. +force_replace +( +id +value +) +} +pub +fn +force_replace_with_error +( +& +self +id : +I +label : -Hub +& +str +) +{ +let +mut +storage += +self +. +storage +. +write +( +) +; +storage +. +remove +( +id +) +; +storage +. +insert_error +( +id +label +) +; +} pub ( crate ) fn unregister -< -' -a -A -: -Access -< -T -> -> ( & self id : I -_token -: -& -' -a -mut -Token -< -A -> ) - > -( Option < -T -> -Token +Arc < -' -a T > -) +> { let value = self . -data +storage . write ( @@ -1528,25 +1247,6 @@ id ; / / -Note -: -careful -about -the -order -here -! -self -. -identity -. -free -( -id -) -; -/ -/ Returning None is @@ -1558,15 +1258,7 @@ s an error ID -( value -Token -: -: -new -( -) -) } pub fn @@ -1587,7 +1279,7 @@ guard = self . -data +storage . read ( @@ -1599,6 +1291,8 @@ type_name guard . kind +( +) ; match guard @@ -1656,10 +1350,6 @@ unzip else { label -. -to_string -( -) } } Err @@ -1693,4 +1383,158 @@ id ) } } +pub +( +crate +) +fn +generate_report +( +& +self +) +- +> +RegistryReport +{ +let +storage += +self +. +storage +. +read +( +) +; +let +mut +report += +RegistryReport +{ +element_size +: +std +: +: +mem +: +: +size_of +: +: +< +T +> +( +) +. +. +Default +: +: +default +( +) +} +; +report +. +num_allocated += +self +. +identity +. +values +. +lock +( +) +. +count +( +) +; +for +element +in +storage +. +map +. +iter +( +) +{ +match +* +element +{ +Element +: +: +Occupied +( +. +. +) += +> +report +. +num_kept_from_user ++ += +1 +Element +: +: +Destroyed +( +. +. +) += +> +report +. +num_destroyed_from_user ++ += +1 +Element +: +: +Vacant += +> +report +. +num_released_from_user ++ += +1 +Element +: +: +Error +( +. +. +) += +> +report +. +num_error ++ += +1 +} +} +report +} } diff --git a/third_party/rust/wgpu-core/src/resource.rs b/third_party/rust/wgpu-core/src/resource.rs index 6d11f7c83fdff..b44f36c0f2c30 100644 --- a/third_party/rust/wgpu-core/src/resource.rs +++ b/third_party/rust/wgpu-core/src/resource.rs @@ -1,3 +1,23 @@ +# +[ +cfg +( +feature += +" +trace +" +) +] +use +crate +: +: +device +: +: +trace +; use crate : @@ -7,6 +27,9 @@ device : : { +queue +BufferMapPendingClosure +Device DeviceError HostMap MissingDownlevelFlags @@ -20,24 +43,28 @@ hal_api : : HalApi -hub -: -: -Token id : : { AdapterId +BufferId DeviceId +QuerySetId +SamplerId +StagingBufferId SurfaceId TextureId -Valid +TextureViewId +TypedId } identity : : +{ GlobalIdentityHandlerFactory +IdentityManager +} init_tracker : : @@ -45,6 +72,7 @@ init_tracker BufferInitTracker TextureInitTracker } +resource track : : @@ -54,9 +82,24 @@ validation : MissingBufferUsageError Label -LifeGuard -RefCount -Stored +SubmissionIndex +} +; +use +hal +: +: +CommandEncoder +; +use +parking_lot +: +: +{ +Mutex +RwLock +RwLockReadGuard +RwLockWriteGuard } ; use @@ -72,6 +115,12 @@ thiserror Error ; use +wgt +: +: +WasmNotSendSync +; +use std : : @@ -80,6 +129,12 @@ borrow : : Borrow +fmt +: +: +Debug +iter +mem ops : : @@ -88,87 +143,32 @@ ptr : : NonNull -} -; -pub -trait -Resource +sync +: +: { -const -TYPE +atomic +: : -& -' -static -str -; -fn -life_guard -( -& -self -) -- -> -& -LifeGuard -; -fn -label -( -& -self -) -- -> -& -str { -# -[ -cfg -( -debug_assertions -) -] -return -& -self -. -life_guard -( -) -. -label -; -# -[ -cfg -( -not -( -debug_assertions -) -) -] -return -" -" -; +AtomicBool +AtomicUsize +Ordering +} +Arc } } +; / / / -The -status -code -provided -to +Information +about the -buffer -mapping -callback +wgpu +- +core +resource . / / @@ -176,50 +176,40 @@ callback / / / -This -is -very -similar -to -BufferAccessResult -except -that -this -is -FFI +Each +type +representing +a +wgpu - -friendly -. -# +core +resource +like [ -repr -( -C -) +Device ] -# +/ +/ +/ [ -derive -( -Debug -) +Buffer ] -pub -enum -BufferMapAsyncStatus -{ +etc +. +contains +a +ResourceInfo +which +contains / / / -The -Buffer -is -sucessfully -mapped -get_mapped_range -can -be -called +its +latest +submission +index +and +label . / / @@ -227,1086 +217,3763 @@ called / / / -All -other -variants -of -this -enum -represent -failures +A +resource +may +need to -map -the -buffer -. -Success +be +retained +for +any +of +several +reasons +: / / / -The -buffer -is -already -mapped -. +and +any +lifetime +logic +will +be +handled +by +Arc +< +Resource +> +refcount / / / / / / -While -this -is -treated -as -an -error +- +The +user +may +hold +a +reference +to it -does -not -prevent -mapped -range -from -being -accessed +( +via +a +wgpu +: +: +Buffer +say +) . -AlreadyMapped -/ / / -Mapping -was -already -requested -. -MapAlreadyPending -/ / / -An -unknown -error -. -Error / / -/ -Mapping -was -aborted +- +Other +resources +may +depend +on +it ( -by -unmapping -or -destroying -the -buffer -before -mapping +a +texture +view +' +s +backing / / / -happened +texture +for +example ) . -Aborted / / / -The -context -is -Lost -. -ContextLost / / / -The -buffer -is -in -an -invalid -state -. -Invalid +- +It +may +be +used +by +commands +sent +to +the +GPU +that +have +not +yet / / / -The -range -isn -' -t -fully -contained -in -the -buffer +finished +execution . -InvalidRange / / / -The -range -isn -' -t -properly -aligned -. -InvalidAlignment / / / -Incompatible -usage -flags -. -InvalidUsageFlags -} -pub -( +[ +Device +] +: crate -) -enum -BufferMapState -< -A : -hal : +device : -Api -> -{ +: +resource +: +: +Device / / / -Mapped -at -creation -. -Init -{ -ptr +[ +Buffer +] : -NonNull -< -u8 -> -stage_buffer +crate : -A : +resource : -Buffer -needs_flush : -bool -} -/ -/ -/ -Waiting -for -GPU -to -be -done -before -mapping -Waiting +Buffer +# +[ +derive ( -BufferPendingMapping +Debug ) -/ -/ -/ -Mapped -Active +] +pub +struct +ResourceInfo +< +Id +: +TypedId +> { -ptr +id : -NonNull +Option < -u8 +Id > -range -: -hal -: +identity : -MemoryRange -host +Option +< +Arc +< +IdentityManager +< +Id +> +> +> +/ +/ +/ +The +index +of +the +last +queue +submission +in +which +the +resource +/ +/ +/ +was +used +. +/ +/ +/ +/ +/ +/ +Each +queue +submission +is +fenced +and +assigned +an +index +number +/ +/ +/ +sequentially +. +Thus +when +a +queue +submission +completes +we +know +any +/ +/ +/ +resources +used +in +that +submission +and +any +lower +- +numbered +submissions +are +/ +/ +/ +no +longer +in +use +by +the +GPU +. +submission_index : -HostMap -} +AtomicUsize / / / -Not -mapped -Idle -} +The +label +from +the +descriptor +used +to +create +the +resource +. # [ cfg ( -any -( -not -( -target_arch -= -" -wasm32 -" +debug_assertions ) -all -( -feature -= -" -fragile -- -send -- -sync -- -non -- -atomic -- -wasm -" -not +] +pub ( -target_feature -= -" -atomics -" -) -) -) +crate ) -] -unsafe +label +: +String +} impl < -A -: -hal -: +Id : -Api +TypedId > -Send +Drop for -BufferMapState +ResourceInfo < -A +Id > { -} -# -[ -cfg +fn +drop ( -any +& +mut +self +) +{ +if +let +Some ( -not +identity +) += +self +. +identity +. +as_ref ( -target_arch +) +{ +let +id = -" -wasm32 -" +self +. +id +. +as_ref +( ) -all +. +unwrap ( -feature -= -" -fragile -- -send -- -sync -- -non -- -atomic -- -wasm -" -not +) +; +identity +. +free +( +* +id +) +; +log +: +: +info +! ( -target_feature -= " -atomics +Freeing +{ +: +? +} " +self +. +label +( ) ) -) -) -] -unsafe +; +} +} +} impl < -A -: -hal +Id : -: -Api +TypedId > -Sync -for -BufferMapState +ResourceInfo < -A +Id > { -} # [ -repr +allow ( -C +unused_variables ) ] pub -struct -BufferMapCallbackC -{ -pub -callback -: -unsafe -extern -" -C -" +( +crate +) fn +new ( -status -: -BufferMapAsyncStatus -user_data +label : -* -mut -u8 +& +str ) -pub -user_data +- +> +Self +{ +Self +{ +id : -* -mut -u8 -} +None +identity +: +None +submission_index +: +AtomicUsize +: +: +new +( +0 +) # [ cfg ( -any -( -not +debug_assertions +) +] +label +: +label +. +to_string ( -target_arch -= -" -wasm32 -" ) -all +} +} +# +[ +allow ( -feature -= -" -fragile -- -send -- -sync -- -non -- -atomic -- -wasm -" -not +unused_assignments +) +] +pub ( -target_feature -= -" -atomics -" +crate ) +fn +label +( +& +self ) +- +> +String +where +Id +: +Debug +{ +let +mut +label += +String +: +: +new +( ) +; +# +[ +cfg +( +debug_assertions ) ] -unsafe -impl -Send -for -BufferMapCallbackC -{ -} -pub -struct -BufferMapCallback { -/ -/ -We -wrap -this -so -creating -the -enum -in -the -C -variant -can -be -unsafe -/ -/ -allowing -our -call -function -to -be -safe -. -inner -: -Option -< -BufferMapCallbackInner -> -} -# -[ -cfg -( -any -( -not -( -target_arch -= -" -wasm32 -" -) -all -( -feature +label = -" -fragile -- -send -- -sync -- -non -- -atomic -- -wasm -" -not +format +! ( -target_feature -= " -atomics +[ +{ +} +] " +self +. +label ) +; +} +if +let +Some +( +id ) -) -) -] -type -BufferMapCallbackCallback = -Box -< -dyn -FnOnce +self +. +id +. +as_ref ( -BufferAccessResult ) -+ -Send -+ -' -static -> -; -# -[ -cfg -( -not -( -any +{ +label +. +push_str ( -not +format +! ( -target_arch -= " -wasm32 +{ +: +? +} " +id ) -all -( -feature -= -" -fragile -- -send -- -sync -- -non -- -atomic -- -wasm -" -not +. +as_str ( -target_feature -= -" -atomics -" -) -) ) ) -) -] -type -BufferMapCallbackCallback -= -Box -< -dyn -FnOnce -( -BufferAccessResult -) -+ -' -static -> ; -enum -BufferMapCallbackInner -{ -Rust -{ -callback -: -BufferMapCallbackCallback -} -C -{ -inner -: -BufferMapCallbackC } +label } -impl -BufferMapCallback -{ pub +( +crate +) fn -from_rust +id ( -callback -: -BufferMapCallbackCallback +& +self ) - > -Self -{ -Self +Id { -inner -: -Some +self +. +id +. +unwrap ( -BufferMapCallbackInner +) +} +pub +( +crate +) +fn +set_id +( +& +mut +self +id : +Id +identity : -Rust +& +Arc +< +IdentityManager +< +Id +> +> +) { -callback -} +self +. +id += +Some +( +id ) -} -} -/ -/ -/ -# -Safety -/ -/ -/ -/ -/ -/ -- -The -callback -pointer -must -be -valid -to -call -with -the -provided -user_data -/ -/ -/ -pointer +; +self . +identity += +Some +( +identity +. +clone +( +) +) +; +} / / / -/ -/ -/ -- -Both -pointers -must -point -to -valid -memory -until +Record +that +this +resource +will +be +used +by +the +queue +submission +with the -callback -is / / / -invoked -which -may -happen -at -an -unspecified -time +given +index . pub -unsafe +( +crate +) fn -from_c +use_at ( -inner +& +self +submit_index : -BufferMapCallbackC +SubmissionIndex ) -- -> -Self -{ -Self { -inner -: -Some +self +. +submission_index +. +store ( -BufferMapCallbackInner +submit_index +as +_ +Ordering : : -C -{ -inner -} +Release ) -} +; } pub ( crate ) fn -call +submission_index ( -mut +& self -result -: -BufferAccessResult ) +- +> +SubmissionIndex { -match self . -inner +submission_index . -take -( -) -{ -Some +load ( -BufferMapCallbackInner +Ordering : : -Rust -{ -callback +Acquire +) +as +_ +} } +pub +( +crate ) +type +ResourceType = +& +' +static +str +; +pub +trait +Resource +< +Id +: +TypedId > +: +' +static ++ +WasmNotSendSync { -callback +const +TYPE +: +ResourceType +; +fn +as_info ( -result +& +self ) +- +> +& +ResourceInfo +< +Id +> ; -} -/ -/ -SAFETY -: -the -contract -of -the -call -to -from_c -says -that -this -unsafe -is -sound -. -Some +fn +as_info_mut ( -BufferMapCallbackInner -: -: -C -{ -inner -} +& +mut +self ) -= +- > -unsafe -{ -let -status -= -match -result +& +mut +ResourceInfo +< +Id +> +; +fn +label +( +& +self +) +- +> +String { -Ok +# +[ +cfg ( +debug_assertions +) +] +return +self +. +as_info ( ) +. +label +. +clone +( ) -= -> -BufferMapAsyncStatus -: -: -Success -Err +; +# +[ +cfg ( -BufferAccessError -: -: -Device +not ( -_ +debug_assertions ) ) -= -> -BufferMapAsyncStatus +] +return +String : : -ContextLost -Err +new ( -BufferAccessError -: -: -Invalid ) -| -Err +; +} +fn +ref_count ( -BufferAccessError -: +self : -Destroyed +& +Arc +< +Self +> ) -= +- > +usize { -BufferMapAsyncStatus +Arc : : -Invalid -} -Err +strong_count ( -BufferAccessError -: -: -AlreadyMapped +self ) -= -> -BufferMapAsyncStatus -: -: -AlreadyMapped -Err +} +fn +is_unique ( -BufferAccessError -: +self : -MapAlreadyPending +& +Arc +< +Self +> ) -= +- > +bool { -BufferMapAsyncStatus -: -: -MapAlreadyPending -} -Err -( -BufferAccessError -: -: -MissingBufferUsage +self +. +ref_count ( -_ -) ) = -> -{ -BufferMapAsyncStatus -: -: -InvalidUsageFlags += +1 } -Err +fn +is_equal ( -BufferAccessError -: +& +self +other : -UnalignedRange +& +Self ) -| -Err -( -BufferAccessError -: -: -UnalignedRangeSize +- +> +bool { +self . -. -} -) -| -Err +as_info ( -BufferAccessError -: -: -UnalignedOffset -{ -. -. -} ) -= -> -{ -BufferMapAsyncStatus -: -: -InvalidAlignment -} -Err -( -BufferAccessError -: -: -OutOfBoundsUnderrun -{ . -. -} -) -| -Err +id ( -BufferAccessError -: -: -OutOfBoundsOverrun -{ -. -. -} ) -| -Err -( -BufferAccessError -: -: -NegativeRange -{ . -. -} -) -= -> -{ -BufferMapAsyncStatus -: -: -InvalidRange -} -Err +unzip ( -_ ) = -> -BufferMapAsyncStatus -: -: -Error -} -; -( -inner += +other . -callback -) +as_info ( -status -inner +) . -user_data +id +( ) -; -} -None -= -> -{ -panic -! +. +unzip ( -" -Map -callback -invoked -twice -" ) -; } } -} -} -impl -Drop -for -BufferMapCallback -{ -fn -drop -( -& -mut -self -) -{ -if -self +/ +/ +/ +The +status +code +provided +to +the +buffer +mapping +callback . -inner +/ +/ +/ +/ +/ +/ +This +is +very +similar +to +BufferAccessResult +except +that +this +is +FFI +- +friendly . -is_some -( -) -{ -panic -! +# +[ +repr ( -" -Map -callback -was -leaked -" +C ) -; -} -} -} -pub -struct -BufferMapOperation -{ -pub -host -: -HostMap -pub -callback -: -BufferMapCallback -} +] +# +[ +derive +( +Debug +) +] +pub +enum +BufferMapAsyncStatus +{ +/ +/ +/ +The +Buffer +is +sucessfully +mapped +get_mapped_range +can +be +called +. +/ +/ +/ +/ +/ +/ +All +other +variants +of +this +enum +represent +failures +to +map +the +buffer +. +Success +/ +/ +/ +The +buffer +is +already +mapped +. +/ +/ +/ +/ +/ +/ +While +this +is +treated +as +an +error +it +does +not +prevent +mapped +range +from +being +accessed +. +AlreadyMapped +/ +/ +/ +Mapping +was +already +requested +. +MapAlreadyPending +/ +/ +/ +An +unknown +error +. +Error +/ +/ +/ +Mapping +was +aborted +( +by +unmapping +or +destroying +the +buffer +before +mapping +/ +/ +/ +happened +) +. +Aborted +/ +/ +/ +The +context +is +Lost +. +ContextLost +/ +/ +/ +The +buffer +is +in +an +invalid +state +. +Invalid +/ +/ +/ +The +range +isn +' +t +fully +contained +in +the +buffer +. +InvalidRange +/ +/ +/ +The +range +isn +' +t +properly +aligned +. +InvalidAlignment +/ +/ +/ +Incompatible +usage +flags +. +InvalidUsageFlags +} +# +[ +derive +( +Debug +) +] +pub +( +crate +) +enum +BufferMapState +< +A +: +HalApi +> +{ +/ +/ +/ +Mapped +at +creation +. +Init +{ +ptr +: +NonNull +< +u8 +> +stage_buffer +: +Arc +< +Buffer +< +A +> +> +needs_flush +: +bool +} +/ +/ +/ +Waiting +for +GPU +to +be +done +before +mapping +Waiting +( +BufferPendingMapping +< +A +> +) +/ +/ +/ +Mapped +Active +{ +ptr +: +NonNull +< +u8 +> +range +: +hal +: +: +MemoryRange +host +: +HostMap +} +/ +/ +/ +Not +mapped +Idle +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +< +A +: +HalApi +> +Send +for +BufferMapState +< +A +> +{ +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +< +A +: +HalApi +> +Sync +for +BufferMapState +< +A +> +{ +} +# +[ +repr +( +C +) +] +pub +struct +BufferMapCallbackC +{ +pub +callback +: +unsafe +extern +" +C +" +fn +( +status +: +BufferMapAsyncStatus +user_data +: +* +mut +u8 +) +pub +user_data +: +* +mut +u8 +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +unsafe +impl +Send +for +BufferMapCallbackC +{ +} +# +[ +derive +( +Debug +) +] +pub +struct +BufferMapCallback +{ +/ +/ +We +wrap +this +so +creating +the +enum +in +the +C +variant +can +be +unsafe +/ +/ +allowing +our +call +function +to +be +safe +. +inner +: +BufferMapCallbackInner +} +# +[ +cfg +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +] +type +BufferMapCallbackCallback += +Box +< +dyn +FnOnce +( +BufferAccessResult +) ++ +Send ++ +' +static +> +; +# +[ +cfg +( +not +( +any +( +not +( +target_arch += +" +wasm32 +" +) +all +( +feature += +" +fragile +- +send +- +sync +- +non +- +atomic +- +wasm +" +not +( +target_feature += +" +atomics +" +) +) +) +) +) +] +type +BufferMapCallbackCallback += +Box +< +dyn +FnOnce +( +BufferAccessResult +) ++ +' +static +> +; +enum +BufferMapCallbackInner +{ +Rust +{ +callback +: +BufferMapCallbackCallback +} +C +{ +inner +: +BufferMapCallbackC +} +} +impl +Debug +for +BufferMapCallbackInner +{ +fn +fmt +( +& +self +f +: +& +mut +std +: +: +fmt +: +: +Formatter +< +' +_ +> +) +- +> +std +: +: +fmt +: +: +Result +{ +match +* +self +{ +BufferMapCallbackInner +: +: +Rust +{ +callback +: +_ +} += +> +f +. +debug_struct +( +" +Rust +" +) +. +finish +( +) +BufferMapCallbackInner +: +: +C +{ +inner +: +_ +} += +> +f +. +debug_struct +( +" +C +" +) +. +finish +( +) +} +} +} +impl +BufferMapCallback +{ +pub +fn +from_rust +( +callback +: +BufferMapCallbackCallback +) +- +> +Self +{ +Self +{ +inner +: +BufferMapCallbackInner +: +: +Rust +{ +callback +} +} +} +/ +/ +/ +# +Safety +/ +/ +/ +/ +/ +/ +- +The +callback +pointer +must +be +valid +to +call +with +the +provided +user_data +/ +/ +/ +pointer +. +/ +/ +/ +/ +/ +/ +- +Both +pointers +must +point +to +valid +memory +until +the +callback +is +/ +/ +/ +invoked +which +may +happen +at +an +unspecified +time +. +pub +unsafe +fn +from_c +( +inner +: +BufferMapCallbackC +) +- +> +Self +{ +Self +{ +inner +: +BufferMapCallbackInner +: +: +C +{ +inner +} +} +} +pub +( +crate +) +fn +call +( +self +result +: +BufferAccessResult +) +{ +match +self +. +inner +{ +BufferMapCallbackInner +: +: +Rust +{ +callback +} += +> +{ +callback +( +result +) +; +} +/ +/ +SAFETY +: +the +contract +of +the +call +to +from_c +says +that +this +unsafe +is +sound +. +BufferMapCallbackInner +: +: +C +{ +inner +} += +> +unsafe +{ +let +status += +match +result +{ +Ok +( +( +) +) += +> +BufferMapAsyncStatus +: +: +Success +Err +( +BufferAccessError +: +: +Device +( +_ +) +) += +> +BufferMapAsyncStatus +: +: +ContextLost +Err +( +BufferAccessError +: +: +Invalid +) +| +Err +( +BufferAccessError +: +: +Destroyed +) += +> +{ +BufferMapAsyncStatus +: +: +Invalid +} +Err +( +BufferAccessError +: +: +AlreadyMapped +) += +> +BufferMapAsyncStatus +: +: +AlreadyMapped +Err +( +BufferAccessError +: +: +MapAlreadyPending +) += +> +{ +BufferMapAsyncStatus +: +: +MapAlreadyPending +} +Err +( +BufferAccessError +: +: +MissingBufferUsage +( +_ +) +) += +> +{ +BufferMapAsyncStatus +: +: +InvalidUsageFlags +} +Err +( +BufferAccessError +: +: +UnalignedRange +) +| +Err +( +BufferAccessError +: +: +UnalignedRangeSize +{ +. +. +} +) +| +Err +( +BufferAccessError +: +: +UnalignedOffset +{ +. +. +} +) += +> +{ +BufferMapAsyncStatus +: +: +InvalidAlignment +} +Err +( +BufferAccessError +: +: +OutOfBoundsUnderrun +{ +. +. +} +) +| +Err +( +BufferAccessError +: +: +OutOfBoundsOverrun +{ +. +. +} +) +| +Err +( +BufferAccessError +: +: +NegativeRange +{ +. +. +} +) += +> +{ +BufferMapAsyncStatus +: +: +InvalidRange +} +Err +( +_ +) += +> +BufferMapAsyncStatus +: +: +Error +} +; +( +inner +. +callback +) +( +status +inner +. +user_data +) +; +} +} +} +} +# +[ +derive +( +Debug +) +] +pub +struct +BufferMapOperation +{ +pub +host +: +HostMap +pub +callback +: +Option +< +BufferMapCallback +> +} +# +[ +derive +( +Clone +Debug +Error +) +] +# +[ +non_exhaustive +] +pub +enum +BufferAccessError +{ +# +[ +error +( +transparent +) +] +Device +( +# +[ +from +] +DeviceError +) +# +[ +error +( +" +Buffer +map +failed +" +) +] +Failed +# +[ +error +( +" +Buffer +is +invalid +" +) +] +Invalid +# +[ +error +( +" +Buffer +is +destroyed +" +) +] +Destroyed +# +[ +error +( +" +Buffer +is +already +mapped +" +) +] +AlreadyMapped +# +[ +error +( +" +Buffer +map +is +pending +" +) +] +MapAlreadyPending +# +[ +error +( +transparent +) +] +MissingBufferUsage +( +# +[ +from +] +MissingBufferUsageError +) +# +[ +error +( +" +Buffer +is +not +mapped +" +) +] +NotMapped +# +[ +error +( +" +Buffer +map +range +must +start +aligned +to +MAP_ALIGNMENT +and +end +to +COPY_BUFFER_ALIGNMENT +" +) +] +UnalignedRange +# +[ +error +( +" +Buffer +offset +invalid +: +offset +{ +offset +} +must +be +multiple +of +8 +" +) +] +UnalignedOffset +{ +offset +: +wgt +: +: +BufferAddress +} +# +[ +error +( +" +Buffer +range +size +invalid +: +range_size +{ +range_size +} +must +be +multiple +of +4 +" +) +] +UnalignedRangeSize +{ +range_size +: +wgt +: +: +BufferAddress +} +# +[ +error +( +" +Buffer +access +out +of +bounds +: +index +{ +index +} +would +underrun +the +buffer +( +limit +: +{ +min +} +) +" +) +] +OutOfBoundsUnderrun +{ +index +: +wgt +: +: +BufferAddress +min +: +wgt +: +: +BufferAddress +} +# +[ +error +( +" +Buffer +access +out +of +bounds +: +last +index +{ +index +} +would +overrun +the +buffer +( +limit +: +{ +max +} +) +" +) +] +OutOfBoundsOverrun +{ +index +: +wgt +: +: +BufferAddress +max +: +wgt +: +: +BufferAddress +} +# +[ +error +( +" +Buffer +map +range +start +{ +start +} +is +greater +than +end +{ +end +} +" +) +] +NegativeRange +{ +start +: +wgt +: +: +BufferAddress +end +: +wgt +: +: +BufferAddress +} +# +[ +error +( +" +Buffer +map +aborted +" +) +] +MapAborted +} +pub +type +BufferAccessResult += +Result +< +( +) +BufferAccessError +> +; +# +[ +derive +( +Debug +) +] +pub +( +crate +) +struct +BufferPendingMapping +< +A +: +HalApi +> +{ +pub +range +: +Range +< +wgt +: +: +BufferAddress +> +pub +op +: +BufferMapOperation +/ +/ +hold +the +parent +alive +while +the +mapping +is +active +pub +_parent_buffer +: +Arc +< +Buffer +< +A +> +> +} +pub +type +BufferDescriptor +< +' +a +> += +wgt +: +: +BufferDescriptor +< +Label +< +' +a +> +> +; +# +[ +derive +( +Debug +) +] +pub +struct +Buffer +< +A +: +HalApi +> +{ +pub +( +crate +) +raw +: +Option +< +A +: +: +Buffer +> +pub +( +crate +) +device +: +Arc +< +Device +< +A +> +> +pub +( +crate +) +usage +: +wgt +: +: +BufferUsages +pub +( +crate +) +size +: +wgt +: +: +BufferAddress +pub +( +crate +) +initialization_status +: +RwLock +< +BufferInitTracker +> +pub +( +crate +) +sync_mapped_writes +: +Mutex +< +Option +< +hal +: +: +MemoryRange +> +> +pub +( +crate +) +info +: +ResourceInfo +< +BufferId +> +pub +( +crate +) +map_state +: +Mutex +< +BufferMapState +< +A +> +> +} +impl +< +A +: +HalApi +> +Drop +for +Buffer +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +Buffer +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use +hal +: +: +Device +; +self +. +device +. +raw +( +) +. +destroy_buffer +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi +> +Buffer +< +A +> +{ +pub +( +crate +) +fn +raw +( +& +self +) +- +> +& +A +: +: +Buffer +{ +self +. +raw +. +as_ref +( +) +. +unwrap +( +) +} +pub +( +crate +) +fn +buffer_unmap_inner +( +self +: +& +Arc +< +Self +> +) +- +> +Result +< +Option +< +BufferMapPendingClosure +> +BufferAccessError +> +{ +use +hal +: +: +Device +; +let +device += +& +self +. +device +; +let +buffer_id += +self +. +info +. +id +( +) +; +log +: +: +debug +! +( +" +Buffer +{ +: +? +} +map +state +- +> +Idle +" +buffer_id +) +; +match +mem +: +: +replace +( +& +mut +* +self +. +map_state +. +lock +( +) +resource +: +: +BufferMapState +: +: +Idle +) +{ +resource +: +: +BufferMapState +: +: +Init +{ +ptr +stage_buffer +needs_flush +} += +> +{ +# +[ +cfg +( +feature += +" +trace +" +) +] +if +let +Some +( +ref +mut +trace +) += +* +device +. +trace +. +lock +( +) +{ +let +data += +trace +. +make_binary +( +" +bin +" +unsafe +{ +std +: +: +slice +: +: +from_raw_parts +( +ptr +. +as_ptr +( +) +self +. +size +as +usize +) +} +) +; +trace +. +add +( +trace +: +: +Action +: +: +WriteBuffer +{ +id +: +buffer_id +data +range +: +0 +. +. +self +. +size +queued +: +true +} +) +; +} +let +_ += +ptr +; +if +needs_flush +{ +unsafe +{ +device +. +raw +( +) +. +flush_mapped_ranges +( +stage_buffer +. +raw +( +) +iter +: +: +once +( +0 +. +. +self +. +size +) +) +; +} +} +let +raw_buf += +self +. +raw +. +as_ref +( +) +. +ok_or +( +BufferAccessError +: +: +Destroyed +) +? +; +self +. +info +. +use_at +( +device +. +active_submission_index +. +load +( +Ordering +: +: +Relaxed +) ++ +1 +) +; +let +region += +wgt +: +: +BufferSize +: +: +new +( +self +. +size +) +. +map +( +| +size +| +hal +: +: +BufferCopy +{ +src_offset +: +0 +dst_offset +: +0 +size +} +) +; +let +transition_src += +hal +: +: +BufferBarrier +{ +buffer +: +stage_buffer +. +raw +( +) +usage +: +hal +: +: +BufferUses +: +: +MAP_WRITE +. +. +hal +: +: +BufferUses +: +: +COPY_SRC +} +; +let +transition_dst += +hal +: +: +BufferBarrier +{ +buffer +: +raw_buf +usage +: +hal +: +: +BufferUses +: +: +empty +( +) +. +. +hal +: +: +BufferUses +: +: +COPY_DST +} +; +let +mut +pending_writes += +device +. +pending_writes +. +lock +( +) +; +let +pending_writes += +pending_writes +. +as_mut +( +) +. +unwrap +( +) +; +let +encoder += +pending_writes +. +activate +( +) +; +unsafe +{ +encoder +. +transition_buffers +( +iter +: +: +once +( +transition_src +) +. +chain +( +iter +: +: +once +( +transition_dst +) +) +) +; +if +self +. +size +> +0 +{ +encoder +. +copy_buffer_to_buffer +( +stage_buffer +. +raw +( +) +raw_buf +region +. +into_iter +( +) +) +; +} +} +pending_writes +. +consume_temp +( +queue +: +: +TempResource +: +: +Buffer +( +stage_buffer +) +) +; +pending_writes +. +dst_buffers +. +insert +( +buffer_id +self +. +clone +( +) +) +; +} +resource +: +: +BufferMapState +: +: +Idle += +> +{ +return +Err +( +BufferAccessError +: +: +NotMapped +) +; +} +resource +: +: +BufferMapState +: +: +Waiting +( +pending +) += +> +{ +return +Ok +( +Some +( +( +pending +. +op +Err +( +BufferAccessError +: +: +MapAborted +) +) +) +) +; +} +resource +: +: +BufferMapState +: +: +Active +{ +ptr +range +host +} += +> +{ +if +host += += +HostMap +: +: +Write +{ +# +[ +cfg +( +feature += +" +trace +" +) +] +if +let +Some +( +ref +mut +trace +) += +* +device +. +trace +. +lock +( +) +{ +let +size += +range +. +end +- +range +. +start +; +let +data += +trace +. +make_binary +( +" +bin +" +unsafe +{ +std +: +: +slice +: +: +from_raw_parts +( +ptr +. +as_ptr +( +) +size +as +usize +) +} +) +; +trace +. +add +( +trace +: +: +Action +: +: +WriteBuffer +{ +id +: +buffer_id +data +range +: +range +. +clone +( +) +queued +: +false +} +) +; +} +let +_ += +( +ptr +range +) +; +} +unsafe +{ +device +. +raw +( +) +. +unmap_buffer +( +self +. +raw +( +) +) +. +map_err +( +DeviceError +: +: +from +) +? +} +; +} +} +Ok +( +None +) +} +pub +( +crate +) +fn +destroy +( +self +: +& +Arc +< +Self +> +) +- +> +Result +< +( +) +DestroyError +> +{ +let +map_closure +; +/ +/ +Restrict +the +locks +to +this +scope +. +{ +let +device += +& +self +. +device +; +let +buffer_id += +self +. +info +. +id +( +) +; +map_closure += +self +. +buffer_unmap_inner +( +) +. +unwrap_or +( +None +) +; +# +[ +cfg +( +feature += +" +trace +" +) +] +if +let +Some +( +ref +mut +trace +) += +* +device +. +trace +. +lock +( +) +{ +trace +. +add +( +trace +: +: +Action +: +: +FreeBuffer +( +buffer_id +) +) +; +} +if +self +. +raw +. +is_none +( +) +{ +return +Err +( +resource +: +: +DestroyError +: +: +AlreadyDestroyed +) +; +} +let +temp += +queue +: +: +TempResource +: +: +Buffer +( +self +. +clone +( +) +) +; +let +mut +pending_writes += +device +. +pending_writes +. +lock +( +) +; +let +pending_writes += +pending_writes +. +as_mut +( +) +. +unwrap +( +) +; +if +pending_writes +. +dst_buffers +. +contains_key +( +& +buffer_id +) +{ +pending_writes +. +temp_resources +. +push +( +temp +) +; +} +else +{ +let +last_submit_index += +self +. +info +. +submission_index +( +) +; +device +. +lock_life +( +) +. +schedule_resource_destruction +( +temp +last_submit_index +) +; +} +} +/ +/ +Note +: +outside +the +scope +where +locks +are +held +when +calling +the +callback +if +let +Some +( +( +mut +operation +status +) +) += +map_closure +{ +if +let +Some +( +callback +) += +operation +. +callback +. +take +( +) +{ +callback +. +call +( +status +) +; +} +} +Ok +( +( +) +) +} +} # [ derive @@ -1322,7 +3989,7 @@ non_exhaustive ] pub enum -BufferAccessError +CreateBufferError { # [ @@ -1344,390 +4011,452 @@ DeviceError error ( " -Buffer +Failed +to map -failed +buffer +while +creating +: +{ +0 +} " ) ] -Failed -# -[ -error +AccessError ( -" -Buffer -is -invalid -" -) -] -Invalid # [ -error -( -" -Buffer -is -destroyed -" -) +from ] -Destroyed +BufferAccessError +) # [ error ( " -Buffer -is -already +Buffers +that +are mapped +at +creation +have +to +be +aligned +to +COPY_BUFFER_ALIGNMENT " ) ] -AlreadyMapped +UnalignedSize # [ error ( " -Buffer -map -is -pending +Invalid +usage +flags +{ +0 +: +? +} " ) ] -MapAlreadyPending -# -[ -error -( -transparent -) -] -MissingBufferUsage -( -# -[ -from -] -MissingBufferUsageError -) -# -[ -error +InvalidUsage ( -" -Buffer -is -not -mapped -" +wgt +: +: +BufferUsages ) -] -NotMapped # [ error ( " -Buffer -map -range -must -start -aligned -to -MAP_ALIGNMENT -and -end -to -COPY_BUFFER_ALIGNMENT +MAP +usage +can +only +be +combined +with +the +opposite +COPY +requested +{ +0 +: +? +} " ) ] -UnalignedRange +UsageMismatch +( +wgt +: +: +BufferUsages +) # [ error ( " Buffer -offset -invalid -: -offset +size { -offset +requested } -must -be -multiple -of -8 +is +greater +than +the +maximum +buffer +size +( +{ +maximum +} +) " ) ] -UnalignedOffset +MaxBufferSize { -offset -: -wgt +requested : +u64 +maximum : -BufferAddress +u64 } # [ error ( +transparent +) +] +MissingDownlevelFlags +( +# +[ +from +] +MissingDownlevelFlags +) +} +impl +< +A +: +HalApi +> +Resource +< +BufferId +> +for +Buffer +< +A +> +{ +const +TYPE +: +ResourceType += " Buffer -range -size -invalid +" +; +fn +as_info +( +& +self +) +- +> +& +ResourceInfo +< +BufferId +> +{ +& +self +. +info +} +fn +as_info_mut +( +& +mut +self +) +- +> +& +mut +ResourceInfo +< +BufferId +> +{ +& +mut +self +. +info +} +} +/ +/ +/ +A +temporary +buffer +consumed +by +the +command +that +uses +it +. +/ +/ +/ +/ +/ +/ +A +[ +StagingBuffer +] +is +designed +for +one +- +shot +uploads +of +data +to +the +GPU +. +It +/ +/ +/ +is +always +created +mapped +and +the +command +that +uses +it +destroys +the +buffer +/ +/ +/ +when +it +is +done +. +/ +/ +/ +/ +/ +/ +[ +StagingBuffer +] +s +can +be +created +with +[ +queue_create_staging_buffer +] +and +/ +/ +/ +used +with +[ +queue_write_staging_buffer +] +. +They +are +also +used +internally +by +/ +/ +/ +operations +like +[ +queue_write_texture +] +that +need +to +upload +data +to +the +GPU +/ +/ +/ +but +that +don +' +t +belong +to +any +particular +wgpu +command +buffer +. +/ +/ +/ +/ +/ +/ +Used +StagingBuffer +s +are +accumulated +in +[ +Device : -range_size -{ -range_size -} -must +: +pending_writes +] +to be -multiple -of -4 -" -) +/ +/ +/ +freed +once +their +associated +operation +' +s +queue +submission +has +finished +/ +/ +/ +execution +. +/ +/ +/ +/ +/ +/ +[ +queue_create_staging_buffer ] -UnalignedRangeSize -{ -range_size : -wgt +Global : : -BufferAddress -} -# +queue_create_staging_buffer +/ +/ +/ [ -error -( -" -Buffer -access -out -of -bounds -: -index -{ -index -} -would -underrun -the -buffer -( -limit -: -{ -min -} -) -" -) +queue_write_staging_buffer ] -OutOfBoundsUnderrun -{ -index -: -wgt -: -: -BufferAddress -min : -wgt +Global : : -BufferAddress -} -# +queue_write_staging_buffer +/ +/ +/ [ -error -( -" -Buffer -access -out -of -bounds -: -last -index -{ -index -} -would -overrun -the -buffer -( -limit -: -{ -max -} -) -" -) +queue_write_texture ] -OutOfBoundsOverrun -{ -index -: -wgt : +Global : -BufferAddress -max : -wgt +queue_write_texture +/ +/ +/ +[ +Device : : -BufferAddress -} -# -[ -error -( -" -Buffer -map -range -start -{ -start -} -is -greater -than -end -{ -end -} -" -) +pending_writes ] -NegativeRange -{ -start -: -wgt : +crate : -BufferAddress -end : -wgt +device : : -BufferAddress -} +Device # [ -error -( -" -Buffer -map -aborted -" -) -] -MapAborted -} -pub -type -BufferAccessResult -= -Result -< -( -) -BufferAccessError -> -; -pub -( -crate -) -struct -BufferPendingMapping -{ -pub -range -: -Range -< -wgt -: -: -BufferAddress -> -pub -op -: -BufferMapOperation -/ -/ -hold -the -parent -alive -while -the -mapping -is -active -pub -_parent_ref_count -: -RefCount -} -pub -type -BufferDescriptor -< -' -a -> -= -wgt -: -: -BufferDescriptor -< -Label -< -' -a -> -> -; +derive +( +Debug +) +] pub struct -Buffer +StagingBuffer < A : -hal -: -: -Api +HalApi > { pub @@ -1736,6 +4465,8 @@ crate ) raw : +Mutex +< Option < A @@ -1743,26 +4474,20 @@ A : Buffer > +> pub ( crate ) -device_id +device : -Stored +Arc < -DeviceId +Device +< +A +> > -pub -( -crate -) -usage -: -wgt -: -: -BufferUsages pub ( crate @@ -1777,235 +4502,120 @@ pub ( crate ) -initialization_status +is_coherent : -BufferInitTracker +bool pub ( crate ) -sync_mapped_writes +info : -Option +ResourceInfo < -hal -: -: -MemoryRange +StagingBufferId > -pub -( -crate -) -life_guard -: -LifeGuard -pub -( -crate -) -map_state +} +impl +< +A : -BufferMapState +HalApi +> +Drop +for +StagingBuffer < A > -} -# -[ -derive -( -Clone -Debug -Error -) -] -# -[ -non_exhaustive -] -pub -enum -CreateBufferError -{ -# -[ -error -( -transparent -) -] -Device -( -# -[ -from -] -DeviceError -) -# -[ -error -( -" -Failed -to -map -buffer -while -creating -: { -0 -} -" -) -] -AccessError -( -# -[ -from -] -BufferAccessError -) -# -[ -error +fn +drop ( -" -Buffers -that -are -mapped -at -creation -have -to -be -aligned -to -COPY_BUFFER_ALIGNMENT -" +& +mut +self ) -] -UnalignedSize -# -[ -error -( -" -Invalid -usage -flags { -0 -: -? -} -" -) -] -InvalidUsage -( -wgt +log : : -BufferUsages -) -# -[ -error +info +! ( " -MAP -usage -can -only -be -combined -with -the -opposite -COPY -requested +Destroying +StagingBuffer { -0 : ? } " -) -] -UsageMismatch +self +. +info +. +label ( -wgt -: -: -BufferUsages ) -# -[ -error +) +; +if +let +Some ( -" -Buffer -size -{ -requested -} -is -greater -than -the -maximum -buffer -size +raw +) += +self +. +raw +. +lock ( -{ -maximum -} ) -" +. +take +( ) -] -MaxBufferSize { -requested +unsafe +{ +use +hal : -u64 -maximum : -u64 -} -# -[ -error -( -transparent -) -] -MissingDownlevelFlags +Device +; +self +. +device +. +raw ( -# -[ -from -] -MissingDownlevelFlags ) +. +destroy_buffer +( +raw +) +; +} +} +} } impl < A : -hal -: -: -Api +HalApi > Resource +< +StagingBufferId +> for -Buffer +StagingBuffer < A > @@ -2013,17 +4623,14 @@ A const TYPE : -& -' -static -str +ResourceType = " -Buffer +StagingBuffer " ; fn -life_guard +as_info ( & self @@ -2031,353 +4638,385 @@ self - > & -LifeGuard +ResourceInfo +< +StagingBufferId +> { & self . -life_guard +info } -} -/ -/ -/ -A -temporary -buffer -consumed -by -the -command -that -uses -it -. -/ -/ -/ -/ -/ -/ -A -[ -StagingBuffer -] -is -designed -for -one +fn +as_info_mut +( +& +mut +self +) - -shot -uploads -of -data -to -the -GPU -. -It -/ -/ -/ -is -always -created -mapped -and -the -command -that -uses -it -destroys -the -buffer -/ -/ -/ -when -it -is -done -. -/ -/ -/ -/ -/ -/ -[ -StagingBuffer -] -s -can -be -created -with -[ -queue_create_staging_buffer -] -and -/ -/ -/ -used -with -[ -queue_write_staging_buffer -] -. -They -are -also -used -internally -by -/ -/ -/ -operations -like -[ -queue_write_texture -] -that -need -to -upload -data -to -the -GPU -/ -/ -/ -but -that -don -' -t -belong -to -any -particular -wgpu -command -buffer +> +& +mut +ResourceInfo +< +StagingBufferId +> +{ +& +mut +self . -/ -/ -/ -/ -/ -/ -Used -StagingBuffer -s -are -accumulated -in -[ -Device +info +} +fn +label +( +& +self +) +- +> +String +{ +String : : -pending_writes -] -to -be -/ -/ -/ -freed -once -their -associated -operation +from +( +" +< +StagingBuffer +> +" +) +} +} +pub +type +TextureDescriptor +< ' -s -queue -submission -has -finished -/ -/ -/ -execution -. -/ -/ -/ -/ -/ -/ -[ -queue_create_staging_buffer -] -: -Global -: +a +> += +wgt : -queue_create_staging_buffer -/ -/ -/ -[ -queue_write_staging_buffer -] : -Global +TextureDescriptor +< +Label +< +' +a +> +Vec +< +wgt : : -queue_write_staging_buffer -/ -/ -/ +TextureFormat +> +> +; +# [ -queue_write_texture +derive +( +Debug +) ] +pub +( +crate +) +enum +TextureInner +< +A : -Global +HalApi +> +{ +Native +{ +raw : +Option +< +A : -queue_write_texture -/ -/ -/ -[ -Device : +Texture +> +} +Surface +{ +raw : -pending_writes -] +Option +< +A : -crate : +SurfaceTexture +> +parent_id : -device +SurfaceId +has_work : +AtomicBool +} +} +impl +< +A : -Device +HalApi +> +TextureInner +< +A +> +{ pub -struct -StagingBuffer +fn +as_raw +( +& +self +) +- +> +Option < +& A : -hal -: : -Api +Texture > { -pub +match +* +self +{ +Self +: +: +Native +{ +raw +: +Some ( -crate +ref +tex ) -raw +} += +> +Some +( +tex +) +Self : -A : +Surface +{ +raw : -Buffer +Some +( +ref +tex +) +. +. +} += +> +Some +( +tex +. +borrow +( +) +) +_ += +> +None +} +} +} +# +[ +derive +( +Debug +) +] pub +enum +TextureClearMode +< +A +: +HalApi +> +{ +BufferCopy +/ +/ +View +for +clear +via +RenderPass +for +every +subsurface ( -crate +mip +/ +layer +/ +slice ) -size +RenderPass +{ +clear_views : -wgt +SmallVec +< +[ +Option +< +A +: +: +TextureView +> +; +1 +] +> +is_color +: +bool +} +Surface +{ +clear_view : +Option +< +A +: +: +TextureView +> +} +/ +/ +Texture +can +' +t +be +cleared +attempting +to +do +so +will +cause +panic +. +/ +/ +( +either +because +it +is +impossible +for +the +type +of +texture +or +it +is +being +destroyed +) +None +} +# +[ +derive +( +Debug +) +] +pub +struct +Texture +< +A : -BufferAddress +HalApi +> +{ pub ( crate ) -is_coherent +inner : -bool -} -impl +RwLock < -A -: -hal -: -: -Api -> -Resource -for -StagingBuffer +Option +< +TextureInner < A > -{ -const -TYPE -: -& -' -static -str -= -" -StagingBuffer -" -; -fn -life_guard -( -& -self -) -- > -& -LifeGuard -{ -unreachable -! -( -) -} -fn -label +> +pub ( -& -self +crate ) -- -> -& -str -{ -" +device +: +Arc < -StagingBuffer -> -" -} -} -pub -type -TextureDescriptor +Device < -' -a +A > -= +> +pub +( +crate +) +desc +: wgt : : TextureDescriptor < -Label -< -' -a -> +( +) Vec < wgt @@ -2386,447 +5025,453 @@ wgt TextureFormat > > -; -# -[ -derive -( -Debug -) -] pub ( crate ) -enum -TextureInner -< -A +hal_usage : hal : : -Api -> -{ -Native -{ -raw -: -Option -< -A +TextureUses +pub +( +crate +) +format_features : +wgt : -Texture -> -} -Surface -{ -raw : -A +TextureFormatFeatures +pub +( +crate +) +initialization_status : +RwLock +< +TextureInitTracker +> +pub +( +crate +) +full_range : -SurfaceTexture -parent_id +TextureSelector +pub +( +crate +) +info : -Valid +ResourceInfo < -SurfaceId +TextureId > -has_work +pub +( +crate +) +clear_mode : -bool -} +RwLock +< +TextureClearMode +< +A +> +> } impl < A : -hal -: -: -Api +HalApi > -TextureInner +Drop +for +Texture < A > { -pub fn -as_raw +drop ( & +mut self ) -- -> -Option -< -& -A +{ +log : : +info +! +( +" +Destroying Texture -> { +: +? +} +" +self +. +info +. +label +( +) +) +; +use +hal +: +: +Device +; +let +mut +clear_mode += +self +. +clear_mode +. +write +( +) +; +let +clear_mode += +& +mut +* +clear_mode +; match * -self +clear_mode { -Self +TextureClearMode : : -Native +Surface +{ +ref +mut +clear_view +. +. +} += +> +{ +if +let +Some +( +view +) += +clear_view +. +take +( +) +{ +unsafe { +self +. +device +. raw -: -Some ( -ref -tex ) -} -= -> -Some +. +destroy_texture_view ( -tex +view ) -Self -: -: -Native -{ -raw -: -None +; } -= -> -None -Self +} +} +TextureClearMode : : -Surface +RenderPass { ref -raw +mut +clear_views . . } = > +{ +clear_views +. +iter_mut +( +) +. +for_each +( +| +clear_view +| +{ +if +let Some ( -raw +view +) += +clear_view . -borrow +take +( +) +{ +unsafe +{ +self +. +device +. +raw ( ) +. +destroy_texture_view +( +view ) +; } } } -# -[ -derive -( -Debug ) -] -pub -enum -TextureClearMode -< -A -: -hal -: -: -Api +; +} +_ += > { -BufferCopy -/ -/ -View -for -clear -via -RenderPass -for -every -subsurface +} +} +; +if +self +. +inner +. +read +( +) +. +is_none ( -mip -/ -layer -/ -slice ) -RenderPass { -clear_views -: -SmallVec -< -[ -A -: -: -TextureView +return ; -1 -] -> -is_color -: -bool } -/ -/ -Texture -can -' -t -be -cleared -attempting -to -do -so -will -cause -panic +let +inner += +self . -/ -/ +inner +. +write ( -either -because -it -is -impossible -for -the -type -of -texture -or -it -is -being -destroyed ) -None -} -impl -< -A -: -hal -: -: -Api -> -TextureClearMode -< -A -> -{ -pub +. +take ( -crate ) -fn -destroy_clear_views +. +unwrap ( -self -device -: -& -A -: -: -Device ) -{ +; if let -TextureClearMode +TextureInner : : -RenderPass +Native { -clear_views -. -. +raw +: +Some +( +raw +) } = -self -{ -for -clear_view -in -clear_views +inner { unsafe { -hal -: -: -Device -: -: -destroy_texture_view -( +self +. device -clear_view +. +raw +( +) +. +destroy_texture +( +raw ) ; } } } } -} -# -[ -derive -( -Debug -) -] -pub -struct +impl +< +A +: +HalApi +> Texture < A -: -hal -: -: -Api > { pub ( crate ) +fn inner -: -TextureInner < -A +' +a > -pub ( -crate +& +' +a +self ) -device_id -: -Stored -< -DeviceId +- > -pub -( -crate -) -desc -: -wgt -: -: -TextureDescriptor +RwLockReadGuard < -( -) -Vec +' +a +Option < -wgt -: -: -TextureFormat +TextureInner +< +A > > -pub +> +{ +self +. +inner +. +read ( -crate ) -hal_usage -: -hal -: -: -TextureUses +} pub ( crate ) -format_features -: -wgt -: -: -TextureFormatFeatures -pub +fn +inner_mut +< +' +a +> ( -crate +& +' +a +self ) -initialization_status -: -TextureInitTracker -pub +- +> +RwLockWriteGuard +< +' +a +Option +< +TextureInner +< +A +> +> +> +{ +self +. +inner +. +write ( -crate ) -full_range -: -TextureSelector +} pub ( crate ) -life_guard -: -LifeGuard -pub +fn +get_clear_view +< +' +a +> ( -crate -) clear_mode : +& +' +a TextureClearMode < A > -} -impl -< -A +desc : -hal +& +' +a +wgt : : -Api -> -Texture +TextureDescriptor < -A -> -{ -pub ( -crate ) -fn -get_clear_view -( -& -self +Vec +< +wgt +: +: +TextureFormat +> +> mip_level : u32 @@ -2837,14 +5482,15 @@ u32 - > & +' +a A : : TextureView { match -self -. +* clear_mode { TextureClearMode @@ -2895,6 +5541,27 @@ cleared TextureClearMode : : +Surface +{ +ref +clear_view +. +. +} += +> +clear_view +. +as_ref +( +) +. +unwrap +( +) +TextureClearMode +: +: RenderPass { ref @@ -2909,8 +5576,6 @@ let index = if -self -. desc . dimension @@ -2942,8 +5607,6 @@ mip acc + ( -self -. desc . size @@ -2965,8 +5628,6 @@ else { mip_level * -self -. desc . size @@ -2976,13 +5637,20 @@ depth_or_array_layers + depth_or_layer ; -& clear_views [ index as usize ] +. +as_ref +( +) +. +unwrap +( +) } } } @@ -3078,69 +5746,60 @@ self ) ; let -mut -token +texture = -Token -: -: -root +{ +hub +. +textures +. +try_get ( +id ) -; -let +. +ok ( -guard -_ ) -= -hub -. -textures . -read +flatten ( -& -mut -token ) +} ; let -texture +inner = -guard +texture . -try_get +as_ref ( -id ) . -ok +unwrap ( ) . -flatten +inner ( ) ; let hal_texture = -texture +inner . -and_then +as_ref ( -| -tex -| -tex +) . -inner +unwrap +( +) . as_raw ( ) -) ; hal_texture_callback ( @@ -3228,44 +5887,18 @@ hub = A : -: -hub -( -self -) -; -let -mut -token -= -Token -: -: -root -( -) -; -let -( -guard -_ -) -= -hub -. -adapters -. -read +: +hub ( -& -mut -token +self ) ; let adapter = -guard +hub +. +adapters . try_get ( @@ -3285,6 +5918,10 @@ hal_adapter = adapter . +as_ref +( +) +. map ( | @@ -3390,38 +6027,12 @@ self ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -guard -_ -) +device = hub . devices . -read -( -& -mut -token -) -; -let -device -= -guard -. try_get ( id @@ -3440,15 +6051,20 @@ hal_device = device . +as_ref +( +) +. map ( | device | -& device . raw +( +) ) ; hal_device_callback @@ -3477,7 +6093,7 @@ destroyed pub unsafe fn -surface_as_hal_mut +surface_as_hal < A : @@ -3489,7 +6105,6 @@ FnOnce Option < & -mut A : : @@ -3525,45 +6140,18 @@ scope Surface : : -as_hal_mut +as_hal " ) ; let -mut -token -= -Token -: -: -root -( -) -; -let -( -mut -guard -_ -) +surface = self . surfaces . -write -( -& -mut -token -) -; -let -surface -= -guard -. -get_mut +get ( id ) @@ -3577,6 +6165,10 @@ hal_surface = surface . +as_ref +( +) +. and_then ( | @@ -3585,7 +6177,7 @@ surface A : : -get_surface_mut +get_surface ( surface ) @@ -3597,7 +6189,7 @@ map surface | & -mut +* surface . raw @@ -3873,6 +6465,21 @@ DeviceError [ error ( +transparent +) +] +CreateTextureView +( +# +[ +from +] +CreateTextureViewError +) +# +[ +error +( " Invalid usage @@ -4348,12 +6955,12 @@ impl < A : -hal -: -: -Api +HalApi > Resource +< +TextureId +> for Texture < @@ -4363,40 +6970,59 @@ A const TYPE : -& -' -static -str +ResourceType = " Texture " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +TextureId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +TextureId +> { & +mut self . -life_guard +info } } impl < A : -hal -: -: -Api +HalApi > Borrow < @@ -4938,10 +7564,7 @@ TextureView < A : -hal -: -: -Api +HalApi > { pub @@ -4950,27 +7573,13 @@ crate ) raw : +Option +< A : : TextureView -/ -/ -The -parent -' -s -refcount -is -held -alive -but -the -parent -may -still -be -deleted +> / / if @@ -4980,32 +7589,42 @@ s a surface texture -. -TODO -: -make -this -cleaner -. +- +it +' +s +none pub ( crate ) -parent_id +parent : -Stored +RwLock < -TextureId +Option +< +Arc +< +Texture +< +A +> +> +> > pub ( crate ) -device_id +device : -Stored +Arc < -DeviceId +Device +< +A +> > / / @@ -5052,37 +7671,166 @@ pub ( crate ) -render_extent +render_extent +: +Result +< +wgt +: +: +Extent3d +TextureViewNotRenderableReason +> +pub +( +crate +) +samples +: +u32 +pub +( +crate +) +selector +: +TextureSelector +pub +( +crate +) +info +: +ResourceInfo +< +TextureViewId +> +} +impl +< +A +: +HalApi +> +Drop +for +TextureView +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +TextureView +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use +hal : -Result -< -wgt : +Device +; +self +. +device +. +raw +( +) +. +destroy_texture_view +( +raw +) +; +} +} +} +} +impl +< +A : -Extent3d -TextureViewNotRenderableReason +HalApi +> +TextureView +< +A > +{ pub ( crate ) -samples -: -u32 -pub +fn +raw ( -crate +& +self ) -selector +- +> +& +A : -TextureSelector -pub +: +TextureView +{ +self +. +raw +. +as_ref ( -crate ) -life_guard -: -LifeGuard +. +unwrap +( +) +} } # [ @@ -5125,6 +7873,10 @@ Not enough memory left +to +create +texture +view " ) ] @@ -5551,12 +8303,12 @@ impl < A : -hal -: -: -Api +HalApi > Resource +< +TextureViewId +> for TextureView < @@ -5566,30 +8318,52 @@ A const TYPE : -& -' -static -str +ResourceType = " TextureView " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +TextureViewId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +TextureViewId +> { & +mut self . -life_guard +info } } / @@ -5934,73 +8708,205 @@ Sampler < A : +HalApi +> +{ +pub +( +crate +) +raw +: +Option +< +A +: +: +Sampler +> +pub +( +crate +) +device +: +Arc +< +Device +< +A +> +> +pub +( +crate +) +info +: +ResourceInfo +< +SamplerId +> +/ +/ +/ +true +if +this +is +a +comparison +sampler +pub +( +crate +) +comparison +: +bool +/ +/ +/ +true +if +this +is +a +filtering +sampler +pub +( +crate +) +filtering +: +bool +} +impl +< +A +: +HalApi +> +Drop +for +Sampler +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +Sampler +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use hal : : -Api +Device +; +self +. +device +. +raw +( +) +. +destroy_sampler +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi +> +Sampler +< +A > { pub ( crate ) +fn raw -: -A -: -: -Sampler -pub ( -crate +& +self ) -device_id -: -Stored -< -DeviceId +- > -pub -( -crate -) -life_guard +& +A : -LifeGuard -/ -/ -/ -true -if -this -is -a -comparison -sampler -pub +: +Sampler +{ +self +. +raw +. +as_ref ( -crate ) -comparison -: -bool -/ -/ -/ -true -if -this -is -a -filtering -sampler -pub +. +unwrap ( -crate ) -filtering -: -bool +} } # [ @@ -6019,12 +8925,6 @@ MinFilter MipmapFilter } impl -std -: -: -fmt -: -: Debug for SamplerFilterErrorType @@ -6338,12 +9238,12 @@ impl < A : -hal -: -: -Api +HalApi > Resource +< +SamplerId +> for Sampler < @@ -6353,30 +9253,52 @@ A const TYPE : -& -' -static -str +ResourceType = " Sampler " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +SamplerId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +SamplerId +> { & +mut self . -life_guard +info } } # @@ -6516,10 +9438,7 @@ QuerySet < A : -hal -: -: -Api +HalApi > { pub @@ -6528,27 +9447,36 @@ crate ) raw : +Option +< A : : QuerySet +> pub ( crate ) -device_id +device : -Stored +Arc < -DeviceId +Device +< +A +> > pub ( crate ) -life_guard +info : -LifeGuard +ResourceInfo +< +QuerySetId +> pub ( crate @@ -6568,12 +9496,96 @@ impl < A : +HalApi +> +Drop +for +QuerySet +< +A +> +{ +fn +drop +( +& +mut +self +) +{ +log +: +: +info +! +( +" +Destroying +QuerySet +{ +: +? +} +" +self +. +info +. +label +( +) +) +; +if +let +Some +( +raw +) += +self +. +raw +. +take +( +) +{ +unsafe +{ +use hal : : -Api +Device +; +self +. +device +. +raw +( +) +. +destroy_query_set +( +raw +) +; +} +} +} +} +impl +< +A +: +HalApi > Resource +< +QuerySetId +> for QuerySet < @@ -6583,30 +9595,94 @@ A const TYPE : -& -' -static -str +ResourceType = " QuerySet " ; fn -life_guard +as_info +( +& +self +) +- +> +& +ResourceInfo +< +QuerySetId +> +{ +& +self +. +info +} +fn +as_info_mut ( & +mut self ) - > & -LifeGuard +mut +ResourceInfo +< +QuerySetId +> +{ +& +mut +self +. +info +} +} +impl +< +A +: +HalApi +> +QuerySet +< +A +> { +pub +( +crate +) +fn +raw +( +& +self +) +- +> & +A +: +: +QuerySet +{ self . -life_guard +raw +. +as_ref +( +) +. +unwrap +( +) } } # diff --git a/third_party/rust/wgpu-core/src/storage.rs b/third_party/rust/wgpu-core/src/storage.rs index 3fe66cdd1aaf2..b90c513b14e25 100644 --- a/third_party/rust/wgpu-core/src/storage.rs +++ b/third_party/rust/wgpu-core/src/storage.rs @@ -7,8 +7,11 @@ marker : : PhantomData -mem ops +sync +: +: +Arc } ; use @@ -23,6 +26,10 @@ crate : { id +resource +: +: +Resource Epoch Index } @@ -92,7 +99,10 @@ epoch . Occupied ( +Arc +< T +> Epoch ) / @@ -121,7 +131,10 @@ yet . Destroyed ( +Arc +< T +> Epoch ) / @@ -170,66 +183,6 @@ derive ( Clone Debug -Default -) -] -pub -struct -StorageReport -{ -pub -num_occupied -: -usize -pub -num_vacant -: -usize -pub -num_error -: -usize -pub -element_size -: -usize -} -impl -StorageReport -{ -pub -fn -is_empty -( -& -self -) -- -> -bool -{ -self -. -num_occupied -+ -self -. -num_vacant -+ -self -. -num_error -= -= -0 -} -} -# -[ -derive -( -Clone -Debug ) ] pub @@ -313,12 +266,20 @@ Storage < T I +> +where +T +: +Resource +< +I +> +I : id : : TypedId -> { pub ( @@ -333,20 +294,12 @@ Element T > > -pub -( -crate -) kind : & ' static str -pub -( -crate -) _phantom : PhantomData @@ -358,36 +311,41 @@ impl < T I -: -id -: -: -TypedId > ops : : Index < -id -: -: -Valid -< I > -> for Storage < T I > +where +T +: +Resource +< +I +> +I +: +id +: +: +TypedId { type Output = +Arc +< T +> ; fn index @@ -396,26 +354,21 @@ index self id : -id -: -: -Valid -< I -> ) - > & +Arc +< T +> { self . get ( id -. -0 ) . unwrap @@ -427,84 +380,91 @@ impl < T I -: -id -: -: -TypedId > -ops -: -: -IndexMut -< -id -: -: -Valid +Storage < +T I > -> -for -Storage -< +where T +: +Resource +< I > -{ -fn -index_mut -( -& -mut -self -id +I : id : : -Valid -< -I -> +TypedId +{ +pub +( +crate +) +fn +new +( ) - > -& -mut -T +Self { -self -. -get_mut -( -id -. -0 -) -. -unwrap +Self +{ +map +: +Vec +: +: +new ( ) +kind +: +T +: +: +TYPE +_phantom +: +PhantomData +} } } impl < T I -: -id -: -: -TypedId > Storage < T I > +where +T +: +Resource +< +I +> +I +: +id +: +: +TypedId { +# +[ +allow +( +dead_code +) +] pub ( crate @@ -705,8 +665,11 @@ Result Option < & +Arc +< T > +> InvalidId > { @@ -839,6 +802,8 @@ storage_epoch } [ { +: +? } ] is @@ -849,7 +814,7 @@ alive self . kind -index +id ) ; result @@ -903,7 +868,10 @@ I Result < & +Arc +< T +> InvalidId > { @@ -978,6 +946,8 @@ panic } [ { +: +? } ] does @@ -987,7 +957,7 @@ exist self . kind -index +id ) Some ( @@ -1053,6 +1023,8 @@ storage_epoch } [ { +: +? } ] is @@ -1063,52 +1035,19 @@ alive self . kind -index +id ) ; result } -/ -/ -/ -Get -a -mutable -reference -to -an -item -behind -a -potentially -invalid -ID -. -/ -/ -/ -Panics -if -there -is -an -epoch -mismatch -or -the -entry -is -empty -. pub ( crate ) fn -get_mut +label_for_invalid_id ( & -mut self id : @@ -1116,717 +1055,13 @@ I ) - > -Result -< & -mut -T -InvalidId -> +str { let ( index -epoch -_ -) -= -id -. -unzip -( -) -; -let -( -result -storage_epoch -) -= -match -self -. -map -. -get_mut -( -index -as -usize -) -{ -Some -( -& -mut -Element -: -: -Occupied -( -ref -mut -v -epoch -) -) -= -> -( -Ok -( -v -) -epoch -) -Some -( -& -mut -Element -: -: -Vacant -) -| -None -= -> -panic -! -( -" -{ -} -[ -{ -} -] -does -not -exist -" -self -. -kind -index -) -Some -( -& -mut -Element -: -: -Error -( -epoch -. -. -) -) -= -> -( -Err -( -InvalidId -) -epoch -) -Some -( -& -mut -Element -: -: -Destroyed -( -. -. -epoch -) -) -= -> -( -Err -( -InvalidId -) -epoch -) -} -; -assert_eq -! -( -epoch -storage_epoch -" -{ -} -[ -{ -} -] -is -no -longer -alive -" -self -. -kind -index -) -; -result -} -/ -/ -/ -Like -get_mut -but -returns -the -element -even -if -it -is -destroyed -. -/ -/ -/ -/ -/ -/ -In -practice -most -API -entry -points -should -use -get -/ -get_mut -so -that -a -/ -/ -/ -destroyed -resource -leads -to -a -validation -error -. -This -should -be -used -internally -/ -/ -/ -in -places -where -we -want -to -do -some -manipulation -potentially -after -the -element -/ -/ -/ -was -destroyed -( -for -example -the -drop -implementation -) -. -pub -( -crate -) -fn -get_occupied_or_destroyed_mut -( -& -mut -self -id -: -I -) -- -> -Result -< -& -mut -T -InvalidId -> -{ -let -( -index -epoch -_ -) -= -id -. -unzip -( -) -; -let -( -result -storage_epoch -) -= -match -self -. -map -. -get_mut -( -index -as -usize -) -{ -Some -( -& -mut -Element -: -: -Occupied -( -ref -mut -v -epoch -) -) -| -Some -( -& -mut -Element -: -: -Destroyed -( -ref -mut -v -epoch -) -) -= -> -( -Ok -( -v -) -epoch -) -Some -( -& -mut -Element -: -: -Vacant -) -| -None -= -> -panic -! -( -" -{ -} -[ -{ -} -] -does -not -exist -" -self -. -kind -index -) -Some -( -& -mut -Element -: -: -Error -( -epoch -. -. -) -) -= -> -( -Err -( -InvalidId -) -epoch -) -} -; -assert_eq -! -( -epoch -storage_epoch -" -{ -} -[ -{ -} -] -is -no -longer -alive -" -self -. -kind -index -) -; -result -} -pub -( -crate -) -fn -get_occupied_or_destroyed -( -& -self -id -: -I -) -- -> -Result -< -& -T -InvalidId -> -{ -let -( -index -epoch -_ -) -= -id -. -unzip -( -) -; -let -( -result -storage_epoch -) -= -match -self -. -map -. -get -( -index -as -usize -) -{ -Some -( -& -Element -: -: -Occupied -( -ref -v -epoch -) -) -| -Some -( -& -Element -: -: -Destroyed -( -ref -v -epoch -) -) -= -> -{ -( -Ok -( -v -) -epoch -) -} -Some -( -& -Element -: -: -Vacant -) -| -None -= -> -panic -! -( -" -{ -} -[ -{ -} -] -does -not -exist -" -self -. -kind -index -) -Some -( -& -Element -: -: -Error -( -epoch -. -. -) -) -= -> -( -Err -( -InvalidId -) -epoch -) -} -; -assert_eq -! -( -epoch -storage_epoch -" -{ -} -[ -{ -} -] -is -no -longer -alive -" -self -. -kind -index -) -; -result -} -pub -( -crate -) -unsafe -fn -get_unchecked -( -& -self -id -: -u32 -) -- -> -& -T -{ -match -self -. -map -[ -id -as -usize -] -{ -Element -: -: -Occupied -( -ref -v -_ -) -= -> -v -Element -: -: -Vacant -= -> -panic -! -( -" -{ -} -[ -{ -} -] -does -not -exist -" -self -. -kind -id -) -Element -: -: -Error -( -_ -_ -) -| -Element -: -: -Destroyed -( -. -. -) -= -> -panic -! -( -" -" -) -} -} -pub -( -crate -) -fn -label_for_invalid_id -( -& -self -id -: -I -) -- -> -& -str -{ -let -( -index -_ +_ _ ) = @@ -1880,6 +1115,9 @@ self index : usize +epoch +: +Epoch element : Element @@ -1946,12 +1184,96 @@ Vacant > { } +Element +: +: +Destroyed +( _ +storage_epoch +) = > -panic +{ +assert_ne +! +( +epoch +storage_epoch +" +Index +{ +index +: +? +} +of +{ +} +is +already +occupied +" +T +: +: +TYPE +) +; +} +Element +: +: +Occupied +( +_ +storage_epoch +) += +> +{ +assert_ne +! +( +epoch +storage_epoch +" +Index +{ +index +: +? +} +of +{ +} +is +already +occupied +" +T +: +: +TYPE +) +; +} +Element +: +: +Error +( +storage_epoch +_ +) += +> +{ +assert_ne ! ( +epoch +storage_epoch " Index { @@ -1959,11 +1281,22 @@ index : ? } +of +{ +} is already occupied +with +Error " +T +: +: +TYPE ) +; +} } } pub @@ -1981,14 +1314,41 @@ id I value : +Arc +< T +> ) { +log +: +: +info +! +( +" +User +is +inserting +{ +} +{ +: +? +} +" +T +: +: +TYPE +id +) +; let ( index epoch -_ +_backend ) = id @@ -2004,6 +1364,7 @@ insert_impl index as usize +epoch Element : : @@ -2033,6 +1394,32 @@ label str ) { +log +: +: +info +! +( +" +User +is +insering +as +error +{ +} +{ +: +? +} +" +T +: +: +TYPE +id +) +; let ( index @@ -2053,6 +1440,7 @@ insert_impl index as usize +epoch Element : : @@ -2085,7 +1473,10 @@ I > Result < +Arc +< T +> InvalidId > { @@ -2202,9 +1593,10 @@ I > Result < -& -mut +Arc +< T +> InvalidId > { @@ -2332,7 +1724,6 @@ Element Destroyed ( ref -mut value . . @@ -2344,6 +1735,10 @@ slot Ok ( value +. +clone +( +) ) } else @@ -2372,6 +1767,30 @@ value T ) { +log +: +: +info +! +( +" +User +is +replacing +{ +} +{ +: +? +} +" +T +: +: +TYPE +id +) +; let ( index @@ -2399,7 +1818,13 @@ Element : Occupied ( +Arc +: +: +new +( value +) epoch ) ; @@ -2422,9 +1847,36 @@ I > Option < +Arc +< T > +> +{ +log +: +: +info +! +( +" +User +is +removing +{ +} { +: +? +} +" +T +: +: +TYPE +id +) +; let ( index @@ -2525,122 +1977,6 @@ resource ) } } -/ -/ -Prevents -panic -on -out -of -range -access -allows -Vacant -elements -. -pub -( -crate -) -fn -_try_remove -( -& -mut -self -id -: -I -) -- -> -Option -< -T -> -{ -let -( -index -epoch -_ -) -= -id -. -unzip -( -) -; -if -index -as -usize -> -= -self -. -map -. -len -( -) -{ -None -} -else -if -let -Element -: -: -Occupied -( -value -storage_epoch -) -= -std -: -: -mem -: -: -replace -( -& -mut -self -. -map -[ -index -as -usize -] -Element -: -: -Vacant -) -{ -assert_eq -! -( -epoch -storage_epoch -) -; -Some -( -value -) -} -else -{ -None -} -} pub ( crate @@ -2664,7 +2000,10 @@ Item ( I & +Arc +< T +> ) > { @@ -2735,136 +2074,40 @@ pub crate ) fn -len +kind ( & self ) - > -usize +& +str { self . -map -. -len -( -) +kind } pub ( crate ) fn -generate_report +len ( & self ) - > -StorageReport -{ -let -mut -report -= -StorageReport +usize { -element_size -: -mem -: -: -size_of -: -: -< -T -> -( -) -. -. -Default -: -: -default -( -) -} -; -for -element -in self . map . -iter -( -) -{ -match -* -element -{ -Element -: -: -Occupied -( -. -. -) -| -Element -: -: -Destroyed -( -. -. -) -= -> -report -. -num_occupied -+ -= -1 -Element -: -: -Vacant -= -> -report -. -num_vacant -+ -= -1 -Element -: -: -Error +len ( -. -. ) -= -> -report -. -num_error -+ -= -1 -} -} -report } } diff --git a/third_party/rust/wgpu-core/src/track/buffer.rs b/third_party/rust/wgpu-core/src/track/buffer.rs index f3c47ec61e3ec..6b0158a02b406 100644 --- a/third_party/rust/wgpu-core/src/track/buffer.rs +++ b/third_party/rust/wgpu-core/src/track/buffer.rs @@ -54,17 +54,20 @@ marker : : PhantomData -vec +sync : : -Drain +Arc } ; use super : : +{ PendingTransition +ResourceTracker +} ; use crate @@ -81,13 +84,18 @@ id { BufferId TypedId -Valid } resource : : +{ Buffer +Resource +} storage +: +: +Storage track : : @@ -99,15 +107,22 @@ ResourceMetadataProvider ResourceUses UsageConflict } -LifeGuard -RefCount } ; use hal : : +{ +BufferBarrier BufferUses +} +; +use +parking_lot +: +: +Mutex ; use wgt @@ -214,6 +229,13 @@ bind group stores . +# +[ +derive +( +Debug +) +] pub ( crate @@ -228,17 +250,22 @@ HalApi { buffers : +Mutex +< Vec < ( -Valid +Arc < -BufferId +Buffer +< +A +> > -RefCount BufferUses ) > +> _phantom : PhantomData @@ -270,12 +297,18 @@ Self { buffers : +Mutex +: +: +new +( Vec : : new ( ) +) _phantom : PhantomData @@ -326,6 +359,16 @@ constant assending order . +# +[ +allow +( +clippy +: +: +pattern_type_mismatch +) +] pub ( crate @@ -334,27 +377,40 @@ fn optimize ( & -mut self ) { +let +mut +buffers += self . buffers . +lock +( +) +; +buffers +. sort_unstable_by_key ( | -& ( -id -_ +b _ ) | -id +b . -0 +as_info +( +) +. +id +( +) . unzip ( @@ -379,9 +435,19 @@ May contain duplicates . +# +[ +allow +( +clippy +: +: +pattern_type_mismatch +) +] pub fn -used +used_ids ( & self @@ -393,19 +459,25 @@ Iterator < Item = -Valid -< BufferId > -> + ' _ { +let +buffers += self . buffers . +lock +( +) +; +buffers +. iter ( ) @@ -413,14 +485,125 @@ iter map ( | -& ( +ref +b +_ +) +| +b +. +as_info +( +) +. id +( +) +) +. +collect +: +: +< +Vec +< _ +> +> +( +) +. +into_iter +( +) +} +/ +/ +/ +Returns +a +list +of +all +buffers +tracked +. +May +contain +duplicates +. +pub +fn +drain_resources +( +& +self +) +- +> +impl +Iterator +< +Item += +Arc +< +Buffer +< +A +> +> +> ++ +' _ +{ +let +mut +buffers += +self +. +buffers +. +lock +( +) +; +buffers +. +drain +( +. +. ) +. +map +( | -id +( +buffer +_u +) +| +buffer +) +. +collect +: +: +< +Vec +< +_ +> +> +( +) +. +into_iter +( ) } / @@ -444,16 +627,12 @@ a > ( & -mut self storage : & ' a -storage -: -: Storage < Buffer @@ -476,11 +655,14 @@ Option & ' a +Arc +< Buffer < A > > +> { let buffer @@ -497,22 +679,26 @@ ok ) ? ; +let +mut +buffers += self . buffers . -push +lock ( +) +; +buffers +. +push ( -Valid ( -id -) buffer . -life_guard -. -add_ref +clone ( ) state @@ -568,6 +754,11 @@ metadata ResourceMetadata < A +BufferId +Buffer +< +A +> > } impl @@ -771,19 +962,17 @@ index / / / -Returns -a -list -of +Drains all buffers tracked . pub fn -used +drain_resources ( & +mut self ) - @@ -793,55 +982,163 @@ Iterator < Item = -Valid +Arc < -BufferId +Buffer +< +A +> > > + ' _ { +let +resources += self . metadata . -owned_ids +drain_resources ( ) -} -/ -/ -/ -Merge -the -list -of -buffer -states -in -the -given -bind -group -into -this -usage -scope +; +self . -/ -/ -/ -/ -/ -/ -If -any -of -the -resulting -states -is +state +. +clear +( +) +; +resources +. +into_iter +( +) +} +pub +fn +get +( +& +self +id +: +BufferId +) +- +> +Option +< +& +Arc +< +Buffer +< +A +> +> +> +{ +let +index += +id +. +unzip +( +) +. +0 +as +usize +; +if +index +> +self +. +metadata +. +size +( +) +{ +return +None +; +} +self +. +tracker_assert_in_bounds +( +index +) +; +unsafe +{ +if +self +. +metadata +. +contains_unchecked +( +index +) +{ +return +Some +( +self +. +metadata +. +get_resource_unchecked +( +index +) +) +; +} +} +None +} +/ +/ +/ +Merge +the +list +of +buffer +states +in +the +given +bind +group +into +this +usage +scope +. +/ +/ +/ +/ +/ +/ +If +any +of +the +resulting +states +is invalid stops the @@ -963,39 +1260,47 @@ Result UsageConflict > { +let +buffers += +bind_group +. +buffers +. +lock +( +) +; for & ( -id ref -ref_count +resource state ) in & -bind_group -. +* buffers { let +index += +resource +. +as_info ( -index32 -epoch -_ ) -= -id . -0 +id +( +) . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -1004,7 +1309,6 @@ unsafe insert_or_merge ( None -None & mut self @@ -1015,7 +1319,9 @@ mut self . metadata -index32 +index +as +_ index BufferStateProvider : @@ -1029,15 +1335,14 @@ ResourceMetadataProvider : Direct { -epoch -ref_count +resource : Cow : : Borrowed ( -ref_count +resource ) } ) @@ -1219,7 +1524,6 @@ unsafe insert_or_merge ( None -None & mut self @@ -1358,9 +1662,6 @@ storage & ' a -storage -: -: Storage < Buffer @@ -1383,10 +1684,13 @@ Result & ' a +Arc +< Buffer < A > +> UsageConflict > { @@ -1416,22 +1720,15 @@ id ? ; let -( -index32 -epoch -_ -) +index = id . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -1453,13 +1750,6 @@ unsafe { insert_or_merge ( -Some -( -& -buffer -. -life_guard -) None & mut @@ -1471,7 +1761,9 @@ mut self . metadata -index32 +index +as +_ index BufferStateProvider : @@ -1485,9 +1777,21 @@ new_state ResourceMetadataProvider : : -Resource +Direct { -epoch +resource +: +Cow +: +: +Owned +( +buffer +. +clone +( +) +) } ) ? @@ -1499,6 +1803,36 @@ buffer ) } } +pub +( +crate +) +type +SetSingleResult +< +A +> += +Option +< +( +Arc +< +Buffer +< +A +> +> +Option +< +PendingTransition +< +BufferUses +> +> +) +> +; / / / @@ -1542,6 +1876,11 @@ metadata ResourceMetadata < A +BufferId +Buffer +< +A +> > temp : @@ -1559,15 +1898,443 @@ A : HalApi > +ResourceTracker +< +BufferId +Buffer +< +A +> +> +for BufferTracker < A > { -pub -fn -new -( +/ +/ +/ +Removes +the +buffer +id +from +this +tracker +if +it +is +otherwise +unused +. +/ +/ +/ +/ +/ +/ +A +buffer +is +' +otherwise +unused +' +when +the +only +references +to +it +are +: +/ +/ +/ +/ +/ +/ +1 +) +the +Arc +that +our +caller +LifetimeTracker +: +: +triage_suspected +has +just +/ +/ +/ +drained +from +LifetimeTracker +: +: +suspected_resources +/ +/ +/ +/ +/ +/ +2 +) +its +Arc +in +[ +self +. +metadata +] +( +owned +by +[ +Device +: +: +trackers +] +) +and +/ +/ +/ +/ +/ +/ +3 +) +its +Arc +in +the +[ +Hub +: +: +buffers +] +registry +. +/ +/ +/ +/ +/ +/ +If +the +buffer +is +indeed +unused +this +function +removes +2 +) +and +/ +/ +/ +triage_suspected +will +remove +3 +) +leaving +1 +) +as +the +sole +/ +/ +/ +remaining +reference +. +/ +/ +/ +/ +/ +/ +Return +true +if +this +tracker +contained +the +buffer +id +. +This +/ +/ +/ +implies +that +we +removed +it +. +/ +/ +/ +/ +/ +/ +[ +Device +: +: +trackers +] +: +crate +: +: +device +: +: +Device +/ +/ +/ +[ +self +. +metadata +] +: +BufferTracker +: +: +metadata +/ +/ +/ +[ +Hub +: +: +buffers +] +: +crate +: +: +hub +: +: +Hub +: +: +buffers +fn +remove_abandoned +( +& +mut +self +id +: +BufferId +external_count +: +usize +) +- +> +bool +{ +let +index += +id +. +unzip +( +) +. +0 +as +usize +; +if +index +> +self +. +metadata +. +size +( +) +{ +return +false +; +} +self +. +tracker_assert_in_bounds +( +index +) +; +unsafe +{ +if +self +. +metadata +. +contains_unchecked +( +index +) +{ +let +existing_ref_count += +self +. +metadata +. +get_ref_count_unchecked +( +index +) +; +/ +/ +2 +ref +count +if +only +in +Device +Tracker +and +suspected +resource +itself +and +already +released +from +user +/ +/ +so +not +appearing +in +Registry +let +min_ref_count += +1 ++ +external_count +; +if +existing_ref_count +< += +min_ref_count +{ +self +. +metadata +. +remove +( +index +) +; +log +: +: +info +! +( +" +Buffer +{ +: +? +} +is +not +tracked +anymore +" +id +) +; +return +true +; +} +else +{ +log +: +: +info +! +( +" +Buffer +{ +: +? +} +is +still +referenced +from +{ +} +" +id +existing_ref_count +) +; +} +} +} +false +} +} +impl +< +A +: +HalApi +> +BufferTracker +< +A +> +{ +pub +fn +new +( ) - > @@ -1809,7 +2576,7 @@ tracked . pub fn -used +used_resources ( & self @@ -1821,9 +2588,12 @@ Iterator < Item = -Valid +Arc < -BufferId +Buffer +< +A +> > > + @@ -1834,7 +2604,7 @@ self . metadata . -owned_ids +owned_resources ( ) } @@ -1849,7 +2619,7 @@ transitions . pub fn -drain +drain_transitions ( & mut @@ -1857,16 +2627,20 @@ self ) - > -Drain +impl +Iterator < -' -_ -PendingTransition +Item += +BufferBarrier < -BufferUses +A > > { +let +buffer_barriers += self . temp @@ -1876,6 +2650,42 @@ drain . . ) +. +map +( +| +pending +| +{ +let +buf += +unsafe +{ +self +. +metadata +. +get_resource_unchecked +( +pending +. +id +as +_ +) +} +; +pending +. +into_hal +( +buf +) +} +) +; +buffer_barriers } / / @@ -1953,37 +2763,31 @@ mut self id : -Valid -< BufferId -> -ref_count +resource : -RefCount +Arc +< +Buffer +< +A +> +> state : BufferUses ) { let -( -index32 -epoch -_ -) +index = id . -0 -. unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -2034,7 +2838,6 @@ tracked } insert ( -None Some ( & @@ -2067,15 +2870,14 @@ ResourceMetadataProvider : Direct { -epoch -ref_count +resource : Cow : : Owned ( -ref_count +resource ) } ) @@ -2164,91 +2966,51 @@ needed pub fn set_single -< -' -a -> ( & mut self -storage +buffer : & -' -a -storage -: -: -Storage +Arc < Buffer < A > -BufferId > -id -: -BufferId state : BufferUses ) - > -Option -< -( -& -' -a -Buffer +SetSingleResult < A > -Option -< -PendingTransition -< -BufferUses -> -> -) -> { let -value +index +: +usize = -storage +buffer . -get +as_info ( -id ) . -ok -( -) -? -; -let +id ( -index32 -epoch -_ ) -= -id . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -2273,13 +3035,6 @@ insert_or_barrier_update Some ( & -value -. -life_guard -) -Some -( -& mut self . @@ -2295,7 +3050,6 @@ mut self . metadata -index32 index BufferStateProvider : @@ -2308,9 +3062,21 @@ None ResourceMetadataProvider : : -Resource +Direct { -epoch +resource +: +Cow +: +: +Owned +( +buffer +. +clone +( +) +) } & mut @@ -2338,7 +3104,11 @@ len Some ( ( -value +buffer +. +clone +( +) self . temp @@ -2405,7 +3175,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -2520,7 +3290,6 @@ unsafe { insert_or_barrier_update ( -None Some ( & @@ -2540,9 +3309,6 @@ self . metadata index -as -u32 -index BufferStateProvider : : @@ -2647,7 +3413,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -2765,7 +3531,6 @@ unsafe { insert_or_barrier_update ( -None Some ( & @@ -2785,9 +3550,6 @@ self . metadata index -as -u32 -index BufferStateProvider : : @@ -2904,7 +3666,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -3054,11 +3816,8 @@ IntoIterator < Item = -Valid -< BufferId > -> ) { let @@ -3105,8 +3864,6 @@ _ = id . -0 -. unzip ( ) @@ -3146,7 +3903,6 @@ unsafe { insert_or_barrier_update ( -None Some ( & @@ -3166,9 +3922,6 @@ self . metadata index -as -u32 -index BufferStateProvider : : @@ -3216,109 +3969,47 @@ index ; } } -/ -/ -/ -Removes -the -given -resource -from -the -tracker -iff -we -have -the -last -reference -to -the -/ -/ -/ -resource -and -the -epoch -matches -. -/ -/ -/ -/ -/ -/ -Returns -true -if -the -resource -was -removed -. -/ -/ -/ -/ -/ -/ -If -the -ID -is -higher -than -the -length -of -internal -vectors -/ -/ -/ -false -will -be -returned -. +# +[ +allow +( +dead_code +) +] pub fn -remove_abandoned +get ( & -mut self id : -Valid -< BufferId -> ) - > -bool +Option +< +& +Arc +< +Buffer +< +A +> +> +> { let -( -index32 -epoch -_ -) +index = id . -0 -. unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -3334,7 +4025,7 @@ size ) { return -false +None ; } self @@ -3356,62 +4047,22 @@ contains_unchecked index ) { -let -existing_epoch -= -self -. -metadata -. -get_epoch_unchecked +return +Some ( -index -) -; -let -existing_ref_count -= self . metadata . -get_ref_count_unchecked +get_resource_unchecked ( index ) -; -if -existing_epoch -= -= -epoch -& -& -existing_ref_count -. -load -( -) -= -= -1 -{ -self -. -metadata -. -remove -( -index ) ; -return -true -; } } -} -false +None } } / @@ -3707,13 +4358,6 @@ A HalApi > ( -life_guard -: -Option -< -& -LifeGuard -> start_states : Option @@ -3738,6 +4382,11 @@ mut ResourceMetadata < A +BufferId +Buffer +< +A +> > index32 : @@ -3759,6 +4408,11 @@ ResourceMetadataProvider ' _ A +BufferId +Buffer +< +A +> > ) - @@ -3791,7 +4445,6 @@ unsafe { insert ( -life_guard start_states current_states resource_metadata @@ -3985,13 +4638,6 @@ A HalApi > ( -life_guard -: -Option -< -& -LifeGuard -> start_states : Option @@ -4016,10 +4662,12 @@ mut ResourceMetadata < A +BufferId +Buffer +< +A +> > -index32 -: -u32 index : usize @@ -4047,6 +4695,11 @@ ResourceMetadataProvider ' _ A +BufferId +Buffer +< +A +> > barriers : @@ -4082,7 +4735,6 @@ unsafe { insert ( -life_guard start_states current_states resource_metadata @@ -4117,7 +4769,6 @@ unsafe barrier ( current_states -index32 index start_state_provider barriers @@ -4151,13 +4802,6 @@ A HalApi > ( -life_guard -: -Option -< -& -LifeGuard -> start_states : Option @@ -4182,6 +4826,11 @@ mut ResourceMetadata < A +BufferId +Buffer +< +A +> > index : @@ -4210,6 +4859,11 @@ ResourceMetadataProvider ' _ A +BufferId +Buffer +< +A +> > ) { @@ -4364,16 +5018,12 @@ index new_end_state ; let -( -epoch -ref_count -) +resource = metadata_provider . get_own ( -life_guard index ) ; @@ -4382,8 +5032,7 @@ resource_metadata insert ( index -epoch -ref_count +resource ) ; } @@ -4431,6 +5080,11 @@ ResourceMetadataProvider ' _ A +BufferId +Buffer +< +A +> > ) - @@ -4574,9 +5228,6 @@ mut [ BufferUses ] -index32 -: -u32 index : usize @@ -4645,7 +5296,9 @@ PendingTransition { id : -index32 +index +as +_ selector : ( @@ -4669,7 +5322,7 @@ trace \ tbuf { -index32 +index } : transition diff --git a/third_party/rust/wgpu-core/src/track/metadata.rs b/third_party/rust/wgpu-core/src/track/metadata.rs index 6ff16810c1ab5..c5ecc277cf96d 100644 --- a/third_party/rust/wgpu-core/src/track/metadata.rs +++ b/third_party/rust/wgpu-core/src/track/metadata.rs @@ -17,13 +17,12 @@ HalApi id : : -{ -self TypedId -} +resource +: +: +Resource Epoch -LifeGuard -RefCount } ; use @@ -46,6 +45,10 @@ marker : PhantomData mem +sync +: +: +Arc } ; use @@ -63,9 +66,10 @@ of resources holding a -[ -RefCount -] +Arc +< +T +> and epoch for @@ -153,6 +157,15 @@ ResourceMetadata A : HalApi +I +: +TypedId +T +: +Resource +< +I +> > { / @@ -185,48 +198,25 @@ usize / A vector -parallel -to -owned holding clones of members ' -RefCount +T s . -ref_counts +resources : Vec < Option < -RefCount +Arc +< +T > > -/ -/ -/ -A -vector -parallel -to -owned -holding -the -epoch -of -each -members -' -id -. -epochs -: -Vec -< -Epoch > / / @@ -247,7 +237,10 @@ _phantom : PhantomData < +( A +I +) > } impl @@ -255,10 +248,21 @@ impl A : HalApi +I +: +TypedId +T +: +Resource +< +I +> > ResourceMetadata < A +I +T > { pub @@ -283,15 +287,7 @@ BitVec default ( ) -ref_counts -: -Vec -: -: -new -( -) -epochs +resources : Vec : @@ -355,7 +351,7 @@ usize { self . -ref_counts +resources . resize ( @@ -363,19 +359,6 @@ size None ) ; -self -. -epochs -. -resize -( -size -u32 -: -: -MAX -) -; resize_bitvec ( & @@ -485,21 +468,7 @@ index < self . -ref_counts -. -len -( -) -) -; -strict_assert -! -( -index -< -self -. -epochs +resources . len ( @@ -519,7 +488,7 @@ index { self . -ref_counts +resources [ index ] @@ -807,12 +776,12 @@ self index : usize -epoch -: -Epoch -ref_count +resource : -RefCount +Arc +< +T +> ) { self @@ -830,19 +799,7 @@ unsafe * self . -epochs -. -get_unchecked_mut -( -index -) -= -epoch -; -* -self -. -ref_counts +resources . get_unchecked_mut ( @@ -851,7 +808,7 @@ index = Some ( -ref_count +resource ) ; } @@ -861,11 +818,6 @@ ref_count / Get the -[ -RefCount -] -of -the resource with the @@ -920,7 +872,7 @@ super ) unsafe fn -get_ref_count_unchecked +get_resource_unchecked ( & self @@ -931,13 +883,16 @@ usize - > & -RefCount +Arc +< +T +> { unsafe { self . -ref_counts +resources . get_unchecked ( @@ -958,12 +913,8 @@ unwrap_unchecked / Get the -[ -Epoch -] -of -the -id +reference +count of the resource @@ -1020,7 +971,7 @@ super ) unsafe fn -get_epoch_unchecked +get_ref_count_unchecked ( & self @@ -1030,19 +981,32 @@ usize ) - > -Epoch +usize { unsafe { -* +Arc +: +: +strong_count +( self . -epochs +resources . get_unchecked ( index ) +. +as_ref +( +) +. +unwrap_unchecked +( +) +) } } / @@ -1053,9 +1017,6 @@ an iterator over the -ids -for -all resources owned by @@ -1066,12 +1027,7 @@ pub super ) fn -owned_ids -< -Id -: -TypedId -> +owned_resources ( & self @@ -1083,12 +1039,9 @@ Iterator < Item = -id -: -: -Valid +Arc < -Id +T > > + @@ -1137,14 +1090,13 @@ index | { let -epoch +resource = unsafe { -* self . -epochs +resources . get_unchecked ( @@ -1152,28 +1104,161 @@ index ) } ; -id -: -: -Valid +resource +. +as_ref +( +) +. +unwrap +( +) +. +clone +( +) +} +) +} +/ +/ +/ +Returns +an +iterator +over +the +resources +owned +by +self +. +pub +( +super +) +fn +drain_resources +( +& +mut +self +) +- +> +Vec +< +Arc +< +T +> +> +{ +if +! +self +. +owned +. +is_empty +( +) +{ +self +. +tracker_assert_in_bounds ( -Id +self +. +owned +. +len +( +) +- +1 +) +} +; +let +mut +resources += +Vec : : -zip +new ( +) +; +iterate_bitvec_indices +( +& +self +. +owned +) +. +for_each +( +| index -as -u32 -epoch -A -: -: -VARIANT +| +{ +let +resource += +unsafe +{ +self +. +resources +. +get_unchecked +( +index +) +} +; +resources +. +push +( +resource +. +as_ref +( ) +. +unwrap +( ) +. +clone +( +) +) +; } ) +; +self +. +owned +. +clear +( +) +; +self +. +resources +. +clear +( +) +; +resources } / / @@ -1283,7 +1368,7 @@ unsafe * self . -ref_counts +resources . get_unchecked_mut ( @@ -1292,21 +1377,6 @@ index = None ; -* -self -. -epochs -. -get_unchecked_mut -( -index -) -= -u32 -: -: -MAX -; } self . @@ -1367,6 +1437,15 @@ a A : HalApi +I +: +TypedId +T +: +Resource +< +I +> > { / @@ -1380,16 +1459,16 @@ values . Direct { -epoch -: -Epoch -ref_count +resource : Cow < ' a -RefCount +Arc +< +T +> > } / @@ -1411,44 +1490,33 @@ a ResourceMetadata < A +I +T > } -/ -/ -/ -The -epoch -is -given -directly -but -the -life -count -comes -from -the -resource -itself -. -Resource -{ -epoch -: -Epoch -} } impl < A : HalApi +I +: +TypedId +T +: +Resource +< +I +> > ResourceMetadataProvider < ' _ A +I +T > { / @@ -1500,7 +1568,7 @@ source / / - -life_guard +info must be Some @@ -1527,23 +1595,16 @@ fn get_own ( self -life_guard -: -Option -< -& -LifeGuard -> index : usize ) - > -( -Epoch -RefCount -) +Arc +< +T +> { match self @@ -1553,21 +1614,15 @@ ResourceMetadataProvider : Direct { -epoch -ref_count +resource } = > -{ -( -epoch -ref_count +resource . into_owned ( ) -) -} ResourceMetadataProvider : : @@ -1585,28 +1640,15 @@ tracker_assert_in_bounds index ) ; -( -unsafe -{ -* -metadata -. -epochs -. -get_unchecked -( -index -) -} { let -ref_count +resource = unsafe { metadata . -ref_counts +resources . get_unchecked ( @@ -1616,7 +1658,7 @@ index ; unsafe { -ref_count +resource . clone ( @@ -1627,43 +1669,6 @@ unwrap_unchecked ) } } -) -} -ResourceMetadataProvider -: -: -Resource -{ -epoch -} -= -> -{ -strict_assert -! -( -life_guard -. -is_some -( -) -) -; -( -epoch -unsafe -{ -life_guard -. -unwrap_unchecked -( -) -} -. -add_ref -( -) -) } } } @@ -1732,61 +1737,28 @@ usize > Epoch { -match -self -{ -ResourceMetadataProvider -: -: -Direct -{ -epoch -. -. -} -| -ResourceMetadataProvider -: -: -Resource -{ -epoch -. -. -} -= -> -epoch -ResourceMetadataProvider -: -: -Indirect -{ -metadata -} -= -> +unsafe { -metadata +self . -tracker_assert_in_bounds +get_own ( index ) -; -unsafe -{ -* -metadata . -epochs +as_info +( +) . -get_unchecked +id ( -index ) -} -} +. +unzip +( +) +. +1 } } } diff --git a/third_party/rust/wgpu-core/src/track/mod.rs b/third_party/rust/wgpu-core/src/track/mod.rs index 3f7330623896a..c3823a36c595c 100644 --- a/third_party/rust/wgpu-core/src/track/mod.rs +++ b/third_party/rust/wgpu-core/src/track/mod.rs @@ -910,9 +910,18 @@ TypedId pipeline resource storage +: +: +Storage } ; use +parking_lot +: +: +RwLock +; +use std : : @@ -1062,6 +1071,24 @@ Range S > } +pub +( +crate +) +type +PendingTransitionList += +Vec +< +PendingTransition +< +hal +: +: +TextureUses +> +> +; impl PendingTransition < @@ -1091,10 +1118,7 @@ into_hal a A : -hal -: -: -Api +HalApi > ( self @@ -1186,10 +1210,7 @@ into_hal a A : -hal -: -: -Api +HalApi > ( self @@ -1201,7 +1222,7 @@ a resource : : -Texture +TextureInner < A > @@ -1223,8 +1244,6 @@ texture = tex . -inner -. as_raw ( ) @@ -2416,6 +2435,13 @@ assending order ) . +# +[ +derive +( +Debug +) +] pub ( crate @@ -2447,6 +2473,10 @@ views : StatelessBindGroupSate < +id +: +: +TextureViewId resource : : @@ -2454,16 +2484,16 @@ TextureView < A > -id -: -: -TextureViewId > pub samplers : StatelessBindGroupSate < +id +: +: +SamplerId resource : : @@ -2471,10 +2501,6 @@ Sampler < A > -id -: -: -SamplerId > } impl @@ -2667,6 +2693,13 @@ the render bundles . +# +[ +derive +( +Debug +) +] pub ( crate @@ -2682,17 +2715,23 @@ HalApi pub buffers : +RwLock +< BufferUsageScope < A > +> pub textures : +RwLock +< TextureUsageScope < A > +> / / Don @@ -2717,9 +2756,15 @@ groups pub bind_groups : +RwLock +< StatelessTracker < A +id +: +: +BindGroupId binding_model : : @@ -2727,17 +2772,20 @@ BindGroup < A > -id -: -: -BindGroupId +> > pub render_pipelines : +RwLock +< StatelessTracker < A +id +: +: +RenderPipelineId pipeline : : @@ -2745,17 +2793,20 @@ RenderPipeline < A > -id -: -: -RenderPipelineId +> > pub query_sets : +RwLock +< StatelessTracker < A +id +: +: +QuerySetId resource : : @@ -2763,10 +2814,7 @@ QuerySet < A > -id -: -: -QuerySetId +> > } impl @@ -2804,9 +2852,6 @@ new buffers : & -storage -: -: Storage < resource @@ -2824,9 +2869,6 @@ BufferId textures : & -storage -: -: Storage < resource @@ -2844,9 +2886,6 @@ TextureId bind_groups : & -storage -: -: Storage < binding_model @@ -2864,9 +2903,6 @@ BindGroupId render_pipelines : & -storage -: -: Storage < pipeline @@ -2884,9 +2920,6 @@ RenderPipelineId query_sets : & -storage -: -: Storage < resource @@ -2907,57 +2940,90 @@ QuerySetId Self { let -mut value = Self { buffers : +RwLock +: +: +new +( BufferUsageScope : : new ( ) +) textures : +RwLock +: +: +new +( TextureUsageScope : : new ( ) +) bind_groups : +RwLock +: +: +new +( StatelessTracker : : new ( ) +) render_pipelines : +RwLock +: +: +new +( StatelessTracker : : new ( ) +) query_sets : +RwLock +: +: +new +( StatelessTracker : : new ( ) +) } ; value . buffers . +write +( +) +. set_size ( buffers @@ -2971,6 +3037,10 @@ value . textures . +write +( +) +. set_size ( textures @@ -2984,6 +3054,10 @@ value . bind_groups . +write +( +) +. set_size ( bind_groups @@ -2997,6 +3071,10 @@ value . render_pipelines . +write +( +) +. set_size ( render_pipelines @@ -3010,6 +3088,10 @@ value . query_sets . +write +( +) +. set_size ( query_sets @@ -3115,26 +3197,6 @@ merge_bind_group & mut self -textures -: -& -storage -: -: -Storage -< -resource -: -: -Texture -< -A -> -id -: -: -TextureId -> bind_group : & @@ -3158,6 +3220,10 @@ self . buffers . +write +( +) +. merge_bind_group ( & @@ -3174,9 +3240,12 @@ self . textures . +write +( +) +. merge_bind_group ( -textures & bind_group . @@ -3288,9 +3357,6 @@ new buffers : & -storage -: -: Storage < resource @@ -3308,9 +3374,6 @@ BufferId textures : & -storage -: -: Storage < resource @@ -3475,26 +3538,6 @@ merge_bind_group & mut self -textures -: -& -storage -: -: -Storage -< -resource -: -: -Texture -< -A -> -id -: -: -TextureId -> bind_group : & @@ -3533,7 +3576,6 @@ textures . merge_bind_group ( -textures & bind_group . @@ -3650,26 +3692,6 @@ merge_render_bundle & mut self -textures -: -& -storage -: -: -Storage -< -resource -: -: -Texture -< -A -> -id -: -: -TextureId -> render_bundle : & @@ -3694,9 +3716,14 @@ buffers merge_usage_scope ( & +* render_bundle . buffers +. +read +( +) ) ? ; @@ -3706,11 +3733,15 @@ textures . merge_usage_scope ( -textures & +* render_bundle . textures +. +read +( +) ) ? ; @@ -3721,6 +3752,48 @@ Ok ) } } +pub +( +crate +) +trait +ResourceTracker +< +Id +R +> +where +Id +: +TypedId +R +: +resource +: +: +Resource +< +Id +> +{ +fn +remove_abandoned +( +& +mut +self +id +: +Id +external_count +: +usize +) +- +> +bool +; +} / / / @@ -3768,6 +3841,10 @@ views StatelessTracker < A +id +: +: +TextureViewId resource : : @@ -3775,10 +3852,6 @@ TextureView < A > -id -: -: -TextureViewId > pub samplers @@ -3786,6 +3859,10 @@ samplers StatelessTracker < A +id +: +: +SamplerId resource : : @@ -3793,10 +3870,6 @@ Sampler < A > -id -: -: -SamplerId > pub bind_groups @@ -3804,6 +3877,10 @@ bind_groups StatelessTracker < A +id +: +: +BindGroupId binding_model : : @@ -3811,10 +3888,6 @@ BindGroup < A > -id -: -: -BindGroupId > pub compute_pipelines @@ -3822,6 +3895,10 @@ compute_pipelines StatelessTracker < A +id +: +: +ComputePipelineId pipeline : : @@ -3829,10 +3906,6 @@ ComputePipeline < A > -id -: -: -ComputePipelineId > pub render_pipelines @@ -3840,6 +3913,10 @@ render_pipelines StatelessTracker < A +id +: +: +RenderPipelineId pipeline : : @@ -3847,10 +3924,6 @@ RenderPipeline < A > -id -: -: -RenderPipelineId > pub bundles @@ -3858,6 +3931,10 @@ bundles StatelessTracker < A +id +: +: +RenderBundleId command : : @@ -3865,10 +3942,6 @@ RenderBundle < A > -id -: -: -RenderBundleId > pub query_sets @@ -3876,6 +3949,10 @@ query_sets StatelessTracker < A +id +: +: +QuerySetId resource : : @@ -3883,10 +3960,6 @@ QuerySet < A > -id -: -: -QuerySetId > } impl @@ -4008,9 +4081,6 @@ buffers Option < & -storage -: -: Storage < resource @@ -4031,9 +4101,6 @@ textures Option < & -storage -: -: Storage < resource @@ -4054,9 +4121,6 @@ views Option < & -storage -: -: Storage < resource @@ -4077,9 +4141,6 @@ samplers Option < & -storage -: -: Storage < resource @@ -4100,9 +4161,6 @@ bind_groups Option < & -storage -: -: Storage < binding_model @@ -4123,9 +4181,6 @@ compute_pipelines Option < & -storage -: -: Storage < pipeline @@ -4146,9 +4201,6 @@ render_pipelines Option < & -storage -: -: Storage < pipeline @@ -4169,9 +4221,6 @@ bundles Option < & -storage -: -: Storage < command @@ -4192,9 +4241,6 @@ query_sets Option < & -storage -: -: Storage < resource @@ -4676,26 +4722,6 @@ set_and_remove_from_usage_scope_sparse & mut self -textures -: -& -storage -: -: -Storage -< -resource -: -: -Texture -< -A -> -id -: -: -TextureId -> scope : & @@ -4730,7 +4756,7 @@ bind_group . buffers . -used +used_ids ( ) ) @@ -4744,7 +4770,6 @@ textures . set_and_remove_from_usage_scope_sparse ( -textures & mut scope @@ -4856,9 +4881,14 @@ bind_groups add_from_tracker ( & +* render_bundle . bind_groups +. +read +( +) ) ; self @@ -4868,9 +4898,14 @@ render_pipelines add_from_tracker ( & +* render_bundle . render_pipelines +. +read +( +) ) ; self @@ -4880,9 +4915,14 @@ query_sets add_from_tracker ( & +* render_bundle . query_sets +. +read +( +) ) ; Ok diff --git a/third_party/rust/wgpu-core/src/track/stateless.rs b/third_party/rust/wgpu-core/src/track/stateless.rs index d8d2536d7347e..6d75012532a4c 100644 --- a/third_party/rust/wgpu-core/src/track/stateless.rs +++ b/third_party/rust/wgpu-core/src/track/stateless.rs @@ -34,10 +34,22 @@ use std : : +{ marker : : PhantomData +sync +: +: +Arc +} +; +use +parking_lot +: +: +Mutex ; use crate @@ -51,19 +63,27 @@ HalApi id : : -{ TypedId -Valid -} resource +: +: +Resource storage +: +: +Storage track : : ResourceMetadata -RefCount } ; +use +super +: +: +ResourceTracker +; / / / @@ -77,6 +97,13 @@ bind group stores . +# +[ +derive +( +Debug +) +] pub ( crate @@ -84,47 +111,49 @@ crate struct StatelessBindGroupSate < -T Id : TypedId +T +: +Resource +< +Id +> > { resources : +Mutex +< Vec < ( -Valid -< Id +Arc +< +T > -RefCount ) > -_phantom -: -PhantomData -< -T > } impl < -T -: -resource +Id : +TypedId +T : Resource +< Id -: -TypedId +> > StatelessBindGroupSate < -T Id +T > { pub @@ -140,15 +169,18 @@ Self { resources : +Mutex +: +: +new +( Vec : : new ( ) -_phantom -: -PhantomData +) } } / @@ -204,14 +236,23 @@ fn optimize ( & -mut self ) { +let +mut +resources += self . resources . +lock +( +) +; +resources +. sort_unstable_by_key ( | @@ -223,8 +264,6 @@ _ | id . -0 -. unzip ( ) @@ -250,7 +289,7 @@ duplicates . pub fn -used +used_resources ( & self @@ -262,19 +301,28 @@ Iterator < Item = -Valid +Arc < -Id +T > > + ' _ { +let +resources += self . resources . +lock +( +) +; +resources +. iter ( ) @@ -284,11 +332,117 @@ map | & ( -id _ +ref +resource ) | -id +resource +. +clone +( +) +) +. +collect +: +: +< +Vec +< +_ +> +> +( +) +. +into_iter +( +) +} +/ +/ +/ +Returns +a +list +of +all +resources +tracked +. +May +contain +duplicates +. +pub +fn +drain_resources +( +& +self +) +- +> +impl +Iterator +< +Item += +Arc +< +T +> +> ++ +' +_ +{ +let +mut +resources += +self +. +resources +. +lock +( +) +; +resources +. +drain +( +. +. +) +. +map +( +| +( +_ +r +) +| +r +) +. +collect +: +: +< +Vec +< +_ +> +> +( +) +. +into_iter +( ) } / @@ -308,16 +462,12 @@ a > ( & -mut self storage : & ' a -storage -: -: Storage < T @@ -352,24 +502,27 @@ ok ) ? ; +let +mut +resources += self . resources . -push +lock ( +) +; +resources +. +push ( -Valid ( id -) resource . -life_guard -( -) -. -add_ref +clone ( ) ) @@ -395,6 +548,13 @@ buffer or device . +# +[ +derive +( +Debug +) +] pub ( crate @@ -405,48 +565,335 @@ StatelessTracker A : HalApi +Id +: +TypedId +T +: +Resource +< +Id +> +> +{ +metadata +: +ResourceMetadata +< +A +Id T +> +_phantom +: +PhantomData +< +Id +> +} +impl +< +A +: +HalApi Id : TypedId +T +: +Resource +< +Id +> +> +ResourceTracker +< +Id +T +> +for +StatelessTracker +< +A +Id +T > { +/ +/ +/ +Removes +the +given +resource +from +the +tracker +iff +we +have +the +last +reference +to +the +/ +/ +/ +resource +and +the +epoch +matches +. +/ +/ +/ +/ +/ +/ +Returns +true +if +the +resource +was +removed +. +/ +/ +/ +/ +/ +/ +If +the +ID +is +higher +than +the +length +of +internal +vectors +/ +/ +/ +false +will +be +returned +. +fn +remove_abandoned +( +& +mut +self +id +: +Id +external_count +: +usize +) +- +> +bool +{ +let +index += +id +. +unzip +( +) +. +0 +as +usize +; +if +index +> +self +. +metadata +. +size +( +) +{ +return +false +; +} +self +. +tracker_assert_in_bounds +( +index +) +; +unsafe +{ +if +self +. +metadata +. +contains_unchecked +( +index +) +{ +let +existing_ref_count += +self +. +metadata +. +get_ref_count_unchecked +( +index +) +; +/ +/ +2 +ref +count +if +only +in +Device +Tracker +and +suspected +resource +itself +and +already +released +from +user +/ +/ +so +not +appearing +in +Registry +let +min_ref_count += +1 ++ +external_count +; +if +existing_ref_count +< += +min_ref_count +{ +self +. metadata +. +remove +( +index +) +; +log +: +: +info +! +( +" +{ +} +{ +: +? +} +is +not +tracked +anymore +" +T +: +: +TYPE +id +) +; +return +true +; +} +else +{ +log +: +: +info +! +( +" +{ +} +{ +: +? +} +is +still +referenced +from +{ +} +" +T : -ResourceMetadata -< -A -> -_phantom : -PhantomData -< -( -T -Id +TYPE +id +existing_ref_count ) -> +; +} +} +} +false +} } impl < A : HalApi -T -: -resource +Id : +TypedId +T : Resource +< Id -: -TypedId +> > StatelessTracker < A -T Id +T > { pub @@ -618,7 +1065,7 @@ tracked . pub fn -used +used_resources ( & self @@ -630,20 +1077,72 @@ Iterator < Item = -Valid +Arc < -Id +T +> +> ++ +' +_ +{ +self +. +metadata +. +owned_resources +( +) +} +/ +/ +/ +Returns +a +list +of +all +resources +tracked +. +pub +fn +drain_resources +( +& +mut +self +) +- +> +impl +Iterator +< +Item += +Arc +< +T > > + ' _ { +let +resources += self . metadata . -owned_ids +drain_resources +( +) +; +resources +. +into_iter ( ) } @@ -721,26 +1220,24 @@ mut self id : -Valid -< Id -> -ref_count +resource : -RefCount +Arc +< +T +> ) { let ( index32 -epoch +_epoch _ ) = id . -0 -. unzip ( ) @@ -775,8 +1272,7 @@ metadata insert ( index -epoch -ref_count +resource ) ; } @@ -842,9 +1338,6 @@ storage & ' a -storage -: -: Storage < T @@ -861,11 +1354,14 @@ Option & ' a +Arc +< T > +> { let -item +resource = storage . @@ -882,7 +1378,7 @@ ok let ( index32 -epoch +_epoch _ ) = @@ -922,14 +1418,9 @@ metadata insert ( index -epoch -item -. -life_guard -( -) +resource . -add_ref +clone ( ) ) @@ -937,7 +1428,7 @@ add_ref } Some ( -item +resource ) } / @@ -1073,25 +1564,13 @@ if previously_owned { let -epoch -= -other -. -metadata -. -get_epoch_unchecked -( -index -) -; -let -other_ref_count +other_resource = other . metadata . -get_ref_count_unchecked +get_resource_unchecked ( index ) @@ -1103,8 +1582,7 @@ metadata insert ( index -epoch -other_ref_count +other_resource . clone ( @@ -1115,109 +1593,37 @@ clone } } } -/ -/ -/ -Removes -the -given -resource -from -the -tracker -iff -we -have -the -last -reference -to -the -/ -/ -/ -resource -and -the -epoch -matches -. -/ -/ -/ -/ -/ -/ -Returns -true -if -the -resource -was -removed -. -/ -/ -/ -/ -/ -/ -If -the -ID -is -higher -than -the -length -of -internal -vectors -/ -/ -/ -false -will -be -returned -. pub fn -remove_abandoned +get ( & -mut self id : -Valid -< Id -> ) - > -bool +Option +< +& +Arc +< +T +> +> { let -( -index32 -epoch -_ -) +index = id . -0 -. unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -1233,7 +1639,7 @@ size ) { return -false +None ; } self @@ -1255,61 +1661,21 @@ contains_unchecked index ) { -let -existing_epoch -= -self -. -metadata -. -get_epoch_unchecked +return +Some ( -index -) -; -let -existing_ref_count -= self . metadata . -get_ref_count_unchecked +get_resource_unchecked ( index ) -; -if -existing_epoch -= -= -epoch -& -& -existing_ref_count -. -load -( -) -= -= -1 -{ -self -. -metadata -. -remove -( -index ) ; -return -true -; } } -} -false +None } } diff --git a/third_party/rust/wgpu-core/src/track/texture.rs b/third_party/rust/wgpu-core/src/track/texture.rs index 86c2d478cf2a8..35b2518977586 100644 --- a/third_party/rust/wgpu-core/src/track/texture.rs +++ b/third_party/rust/wgpu-core/src/track/texture.rs @@ -187,6 +187,8 @@ range : RangedStates PendingTransition +PendingTransitionList +ResourceTracker } ; use @@ -204,13 +206,15 @@ id { TextureId TypedId -Valid } resource : : +{ +Resource Texture -storage +TextureInner +} track : : @@ -222,8 +226,6 @@ ResourceMetadataProvider ResourceUses UsageConflict } -LifeGuard -RefCount } ; use @@ -245,6 +247,15 @@ naga FastHashMap ; use +parking_lot +: +: +{ +Mutex +RwLockReadGuard +} +; +use wgt : : @@ -271,6 +282,10 @@ ops : : Range +sync +: +: +Arc vec : : @@ -1027,6 +1042,40 @@ inner ) } } +# +[ +derive +( +Debug +) +] +struct +TextureBindGroupStateData +< +A +: +HalApi +> +{ +selector +: +Option +< +TextureSelector +> +texture +: +Arc +< +Texture +< +A +> +> +usage +: +TextureUses +} / / / @@ -1040,6 +1089,13 @@ bind group stores . +# +[ +derive +( +Debug +) +] pub ( crate @@ -1054,26 +1110,15 @@ HalApi { textures : -Vec +Mutex < -( -Valid +Vec < -TextureId -> -Option +TextureBindGroupStateData < -TextureSelector +A > -RefCount -TextureUses -) > -_phantom -: -PhantomData -< -A > } impl @@ -1100,15 +1145,18 @@ Self { textures : +Mutex +: +: +new +( Vec : : new ( ) -_phantom -: -PhantomData +) } } / @@ -1164,28 +1212,39 @@ fn optimize ( & -mut self ) { +let +mut +textures += self . textures . +lock +( +) +; +textures +. sort_unstable_by_key ( | -& +v +| +v +. +texture +. +as_info ( -id -_ -_ -_ ) -| -id . -0 +id +( +) . unzip ( @@ -1203,7 +1262,7 @@ a list of all -buffers +textures tracked . May @@ -1212,7 +1271,7 @@ duplicates . pub fn -used +drain_resources ( & self @@ -1224,35 +1283,62 @@ Iterator < Item = -Valid +Arc < -TextureId +Texture +< +A +> > > + ' _ { +let +mut +textures += self . textures . -iter +lock +( +) +; +textures +. +drain ( +. +. ) . map ( | -& -( -id -_ -_ +v +| +v +. +texture +) +. +collect +: +: +< +Vec +< _ +> +> +( ) -| -id +. +into_iter +( ) } / @@ -1276,30 +1362,19 @@ a > ( & -mut self -storage +texture : & ' a -storage -: -: -Storage +Arc < Texture < A > -TextureId > -id -: -TextureId -ref_count -: -RefCount selector : Option @@ -1317,47 +1392,50 @@ Option & ' a +Arc +< Texture < A > > +> { let -value +mut +textures = -storage +self . -get -( -id -) +textures . -ok +lock ( ) -? ; -self -. textures . push ( +TextureBindGroupStateData +{ +selector +texture +: +texture +. +clone ( -Valid -( -id ) -selector -ref_count +usage +: state -) +} ) ; Some ( -value +texture ) } } @@ -1397,7 +1475,7 @@ complex : FastHashMap < -u32 +usize ComplexTextureState > } @@ -1433,6 +1511,31 @@ default } } fn +clear +( +& +mut +self +) +{ +self +. +simple +. +clear +( +) +; +self +. +complex +. +clear +( +) +; +} +fn set_size ( & @@ -1498,6 +1601,11 @@ metadata ResourceMetadata < A +TextureId +Texture +< +A +> > } impl @@ -1613,11 +1721,7 @@ complex contains_key ( & -( index -as -u32 -) ) } else @@ -1700,19 +1804,20 @@ size / / / -Returns -a -list -of +Drains all textures tracked . pub +( +crate +) fn -used +drain_resources ( & +mut self ) - @@ -1722,20 +1827,40 @@ Iterator < Item = -Valid +Arc < -TextureId +Texture +< +A +> > > + ' _ { +let +resources += self . metadata . -owned_ids +drain_resources +( +) +; +self +. +set +. +clear +( +) +; +resources +. +into_iter ( ) } @@ -1882,20 +2007,6 @@ merge_usage_scope & mut self -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> scope : & @@ -1955,13 +2066,6 @@ owned_indices ( ) { -let -index32 -= -index -as -u32 -; self . tracker_assert_in_bounds @@ -1977,22 +2081,28 @@ index ) ; let -texture_data +texture_selector = unsafe { -texture_data_from_texture +& +scope +. +metadata +. +get_resource_unchecked ( -storage -index32 +index ) +. +full_range } ; unsafe { insert_or_merge ( -texture_data +texture_selector & mut self @@ -2003,7 +2113,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -2176,20 +2285,6 @@ merge_bind_group & mut self -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> bind_group : & @@ -2207,20 +2302,22 @@ Result UsageConflict > { -for -& +let +textures += +bind_group +. +textures +. +lock ( -id -ref -selector -ref -ref_count -state ) +; +for +t in & -bind_group -. +* textures { unsafe @@ -2229,15 +2326,20 @@ self . merge_single ( -storage -id +& +t +. +texture +t +. selector . clone ( ) -ref_count -state +t +. +usage ) ? } @@ -2377,25 +2479,15 @@ merge_single & mut self -storage +texture : & -storage -: -: -Storage +Arc < Texture < A > -TextureId -> -id -: -Valid -< -TextureId > selector : @@ -2403,10 +2495,6 @@ Option < TextureSelector > -ref_count -: -& -RefCount new_state : TextureUses @@ -2421,24 +2509,23 @@ UsageConflict > { let +index += +texture +. +as_info ( -index32 -epoch -_ ) -= -id . -0 +id +( +) . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -2450,22 +2537,18 @@ index ) ; let -texture_data +texture_selector = -unsafe -{ -texture_data_from_texture -( -storage -index32 -) -} +& +texture +. +full_range ; unsafe { insert_or_merge ( -texture_data +texture_selector & mut self @@ -2476,7 +2559,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -2491,15 +2573,14 @@ ResourceMetadataProvider : Direct { -epoch -ref_count +resource : Cow : : Borrowed ( -ref_count +texture ) } ) @@ -2550,6 +2631,11 @@ metadata ResourceMetadata < A +TextureId +Texture +< +A +> > temp : @@ -2573,81 +2659,370 @@ A : HalApi > +ResourceTracker +< +TextureId +Texture +< +A +> +> +for TextureTracker < A > { -pub +/ +/ +/ +Removes +the +given +resource +from +the +tracker +iff +we +have +the +last +reference +to +the +/ +/ +/ +resource +and +the +epoch +matches +. +/ +/ +/ +/ +/ +/ +Returns +true +if +the +resource +was +removed +. +/ +/ +/ +/ +/ +/ +If +the +ID +is +higher +than +the +length +of +internal +vectors +/ +/ +/ +false +will +be +returned +. fn -new +remove_abandoned ( +& +mut +self +id +: +TextureId +external_count +: +usize ) - > -Self -{ -Self +bool { -start_set -: -TextureStateSet -: -: -new -( -) -end_set -: -TextureStateSet -: -: -new +let +index += +id +. +unzip ( ) +. +0 +as +usize +; +if +index +> +self +. metadata -: -ResourceMetadata -: -: -new -( -) -temp -: -Vec -: -: -new +. +size ( ) -_phantom -: -PhantomData -} +{ +return +false +; } -fn +self +. tracker_assert_in_bounds ( -& -self index -: -usize ) +; +unsafe { +if self . metadata . -tracker_assert_in_bounds +contains_unchecked ( index ) -; -strict_assert -! -( +{ +let +existing_ref_count += +self +. +metadata +. +get_ref_count_unchecked +( +index +) +; +/ +/ +2 +ref +count +if +only +in +Device +Tracker +and +suspected +resource +itself +and +already +released +from +user +/ +/ +so +not +appearing +in +Registry +let +min_ref_count += +1 ++ +external_count +; +if +existing_ref_count +< += +min_ref_count +{ +self +. +start_set +. +complex +. +remove +( +& +index +) +; +self +. +end_set +. +complex +. +remove +( +& +index +) +; +self +. +metadata +. +remove +( +index +) +; +log +: +: +info +! +( +" +Texture +{ +: +? +} +is +not +tracked +anymore +" +id +) +; +return +true +; +} +else +{ +log +: +: +info +! +( +" +Texture +{ +: +? +} +is +still +referenced +from +{ +} +" +id +existing_ref_count +) +; +} +} +} +false +} +} +impl +< +A +: +HalApi +> +TextureTracker +< +A +> +{ +pub +fn +new +( +) +- +> +Self +{ +Self +{ +start_set +: +TextureStateSet +: +: +new +( +) +end_set +: +TextureStateSet +: +: +new +( +) +metadata +: +ResourceMetadata +: +: +new +( +) +temp +: +Vec +: +: +new +( +) +_phantom +: +PhantomData +} +} +fn +tracker_assert_in_bounds +( +& +self +index +: +usize +) +{ +self +. +metadata +. +tracker_assert_in_bounds +( +index +) +; +strict_assert +! +( index < self @@ -2715,11 +3090,7 @@ complex contains_key ( & -( index -as -u32 -) ) } else @@ -2766,11 +3137,7 @@ complex contains_key ( & -( index -as -u32 -) ) } else @@ -2922,7 +3289,7 @@ tracked . pub fn -used +used_resources ( & self @@ -2934,9 +3301,12 @@ Iterator < Item = -Valid +Arc < -TextureId +Texture +< +A +> > > + @@ -2947,14 +3317,14 @@ self . metadata . -owned_ids +owned_resources ( ) } / / / -Drains +Drain all currently pending @@ -2962,22 +3332,53 @@ transitions . pub fn -drain +drain_transitions +< +' +a +> ( & +' +a mut self ) - > -Drain +( +PendingTransitionList +Vec < -PendingTransition +RwLockReadGuard < -TextureUses +' +a +Option +< +TextureInner +< +A +> > > +> +) { +let +mut +textures += +Vec +: +: +new +( +) +; +let +transitions += self . temp @@ -2987,131 +3388,56 @@ drain . . ) -} -/ -/ -/ -Get -the -refcount -of -the -given -resource -. -/ -/ -/ -/ -/ -/ -# -Safety -/ -/ -/ -/ -/ -/ -[ -Self -: -: -set_size -] -must -be -called -with -the -maximum -possible -Buffer -ID -before -this -/ -/ -/ -method -is -called -. -/ -/ -/ -/ -/ -/ -The -resource -must -be -tracked -by -this -tracker . -pub -unsafe -fn -get_ref_count +map ( -& -self -id -: -Valid -< -TextureId -> -) -- -> -& -RefCount +| +pending +| { let +tex += +unsafe +{ +self +. +metadata +. +get_resource_unchecked ( -index32 -_ +pending +. +id +as _ ) -= -id +} +; +textures . -0 +push +( +tex . -unzip +inner ( ) +) ; -let -index -= -index32 -as -usize -; -self +pending +} +) . -tracker_assert_in_bounds +collect ( -index ) ; -unsafe -{ -self -. -metadata -. -get_ref_count_unchecked ( -index +transitions +textures ) } -} / / / @@ -3189,31 +3515,30 @@ self id : TextureId -ref_count +resource : -RefCount +Arc +< +Texture +< +A +> +> usage : TextureUses ) { let -( -index32 -epoch -_ -) +index = id . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -3283,7 +3608,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -3300,15 +3624,14 @@ ResourceMetadataProvider : Direct { -epoch -ref_count +resource : Cow : : Owned ( -ref_count +resource ) } ) @@ -3397,13 +3720,13 @@ self texture : & +Arc +< Texture < A > -id -: -TextureId +> selector : TextureSelector @@ -3427,22 +3750,23 @@ TextureUses > { let +index += +texture +. +as_info ( -index32 -epoch -_ ) -= +. id +( +) . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -3464,16 +3788,10 @@ unsafe { insert_or_barrier_update ( -( -& -texture -. -life_guard & texture . full_range -) Some ( & @@ -3492,7 +3810,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -3508,9 +3825,21 @@ None ResourceMetadataProvider : : -Resource +Direct { -epoch +resource +: +Cow +: +: +Owned +( +texture +. +clone +( +) +) } & mut @@ -3588,7 +3917,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -3638,20 +3967,6 @@ set_from_tracker & mut self -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> tracker : & @@ -3703,13 +4018,6 @@ owned_indices ( ) { -let -index32 -= -index -as -u32 -; self . tracker_assert_in_bounds @@ -3726,13 +4034,24 @@ index ; unsafe { -insert_or_barrier_update -( -texture_data_from_texture +let +texture_selector += +& +tracker +. +metadata +. +get_resource_unchecked ( -storage -index32 +index ) +. +full_range +; +insert_or_barrier_update +( +texture_selector Some ( & @@ -3751,7 +4070,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -3858,7 +4176,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -3908,20 +4226,6 @@ set_from_usage_scope & mut self -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> scope : & @@ -3976,13 +4280,6 @@ owned_indices ( ) { -let -index32 -= -index -as -u32 -; self . tracker_assert_in_bounds @@ -3999,13 +4296,24 @@ index ; unsafe { -insert_or_barrier_update -( -texture_data_from_texture +let +texture_selector += +& +scope +. +metadata +. +get_resource_unchecked ( -storage -index32 +index ) +. +full_range +; +insert_or_barrier_update +( +texture_selector Some ( & @@ -4024,7 +4332,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -4143,7 +4450,7 @@ to Self : : -drain +drain_transitions ] is needed @@ -4275,20 +4582,6 @@ set_and_remove_from_usage_scope_sparse & mut self -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> scope : & @@ -4340,17 +4633,20 @@ incoming_size ) ; } -for -& +let +textures += +bind_group_state +. +textures +. +lock ( -id -_ -_ -_ ) +; +for +t in -bind_group_state -. textures . iter @@ -4358,24 +4654,25 @@ iter ) { let +index += +t +. +texture +. +as_info ( -index32 -_ -_ ) -= -id . -0 +id +( +) . unzip ( ) -; -let -index -= -index32 +. +0 as usize ; @@ -4404,22 +4701,20 @@ continue ; } let -texture_data +texture_selector = -unsafe -{ -texture_data_from_texture -( -storage -index32 -) -} +& +t +. +texture +. +full_range ; unsafe { insert_or_barrier_update ( -texture_data +texture_selector Some ( & @@ -4438,7 +4733,6 @@ mut self . metadata -index32 index TextureStateProvider : @@ -4547,233 +4841,22 @@ mut self id : -Valid -< TextureId -> ) - > bool { let -( -index32 -epoch -_ -) +index = id . -0 -. unzip ( ) -; -let -index -= -index32 -as -usize -; -if -index -> -self -. -metadata -. -size -( -) -{ -return -false -; -} -self -. -tracker_assert_in_bounds -( -index -) -; -unsafe -{ -if -self -. -metadata -. -contains_unchecked -( -index -) -{ -let -existing_epoch -= -self -. -metadata -. -get_epoch_unchecked -( -index -) -; -assert_eq -! -( -existing_epoch -epoch -) -; -self -. -start_set -. -complex -. -remove -( -& -index32 -) -; -self -. -end_set -. -complex -. -remove -( -& -index32 -) -; -self -. -metadata -. -remove -( -index -) -; -return -true -; -} -} -false -} -/ -/ -/ -Removes -the -given -resource -from -the -tracker -iff -we -have -the -last -reference -to -the -/ -/ -/ -resource -and -the -epoch -matches -. -/ -/ -/ -/ -/ -/ -Returns -true -if -the -resource -was -removed -. -/ -/ -/ -/ -/ -/ -If -the -ID -is -higher -than -the -length -of -internal -vectors -/ -/ -/ -false -will -be -returned -. -pub -fn -remove_abandoned -( -& -mut -self -id -: -Valid -< -TextureId -> -) -- -> -bool -{ -let -( -index32 -epoch -_ -) -= -id . 0 -. -unzip -( -) -; -let -index -= -index32 as usize ; @@ -4787,69 +4870,29 @@ metadata size ( ) -{ -return -false -; -} -self -. -tracker_assert_in_bounds -( -index -) -; -unsafe -{ -if -self -. -metadata -. -contains_unchecked -( -index -) -{ -let -existing_epoch -= -self -. -metadata -. -get_epoch_unchecked -( -index -) +{ +return +false ; -let -existing_ref_count -= +} self . -metadata -. -get_ref_count_unchecked +tracker_assert_in_bounds ( index ) ; +unsafe +{ if -existing_epoch -= -= -epoch -& -& -existing_ref_count +self +. +metadata . -load +contains_unchecked ( +index ) -= -= -1 { self . @@ -4860,7 +4903,7 @@ complex remove ( & -index32 +index ) ; self @@ -4872,7 +4915,7 @@ complex remove ( & -index32 +index ) ; self @@ -4889,7 +4932,6 @@ true ; } } -} false } } @@ -5253,7 +5295,7 @@ Panics / Panics if -texture_data +texture_selector is None and @@ -5307,20 +5349,13 @@ fn get_state ( self -texture_data +texture_selector : Option < -( -& -LifeGuard & TextureSelector -) > -index32 -: -u32 index : usize @@ -5430,13 +5465,11 @@ here . if * -texture_data +texture_selector . unwrap ( ) -. -1 = = selector @@ -5522,7 +5555,7 @@ complex get ( & -index32 +index ) . unwrap_unchecked @@ -5565,96 +5598,6 @@ new_state / / / -Helper -function -that -gets -what -is -needed -from -the -texture -storage -/ -/ -/ -out -of -the -texture -storage -. -# -[ -inline -( -always -) -] -unsafe -fn -texture_data_from_texture -< -A -: -HalApi -> -( -storage -: -& -storage -: -: -Storage -< -Texture -< -A -> -TextureId -> -index32 -: -u32 -) -- -> -( -& -LifeGuard -& -TextureSelector -) -{ -let -texture -= -unsafe -{ -storage -. -get_unchecked -( -index32 -) -} -; -( -& -texture -. -life_guard -& -texture -. -full_range -) -} -/ -/ -/ Does an insertion @@ -5756,14 +5699,10 @@ A HalApi > ( -texture_data +texture_selector : -( -& -LifeGuard & TextureSelector -) current_state_set : & @@ -5776,10 +5715,12 @@ mut ResourceMetadata < A +TextureId +Texture +< +A +> > -index32 -: -u32 index : usize @@ -5797,6 +5738,11 @@ ResourceMetadataProvider ' _ A +TextureId +Texture +< +A +> > ) - @@ -5831,12 +5777,11 @@ insert ( Some ( -texture_data +texture_selector ) None current_state_set resource_metadata -index32 index state_provider None @@ -5856,9 +5801,8 @@ unsafe { merge ( -texture_data +texture_selector current_state_set -index32 index state_provider metadata_provider @@ -6028,14 +5972,10 @@ A HalApi > ( -texture_data +texture_selector : -( -& -LifeGuard & TextureSelector -) start_state : Option @@ -6056,10 +5996,12 @@ mut ResourceMetadata < A +TextureId +Texture +< +A +> > -index32 -: -u32 index : usize @@ -6087,6 +6029,11 @@ ResourceMetadataProvider ' _ A +TextureId +Texture +< +A +> > barriers : @@ -6124,12 +6071,11 @@ insert ( Some ( -texture_data +texture_selector ) start_state current_state_set resource_metadata -index32 index start_state_provider end_state_provider @@ -6160,9 +6106,8 @@ unsafe { barrier ( -texture_data +texture_selector current_state_set -index32 index start_state_provider barriers @@ -6182,10 +6127,9 @@ unsafe { update ( -texture_data +texture_selector start_state_set current_state_set -index32 index update_state_provider ) @@ -6208,16 +6152,12 @@ A HalApi > ( -texture_data +texture_selector : Option < -( -& -LifeGuard & TextureSelector -) > start_state : @@ -6239,10 +6179,12 @@ mut ResourceMetadata < A +TextureId +Texture +< +A +> > -index32 -: -u32 index : usize @@ -6270,6 +6212,11 @@ ResourceMetadataProvider ' _ A +TextureId +Texture +< +A +> > ) { @@ -6282,8 +6229,7 @@ start_state_provider . get_state ( -texture_data -index32 +texture_selector index ) } @@ -6351,7 +6297,7 @@ trace \ ttex { -index32 +index } : insert @@ -6445,14 +6391,12 @@ state_iter let full_range = -texture_data +texture_selector . unwrap ( ) . -1 -. clone ( ) @@ -6482,7 +6426,7 @@ trace \ ttex { -index32 +index } : insert @@ -6528,7 +6472,7 @@ complex . insert ( -index32 +index complex . clone @@ -6587,7 +6531,7 @@ complex . insert ( -index32 +index complex ) ; @@ -6610,8 +6554,7 @@ end_state_provider . get_state ( -texture_data -index32 +texture_selector index ) } @@ -6676,7 +6619,7 @@ trace \ ttex { -index32 +index } : insert @@ -6741,14 +6684,12 @@ state_iter let full_range = -texture_data +texture_selector . unwrap ( ) . -1 -. clone ( ) @@ -6778,7 +6719,7 @@ trace \ ttex { -index32 +index } : insert @@ -6838,7 +6779,7 @@ complex . insert ( -index32 +index complex ) ; @@ -6848,27 +6789,12 @@ complex unsafe { let -( -epoch -ref_count -) +resource = metadata_provider . get_own ( -texture_data -. -map -( -| -( -life_guard -_ -) -| -life_guard -) index ) ; @@ -6877,8 +6803,7 @@ resource_metadata insert ( index -epoch -ref_count +resource ) ; } @@ -6899,22 +6824,15 @@ A HalApi > ( -texture_data +texture_selector : -( -& -LifeGuard & TextureSelector -) current_state_set : & mut TextureStateSet -index32 -: -u32 index : usize @@ -6932,6 +6850,11 @@ ResourceMetadataProvider ' _ A +TextureId +Texture +< +A +> > ) - @@ -6985,7 +6908,7 @@ complex get_mut ( & -index32 +index ) . unwrap_unchecked @@ -7016,9 +6939,8 @@ get_state ( Some ( -texture_data +texture_selector ) -index32 index ) } @@ -7066,7 +6988,7 @@ trace \ ttex { -index32 +index } : merge @@ -7104,7 +7026,9 @@ TextureId : zip ( -index32 +index +as +_ unsafe { metadata_provider @@ -7119,9 +7043,7 @@ A : VARIANT ) -texture_data -. -1 +texture_selector . clone ( @@ -7209,9 +7131,7 @@ ComplexTextureState : from_selector_state_iter ( -texture_data -. -1 +texture_selector . clone ( @@ -7222,9 +7142,7 @@ iter once ( ( -texture_data -. -1 +texture_selector . clone ( @@ -7262,7 +7180,7 @@ trace \ ttex { -index32 +index } : merge @@ -7304,7 +7222,9 @@ TextureId : zip ( -index32 +index +as +_ unsafe { metadata_provider @@ -7406,7 +7326,7 @@ complex . insert ( -index32 +index new_complex ) ; @@ -7520,7 +7440,7 @@ trace \ ttex { -index32 +index } : merge @@ -7568,7 +7488,9 @@ TextureId : zip ( -index32 +index +as +_ unsafe { metadata_provider @@ -7767,7 +7689,7 @@ trace \ ttex { -index32 +index } : merge @@ -7815,7 +7737,9 @@ TextureId : zip ( -index32 +index +as +_ unsafe { metadata_provider @@ -7888,21 +7812,14 @@ unsafe fn barrier ( -texture_data +texture_selector : -( -& -LifeGuard & TextureSelector -) current_state_set : & TextureStateSet -index32 -: -u32 index : usize @@ -7968,7 +7885,7 @@ complex get ( & -index32 +index ) . unwrap_unchecked @@ -7999,9 +7916,8 @@ get_state ( Some ( -texture_data +texture_selector ) -index32 index ) } @@ -8051,7 +7967,7 @@ trace \ ttex { -index32 +index } : transition @@ -8079,12 +7995,12 @@ PendingTransition { id : -index32 +index +as +_ selector : -texture_data -. -1 +texture_selector . clone ( @@ -8158,7 +8074,7 @@ trace \ ttex { -index32 +index } : transition @@ -8190,7 +8106,9 @@ PendingTransition { id : -index32 +index +as +_ selector usage : @@ -8293,7 +8211,7 @@ trace \ ttex { -index32 +index } : transition @@ -8331,7 +8249,9 @@ PendingTransition { id : -index32 +index +as +_ selector : TextureSelector @@ -8492,7 +8412,7 @@ trace \ ttex { -index32 +index } : transition @@ -8530,7 +8450,9 @@ PendingTransition { id : -index32 +index +as +_ selector : TextureSelector @@ -8595,14 +8517,10 @@ unsafe fn update ( -texture_data +texture_selector : -( -& -LifeGuard & TextureSelector -) start_state_set : & @@ -8613,9 +8531,6 @@ current_state_set & mut TextureStateSet -index32 -: -u32 index : usize @@ -8709,7 +8624,7 @@ complex get_mut ( & -index32 +index ) . unwrap_unchecked @@ -8761,7 +8676,7 @@ complex get_mut ( & -index32 +index ) . unwrap_unchecked @@ -8792,9 +8707,8 @@ get_state ( Some ( -texture_data +texture_selector ) -index32 index ) } @@ -8900,9 +8814,7 @@ ComplexTextureState : from_selector_state_iter ( -texture_data -. -1 +texture_selector . clone ( @@ -8913,9 +8825,7 @@ iter once ( ( -texture_data -. -1 +texture_selector . clone ( @@ -9030,7 +8940,7 @@ complex . insert ( -index32 +index new_complex ) ; @@ -9225,7 +9135,7 @@ complex remove ( & -index32 +index ) . unwrap_unchecked diff --git a/third_party/rust/wgpu-hal/.cargo-checksum.json b/third_party/rust/wgpu-hal/.cargo-checksum.json index 88c438cba8c60..89fdffb6d2df6 100644 --- a/third_party/rust/wgpu-hal/.cargo-checksum.json +++ b/third_party/rust/wgpu-hal/.cargo-checksum.json @@ -51,7 +51,7 @@ rs " : " -216efbf93177cc633b5a7e598a0570df760a41bab01c29b42e1cee4a863a9a5e +360828f6f103ce966a152ceaff50087b59d0eac580fac12c8f89850024ccc233 " " examples @@ -92,7 +92,7 @@ rs " : " -d2b853152d8d84591f8ebef8b3739e506e370d8fef4582e00b31128784c0395c +33f536693b08a9f00b0358416be8f368894bf92a2e673b16622fa9c244854c91 " " src @@ -137,7 +137,7 @@ rs " : " -b66a77645ede6b32d709cef23ba258323f59d4f996dc72edbdae27d930795fbe +65c758d6583c2fdac0b3d48d1a0a2a414ff913efc4f3913a38bd660819c3a2e2 " " src @@ -247,7 +247,7 @@ rs " : " -96ccd8d6645839f3daf832ddf569676643ac92d1b332ab9a0c8563b3b5026295 +4ee1880b0d48ed054654e936c76b3e7b7e370fbf79c2f0af370f8de350fd94ff " " src @@ -273,7 +273,7 @@ rs " : " -4fb09475fb24bc45fb7a464a7c6a30b45e10fed0022aad2891a390b512c11ae1 +1b4c3575fd8fd30d07a61ce68ec3c930305c4df5aa5dcf54dd1fdd4edff590d4 " " src @@ -286,7 +286,7 @@ rs " : " -4023922673cbfde7fbb4a8c7620607ff317b8f0075567e5b9c6a11a081eb8aab +1f2e7f04801b4e65aa27183bc0ddeee0dd3aa686bac4056649dbd97ddef142e1 " " src @@ -299,7 +299,7 @@ rs " : " -28868258dae69a70b111a21c4b6ae3b6c4dbb7e0470737ccff0a15b75b466e9a +03763cc928b38a4153ab91d7a6ab7d38e2f64c7590f2e17a29c56e0a93b1284f " " src @@ -351,7 +351,7 @@ rs " : " -f015f59682768b24474cd1736d9461e65e0a2c932976ff4c502e2f1bdaae86cd +0ac995a92acd8cbe160f58f7347ed50ce5c0d16a3da496127aff66eecca765e7 " " src @@ -364,7 +364,7 @@ rs " : " -493a1e93474d72a4d3bea8701d9195a478fe36ce2ad4a881f65b15db8f8f7f6d +719125a6adb69f16df1a0069c8a1ccb5792169a00abdf2e38cc26b633b15768a " " src @@ -377,7 +377,7 @@ rs " : " -d0c547838442d34e6a04e695b299be0b81c96675a81e5539df0e0dc941310284 +9c5c3babcdfc0daa81ba85a2729020e102e5bcc7c2ec35d3d228ccf477775edf " " src @@ -440,7 +440,7 @@ rs " : " -4a47b337ed93a076613c379b001f12d276da6423af6cd0df1e344c52886cef86 +8288689e0016c60e58d1c3e24fe3a9ef247bb23961c9f01482a0bf21870379a0 " " src @@ -453,7 +453,7 @@ rs " : " -676d3c7d80b1fff7225863a8ddee8f041fef9aaa8fb3bef95455ceea1c2714f6 +6e38936a7a3f01f9aa13b6568e495499b320d009f33146cf978cf57bcd795013 " " src @@ -492,7 +492,7 @@ rs " : " -bf5b3a6eeff4ec56d25783d92c0ccd50a06f5142ead3ae209e50a5f81fedd26e +8e13133b398f25850e342777edd06076188644a1013004b2a08e00845d62e6a6 " " src @@ -505,7 +505,7 @@ rs " : " -99df0b03679e0725481093a520870fbdfb45e00359a1820e8aa40a255be4d92d +89212bdacbb9dc43eebcc7b74fb612a69d35ffc1dfe2b626820c44c61256c4c9 " " src @@ -531,7 +531,7 @@ rs " : " -c7de1063f8d0775c84e5ea578020e01c8b385b84f37e1a9bada299105ca5e82c +43b3e9d03f9eca064832dd307e4b8b8f1d2d3bbcdad21c87af3854f9bd479e3d " " src @@ -544,7 +544,7 @@ rs " : " -999652c9b1305a9792933989b29792c685a0130d6cc3da491ad8bd37b57b0f85 +b6c675d5f76309650779ccf0d35ca32e322020d7199de09586d040b58ad719b0 " " src @@ -617,7 +617,7 @@ rs " : " -8c1758a3eac121acc56368d9b7a50b6c9e800010d676be38b30fd1aa77cea2e2 +5623c8c78584c5e9182502e0997bd11e627e67ccd23d516e65526f415215de2f " " src @@ -630,7 +630,7 @@ rs " : " -b7272b616f39b7eb743501fadc974a60893dacbb63df92da876abe446981e01c +ec1c958acc903af43c29e60059c2c71257b5735312c15679647daed774ad01a1 " " src @@ -641,7 +641,7 @@ rs " : " -66736c592e1fef7c25e2b5be19e5e04cbf391ab1609eea3a8c4415bf5dc4ad38 +04b61b4d07fc001fd3c2d95d7577bc485e7ac67406e7052681222d32233cc0ae " " src @@ -706,7 +706,7 @@ rs " : " -ab7a2570144fae14203a8126d7cdcb9df576c046d0fd2b83514246574ab124b1 +3c49207a7cc88b75785aa4886147121192d19d01cdc621319aff36b3659fa98c " " src @@ -719,7 +719,7 @@ rs " : " -f4b3f8364ec32a7540f7a1da3b4b7e8c6c1cf336aa5535a4515b4efb5b11c443 +01539fa9f22c26fdcca5ee915ca97cf76cecc7fae237347dfc9a813ae13e98cd " " src @@ -745,7 +745,7 @@ rs " : " -939a24ec9b3b03c874c00903755f8b575b35397fde6d28846d18bcb5e5cd9002 +d9af751f16d30b3d129a7481d1f529ef53cc7c6e0ca0b6f25181f8449f23b6fd " " src @@ -784,7 +784,7 @@ rs " : " -fa515d41a30bdbd91c6d7c7f3c6b72538c918f16ff077c45e5702012fd060801 +1557ee3b93a085b1704b858a42a7b3b8c742c20b87ab325e9f0096ec5b97bc59 " " src @@ -797,7 +797,7 @@ rs " : " -d71d9707b01584f423916ecc1784a625f7f2a9c57751cb555a7f40878182d28a +e16d2e849b2ead8d83d354946bbffd03c26e2b024b07fe8b59c3ea47093a0a12 " " src @@ -810,7 +810,7 @@ rs " : " -a0cbaa351d6a41f1ef8db2f7b1c0c4b0051aaa37798ae8ce737eb8009fd879d3 +7ed5c34156d70808e7845575d93a8c2a07bfa989d455c3848e93e8ae372b99ff " } " diff --git a/third_party/rust/wgpu-hal/examples/halmark/main.rs b/third_party/rust/wgpu-hal/examples/halmark/main.rs index 5b6ed87ea1d61..9266b617b8830 100644 --- a/third_party/rust/wgpu-hal/examples/halmark/main.rs +++ b/third_party/rust/wgpu-hal/examples/halmark/main.rs @@ -698,7 +698,6 @@ instance_desc } ; let -mut surface = { @@ -858,7 +857,6 @@ hal OpenDevice { device -mut queue } = @@ -4780,7 +4778,6 @@ queue present ( & -mut self . surface @@ -4817,7 +4814,7 @@ do_fence log : : -info +debug ! ( " diff --git a/third_party/rust/wgpu-hal/examples/raw-gles.rs b/third_party/rust/wgpu-hal/examples/raw-gles.rs index aed9f386026f1..627bf1eb287df 100644 --- a/third_party/rust/wgpu-hal/examples/raw-gles.rs +++ b/third_party/rust/wgpu-hal/examples/raw-gles.rs @@ -974,7 +974,6 @@ _ } ; let -mut od = unsafe diff --git a/third_party/rust/wgpu-hal/src/auxil/dxgi/factory.rs b/third_party/rust/wgpu-hal/src/auxil/dxgi/factory.rs index 251b2368e4518..0f7d1c55123b3 100644 --- a/third_party/rust/wgpu-hal/src/auxil/dxgi/factory.rs +++ b/third_party/rust/wgpu-hal/src/auxil/dxgi/factory.rs @@ -104,6 +104,221 @@ desc ; / / +The +Intel +Haswell +family +of +iGPUs +had +support +for +the +D3D12 +API +but +it +was +later +/ +/ +removed +due +to +a +security +vulnerability +. +/ +/ +/ +/ +We +are +explicitly +filtering +out +all +the +devices +in +the +family +because +we +are +now +/ +/ +getting +reports +of +device +loss +at +a +later +time +than +at +device +creation +time +( +D3D12CreateDevice +) +. +/ +/ +/ +/ +See +https +: +/ +/ +www +. +intel +. +com +/ +content +/ +www +/ +us +/ +en +/ +support +/ +articles +/ +000057520 +/ +graphics +. +html +/ +/ +This +list +of +device +IDs +is +from +https +: +/ +/ +dgpu +- +docs +. +intel +. +com +/ +devices +/ +hardware +- +table +. +html +let +haswell_device_ids += +[ +0x0422 +0x0426 +0x042A +0x042B +0x042E +0x0C22 +0x0C26 +0x0C2A +0x0C2B +0x0C2E +0x0A22 +0x0A2A +0x0A2B +0x0D2A +0x0D2B +0x0D2E +0x0A26 +0x0A2E +0x0D22 +0x0D26 +0x0412 +0x0416 +0x0D12 +0x041A +0x041B +0x0C12 +0x0C16 +0x0C1A +0x0C1B +0x0C1E +0x0A12 +0x0A1A +0x0A1B +0x0D16 +0x0D1A +0x0D1B +0x0D1E +0x041E +0x0A16 +0x0A1E +0x0402 +0x0406 +0x040A +0x040B +0x040E +0x0C02 +0x0C06 +0x0C0A +0x0C0B +0x0C0E +0x0A02 +0x0A06 +0x0A0A +0x0A0B +0x0A0E +0x0D02 +0x0D06 +0x0D0A +0x0D0B +0x0D0E +] +; +if +desc +. +VendorId += += +0x8086 +& +& +haswell_device_ids +. +contains +( +& +desc +. +DeviceId +) +{ +return +false +; +} +/ +/ If run completely @@ -635,7 +850,7 @@ err log : : -info +warn ! ( " @@ -717,7 +932,7 @@ err log : : -info +warn ! ( " @@ -1227,7 +1442,7 @@ t print it to -info +warn as all win7 @@ -1246,7 +1461,7 @@ err log : : -info +warn ! ( " @@ -1419,7 +1634,7 @@ t print it to -info +warn . Err ( @@ -1431,7 +1646,7 @@ err log : : -info +warn ! ( " @@ -1750,7 +1965,7 @@ t print it to -info +warn . Err ( @@ -1762,7 +1977,7 @@ err log : : -info +warn ! ( " diff --git a/third_party/rust/wgpu-hal/src/dx11/device.rs b/third_party/rust/wgpu-hal/src/dx11/device.rs index a83f3c362a3c5..d4f5fc2df2d55 100644 --- a/third_party/rust/wgpu-hal/src/dx11/device.rs +++ b/third_party/rust/wgpu-hal/src/dx11/device.rs @@ -1057,7 +1057,6 @@ fn submit ( & -mut self command_buffers : @@ -1109,12 +1108,10 @@ fn present ( & -mut self surface : & -mut super : : diff --git a/third_party/rust/wgpu-hal/src/dx11/library.rs b/third_party/rust/wgpu-hal/src/dx11/library.rs index 2aa6ee75c4386..50d26feaf42bd 100644 --- a/third_party/rust/wgpu-hal/src/dx11/library.rs +++ b/third_party/rust/wgpu-hal/src/dx11/library.rs @@ -708,7 +708,7 @@ hr log : : -info +warn ! ( " @@ -790,7 +790,7 @@ hr log : : -info +warn ! ( " diff --git a/third_party/rust/wgpu-hal/src/dx11/mod.rs b/third_party/rust/wgpu-hal/src/dx11/mod.rs index 7e92c3ac135ce..6e0239b921fd8 100644 --- a/third_party/rust/wgpu-hal/src/dx11/mod.rs +++ b/third_party/rust/wgpu-hal/src/dx11/mod.rs @@ -491,11 +491,25 @@ struct ShaderModule { } +# +[ +derive +( +Debug +) +] pub struct RenderPipeline { } +# +[ +derive +( +Debug +) +] pub struct ComputePipeline @@ -517,7 +531,6 @@ fn configure ( & -mut self device : @@ -553,7 +566,6 @@ fn unconfigure ( & -mut self device : @@ -571,7 +583,6 @@ fn acquire_texture ( & -mut self _timeout : @@ -616,7 +627,6 @@ fn discard_texture ( & -mut self texture : diff --git a/third_party/rust/wgpu-hal/src/dx12/adapter.rs b/third_party/rust/wgpu-hal/src/dx12/adapter.rs index 0186d73278a0a..9054c5158152a 100644 --- a/third_party/rust/wgpu-hal/src/dx12/adapter.rs +++ b/third_party/rust/wgpu-hal/src/dx12/adapter.rs @@ -28,6 +28,12 @@ SurfaceTarget } ; use +parking_lot +: +: +Mutex +; +use std : : @@ -2685,12 +2691,18 @@ raw queue temp_lists : +Mutex +: +: +new +( Vec : : new ( ) +) } } ) diff --git a/third_party/rust/wgpu-hal/src/dx12/device.rs b/third_party/rust/wgpu-hal/src/dx12/device.rs index 98e6926481417..c72aa90388af3 100644 --- a/third_party/rust/wgpu-hal/src/dx12/device.rs +++ b/third_party/rust/wgpu-hal/src/dx12/device.rs @@ -1171,7 +1171,7 @@ cur_value log : : -info +debug ! ( " diff --git a/third_party/rust/wgpu-hal/src/dx12/instance.rs b/third_party/rust/wgpu-hal/src/dx12/instance.rs index a04e3a5737648..73ebe65aacef4 100644 --- a/third_party/rust/wgpu-hal/src/dx12/instance.rs +++ b/third_party/rust/wgpu-hal/src/dx12/instance.rs @@ -1,4 +1,10 @@ use +parking_lot +: +: +RwLock +; +use winapi : : @@ -414,7 +420,7 @@ err log : : -info +warn ! ( " @@ -851,7 +857,13 @@ self supports_allow_tearing swap_chain : +RwLock +: +: +new +( None +) } ) _ diff --git a/third_party/rust/wgpu-hal/src/dx12/mod.rs b/third_party/rust/wgpu-hal/src/dx12/mod.rs index b9f63e7e0f954..c55d68d3b6c6f 100644 --- a/third_party/rust/wgpu-hal/src/dx12/mod.rs +++ b/third_party/rust/wgpu-hal/src/dx12/mod.rs @@ -270,7 +270,10 @@ use parking_lot : : +{ Mutex +RwLock +} ; use std @@ -611,7 +614,13 @@ self supports_allow_tearing swap_chain : +RwLock +: +: +new +( None +) } } pub @@ -668,7 +677,13 @@ self supports_allow_tearing swap_chain : +RwLock +: +: +new +( None +) } } pub @@ -739,7 +754,13 @@ self supports_allow_tearing swap_chain : +RwLock +: +: +new +( None +) } } } @@ -904,10 +925,13 @@ supports_allow_tearing bool swap_chain : +RwLock +< Option < SwapChain > +> } unsafe impl @@ -1380,6 +1404,8 @@ d3d12 CommandQueue temp_lists : +Mutex +< Vec < d3d12 @@ -1387,6 +1413,7 @@ d3d12 : CommandList > +> } unsafe impl @@ -2634,6 +2661,7 @@ s [ derive ( +Debug Clone Copy ) @@ -2745,6 +2773,13 @@ RootIndex = u32 ; +# +[ +derive +( +Debug +) +] struct BindGroupInfo { @@ -2765,6 +2800,7 @@ BufferViewKind [ derive ( +Debug Clone ) ] @@ -2791,6 +2827,7 @@ u32 [ derive ( +Debug Clone ) ] @@ -2833,6 +2870,13 @@ for PipelineLayoutShared { } +# +[ +derive +( +Debug +) +] pub struct PipelineLayout @@ -3019,6 +3063,13 @@ self { } } +# +[ +derive +( +Debug +) +] pub struct RenderPipeline @@ -3066,6 +3117,13 @@ for RenderPipeline { } +# +[ +derive +( +Debug +) +] pub struct ComputePipeline @@ -3289,7 +3347,6 @@ fn configure ( & -mut self device : @@ -3465,6 +3522,10 @@ self . swap_chain . +write +( +) +. take ( ) @@ -4382,9 +4443,20 @@ resource ) ; } +let +mut +swapchain += self . swap_chain +. +write +( +) +; +* +swapchain = Some ( @@ -4427,7 +4499,6 @@ fn unconfigure ( & -mut self device : @@ -4446,6 +4517,10 @@ self . swap_chain . +write +( +) +. take ( ) @@ -4545,7 +4620,6 @@ fn acquire_texture ( & -mut self timeout : @@ -4581,12 +4655,22 @@ SurfaceError > { let -sc +mut +swapchain = self . swap_chain . +write +( +) +; +let +sc += +swapchain +. as_mut ( ) @@ -4717,7 +4801,6 @@ fn discard_texture ( & -mut self _texture : @@ -4725,12 +4808,22 @@ Texture ) { let -sc +mut +swapchain = self . swap_chain . +write +( +) +; +let +sc += +swapchain +. as_mut ( ) @@ -4764,7 +4857,6 @@ fn submit ( & -mut self command_buffers : @@ -4800,10 +4892,20 @@ crate DeviceError > { +let +mut +temp_lists += self . temp_lists . +lock +( +) +; +temp_lists +. clear ( ) @@ -4813,8 +4915,6 @@ cmd_buf in command_buffers { -self -. temp_lists . push @@ -4851,8 +4951,6 @@ raw execute_command_lists ( & -self -. temp_lists ) ; @@ -4964,12 +5062,10 @@ fn present ( & -mut self surface : & -mut Surface _texture : @@ -4988,12 +5084,22 @@ SurfaceError > { let -sc +mut +swapchain = surface . swap_chain . +write +( +) +; +let +sc += +swapchain +. as_mut ( ) diff --git a/third_party/rust/wgpu-hal/src/empty.rs b/third_party/rust/wgpu-hal/src/empty.rs index d9a06330fcad4..6c2ef7cc3b872 100644 --- a/third_party/rust/wgpu-hal/src/empty.rs +++ b/third_party/rust/wgpu-hal/src/empty.rs @@ -307,7 +307,6 @@ fn configure ( & -mut self device : @@ -344,7 +343,6 @@ fn unconfigure ( & -mut self device : @@ -358,7 +356,6 @@ fn acquire_texture ( & -mut self timeout : @@ -403,7 +400,6 @@ fn discard_texture ( & -mut self texture : @@ -559,7 +555,6 @@ fn submit ( & -mut self command_buffers : @@ -602,12 +597,10 @@ fn present ( & -mut self surface : & -mut Context texture : diff --git a/third_party/rust/wgpu-hal/src/gles/adapter.rs b/third_party/rust/wgpu-hal/src/gles/adapter.rs index 74de8370c3f7c..22704cddf6174 100644 --- a/third_party/rust/wgpu-hal/src/gles/adapter.rs +++ b/third_party/rust/wgpu-hal/src/gles/adapter.rs @@ -5,13 +5,25 @@ glow HasContext ; use +parking_lot +: +: +Mutex +; +use std : : sync : : +{ +atomic +: +: +AtomicU8 Arc +} ; use wgt @@ -1771,7 +1783,7 @@ VERSION log : : -trace +debug ! ( " @@ -1786,7 +1798,7 @@ vendor log : : -trace +debug ! ( " @@ -1801,7 +1813,7 @@ renderer log : : -trace +debug ! ( " @@ -2131,7 +2143,7 @@ SHADING_LANGUAGE_VERSION log : : -trace +debug ! ( " @@ -2305,7 +2317,7 @@ wasm32 log : : -trace +debug ! ( " @@ -6572,18 +6584,36 @@ shader_clear_program_color_uniform_location zero_buffer temp_query_results : +Mutex +: +: +new +( Vec : : new ( ) +) draw_buffer_count : +AtomicU8 +: +: +new +( 1 +) current_index_buffer : +Mutex +: +: +new +( None +) } } ) diff --git a/third_party/rust/wgpu-hal/src/gles/device.rs b/third_party/rust/wgpu-hal/src/gles/device.rs index 591062a9184fd..27d79e283e631 100644 --- a/third_party/rust/wgpu-hal/src/gles/device.rs +++ b/third_party/rust/wgpu-hal/src/gles/device.rs @@ -1377,7 +1377,7 @@ raw log : : -info +debug ! ( " @@ -2879,7 +2879,7 @@ shader log : : -info +debug ! ( " @@ -9935,12 +9935,16 @@ u64 ) } ; +if let +Some +( & ( _ sync ) +) = fence . @@ -9965,11 +9969,8 @@ value = wait_value ) -. -unwrap -( -) -; +{ +return match unsafe { @@ -10073,15 +10074,14 @@ DeviceError Lost ) } +; +} } -else -{ Ok ( true ) } -} unsafe fn start_capture diff --git a/third_party/rust/wgpu-hal/src/gles/egl.rs b/third_party/rust/wgpu-hal/src/gles/egl.rs index 0b3eec8e5062d..598ce727ab46f 100644 --- a/third_party/rust/wgpu-hal/src/gles/egl.rs +++ b/third_party/rust/wgpu-hal/src/gles/egl.rs @@ -11,6 +11,7 @@ parking_lot { Mutex MutexGuard +RwLock } ; use @@ -1049,7 +1050,7 @@ DisplayOwner log : : -info +debug ! ( " @@ -1258,7 +1259,7 @@ available log : : -info +debug ! ( " @@ -1652,7 +1653,7 @@ tier_max log : : -info +debug ! ( " @@ -3231,7 +3232,7 @@ to_string_lossy log : : -info +debug ! ( " @@ -3301,7 +3302,7 @@ version log : : -info +debug ! ( " @@ -3333,7 +3334,7 @@ EGL_KHR_gl_colorspace log : : -info +debug ! ( " @@ -3758,7 +3759,7 @@ version log : : -info +debug ! ( " @@ -3801,7 +3802,7 @@ supports_khr_context log : : -info +debug ! ( " @@ -3826,7 +3827,7 @@ else log : : -info +debug ! ( " @@ -3913,7 +3914,7 @@ EGL_ANGLE_ log : : -info +debug ! ( " @@ -3964,7 +3965,7 @@ EGL_EXT_create_context_robustness log : : -info +debug ! ( " @@ -4204,7 +4205,7 @@ emscripten log : : -info +debug ! ( " @@ -5438,7 +5439,7 @@ EGL_MESA_platform_surfaceless log : : -info +warn ! ( " @@ -5520,7 +5521,7 @@ else log : : -info +warn ! ( " @@ -5593,7 +5594,7 @@ EGL_KHR_debug log : : -info +debug ! ( " @@ -6375,7 +6376,13 @@ raw_window_handle window_handle swapchain : +RwLock +: +: +new +( None +) srgb_kind : inner @@ -6514,7 +6521,7 @@ supports_debug log : : -info +debug ! ( " @@ -6566,7 +6573,7 @@ supports_debug log : : -info +debug ! ( " @@ -6984,10 +6991,13 @@ raw_window_handle RawWindowHandle swapchain : +RwLock +< Option < Swapchain > +> srgb_kind : SrgbFrameBufferKind @@ -7018,7 +7028,6 @@ fn present ( & -mut self _suf_texture : @@ -7056,12 +7065,21 @@ get_without_egl_lock } ; let -sc +swapchain = self . swapchain . +read +( +) +; +let +sc += +swapchain +. as_ref ( ) @@ -7420,7 +7438,6 @@ fn unconfigure_impl ( & -mut self device : @@ -7470,6 +7487,10 @@ self . swapchain . +write +( +) +. take ( ) @@ -7572,7 +7593,6 @@ fn configure ( & -mut self device : @@ -8966,9 +8986,20 @@ None ) } ; +let +mut +swapchain += self . swapchain +. +write +( +) +; +* +swapchain = Some ( @@ -9017,7 +9048,6 @@ fn unconfigure ( & -mut self device : @@ -9145,7 +9175,6 @@ fn acquire_texture ( & -mut self _timeout_ms : @@ -9181,12 +9210,21 @@ SurfaceError > { let -sc +swapchain = self . swapchain . +read +( +) +; +let +sc += +swapchain +. as_ref ( ) @@ -9291,7 +9329,6 @@ fn discard_texture ( & -mut self _texture : diff --git a/third_party/rust/wgpu-hal/src/gles/mod.rs b/third_party/rust/wgpu-hal/src/gles/mod.rs index 24c6a890c6f9e..c36880415e0e9 100644 --- a/third_party/rust/wgpu-hal/src/gles/mod.rs +++ b/third_party/rust/wgpu-hal/src/gles/mod.rs @@ -771,7 +771,10 @@ sync atomic : : +{ AtomicU32 +AtomicU8 +} ; use std @@ -1753,15 +1756,20 @@ glow Buffer temp_query_results : +Mutex +< Vec < u64 > +> draw_buffer_count : -u8 +AtomicU8 current_index_buffer : +Mutex +< Option < glow @@ -1769,6 +1777,7 @@ glow : Buffer > +> } # [ @@ -2525,6 +2534,13 @@ BindGroupLayoutEntry ] > } +# +[ +derive +( +Debug +) +] struct BindGroupLayoutInfo { @@ -2622,6 +2638,13 @@ u8 ] > } +# +[ +derive +( +Debug +) +] pub struct PipelineLayout @@ -3117,6 +3140,13 @@ u8 MAX_TEXTURE_SLOTS ] ; +# +[ +derive +( +Debug +) +] struct PipelineInner { @@ -3299,6 +3329,13 @@ PipelineError > > ; +# +[ +derive +( +Debug +) +] pub struct RenderPipeline @@ -3449,6 +3486,13 @@ for RenderPipeline { } +# +[ +derive +( +Debug +) +] pub struct ComputePipeline @@ -3998,6 +4042,7 @@ default [ derive ( +Debug Clone Default ) diff --git a/third_party/rust/wgpu-hal/src/gles/queue.rs b/third_party/rust/wgpu-hal/src/gles/queue.rs index c042142d88caa..3ab60cf36d87f 100644 --- a/third_party/rust/wgpu-hal/src/gles/queue.rs +++ b/third_party/rust/wgpu-hal/src/gles/queue.rs @@ -35,8 +35,14 @@ slice sync : : +{ +atomic +: +: +Ordering Arc } +} ; const DEBUG_ID @@ -441,10 +447,23 @@ TRIANGLES ) } ; -if +let +draw_buffer_count += self . draw_buffer_count +. +load +( +Ordering +: +: +Relaxed +) +; +if +draw_buffer_count ! = 0 @@ -469,8 +488,6 @@ indices 0 . . -self -. draw_buffer_count as u32 @@ -525,7 +542,6 @@ fn reset_state ( & -mut self gl : @@ -695,9 +711,20 @@ None ) } ; +let +mut +current_index_buffer += self . current_index_buffer +. +lock +( +) +; +* +current_index_buffer = None ; @@ -1013,7 +1040,6 @@ fn process ( & -mut self gl : @@ -2203,9 +2229,14 @@ glow : : ELEMENT_ARRAY_BUFFER +* self . current_index_buffer +. +lock +( +) ) } ; @@ -4587,9 +4618,20 @@ buffer ) } ; +let +mut +current_index_buffer += self . current_index_buffer +. +lock +( +) +; +* +current_index_buffer = Some ( @@ -4878,10 +4920,20 @@ buffer } else { +let +mut +temp_query_results += self . temp_query_results . +lock +( +) +; +temp_query_results +. clear ( ) @@ -4946,8 +4998,6 @@ usize ) } ; -self -. temp_query_results . push @@ -4966,8 +5016,6 @@ slice : from_raw_parts ( -self -. temp_query_results . as_ptr @@ -4977,8 +5025,6 @@ as * const u8 -self -. temp_query_results . len @@ -5540,8 +5586,15 @@ count self . draw_buffer_count -= +. +store +( count +Ordering +: +: +Relaxed +) ; let indices @@ -10030,7 +10083,6 @@ fn submit ( & -mut self command_buffers : @@ -10355,12 +10407,10 @@ fn present ( & -mut self surface : & -mut super : : diff --git a/third_party/rust/wgpu-hal/src/gles/web.rs b/third_party/rust/wgpu-hal/src/gles/web.rs index 078796bd3e574..bf111a83943cc 100644 --- a/third_party/rust/wgpu-hal/src/gles/web.rs +++ b/third_party/rust/wgpu-hal/src/gles/web.rs @@ -8,7 +8,10 @@ use parking_lot : : +{ Mutex +RwLock +} ; use wasm_bindgen @@ -751,13 +754,31 @@ canvas webgl2_context srgb_present_program : +Mutex +: +: +new +( None +) swapchain : +RwLock +: +: +new +( None +) texture : +Mutex +: +: +new +( None +) presentable : true @@ -1322,7 +1343,6 @@ None [ derive ( -Clone Debug ) ] @@ -1345,12 +1365,17 @@ super ) swapchain : +RwLock +< Option < Swapchain > +> texture : +Mutex +< Option < glow @@ -1358,6 +1383,7 @@ glow : Texture > +> pub ( super @@ -1367,6 +1393,8 @@ presentable bool srgb_present_program : +Mutex +< Option < glow @@ -1374,6 +1402,101 @@ glow : Program > +> +} +impl +Clone +for +Surface +{ +fn +clone +( +& +self +) +- +> +Self +{ +Self +{ +canvas +: +self +. +canvas +. +clone +( +) +webgl2_context +: +self +. +webgl2_context +. +clone +( +) +swapchain +: +RwLock +: +: +new +( +self +. +swapchain +. +read +( +) +. +clone +( +) +) +texture +: +Mutex +: +: +new +( +* +self +. +texture +. +lock +( +) +) +presentable +: +self +. +presentable +srgb_present_program +: +Mutex +: +: +new +( +* +self +. +srgb_present_program +. +lock +( +) +) +} +} } # [ @@ -1553,7 +1676,6 @@ fn present ( & -mut self _suf_texture : @@ -1593,6 +1715,15 @@ self . swapchain . +read +( +) +; +let +swapchain += +swapchain +. as_ref ( ) @@ -1722,9 +1853,14 @@ glow : : TEXTURE_2D +* self . texture +. +lock +( +) ) } ; @@ -1734,9 +1870,14 @@ gl . use_program ( +* self . srgb_present_program +. +lock +( +) ) } ; @@ -2241,7 +2382,6 @@ fn configure ( & -mut self device : @@ -2358,6 +2498,19 @@ lock ( ) ; +{ +let +mut +swapchain += +self +. +swapchain +. +write +( +) +; if let Some @@ -2365,8 +2518,6 @@ Some swapchain ) = -self -. swapchain . take @@ -2394,11 +2545,23 @@ framebuffer } ; } -if +} +{ +let +mut +srgb_present_program += self . srgb_present_program . +lock +( +) +; +if +srgb_present_program +. is_none ( ) @@ -2412,8 +2575,7 @@ is_srgb ( ) { -self -. +* srgb_present_program = Some @@ -2431,6 +2593,20 @@ gl ) ; } +} +{ +let +mut +texture += +self +. +texture +. +lock +( +) +; if let Some @@ -2438,8 +2614,6 @@ Some texture ) = -self -. texture . take @@ -2457,8 +2631,7 @@ texture } ; } -self -. +* texture = Some @@ -2533,8 +2706,7 @@ glow : : TEXTURE_2D -self -. +* texture ) } @@ -2699,8 +2871,7 @@ glow : : TEXTURE_2D -self -. +* texture 0 ) @@ -2720,9 +2891,20 @@ None ) } ; +let +mut +swapchain += self . swapchain +. +write +( +) +; +* +swapchain = Some ( @@ -2758,6 +2940,7 @@ framebuffer } ) ; +} Ok ( ( @@ -2769,7 +2952,6 @@ fn unconfigure ( & -mut self device : @@ -2793,6 +2975,19 @@ lock ( ) ; +{ +let +mut +swapchain += +self +. +swapchain +. +write +( +) +; if let Some @@ -2800,8 +2995,6 @@ Some swapchain ) = -self -. swapchain . take @@ -2821,6 +3014,7 @@ framebuffer } ; } +} if let Some @@ -2832,6 +3026,10 @@ self . texture . +lock +( +) +. take ( ) @@ -2853,7 +3051,6 @@ fn acquire_texture ( & -mut self _timeout_ms : @@ -2895,12 +3092,21 @@ SurfaceError > { let -sc +swapchain = self . swapchain . +read +( +) +; +let +sc += +swapchain +. as_ref ( ) @@ -2933,6 +3139,10 @@ self . texture . +lock +( +) +. unwrap ( ) @@ -3015,7 +3225,6 @@ fn discard_texture ( & -mut self _texture : diff --git a/third_party/rust/wgpu-hal/src/gles/wgl.rs b/third_party/rust/wgpu-hal/src/gles/wgl.rs index 4612229efa893..a376c6afe4921 100644 --- a/third_party/rust/wgpu-hal/src/gles/wgl.rs +++ b/third_party/rust/wgpu-hal/src/gles/wgl.rs @@ -35,6 +35,7 @@ parking_lot { Mutex MutexGuard +RwLock } ; use @@ -3268,7 +3269,13 @@ presentable true swapchain : +RwLock +: +: +new +( None +) srgb_capable : self @@ -3457,10 +3464,13 @@ presentable bool swapchain : +RwLock +< Option < Swapchain > +> srgb_capable : bool @@ -3491,7 +3501,6 @@ fn present ( & -mut self _suf_texture : @@ -3517,12 +3526,21 @@ SurfaceError > { let -sc +swapchain = self . swapchain . +read +( +) +; +let +sc += +swapchain +. as_ref ( ) @@ -4020,7 +4038,6 @@ fn configure ( & -mut self device : @@ -4767,8 +4784,12 @@ interval self . swapchain -= -Some +. +write +( +) +. +replace ( Swapchain { @@ -4813,7 +4834,6 @@ fn unconfigure ( & -mut self device : @@ -4849,6 +4869,10 @@ self . swapchain . +write +( +) +. take ( ) @@ -4881,7 +4905,6 @@ fn acquire_texture ( & -mut self _timeout_ms : @@ -4914,12 +4937,21 @@ SurfaceError > { let -sc +swapchain = self . swapchain . +read +( +) +; +let +sc += +swapchain +. as_ref ( ) @@ -5024,7 +5056,6 @@ fn discard_texture ( & -mut self _texture : diff --git a/third_party/rust/wgpu-hal/src/lib.rs b/third_party/rust/wgpu-hal/src/lib.rs index 91a928744b18d..f4f94db9313e6 100644 --- a/third_party/rust/wgpu-hal/src/lib.rs +++ b/third_party/rust/wgpu-hal/src/lib.rs @@ -756,10 +756,7 @@ use wgt : : -{ -WasmNotSend -WasmNotSync -} +WasmNotSendSync ; / / @@ -1583,9 +1580,7 @@ Self type CommandBuffer : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync + fmt : @@ -1600,9 +1595,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync + ' static @@ -1615,9 +1608,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync + ' static @@ -1630,9 +1621,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync + Borrow < @@ -1650,9 +1639,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type Sampler @@ -1662,9 +1649,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type QuerySet @@ -1674,9 +1659,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type Fence @@ -1686,9 +1669,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type BindGroupLayout @@ -1698,9 +1679,7 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type BindGroup @@ -1710,16 +1689,17 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type PipelineLayout : -WasmNotSend +fmt +: +: +Debug + -WasmNotSync +WasmNotSendSync ; type ShaderModule @@ -1729,23 +1709,27 @@ fmt : Debug + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync ; type RenderPipeline : -WasmNotSend +fmt +: +: +Debug + -WasmNotSync +WasmNotSendSync ; type ComputePipeline : -WasmNotSend +fmt +: +: +Debug + -WasmNotSync +WasmNotSendSync ; } pub @@ -1759,9 +1743,7 @@ Api : Sized + -WasmNotSend -+ -WasmNotSync +WasmNotSendSync { unsafe fn @@ -1851,9 +1833,7 @@ A Api > : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync { / / @@ -1955,7 +1935,6 @@ fn configure ( & -mut self device : @@ -2074,7 +2053,6 @@ fn unconfigure ( & -mut self device : @@ -2171,7 +2149,6 @@ fn acquire_texture ( & -mut self timeout : @@ -2205,7 +2182,6 @@ fn discard_texture ( & -mut self texture : @@ -2225,9 +2201,7 @@ A Api > : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync { unsafe fn @@ -2393,9 +2367,7 @@ A Api > : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync { / / @@ -3192,9 +3164,7 @@ A Api > : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync { / / @@ -3264,7 +3234,6 @@ fn submit ( & -mut self command_buffers : @@ -3305,12 +3274,10 @@ fn present ( & -mut self surface : & -mut A : : @@ -3410,9 +3377,7 @@ A Api > : -WasmNotSend -+ -WasmNotSync +WasmNotSendSync + fmt : diff --git a/third_party/rust/wgpu-hal/src/metal/mod.rs b/third_party/rust/wgpu-hal/src/metal/mod.rs index 3067da3494784..9e3a91ce73b70 100644 --- a/third_party/rust/wgpu-hal/src/metal/mod.rs +++ b/third_party/rust/wgpu-hal/src/metal/mod.rs @@ -231,7 +231,10 @@ use parking_lot : : +{ Mutex +RwLock +} ; # [ @@ -1728,6 +1731,8 @@ MetalLayer > swapchain_format : +RwLock +< Option < wgt @@ -1735,12 +1740,16 @@ wgt : TextureFormat > +> extent : +RwLock +< wgt : : Extent3d +> main_thread_id : thread @@ -1868,7 +1877,6 @@ fn submit ( & -mut self command_buffers : @@ -2161,12 +2169,10 @@ fn present ( & -mut self _surface : & -mut Surface texture : @@ -3887,6 +3893,13 @@ sized_bindings ; } } +# +[ +derive +( +Debug +) +] pub struct RenderPipeline @@ -3998,6 +4011,13 @@ for RenderPipeline { } +# +[ +derive +( +Debug +) +] pub struct ComputePipeline diff --git a/third_party/rust/wgpu-hal/src/metal/surface.rs b/third_party/rust/wgpu-hal/src/metal/surface.rs index c1edff531a922..e6de8cfbd59f1 100644 --- a/third_party/rust/wgpu-hal/src/metal/surface.rs +++ b/third_party/rust/wgpu-hal/src/metal/surface.rs @@ -97,7 +97,10 @@ use parking_lot : : +{ Mutex +RwLock +} ; # [ @@ -401,9 +404,20 @@ layer ) swapchain_format : +RwLock +: +: +new +( None +) extent : +RwLock +: +: +new +( wgt : : @@ -413,6 +427,7 @@ Extent3d default ( ) +) main_thread_id : thread @@ -1249,7 +1264,6 @@ fn configure ( & -mut self device : @@ -1281,7 +1295,7 @@ SurfaceError log : : -info +debug ! ( " @@ -1305,9 +1319,14 @@ shared . private_caps ; +* self . swapchain_format +. +write +( +) = Some ( @@ -1316,9 +1335,14 @@ config format ) ; +* self . extent +. +write +( +) = config . @@ -1786,7 +1810,6 @@ fn unconfigure ( & -mut self _device : @@ -1797,9 +1820,14 @@ super Device ) { +* self . swapchain_format +. +write +( +) = None ; @@ -1809,7 +1837,6 @@ fn acquire_texture ( & -mut self _timeout_ms : @@ -1922,6 +1949,32 @@ None } ; let +swapchain_format += +self +. +swapchain_format +. +read +( +) +. +unwrap +( +) +; +let +extent += +self +. +extent +. +read +( +) +; +let suf_texture = super @@ -1941,13 +1994,7 @@ raw texture format : -self -. swapchain_format -. -unwrap -( -) raw_type : metal @@ -1972,15 +2019,11 @@ CopyExtent { width : -self -. extent . width height : -self -. extent . height @@ -2021,7 +2064,6 @@ fn discard_texture ( & -mut self _texture : diff --git a/third_party/rust/wgpu-hal/src/vulkan/adapter.rs b/third_party/rust/wgpu-hal/src/vulkan/adapter.rs index b1758ed619d24..9c60e6c5a7a96 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/adapter.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/adapter.rs @@ -38,8 +38,14 @@ CStr sync : : +{ +atomic +: +: +AtomicIsize Arc } +} ; fn depth_stencil_required_flags @@ -6511,6 +6517,55 @@ VENDOR } ; if +let +Some +( +driver +) += +phd_capabilities +. +driver +{ +if +driver +. +conformance_version +. +major += += +0 +{ +log +: +: +warn +! +( +" +Adapter +is +not +Vulkan +compliant +hiding +adapter +: +{ +} +" +info +. +name +) +; +return +None +; +} +} +if phd_capabilities . device_api_version @@ -8760,7 +8815,14 @@ family_index relay_semaphores relay_index : -None +AtomicIsize +: +: +new +( +- +1 +) } ; let diff --git a/third_party/rust/wgpu-hal/src/vulkan/device.rs b/third_party/rust/wgpu-hal/src/vulkan/device.rs index 486e7a0549d91..605a45009fc46 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/device.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/device.rs @@ -3719,7 +3719,6 @@ self surface : & -mut super : : diff --git a/third_party/rust/wgpu-hal/src/vulkan/instance.rs b/third_party/rust/wgpu-hal/src/vulkan/instance.rs index dbe1ddec4f339..21c07d4bb17bf 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/instance.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/instance.rs @@ -34,6 +34,12 @@ khr vk } ; +use +parking_lot +: +: +RwLock +; unsafe extern " @@ -2158,7 +2164,7 @@ else log : : -info +warn ! ( " @@ -2375,7 +2381,7 @@ InstanceError log : : -info +debug ! ( " @@ -2570,7 +2576,7 @@ name log : : -info +debug ! ( " @@ -3858,7 +3864,13 @@ shared ) swapchain : +RwLock +: +: +new +( None +) } } } @@ -4478,7 +4490,7 @@ e log : : -info +debug ! ( " @@ -6497,7 +6509,6 @@ fn configure ( & -mut self device : @@ -6547,12 +6558,22 @@ in use . let -old +mut +swap_chain = self . swapchain . +write +( +) +; +let +old += +swap_chain +. take ( ) @@ -6594,9 +6615,8 @@ old ? } ; -self -. -swapchain +* +swap_chain = Some ( @@ -6614,7 +6634,6 @@ fn unconfigure ( & -mut self device : @@ -6636,6 +6655,10 @@ self . swapchain . +write +( +) +. take ( ) @@ -6700,7 +6723,6 @@ fn acquire_texture ( & -mut self timeout : @@ -6739,12 +6761,22 @@ SurfaceError > { let -sc +mut +swapchain = self . swapchain . +write +( +) +; +let +sc += +swapchain +. as_mut ( ) @@ -7481,7 +7513,6 @@ fn discard_texture ( & -mut self _texture : diff --git a/third_party/rust/wgpu-hal/src/vulkan/mod.rs b/third_party/rust/wgpu-hal/src/vulkan/mod.rs index 7b36dab6b7f02..35829fff885d8 100644 --- a/third_party/rust/wgpu-hal/src/vulkan/mod.rs +++ b/third_party/rust/wgpu-hal/src/vulkan/mod.rs @@ -188,8 +188,17 @@ NonZeroU32 sync : : +{ +atomic +: +: +{ +AtomicIsize +Ordering +} Arc } +} ; use arrayvec @@ -216,7 +225,10 @@ use parking_lot : : +{ Mutex +RwLock +} ; const MILLIS_TO_NANOS @@ -796,10 +808,13 @@ InstanceShared > swapchain : +RwLock +< Option < Swapchain > +> } # [ @@ -2036,10 +2051,7 @@ Semaphore ] relay_index : -Option -< -usize -> +AtomicIsize } # [ @@ -3266,7 +3278,6 @@ fn submit ( & -mut self command_buffers : @@ -3572,19 +3583,28 @@ TOP_OF_PIPE ] ; let -sem_index +old_index = -match self . relay_index -{ -Some +. +load ( -old_index +Ordering +: +: +Relaxed ) +; +let +sem_index = +if +old_index > += +0 { vk_info = @@ -3598,9 +3618,13 @@ self relay_semaphores [ old_index +as +usize . . old_index +as +usize + 1 ] @@ -3614,6 +3638,8 @@ wait_stage_mask ; ( old_index +as +usize + 1 ) @@ -3626,19 +3652,24 @@ len ( ) } -None -= -> +else +{ 0 } ; self . relay_index -= -Some +. +store ( sem_index +as +isize +Ordering +: +: +Relaxed ) ; signal_semaphores @@ -3743,12 +3774,10 @@ fn present ( & -mut self surface : & -mut Surface texture : @@ -3767,13 +3796,23 @@ SurfaceError > { let -ssc +mut +swapchain = surface . swapchain . -as_ref +write +( +) +; +let +ssc += +swapchain +. +as_mut ( ) . @@ -3825,20 +3864,28 @@ image_indices image_indices ) ; -if let -Some -( old_index -) = self . relay_index . -take +swap ( +- +1 +Ordering +: +: +Relaxed ) +; +if +old_index +> += +0 { vk_info = @@ -3852,9 +3899,13 @@ self relay_semaphores [ old_index +as +usize . . old_index +as +usize + 1 ] diff --git a/third_party/rust/wgpu-types/.cargo-checksum.json b/third_party/rust/wgpu-types/.cargo-checksum.json index 15c68d0f08565..bfbb7b453796c 100644 --- a/third_party/rust/wgpu-types/.cargo-checksum.json +++ b/third_party/rust/wgpu-types/.cargo-checksum.json @@ -51,7 +51,7 @@ rs " : " -4e1ef56078799af2c15ca573a05b5deebbb084b447a5840cd61971afa4c73924 +6c3886f27653eee4359a8d150a6091a7d6e0ff1abab44c9afff2d54a0d0a474b " " src diff --git a/third_party/rust/wgpu-types/src/lib.rs b/third_party/rust/wgpu-types/src/lib.rs index e88ee2aa1e5d5..d0510ed383a5f 100644 --- a/third_party/rust/wgpu-types/src/lib.rs +++ b/third_party/rust/wgpu-types/src/lib.rs @@ -56480,6 +56480,28 @@ hidden mod send_sync { +pub +trait +WasmNotSendSync +: +WasmNotSend ++ +WasmNotSync +{ +} +impl +< +T +: +WasmNotSend ++ +WasmNotSync +> +WasmNotSendSync +for +T +{ +} # [ cfg