diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d99a7254ed..f4ed15c4a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -155,11 +155,7 @@ jobs: # build for Emscripten cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features - # build cube example - cargo clippy --target ${{ matrix.target }} --bin cube - - # build raw-gles example - cargo clippy --target ${{ matrix.target }} --example raw-gles + # Don't check samples since we use winit in our samples which has dropped support for Emscripten. # all features cargo clippy --target ${{ matrix.target }} -p wgpu-hal --all-features diff --git a/CHANGELOG.md b/CHANGELOG.md index 932a5eb4c6..72aa2022c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,8 +40,16 @@ Bottom level categories: ## Unreleased +### Changes + +- Omit texture store bound checks since they are no-ops if out of bounds on all APIs. By @teoxoy in [#3975](https://github.com/gfx-rs/wgpu/pull/3975) + ### Bug Fixes +#### General + +- Derive storage bindings via `naga::StorageAccess` instead of `naga::GlobalUse`. By @teoxoy in [#3985](https://github.com/gfx-rs/wgpu/pull/3985). + #### Vulkan - Fix enabling `wgpu::Features::PARTIALLY_BOUND_BINDING_ARRAY` not being actually enabled in vulkan backend. By @39ali in[#3772](https://github.com/gfx-rs/wgpu/pull/3772). diff --git a/Cargo.lock b/Cargo.lock index 6b43267ec9..8835c76b5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,22 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ab_glyph" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5110f1c78cf582855d895ecd0746b653db010cec6d9f5575293f27934d980a39" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" + [[package]] name = "addr2line" version = "0.20.0" @@ -37,6 +53,30 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-activity" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40bc1575e653f158cbdc6ebcd917b9564e66321c5325c232c3591269c257be69" +dependencies = [ + "android-properties", + "bitflags 1.3.2", + "cc", + "jni-sys", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "num_enum 0.6.1", +] + +[[package]] +name = "android-properties" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -119,7 +159,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -195,6 +235,25 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-sys" +version = "0.1.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +dependencies = [ + "objc-sys", +] + +[[package]] +name = "block2" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" +dependencies = [ + "block-sys", + "objc2-encode", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -218,7 +277,7 @@ checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -252,6 +311,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -259,6 +321,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "cgl" version = "0.3.2" @@ -847,7 +915,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -985,7 +1053,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -1098,7 +1166,7 @@ dependencies = [ "wayland-client", "wayland-egl", "winapi", - "winit", + "winit 0.27.5", ] [[package]] @@ -1332,6 +1400,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.64" @@ -1560,7 +1637,7 @@ dependencies = [ "bitflags 1.3.2", "jni-sys", "ndk-sys", - "num_enum", + "num_enum 0.5.11", "raw-window-handle 0.5.2", "thiserror", ] @@ -1722,7 +1799,16 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ - "num_enum_derive", + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive 0.6.1", ] [[package]] @@ -1737,6 +1823,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.28", +] + [[package]] name = "nv-flip" version = "0.1.2" @@ -1771,6 +1869,32 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-sys" +version = "0.2.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" + +[[package]] +name = "objc2" +version = "0.3.0-beta.3.patch-leaks.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" +dependencies = [ + "block2", + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "2.0.0-pre.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" +dependencies = [ + "objc-sys", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -1795,6 +1919,15 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "orbclient" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "221d488cd70617f1bd599ed8ceb659df2147d9393717954d82a0f5e8032a6ab1" +dependencies = [ + "redox_syscall", +] + [[package]] name = "osmesa-sys" version = "0.1.2" @@ -1810,6 +1943,15 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" +[[package]] +name = "owned_ttf_parser" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" +dependencies = [ + "ttf-parser", +] + [[package]] name = "parking" version = "2.1.0" @@ -1884,7 +2026,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -1916,7 +2058,7 @@ dependencies = [ "serde", "wgpu-core", "wgpu-types", - "winit", + "winit 0.28.6", ] [[package]] @@ -2218,7 +2360,20 @@ dependencies = [ "crossfont", "log", "smithay-client-toolkit", - "tiny-skia", + "tiny-skia 0.7.0", +] + +[[package]] +name = "sctk-adwaita" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda4e97be1fd174ccc2aae81c8b694e803fa99b34e8fd0f057a9d70698e3ed09" +dependencies = [ + "ab_glyph", + "log", + "memmap2", + "smithay-client-toolkit", + "tiny-skia 0.8.4", ] [[package]] @@ -2244,9 +2399,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.173" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91f70896d6720bc714a4a57d22fc91f1db634680e65c8efe13323f1fa38d53f" +checksum = "0ea67f183f058fe88a4e3ec6e2788e003840893b91bac4559cabedd00863b3ed" dependencies = [ "serde_derive", ] @@ -2262,20 +2417,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.173" +version = "1.0.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6250dde8342e0232232be9ca3db7aa40aceb5a3e5dd9bddbc00d99a007cde49" +checksum = "24e744d7782b686ab3b73267ef05697159cc0e5abbed3f47f9933165e5219036" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] name = "serde_json" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "indexmap 2.0.0", "itoa", @@ -2441,6 +2596,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strict-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" + [[package]] name = "strsim" version = "0.10.0" @@ -2460,9 +2621,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.26" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -2480,22 +2641,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.43" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -2510,7 +2671,21 @@ dependencies = [ "cfg-if", "png", "safe_arch", - "tiny-skia-path", + "tiny-skia-path 0.7.0", +] + +[[package]] +name = "tiny-skia" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67" +dependencies = [ + "arrayref", + "arrayvec 0.7.4", + "bytemuck", + "cfg-if", + "png", + "tiny-skia-path 0.8.4", ] [[package]] @@ -2523,6 +2698,17 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "tiny-skia-path" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adbfb5d3f3dd57a0e11d12f4f13d4ebbbc1b5c15b7ab0a156d030b21da5f677c" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2566,7 +2752,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", ] [[package]] @@ -2586,6 +2772,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "ttf-parser" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33" + [[package]] name = "unic-char-property" version = "0.9.0" @@ -2770,7 +2962,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", "wasm-bindgen-shared", ] @@ -2804,7 +2996,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.26", + "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2965,7 +3157,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -2980,7 +3172,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -2998,7 +3190,7 @@ dependencies = [ "wasm-bindgen-test", "wgpu", "wgpu-example", - "winit", + "winit 0.28.6", ] [[package]] @@ -3009,7 +3201,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3045,7 +3237,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3066,7 +3258,7 @@ dependencies = [ "wgpu", "wgpu-hal", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3109,7 +3301,7 @@ dependencies = [ "web-sys", "wgpu-types", "winapi", - "winit", + "winit 0.28.6", ] [[package]] @@ -3127,7 +3319,7 @@ dependencies = [ "wasm-bindgen-test", "wgpu", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3157,7 +3349,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu", - "winit", + "winit 0.28.6", ] [[package]] @@ -3169,7 +3361,7 @@ dependencies = [ "env_logger", "pollster", "wgpu", - "winit", + "winit 0.28.6", ] [[package]] @@ -3196,7 +3388,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3210,7 +3402,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3223,7 +3415,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3239,7 +3431,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3251,7 +3443,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3288,7 +3480,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3314,7 +3506,7 @@ dependencies = [ "wgpu", "wgpu-example", "wgpu-test", - "winit", + "winit 0.28.6", ] [[package]] @@ -3387,6 +3579,15 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3563,7 +3764,7 @@ dependencies = [ "percent-encoding", "raw-window-handle 0.4.3", "raw-window-handle 0.5.2", - "sctk-adwaita", + "sctk-adwaita 0.4.3", "smithay-client-toolkit", "wasm-bindgen", "wayland-client", @@ -3573,6 +3774,41 @@ dependencies = [ "x11-dl", ] +[[package]] +name = "winit" +version = "0.28.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "866db3f712fffba75d31bf0cdecf357c8aeafd158c5b7ab51dba2a2b2d47f196" +dependencies = [ + "android-activity", + "bitflags 1.3.2", + "cfg_aliases", + "core-foundation", + "core-graphics", + "dispatch", + "instant", + "libc", + "log", + "mio", + "ndk", + "objc2", + "once_cell", + "orbclient", + "percent-encoding", + "raw-window-handle 0.5.2", + "redox_syscall", + "sctk-adwaita 0.5.4", + "smithay-client-toolkit", + "wasm-bindgen", + "wayland-client", + "wayland-commons", + "wayland-protocols", + "wayland-scanner", + "web-sys", + "windows-sys 0.45.0", + "x11-dl", +] + [[package]] name = "winnow" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 9c3246f670..19a8f80c8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,7 @@ raw-window-handle = "0.5" renderdoc-sys = "1.0.0" ron = "0.8" serde = "1" -serde_json = "1.0.96" +serde_json = "1.0.104" smallvec = "1" static_assertions = "1.1.0" thiserror = "1" @@ -98,7 +98,7 @@ wgpu-core = { version = "0.17.0", path = "./wgpu-core" } wgpu-example = { version = "0.17.0", path = "./examples/common" } wgpu-test = { version = "0.17", path = "./tests"} wgpu-types = { version = "0.17.0", path = "./wgpu-types" } -winit = "0.27.1" +winit = { version = "0.28.6", features = [ "android-native-activity" ] } # Metal dependencies block = "0.1" diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index 482d970563..f26e136d81 100644 --- a/examples/common/src/framework.rs +++ b/examples/common/src/framework.rs @@ -12,9 +12,9 @@ use winit::{ #[allow(dead_code)] pub fn cast_slice(data: &[T]) -> &[u8] { - use std::{mem::size_of, slice::from_raw_parts}; + use std::{mem::size_of_val, slice::from_raw_parts}; - unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::()) } + unsafe { from_raw_parts(data.as_ptr() as *const u8, size_of_val(data)) } } #[allow(dead_code)] @@ -453,7 +453,7 @@ pub fn run(title: &str) { #[cfg(target_arch = "wasm32")] pub fn run(title: &str) { - use wasm_bindgen::{prelude::*, JsCast}; + use wasm_bindgen::prelude::*; let title = title.to_owned(); wasm_bindgen_futures::spawn_local(async move { diff --git a/examples/hello-compute/src/main.rs b/examples/hello-compute/src/main.rs index afdf7744c9..cad0ad6876 100644 --- a/examples/hello-compute/src/main.rs +++ b/examples/hello-compute/src/main.rs @@ -75,8 +75,7 @@ async fn execute_gpu_inner( }); // Gets the size in bytes of the buffer. - let slice_size = numbers.len() * std::mem::size_of::(); - let size = slice_size as wgpu::BufferAddress; + let size = std::mem::size_of_val(numbers) as wgpu::BufferAddress; // Instantiates buffer without data. // `usage` of buffer specifies how it can be used: diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 20e057a934..074170e562 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -1285,8 +1285,7 @@ impl Device { inner: Box::new(inner), }) })?; - let interface = - validation::Interface::new(&module, &info, self.features, self.limits.clone()); + let interface = validation::Interface::new(&module, &info, self.limits.clone()); let hal_shader = hal::ShaderInput::Naga(hal::NagaShader { module, info }); let hal_desc = hal::ShaderModuleDescriptor { diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 771adba731..84e1e71691 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -1,5 +1,4 @@ use crate::{binding_model::BindEntryMap, FastHashMap, FastHashSet}; -use naga::valid::GlobalUse; use std::{collections::hash_map::Entry, fmt}; use thiserror::Error; use wgt::{BindGroupLayoutEntry, BindingType}; @@ -112,7 +111,7 @@ struct SpecializationConstant { struct EntryPoint { inputs: Vec, outputs: Vec, - resources: Vec<(naga::Handle, GlobalUse)>, + resources: Vec>, #[allow(unused)] spec_constants: Vec, sampling_pairs: FastHashSet<(naga::Handle, naga::Handle)>, @@ -121,7 +120,6 @@ struct EntryPoint { #[derive(Debug)] pub struct Interface { - features: wgt::Features, limits: wgt::Limits, resources: naga::Arena, entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>, @@ -174,11 +172,6 @@ pub enum BindingError { Missing, #[error("Visibility flags don't include the shader stage")] Invisible, - #[error("The shader requires the load/store access flags {required:?} but only {allowed:?} is allowed")] - WrongUsage { - required: GlobalUse, - allowed: GlobalUse, - }, #[error("Type on the shader side does not match the pipeline binding")] WrongType, #[error("Storage class {binding:?} doesn't match the shader {shader:?}")] @@ -206,9 +199,9 @@ pub enum BindingError { #[error("Texture format {0:?} is not supported for storage use")] BadStorageFormat(wgt::TextureFormat), #[error( - "Storage texture usage {0:?} doesn't have a matching supported `StorageTextureAccess`" + "Storage texture with access {0:?} doesn't have a matching supported `StorageTextureAccess`" )] - UnsupportedTextureStorageAccess(GlobalUse), + UnsupportedTextureStorageAccess(naga::StorageAccess), } #[derive(Clone, Debug, Error)] @@ -379,43 +372,32 @@ fn map_storage_format_from_naga(format: naga::StorageFormat) -> wgt::TextureForm } impl Resource { - fn check_binding_use( - &self, - entry: &BindGroupLayoutEntry, - shader_usage: GlobalUse, - ) -> Result<(), BindingError> { - let allowed_usage = match self.ty { + fn check_binding_use(&self, entry: &BindGroupLayoutEntry) -> Result<(), BindingError> { + match self.ty { ResourceType::Buffer { size } => { - let (allowed_usage, min_size) = match entry.ty { + let min_size = match entry.ty { BindingType::Buffer { ty, has_dynamic_offset: _, min_binding_size, } => { - let (class, global_use) = match ty { - wgt::BufferBindingType::Uniform => { - (naga::AddressSpace::Uniform, GlobalUse::READ) - } + let class = match ty { + wgt::BufferBindingType::Uniform => naga::AddressSpace::Uniform, wgt::BufferBindingType::Storage { read_only } => { - let mut global_use = GlobalUse::READ | GlobalUse::QUERY; - global_use.set(GlobalUse::WRITE, !read_only); let mut naga_access = naga::StorageAccess::LOAD; naga_access.set(naga::StorageAccess::STORE, !read_only); - ( - naga::AddressSpace::Storage { - access: naga_access, - }, - global_use, - ) + naga::AddressSpace::Storage { + access: naga_access, + } } }; - if !address_space_matches(self.class, class) { + if self.class != class { return Err(BindingError::WrongAddressSpace { binding: class, shader: self.class, }); } - (global_use, min_binding_size) + min_binding_size } _ => return Err(BindingError::WrongType), }; @@ -425,13 +407,10 @@ impl Resource { } _ => (), } - allowed_usage } ResourceType::Sampler { comparison } => match entry.ty { BindingType::Sampler(ty) => { - if (ty == wgt::SamplerBindingType::Comparison) == comparison { - GlobalUse::READ - } else { + if (ty == wgt::SamplerBindingType::Comparison) != comparison { return Err(BindingError::WrongSamplerComparison); } } @@ -480,29 +459,26 @@ impl Resource { } } } - let (expected_class, usage) = match entry.ty { + let expected_class = match entry.ty { BindingType::Texture { sample_type, view_dimension: _, multisampled: multi, - } => { - let class = match sample_type { - wgt::TextureSampleType::Float { .. } => naga::ImageClass::Sampled { - kind: naga::ScalarKind::Float, - multi, - }, - wgt::TextureSampleType::Sint => naga::ImageClass::Sampled { - kind: naga::ScalarKind::Sint, - multi, - }, - wgt::TextureSampleType::Uint => naga::ImageClass::Sampled { - kind: naga::ScalarKind::Uint, - multi, - }, - wgt::TextureSampleType::Depth => naga::ImageClass::Depth { multi }, - }; - (class, GlobalUse::READ | GlobalUse::QUERY) - } + } => match sample_type { + wgt::TextureSampleType::Float { .. } => naga::ImageClass::Sampled { + kind: naga::ScalarKind::Float, + multi, + }, + wgt::TextureSampleType::Sint => naga::ImageClass::Sampled { + kind: naga::ScalarKind::Sint, + multi, + }, + wgt::TextureSampleType::Uint => naga::ImageClass::Sampled { + kind: naga::ScalarKind::Uint, + multi, + }, + wgt::TextureSampleType::Depth => naga::ImageClass::Depth { multi }, + }, BindingType::StorageTexture { access, format, @@ -510,26 +486,15 @@ impl Resource { } => { let naga_format = map_storage_format_to_naga(format) .ok_or(BindingError::BadStorageFormat(format))?; - let (naga_access, usage) = match access { - wgt::StorageTextureAccess::ReadOnly => ( - naga::StorageAccess::LOAD, - GlobalUse::READ | GlobalUse::QUERY, - ), - wgt::StorageTextureAccess::WriteOnly => ( - naga::StorageAccess::STORE, - GlobalUse::WRITE | GlobalUse::QUERY, - ), - wgt::StorageTextureAccess::ReadWrite => { - (naga::StorageAccess::all(), GlobalUse::all()) - } + let naga_access = match access { + wgt::StorageTextureAccess::ReadOnly => naga::StorageAccess::LOAD, + wgt::StorageTextureAccess::WriteOnly => naga::StorageAccess::STORE, + wgt::StorageTextureAccess::ReadWrite => naga::StorageAccess::all(), }; - ( - naga::ImageClass::Storage { - format: naga_format, - access: naga_access, - }, - usage, - ) + naga::ImageClass::Storage { + format: naga_format, + access: naga_access, + } } _ => return Err(BindingError::WrongType), }; @@ -539,31 +504,19 @@ impl Resource { shader: class, }); } - usage } }; - if allowed_usage.contains(shader_usage) { - Ok(()) - } else { - Err(BindingError::WrongUsage { - required: shader_usage, - allowed: allowed_usage, - }) - } + Ok(()) } - fn derive_binding_type( - &self, - shader_usage: GlobalUse, - features: wgt::Features, - ) -> Result { + fn derive_binding_type(&self) -> Result { Ok(match self.ty { ResourceType::Buffer { size } => BindingType::Buffer { ty: match self.class { naga::AddressSpace::Uniform => wgt::BufferBindingType::Uniform, - naga::AddressSpace::Storage { .. } => wgt::BufferBindingType::Storage { - read_only: !shader_usage.contains(GlobalUse::WRITE), + naga::AddressSpace::Storage { access } => wgt::BufferBindingType::Storage { + read_only: access == naga::StorageAccess::LOAD, }, _ => return Err(BindingError::WrongType), }, @@ -606,19 +559,15 @@ impl Resource { view_dimension, multisampled: multi, }, - naga::ImageClass::Storage { format, .. } => BindingType::StorageTexture { - access: if !shader_usage.contains(GlobalUse::READ) { - wgt::StorageTextureAccess::WriteOnly - } else if !features - .contains(wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES) - { - return Err(BindingError::UnsupportedTextureStorageAccess( - shader_usage, - )); - } else if shader_usage.contains(GlobalUse::WRITE) { - wgt::StorageTextureAccess::ReadWrite - } else { - wgt::StorageTextureAccess::ReadOnly + naga::ImageClass::Storage { format, access } => BindingType::StorageTexture { + access: { + const LOAD_STORE: naga::StorageAccess = naga::StorageAccess::all(); + match access { + naga::StorageAccess::LOAD => wgt::StorageTextureAccess::ReadOnly, + naga::StorageAccess::STORE => wgt::StorageTextureAccess::WriteOnly, + LOAD_STORE => wgt::StorageTextureAccess::ReadWrite, + _ => unreachable!(), + } }, view_dimension, format: { @@ -880,12 +829,7 @@ impl Interface { list.push(varying); } - pub fn new( - module: &naga::Module, - info: &naga::valid::ModuleInfo, - features: wgt::Features, - limits: wgt::Limits, - ) -> Self { + pub fn new(module: &naga::Module, info: &naga::valid::ModuleInfo, limits: wgt::Limits) -> Self { let mut resources = naga::Arena::new(); let mut resource_mapping = FastHashMap::default(); for (var_handle, var) in module.global_variables.iter() { @@ -949,11 +893,8 @@ impl Interface { for (var_handle, var) in module.global_variables.iter() { let usage = info[var_handle]; - if usage.is_empty() { - continue; - } - if var.binding.is_some() { - ep.resources.push((resource_mapping[&var_handle], usage)); + if !usage.is_empty() && var.binding.is_some() { + ep.resources.push(resource_mapping[&var_handle]); } } @@ -968,7 +909,6 @@ impl Interface { } Self { - features, limits, resources, entry_points, @@ -1000,7 +940,7 @@ impl Interface { .ok_or(StageError::MissingEntryPoint(pair.1))?; // check resources visibility - for &(handle, usage) in entry_point.resources.iter() { + for &handle in entry_point.resources.iter() { let res = &self.resources[handle]; let result = match given_layouts { Some(layouts) => { @@ -1026,13 +966,13 @@ impl Interface { Err(BindingError::Invisible) } }) - .and_then(|entry| res.check_binding_use(entry, usage)) + .and_then(|entry| res.check_binding_use(entry)) } None => derived_layouts .get_mut(res.bind.group as usize) .ok_or(BindingError::Missing) .and_then(|set| { - let ty = res.derive_binding_type(usage, self.features)?; + let ty = res.derive_binding_type()?; match set.entry(res.bind.binding) { Entry::Occupied(e) if e.get().ty != ty => { return Err(BindingError::InconsistentlyDerivedType) @@ -1237,72 +1177,3 @@ impl Interface { Ok(outputs) } } - -fn address_space_matches(shader: naga::AddressSpace, binding: naga::AddressSpace) -> bool { - match (shader, binding) { - ( - naga::AddressSpace::Storage { - access: access_shader, - }, - naga::AddressSpace::Storage { - access: access_pipeline, - }, - ) => { - // Allow read- and write-only usages to match read-write layouts: - (access_shader & access_pipeline) == access_shader - } - (a, b) => a == b, - } -} - -#[cfg(test)] -mod test { - use super::address_space_matches; - - #[test] - fn address_space_matches_correctly() { - assert!(address_space_matches( - naga::AddressSpace::Uniform, - naga::AddressSpace::Uniform - )); - - assert!(!address_space_matches( - naga::AddressSpace::Uniform, - naga::AddressSpace::Storage { - access: naga::StorageAccess::LOAD - } - )); - - let test_cases = [ - (naga::StorageAccess::LOAD, naga::StorageAccess::LOAD, true), - (naga::StorageAccess::STORE, naga::StorageAccess::LOAD, false), - (naga::StorageAccess::LOAD, naga::StorageAccess::STORE, false), - (naga::StorageAccess::STORE, naga::StorageAccess::STORE, true), - ( - naga::StorageAccess::LOAD | naga::StorageAccess::STORE, - naga::StorageAccess::LOAD | naga::StorageAccess::STORE, - true, - ), - ( - naga::StorageAccess::STORE, - naga::StorageAccess::LOAD | naga::StorageAccess::STORE, - true, - ), - ( - naga::StorageAccess::LOAD, - naga::StorageAccess::LOAD | naga::StorageAccess::STORE, - true, - ), - ]; - - for (shader, binding, expect_match) in test_cases { - assert_eq!( - expect_match, - address_space_matches( - naga::AddressSpace::Storage { access: shader }, - naga::AddressSpace::Storage { access: binding } - ) - ); - } - } -} diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 04459488c4..550752eb37 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -134,7 +134,7 @@ features = ["wgsl-in"] [dev-dependencies] cfg-if = "1" env_logger = "0.10" -winit = "0.27.1" # for "halmark" example +winit = { version = "0.28.6", features = [ "android-native-activity" ] } # for "halmark" example [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] glutin = "0.29.1" # for "gles" example diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 446742c283..b36ff3b57e 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -606,7 +606,7 @@ impl super::Adapter { // Drop the GL guard so we can move the context into AdapterShared // ( on Wasm the gl handle is just a ref so we tell clippy to allow // dropping the ref ) - #[allow(clippy::drop_ref)] + #[cfg_attr(target_arch = "wasm32", allow(clippy::drop_ref))] drop(gl); Some(crate::ExposedAdapter { diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 5e3a1c52c8..c31b577079 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -49,10 +49,7 @@ impl super::CommandBuffer { fn add_push_constant_data(&mut self, data: &[u32]) -> Range { let data_raw = unsafe { - std::slice::from_raw_parts( - data.as_ptr() as *const _, - data.len() * mem::size_of::(), - ) + std::slice::from_raw_parts(data.as_ptr() as *const _, mem::size_of_val(data)) }; let start = self.data_bytes.len(); assert!(start < u32::MAX as usize); diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 54f3003fc9..cc21f14836 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -222,7 +222,7 @@ impl super::Device { index: BoundsCheckPolicy::Unchecked, buffer: BoundsCheckPolicy::Unchecked, image_load: image_check, - image_store: image_check, + image_store: BoundsCheckPolicy::Unchecked, binding_array: BoundsCheckPolicy::Unchecked, }; diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 5fde99982c..88e244c7ef 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -60,7 +60,7 @@ pub mod dx12; /// A dummy API implementation. pub mod empty; /// GLES API internals. -#[cfg(all(feature = "gles"))] +#[cfg(feature = "gles")] pub mod gles; /// Metal API internals. #[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index b0db65dab2..c3166d26ab 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -100,7 +100,7 @@ impl super::Device { index: bounds_check_policy, buffer: bounds_check_policy, image_load: bounds_check_policy, - image_store: bounds_check_policy, + image_store: naga::proc::BoundsCheckPolicy::Unchecked, // TODO: support bounds checks on binding arrays binding_array: naga::proc::BoundsCheckPolicy::Unchecked, }, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index c0a374c878..ab88bcee19 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1212,12 +1212,6 @@ impl super::Adapter { None }; - let image_checks = if self.private_caps.robust_image_access { - naga::proc::BoundsCheckPolicy::Unchecked - } else { - naga::proc::BoundsCheckPolicy::Restrict - }; - let naga_options = { use naga::back::spv; @@ -1279,8 +1273,12 @@ impl super::Adapter { } else { naga::proc::BoundsCheckPolicy::Restrict }, - image_load: image_checks, - image_store: image_checks, + image_load: if self.private_caps.robust_image_access { + naga::proc::BoundsCheckPolicy::Unchecked + } else { + naga::proc::BoundsCheckPolicy::Restrict + }, + image_store: naga::proc::BoundsCheckPolicy::Unchecked, // TODO: support bounds checks on binding arrays binding_array: naga::proc::BoundsCheckPolicy::Unchecked, }, diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index a782b34dc2..313d67bfb5 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -42,4 +42,4 @@ web-sys = { version = "0.3.64", features = [ [dev-dependencies] serde = { version = "1", features = ["serde_derive"] } -serde_json = "1.0.96" +serde_json = "1.0.104" diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 180dd095ae..29619210e1 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6311,7 +6311,7 @@ pub enum Dx12Compiler { Dxc { /// Path to the `dxil.dll` file, or path to the directory containing `dxil.dll` file. Passing `None` will use standard platform specific dll loading rules. dxil_path: Option, - /// Path to the `dxcompiler.dll` file, or path to the directory containing `dxil.dll` file. Passing `None` will use standard platform specific dll loading rules. + /// Path to the `dxcompiler.dll` file, or path to the directory containing `dxcompiler.dll` file. Passing `None` will use standard platform specific dll loading rules. dxc_path: Option, }, } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 7804a93bb5..b4b34c6aa4 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -2736,33 +2736,6 @@ fn range_to_offset_size>( (offset, size) } -#[cfg(test)] -mod tests { - use crate::BufferSize; - - #[test] - fn range_to_offset_size_works() { - assert_eq!(crate::range_to_offset_size(0..2), (0, BufferSize::new(2))); - assert_eq!(crate::range_to_offset_size(2..5), (2, BufferSize::new(3))); - assert_eq!(crate::range_to_offset_size(..), (0, None)); - assert_eq!(crate::range_to_offset_size(21..), (21, None)); - assert_eq!(crate::range_to_offset_size(0..), (0, None)); - assert_eq!(crate::range_to_offset_size(..21), (0, BufferSize::new(21))); - } - - #[test] - #[should_panic] - fn range_to_offset_size_panics_for_empty_range() { - crate::range_to_offset_size(123..123); - } - - #[test] - #[should_panic] - fn range_to_offset_size_panics_for_unbounded_empty_range() { - crate::range_to_offset_size(..0); - } -} - /// Read only view into a mapped buffer. #[derive(Debug)] pub struct BufferView<'a> { @@ -5107,3 +5080,30 @@ mod send_sync { } } } + +#[cfg(test)] +mod tests { + use crate::BufferSize; + + #[test] + fn range_to_offset_size_works() { + assert_eq!(crate::range_to_offset_size(0..2), (0, BufferSize::new(2))); + assert_eq!(crate::range_to_offset_size(2..5), (2, BufferSize::new(3))); + assert_eq!(crate::range_to_offset_size(..), (0, None)); + assert_eq!(crate::range_to_offset_size(21..), (21, None)); + assert_eq!(crate::range_to_offset_size(0..), (0, None)); + assert_eq!(crate::range_to_offset_size(..21), (0, BufferSize::new(21))); + } + + #[test] + #[should_panic] + fn range_to_offset_size_panics_for_empty_range() { + crate::range_to_offset_size(123..123); + } + + #[test] + #[should_panic] + fn range_to_offset_size_panics_for_unbounded_empty_range() { + crate::range_to_offset_size(..0); + } +}