reworked swapchain tutorial to use surface

0.10
Ben Hansen 3 years ago
parent 30c5693fb9
commit b322b8f6b8

664
Cargo.lock generated

@ -26,6 +26,17 @@ version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "ahash"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]]
name = "aho-corasick"
version = "0.7.18"
@ -35,6 +46,10 @@ dependencies = [
"memchr",
]
[[package]]
name = "alignment"
version = "0.1.0"
[[package]]
name = "andrew"
version = "0.3.1"
@ -48,6 +63,21 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
[[package]]
name = "approx"
version = "0.4.0"
@ -62,6 +92,9 @@ name = "arrayvec"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd"
dependencies = [
"serde",
]
[[package]]
name = "ash"
@ -89,6 +122,12 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bit-set"
version = "0.5.2"
@ -127,6 +166,20 @@ name = "bytemuck"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "byteorder"
@ -178,6 +231,27 @@ dependencies = [
"num-traits",
]
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"winapi",
]
[[package]]
name = "cmake"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"
dependencies = [
"cc",
]
[[package]]
name = "cocoa"
version = "0.24.0"
@ -225,6 +299,26 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "compute"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"rayon",
"shaderc",
"tobj 2.0.4",
"wgpu",
"winit",
]
[[package]]
name = "copyless"
version = "0.1.5"
@ -508,9 +602,9 @@ dependencies = [
[[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"
@ -533,6 +627,34 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "framework"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"rayon",
"shaderc",
"thiserror",
"tobj 2.0.4",
"wgpu",
"wgpu-subscriber",
"winit",
]
[[package]]
name = "fs_extra"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
[[package]]
name = "fxhash"
version = "0.2.1"
@ -542,6 +664,27 @@ dependencies = [
"byteorder",
]
[[package]]
name = "getrandom"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi",
]
[[package]]
name = "gif"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af"
dependencies = [
"color_quant",
"lzw",
]
[[package]]
name = "gif"
version = "0.11.2"
@ -552,6 +695,33 @@ dependencies = [
"weezl",
]
[[package]]
name = "gifs"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"framework",
"fs_extra",
"gif 0.10.3",
"glob",
"image",
"log",
"pollster",
"shaderc",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "glow"
version = "0.11.0"
@ -609,7 +779,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash",
"ahash 0.4.7",
]
[[package]]
@ -648,7 +818,7 @@ dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"gif",
"gif 0.11.2",
"jpeg-decoder",
"num-iter",
"num-rational",
@ -683,6 +853,12 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "jni-sys"
version = "0.3.0"
@ -767,6 +943,12 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "lzw"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -776,6 +958,15 @@ dependencies = [
"libc",
]
[[package]]
name = "matchers"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
dependencies = [
"regex-automata",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
@ -881,8 +1072,9 @@ dependencies = [
[[package]]
name = "naga"
version = "0.6.0"
source = "git+https://github.com/gfx-rs/naga?rev=93db57c#93db57c12b4a5eff48bdd00c494efa5ec89567ad"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c5859e55c51da10b98e7a73068e0a0c5da7bbcae4fc38f86043d0c6d1b917cf"
dependencies = [
"bit-set",
"bitflags",
@ -891,6 +1083,7 @@ dependencies = [
"log",
"num-traits",
"petgraph",
"serde",
"spirv",
"thiserror",
]
@ -1111,7 +1304,7 @@ dependencies = [
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
"redox_syscall 0.2.10",
"smallvec",
"winapi",
]
@ -1124,14 +1317,20 @@ 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.19"
@ -1239,6 +1438,12 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_syscall"
version = "0.2.10"
@ -1259,6 +1464,15 @@ dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
@ -1271,6 +1485,17 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157"
[[package]]
name = "ron"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45005aa836116903a49cf3461474da697cfe66221762c6e95871092009ec86d6"
dependencies = [
"base64",
"bitflags",
"serde",
]
[[package]]
name = "rusttype"
version = "0.9.2"
@ -1281,6 +1506,12 @@ dependencies = [
"owned_ttf_parser",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "same-file"
version = "1.0.6"
@ -1313,6 +1544,60 @@ name = "serde"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "shaderc"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58da8aaf4ad3508598cdf098567114c98d5f455de7d69b1213232ac557bc67ea"
dependencies = [
"libc",
"shaderc-sys",
]
[[package]]
name = "shaderc-sys"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bd76ec0bd25f2017a65250373485e43cdc81b5cb8fd83c6115375c8d018cdf9"
dependencies = [
"cmake",
"libc",
]
[[package]]
name = "sharded-slab"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982"
dependencies = [
"lazy_static",
]
[[package]]
name = "slotmap"
@ -1404,6 +1689,26 @@ dependencies = [
"syn",
]
[[package]]
name = "thread-id"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1"
dependencies = [
"libc",
"redox_syscall 0.1.57",
"winapi",
]
[[package]]
name = "thread_local"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
dependencies = [
"once_cell",
]
[[package]]
name = "tiff"
version = "0.6.1"
@ -1415,6 +1720,21 @@ dependencies = [
"weezl",
]
[[package]]
name = "tobj"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2468f55be8e59cf7219f1685cf1af4eb00ef2314823a7941a41c8d69538f881b"
[[package]]
name = "tobj"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267a53ebc1139c69d3feedc33a381c382b2e3b0c47f44f48679e90c4a69b8dac"
dependencies = [
"ahash 0.7.4",
]
[[package]]
name = "toml"
version = "0.5.8"
@ -1424,6 +1744,69 @@ dependencies = [
"serde",
]
[[package]]
name = "tracing"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca517f43f0fb96e0c3072ed5c275fe5eece87e8cb52f4a77b69226d3b1c9df8"
dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-log"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-serde"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
dependencies = [
"serde",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9cbe87a2fa7e35900ce5de20220a582a9483a7063811defce79d7cbd59d4cfe"
dependencies = [
"ansi_term",
"chrono",
"lazy_static",
"matchers",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
"tracing-serde",
]
[[package]]
name = "ttf-parser"
version = "0.6.2"
@ -1431,11 +1814,113 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc"
[[package]]
name = "tutorial2-swapchain"
name = "tutorial1-window"
version = "0.1.0"
dependencies = [
"cgmath",
"env_logger",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial10-lighting"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "tutorial11-normals"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "tutorial12-camera"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "tutorial13-threading"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"rayon",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "tutorial2-surface"
version = "0.1.0"
dependencies = [
"cgmath",
"env_logger",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial3-pipeline"
version = "0.1.0"
dependencies = [
"anyhow",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
@ -1443,6 +1928,109 @@ dependencies = [
"winit",
]
[[package]]
name = "tutorial4-buffer"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial5-textures"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial6-uniforms"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial7-instancing"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial8-depth"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"wgpu",
"winit",
]
[[package]]
name = "tutorial9-models"
version = "0.1.0"
dependencies = [
"anyhow",
"bytemuck",
"cgmath",
"env_logger",
"fs_extra",
"glob",
"image",
"log",
"pollster",
"tobj 3.2.0",
"wgpu",
"winit",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
@ -1472,6 +2060,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.76"
@ -1613,9 +2207,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.53"
version = "0.3.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c"
checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -1630,13 +2224,15 @@ checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "wgpu"
version = "0.10.1"
source = "git+https://github.com/gfx-rs/wgpu/#ce35395910f104d7b064e1a7b94a79d1c9d10fbc"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d92a4fe73b1e7d7ef99938dacd49258cbf1ad87cdb5bf6efa20c27447442b45"
dependencies = [
"arrayvec",
"js-sys",
"log",
"parking_lot",
"raw-window-handle",
"serde",
"smallvec",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -1648,8 +2244,9 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.10.0"
source = "git+https://github.com/gfx-rs/wgpu/#ce35395910f104d7b064e1a7b94a79d1c9d10fbc"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "425b975c319d311e051bf3afb54120a34b187f9d889edc68e347567e512774c8"
dependencies = [
"arrayvec",
"bitflags",
@ -1661,6 +2258,8 @@ dependencies = [
"parking_lot",
"profiling",
"raw-window-handle",
"ron",
"serde",
"smallvec",
"thiserror",
"wgpu-hal",
@ -1669,8 +2268,9 @@ dependencies = [
[[package]]
name = "wgpu-hal"
version = "0.10.1"
source = "git+https://github.com/gfx-rs/wgpu/#ce35395910f104d7b064e1a7b94a79d1c9d10fbc"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b33daf5eff68118c0aad030886655824052f82a164fd2e257211f742c6cade53"
dependencies = [
"arrayvec",
"ash",
@ -1700,12 +2300,27 @@ dependencies = [
"winapi",
]
[[package]]
name = "wgpu-subscriber"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91955b0d6480d86e577bbd0b0d1dd5acd0699c054610dc8673c4c3366295ed27"
dependencies = [
"parking_lot",
"thread-id",
"tracing",
"tracing-log",
"tracing-subscriber",
]
[[package]]
name = "wgpu-types"
version = "0.10.0"
source = "git+https://github.com/gfx-rs/wgpu/#ce35395910f104d7b064e1a7b94a79d1c9d10fbc"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25feb2fbf24ab3219a9f10890ceb8e1ef02b13314ed89d64a9ae99dcad883e18"
dependencies = [
"bitflags",
"serde",
]
[[package]]
@ -1739,6 +2354,19 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windowless"
version = "0.1.0"
dependencies = [
"cgmath",
"image",
"pollster",
"raw-window-handle",
"shaderc",
"wgpu",
"winit",
]
[[package]]
name = "winit"
version = "0.25.0"

@ -2,14 +2,13 @@
resolver = "2"
members = [
# # beginner tutorials
# "code/beginner/*",
"code/beginner/*",
# # intermediate tutorials
# "code/intermediate/*",
"code/intermediate/*",
# # showcase
# "code/showcase/*",
"code/beginner/tutorial2-swapchain"
"code/showcase/*",
]
exclude = [
"code/showcase/imgui-demo",

@ -1,5 +1,5 @@
[package]
name = "tutorial2-swapchain"
name = "tutorial2-surface"
version = "0.1.0"
authors = ["Ben Hansen <bhbenjaminhansen@gmail.com>"]
edition = "2018"
@ -12,15 +12,15 @@ winit = "0.25"
cgmath = "0.18"
env_logger = "0.9"
log = "0.4"
# wgpu = "0.10"
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/"}
# 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]]

@ -131,7 +131,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| {

@ -7,10 +7,6 @@ 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,
@ -57,8 +53,6 @@ impl State {
surface.configure(&device, &config);
Self {
instance,
adapter,
surface,
device,
queue,
@ -124,7 +118,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| {

@ -239,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| {

@ -176,7 +176,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| {

@ -318,7 +318,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| {

@ -250,7 +250,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| {

@ -348,7 +348,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| {

@ -303,7 +303,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| {

@ -531,7 +531,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| {

@ -512,7 +512,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| {

@ -660,7 +660,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| {

@ -610,7 +610,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| {

@ -829,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| {

@ -639,7 +639,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| {

@ -556,7 +556,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| {

@ -17,6 +17,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.

@ -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.
@ -62,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.
<div class="note">
@ -79,11 +84,19 @@ let adapter = instance
.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).
</div>
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(
@ -100,11 +113,11 @@ The `features` field on `DeviceDescriptor`, allows us to specify what extra feat
<div class="note">
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).
</div>
@ -120,23 +133,31 @@ The `limits` field describes the limit of certain types of resource we can creat
};
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 `TextureUsages`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_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.
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 `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.
`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.
`width` and `height`, are the width and height in pixels of the `SurfaceTexture`. This should usually be the width and height of the window.
<div class="warning">
Make sure that the width and height of the `SurfaceTexture` are not 0, as that can cause your app to crash.
</div>
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 `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)
At the end of the method, we simply return the resulting struct.
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,
config,
swap_chain,
size,
}
}
@ -147,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));
```
@ -158,7 +179,7 @@ You can use heavier libraries like [async_std](https://docs.rs/async_std) and [t
</div>
## 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 `config` 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
@ -172,7 +193,7 @@ pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) {
}
```
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.
@ -253,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::SurfaceError> {
let frame = self
.swap_chain
.get_current_frame()?
.output;
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
@ -281,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,
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,
});
}
@ -324,7 +350,7 @@ event_loop.run(move |event, _, control_flow| {
state.update();
match state.render() {
Ok(_) => {}
// Recreate the swap_chain if lost
// 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::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
@ -360,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,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
@ -374,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
<div class="note">

Loading…
Cancel
Save