diff --git a/Cargo.lock b/Cargo.lock index e6180182..85280ea8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,15 +4,21 @@ version = 3 [[package]] name = "ab_glyph_rasterizer" -version = "0.1.3" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9fe5e32de01730eb1f6b7f5b51c17e03e2325bf40a74f754f04f130043affff" + +[[package]] +name = "adler" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2692800d602527d2b8fea50036119c37df74ab565b10e285706a3dcec0ec3e16" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "adler32" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" @@ -33,9 +39,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.13" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -68,9 +74,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.32" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" +checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" [[package]] name = "approx" @@ -83,18 +89,18 @@ dependencies = [ [[package]] name = "arrayvec" -version = "0.5.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" dependencies = [ "serde", ] [[package]] name = "ash" -version = "0.32.1" +version = "0.33.3+1.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06063a002a77d2734631db74e8f4ce7148b77fe522e6bca46f2ae7774fd48112" +checksum = "cc4f1d82f164f838ae413296d1131aa6fa79b917d25bebaa7033d25620c09219" dependencies = [ "libloading 0.7.0", ] @@ -112,9 +118,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "base64" @@ -139,9 +145,9 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block" @@ -151,24 +157,24 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bumpalo" -version = "3.4.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "bytemuck" -version = "1.4.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92046dbb6f9332943252123f53623e0a6d513651af14967e2991c371ec20201c" +checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dae23a39becf0b1c8f9198d7e9fc80aaf1ec1ee7428ec570f6a0269e59a9cc" +checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54" dependencies = [ "proc-macro2", "quote", @@ -177,9 +183,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "calloop" @@ -188,17 +194,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b036167e76041694579972c28cf4877b4f92da222560ddb49008937b6a6727c" dependencies = [ "log", - "nix", + "nix 0.18.0", ] [[package]] name = "cc" -version = "1.0.67" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" -dependencies = [ - "jobserver", -] +checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" [[package]] name = "cfg-if" @@ -237,24 +240,14 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time", "winapi", ] -[[package]] -name = "cloudabi" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" -dependencies = [ - "bitflags", -] - [[package]] name = "cmake" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" +checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" dependencies = [ "cc", ] @@ -268,8 +261,8 @@ dependencies = [ "bitflags", "block", "cocoa-foundation", - "core-foundation 0.9.0", - "core-graphics 0.22.1", + "core-foundation 0.9.1", + "core-graphics 0.22.2", "foreign-types", "libc", "objc", @@ -283,7 +276,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ "bitflags", "block", - "core-foundation 0.9.0", + "core-foundation 0.9.1", "core-graphics-types", "foreign-types", "libc", @@ -302,9 +295,9 @@ dependencies = [ [[package]] name = "color_quant" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "compute" @@ -318,20 +311,14 @@ dependencies = [ "glob", "image", "log", + "naga", "pollster", "rayon", - "shaderc", - "tobj 2.0.2", + "tobj 2.0.4", "wgpu", "winit", ] -[[package]] -name = "const_fn" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab" - [[package]] name = "copyless" version = "0.1.5" @@ -350,11 +337,11 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b5ed8e7e76c45974e15e41bfa8d5b0483cd90191639e01d8f5f1e606299d3fb" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ - "core-foundation-sys 0.8.0", + "core-foundation-sys 0.8.2", "libc", ] @@ -366,9 +353,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "core-foundation-sys" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a21fa21941700a3cd8fcb4091f361a6a712fac632f85d9f487cc892045d55c6" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "core-graphics" @@ -384,12 +371,12 @@ dependencies = [ [[package]] name = "core-graphics" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc239bba52bab96649441699533a68de294a101533b0270b2d65aa402b29a7f9" +checksum = "269f35f69b542b80e736a20a89a05215c0ce80c2c03c514abb2e318b78379d86" dependencies = [ "bitflags", - "core-foundation 0.9.0", + "core-foundation 0.9.1", "core-graphics-types", "foreign-types", "libc", @@ -402,7 +389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", - "core-foundation 0.9.0", + "core-foundation 0.9.1", "foreign-types", "libc", ] @@ -422,18 +409,18 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] name = "crossbeam" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd01a6eb3daaafa260f6fc94c3a6c36390abc2080e38e3e34ced87393fb77d80" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" dependencies = [ "cfg-if 1.0.0", "crossbeam-channel", @@ -445,9 +432,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -455,9 +442,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", @@ -466,12 +453,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.0" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ "cfg-if 1.0.0", - "const_fn", "crossbeam-utils", "lazy_static", "memoffset", @@ -500,9 +486,9 @@ dependencies = [ [[package]] name = "d3d12" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "091ed1b25fe47c7ff129fc440c23650b6114f36aa00bc7212cc8041879294428" +checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c" dependencies = [ "bitflags", "libloading 0.7.0", @@ -556,9 +542,9 @@ dependencies = [ [[package]] name = "derivative" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", @@ -577,29 +563,29 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b11f15d1e3268f140f68d390637d5e76d849782d971ae7063e0da69fe9709a76" dependencies = [ - "libloading 0.6.2", + "libloading 0.6.7", ] [[package]] -name = "downcast-rs" -version = "1.2.0" +name = "dlib" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" +dependencies = [ + "libloading 0.7.0", +] [[package]] -name = "drm-fourcc" -version = "2.1.1" +name = "downcast-rs" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebbf3a5ed4671aabffefce172ff43d69c1f27dd2c6aea28e5212a70f32ada0cf" -dependencies = [ - "serde", -] +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "either" -version = "1.5.3" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "env_logger" @@ -614,21 +600,11 @@ dependencies = [ "termcolor", ] -[[package]] -name = "external-memory" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4dfe8d292b014422776a8c516862d2bff8a81b223a4461dfdc45f3862dc9d39" -dependencies = [ - "bitflags", - "drm-fourcc", -] - [[package]] name = "fixedbitset" -version = "0.2.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" [[package]] name = "fnv" @@ -667,7 +643,7 @@ dependencies = [ "rayon", "shaderc", "thiserror", - "tobj 2.0.2", + "tobj 2.0.4", "wgpu", "wgpu-subscriber", "winit", @@ -688,19 +664,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generator" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc" -dependencies = [ - "cc", - "libc", - "log", - "rustc_version", - "winapi", -] - [[package]] name = "getrandom" version = "0.2.3" @@ -713,175 +676,23 @@ dependencies = [ ] [[package]] -name = "gfx-auxil" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1694991b11d642680e82075a75c7c2bd75556b805efa7660b705689f05b1ab1c" -dependencies = [ - "fxhash", - "gfx-hal", - "spirv_cross", -] - -[[package]] -name = "gfx-backend-dx11" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9e453baf3aaef2b0c354ce0b3d63d76402e406a59b64b7182d123cfa6635ae" -dependencies = [ - "arrayvec", - "bitflags", - "gfx-auxil", - "gfx-hal", - "gfx-renderdoc", - "libloading 0.7.0", - "log", - "parking_lot", - "range-alloc", - "raw-window-handle", - "smallvec", - "spirv_cross", - "thunderdome", - "winapi", - "wio", -] - -[[package]] -name = "gfx-backend-dx12" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21506399f64a3c4d389182a89a30073856ae33eb712315456b4fd8f39ee7682a" -dependencies = [ - "arrayvec", - "bit-set", - "bitflags", - "d3d12", - "gfx-auxil", - "gfx-hal", - "gfx-renderdoc", - "log", - "parking_lot", - "range-alloc", - "raw-window-handle", - "smallvec", - "spirv_cross", - "thunderdome", - "winapi", -] - -[[package]] -name = "gfx-backend-empty" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c8f813c47791918aa00dc9c9ddf961d23fa8c2a5d869e6cb8ea84f944820f4" -dependencies = [ - "gfx-hal", - "log", - "raw-window-handle", -] - -[[package]] -name = "gfx-backend-gl" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bae057fc3a0ab23ecf97ae51d4017d27d5ddf0aab16ee6dcb58981af88c3152" -dependencies = [ - "arrayvec", - "bitflags", - "fxhash", - "gfx-hal", - "glow", - "js-sys", - "khronos-egl", - "libloading 0.7.0", - "log", - "naga", - "parking_lot", - "raw-window-handle", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "gfx-backend-metal" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de85808e2a98994c6af925253f8a9593bc57180ef1ea137deab6d35cc949517" -dependencies = [ - "arrayvec", - "bitflags", - "block", - "cocoa-foundation", - "copyless", - "core-graphics-types", - "foreign-types", - "fxhash", - "gfx-hal", - "log", - "metal", - "naga", - "objc", - "parking_lot", - "profiling", - "range-alloc", - "raw-window-handle", - "storage-map", -] - -[[package]] -name = "gfx-backend-vulkan" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9861ec855acbbc65c0e4f966d761224886e811dc2c6d413a4776e9293d0e5c0" -dependencies = [ - "arrayvec", - "ash", - "byteorder", - "core-graphics-types", - "gfx-hal", - "gfx-renderdoc", - "inplace_it", - "log", - "naga", - "objc", - "parking_lot", - "raw-window-handle", - "smallvec", - "winapi", -] - -[[package]] -name = "gfx-hal" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fbb575ea793dd0507b3082f4f2cde62dc9f3cebd98f5cd49ba2a4da97a976fd" -dependencies = [ - "bitflags", - "external-memory", - "naga", - "raw-window-handle", - "thiserror", -] - -[[package]] -name = "gfx-renderdoc" -version = "0.1.0" +name = "gif" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8027995e247e2426d3a00d13f5191dd56c314bff02dc4b54cbf727f1ba9c40a" +checksum = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" dependencies = [ - "libloading 0.7.0", - "log", - "renderdoc-sys", + "color_quant", + "lzw", ] [[package]] name = "gif" -version = "0.10.3" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" +checksum = "5a668f699973d0f573d15749b7002a9ac9e1f9c6b220e7b165601334c173d8de" dependencies = [ "color_quant", - "lzw", + "weezl", ] [[package]] @@ -894,13 +705,13 @@ dependencies = [ "env_logger", "framework", "fs_extra", - "gif", + "gif 0.10.3", "glob", "image", "log", "pollster", "shaderc", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] @@ -913,9 +724,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "glow" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b80b98efaa8a34fce11d60dd2ce2760d5d83c373cbcc73bb87c2a3a84a54108" +checksum = "4f04649123493bc2483cbef4daddb45d40bbdae5adb221a63a23efdb0cc99520" dependencies = [ "js-sys", "slotmap", @@ -925,9 +736,9 @@ dependencies = [ [[package]] name = "gpu-alloc" -version = "0.4.7" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc1b6ca374e81862526786d9cb42357ce03706ed1b8761730caafd02ab91f3a" +checksum = "ab8524eac5fc9d05625c891adf78fcf64dc0ee9f8d0882874b9f220f42b442bf" dependencies = [ "bitflags", "gpu-alloc-types", @@ -944,13 +755,13 @@ dependencies = [ [[package]] name = "gpu-descriptor" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d74668a6a6f0202e29f212a6d47ef8c7e092a76f4ab267b0065b6e0d175e45c6" +checksum = "d7a237f0419ab10d17006d55c62ac4f689a6bf52c75d3f38b8361d249e8d4b0b" dependencies = [ "bitflags", "gpu-descriptor-types", - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -971,11 +782,17 @@ dependencies = [ "ahash 0.4.7", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "hermit-abi" -version = "0.1.15" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -994,13 +811,14 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "image" -version = "0.23.7" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2397fc43bd5648b7117aabb3c5e62d0e62c194826ec77b0b4d0c41e62744635" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" dependencies = [ "bytemuck", "byteorder", - "gif", + "color_quant", + "gif 0.11.2", "jpeg-decoder", "num-iter", "num-rational", @@ -1012,12 +830,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.11.2", ] [[package]] @@ -1028,15 +846,18 @@ checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca" [[package]] name = "instant" -version = "0.1.6" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" +dependencies = [ + "cfg-if 1.0.0", +] [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "jni-sys" @@ -1044,30 +865,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" -[[package]] -name = "jobserver" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" -dependencies = [ - "libc", -] - [[package]] name = "jpeg-decoder" -version = "0.1.20" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc797adac5f083b8ff0ca6f6294a999393d76e197c36488e2ef732c4715f6fa3" +checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" dependencies = [ - "byteorder", "rayon", ] [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" dependencies = [ "wasm-bindgen", ] @@ -1090,16 +901,17 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" [[package]] name = "libloading" -version = "0.6.2" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" +checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" dependencies = [ + "cfg-if 1.0.0", "winapi", ] @@ -1115,33 +927,20 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "loom" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" -dependencies = [ - "cfg-if 0.1.10", - "generator", - "scoped-tls", - "serde", - "serde_json", + "cfg-if 1.0.0", ] [[package]] @@ -1176,9 +975,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memmap2" @@ -1191,18 +990,18 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.5.5" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" dependencies = [ "autocfg", ] [[package]] name = "metal" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d7d769f1c104b8388294d6594d491d2e21240636f5f94d37f8a0f3d7904450" +checksum = "e0514f491f4cc03632ab399ee01e2c1c1b12d3e1cf2d667c1ff5f87d6dcd2084" dependencies = [ "bitflags", "block", @@ -1212,6 +1011,12 @@ dependencies = [ "objc", ] +[[package]] +name = "minimal-lexical" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c835948974f68e0bd58636fc6c5b1fbff7b297e3046f11b3b3c18bbac012c6d" + [[package]] name = "miniz_oxide" version = "0.3.7" @@ -1221,11 +1026,21 @@ dependencies = [ "adler32", ] +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", @@ -1236,9 +1051,9 @@ dependencies = [ [[package]] name = "mio-misc" -version = "1.0.1" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d9bf3ad929ad9ec136d7bd55f68c62223561423474c21b5e34eb9322018d36" +checksum = "0ddf05411bb159cdb5801bb10002afb66cb4572be656044315e363460ce69dc2" dependencies = [ "crossbeam", "crossbeam-queue", @@ -1257,9 +1072,9 @@ dependencies = [ [[package]] name = "naga" -version = "0.5.0" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef670817eef03d356d5a509ea275e7dd3a78ea9e24261ea3cb2dfed1abb08f64" +checksum = "8c5859e55c51da10b98e7a73068e0a0c5da7bbcae4fc38f86043d0c6d1b917cf" dependencies = [ "bit-set", "bitflags", @@ -1268,8 +1083,10 @@ dependencies = [ "log", "num-traits", "petgraph", + "pp-rs", "rose_tree", - "spirv_headers", + "serde", + "spirv", "thiserror", ] @@ -1306,7 +1123,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d1c6307dc424d0f65b9b06e94f88248e6305726b14729fd67a5e47b2dc481d" dependencies = [ "darling", - "proc-macro-crate", + "proc-macro-crate 0.1.5", "proc-macro2", "quote", "syn", @@ -1330,13 +1147,26 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", +] + [[package]] name = "nom" -version = "5.1.2" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" dependencies = [ "memchr", + "minimal-lexical", "version_check", ] @@ -1351,9 +1181,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", "num-traits", @@ -1361,9 +1191,9 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" dependencies = [ "autocfg", "num-integer", @@ -1372,9 +1202,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ "autocfg", "num-integer", @@ -1383,9 +1213,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg", ] @@ -1402,9 +1232,9 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066" +checksum = "3f9bd055fb730c4f8f4f57d45d35cd6b3f0980535b056dc7ff119cee6a66ed6f" dependencies = [ "derivative", "num_enum_derive", @@ -1412,11 +1242,11 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.5.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e" +checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.0.0", "proc-macro2", "quote", "syn", @@ -1443,9 +1273,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "owned_ttf_parser" @@ -1458,9 +1288,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", @@ -1469,15 +1299,14 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.0" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if 0.1.10", - "cloudabi", + "cfg-if 1.0.0", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.10", "smallvec", "winapi", ] @@ -1490,30 +1319,36 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "petgraph" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" dependencies = [ "fixedbitset", "indexmap", ] +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "png" -version = "0.16.7" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ "bitflags", "crc32fast", "deflate", - "miniz_oxide", + "miniz_oxide 0.3.7", ] [[package]] @@ -1522,6 +1357,15 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb20dcc30536a1508e75d47dd0e399bb2fe7354dcf35cda9127f2bf1ed92e30e" +[[package]] +name = "pp-rs" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee" +dependencies = [ + "unicode-xid", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -1531,35 +1375,45 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fdbd1df62156fbc5945f4762632564d7d038153091c3fcf1067f6aef7cff92" +dependencies = [ + "thiserror", + "toml", +] + [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" dependencies = [ "unicode-xid", ] [[package]] name = "profiling" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a66d5e88679f2720126c11ee29da07a08f094eac52306b066edd7d393752d6" +checksum = "87dfd5592a8eed7e74f56ad7b125f8234763b805c30f0c7c95c486920026a6ec" [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] [[package]] name = "range-alloc" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a871f1e45a3a3f0c73fb60343c811238bb5143a81642e27c2ac7aac27ff01a63" +checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" [[package]] name = "raw-window-handle" @@ -1572,9 +1426,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" dependencies = [ "autocfg", "crossbeam-deque", @@ -1584,9 +1438,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -1601,33 +1455,40 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" -version = "1.3.9" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "byteorder", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "renderdoc-sys" @@ -1637,9 +1498,9 @@ checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" [[package]] name = "ron" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064ea8613fb712a19faf920022ec8ddf134984f100090764a4e1d768f3827f1f" +checksum = "45005aa836116903a49cf3461474da697cfe66221762c6e95871092009ec86d6" dependencies = [ "base64", "bitflags", @@ -1648,22 +1509,13 @@ dependencies = [ [[package]] name = "rose_tree" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284de9dae38774e2813aaabd7e947b4a6fe9b8c58c2309f754a487cdd50de1c2" +checksum = "fcd16c61e9205949fa4f8a22096705b4c2f8b8025b2ff67ff6c86afd854039ae" dependencies = [ "petgraph", ] -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - [[package]] name = "rusttype" version = "0.9.2" @@ -1707,35 +1559,20 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" -version = "1.0.126" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.126" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ "proc-macro2", "quote", @@ -1744,9 +1581,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.59" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" +checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" dependencies = [ "itoa", "ryu", @@ -1755,9 +1592,9 @@ dependencies = [ [[package]] name = "shaderc" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03f0cb8d1f8667fc9c50d5054be830a117af5f9a15f87c66b72bbca0c2fca484" +checksum = "58da8aaf4ad3508598cdf098567114c98d5f455de7d69b1213232ac557bc67ea" dependencies = [ "libc", "shaderc-sys", @@ -1765,9 +1602,9 @@ dependencies = [ [[package]] name = "shaderc-sys" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89175f80244b82f882033a81bd188f87307c4c39b2fe8d0f194314f270bdea9" +checksum = "8bd76ec0bd25f2017a65250373485e43cdc81b5cb8fd83c6115375c8d018cdf9" dependencies = [ "cmake", "libc", @@ -1775,25 +1612,27 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" +checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982" dependencies = [ "lazy_static", - "loom", ] [[package]] name = "slotmap" -version = "0.4.0" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] [[package]] name = "smallvec" -version = "1.4.1" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "smithay-client-toolkit" @@ -1804,46 +1643,26 @@ dependencies = [ "andrew", "bitflags", "calloop", - "dlib", + "dlib 0.4.2", "lazy_static", "log", "memmap2", - "nix", + "nix 0.18.0", "wayland-client", "wayland-cursor", "wayland-protocols", ] [[package]] -name = "spirv_cross" -version = "0.23.0" +name = "spirv" +version = "0.2.0+1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06db6bd7b6518f761593783e2896eefe55e90455efc5f44511078ce0426ed418" -dependencies = [ - "cc", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "spirv_headers" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c" +checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830" dependencies = [ "bitflags", "num-traits", ] -[[package]] -name = "storage-map" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c" -dependencies = [ - "lock_api", -] - [[package]] name = "strsim" version = "0.9.3" @@ -1852,9 +1671,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "syn" -version = "1.0.72" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" dependencies = [ "proc-macro2", "quote", @@ -1863,27 +1682,27 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.23" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.23" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" dependencies = [ "proc-macro2", "quote", @@ -1897,107 +1716,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" dependencies = [ "libc", - "redox_syscall", + "redox_syscall 0.1.57", "winapi", ] [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] -[[package]] -name = "thunderdome" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87b4947742c93ece24a0032141d9caa3d853752e694a57e35029dd2bd08673e0" - [[package]] name = "tiff" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3b8a87c4da944c3f27e5943289171ac71a6150a79ff6bacfff06d159dfff2f" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" dependencies = [ - "byteorder", - "lzw", - "miniz_oxide", -] - -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi", + "jpeg-decoder", + "miniz_oxide 0.4.4", + "weezl", ] [[package]] name = "tobj" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6172100cd5b17cdd085c94f261e31101ca31886c86a2337a6687dac6d2fb3cf1" +checksum = "2468f55be8e59cf7219f1685cf1af4eb00ef2314823a7941a41c8d69538f881b" [[package]] name = "tobj" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89f99c842ccf23791f0d183c69431f4e82844ab3152525abbd99e1f51bec30e1" +checksum = "267a53ebc1139c69d3feedc33a381c382b2e3b0c47f44f48679e90c4a69b8dac" dependencies = [ "ahash 0.7.4", ] [[package]] name = "toml" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] [[package]] name = "tracing" -version = "0.1.19" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ - "cfg-if 0.1.10", - "tracing-attributes", + "cfg-if 1.0.0", + "pin-project-lite", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "2ca517f43f0fb96e0c3072ed5c275fe5eece87e8cb52f4a77b69226d3b1c9df8" dependencies = [ "lazy_static", ] [[package]] name = "tracing-log" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" dependencies = [ "lazy_static", "log", @@ -2016,9 +1807,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.15" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1fa8f0c8f4c594e4fc9debc1990deab13238077271ba84dd853d54902ee3401" +checksum = "b9cbe87a2fa7e35900ce5de20220a582a9483a7063811defce79d7cbd59d4cfe" dependencies = [ "ansi_term", "chrono", @@ -2068,7 +1859,7 @@ dependencies = [ "image", "log", "pollster", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] @@ -2086,7 +1877,7 @@ dependencies = [ "image", "log", "pollster", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] @@ -2104,7 +1895,7 @@ dependencies = [ "image", "log", "pollster", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] @@ -2123,13 +1914,13 @@ dependencies = [ "log", "pollster", "rayon", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] [[package]] -name = "tutorial2-swapchain" +name = "tutorial2-surface" version = "0.1.0" dependencies = [ "cgmath", @@ -2255,7 +2046,7 @@ dependencies = [ "image", "log", "pollster", - "tobj 3.1.0", + "tobj 3.2.0", "wgpu", "winit", ] @@ -2268,21 +2059,21 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "walkdir" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", "winapi", @@ -2291,15 +2082,15 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2307,9 +2098,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" dependencies = [ "bumpalo", "lazy_static", @@ -2322,9 +2113,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "a87d738d4abc4cf22f6eb142f5b9a81301331ee3c767f2fef2fda4e325492060" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2334,9 +2125,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2344,9 +2135,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" dependencies = [ "proc-macro2", "quote", @@ -2357,20 +2148,20 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" [[package]] name = "wayland-client" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b227f47871e47d657c1c5e5360b4af9a877aa9c892716787be1c192c78c42" +checksum = "e3ab332350e502f159382201394a78e3cc12d0f04db863429260164ea40e0355" dependencies = [ "bitflags", "downcast-rs", "libc", - "nix", + "nix 0.20.0", "scoped-tls", "wayland-commons", "wayland-scanner", @@ -2379,11 +2170,11 @@ dependencies = [ [[package]] name = "wayland-commons" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "230b3ffeda101f877ff8ecb8573f5d26e7beb345b197807c4df34ec06879a3e6" +checksum = "a21817947c7011bbd0a27e11b17b337bfd022e8544b071a2641232047966fbda" dependencies = [ - "nix", + "nix 0.20.0", "once_cell", "smallvec", "wayland-sys", @@ -2391,20 +2182,20 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aad1b4301cdccfb5f64056a4736e8155a5f4734bac41fdbca80b1fdbe1ab3e1" +checksum = "be610084edd1586d45e7bdd275fe345c7c1873598caa464c4fb835dee70fa65a" dependencies = [ - "nix", + "nix 0.20.0", "wayland-client", "xcursor", ] [[package]] name = "wayland-protocols" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc16a9db803cae58b45f9a84a6cf364434cc49a95c8b1ef98ffeb467d228bdc9" +checksum = "286620ea4d803bacf61fa087a4242ee316693099ee5a140796aaba02b29f861f" dependencies = [ "bitflags", "wayland-client", @@ -2414,9 +2205,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee5bd43a1d746efc486515fec561e47205f328b74802b959f10f5500f7e56cc" +checksum = "ce923eb2deb61de332d1f356ec7b6bf37094dc5573952e1c8936db03b54c03f1" dependencies = [ "proc-macro2", "quote", @@ -2425,30 +2216,36 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.28.2" +version = "0.28.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0814adbecc7ea97869971e1d1c1b657e31863dda6fd768f119ad3dc408a01e58" +checksum = "d841fca9aed7febf9bed2e9796c49bf58d4152ceda8ac949ebe00868d8f0feb8" dependencies = [ - "dlib", + "dlib 0.5.0", "lazy_static", "pkg-config", ] [[package]] name = "web-sys" -version = "0.3.50" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" dependencies = [ "js-sys", "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e" + [[package]] name = "wgpu" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd247f8b26fd3d42ef2f320d378025cd6e84d782ef749fab45cc3b981fbe3275" +checksum = "3d92a4fe73b1e7d7ef99938dacd49258cbf1ad87cdb5bf6efa20c27447442b45" dependencies = [ "arrayvec", "js-sys", @@ -2462,29 +2259,21 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu-core", + "wgpu-hal", "wgpu-types", ] [[package]] name = "wgpu-core" -version = "0.9.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af5c8acd3ae5781a277cdf65a17f3a7135de5ae782775620e74ea16c9d47770" +checksum = "425b975c319d311e051bf3afb54120a34b187f9d889edc68e347567e512774c8" dependencies = [ "arrayvec", "bitflags", "cfg_aliases", "copyless", "fxhash", - "gfx-backend-dx11", - "gfx-backend-dx12", - "gfx-backend-empty", - "gfx-backend-gl", - "gfx-backend-metal", - "gfx-backend-vulkan", - "gfx-hal", - "gpu-alloc", - "gpu-descriptor", "log", "naga", "parking_lot", @@ -2494,9 +2283,44 @@ dependencies = [ "serde", "smallvec", "thiserror", + "wgpu-hal", "wgpu-types", ] +[[package]] +name = "wgpu-hal" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b33daf5eff68118c0aad030886655824052f82a164fd2e257211f742c6cade53" +dependencies = [ + "arrayvec", + "ash", + "bit-set", + "bitflags", + "block", + "core-graphics-types", + "d3d12", + "foreign-types", + "fxhash", + "glow", + "gpu-alloc", + "gpu-descriptor", + "inplace_it", + "khronos-egl", + "libloading 0.7.0", + "log", + "metal", + "naga", + "objc", + "parking_lot", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "thiserror", + "wgpu-types", + "winapi", +] + [[package]] name = "wgpu-subscriber" version = "0.1.0" @@ -2512,9 +2336,9 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5c9678cd533558e28b416d66947b099742df1939307478db54f867137f1b60" +checksum = "25feb2fbf24ab3219a9f10890ceb8e1ef02b13314ed89d64a9ae99dcad883e18" dependencies = [ "bitflags", "serde", @@ -2572,8 +2396,8 @@ checksum = "79610794594d5e86be473ef7763f604f2159cbac8c94debd00df8fb41e86c2f8" dependencies = [ "bitflags", "cocoa", - "core-foundation 0.9.0", - "core-graphics 0.22.1", + "core-foundation 0.9.1", + "core-graphics 0.22.2", "core-video-sys", "dispatch", "instant", @@ -2596,15 +2420,6 @@ dependencies = [ "x11-dl", ] -[[package]] -name = "wio" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" -dependencies = [ - "winapi", -] - [[package]] name = "x11-dl" version = "2.18.5" @@ -2619,9 +2434,9 @@ dependencies = [ [[package]] name = "xcursor" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a481cfdefd35e1c50073ae33a8000d695c98039544659f5dc5dd71311b0d01" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ "nom", ] @@ -2634,6 +2449,6 @@ checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" [[package]] name = "xml-rs" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" +checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" diff --git a/Cargo.toml b/Cargo.toml index 6bd08932..33549d3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,13 @@ [workspace] +resolver = "2" members = [ - # beginner tutorials + # # beginner tutorials "code/beginner/*", - # intermediate tutorials + # # intermediate tutorials "code/intermediate/*", - # showcase + # # showcase "code/showcase/*", ] exclude = [ diff --git a/code/beginner/tutorial1-window/Cargo.toml b/code/beginner/tutorial1-window/Cargo.toml index a4dff8e0..5cefb005 100644 --- a/code/beginner/tutorial1-window/Cargo.toml +++ b/code/beginner/tutorial1-window/Cargo.toml @@ -17,5 +17,5 @@ winit = "0.25" cgmath = "0.18" env_logger = "0.9" log = "0.4" -wgpu = "0.9" +wgpu = "0.10" pollster = "0.2" diff --git a/code/beginner/tutorial2-swapchain/Cargo.toml b/code/beginner/tutorial2-surface/Cargo.toml similarity index 62% rename from code/beginner/tutorial2-swapchain/Cargo.toml rename to code/beginner/tutorial2-surface/Cargo.toml index 8e6f739f..9da2acd2 100644 --- a/code/beginner/tutorial2-swapchain/Cargo.toml +++ b/code/beginner/tutorial2-surface/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tutorial2-swapchain" +name = "tutorial2-surface" version = "0.1.0" authors = ["Ben Hansen "] edition = "2018" @@ -12,12 +12,15 @@ winit = "0.25" cgmath = "0.18" env_logger = "0.9" log = "0.4" -wgpu = "0.9" +wgpu = "0.10" +# wgpu = { version = "0.10", features=["trace"]} +# wgpu = { git = "https://github.com/gfx-rs/wgpu/"} +# wgpu = { git = "https://github.com/gfx-rs/wgpu/", features=["trace"]} pollster = "0.2" [[bin]] -name = "tutorial2-swapchain" +name = "tutorial2-surface" path = "src/main.rs" [[bin]] diff --git a/code/beginner/tutorial2-swapchain/src/challenge.rs b/code/beginner/tutorial2-surface/src/challenge.rs similarity index 80% rename from code/beginner/tutorial2-swapchain/src/challenge.rs rename to code/beginner/tutorial2-surface/src/challenge.rs index 6b5e86f6..585f0bfd 100644 --- a/code/beginner/tutorial2-swapchain/src/challenge.rs +++ b/code/beginner/tutorial2-surface/src/challenge.rs @@ -7,11 +7,14 @@ use winit::{ }; struct State { + #[allow(dead_code)] + instance: wgpu::Instance, + #[allow(dead_code)] + adapter: wgpu::Adapter, surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, clear_color: wgpu::Color, } @@ -22,7 +25,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -44,26 +47,25 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let clear_color = wgpu::Color::BLACK; Self { + instance, + adapter, surface, device, queue, - sc_desc, - swap_chain, - + config, clear_color, - size, } } @@ -71,9 +73,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -94,8 +96,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -107,7 +112,7 @@ impl State { let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(self.clear_color), @@ -129,7 +134,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -165,10 +170,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial2-swapchain/src/main.rs b/code/beginner/tutorial2-surface/src/main.rs similarity index 80% rename from code/beginner/tutorial2-swapchain/src/main.rs rename to code/beginner/tutorial2-surface/src/main.rs index e93aa75e..ff0b5980 100644 --- a/code/beginner/tutorial2-swapchain/src/main.rs +++ b/code/beginner/tutorial2-surface/src/main.rs @@ -10,8 +10,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, } @@ -21,7 +20,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -38,26 +37,26 @@ impl State { features: wgpu::Features::empty(), limits: wgpu::Limits::default(), }, - None, // Trace path + // Some(&std::path::Path::new("trace")), // Trace path + None, ) .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); Self { surface, device, queue, - sc_desc, - swap_chain, + config, size, } } @@ -65,9 +64,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -78,8 +77,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -91,7 +93,7 @@ impl State { let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -118,7 +120,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state: State = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -155,10 +157,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial3-pipeline/Cargo.toml b/code/beginner/tutorial3-pipeline/Cargo.toml index 65fc9e93..11b4fdd6 100644 --- a/code/beginner/tutorial3-pipeline/Cargo.toml +++ b/code/beginner/tutorial3-pipeline/Cargo.toml @@ -10,7 +10,7 @@ winit = "0.25" cgmath = "0.18" env_logger = "0.9" log = "0.4" -wgpu = "0.9" +wgpu = "0.10" pollster = "0.2" # NEW! diff --git a/code/beginner/tutorial3-pipeline/src/challenge.rs b/code/beginner/tutorial3-pipeline/src/challenge.rs index 9c9ba440..aa014ae7 100644 --- a/code/beginner/tutorial3-pipeline/src/challenge.rs +++ b/code/beginner/tutorial3-pipeline/src/challenge.rs @@ -10,8 +10,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, challenge_render_pipeline: wgpu::RenderPipeline, @@ -24,7 +23,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -46,18 +45,17 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -80,12 +78,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -110,7 +108,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Challenge Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("challenge.wgsl").into()), }); @@ -127,9 +124,9 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState::REPLACE), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -155,8 +152,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, challenge_render_pipeline, use_color, @@ -167,9 +163,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -193,8 +189,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -206,7 +205,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -240,7 +239,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -276,10 +275,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial3-pipeline/src/main.rs b/code/beginner/tutorial3-pipeline/src/main.rs index 6c772284..43a8bc87 100644 --- a/code/beginner/tutorial3-pipeline/src/main.rs +++ b/code/beginner/tutorial3-pipeline/src/main.rs @@ -10,8 +10,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, // NEW! render_pipeline: wgpu::RenderPipeline, @@ -23,7 +22,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -45,18 +44,17 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -79,12 +77,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -112,8 +110,7 @@ impl State { device, queue, size, - sc_desc, - swap_chain, + config, render_pipeline, } } @@ -121,9 +118,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -134,8 +131,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -147,7 +147,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -177,7 +177,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -213,10 +213,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial4-buffer/Cargo.toml b/code/beginner/tutorial4-buffer/Cargo.toml index 6f7882ab..27a7f653 100644 --- a/code/beginner/tutorial4-buffer/Cargo.toml +++ b/code/beginner/tutorial4-buffer/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" image = "0.23" cgmath = "0.18" winit = "0.25" -wgpu = "0.9" +wgpu = "0.10" env_logger = "0.9" log = "0.4" pollster = "0.2" diff --git a/code/beginner/tutorial4-buffer/src/challenge.rs b/code/beginner/tutorial4-buffer/src/challenge.rs index 87b81a53..a4e420bc 100644 --- a/code/beginner/tutorial4-buffer/src/challenge.rs +++ b/code/beginner/tutorial4-buffer/src/challenge.rs @@ -18,7 +18,7 @@ impl Vertex { fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -64,8 +64,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, @@ -87,7 +86,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -109,18 +108,17 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -143,12 +141,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -174,12 +172,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -206,12 +204,12 @@ impl State { device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Challenge Vertex Buffer"), contents: bytemuck::cast_slice(&challenge_verts), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let challenge_index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Challenge Index Buffer"), contents: bytemuck::cast_slice(&challenge_indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let use_complex = false; @@ -220,8 +218,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, index_buffer, @@ -237,9 +234,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -263,8 +260,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -276,7 +276,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -319,7 +319,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -355,10 +355,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial4-buffer/src/main.rs b/code/beginner/tutorial4-buffer/src/main.rs index e58deb76..81ce6c49 100644 --- a/code/beginner/tutorial4-buffer/src/main.rs +++ b/code/beginner/tutorial4-buffer/src/main.rs @@ -18,7 +18,7 @@ impl Vertex { fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -64,8 +64,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, // NEW! @@ -80,7 +79,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -102,18 +101,17 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -136,12 +134,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -167,12 +165,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -180,8 +178,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -193,9 +190,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -206,8 +203,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -219,7 +219,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -251,7 +251,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -287,10 +287,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial5-textures/Cargo.toml b/code/beginner/tutorial5-textures/Cargo.toml index 03c4d6dd..bd97c515 100644 --- a/code/beginner/tutorial5-textures/Cargo.toml +++ b/code/beginner/tutorial5-textures/Cargo.toml @@ -14,7 +14,7 @@ env_logger = "0.9" log = "0.4" pollster = "0.2" image = "0.23" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/beginner/tutorial5-textures/src/challenge.rs b/code/beginner/tutorial5-textures/src/challenge.rs index 4ae8d423..e5250750 100644 --- a/code/beginner/tutorial5-textures/src/challenge.rs +++ b/code/beginner/tutorial5-textures/src/challenge.rs @@ -21,7 +21,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -67,8 +67,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -89,7 +88,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -110,21 +109,21 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -134,7 +133,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -186,7 +185,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -209,12 +207,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -240,12 +238,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -253,8 +251,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, index_buffer, @@ -271,9 +268,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -297,8 +294,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -310,7 +310,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -349,7 +349,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -385,10 +385,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial5-textures/src/main.rs b/code/beginner/tutorial5-textures/src/main.rs index 4b354ce6..09769344 100644 --- a/code/beginner/tutorial5-textures/src/main.rs +++ b/code/beginner/tutorial5-textures/src/main.rs @@ -21,7 +21,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -67,8 +67,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -86,7 +85,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -107,14 +106,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -125,7 +124,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -135,7 +134,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -163,7 +162,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -186,12 +184,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -217,12 +215,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -230,8 +228,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -245,9 +242,9 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } @@ -258,8 +255,11 @@ impl State { fn update(&mut self) {} - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -271,7 +271,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -304,7 +304,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -340,10 +340,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial5-textures/src/texture.rs b/code/beginner/tutorial5-textures/src/texture.rs index 7efe9bed..d6d61407 100644 --- a/code/beginner/tutorial5-textures/src/texture.rs +++ b/code/beginner/tutorial5-textures/src/texture.rs @@ -41,11 +41,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/beginner/tutorial6-uniforms/Cargo.toml b/code/beginner/tutorial6-uniforms/Cargo.toml index 8c67c325..05a3f032 100644 --- a/code/beginner/tutorial6-uniforms/Cargo.toml +++ b/code/beginner/tutorial6-uniforms/Cargo.toml @@ -12,7 +12,7 @@ env_logger = "0.9" log = "0.4" pollster = "0.2" image = "0.23" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/beginner/tutorial6-uniforms/src/challenge.rs b/code/beginner/tutorial6-uniforms/src/challenge.rs index 4c9a16b8..b3daa292 100644 --- a/code/beginner/tutorial6-uniforms/src/challenge.rs +++ b/code/beginner/tutorial6-uniforms/src/challenge.rs @@ -21,7 +21,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -228,8 +228,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, @@ -251,7 +250,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -272,14 +271,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -290,7 +289,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -300,7 +299,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -330,7 +329,7 @@ impl State { eye: (0.0, 1.0, 2.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -344,14 +343,14 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -373,7 +372,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -396,12 +394,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -427,12 +425,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -440,8 +438,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, index_buffer, @@ -460,12 +457,12 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); self.camera_staging.camera.aspect = - self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.config.width as f32 / self.config.height as f32; } } @@ -485,8 +482,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -498,7 +498,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -532,7 +532,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -568,10 +568,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial6-uniforms/src/main.rs b/code/beginner/tutorial6-uniforms/src/main.rs index 9c4103ea..19995251 100644 --- a/code/beginner/tutorial6-uniforms/src/main.rs +++ b/code/beginner/tutorial6-uniforms/src/main.rs @@ -21,7 +21,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -212,8 +212,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -236,7 +235,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -257,14 +256,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -275,7 +274,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -285,7 +284,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -315,7 +314,7 @@ impl State { eye: (0.0, 1.0, 2.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -328,14 +327,14 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -357,7 +356,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -380,12 +378,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -411,12 +409,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -424,8 +422,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -444,11 +441,11 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; } } @@ -466,8 +463,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -479,7 +479,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -513,7 +513,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -549,10 +549,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial6-uniforms/src/texture.rs b/code/beginner/tutorial6-uniforms/src/texture.rs index 7efe9bed..d6d61407 100644 --- a/code/beginner/tutorial6-uniforms/src/texture.rs +++ b/code/beginner/tutorial6-uniforms/src/texture.rs @@ -41,11 +41,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/beginner/tutorial7-instancing/Cargo.toml b/code/beginner/tutorial7-instancing/Cargo.toml index b5f82d51..260bd44d 100644 --- a/code/beginner/tutorial7-instancing/Cargo.toml +++ b/code/beginner/tutorial7-instancing/Cargo.toml @@ -12,7 +12,7 @@ env_logger = "0.9" log = "0.4" pollster = "0.2" image = "0.23" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/beginner/tutorial7-instancing/src/challenge.rs b/code/beginner/tutorial7-instancing/src/challenge.rs index 9aa9bafa..6dd2a072 100644 --- a/code/beginner/tutorial7-instancing/src/challenge.rs +++ b/code/beginner/tutorial7-instancing/src/challenge.rs @@ -22,7 +22,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -245,7 +245,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -280,8 +280,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, @@ -333,7 +332,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -354,14 +353,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -372,7 +371,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -382,7 +381,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -412,7 +411,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -425,7 +424,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let instances = (0..NUM_INSTANCES_PER_ROW) @@ -457,14 +456,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -486,7 +485,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -509,12 +507,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -540,12 +538,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -553,8 +551,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, index_buffer, @@ -575,11 +572,11 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; } } @@ -613,8 +610,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -626,7 +626,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -661,7 +661,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -697,10 +697,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial7-instancing/src/main.rs b/code/beginner/tutorial7-instancing/src/main.rs index 9a5f40af..3657dabc 100644 --- a/code/beginner/tutorial7-instancing/src/main.rs +++ b/code/beginner/tutorial7-instancing/src/main.rs @@ -29,7 +29,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -235,7 +235,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -270,8 +270,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -297,7 +296,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -318,14 +317,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -336,7 +335,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -346,7 +345,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -376,7 +375,7 @@ impl State { eye: (0.0, 5.0, 10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -389,7 +388,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let instances = (0..NUM_INSTANCES_PER_ROW) @@ -421,14 +420,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -450,7 +449,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -473,12 +471,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -504,12 +502,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -517,8 +515,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -540,11 +537,11 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; } } @@ -562,8 +559,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -575,7 +575,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -611,7 +611,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -647,10 +647,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial7-instancing/src/texture.rs b/code/beginner/tutorial7-instancing/src/texture.rs index 7efe9bed..d6d61407 100644 --- a/code/beginner/tutorial7-instancing/src/texture.rs +++ b/code/beginner/tutorial7-instancing/src/texture.rs @@ -41,11 +41,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/beginner/tutorial8-depth/Cargo.toml b/code/beginner/tutorial8-depth/Cargo.toml index 4d110474..00e883ce 100644 --- a/code/beginner/tutorial8-depth/Cargo.toml +++ b/code/beginner/tutorial8-depth/Cargo.toml @@ -12,7 +12,7 @@ env_logger = "0.9" pollster = "0.2" image = "0.23" log = "0.4" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/beginner/tutorial8-depth/src/challenge.rs b/code/beginner/tutorial8-depth/src/challenge.rs index ce7f8f9b..afe47e06 100644 --- a/code/beginner/tutorial8-depth/src/challenge.rs +++ b/code/beginner/tutorial8-depth/src/challenge.rs @@ -22,7 +22,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -266,7 +266,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -308,8 +308,8 @@ struct DepthPass { } impl DepthPass { - fn new(device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) -> Self { - let texture = texture::Texture::create_depth_texture(device, sc_desc, "depth_texture"); + fn new(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> Self { + let texture = texture::Texture::create_depth_texture(device, config, "depth_texture"); let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: Some("Depth Pass Layout"), @@ -322,7 +322,7 @@ impl DepthPass { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, }, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, }, wgpu::BindGroupLayoutEntry { binding: 1, @@ -331,7 +331,7 @@ impl DepthPass { comparison: true, filtering: true, }, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, }, ], }); @@ -354,12 +354,12 @@ impl DepthPass { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Depth Pass VB"), contents: bytemuck::cast_slice(DEPTH_VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Depth Pass IB"), contents: bytemuck::cast_slice(DEPTH_INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -370,7 +370,6 @@ impl DepthPass { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shadow Display Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("challenge.wgsl").into()), }); @@ -386,12 +385,12 @@ impl DepthPass { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -425,8 +424,8 @@ impl DepthPass { } } - fn resize(&mut self, device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor) { - self.texture = texture::Texture::create_depth_texture(device, sc_desc, "depth_texture"); + fn resize(&mut self, device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) { + self.texture = texture::Texture::create_depth_texture(device, config, "depth_texture"); self.bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { layout: &self.layout, entries: &[ @@ -443,11 +442,11 @@ impl DepthPass { }); } - fn render(&self, frame: &wgpu::SwapChainTexture, encoder: &mut wgpu::CommandEncoder) { + fn render(&self, view: &wgpu::TextureView, encoder: &mut wgpu::CommandEncoder) { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Depth Visual Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, @@ -468,8 +467,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, @@ -495,7 +493,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -516,14 +514,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -534,7 +532,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -544,7 +542,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -574,7 +572,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -587,7 +585,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let instances = (0..NUM_INSTANCES_PER_ROW) @@ -619,14 +617,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -648,7 +646,6 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); @@ -671,12 +668,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -712,23 +709,22 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; - let depth_pass = DepthPass::new(&device, &sc_desc); + let depth_pass = DepthPass::new(&device, &config); Self { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, index_buffer, @@ -749,13 +745,13 @@ impl State { pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; + self.config.width = new_size.width; + self.config.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_pass.resize(&self.device, &self.sc_desc); + self.surface.configure(&self.device, &self.config); + self.depth_pass.resize(&self.device, &self.config); - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; } } @@ -773,8 +769,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -786,7 +785,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -817,7 +816,7 @@ impl State { render_pass.draw_indexed(0..self.num_indices, 0, 0..self.instances.len() as u32); } - self.depth_pass.render(&frame, &mut encoder); + self.depth_pass.render(&view, &mut encoder); self.queue.submit(iter::once(encoder.finish())); @@ -830,7 +829,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -866,10 +865,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial8-depth/src/main.rs b/code/beginner/tutorial8-depth/src/main.rs index e87d7393..c4598733 100644 --- a/code/beginner/tutorial8-depth/src/main.rs +++ b/code/beginner/tutorial8-depth/src/main.rs @@ -22,7 +22,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -244,7 +244,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -279,8 +279,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -307,7 +306,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -328,14 +327,14 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); let diffuse_texture = @@ -346,7 +345,7 @@ impl State { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -356,7 +355,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -386,7 +385,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -399,7 +398,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let instances = (0..NUM_INSTANCES_PER_ROW) @@ -431,14 +430,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -460,12 +459,11 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -486,12 +484,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -523,12 +521,12 @@ impl State { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); let num_indices = INDICES.len() as u32; @@ -536,8 +534,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -559,16 +556,13 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.camera.aspect = self.config.width as f32 / self.config.height as f32; // NEW! - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -586,8 +580,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -599,7 +596,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -640,7 +637,7 @@ fn main() { let event_loop = EventLoop::new(); let window = WindowBuilder::new().build(&event_loop).unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -676,10 +673,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial8-depth/src/texture.rs b/code/beginner/tutorial8-depth/src/texture.rs index b322089c..dfd9e83c 100644 --- a/code/beginner/tutorial8-depth/src/texture.rs +++ b/code/beginner/tutorial8-depth/src/texture.rs @@ -14,12 +14,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -29,7 +29,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -84,11 +84,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/beginner/tutorial9-models/Cargo.toml b/code/beginner/tutorial9-models/Cargo.toml index c12e7b26..7aa8e33f 100644 --- a/code/beginner/tutorial9-models/Cargo.toml +++ b/code/beginner/tutorial9-models/Cargo.toml @@ -13,7 +13,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "3.0" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/beginner/tutorial9-models/src/main.rs b/code/beginner/tutorial9-models/src/main.rs index 2454eebc..50f21466 100644 --- a/code/beginner/tutorial9-models/src/main.rs +++ b/code/beginner/tutorial9-models/src/main.rs @@ -188,7 +188,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -223,8 +223,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, @@ -245,7 +244,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -267,22 +266,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -292,7 +291,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -307,7 +306,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -320,7 +319,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -350,14 +349,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -386,16 +385,13 @@ impl State { ) .unwrap(); - // let vs_module = device.create_shader_module(&wgpu::include_spirv!("shader.vert.spv")); - // let fs_module = device.create_shader_module(&wgpu::include_spirv!("shader.frag.spv")); let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("shader.wgsl"), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), - flags: wgpu::ShaderFlags::VALIDATION, }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -416,12 +412,12 @@ impl State { module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -454,8 +450,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, obj_model, @@ -472,16 +467,13 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } fn input(&mut self, event: &WindowEvent) -> bool { @@ -498,8 +490,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -511,7 +506,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -557,7 +552,7 @@ fn main() { .build(&event_loop) .unwrap(); - // Since main can't be async, we're going to need to block + // State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); event_loop.run(move |event, _, control_flow| { @@ -594,10 +589,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/beginner/tutorial9-models/src/model.rs b/code/beginner/tutorial9-models/src/model.rs index fea72c52..a4f933e5 100644 --- a/code/beginner/tutorial9-models/src/model.rs +++ b/code/beginner/tutorial9-models/src/model.rs @@ -23,7 +23,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -135,12 +135,12 @@ impl Model { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/beginner/tutorial9-models/src/texture.rs b/code/beginner/tutorial9-models/src/texture.rs index f3376b3e..16c5910d 100644 --- a/code/beginner/tutorial9-models/src/texture.rs +++ b/code/beginner/tutorial9-models/src/texture.rs @@ -26,12 +26,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -41,7 +41,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -83,7 +83,7 @@ impl Texture { label: Option<&str>, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -97,11 +97,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/intermediate/tutorial10-lighting/Cargo.toml b/code/intermediate/tutorial10-lighting/Cargo.toml index cceaa11b..8380cb60 100644 --- a/code/intermediate/tutorial10-lighting/Cargo.toml +++ b/code/intermediate/tutorial10-lighting/Cargo.toml @@ -13,7 +13,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "3.0" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/intermediate/tutorial10-lighting/src/main.rs b/code/intermediate/tutorial10-lighting/src/main.rs index 5b31c9bf..202f8507 100644 --- a/code/intermediate/tutorial10-lighting/src/main.rs +++ b/code/intermediate/tutorial10-lighting/src/main.rs @@ -194,7 +194,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -253,8 +253,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: Camera, @@ -300,7 +299,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -336,7 +335,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -357,22 +356,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -382,7 +381,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -397,7 +396,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -411,7 +410,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -441,14 +440,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -486,14 +485,14 @@ impl State { let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -514,7 +513,7 @@ impl State { }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -530,13 +529,12 @@ impl State { let render_pipeline = { let shader = wgpu::ShaderModuleDescriptor { label: Some("Normal Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }; create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], shader, @@ -551,13 +549,12 @@ impl State { }); let shader = wgpu::ShaderModuleDescriptor { label: Some("Light Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()), }; create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], shader, @@ -568,8 +565,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, obj_model, camera, @@ -590,16 +586,13 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -629,8 +622,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -642,7 +638,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -729,10 +725,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/intermediate/tutorial10-lighting/src/model.rs b/code/intermediate/tutorial10-lighting/src/model.rs index 346ff457..3ad125c4 100644 --- a/code/intermediate/tutorial10-lighting/src/model.rs +++ b/code/intermediate/tutorial10-lighting/src/model.rs @@ -23,7 +23,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -135,12 +135,12 @@ impl Model { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/intermediate/tutorial10-lighting/src/texture.rs b/code/intermediate/tutorial10-lighting/src/texture.rs index f3376b3e..16c5910d 100644 --- a/code/intermediate/tutorial10-lighting/src/texture.rs +++ b/code/intermediate/tutorial10-lighting/src/texture.rs @@ -26,12 +26,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -41,7 +41,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -83,7 +83,7 @@ impl Texture { label: Option<&str>, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -97,11 +97,12 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/intermediate/tutorial11-normals/Cargo.toml b/code/intermediate/tutorial11-normals/Cargo.toml index 1a10b700..3b8b7dfa 100644 --- a/code/intermediate/tutorial11-normals/Cargo.toml +++ b/code/intermediate/tutorial11-normals/Cargo.toml @@ -13,7 +13,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "3.0" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/intermediate/tutorial11-normals/src/main.rs b/code/intermediate/tutorial11-normals/src/main.rs index 939625bf..36146949 100644 --- a/code/intermediate/tutorial11-normals/src/main.rs +++ b/code/intermediate/tutorial11-normals/src/main.rs @@ -193,7 +193,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -252,8 +252,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: Camera, @@ -301,7 +300,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -337,7 +336,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -358,22 +357,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -383,7 +382,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -393,7 +392,7 @@ impl State { // normal map wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -403,7 +402,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -418,7 +417,7 @@ impl State { eye: (0.0, 5.0, -10.0).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -432,7 +431,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -462,14 +461,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -507,14 +506,14 @@ impl State { let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -535,7 +534,7 @@ impl State { }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -551,13 +550,12 @@ impl State { let render_pipeline = { let shader = wgpu::ShaderModuleDescriptor { label: Some("Normal Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }; create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], shader, @@ -572,13 +570,12 @@ impl State { }); let shader = wgpu::ShaderModuleDescriptor { label: Some("Light Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()), }; create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], shader, @@ -619,8 +616,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, obj_model, camera, @@ -643,16 +639,13 @@ impl State { fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { - self.camera.aspect = self.sc_desc.width as f32 / self.sc_desc.height as f32; + self.camera.aspect = self.config.width as f32 / self.config.height as f32; self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -682,8 +675,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -695,7 +691,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -782,10 +778,10 @@ fn main() { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/intermediate/tutorial11-normals/src/model.rs b/code/intermediate/tutorial11-normals/src/model.rs index 9de46d6a..968dfa8a 100644 --- a/code/intermediate/tutorial11-normals/src/model.rs +++ b/code/intermediate/tutorial11-normals/src/model.rs @@ -26,7 +26,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -256,12 +256,12 @@ impl Model { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/intermediate/tutorial11-normals/src/texture.rs b/code/intermediate/tutorial11-normals/src/texture.rs index 30f15da5..0272cc8b 100644 --- a/code/intermediate/tutorial11-normals/src/texture.rs +++ b/code/intermediate/tutorial11-normals/src/texture.rs @@ -27,12 +27,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -42,7 +42,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -86,7 +86,7 @@ impl Texture { is_normal_map: bool, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -104,11 +104,12 @@ impl Texture { } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/intermediate/tutorial12-camera/Cargo.toml b/code/intermediate/tutorial12-camera/Cargo.toml index 39e24395..a7aaa6e8 100644 --- a/code/intermediate/tutorial12-camera/Cargo.toml +++ b/code/intermediate/tutorial12-camera/Cargo.toml @@ -13,7 +13,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "3.0" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/intermediate/tutorial12-camera/src/main.rs b/code/intermediate/tutorial12-camera/src/main.rs index 8e677bae..ecc1452a 100644 --- a/code/intermediate/tutorial12-camera/src/main.rs +++ b/code/intermediate/tutorial12-camera/src/main.rs @@ -70,7 +70,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -129,8 +129,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: camera::Camera, // UPDATED! @@ -181,7 +180,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -217,7 +216,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -238,22 +237,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -263,7 +262,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -273,7 +272,7 @@ impl State { // normal map wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -283,7 +282,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -297,7 +296,7 @@ impl State { // UPDATED! let camera = camera::Camera::new((0.0, 5.0, 10.0), cgmath::Deg(-90.0), cgmath::Deg(-20.0)); let projection = - camera::Projection::new(sc_desc.width, sc_desc.height, cgmath::Deg(45.0), 0.1, 100.0); + camera::Projection::new(config.width, config.height, cgmath::Deg(45.0), 0.1, 100.0); let camera_controller = camera::CameraController::new(4.0, 0.4); let mut camera_uniform = CameraUniform::new(); @@ -306,7 +305,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -336,14 +335,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -383,14 +382,14 @@ impl State { let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -411,7 +410,7 @@ impl State { }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -427,13 +426,12 @@ impl State { let render_pipeline = { let shader = wgpu::ShaderModuleDescriptor { label: Some("Normal Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }; create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], shader, @@ -448,13 +446,12 @@ impl State { }); let shader = wgpu::ShaderModuleDescriptor { label: Some("Light Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()), }; create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], shader, @@ -495,8 +492,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, obj_model, camera, @@ -525,14 +521,11 @@ impl State { if new_size.width > 0 && new_size.height > 0 { self.projection.resize(new_size.width, new_size.height); self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -589,8 +582,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -602,7 +598,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -699,10 +695,10 @@ fn main() { state.update(dt); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/intermediate/tutorial12-camera/src/model.rs b/code/intermediate/tutorial12-camera/src/model.rs index 9de46d6a..968dfa8a 100644 --- a/code/intermediate/tutorial12-camera/src/model.rs +++ b/code/intermediate/tutorial12-camera/src/model.rs @@ -26,7 +26,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -256,12 +256,12 @@ impl Model { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/intermediate/tutorial12-camera/src/texture.rs b/code/intermediate/tutorial12-camera/src/texture.rs index 30f15da5..0272cc8b 100644 --- a/code/intermediate/tutorial12-camera/src/texture.rs +++ b/code/intermediate/tutorial12-camera/src/texture.rs @@ -27,12 +27,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -42,7 +42,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -86,7 +86,7 @@ impl Texture { is_normal_map: bool, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -104,11 +104,12 @@ impl Texture { } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/intermediate/tutorial13-threading/Cargo.toml b/code/intermediate/tutorial13-threading/Cargo.toml index cb2949a5..1f6904f3 100644 --- a/code/intermediate/tutorial13-threading/Cargo.toml +++ b/code/intermediate/tutorial13-threading/Cargo.toml @@ -14,7 +14,7 @@ image = "0.23" log = "0.4" rayon = "1.4" # NEW! tobj = "3.0" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" [build-dependencies] diff --git a/code/intermediate/tutorial13-threading/src/main.rs b/code/intermediate/tutorial13-threading/src/main.rs index f1c52751..d58e47c0 100644 --- a/code/intermediate/tutorial13-threading/src/main.rs +++ b/code/intermediate/tutorial13-threading/src/main.rs @@ -70,7 +70,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -129,8 +129,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: camera::Camera, @@ -180,7 +179,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -216,7 +215,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -237,22 +236,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -262,7 +261,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -272,7 +271,7 @@ impl State { // normal map wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -282,7 +281,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -296,7 +295,7 @@ impl State { // UPDATED! let camera = camera::Camera::new((0.0, 5.0, 10.0), cgmath::Deg(-90.0), cgmath::Deg(-20.0)); let projection = - camera::Projection::new(sc_desc.width, sc_desc.height, cgmath::Deg(45.0), 0.1, 100.0); + camera::Projection::new(config.width, config.height, cgmath::Deg(45.0), 0.1, 100.0); let camera_controller = camera::CameraController::new(4.0, 0.4); let mut camera_uniform = CameraUniform::new(); @@ -305,7 +304,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -337,14 +336,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -382,14 +381,14 @@ impl State { let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -410,7 +409,7 @@ impl State { }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -426,13 +425,12 @@ impl State { let render_pipeline = { let shader = wgpu::ShaderModuleDescriptor { label: Some("Normal Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), }; create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], shader, @@ -447,13 +445,12 @@ impl State { }); let shader = wgpu::ShaderModuleDescriptor { label: Some("Light Shader"), - flags: wgpu::ShaderFlags::all(), source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()), }; create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], shader, @@ -494,8 +491,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, obj_model, camera, @@ -522,14 +518,11 @@ impl State { if new_size.width > 0 && new_size.height > 0 { self.projection.resize(new_size.width, new_size.height); self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -584,8 +577,11 @@ impl State { ); } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self.swap_chain.get_current_frame()?.output; + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self .device @@ -597,7 +593,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -692,10 +688,10 @@ fn main() { state.update(dt); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } diff --git a/code/intermediate/tutorial13-threading/src/model.rs b/code/intermediate/tutorial13-threading/src/model.rs index 9de46d6a..968dfa8a 100644 --- a/code/intermediate/tutorial13-threading/src/model.rs +++ b/code/intermediate/tutorial13-threading/src/model.rs @@ -26,7 +26,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -256,12 +256,12 @@ impl Model { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/intermediate/tutorial13-threading/src/texture.rs b/code/intermediate/tutorial13-threading/src/texture.rs index 30f15da5..0272cc8b 100644 --- a/code/intermediate/tutorial13-threading/src/texture.rs +++ b/code/intermediate/tutorial13-threading/src/texture.rs @@ -27,12 +27,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -42,7 +42,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -86,7 +86,7 @@ impl Texture { is_normal_map: bool, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -104,11 +104,12 @@ impl Texture { } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/showcase/compute/Cargo.toml b/code/showcase/compute/Cargo.toml index 4c4afb5f..a08ec248 100644 --- a/code/showcase/compute/Cargo.toml +++ b/code/showcase/compute/Cargo.toml @@ -14,7 +14,7 @@ image = "0.23" log = "0.4" rayon = "1.4" tobj = "2.0" -wgpu = { version = "0.9", features = ["trace"] } +wgpu = { version = "0.10", features = ["trace", "spirv"] } winit = "0.25" [build-dependencies] @@ -22,4 +22,4 @@ anyhow = "1.0" fs_extra = "1.2" glob = "0.3" rayon = "1.4" -shaderc = "0.7" \ No newline at end of file +naga = { version = "0.6", features = ["glsl-in", "spv-out", "wgsl-out"]} \ No newline at end of file diff --git a/code/showcase/compute/build.rs b/code/showcase/compute/build.rs index 57a1af5e..dcd07590 100644 --- a/code/showcase/compute/build.rs +++ b/code/showcase/compute/build.rs @@ -2,42 +2,62 @@ use anyhow::*; use fs_extra::copy_items; use fs_extra::dir::CopyOptions; use glob::glob; +use naga::back::wgsl; +use naga::front::glsl::Options; +use naga::front::glsl::Parser; use rayon::prelude::*; use std::env; -use std::fs::{read_to_string, write}; -use std::path::PathBuf; +use std::{fs::read_to_string, path::PathBuf}; -struct ShaderData { - src: String, - src_path: PathBuf, - spv_path: PathBuf, - kind: shaderc::ShaderKind, -} +pub fn load_shader(src_path: PathBuf) -> Result<()> { + let extension = src_path + .extension() + .context("File has no extension")? + .to_str() + .context("Extension cannot be converted to &str")?; + let kind = match extension { + "vert" => naga::ShaderStage::Vertex, + "frag" => naga::ShaderStage::Fragment, + "comp" => naga::ShaderStage::Compute, + _ => bail!("Unsupported shader: {}", src_path.display()), + }; + + let src = read_to_string(src_path.clone())?; + // let spv_path = src_path.with_extension(format!("{}.spv", extension)); + let wgsl_path = src_path.with_extension(format!("{}.wgsl", extension)); -impl ShaderData { - pub fn load(src_path: PathBuf) -> Result { - let extension = src_path - .extension() - .context("File has no extension")? - .to_str() - .context("Extension cannot be converted to &str")?; - let kind = match extension { - "vert" => shaderc::ShaderKind::Vertex, - "frag" => shaderc::ShaderKind::Fragment, - "comp" => shaderc::ShaderKind::Compute, - _ => bail!("Unsupported shader: {}", src_path.display()), - }; + let mut parser = Parser::default(); + let options = Options::from(kind); + let module = match parser.parse(&options, &src) { + Ok(it) => it, + Err(errors) => { + bail!( + "Failed to compile shader: {}\nErrors:\n{:#?}", + src_path.display(), + errors + ); + } + }; - let src = read_to_string(src_path.clone())?; - let spv_path = src_path.with_extension(format!("{}.spv", extension)); + let info = naga::valid::Validator::new( + naga::valid::ValidationFlags::all(), + naga::valid::Capabilities::empty(), + ) + .validate(&module)?; + std::fs::write(wgsl_path, wgsl::write_string(&module, &info)?)?; - Ok(Self { - src, - src_path, - spv_path, - kind, - }) - } + // let flags = spv::WriterFlags::DEBUG | spv::WriterFlags::ADJUST_COORDINATE_SPACE; + // let options = spv::Options { + // flags, + // ..Default::default() + // }; + // let spv = spv::write_vec(&module, &info, &options)?; + // let dis = rspirv::dr::load_words(spv) + // .expect("Unable to disassemble shader") + // .disassemble(); + // std::fs::write(spv_path, &spv)?; + + Ok(()) } fn main() -> Result<()> { @@ -46,45 +66,30 @@ fn main() -> Result<()> { // Collect all shaders recursively within /src/ // UDPATED! - let mut shader_paths = Vec::new(); - shader_paths.extend(glob("./src/**/*.vert")?); - shader_paths.extend(glob("./src/**/*.frag")?); - shader_paths.extend(glob("./src/**/*.comp")?); + let shader_paths = { + let mut data = Vec::new(); + data.extend(glob("./src/**/*.vert")?); + data.extend(glob("./src/**/*.frag")?); + data.extend(glob("./src/**/*.comp")?); + data + }; // UPDATED! // This is parallelized - let shaders = shader_paths + shader_paths .into_par_iter() - .map(|glob_result| ShaderData::load(glob_result?)) + .map(|glob_result| load_shader(glob_result?)) .collect::>>() .into_iter() - .collect::>>(); - - let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?; - - // This can't be parallelized. The [shaderc::Compiler] is not - // thread safe. Also, it creates a lot of resources. You could - // spawn multiple processes to handle this, but it would probably - // be better just to only compile shaders that have been changed - // recently. - for shader in shaders? { - let compiled = compiler.compile_into_spirv( - &shader.src, - shader.kind, - shader.src_path.to_str().unwrap(), - "main", - None, - )?; - write(shader.spv_path, compiled.as_binary_u8())?; - } + .collect::>>()?; // This tells cargo to rerun this script if something in /res/ changes. println!("cargo:rerun-if-changed=res/*"); let out_dir = env::var("OUT_DIR")?; let mut copy_options = CopyOptions::new(); - copy_options.overwrite = true; let mut paths_to_copy = Vec::new(); + copy_options.overwrite = true; paths_to_copy.push("res/"); copy_items(&paths_to_copy, out_dir, ©_options)?; diff --git a/code/showcase/compute/src/light.frag.spv b/code/showcase/compute/src/light.frag.spv deleted file mode 100644 index 199e2f43..00000000 Binary files a/code/showcase/compute/src/light.frag.spv and /dev/null differ diff --git a/code/showcase/compute/src/light.frag.wgsl b/code/showcase/compute/src/light.frag.wgsl new file mode 100644 index 00000000..9f7281a4 --- /dev/null +++ b/code/showcase/compute/src/light.frag.wgsl @@ -0,0 +1,20 @@ +struct FragmentOutput { + [[location(0)]] f_color: vec4; +}; + +var v_color1: vec3; +var f_color: vec4; + +fn main1() { + let _e2: vec3 = v_color1; + f_color = vec4(_e2, 1.0); + return; +} + +[[stage(fragment)]] +fn main([[location(0)]] v_color: vec3) -> FragmentOutput { + v_color1 = v_color; + main1(); + let _e7: vec4 = f_color; + return FragmentOutput(_e7); +} diff --git a/code/showcase/compute/src/light.vert.spv b/code/showcase/compute/src/light.vert.spv deleted file mode 100644 index cd8b0cd9..00000000 Binary files a/code/showcase/compute/src/light.vert.spv and /dev/null differ diff --git a/code/showcase/compute/src/light.vert.wgsl b/code/showcase/compute/src/light.vert.wgsl new file mode 100644 index 00000000..a319998a --- /dev/null +++ b/code/showcase/compute/src/light.vert.wgsl @@ -0,0 +1,49 @@ +[[block]] +struct Camera { + u_view_position: vec3; + u_view_proj: mat4x4; +}; + +[[block]] +struct Light { + u_position: vec3; + u_color: vec3; +}; + +struct VertexOutput { + [[location(0)]] v_color: vec3; + [[builtin(position)]] member: vec4; +}; + +var a_position1: vec3; +var v_color: vec3; +[[group(0), binding(0)]] +var global: Camera; +[[group(1), binding(0)]] +var global1: Light; +var scale: f32 = 0.25; +var gl_Position: vec4; + +fn main1() { + var v_position: vec3; + + let _e11: vec3 = a_position1; + let _e12: f32 = scale; + let _e14: vec3 = global1.u_position; + v_position = ((_e11 * _e12) + _e14); + let _e18: mat4x4 = global.u_view_proj; + let _e19: vec3 = v_position; + gl_Position = (_e18 * vec4(_e19, f32(1))); + let _e24: vec3 = global1.u_color; + v_color = _e24; + return; +} + +[[stage(vertex)]] +fn main([[location(0)]] a_position: vec3) -> VertexOutput { + a_position1 = a_position; + main1(); + let _e18: vec3 = v_color; + let _e20: vec4 = gl_Position; + return VertexOutput(_e18, _e20); +} diff --git a/code/showcase/compute/src/main.rs b/code/showcase/compute/src/main.rs index fce9d1d0..1ab035d0 100644 --- a/code/showcase/compute/src/main.rs +++ b/code/showcase/compute/src/main.rs @@ -52,15 +52,17 @@ impl Instance { model: (cgmath::Matrix4::from_translation(self.position) * cgmath::Matrix4::from(self.rotation)) .into(), + normal: cgmath::Matrix3::from(self.rotation).into(), } } } #[repr(C)] #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +#[allow(dead_code)] struct InstanceRaw { - #[allow(dead_code)] model: [[f32; 4]; 4], + normal: [[f32; 3]; 3], } impl model::Vertex for InstanceRaw { @@ -71,7 +73,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -97,6 +99,21 @@ impl model::Vertex for InstanceRaw { shader_location: 8, format: wgpu::VertexFormat::Float32x4, }, + wgpu::VertexAttribute { + offset: mem::size_of::<[f32; 16]>() as wgpu::BufferAddress, + shader_location: 9, + format: wgpu::VertexFormat::Float32x3, + }, + wgpu::VertexAttribute { + offset: mem::size_of::<[f32; 19]>() as wgpu::BufferAddress, + shader_location: 10, + format: wgpu::VertexFormat::Float32x3, + }, + wgpu::VertexAttribute { + offset: mem::size_of::<[f32; 22]>() as wgpu::BufferAddress, + shader_location: 11, + format: wgpu::VertexFormat::Float32x3, + }, ], } } @@ -115,8 +132,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, obj_model: model::Model, camera: camera::Camera, @@ -146,7 +162,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -168,22 +184,22 @@ impl State { .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -193,7 +209,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -203,7 +219,7 @@ impl State { // normal map wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -213,7 +229,7 @@ impl State { }, wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -227,7 +243,7 @@ impl State { // UPDATED! let camera = camera::Camera::new((0.0, 5.0, 10.0), cgmath::Deg(-90.0), cgmath::Deg(-20.0)); let projection = - camera::Projection::new(sc_desc.width, sc_desc.height, cgmath::Deg(45.0), 0.1, 100.0); + camera::Projection::new(config.width, config.height, cgmath::Deg(45.0), 0.1, 100.0); let camera_controller = camera::CameraController::new(4.0, 0.4); let mut camera_uniform = CameraUniform::new(); @@ -236,7 +252,7 @@ impl State { let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); const SPACE_BETWEEN: f32 = 3.0; @@ -268,14 +284,14 @@ impl State { let instance_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -317,14 +333,14 @@ impl State { let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -345,7 +361,7 @@ impl State { }); let depth_texture = - texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); + texture::Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -358,16 +374,18 @@ impl State { push_constant_ranges: &[], }); + println!("Creating RENDER pipeline"); let render_pipeline = create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], - wgpu::include_spirv!("shader.vert.spv"), - wgpu::include_spirv!("shader.frag.spv"), + wgpu::include_wgsl!("shader.vert.wgsl"), + wgpu::include_wgsl!("shader.frag.wgsl"), ); + println!("Creating LIGHT pipeline"); let light_render_pipeline = { let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Light Pipeline Layout"), @@ -378,11 +396,11 @@ impl State { create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], - wgpu::include_spirv!("light.vert.spv"), - wgpu::include_spirv!("light.frag.spv"), + wgpu::include_wgsl!("light.vert.wgsl"), + wgpu::include_wgsl!("light.frag.wgsl"), ) }; @@ -420,8 +438,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, obj_model, camera, @@ -449,14 +466,11 @@ impl State { if new_size.width > 0 && new_size.height > 0 { self.projection.resize(new_size.width, new_size.height); self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); - self.depth_texture = texture::Texture::create_depth_texture( - &self.device, - &self.sc_desc, - "depth_texture", - ); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); + self.depth_texture = + texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } } @@ -520,11 +534,14 @@ impl State { } fn render(&mut self) { - let frame = self.swap_chain.get_current_frame(); + let frame = self.surface.get_current_frame(); match frame { Ok(frame) => { - let frame = frame.output; + let output = frame.output; + let view = output + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = self.device .create_command_encoder(&wgpu::CommandEncoderDescriptor { @@ -535,7 +552,7 @@ impl State { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { diff --git a/code/showcase/compute/src/model.rs b/code/showcase/compute/src/model.rs index 2a8b1e33..761dbdb2 100644 --- a/code/showcase/compute/src/model.rs +++ b/code/showcase/compute/src/model.rs @@ -27,7 +27,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -141,7 +141,7 @@ impl pipeline::Bindable for BitangentComputeBinding { // We use these vertices to compute the tangent and bitangent wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::COMPUTE, + visibility: wgpu::ShaderStages::COMPUTE, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Storage { read_only: true }, has_dynamic_offset: false, @@ -153,7 +153,7 @@ impl pipeline::Bindable for BitangentComputeBinding { // We'll store the computed tangent and bitangent here wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::COMPUTE, + visibility: wgpu::ShaderStages::COMPUTE, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Storage { // We will change the values in this buffer @@ -167,7 +167,7 @@ impl pipeline::Bindable for BitangentComputeBinding { // Indices wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::COMPUTE, + visibility: wgpu::ShaderStages::COMPUTE, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Storage { // We won't change the indices @@ -181,7 +181,7 @@ impl pipeline::Bindable for BitangentComputeBinding { // ComputeInfo wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::COMPUTE, + visibility: wgpu::ShaderStages::COMPUTE, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -232,8 +232,9 @@ pub struct ModelLoader { impl ModelLoader { // NEW! pub fn new(device: &wgpu::Device) -> Self { + println!("Creating MODELLOADER pipeline"); let binder = pipeline::Binder::new(device, Some("ModelLoader Binder")); - let shader_src = wgpu::include_spirv!("model_load.comp.spv"); + let shader_src = wgpu::include_wgsl!("model_load.comp.wgsl"); let pipeline = pipeline::create_compute_pipeline( device, &[&binder.layout], @@ -316,20 +317,20 @@ impl ModelLoader { label: Some(&format!("{:?} Vertex Buffer", m.name)), contents: bytemuck::cast_slice(&vertices), // UPDATED! - usage: wgpu::BufferUsage::STORAGE, + usage: wgpu::BufferUsages::STORAGE, }); let dst_vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", m.name)), contents: bytemuck::cast_slice(&vertices), // UPDATED! - usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::STORAGE, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::STORAGE, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", m.name)), contents: bytemuck::cast_slice(&m.mesh.indices), // UPDATED! - usage: wgpu::BufferUsage::INDEX | wgpu::BufferUsage::STORAGE, + usage: wgpu::BufferUsages::INDEX | wgpu::BufferUsages::STORAGE, }); let compute_info = ComputeInfo { num_vertices: vertices.len() as _, @@ -338,7 +339,7 @@ impl ModelLoader { let info_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Compute Info Buffer", m.name)), contents: bytemuck::cast_slice(&[compute_info]), - usage: wgpu::BufferUsage::UNIFORM, + usage: wgpu::BufferUsages::UNIFORM, }); // NEW! diff --git a/code/showcase/compute/src/model_load.comp b/code/showcase/compute/src/model_load.comp index 0bc57101..d61a2160 100644 --- a/code/showcase/compute/src/model_load.comp +++ b/code/showcase/compute/src/model_load.comp @@ -11,13 +11,13 @@ struct ModelVertex { uint pad0; uint pad1; }; -layout(std430, set=0, binding=0) buffer SrcVertexBuffer { +layout(std430, set=0, binding=0) readonly buffer SrcVertexBuffer { ModelVertex srcVertices[]; }; layout(std430, set=0, binding=1) buffer DstVertexBuffer { ModelVertex dstVertices[]; }; -layout(std430, set=0, binding=2) buffer IndexBuffer { +layout(std430, set=0, binding=2) readonly buffer IndexBuffer { uint indices[]; }; diff --git a/code/showcase/compute/src/model_load.comp.spv b/code/showcase/compute/src/model_load.comp.spv deleted file mode 100644 index 97dbb23e..00000000 Binary files a/code/showcase/compute/src/model_load.comp.spv and /dev/null differ diff --git a/code/showcase/compute/src/model_load.comp.wgsl b/code/showcase/compute/src/model_load.comp.wgsl new file mode 100644 index 00000000..4e0b681d --- /dev/null +++ b/code/showcase/compute/src/model_load.comp.wgsl @@ -0,0 +1,252 @@ +struct ModelVertex { + x: f32; + y: f32; + z: f32; + uv: f32; + uw: f32; + nx: f32; + ny: f32; + nz: f32; + tx: f32; + ty: f32; + tz: f32; + bx: f32; + by: f32; + bz: f32; + pad0_: u32; + pad1_: u32; +}; + +[[block]] +struct SrcVertexBuffer { + srcVertices: [[stride(64)]] array; +}; + +[[block]] +struct DstVertexBuffer { + dstVertices: [[stride(64)]] array; +}; + +[[block]] +struct IndexBuffer { + indices: [[stride(4)]] array; +}; + +[[block]] +struct ComputeInfo { + numVertices: u32; + numIndices: u32; +}; + +[[group(0), binding(0)]] +var global: SrcVertexBuffer; +[[group(0), binding(1)]] +var global1: DstVertexBuffer; +[[group(0), binding(2)]] +var global2: IndexBuffer; +[[group(0), binding(3)]] +var global3: ComputeInfo; +var gl_GlobalInvocationID: vec3; + +fn getPos(v: ModelVertex) -> vec3 { + var v1: ModelVertex; + + v1 = v; + let _e12: ModelVertex = v1; + let _e14: ModelVertex = v1; + let _e16: ModelVertex = v1; + return vec3(_e12.x, _e14.y, _e16.z); +} + +fn getUV(v2: ModelVertex) -> vec2 { + var v3: ModelVertex; + + v3 = v2; + let _e12: ModelVertex = v3; + let _e14: ModelVertex = v3; + return vec2(_e12.uv, _e14.uw); +} + +fn getNormal(v4: ModelVertex) -> vec3 { + var v5: ModelVertex; + + v5 = v4; + let _e12: ModelVertex = v5; + let _e14: ModelVertex = v5; + let _e16: ModelVertex = v5; + return vec3(_e12.nx, _e14.ny, _e16.nz); +} + +fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex { + var vertexIndex1: u32; + var v6: ModelVertex; + var tangent: vec3 = vec3(0.0, 0.0, 0.0); + var bitangent: vec3 = vec3(0.0, 0.0, 0.0); + var trianglesIncluded: u32 = 0u; + var i: u32 = 0u; + var index0_: u32; + var index1_: u32; + var index2_: u32; + var v0_: ModelVertex; + var v1_: ModelVertex; + var v2_: ModelVertex; + var pos0_: vec3; + var pos1_: vec3; + var pos2_: vec3; + var uv0_: vec2; + var uv1_: vec2; + var uv2_: vec2; + var delta_pos1_: vec3; + var delta_pos2_: vec3; + var delta_uv1_: vec2; + var delta_uv2_: vec2; + var r: f32; + + vertexIndex1 = vertexIndex; + let _e12: u32 = vertexIndex1; + let _e14: ModelVertex = global.srcVertices[_e12]; + v6 = _e14; + loop { + let _e30: u32 = i; + let _e31: u32 = global3.numIndices; + if (!((_e30 < _e31))) { + break; + } + { + let _e38: u32 = i; + let _e40: u32 = global2.indices[_e38]; + index0_ = _e40; + let _e42: u32 = i; + let _e47: u32 = global2.indices[(_e42 + u32(1))]; + index1_ = _e47; + let _e49: u32 = i; + let _e54: u32 = global2.indices[(_e49 + u32(2))]; + index2_ = _e54; + let _e56: u32 = index0_; + let _e57: u32 = vertexIndex1; + let _e59: u32 = index1_; + let _e60: u32 = vertexIndex1; + let _e63: u32 = index2_; + let _e64: u32 = vertexIndex1; + if ((((_e56 == _e57) || (_e59 == _e60)) || (_e63 == _e64))) { + { + let _e67: u32 = index0_; + let _e69: ModelVertex = global.srcVertices[_e67]; + v0_ = _e69; + let _e71: u32 = index1_; + let _e73: ModelVertex = global.srcVertices[_e71]; + v1_ = _e73; + let _e75: u32 = index2_; + let _e77: ModelVertex = global.srcVertices[_e75]; + v2_ = _e77; + let _e80: ModelVertex = v0_; + let _e81: vec3 = getPos(_e80); + pos0_ = _e81; + let _e84: ModelVertex = v1_; + let _e85: vec3 = getPos(_e84); + pos1_ = _e85; + let _e88: ModelVertex = v2_; + let _e89: vec3 = getPos(_e88); + pos2_ = _e89; + let _e92: ModelVertex = v0_; + let _e93: vec2 = getUV(_e92); + uv0_ = _e93; + let _e96: ModelVertex = v1_; + let _e97: vec2 = getUV(_e96); + uv1_ = _e97; + let _e100: ModelVertex = v2_; + let _e101: vec2 = getUV(_e100); + uv2_ = _e101; + let _e103: vec3 = pos1_; + let _e104: vec3 = pos0_; + delta_pos1_ = (_e103 - _e104); + let _e107: vec3 = pos2_; + let _e108: vec3 = pos0_; + delta_pos2_ = (_e107 - _e108); + let _e111: vec2 = uv1_; + let _e112: vec2 = uv0_; + delta_uv1_ = (_e111 - _e112); + let _e115: vec2 = uv2_; + let _e116: vec2 = uv0_; + delta_uv2_ = (_e115 - _e116); + let _e120: vec2 = delta_uv1_; + let _e122: vec2 = delta_uv2_; + let _e125: vec2 = delta_uv1_; + let _e127: vec2 = delta_uv2_; + r = (1.0 / ((_e120.x * _e122.y) - (_e125.y * _e127.x))); + let _e133: vec3 = tangent; + let _e134: vec3 = delta_pos1_; + let _e135: vec2 = delta_uv2_; + let _e138: vec3 = delta_pos2_; + let _e139: vec2 = delta_uv1_; + let _e143: f32 = r; + tangent = (_e133 + (((_e134 * _e135.y) - (_e138 * _e139.y)) * _e143)); + let _e146: vec3 = bitangent; + let _e147: vec3 = delta_pos2_; + let _e148: vec2 = delta_uv1_; + let _e151: vec3 = delta_pos1_; + let _e152: vec2 = delta_uv2_; + let _e156: f32 = r; + bitangent = (_e146 + (((_e147 * _e148.x) - (_e151 * _e152.x)) * _e156)); + let _e159: u32 = trianglesIncluded; + trianglesIncluded = (_e159 + u32(1)); + } + } + } + continuing { + let _e34: u32 = i; + i = (_e34 + u32(3)); + } + } + let _e163: u32 = trianglesIncluded; + if ((_e163 > u32(0))) { + { + let _e167: vec3 = tangent; + let _e168: u32 = trianglesIncluded; + tangent = (_e167 / vec3(f32(_e168))); + let _e172: vec3 = bitangent; + let _e173: u32 = trianglesIncluded; + bitangent = (_e172 / vec3(f32(_e173))); + let _e178: vec3 = tangent; + tangent = normalize(_e178); + let _e181: vec3 = bitangent; + bitangent = normalize(_e181); + } + } + let _e184: vec3 = tangent; + v6.tx = _e184.x; + let _e187: vec3 = tangent; + v6.ty = _e187.y; + let _e190: vec3 = tangent; + v6.tz = _e190.z; + let _e193: vec3 = bitangent; + v6.bx = _e193.x; + let _e196: vec3 = bitangent; + v6.by = _e196.y; + let _e199: vec3 = bitangent; + v6.bz = _e199.z; + let _e201: ModelVertex = v6; + return _e201; +} + +fn main1() { + var vertexIndex2: u32; + var result: ModelVertex; + + let _e11: vec3 = gl_GlobalInvocationID; + vertexIndex2 = _e11.x; + let _e15: u32 = vertexIndex2; + let _e16: ModelVertex = calcTangentBitangent(_e15); + result = _e16; + let _e18: u32 = vertexIndex2; + let _e20: ModelVertex = result; + global1.dstVertices[_e18] = _e20; + return; +} + +[[stage(compute), workgroup_size(64, 1, 1)]] +fn main([[builtin(global_invocation_id)]] param: vec3) { + gl_GlobalInvocationID = param; + main1(); + return; +} diff --git a/code/showcase/compute/src/pipeline.rs b/code/showcase/compute/src/pipeline.rs index 7309a375..a771648f 100644 --- a/code/showcase/compute/src/pipeline.rs +++ b/code/showcase/compute/src/pipeline.rs @@ -40,12 +40,12 @@ pub fn create_render_pipeline( color_format: wgpu::TextureFormat, depth_format: Option, vertex_layouts: &[wgpu::VertexBufferLayout], - mut vs_src: wgpu::ShaderModuleDescriptor, - mut fs_src: wgpu::ShaderModuleDescriptor, + vs_src: wgpu::ShaderModuleDescriptor, + fs_src: wgpu::ShaderModuleDescriptor, ) -> wgpu::RenderPipeline { - vs_src.flags &= wgpu::ShaderFlags::VALIDATION; - fs_src.flags &= wgpu::ShaderFlags::VALIDATION; + println!("Creating VS Module ======="); let vs_module = device.create_shader_module(&vs_src); + println!("Creating FS Module ======="); let fs_module = device.create_shader_module(&fs_src); device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -62,7 +62,7 @@ pub fn create_render_pipeline( targets: &[wgpu::ColorTargetState { format: color_format, blend: None, - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { diff --git a/code/showcase/compute/src/shader.frag.spv b/code/showcase/compute/src/shader.frag.spv deleted file mode 100644 index 45ccebc0..00000000 Binary files a/code/showcase/compute/src/shader.frag.spv and /dev/null differ diff --git a/code/showcase/compute/src/shader.frag.wgsl b/code/showcase/compute/src/shader.frag.wgsl new file mode 100644 index 00000000..dfcbc242 --- /dev/null +++ b/code/showcase/compute/src/shader.frag.wgsl @@ -0,0 +1,109 @@ +[[block]] +struct Light { + light_position: vec3; + light_color: vec3; +}; + +struct FragmentOutput { + [[location(0)]] f_color: vec4; +}; + +var v_tex_coords1: vec2; +var v_position1: vec3; +var v_light_position1: vec3; +var v_view_position1: vec3; +var f_color: vec4; +[[group(0), binding(0)]] +var t_diffuse: texture_2d; +[[group(0), binding(1)]] +var s_diffuse: sampler; +[[group(0), binding(2)]] +var t_normal: texture_2d; +[[group(0), binding(3)]] +var s_normal: sampler; +[[group(2), binding(0)]] +var global: Light; + +fn main1() { + var object_color: vec4; + var object_normal: vec4; + var ambient_strength: f32 = 0.10000000149011612; + var ambient_color: vec3; + var normal: vec3; + var light_dir: vec3; + var diffuse_strength: f32; + var diffuse_color: vec3; + var view_dir: vec3; + var half_dir: vec3; + var specular_strength: f32; + var specular_color: vec3; + var result: vec3; + + let _e14: vec2 = v_tex_coords1; + let _e15: vec4 = textureSample(t_diffuse, s_diffuse, _e14); + object_color = _e15; + let _e18: vec2 = v_tex_coords1; + let _e19: vec4 = textureSample(t_normal, s_normal, _e18); + object_normal = _e19; + let _e23: vec3 = global.light_color; + let _e24: f32 = ambient_strength; + ambient_color = (_e23 * _e24); + let _e27: vec4 = object_normal; + let _e34: vec4 = object_normal; + normal = normalize(((_e34.xyz * 2.0) - vec3(1.0))); + let _e43: vec3 = v_light_position1; + let _e44: vec3 = v_position1; + let _e46: vec3 = v_light_position1; + let _e47: vec3 = v_position1; + light_dir = normalize((_e46 - _e47)); + let _e53: vec3 = normal; + let _e54: vec3 = light_dir; + let _e59: vec3 = normal; + let _e60: vec3 = light_dir; + diffuse_strength = max(dot(_e59, _e60), 0.0); + let _e65: vec3 = global.light_color; + let _e66: f32 = diffuse_strength; + diffuse_color = (_e65 * _e66); + let _e69: vec3 = v_view_position1; + let _e70: vec3 = v_position1; + let _e72: vec3 = v_view_position1; + let _e73: vec3 = v_position1; + view_dir = normalize((_e72 - _e73)); + let _e77: vec3 = view_dir; + let _e78: vec3 = light_dir; + let _e80: vec3 = view_dir; + let _e81: vec3 = light_dir; + half_dir = normalize((_e80 + _e81)); + let _e87: vec3 = normal; + let _e88: vec3 = half_dir; + let _e93: vec3 = normal; + let _e94: vec3 = half_dir; + let _e101: vec3 = normal; + let _e102: vec3 = half_dir; + let _e107: vec3 = normal; + let _e108: vec3 = half_dir; + specular_strength = pow(max(dot(_e107, _e108), 0.0), f32(32)); + let _e116: f32 = specular_strength; + let _e117: vec3 = global.light_color; + specular_color = (_e116 * _e117); + let _e120: vec3 = ambient_color; + let _e121: vec3 = diffuse_color; + let _e123: vec3 = specular_color; + let _e125: vec4 = object_color; + result = (((_e120 + _e121) + _e123) * _e125.xyz); + let _e129: vec3 = result; + let _e130: vec4 = object_color; + f_color = vec4(_e129, _e130.w); + return; +} + +[[stage(fragment)]] +fn main([[location(0)]] v_tex_coords: vec2, [[location(1)]] v_position: vec3, [[location(2)]] v_light_position: vec3, [[location(3)]] v_view_position: vec3) -> FragmentOutput { + v_tex_coords1 = v_tex_coords; + v_position1 = v_position; + v_light_position1 = v_light_position; + v_view_position1 = v_view_position; + main1(); + let _e31: vec4 = f_color; + return FragmentOutput(_e31); +} diff --git a/code/showcase/compute/src/shader.vert b/code/showcase/compute/src/shader.vert index be49b4e1..460c3824 100644 --- a/code/showcase/compute/src/shader.vert +++ b/code/showcase/compute/src/shader.vert @@ -22,6 +22,10 @@ layout(location=6) in vec4 model_matrix_1; layout(location=7) in vec4 model_matrix_2; layout(location=8) in vec4 model_matrix_3; +layout(location=9) in vec3 normal_matrix_0; +layout(location=10) in vec3 normal_matrix_1; +layout(location=11) in vec3 normal_matrix_2; + // NEW! layout(set=2, binding=0) uniform Light { vec3 light_position; @@ -37,7 +41,11 @@ void main() { ); v_tex_coords = a_tex_coords; - mat3 normal_matrix = mat3(transpose(inverse(model_matrix))); + mat3 normal_matrix = mat3( + normal_matrix_0, + normal_matrix_1, + normal_matrix_2 + ); vec3 normal = normalize(normal_matrix * a_normal); vec3 tangent = normalize(normal_matrix * a_tangent); vec3 bitangent = normalize(normal_matrix * a_bitangent); @@ -50,7 +58,6 @@ void main() { )); vec4 model_space = model_matrix * vec4(a_position, 1.0); - v_position = model_space.xyz; // NEW! v_position = tangent_matrix * model_space.xyz; diff --git a/code/showcase/compute/src/shader.vert.spv b/code/showcase/compute/src/shader.vert.spv deleted file mode 100644 index 7731b5d9..00000000 Binary files a/code/showcase/compute/src/shader.vert.spv and /dev/null differ diff --git a/code/showcase/compute/src/shader.vert.wgsl b/code/showcase/compute/src/shader.vert.wgsl new file mode 100644 index 00000000..34a7c1d5 --- /dev/null +++ b/code/showcase/compute/src/shader.vert.wgsl @@ -0,0 +1,124 @@ +[[block]] +struct Camera { + u_view_position: vec3; + u_view_proj: mat4x4; +}; + +[[block]] +struct Light { + light_position: vec3; + light_color: vec3; +}; + +struct VertexOutput { + [[location(0)]] v_tex_coords: vec2; + [[location(1)]] v_position: vec3; + [[location(2)]] v_light_position: vec3; + [[location(3)]] v_view_position: vec3; + [[builtin(position)]] member: vec4; +}; + +var a_position1: vec3; +var a_tex_coords1: vec2; +var a_normal1: vec3; +var a_tangent1: vec3; +var a_bitangent1: vec3; +var v_tex_coords: vec2; +var v_position: vec3; +var v_light_position: vec3; +var v_view_position: vec3; +[[group(1), binding(0)]] +var global: Camera; +var model_matrix_0_1: vec4; +var model_matrix_1_1: vec4; +var model_matrix_2_1: vec4; +var model_matrix_3_1: vec4; +var normal_matrix_0_1: vec3; +var normal_matrix_1_1: vec3; +var normal_matrix_2_1: vec3; +[[group(2), binding(0)]] +var global1: Light; +var gl_Position: vec4; + +fn main1() { + var model_matrix: mat4x4; + var normal_matrix: mat3x3; + var normal: vec3; + var tangent: vec3; + var bitangent: vec3; + var tangent_matrix: mat3x3; + var model_space: vec4; + + let _e24: vec4 = model_matrix_0_1; + let _e25: vec4 = model_matrix_1_1; + let _e26: vec4 = model_matrix_2_1; + let _e27: vec4 = model_matrix_3_1; + model_matrix = mat4x4(vec4(_e24.x, _e24.y, _e24.z, _e24.w), vec4(_e25.x, _e25.y, _e25.z, _e25.w), vec4(_e26.x, _e26.y, _e26.z, _e26.w), vec4(_e27.x, _e27.y, _e27.z, _e27.w)); + let _e50: vec2 = a_tex_coords1; + v_tex_coords = _e50; + let _e51: vec3 = normal_matrix_0_1; + let _e52: vec3 = normal_matrix_1_1; + let _e53: vec3 = normal_matrix_2_1; + normal_matrix = mat3x3(vec3(_e51.x, _e51.y, _e51.z), vec3(_e52.x, _e52.y, _e52.z), vec3(_e53.x, _e53.y, _e53.z)); + let _e68: mat3x3 = normal_matrix; + let _e69: vec3 = a_normal1; + let _e71: mat3x3 = normal_matrix; + let _e72: vec3 = a_normal1; + normal = normalize((_e71 * _e72)); + let _e76: mat3x3 = normal_matrix; + let _e77: vec3 = a_tangent1; + let _e79: mat3x3 = normal_matrix; + let _e80: vec3 = a_tangent1; + tangent = normalize((_e79 * _e80)); + let _e84: mat3x3 = normal_matrix; + let _e85: vec3 = a_bitangent1; + let _e87: mat3x3 = normal_matrix; + let _e88: vec3 = a_bitangent1; + bitangent = normalize((_e87 * _e88)); + let _e92: vec3 = tangent; + let _e93: vec3 = bitangent; + let _e94: vec3 = normal; + let _e108: vec3 = tangent; + let _e109: vec3 = bitangent; + let _e110: vec3 = normal; + tangent_matrix = transpose(mat3x3(vec3(_e108.x, _e108.y, _e108.z), vec3(_e109.x, _e109.y, _e109.z), vec3(_e110.x, _e110.y, _e110.z))); + let _e126: mat4x4 = model_matrix; + let _e127: vec3 = a_position1; + model_space = (_e126 * vec4(_e127, 1.0)); + let _e132: mat3x3 = tangent_matrix; + let _e133: vec4 = model_space; + v_position = (_e132 * _e133.xyz); + let _e136: mat3x3 = tangent_matrix; + let _e137: vec3 = global1.light_position; + v_light_position = (_e136 * _e137); + let _e139: mat3x3 = tangent_matrix; + let _e140: vec3 = global.u_view_position; + v_view_position = (_e139 * _e140); + let _e143: mat4x4 = global.u_view_proj; + let _e144: vec4 = model_space; + gl_Position = (_e143 * _e144); + return; +} + +[[stage(vertex)]] +fn main([[location(0)]] a_position: vec3, [[location(1)]] a_tex_coords: vec2, [[location(2)]] a_normal: vec3, [[location(3)]] a_tangent: vec3, [[location(4)]] a_bitangent: vec3, [[location(5)]] model_matrix_0_: vec4, [[location(6)]] model_matrix_1_: vec4, [[location(7)]] model_matrix_2_: vec4, [[location(8)]] model_matrix_3_: vec4, [[location(9)]] normal_matrix_0_: vec3, [[location(10)]] normal_matrix_1_: vec3, [[location(11)]] normal_matrix_2_: vec3) -> VertexOutput { + a_position1 = a_position; + a_tex_coords1 = a_tex_coords; + a_normal1 = a_normal; + a_tangent1 = a_tangent; + a_bitangent1 = a_bitangent; + model_matrix_0_1 = model_matrix_0_; + model_matrix_1_1 = model_matrix_1_; + model_matrix_2_1 = model_matrix_2_; + model_matrix_3_1 = model_matrix_3_; + normal_matrix_0_1 = normal_matrix_0_; + normal_matrix_1_1 = normal_matrix_1_; + normal_matrix_2_1 = normal_matrix_2_; + main1(); + let _e65: vec2 = v_tex_coords; + let _e67: vec3 = v_position; + let _e69: vec3 = v_light_position; + let _e71: vec3 = v_view_position; + let _e73: vec4 = gl_Position; + return VertexOutput(_e65, _e67, _e69, _e71, _e73); +} diff --git a/code/showcase/compute/src/texture.rs b/code/showcase/compute/src/texture.rs index 30f15da5..0272cc8b 100644 --- a/code/showcase/compute/src/texture.rs +++ b/code/showcase/compute/src/texture.rs @@ -27,12 +27,12 @@ impl Texture { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, label: &str, ) -> Self { let size = wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -42,7 +42,7 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -86,7 +86,7 @@ impl Texture { is_normal_map: bool, ) -> Result { let dimensions = img.dimensions(); - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let size = wgpu::Extent3d { width: dimensions.0, @@ -104,11 +104,12 @@ impl Texture { } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/code/showcase/framework/Cargo.toml b/code/showcase/framework/Cargo.toml index 17a8feb9..95cb99c1 100644 --- a/code/showcase/framework/Cargo.toml +++ b/code/showcase/framework/Cargo.toml @@ -14,7 +14,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "2.0" -wgpu = "0.9" +wgpu = "0.10" wgpu-subscriber = "0.1" winit = "0.25" diff --git a/code/showcase/framework/src/buffer.rs b/code/showcase/framework/src/buffer.rs index 0780579e..40e48a3a 100644 --- a/code/showcase/framework/src/buffer.rs +++ b/code/showcase/framework/src/buffer.rs @@ -18,13 +18,13 @@ impl RawBuffer { pub fn from_slice>( device: &wgpu::Device, data: &[T], - usage: wgpu::BufferUsage, + usage: wgpu::BufferUsages, ) -> Self { let raw_data = data.iter().map(ToRaw::to_raw).collect::>(); Self::from_vec(device, raw_data, usage) } - pub fn from_vec(device: &wgpu::Device, data: Vec, usage: wgpu::BufferUsage) -> Self { + pub fn from_vec(device: &wgpu::Device, data: Vec, usage: wgpu::BufferUsages) -> Self { let buffer = device.create_buffer_init(&BufferInitDescriptor { contents: bytemuck::cast_slice(&data), usage, @@ -33,7 +33,7 @@ impl RawBuffer { Self::from_parts(buffer, data, usage) } - pub fn from_parts(buffer: wgpu::Buffer, data: Vec, _usage: wgpu::BufferUsage) -> Self { + pub fn from_parts(buffer: wgpu::Buffer, data: Vec, _usage: wgpu::BufferUsages) -> Self { Self { buffer, data } } @@ -45,26 +45,26 @@ impl RawBuffer { pub struct Buffer, R: Copy + bytemuck::Pod + bytemuck::Zeroable> { pub data: Vec, pub raw_buffer: RawBuffer, - pub usage: wgpu::BufferUsage, + pub usage: wgpu::BufferUsages, } impl, R: Copy + bytemuck::Pod + bytemuck::Zeroable> Buffer { pub fn uniform(device: &wgpu::Device, datum: U) -> Self { let data = vec![datum]; - let usage = wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST; + let usage = wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST; Self::with_usage(device, data, usage) } pub fn storage(device: &wgpu::Device, data: Vec) -> Self { - let usage = wgpu::BufferUsage::STORAGE | wgpu::BufferUsage::COPY_DST; + let usage = wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST; Self::with_usage(device, data, usage) } pub fn staging(device: &wgpu::Device, other: &Self) -> Self { let buffer_size = other.raw_buffer.buffer_size(); - let usage = wgpu::BufferUsage::COPY_SRC - | wgpu::BufferUsage::MAP_READ - | wgpu::BufferUsage::MAP_WRITE; + let usage = wgpu::BufferUsages::COPY_SRC + | wgpu::BufferUsages::MAP_READ + | wgpu::BufferUsages::MAP_WRITE; let buffer = device.create_buffer(&wgpu::BufferDescriptor { size: buffer_size, usage, @@ -75,12 +75,12 @@ impl, R: Copy + bytemuck::Pod + bytemuck::Zeroable> Buffer< Self::from_parts(Vec::new(), raw_buffer, usage) } - pub fn with_usage(device: &wgpu::Device, data: Vec, usage: wgpu::BufferUsage) -> Self { + pub fn with_usage(device: &wgpu::Device, data: Vec, usage: wgpu::BufferUsages) -> Self { let raw_buffer = RawBuffer::from_slice(device, &data, usage); Self::from_parts(data, raw_buffer, usage) } - pub fn from_parts(data: Vec, raw_buffer: RawBuffer, usage: wgpu::BufferUsage) -> Self { + pub fn from_parts(data: Vec, raw_buffer: RawBuffer, usage: wgpu::BufferUsages) -> Self { Self { data, raw_buffer, diff --git a/code/showcase/framework/src/lib.rs b/code/showcase/framework/src/lib.rs index f327b158..50dae812 100644 --- a/code/showcase/framework/src/lib.rs +++ b/code/showcase/framework/src/lib.rs @@ -26,8 +26,7 @@ use winit::window::{Window, WindowBuilder}; pub struct Display { surface: wgpu::Surface, pub window: Window, - pub sc_desc: wgpu::SwapChainDescriptor, - pub swap_chain: wgpu::SwapChain, + pub config: wgpu::SurfaceConfiguration, pub device: wgpu::Device, pub queue: wgpu::Queue, } @@ -35,7 +34,7 @@ pub struct Display { impl Display { pub async fn new(window: Window) -> Result { let size = window.inner_size(); - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(&window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -55,29 +54,28 @@ impl Display { ) .await .unwrap(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); Ok(Self { surface, window, - sc_desc, - swap_chain, + config, device, queue, }) } pub fn resize(&mut self, width: u32, height: u32) { - self.sc_desc.width = width; - self.sc_desc.height = height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = width; + self.config.height = height; + self.surface.configure(&self.device, &self.config); } } @@ -108,7 +106,7 @@ impl CameraUniform { let buffer = device.create_buffer_init(&BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[data]), - usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::UNIFORM, }); Self { data, buffer } @@ -123,7 +121,7 @@ impl CameraUniform { let staging_buffer = device.create_buffer_init(&BufferInitDescriptor { label: Some("Camera Update Buffer"), contents: bytemuck::cast_slice(&[self.data]), - usage: wgpu::BufferUsage::COPY_SRC, + usage: wgpu::BufferUsages::COPY_SRC, }); encoder.copy_buffer_to_buffer( &staging_buffer, @@ -149,7 +147,7 @@ impl UniformBinding { let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, diff --git a/code/showcase/framework/src/light.rs b/code/showcase/framework/src/light.rs index b4579a85..c3258ca9 100644 --- a/code/showcase/framework/src/light.rs +++ b/code/showcase/framework/src/light.rs @@ -26,7 +26,7 @@ impl LightUniform { }; let buffer = device.create_buffer_init(&BufferInitDescriptor { contents: bytemuck::cast_slice(&[data]), - usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::UNIFORM, label: Some("Light Buffer"), }); diff --git a/code/showcase/framework/src/model.rs b/code/showcase/framework/src/model.rs index 012e3f1a..293d872a 100644 --- a/code/showcase/framework/src/model.rs +++ b/code/showcase/framework/src/model.rs @@ -24,7 +24,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -222,12 +222,12 @@ impl<'a> Model<'a> { let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); meshes.push(Mesh { diff --git a/code/showcase/framework/src/pipeline.rs b/code/showcase/framework/src/pipeline.rs index a4902cea..228fb278 100644 --- a/code/showcase/framework/src/pipeline.rs +++ b/code/showcase/framework/src/pipeline.rs @@ -103,7 +103,7 @@ impl<'a> RenderPipelineBuilder<'a> { self.color_state(wgpu::ColorTargetState { format, blend: None, - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }) } diff --git a/code/showcase/framework/src/shader_canvas.rs b/code/showcase/framework/src/shader_canvas.rs index 313bd35b..0a6ff16c 100644 --- a/code/showcase/framework/src/shader_canvas.rs +++ b/code/showcase/framework/src/shader_canvas.rs @@ -127,9 +127,9 @@ impl<'a> ShaderCanvasBuilder<'a> { self } - pub fn use_swap_chain_desc(&mut self, sc_desc: &wgpu::SwapChainDescriptor) -> &mut Self { - self.display_format(sc_desc.format); - self.canvas_size(sc_desc.width as f32, sc_desc.height as f32) + pub fn use_swap_chain_desc(&mut self, config: &wgpu::SurfaceConfiguration) -> &mut Self { + self.display_format(config.format); + self.canvas_size(config.width as f32, config.height as f32) } pub fn fragment_shader(&mut self, code: wgpu::ShaderModuleDescriptor<'a>) -> &mut Self { @@ -165,7 +165,7 @@ impl<'a> ShaderCanvasBuilder<'a> { let simulation_data_buffer = device.create_buffer_init(&BufferInitDescriptor { label: self.label, contents: bytemuck::cast_slice(&[simulation_data]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); let simulation_bind_group_layout = @@ -175,7 +175,7 @@ impl<'a> ShaderCanvasBuilder<'a> { // SimulationData wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, count: None, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, @@ -219,7 +219,7 @@ impl<'a> ShaderCanvasBuilder<'a> { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { diff --git a/code/showcase/framework/src/texture.rs b/code/showcase/framework/src/texture.rs index 546a78d3..0b1b7897 100644 --- a/code/showcase/framework/src/texture.rs +++ b/code/showcase/framework/src/texture.rs @@ -70,7 +70,7 @@ impl<'a> Texture<'a> { _label: Option<&str>, is_normal_map: bool, ) -> Result { - let rgba = img.to_rgba(); + let rgba = img.to_rgba8(); let dimensions = img.dimensions(); let size = wgpu::Extent3d { @@ -88,13 +88,14 @@ impl<'a> Texture<'a> { } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, label: None, }; let texture = device.create_texture(&desc); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, @@ -132,20 +133,20 @@ impl<'a> Texture<'a> { pub fn create_depth_texture( device: &wgpu::Device, - sc_desc: &wgpu::SwapChainDescriptor, + config: &wgpu::SurfaceConfiguration, ) -> Self { let desc = wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }, mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, }; Self::from_descriptor(device, desc) } @@ -155,7 +156,7 @@ impl<'a> Texture<'a> { self.desc.size.width * self.desc.size.height * self.desc.size.depth_or_array_layers; let buffer_size = num_pixels * mem::size_of::<[f32; 4]>() as u32; - let buffer_usage = wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::MAP_READ; + let buffer_usage = wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ; let buffer_desc = wgpu::BufferDescriptor { size: buffer_size as wgpu::BufferAddress, usage: buffer_usage, diff --git a/code/showcase/gifs/Cargo.toml b/code/showcase/gifs/Cargo.toml index 48138835..0847fb4b 100644 --- a/code/showcase/gifs/Cargo.toml +++ b/code/showcase/gifs/Cargo.toml @@ -14,7 +14,7 @@ pollster = "0.2" image = "0.23" log = "0.4" tobj = "3.1" -wgpu = "0.9" +wgpu = "0.10" winit = "0.25" gif = "0.10.3" diff --git a/code/showcase/gifs/src/main.rs b/code/showcase/gifs/src/main.rs index bbd3dfca..cc6666ff 100644 --- a/code/showcase/gifs/src/main.rs +++ b/code/showcase/gifs/src/main.rs @@ -4,7 +4,7 @@ use anyhow::*; use std::{iter, mem, num::NonZeroU32}; async fn run() { - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions::default()) .await @@ -44,7 +44,7 @@ async fn run() { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::COPY_SRC | wgpu::TextureUsage::RENDER_ATTACHMENT, + usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, label: None, }; let render_target = framework::Texture::from_descriptor(&device, rt_desc); @@ -63,7 +63,7 @@ async fn run() { let buffer_size = (padded_bytes_per_row * texture_size) as wgpu::BufferAddress; let buffer_desc = wgpu::BufferDescriptor { size: buffer_size, - usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::MAP_READ, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, label: Some("Output Buffer"), mapped_at_creation: false, }; @@ -103,6 +103,7 @@ async fn run() { encoder.copy_texture_to_buffer( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &render_target.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, @@ -190,7 +191,7 @@ fn create_render_pipeline( targets: &[wgpu::ColorTargetState { format: target.desc.format, blend: Some(wgpu::BlendState::REPLACE), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { diff --git a/code/showcase/imgui-demo/Cargo.toml b/code/showcase/imgui-demo/Cargo.toml index 7a6800b2..ddd9c63b 100644 --- a/code/showcase/imgui-demo/Cargo.toml +++ b/code/showcase/imgui-demo/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" [dependencies] anyhow = "1.0" -wgpu = "0.9" +wgpu = "0.10" pollster = "0.2" imgui = "0.7" -imgui-wgpu = "0.15" +imgui-wgpu = "0.17" imgui-winit-support = "0.7" framework = { path = "../framework" } \ No newline at end of file diff --git a/code/showcase/imgui-demo/src/main.rs b/code/showcase/imgui-demo/src/main.rs index e32f4624..933e3a9e 100644 --- a/code/showcase/imgui-demo/src/main.rs +++ b/code/showcase/imgui-demo/src/main.rs @@ -14,7 +14,7 @@ struct ImguiDemo { impl framework::Demo for ImguiDemo { fn init(display: &framework::Display) -> Result { let canvas = framework::ShaderCanvasBuilder::new() - .display_format(display.sc_desc.format) + .display_format(display.config.format) .build(&display.device)?; let mut imgui = imgui::Context::create(); @@ -39,7 +39,7 @@ impl framework::Demo for ImguiDemo { }]); let renderer_config = RendererConfig { - texture_format: display.sc_desc.format, + texture_format: display.config.format, ..Default::default() }; let renderer = Renderer::new(&mut imgui, &display.device, &display.queue, renderer_config); @@ -102,8 +102,8 @@ impl framework::Demo for ImguiDemo { &display.queue, &mut encoder, &output.view, - display.sc_desc.width as f32, - display.sc_desc.height as f32, + display.config.width as f32, + display.config.height as f32, ); // Render the UI diff --git a/code/showcase/pong/Cargo.toml b/code/showcase/pong/Cargo.toml index 47a94f30..f77fada9 100644 --- a/code/showcase/pong/Cargo.toml +++ b/code/showcase/pong/Cargo.toml @@ -11,7 +11,7 @@ anyhow = "1.0" bytemuck = { version = "1.4", features = [ "derive" ] } cgmath = "0.18" pollster = "0.2" -wgpu = "0.9" +wgpu = "0.10" wgpu_glyph = "0.12" rand = "0.8" rodio = "0.14" diff --git a/code/showcase/pong/src/render/buffer.rs b/code/showcase/pong/src/render/buffer.rs index f29c6a02..8ec2ae84 100644 --- a/code/showcase/pong/src/render/buffer.rs +++ b/code/showcase/pong/src/render/buffer.rs @@ -17,7 +17,7 @@ impl Vertex { pub const SIZE: wgpu::BufferAddress = std::mem::size_of::() as wgpu::BufferAddress; pub const DESC: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout { array_stride: Self::SIZE, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![ 0 => Float32x2 ], @@ -111,7 +111,7 @@ impl StagingBuffer { StagingBuffer { buffer: device.create_buffer_init(&BufferInitDescriptor { contents: bytemuck::cast_slice(data), - usage: wgpu::BufferUsage::COPY_SRC, + usage: wgpu::BufferUsages::COPY_SRC, label: Some("Staging Buffer"), }), size: size_of_slice(data) as wgpu::BufferAddress, diff --git a/code/showcase/pong/src/render/mod.rs b/code/showcase/pong/src/render/mod.rs index b7b44501..0ab8faf5 100644 --- a/code/showcase/pong/src/render/mod.rs +++ b/code/showcase/pong/src/render/mod.rs @@ -19,8 +19,7 @@ pub struct Render { adapter: wgpu::Adapter, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, index_buffer: wgpu::Buffer, @@ -30,18 +29,18 @@ pub struct Render { impl Render { pub fn width(&self) -> f32 { - self.sc_desc.width as f32 + self.config.width as f32 } #[allow(dead_code)] pub fn height(&self) -> f32 { - self.sc_desc.height as f32 + self.config.height as f32 } pub async fn new(window: &Window, video_mode: &VideoMode) -> Self { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -63,14 +62,14 @@ impl Render { .unwrap(); let size = video_mode.size(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { bind_group_layouts: &[], @@ -80,7 +79,7 @@ impl Render { let pipeline = create_render_pipeline( &device, &pipeline_layout, - sc_desc.format, + config.format, &[Vertex::DESC], wgpu::include_spirv!("../../res/shaders/textured.vert.spv"), wgpu::include_spirv!("../../res/shaders/textured.frag.spv"), @@ -89,20 +88,20 @@ impl Render { let vertex_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: Vertex::SIZE * 4 * 3, - usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); let index_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: U32_SIZE * 6 * 3, - usage: wgpu::BufferUsage::INDEX | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); let font = ab_glyph::FontArc::try_from_slice(FONT_BYTES).unwrap(); let glyph_brush = - wgpu_glyph::GlyphBrushBuilder::using_font(font).build(&device, sc_desc.format); + wgpu_glyph::GlyphBrushBuilder::using_font(font).build(&device, config.format); let staging_belt = wgpu::util::StagingBelt::new(1024); Self { @@ -110,8 +109,7 @@ impl Render { adapter, device, queue, - sc_desc, - swap_chain, + config, pipeline, vertex_buffer, index_buffer, @@ -186,16 +184,16 @@ impl Render { &mut self.staging_belt, &mut encoder, &frame.output.view, - self.sc_desc.width, - self.sc_desc.height, + self.config.width, + self.config.height, ) .unwrap(); self.staging_belt.finish(); self.queue.submit(iter::once(encoder.finish())); } - Err(wgpu::SwapChainError::Outdated) => { - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + Err(wgpu::SurfaceError::Outdated) => { + self.surface.configure(&self.device, &self.config); } Err(e) => { eprintln!("Error: {}", e); @@ -257,7 +255,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { diff --git a/code/showcase/windowless/Cargo.toml b/code/showcase/windowless/Cargo.toml index 097dd02d..de49875b 100644 --- a/code/showcase/windowless/Cargo.toml +++ b/code/showcase/windowless/Cargo.toml @@ -12,7 +12,7 @@ raw-window-handle = "0.3" winit = "0.25" shaderc = "0.7" cgmath = "0.18" -wgpu = "0.9" +wgpu = "0.10" pollster = "0.2" [[bin]] diff --git a/code/showcase/windowless/src/main.rs b/code/showcase/windowless/src/main.rs index 15c97e1c..c8b9f0c9 100644 --- a/code/showcase/windowless/src/main.rs +++ b/code/showcase/windowless/src/main.rs @@ -1,7 +1,7 @@ use std::num::NonZeroU32; async fn run() { - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::default(), @@ -25,7 +25,7 @@ async fn run() { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::COPY_SRC | wgpu::TextureUsage::RENDER_ATTACHMENT, + usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, label: None, }; let texture = device.create_texture(&texture_desc); @@ -37,9 +37,9 @@ async fn run() { let output_buffer_size = (u32_size * texture_size * texture_size) as wgpu::BufferAddress; let output_buffer_desc = wgpu::BufferDescriptor { size: output_buffer_size, - usage: wgpu::BufferUsage::COPY_DST + usage: wgpu::BufferUsages::COPY_DST // this tells wpgu that we want to read this buffer from the cpu - | wgpu::BufferUsage::MAP_READ, + | wgpu::BufferUsages::MAP_READ, label: None, mapped_at_creation: false, }; @@ -71,12 +71,10 @@ async fn run() { let vs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Vertex Shader"), source: vs_data, - flags: wgpu::ShaderFlags::default(), }); let fs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Fragment Shader"), source: fs_data, - flags: wgpu::ShaderFlags::default(), }); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -102,7 +100,7 @@ async fn run() { alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -154,6 +152,7 @@ async fn run() { encoder.copy_texture_to_buffer( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 5125b7f6..d6e5955c 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -10,7 +10,7 @@ module.exports = { }, themeConfig: { author: { - name: 'Benjamin R Hansen', + name: 'Benjamin Hansen', twitter: 'https://twitter.com/sotrh760', }, displayAllHeaders: false, @@ -22,7 +22,7 @@ module.exports = { collapsable: false, children: [ '/beginner/tutorial1-window/', - '/beginner/tutorial2-swapchain/', + '/beginner/tutorial2-surface/', '/beginner/tutorial3-pipeline/', '/beginner/tutorial4-buffer/', '/beginner/tutorial5-textures/', diff --git a/docs/beginner/tutorial1-window/README.md b/docs/beginner/tutorial1-window/README.md index 95fccc10..b5d9e3e1 100644 --- a/docs/beginner/tutorial1-window/README.md +++ b/docs/beginner/tutorial1-window/README.md @@ -13,10 +13,13 @@ winit = "0.25" cgmath = "0.18" env_logger = "0.9" log = "0.4" -wgpu = "0.9" +wgpu = "0.10" pollster = "0.2" ``` +## Using Rust's new resolver +As of version 0.10, wgpu require's cargo's [newest feature resolver](https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2). As a result you must include `resolver = 2` in either the `[package]` section of `Cargo.toml` if you are working on a single crate, or the `[workspace]` section of the root `Cargo.toml` in a workspace. + ## The code There's not much going on here yet, so I'm just going to post the code in full. Just paste this into your `main.rs` or equivalent. diff --git a/docs/beginner/tutorial2-swapchain/README.md b/docs/beginner/tutorial2-surface/README.md similarity index 65% rename from docs/beginner/tutorial2-swapchain/README.md rename to docs/beginner/tutorial2-surface/README.md index f5236015..7b657651 100644 --- a/docs/beginner/tutorial2-swapchain/README.md +++ b/docs/beginner/tutorial2-surface/README.md @@ -1,4 +1,4 @@ -# The Swapchain +# The Surface ## First, some house keeping: State For convenience we're going to pack all the fields into a struct, and create some methods on that. @@ -11,8 +11,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, } @@ -34,7 +33,7 @@ impl State { todo!() } - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { todo!() } } @@ -53,7 +52,7 @@ impl State { // The instance is a handle to our GPU // BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::all()); let surface = unsafe { instance.create_surface(window) }; let adapter = instance.request_adapter( &wgpu::RequestAdapterOptions { @@ -63,7 +62,12 @@ impl State { ).await.unwrap(); ``` -The `surface` is used to create the `swap_chain`. Our `window` needs to implement [raw-window-handle](https://crates.io/crates/raw-window-handle)'s `HasRawWindowHandle` trait to access the native window implementation for `wgpu` to properly create the graphics backend. Fortunately, winit's `Window` fits the bill. We also need it to request our `adapter`. +### Instance and Adapter + +The `instance` is the first thing you create when using wgpu. It's may purpose +is to create `Adapter`s and `Surface`s. + +The `adapter` is a handle to our actual graphics card. You can use this get information about the graphics card such as its name and what backend the adapter uses. We use this to create our `Device` and `Queue` later.
@@ -71,20 +75,28 @@ The options I've passed to `request_adapter` aren't guaranteed to work for all d ```rust let adapter = instance - .enumerate_adapters(wgpu::BackendBit::PRIMARY) + .enumerate_adapters(wgpu::Backends::all()) .filter(|adapter| { // Check if this adapter supports our surface - adapter.get_swap_chain_preferred_format(&surface).is_some() + surface.get_preferred_format(&adapter).is_some() }) .first() .unwrap() ``` -For more fields you can use to refine you're search [check out the docs](https://docs.rs/wgpu/0.9.0/wgpu/struct.Adapter.html). +Another thing to note is that `Adapter`s are locked to a specific backend. If you are on Windows and have 2 graphics cards you'll have at least 4 adapters available to use, 2 Vulkan and 2 DirectX. + +For more fields you can use to refine you're search [check out the docs](https://docs.rs/wgpu/0.10.1/wgpu/struct.Adapter.html).
-We need the `adapter` to create the device and queue. +### The Surface + +The `surface` is the part of the window that we draw to. We need it to draw directly to the screen. Our `window` needs to implement [raw-window-handle](https://crates.io/crates/raw-window-handle)'s `HasRawWindowHandle` trait to create a surface. Fortunately, winit's `Window` fits the bill. We also need it to request our `adapter`. + +### Device and Queue + +Let's use the `adapter` to create the device and queue. ```rust let (device, queue) = adapter.request_device( @@ -101,43 +113,51 @@ The `features` field on `DeviceDescriptor`, allows us to specify what extra feat
-The device you have limits the features you can use. If you want to use certain features you may need to limit what devices you support, or provide work arounds. +The graphics card you have limits the features you can use. If you want to use certain features you may need to limit what devices you support, or provide work arounds. You can get a list of features supported by your device using `adapter.features()`, or `device.features()`. -You can view a full list of features [here](https://docs.rs/wgpu/0.7.0/wgpu/struct.Features.html). +You can view a full list of features [here](https://docs.rs/wgpu/0.10.1/wgpu/struct.Features.html).
The `limits` field describes the limit of certain types of resource we can create. We'll use the defaults for this tutorial, so we can support most devices. You can view a list of limits [here](https://docs.rs/wgpu/0.7.0/wgpu/struct.Limits.html). ```rust - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + let config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface.get_preferred_format(&adapter).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, }; - let swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &config); ``` -Here we are defining and creating the `swap_chain`. The `usage` field describes how the `swap_chain`'s underlying textures will be used. `RENDER_ATTACHMENT` specifies that the textures will be used to write to the screen (we'll talk about more `TextureUsage`s later). -The `format` defines how the `swap_chain`s textures will be stored on the gpu. Different displays prefer different formats. We use `adapter.get_swap_chain_preferred_format()` to figure out the best format to use. +Here we are defining a config for our surface. This will define how the surface creates it's underlying `SurfaceTexture`s. We will talk about `SurfaceTexture` when we get to the `render` function. For now lets talk about some of the our configs fields. -`width` and `height`, are the width and height in pixels of the swap chain. This should usually be the width and height of the window. +The `usage` field describes how the `SurfaceTexture`s will be used. `RENDER_ATTACHMENT` specifies that the textures will be used to write to the screen (we'll talk about more `TextureUsages`s later). -The `present_mode` uses the `wgpu::PresentMode` enum which determines how to sync the swap chain with the display. You can see all the options [in the docs](https://docs.rs/wgpu/0.7.0/wgpu/enum.PresentMode.html) +The `format` defines how the `SurfaceTexture`s will be stored on the gpu. Different displays prefer different formats. We use `surface.get_preferred_format(&adapter)` to figure out the best format to use based on the display you're using. -At the end of the method, we simply return the resulting struct. +`width` and `height`, are the width and height in pixels of the `SurfaceTexture`. This should usually be the width and height of the window. + +
+Make sure that the width and height of the `SurfaceTexture` are not 0, as that can cause your app to crash. +
+ +The `present_mode` uses the `wgpu::PresentMode` enum which determines how to sync the surface with the display. The option we picked `FIFO`, will cap the display rate at the displays framerate. This is essentially VSync. This is also the most optimal mode on mobile. There are other options and you can see all them [in the docs](https://docs.rs/wgpu/0.10.1/wgpu/enum.PresentMode.html) + +Now that we've configured our surface properly we can add these new fields at the end of the method. ```rust Self { + instance, + adapter, surface, device, queue, - sc_desc, - swap_chain, + config, size, } } @@ -148,7 +168,7 @@ At the end of the method, we simply return the resulting struct. We'll want to call this in our main method before we enter the event loop. ```rust -// Since main can't be async, we're going to need to block +// State::new uses async code, so we're going to wait for it to finish let mut state = pollster::block_on(State::new(&window)); ``` @@ -159,21 +179,21 @@ You can use heavier libraries like [async_std](https://docs.rs/async_std) and [t ## resize() -If we want to support resizing in our application, we're going to need to recreate the `swap_chain` everytime the window's size changes. That's the reason we stored the physical `size` and the `sc_desc` used to create the swapchain. With all of these, the resize method is very simple. +If we want to support resizing in our application, we're going to need to reconfigure the `surface` everytime the window's size changes. That's the reason we stored the physical `size` and the `config` used to configure the `surface`. With all of these, the resize method is very simple. ```rust // impl State pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { if new_size.width > 0 && new_size.height > 0 { self.size = new_size; - self.sc_desc.width = new_size.width; - self.sc_desc.height = new_size.height; - self.swap_chain = self.device.create_swap_chain(&self.surface, &self.sc_desc); + self.config.width = new_size.width; + self.config.height = new_size.height; + self.surface.configure(&self.device, &self.config); } } ``` -There's nothing really different here from creating the `swap_chain` initially, so I won't get into it. +There's nothing really different here from configurating the `surface` initially, so I won't get into it. We call this method in `main()` in the event loop for the following events. @@ -254,20 +274,27 @@ fn update(&mut self) { } ``` +We'll add some code here later on to move around objects. + ## render() -Here's where the magic happens. First we need to get a frame to render to. This will include a `wgpu::Texture` and `wgpu::TextureView` that will hold the actual image we're drawing to (we'll cover this more when we talk about textures). +Here's where the magic happens. First we need to get a frame to render to. ```rust // impl State -fn render(&mut self) -> Result<(), wgpu::SwapChainError> { - let frame = self - .swap_chain - .get_current_frame()? - .output; +fn render(&mut self) -> Result<(), wgpu::SurfaceError> { + let output = self.surface.get_current_frame()?.output; ``` +The `get_current_frame` function will wait for the `surface` to provide a new `SurfaceTexture` that we will render to. We'll store this in `output` for later. + +```rust + let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default()); +``` + +This line creates a `TextureView` with default settings. We need to do this because we want to control how the render code interacts with the texture. + We also need to create a `CommandEncoder` to create the actual commands to send to the gpu. Most modern graphics frameworks expect commands to be stored in a command buffer before being sent to the gpu. The `encoder` builds a command buffer that we can then send to the gpu. ```rust @@ -282,21 +309,19 @@ Now we can actually get to clearing the screen (long time coming). We need to us { let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), - color_attachments: &[ - wgpu::RenderPassColorAttachment { - view: &frame.view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }), - store: true, - } - } - ], + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }), + store: true, + }, + }], depth_stencil_attachment: None, }); } @@ -325,10 +350,10 @@ event_loop.run(move |event, _, control_flow| { state.update(); match state.render() { Ok(_) => {} - // Recreate the swap_chain if lost - Err(wgpu::SwapChainError::Lost) => state.resize(state.size), + // Reconfigure the surface if lost + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SwapChainError::OutOfMemory) => *control_flow = ControlFlow::Exit, + Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, // All other errors (Outdated, Timeout) should be resolved by the next frame Err(e) => eprintln!("{:?}", e), } @@ -361,11 +386,13 @@ Some of you may be able to tell what's going on just by looking at it, but I'd b } ``` -A `RenderPassDescriptor` only has three fields: `label`, `color_attachments` and `depth_stencil_attachment`. The `color_attachements` describe where we are going to draw our color to. We'll use `depth_stencil_attachment` later, but we'll set it to `None` for now. +A `RenderPassDescriptor` only has three fields: `label`, `color_attachments` and `depth_stencil_attachment`. The `color_attachements` describe where we are going to draw our color to. We use the `TextureView` we created earlier to make sure that we render to the screen. + +We'll use `depth_stencil_attachment` later, but we'll set it to `None` for now. ```rust wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -375,15 +402,15 @@ wgpu::RenderPassColorAttachment { a: 1.0, }), store: true, - } + }, } ``` -The `RenderPassColorAttachment` has the `view` field which informs `wgpu` what texture to save the colors to. In this case we specify `frame.view` that we created using `swap_chain.get_current_frame()`. This means that any colors we draw to this attachment will get drawn to the screen. +The `RenderPassColorAttachment` has the `view` field which informs `wgpu` what texture to save the colors to. In this case we specify `frame.view` that we created using `surface.get_current_frame()`. This means that any colors we draw to this attachment will get drawn to the screen. The `resolve_target` is the texture that will receive the resolved output. This will be the same as `attachment` unless multisampling is enabled. We don't need to specify this, so we leave it as `None`. -The `ops` field takes a `wpgu::Operations` object. This tells wgpu what to do with the colors on the screen (specified by `frame.view`). The `load` field tells wgpu how to handle colors stored from the previous frame. Currently we are clearing the screen with a bluish color. +The `ops` field takes a `wpgu::Operations` object. This tells wgpu what to do with the colors on the screen (specified by `frame.view`). The `load` field tells wgpu how to handle colors stored from the previous frame. Currently we are clearing the screen with a bluish color. The `store` field tells wgpu with we want to store the rendered results to the `Texture` behind our `TextureView` (in this case it's the `SurfaceTexture`). We use `true` as we do want to store our render results. There are cases when you wouldn't want to but those
@@ -393,6 +420,10 @@ It's not uncommon to not clear the screen if the screen is going to be completel
+## Validation Errors? + +If wgpu is using Vulkan on your machine, you may run into validation errors if you are running an older version of the Vulkan SDK. You should be using at least version `1.2.182` as older versions can give out some false positives. If errors persist, you may have encountered a bug in wgpu. You can post an issue at [https://github.com/gfx-rs/wgpu](https://github.com/gfx-rs/wgpu) + ## Challenge Modify the `input()` method to capture mouse events, and update the clear color using that. *Hint: you'll probably need to use `WindowEvent::CursorMoved`*. diff --git a/docs/beginner/tutorial2-swapchain/cleared-window.png b/docs/beginner/tutorial2-surface/cleared-window.png similarity index 100% rename from docs/beginner/tutorial2-swapchain/cleared-window.png rename to docs/beginner/tutorial2-surface/cleared-window.png diff --git a/docs/beginner/tutorial2-swapchain/no-clear.png b/docs/beginner/tutorial2-surface/no-clear.png similarity index 100% rename from docs/beginner/tutorial2-swapchain/no-clear.png rename to docs/beginner/tutorial2-surface/no-clear.png diff --git a/docs/beginner/tutorial3-pipeline/README.md b/docs/beginner/tutorial3-pipeline/README.md index aba90784..fe348f19 100644 --- a/docs/beginner/tutorial3-pipeline/README.md +++ b/docs/beginner/tutorial3-pipeline/README.md @@ -130,8 +130,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, // NEW! render_pipeline: wgpu::RenderPipeline, @@ -174,9 +173,9 @@ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescrip module: &shader, entry_point: "main", targets: &[wgpu::ColorTargetState { // 4. - format: sc_desc.format, + format: config.format, blend: Some(wgpu::BlendState::REPLACE), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), // continued ... @@ -185,8 +184,8 @@ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescrip Two things to note here: 1. Here you can specify which function inside of the shader should be called, which is known as the `entry_point`. These are the functions we marked with `[[stage(vertex)]]` and `[[stage(fragment)]]` 2. The `buffers` field tells `wgpu` what type of vertices we want to pass to the vertex shader. We're specifying the vertices in the vertex shader itself so we'll leave this empty. We'll put something there in the next tutorial. -3. The `fragment` is technically optional, so you have to wrap it in `Some()`. We need it if we want to store color data to the `swap_chain`. -4. The `targets` field tells `wgpu` what color outputs it should set up.Currently we only need one for the `swap_chain`. We use the `swap_chain`'s format so that copying to it is easy, and we specify that the blending should just replace old pixel data with new data. We also tell `wgpu` to write to all colors: red, blue, green, and alpha. *We'll talk more about*`color_state` *when we talk about textures.* +3. The `fragment` is technically optional, so you have to wrap it in `Some()`. We need it if we want to store color data to the `surface`. +4. The `targets` field tells `wgpu` what color outputs it should set up.Currently we only need one for the `surface`. We use the `surface`'s format so that copying to it is easy, and we specify that the blending should just replace old pixel data with new data. We also tell `wgpu` to write to all colors: red, blue, green, and alpha. *We'll talk more about*`color_state` *when we talk about textures.* ```rust primitive: wgpu::PrimitiveState { @@ -235,8 +234,7 @@ Self { surface, device, queue, - sc_desc, - swap_chain, + config, size, // NEW! render_pipeline, @@ -257,7 +255,7 @@ If you run your program now, it'll take a little longer to start, but it will st color_attachments: &[ // This is what [[location(0)]] in the fragment shader targets wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear( diff --git a/docs/beginner/tutorial4-buffer/README.md b/docs/beginner/tutorial4-buffer/README.md index b345a2fb..dbc7a01f 100644 --- a/docs/beginner/tutorial4-buffer/README.md +++ b/docs/beginner/tutorial4-buffer/README.md @@ -57,7 +57,7 @@ let vertex_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, } ); ``` @@ -105,8 +105,7 @@ Self { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -121,7 +120,7 @@ A `VertexBufferLayout` defines how a buffer is layed out in memory. Without this ```rust wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, // 1. - step_mode: wgpu::InputStepMode::Vertex, // 2. + step_mode: wgpu::VertexStepMode::Vertex, // 2. attributes: &[ // 3. wgpu::VertexAttribute { offset: 0, // 4. @@ -138,7 +137,7 @@ wgpu::VertexBufferLayout { ``` 1. The `array_stride` defines how wide a vertex is. When the shader goes to read the next vertex, it will skip over `array_stride` number of bytes. In our case, array_stride will probably be 24 bytes. -2. `step_mode` tells the pipeline how often it should move to the next vertex. This seems redundant in our case, but we can specify `wgpu::InputStepMode::Instance` if we only want to change vertices when we start drawing a new instance. We'll cover instancing in a later tutorial. +2. `step_mode` tells the pipeline how often it should move to the next vertex. This seems redundant in our case, but we can specify `wgpu::VertexStepMode::Instance` if we only want to change vertices when we start drawing a new instance. We'll cover instancing in a later tutorial. 3. Vertex attributes describe the individual parts of the vertex. Generally this is a 1:1 mapping with a struct's fields, which it is in our case. 4. This defines the `offset` in bytes that this attribute starts. The first attribute is usually zero, and any future attributes are the collective `size_of` the previous attributes data. 5. This tells the shader what location to store this attribute at. For example `[[location(0)]] x: vec3` in the vertex shader would correspond to the position field of the struct, while `[[location(1)]] x: vec3` would be the color field. @@ -156,7 +155,7 @@ impl Vertex { fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -181,7 +180,7 @@ Specifying the attributes as we did now is quite verbose. We could use the `vert ```rust wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3], } ``` @@ -241,8 +240,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, render_pipeline, vertex_buffer, num_vertices, @@ -350,7 +348,7 @@ let vertex_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(VERTICES), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, } ); // NEW! @@ -358,7 +356,7 @@ let index_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(INDICES), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, } ); let num_indices = INDICES.len() as u32; @@ -371,8 +369,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -389,8 +386,7 @@ Self { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -422,7 +418,7 @@ With all that you should have a garishly magenta pentagon in your window. If you use a color picker on the magenta pentagon, you'll get a hex value of #BC00BC. If you convert this to RGB values you'll get (188, 0, 188). Dividing these values by 255 to get them into the [0, 1] range we get roughly (0.737254902, 0, 0.737254902). This is not the same as we are using for our vertex colors which is (0.5, 0.0, 0.5). The reason for this has to do with color spaces. -Most monitors use a color space know as sRGB. Our swap chain is (most likely depending on what is returned from `adapter.get_swap_chain_preferred_format()`) using an sRGB texture format. The sRGB format stores colors according to their relative brightness instead of their actual brightness. The reason for this is that our eyes don't perceive light linearly. We notice more differences in darker colors than we do lighter colors. +Most monitors use a color space know as sRGB. Our surface is (most likely depending on what is returned from `surface.get_preferred_format()`) using an sRGB texture format. The sRGB format stores colors according to their relative brightness instead of their actual brightness. The reason for this is that our eyes don't perceive light linearly. We notice more differences in darker colors than we do lighter colors. You get an approximation of the correct color using the following formula: `srgb_color = (rgb_color / 255) ^ 2.2`. Doing this with an RGB value of (188, 0, 188) will give us (0.511397819, 0.0, 0.511397819). A little off from our (0.5, 0.0, 0.5). While you could tweak the formula to get the desired values, you'll likely save a lot of time by using textures instead as they are stored as sRGB by default, so they don't suffer from the same color inaccuracies that vertex colors do. We'll cover textures in the next lesson. diff --git a/docs/beginner/tutorial5-textures/README.md b/docs/beginner/tutorial5-textures/README.md index 4951fd67..8d9bc567 100644 --- a/docs/beginner/tutorial5-textures/README.md +++ b/docs/beginner/tutorial5-textures/README.md @@ -12,10 +12,10 @@ If we want to map an image to our mesh, we first need an image. Let's use this h We'll use the [image crate](https://crates.io/crates/image) to load our tree. We already added to our dependencies in the first section, so all we have to do is use it. -In `State`'s `new()` method add the following just after creating the `swap_chain`: +In `State`'s `new()` method add the following just after configuring the `surface`: ```rust -let swap_chain = device.create_swap_chain(&surface, &sc_desc); +surface.configure(&device, &config); // NEW! let diffuse_bytes = include_bytes!("happy-tree.png"); @@ -48,7 +48,7 @@ let diffuse_texture = device.create_texture( format: wgpu::TextureFormat::Rgba8UnormSrgb, // SAMPLED tells wgpu that we want to use this texture in shaders // COPY_DST means that we want to copy data to this texture - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, label: Some("diffuse_texture"), } ); @@ -87,7 +87,7 @@ let buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Temp Buffer"), contents: &diffuse_rgba, - usage: wgpu::BufferUsage::COPY_SRC, + usage: wgpu::BufferUsages::COPY_SRC, } ); @@ -169,7 +169,7 @@ let texture_bind_group_layout = device.create_bind_group_layout( entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, view_dimension: wgpu::TextureViewDimension::D2, @@ -179,7 +179,7 @@ let texture_bind_group_layout = device.create_bind_group_layout( }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { // This is only for TextureSampleType::Depth comparison: false, @@ -228,8 +228,7 @@ struct State { surface: wgpu::Surface, device: wgpu::Device, queue: wgpu::Queue, - sc_desc: wgpu::SwapChainDescriptor, - swap_chain: wgpu::SwapChain, + config: wgpu::SurfaceConfiguration, size: winit::dpi::PhysicalSize, render_pipeline: wgpu::RenderPipeline, vertex_buffer: wgpu::Buffer, @@ -249,8 +248,7 @@ impl State { surface, device, queue, - sc_desc, - swap_chain, + config, size, render_pipeline, vertex_buffer, @@ -318,7 +316,7 @@ impl Vertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -434,7 +432,7 @@ winit = "0.25" env_logger = "0.9" log = "0.4" pollster = "0.2" -wgpu = "0.9" +wgpu = "0.10" bytemuck = { version = "1.4", features = [ "derive" ] } anyhow = "1.0" // NEW! ``` @@ -484,12 +482,13 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, } ); queue.write_texture( wgpu::ImageCopyTexture { + aspect: wgpu::TextureAspect::All, texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, @@ -532,7 +531,7 @@ mod texture; The texture creation code in `new()` now gets a lot simpler: ```rust -let swap_chain = device.create_swap_chain(&surface, &sc_desc); +surface.configure(&device, &config); let diffuse_bytes = include_bytes!("happy-tree.png"); // CHANGED! let diffuse_texture = texture::Texture::from_bytes(&device, &queue, diffuse_bytes, "happy-tree.png").unwrap(); // CHANGED! diff --git a/docs/beginner/tutorial6-uniforms/README.md b/docs/beginner/tutorial6-uniforms/README.md index 90e8e282..e23527aa 100644 --- a/docs/beginner/tutorial6-uniforms/README.md +++ b/docs/beginner/tutorial6-uniforms/README.md @@ -69,7 +69,7 @@ async fn new(window: &Window) -> Self { target: (0.0, 0.0, 0.0).into(), // which way is "up" up: cgmath::Vector3::unit_y(), - aspect: sc_desc.width as f32 / sc_desc.height as f32, + aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, @@ -126,7 +126,7 @@ let camera_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Camera Buffer"), contents: bytemuck::cast_slice(&[camera_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, } ); ``` @@ -140,7 +140,7 @@ let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupL entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -408,7 +408,7 @@ fn input(&mut self, event: &WindowEvent) -> bool { Up to this point, the camera controller isn't actually doing anything. The values in our uniform buffer need to be updated. There are a few main methods to do that. 1. We can create a separate buffer and copy it's contents to our `camera_buffer`. The new buffer is known as a staging buffer. This method is usually how it's done as it allows the contents of the main buffer (in this case `camera_buffer`) to only be accessible by the gpu. The gpu can do some speed optimizations which it couldn't if we could access the buffer via the cpu. -2. We can call on of the mapping method's `map_read_async`, and `map_write_async` on the buffer itself. These allow us to access a buffer's contents directly, but requires us to deal with the `async` aspect of these methods this also requires our buffer to use the `BufferUsage::MAP_READ` and/or `BufferUsage::MAP_WRITE`. We won't talk about it here, but you check out [Wgpu without a window](../../showcase/windowless) tutorial if you want to know more. +2. We can call on of the mapping method's `map_read_async`, and `map_write_async` on the buffer itself. These allow us to access a buffer's contents directly, but requires us to deal with the `async` aspect of these methods this also requires our buffer to use the `BufferUsages::MAP_READ` and/or `BufferUsages::MAP_WRITE`. We won't talk about it here, but you check out [Wgpu without a window](../../showcase/windowless) tutorial if you want to know more. 3. We can use `write_buffer` on `queue`. We're going to use option number 3. diff --git a/docs/beginner/tutorial7-instancing/README.md b/docs/beginner/tutorial7-instancing/README.md index 2b35df81..cbe73dee 100644 --- a/docs/beginner/tutorial7-instancing/README.md +++ b/docs/beginner/tutorial7-instancing/README.md @@ -123,7 +123,7 @@ let instance_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Instance Buffer"), contents: bytemuck::cast_slice(&instance_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, } ); ``` @@ -139,7 +139,7 @@ impl InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, diff --git a/docs/beginner/tutorial8-depth/README.md b/docs/beginner/tutorial8-depth/README.md index ddb12c66..bb145bca 100644 --- a/docs/beginner/tutorial8-depth/README.md +++ b/docs/beginner/tutorial8-depth/README.md @@ -26,10 +26,10 @@ Let's make a function to create the depth texture in `texture.rs`. impl Texture { pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; // 1. - pub fn create_depth_texture(device: &wgpu::Device, sc_desc: &wgpu::SwapChainDescriptor, label: &str) -> Self { + pub fn create_depth_texture(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration, label: &str) -> Self { let size = wgpu::Extent3d { // 2. - width: sc_desc.width, - height: sc_desc.height, + width: config.width, + height: config.height, depth_or_array_layers: 1, }; let desc = wgpu::TextureDescriptor { @@ -39,8 +39,8 @@ impl Texture { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT // 3. - | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT // 3. + | wgpu::TextureUsages::TEXTURE_BINDING, }; let texture = device.create_texture(&desc); @@ -66,7 +66,7 @@ impl Texture { ``` 1. We need the DEPTH_FORMAT for when we create the depth stage of the `render_pipeline` and creating the depth texture itself. -2. Our depth texture needs to be the same size as our screen if we want things to render correctly. We can use our `sc_desc` to make sure that our depth texture is the same size as our swap chain images. +2. Our depth texture needs to be the same size as our screen if we want things to render correctly. We can use our `config` to make sure that our depth texture is the same size as our surface textures. 3. Since we are rendering to this texture, we need to add the `RENDER_ATTACHMENT` flag to it. 4. We technically don't *need* a sampler for a depth texture, but our `Texture` struct requires it, and we need one if we ever want to sample it. 5. If we do decide to render our depth texture, we need to use `CompareFunction::LessEqual`. This is due to how the `samplerShadow` and `sampler2DShadow()` interacts with the `texture()` function in GLSL. @@ -74,7 +74,7 @@ impl Texture { We create our `depth_texture` in `State::new()`. ```rust -let depth_texture = texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture"); +let depth_texture = texture::Texture::create_depth_texture(&device, &config, "depth_texture"); ``` We need to modify our `render_pipeline` to allow depth testing. @@ -129,13 +129,13 @@ We need to remember to change the `resize()` method to create a new `depth_textu fn resize(&mut self, new_size: winit::dpi::PhysicalSize) { // ... - self.depth_texture = texture::Texture::create_depth_texture(&self.device, &self.sc_desc, "depth_texture"); + self.depth_texture = texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); // ... } ``` -Make sure you update the `depth_texture` *after* you update `sc_desc`. If you don't, your program will crash as the `depth_texture` will be a different size than the `swap_chain` texture. +Make sure you update the `depth_texture` *after* you update `config`. If you don't, your program will crash as the `depth_texture` will be a different size than the `surface` texture. The last change we need to make is in the `render()` function. We've created the `depth_texture`, but we're not currently using it. We use it by attaching it to the `depth_stencil_attachment` of a render pass. diff --git a/docs/beginner/tutorial9-models/README.md b/docs/beginner/tutorial9-models/README.md index a0fe0987..e3261feb 100644 --- a/docs/beginner/tutorial9-models/README.md +++ b/docs/beginner/tutorial9-models/README.md @@ -37,7 +37,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -126,7 +126,15 @@ glob = "0.3" ## Loading models with TOBJ -We're going to use the [tobj](https://docs.rs/tobj/0.1.12/tobj/) library to load our model. Before we can load our model though, we need somewhere to put it. +We're going to use the [tobj](https://docs.rs/tobj/3.0/tobj/) library to load our model. Let's add it to our `Cargo.toml`. + +```toml +[dependencies] +# other dependencies... +tobj = "3.0" +``` + +Before we can load our model though, we need somewhere to put it. ```rust // model.rs @@ -263,14 +271,14 @@ impl Model { &wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Vertex Buffer", path.as_ref())), contents: bytemuck::cast_slice(&vertices), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, } ); let index_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", path.as_ref())), contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, } ); diff --git a/docs/intermediate/tutorial10-lighting/README.md b/docs/intermediate/tutorial10-lighting/README.md index 4f248506..854ed6dc 100644 --- a/docs/intermediate/tutorial10-lighting/README.md +++ b/docs/intermediate/tutorial10-lighting/README.md @@ -46,7 +46,7 @@ let light_buffer = device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("Light VB"), contents: bytemuck::cast_slice(&[light_uniform]), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, } ); ``` @@ -58,7 +58,7 @@ let light_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -137,7 +137,7 @@ fn create_render_pipeline( alpha: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -180,7 +180,7 @@ let render_pipeline = { create_render_pipeline( &device, &render_pipeline_layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc(), InstanceRaw::desc()], shader, @@ -294,7 +294,7 @@ let light_render_pipeline = { create_render_pipeline( &device, &layout, - sc_desc.format, + config.format, Some(texture::Texture::DEPTH_FORMAT), &[model::ModelVertex::desc()], shader, @@ -439,7 +439,7 @@ Finally we want to add Light rendering to our render passes. ```rust impl State { // ... - fn render(&mut self) -> Result<(), wgpu::SwapChainError> { + fn render(&mut self) -> Result<(), wgpu::SurfaceError> { // ... render_pass.set_vertex_buffer(1, self.instance_buffer.slice(..)); @@ -628,7 +628,7 @@ impl model::Vertex for InstanceRaw { // We need to switch from using a step mode of Vertex to Instance // This means that our shaders will only change to use the next // instance when the shader starts processing a new instance - step_mode: wgpu::InputStepMode::Instance, + step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { offset: 0, @@ -820,7 +820,7 @@ let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupL entries: &[ wgpu::BindGroupLayoutBinding { // ... - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, // Updated! + visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, // Updated! // ... }, // ... diff --git a/docs/intermediate/tutorial11-normals/README.md b/docs/intermediate/tutorial11-normals/README.md index 89acb528..a25abc3c 100644 --- a/docs/intermediate/tutorial11-normals/README.md +++ b/docs/intermediate/tutorial11-normals/README.md @@ -30,7 +30,7 @@ let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroup // normal map wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -40,7 +40,7 @@ let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroup }, wgpu::BindGroupLayoutEntry { binding: 3, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, filtering: true, @@ -190,7 +190,7 @@ impl Vertex for ModelVertex { use std::mem; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ // ... @@ -425,7 +425,7 @@ pub fn from_image( } else { wgpu::TextureFormat::Rgba8UnormSrgb }, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); // ... diff --git a/docs/intermediate/tutorial12-camera/README.md b/docs/intermediate/tutorial12-camera/README.md index fde04380..ade3690b 100644 --- a/docs/intermediate/tutorial12-camera/README.md +++ b/docs/intermediate/tutorial12-camera/README.md @@ -284,7 +284,7 @@ impl State { // UPDATED! let camera = camera::Camera::new((0.0, 5.0, 10.0), cgmath::Deg(-90.0), cgmath::Deg(-20.0)); - let projection = camera::Projection::new(sc_desc.width, sc_desc.height, cgmath::Deg(45.0), 0.1, 100.0); + let projection = camera::Projection::new(config.width, config.height, cgmath::Deg(45.0), 0.1, 100.0); let camera_controller = camera::CameraController::new(4.0, 0.4); // ... diff --git a/docs/intermediate/tutorial13-threading/README.md b/docs/intermediate/tutorial13-threading/README.md index d6f3b124..13ae9787 100644 --- a/docs/intermediate/tutorial13-threading/README.md +++ b/docs/intermediate/tutorial13-threading/README.md @@ -92,7 +92,7 @@ impl Model { &wgpu::util::BufferInitDescriptor { label: Some(&format!("{:?} Index Buffer", m.name)), // UPDATED! contents: bytemuck::cast_slice(&m.mesh.indices), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, } ); // ... diff --git a/docs/news/README.md b/docs/news/README.md index 7a2571b5..26fb6b92 100644 --- a/docs/news/README.md +++ b/docs/news/README.md @@ -27,7 +27,7 @@ The `wgpu_glyph`, and `imgui-wgpu` crates currently depend on `wgpu` 0.7, which * `CullMode` is no longer a thing, instead `PrimitiveState::cull_mode` will require an `Option` * Added `clamp_depth` and `conservative` to `PrimitiveState`. Part of this means that `DepthStencilState` no longer has a `clamp_depth` field. * `color_blend` and `alpha_blend` have been moved into the new `blend` field with accepts an `Option` -* `adapter.get_swap_chain_preferred_format()` now returns an `Option` +* `adapter.get_preferred_format()` now returns an `Option` * `wgpu::RenderPassColorAttachmentDescriptor` has been renamed `wgpu::RenderPassColorAttachement` and the `attachment` field has been renamed to `view` * `wgpu::RenderPassDepthStencialAttachmentDescriptor` also loses the `Descriptor` part of it's name. `attachment` gets renamed to `view` as well. * `wgpu::TextureCopyView` has been renamed to `wgpu::ImageCopyTexture`. This is a typedef for `wgpu::ImageCopyTextureBase` @@ -42,7 +42,7 @@ There were a lot of changes particularly to the `RenderPipelineDescriptor`. Most School is starting to ramp up, so I haven't had as much time to work on the site as I would like to. Because of that there were some issues piling up. I decided to tackle a bunch of them in one go. Here's a snapshot of what I did: -* The tutorial now handles `SwapChainError` properly +* The tutorial now handles `SurfaceError` properly * I'm now using bytemuck's derive feature on all buffer data structs. * The [instancing tutorial](../beginner/tutorial7-instancing) now uses vertex buffers instead of storage buffers. * `build.rs` now updates when individual shaders are changed, not whenever `/src` is changed. @@ -88,7 +88,7 @@ Up to this point, we created textures manually everytime. I've pulled out the te ## Fixed panics do to not specifying the correct `usage` -Wgpu has become more strict about what `BufferUsage`s and `TextureUsage`s are required when performing certain operations. For example int the [Wgpu without a window example](/intermediate/windowless/), the `texture_desc` only specified the usage to by `COPY_SRC`. This caused a crash when the `texture` was used as a render target. Adding `OUTPUT_ATTACHMENT` fixed the issue. +Wgpu has become more strict about what `BufferUsages`s and `TextureUsages`s are required when performing certain operations. For example int the [Wgpu without a window example](/intermediate/windowless/), the `texture_desc` only specified the usage to by `COPY_SRC`. This caused a crash when the `texture` was used as a render target. Adding `OUTPUT_ATTACHMENT` fixed the issue. ## Updating Winit from 0.20.0-alpha5 to 0.20 diff --git a/docs/showcase/gifs/README.md b/docs/showcase/gifs/README.md index 97e1fc81..2fe39df4 100644 --- a/docs/showcase/gifs/README.md +++ b/docs/showcase/gifs/README.md @@ -60,8 +60,8 @@ let rt_desc = wgpu::TextureDescriptor { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::COPY_SRC - | wgpu::TextureUsage::RENDER_ATTACHMENT, + usage: wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::RENDER_ATTACHMENT, label: None, }; let render_target = framework::Texture::from_descriptor(&device, rt_desc); @@ -80,7 +80,7 @@ let padded_bytes_per_row = unpadded_bytes_per_row + padding; let buffer_size = (padded_bytes_per_row * texture_size) as wgpu::BufferAddress; let buffer_desc = wgpu::BufferDescriptor { size: buffer_size, - usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::MAP_READ, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, label: Some("Output Buffer"), mapped_at_creation: false, }; diff --git a/docs/showcase/imgui-demo/README.md b/docs/showcase/imgui-demo/README.md index d52f0893..505c4973 100644 --- a/docs/showcase/imgui-demo/README.md +++ b/docs/showcase/imgui-demo/README.md @@ -2,7 +2,11 @@
-This example is currently broken for 0.8. Some of the dependecies used are still on wgpu 0.7 which causes some dependency conflicts. Once the `imgui-wgpu` crate has been updated to use wgpu 0.8 I'll update the dependencies and remove this warning. +This example is currently broken. It got behind when I was migrating the tutorial to 0.8 as the imgui_wgpu crate was still on 0.7 at the time. I haven't updated it since. While the fixing it wouldn't be too hard (feel free to send a PR), I'm considering removing this example entirely. + +This tutorial is focused how to use wgpu (and by extension the WebGPU standard). I'm looking to minimize the amount of wgpu-adjacent crates that I'm using. They can get in the way of keeping this tutorial as current as possible, and often a crate I'm using will have a different version of wgpu (or winit as is the case as of writing) preventing me from continuing with migration. Beyond dependency conflicts, I'd like to cover some of the topics that some of the existing crates implement such as text and guis. + +For the 0.10 migration I'll keep this example in and keep the showcase code excluded.
@@ -49,11 +53,11 @@ imgui.fonts().add_font(&[FontSource::DefaultFontData { }]); ``` -Then you need to create the renderer. We need to use the swap chains `TextureFormat` in order for things to work properly. +Then you need to create the renderer. We need to use the surface's `TextureFormat` in order for things to work properly. ```rust let renderer_config = RendererConfig { - texture_format: display.sc_desc.format, + texture_format: display.config.format, ..Default::default() }; let renderer = Renderer::new(&mut imgui, &display.device, &display.queue, renderer_config); @@ -105,8 +109,8 @@ self.canvas.render( &display.queue, &mut encoder, &output.view, - display.sc_desc.width as f32, - display.sc_desc.height as f32 + display.config.width as f32, + display.config.height as f32 ); // Render the UI @@ -118,7 +122,7 @@ if self.last_cursor != ui.mouse_cursor() { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("UI RenderPass"), color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.view, + view: &view, attachment: &output.view, resolve_target: None, ops: wgpu::Operations { diff --git a/docs/showcase/pong/README.md b/docs/showcase/pong/README.md index 2531237b..e65a7cd9 100644 --- a/docs/showcase/pong/README.md +++ b/docs/showcase/pong/README.md @@ -2,7 +2,7 @@
-This example is currently broken for 0.8. Some of the dependecies used are still on wgpu 0.7 which causes some dependency conflicts. Once the `imgui-wgpu` crate has been updated to use wgpu 0.8 I'll update the dependencies and remove this warning. +This example is currently broken. I'm planning on rewriting it to use `wgsl` as well as being more sound design wise.
diff --git a/docs/showcase/windowless/README.md b/docs/showcase/windowless/README.md index 1df807ec..11e06453 100644 --- a/docs/showcase/windowless/README.md +++ b/docs/showcase/windowless/README.md @@ -22,7 +22,7 @@ let (device, queue) = adapter ## A triangle without a window -Now we've talked about not needing to see what the gpu is doing, but we do need to see the results at some point. If we look back to talking about the [swap chain](/beginner/tutorial2-swapchain/#render) we see that we use `swap_chain.get_next_texture()` to grab a texture to draw to. We'll skip that step by creating the texture ourselves. One thing to note here is we need to specify `wgpu::TextureFormat::Rgba8UnormSrgb` to `format` instead of `adapter.get_swap_chain_preferred_format(&surface)` since PNG uses RGBA, not BGRA. +Now we've talked about not needing to see what the gpu is doing, but we do need to see the results at some point. If we look back to talking about the [surface](/beginner/tutorial2-surface/#render) we see that we use `surface.get_current_frame()` to grab a texture to draw to. We'll skip that step by creating the texture ourselves. One thing to note here is we need to specify `wgpu::TextureFormat::Rgba8UnormSrgb` to `format` instead of `surface.get_preferred_format(&adapter)` since PNG uses RGBA, not BGRA. ```rust let texture_size = 256u32; @@ -37,8 +37,8 @@ let texture_desc = wgpu::TextureDescriptor { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::COPY_SRC - | wgpu::TextureUsage::RENDER_ATTACHMENT + usage: wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::RENDER_ATTACHMENT , label: None, }; @@ -46,7 +46,7 @@ let texture = device.create_texture(&texture_desc); let texture_view = texture.create_view(&Default::default()); ``` -We're using `TextureUsage::OUTPUT_ATTACHMENT` so wgpu can render to our texture. The `TextureUsage::COPY_SRC` is so we can pull data out of the texture so we can save it to a file. +We're using `TextureUsages::OUTPUT_ATTACHMENT` so wgpu can render to our texture. The `TextureUsages::COPY_SRC` is so we can pull data out of the texture so we can save it to a file. While we can use this texture to draw our triangle, we need some way to get at the pixels inside it. Back in the [texture tutorial](/beginner/tutorial5-textures/) we used a buffer load color data from a file that we then copied into our buffer. Now we are going to do the reverse: copy data into a buffer from our texture to save into a file. We'll need a buffer big enough for our data. @@ -57,9 +57,9 @@ let u32_size = std::mem::size_of::() as u32; let output_buffer_size = (u32_size * texture_size * texture_size) as wgpu::BufferAddress; let output_buffer_desc = wgpu::BufferDescriptor { size: output_buffer_size, - usage: wgpu::BufferUsage::COPY_DST + usage: wgpu::BufferUsages::COPY_DST // this tells wpgu that we want to read this buffer from the cpu - | wgpu::BufferUsage::MAP_READ, + | wgpu::BufferUsages::MAP_READ, label: None, mapped_at_creation: false, }; @@ -152,7 +152,7 @@ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescrip format: texture_desc.format, alpha_blend: wgpu::BlendState::REPLACE, color_blend: wgpu::BlendState::REPLACE, - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), primitive: wgpu::PrimitiveState { @@ -215,7 +215,8 @@ There's not much we can do with the data when it's stuck in a `Texture`, so let' ```rust encoder.copy_texture_to_buffer( wgpu::ImageCopyTexture { - texture: &texture, + aspect: wgpu::TextureAspect::All, + texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, },