diff --git a/examples/triangle/Cargo.lock b/examples/triangle/Cargo.lock index aae3511..5653577 100644 --- a/examples/triangle/Cargo.lock +++ b/examples/triangle/Cargo.lock @@ -4,8 +4,14 @@ version = "0.1.0" dependencies = [ "ash 0.2.0", "glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winit 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "android_glue" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ash" version = "0.2.0" @@ -19,6 +25,25 @@ name = "bitflags" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cgl" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gleam 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cmake" version = "0.1.20" @@ -27,6 +52,67 @@ dependencies = [ "gcc 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cocoa" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-graphics" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dlib" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dtoa" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "dwmapi-sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "enum_primitive" version = "0.1.0" @@ -35,11 +121,48 @@ dependencies = [ "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fs2" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gcc" version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "gdi32-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gl_generator" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gleam" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "glfw" version = "0.9.1" @@ -62,6 +185,25 @@ dependencies = [ "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itoa" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "khronos_api" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "0.2.2" @@ -72,11 +214,41 @@ name = "libc" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libloading" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memmap" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fs2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nom" version = "1.2.4" @@ -148,6 +320,50 @@ name = "num-traits" version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "objc" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_codegen" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_generator" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "phf_shared" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "pkg-config" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand" version = "0.3.15" @@ -161,6 +377,19 @@ name = "rustc-serialize" version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rustc_version" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "semver" version = "0.2.3" @@ -169,6 +398,22 @@ dependencies = [ "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_json" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "shared_library" version = "0.1.5" @@ -178,16 +423,181 @@ dependencies = [ "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "shell32-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "target_build_utils" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tempfile" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "user32-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-client" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-scanner 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-kbd" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-scanner" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-sys" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wayland-window" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winit" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cocoa 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-kbd 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-window 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "x11-dl 2.11.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "x11-dl" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "xml-rs" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] +"checksum android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e2b80445d331077679dfc6f3014f3e9ab7083e588423d35041d3fc017198189" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" +"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" +"checksum cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8bdd78cca65a739cb5475dbf6b6bbb49373e327f4a6f2b499c0f98632df38c10" "checksum cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a6805df695087e7c1bcd9a82e03ad6fb864c8e67ac41b1348229ce5b7f0407" +"checksum cocoa 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1be5fd98bb7e8ef0eea233a4984f4e85ecdcfa002a90b8b12b7a20faf44dc1" +"checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" +"checksum core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "05eed248dc504a5391c63794fe4fb64f46f071280afaa1b73308f3c0ce4574c5" +"checksum core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66e998abb8823fecd2a8a7205429b17a340d447d8c69b3bce86846dcdea3e33b" +"checksum dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "148bce4ce1c36c4509f29cb54e62c2bd265551a9b00b38070fad551a851866ec" +"checksum dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0dd841b58510c9618291ffa448da2e4e0f699d984d436122372f446dae62263d" +"checksum dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07c4c7cc7b396419bc0a4d90371d0cee16cb5053b53647d287c0b728000c41fe" "checksum enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f79eff5be92a4d7d5bddf7daa7d650717ea71628634efe6ca7bcda85b2183c23" +"checksum fs2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bcd414e5a1a979b931bb92f41b7a54106d3f6d2e6c253e9ce943b7cd468251ef" "checksum gcc 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "872db9e59486ef2b14f8e8c10e9ef02de2bccef6363d7f34835dedb386b3d950" +"checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a" +"checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55" +"checksum gleam 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b83402229bde9d923f0b92811be017f9df5946ee86f8647367b1e02bcf5c293" "checksum glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b14e68c4ccefdf293ecb65390a5761971b83fcfc54d153a5b73d438327633965" "checksum glfw-sys 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0031461ad52978b865d3e9bafa2be2825052ddec12c56bbf2da2cf1c0274d6ea" +"checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09c9d3760673c427d46f91a0350f0a84a52e6bc5a84adf26dc610b6c52436630" "checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" "checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70" +"checksum libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "84816a8c6ed8163dfe0dbdd2b09d35c6723270ea77a4c7afa4bedf038a36cb99" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" +"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +"checksum memmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69253224aa10070855ea8fe9dbe94a03fc2b1d7930bb340c9e586a7513716fea" "checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" "checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" "checksum num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "88b14378471f7c2adc5262f05b4701ef53e8da376453a8d8fee48e51db745e49" @@ -196,7 +606,31 @@ dependencies = [ "checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" "checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf" "checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" +"checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e" +"checksum phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0c6afb2057bb5f846a7b75703f90bc1cef4970c35209f712925db7768e999202" +"checksum phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "6b63f121bf9a128f2172a65d8313a8e0e79d63874eeb4b4b7d82e6dda6b62f7c" +"checksum phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "50ffbd7970f75afa083c5dd7b6830c97b72b81579c7a92d8134ef2ee6c0c7eb0" +"checksum phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "286385a0e50d4147bce15b2c19f0cf84c395b0e061aaf840898a7bf664c2cfb7" +"checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" +"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" +"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" +"checksum serde 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "793aa8d4a777e46a68bbf88998cd957e638427ba5bfb0de22c92ff277b65bd21" +"checksum serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7d3c184d35801fb8b32b46a7d58d57dbcc150b0eb2b46a1eb79645e8ecfd5b" "checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a" +"checksum shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72f20b8f3c060374edb8046591ba28f62448c369ccbdc7b02075103fb3a9e38d" +"checksum target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54c550e226618cd35334b75e92bfa5437c61474bdb75c38bf330ab5a8037b77c" +"checksum tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9270837a93bad1b1dac18fe67e786b3c960513af86231f6f4f57fddd594ff0c8" +"checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504" +"checksum wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8c3e3edc131b755a1c6ab9873ce27557f5c5f075959597cd201bc00019555c9e" +"checksum wayland-kbd 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7707deadab966d6ea58651f4150add1fc442058a9598c3da11f0ce27c99f440f" +"checksum wayland-scanner 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c7459efa4b7bab8f34657ce6167ff470871cc7932d75cfc8db7e2ef99f81397b" +"checksum wayland-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bb879ab3916b7bbacda1258df0bc78eaa12b483f377a73ecc40b9f0b24f15465" +"checksum wayland-window 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3046a8f3e7d24fba7ec83ffcb0e03f4825041ca270c78a63f2ce1049dc20e52" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum winit 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "205495562dee0b698398cf7a13849c895473e1eb227af550d57b37ab1b6524b6" +"checksum x11-dl 2.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4c7f0a7fb861a1bde4aa23bbda9509bda6b87de4d47c322f86e4c88241ebdd" +"checksum xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b15eed12692bd59d15e98ee7f8dc8408465b992d8ddb4d1672c24865132ec7" diff --git a/examples/triangle/Cargo.toml b/examples/triangle/Cargo.toml index 7b32d83..1b850c4 100644 --- a/examples/triangle/Cargo.toml +++ b/examples/triangle/Cargo.toml @@ -5,4 +5,5 @@ authors = ["maik klein "] [dependencies] glfw = "0.9.1" +winit = "0.5.6" ash = { version = "*", path = "../../"} diff --git a/examples/triangle/src/main.rs b/examples/triangle/src/main.rs index 1a7a71d..59ff57a 100644 --- a/examples/triangle/src/main.rs +++ b/examples/triangle/src/main.rs @@ -1,11 +1,10 @@ #![allow(dead_code)] #[macro_use] extern crate ash; -extern crate glfw; +extern crate winit; use ash::vk; use std::default::Default; -use glfw::*; use ash::entry::Entry; use ash::instance::Instance; use ash::extensions::{Swapchain, XlibSurface, Surface, DebugReport}; @@ -16,6 +15,7 @@ use std::mem; use std::path::Path; use std::fs::File; use std::io::Read; +use winit::os::unix::WindowExt; // Simple offset_of macro akin to C++ offsetof macro_rules! offset_of{ @@ -31,10 +31,10 @@ macro_rules! offset_of{ #[cfg(all(unix, not(target_os = "android")))] fn create_surface(instance: &Instance, entry: &Entry, - window: &Window) + window: &winit::Window) -> Result { - let x11_display = window.glfw.get_x11_display(); - let x11_window = window.get_x11_window(); + let x11_display = window.get_xlib_display().unwrap(); + let x11_window = window.get_xlib_window().unwrap(); let x11_create_info = vk::XlibSurfaceCreateInfoKHR { s_type: vk::StructureType::XlibSurfaceCreateInfoKhr, p_next: ptr::null(), @@ -73,12 +73,6 @@ unsafe extern "system" fn vulkan_debug_callback(flags: vk::DebugReportFlagsEXT, println!("{:?}", CStr::from_ptr(p_message)); 1 } -fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) { - match event { - glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => window.set_should_close(true), - _ => {} - } -} pub fn find_memorytype_index(memory_req: &vk::MemoryRequirements, memory_prop: &vk::PhysicalDeviceMemoryProperties, @@ -99,357 +93,441 @@ struct Vertex { pos: [f32; 4], color: [f32; 4], } -fn main() { - unsafe { - let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap(); +fn resize_callback(width: u32, height: u32) { + println!("Window resized to {}x{}", width, height); +} - let window_width = 1920; - let window_height = 1080; +pub struct ExampleBase { + pub entry: Entry, + pub instance: Instance, + pub device: Device, + pub surface_loader: Surface, + pub swapchain_loader: Swapchain, + pub window: winit::Window, - let (mut window, events) = glfw.create_window(window_width, - window_height, - "Hello this is window", - glfw::WindowMode::Windowed) - .expect("Failed to create GLFW window."); + pub pdevice: vk::PhysicalDevice, + pub device_memory_properties: vk::PhysicalDeviceMemoryProperties, + pub queue_family_index: u32, + pub present_queue: vk::Queue, + pub surface_format: vk::SurfaceFormatKHR, + pub surface_resolution: vk::Extent2D, + pub swapchain: vk::SwapchainKHR, - window.set_key_polling(true); - window.make_current(); - glfw.set_swap_interval(0); - let entry = Entry::load_vulkan().unwrap(); - let instance_ext_props = entry.enumerate_instance_extension_properties().unwrap(); - let app_name = CString::new("VulkanTriangle").unwrap(); - let raw_name = app_name.as_ptr(); + pub present_images: Vec, + pub present_image_views: Vec, + pub pool: vk::CommandPool, + pub draw_command_buffer: vk::CommandBuffer, + pub setup_command_buffer: vk::CommandBuffer, - let layer_names = [CString::new("VK_LAYER_LUNARG_standard_validation").unwrap()]; - let layers_names_raw: Vec<*const i8> = layer_names.iter() - .map(|raw_name| raw_name.as_ptr()) - .collect(); - let extension_names = extension_names(); - let extension_names_raw: Vec<*const i8> = extension_names.iter() - .map(|raw_name| raw_name.as_ptr()) - .collect(); - let appinfo = vk::ApplicationInfo { - p_application_name: raw_name, - s_type: vk::StructureType::ApplicationInfo, - p_next: ptr::null(), - application_version: 0, - p_engine_name: raw_name, - engine_version: 0, - api_version: vk_make_version!(1, 0, 36), - }; - let create_info = vk::InstanceCreateInfo { - s_type: vk::StructureType::InstanceCreateInfo, - p_next: ptr::null(), - flags: Default::default(), - p_application_info: &appinfo, - pp_enabled_layer_names: layers_names_raw.as_ptr(), - enabled_layer_count: layers_names_raw.len() as u32, - pp_enabled_extension_names: extension_names_raw.as_ptr(), - enabled_extension_count: extension_names_raw.len() as u32, - }; - let instance: Instance = entry.create_instance(&create_info) - .expect("Instance creation error"); - let debug_info = vk::DebugReportCallbackCreateInfoEXT { - s_type: vk::StructureType::DebugReportCallbackCreateInfoExt, - p_next: ptr::null(), - flags: vk::DEBUG_REPORT_ERROR_BIT_EXT | vk::DEBUG_REPORT_WARNING_BIT_EXT | - vk::DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, - pfn_callback: vulkan_debug_callback, - p_user_data: ptr::null_mut(), - }; - let debug_report_loader = DebugReport::new(&entry, &instance) - .expect("Unable to load debug report"); - let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info) - .unwrap(); - let surface = create_surface(&instance, &entry, &window).unwrap(); - let pdevices = instance.enumerate_physical_devices().expect("Physical device error"); - let surface_loader = Surface::new(&entry, &instance) - .expect("Unable to load the Surface extension"); - let (pdevice, queue_family_index) = pdevices.iter() - .map(|pdevice| { - instance.get_physical_device_queue_family_properties(*pdevice) - .iter() - .enumerate() - .filter_map(|(index, ref info)| { - let supports_graphic_and_surface = - info.queue_flags.subset(vk::QUEUE_GRAPHICS_BIT) && - surface_loader.get_physical_device_surface_support_khr(*pdevice, - index as u32, - surface); - match supports_graphic_and_surface { - true => Some((*pdevice, index)), - _ => None, - } - }) - .nth(0) - }) - .filter_map(|v| v) - .nth(0) - .expect("Couldn't find suitable device."); - let queue_family_index = queue_family_index as u32; - let device_extension_names = [CString::new("VK_KHR_swapchain").unwrap()]; - let device_extension_names_raw: Vec<*const i8> = device_extension_names.iter() - .map(|raw_name| raw_name.as_ptr()) - .collect(); - let features = vk::PhysicalDeviceFeatures { shader_clip_distance: 1, ..Default::default() }; - let priorities = [1.0]; - let queue_info = vk::DeviceQueueCreateInfo { - s_type: vk::StructureType::DeviceQueueCreateInfo, - p_next: ptr::null(), - flags: Default::default(), - queue_family_index: queue_family_index as u32, - p_queue_priorities: priorities.as_ptr(), - queue_count: priorities.len() as u32, - }; - let device_create_info = vk::DeviceCreateInfo { - s_type: vk::StructureType::DeviceCreateInfo, - p_next: ptr::null(), - flags: Default::default(), - queue_create_info_count: 1, - p_queue_create_infos: &queue_info, - enabled_layer_count: 0, - pp_enabled_layer_names: ptr::null(), - enabled_extension_count: device_extension_names_raw.len() as u32, - pp_enabled_extension_names: device_extension_names_raw.as_ptr(), - p_enabled_features: &features, - }; - let device: Device = instance.create_device(pdevice, &device_create_info) - .unwrap(); - let present_queue = device.get_device_queue(queue_family_index as u32, 0); + pub depth_image: vk::Image, + pub depth_image_view: vk::ImageView, +} - let surface_formats = - surface_loader.get_physical_device_surface_formats_khr(pdevice, surface) - .unwrap(); - let surface_format = surface_formats.iter() - .map(|sfmt| { - match sfmt.format { - vk::Format::Undefined => { - vk::SurfaceFormatKHR { - format: vk::Format::B8g8r8Unorm, - color_space: sfmt.color_space, - } - } - _ => sfmt.clone(), - } - }) - .nth(0) - .expect("Unable to find suitable surface format."); - let surface_capabilities = - surface_loader.get_physical_device_surface_capabilities_khr(pdevice, surface).unwrap(); - let desired_image_count = surface_capabilities.min_image_count + 1; - assert!(surface_capabilities.min_image_count <= desired_image_count && - surface_capabilities.max_image_count >= desired_image_count, - "Image count err"); - let surface_resoultion = match surface_capabilities.current_extent.width { - std::u32::MAX => { - vk::Extent2D { - width: window_width, - height: window_height, +impl ExampleBase { + pub fn render_loop(&self, f: F) { + 'render: loop { + for event in self.window.poll_events() { + match event { + winit::Event::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) | + winit::Event::Closed => break 'render, + _ => (), } } - _ => surface_capabilities.current_extent, - }; - - let pre_transform = if surface_capabilities.supported_transforms - .subset(vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR) { - vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR - } else { - surface_capabilities.current_transform - }; - let present_modes = - surface_loader.get_physical_device_surface_present_modes_khr(pdevice, surface) + f(); + } + } + pub fn new(window_width: u32, window_height: u32) -> Self { + unsafe { + let window = winit::WindowBuilder::new() + .with_title("A fantastic window!") + .with_dimensions(window_width, window_height) + .with_window_resize_callback(resize_callback) + .build() .unwrap(); - let present_mode = present_modes.iter() - .cloned() - .find(|&mode| mode == vk::PresentModeKHR::Mailbox) - .unwrap_or(vk::PresentModeKHR::Fifo); - let swapchain_loader = Swapchain::new(&instance, &device) - .expect("Unable to load swapchain"); - let swapchain_create_info = vk::SwapchainCreateInfoKHR { - s_type: vk::StructureType::SwapchainCreateInfoKhr, - p_next: ptr::null(), - flags: Default::default(), - surface: surface, - min_image_count: desired_image_count, - image_color_space: surface_format.color_space, - image_format: surface_format.format, - image_extent: surface_resoultion.clone(), - image_usage: vk::IMAGE_USAGE_COLOR_ATTACHMENT_BIT, - image_sharing_mode: vk::SharingMode::Exclusive, - pre_transform: pre_transform, - composite_alpha: vk::COMPOSITE_ALPHA_OPAQUE_BIT_KHR, - present_mode: present_mode, - clipped: 1, - old_swapchain: vk::SwapchainKHR::null(), - image_array_layers: 1, - p_queue_family_indices: ptr::null(), - queue_family_index_count: 0, - }; - let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info).unwrap(); - let pool_create_info = vk::CommandPoolCreateInfo { - s_type: vk::StructureType::CommandPoolCreateInfo, - p_next: ptr::null(), - flags: vk::COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, - queue_family_index: queue_family_index, - }; - let pool = device.create_command_pool(&pool_create_info).unwrap(); - let command_buffer_allocate_info = vk::CommandBufferAllocateInfo { - s_type: vk::StructureType::CommandBufferAllocateInfo, - p_next: ptr::null(), - command_buffer_count: 2, - command_pool: pool, - level: vk::CommandBufferLevel::Primary, - }; - let command_buffers = device.allocate_command_buffers(&command_buffer_allocate_info) - .unwrap(); - let setup_command_buffer = command_buffers[0]; - let draw_command_buffer = command_buffers[1]; + let entry = Entry::load_vulkan().unwrap(); + let instance_ext_props = entry.enumerate_instance_extension_properties().unwrap(); + let app_name = CString::new("VulkanTriangle").unwrap(); + let raw_name = app_name.as_ptr(); - let present_images = swapchain_loader.get_swapchain_images_khr(swapchain).unwrap(); - let present_image_views: Vec = present_images.iter() - .map(|&image| { - let create_view_info = vk::ImageViewCreateInfo { - s_type: vk::StructureType::ImageViewCreateInfo, - p_next: ptr::null(), - flags: Default::default(), - view_type: vk::ImageViewType::Type2d, - format: surface_format.format, - components: vk::ComponentMapping { - r: vk::ComponentSwizzle::R, - g: vk::ComponentSwizzle::G, - b: vk::ComponentSwizzle::B, - a: vk::ComponentSwizzle::A, - }, - subresource_range: vk::ImageSubresourceRange { - aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT, - base_mip_level: 0, - level_count: 1, - base_array_layer: 0, - layer_count: 1, - }, - image: image, - }; - device.create_image_view(&create_view_info).unwrap() - }) - .collect(); - let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); - let depth_image_create_info = vk::ImageCreateInfo { - s_type: vk::StructureType::ImageCreateInfo, - p_next: ptr::null(), - flags: vk::IMAGE_CREATE_SPARSE_BINDING_BIT, - image_type: vk::ImageType::Type2d, - format: vk::Format::D16Unorm, - extent: vk::Extent3D { - width: surface_resoultion.width, - height: surface_resoultion.height, - depth: 1, - }, - mip_levels: 1, - array_layers: 1, - samples: vk::SAMPLE_COUNT_1_BIT, - tiling: vk::ImageTiling::Optimal, - usage: vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, - sharing_mode: vk::SharingMode::Exclusive, - queue_family_index_count: 0, - p_queue_family_indices: ptr::null(), - initial_layout: vk::ImageLayout::Undefined, - }; - let depth_image = device.create_image(&depth_image_create_info).unwrap(); - let depth_image_memory_req = device.get_image_memory_requirements(depth_image); - let depth_image_memory_index = find_memorytype_index(&depth_image_memory_req, - &device_memory_properties, - vk::MEMORY_PROPERTY_DEVICE_LOCAL_BIT) - .expect("Unable to find suitable memory index for depth image."); + let layer_names = [CString::new("VK_LAYER_LUNARG_standard_validation").unwrap()]; + let layers_names_raw: Vec<*const i8> = layer_names.iter() + .map(|raw_name| raw_name.as_ptr()) + .collect(); + let extension_names = extension_names(); + let extension_names_raw: Vec<*const i8> = extension_names.iter() + .map(|raw_name| raw_name.as_ptr()) + .collect(); + let appinfo = vk::ApplicationInfo { + p_application_name: raw_name, + s_type: vk::StructureType::ApplicationInfo, + p_next: ptr::null(), + application_version: 0, + p_engine_name: raw_name, + engine_version: 0, + api_version: vk_make_version!(1, 0, 36), + }; + let create_info = vk::InstanceCreateInfo { + s_type: vk::StructureType::InstanceCreateInfo, + p_next: ptr::null(), + flags: Default::default(), + p_application_info: &appinfo, + pp_enabled_layer_names: layers_names_raw.as_ptr(), + enabled_layer_count: layers_names_raw.len() as u32, + pp_enabled_extension_names: extension_names_raw.as_ptr(), + enabled_extension_count: extension_names_raw.len() as u32, + }; + let instance: Instance = entry.create_instance(&create_info) + .expect("Instance creation error"); + let debug_info = vk::DebugReportCallbackCreateInfoEXT { + s_type: vk::StructureType::DebugReportCallbackCreateInfoExt, + p_next: ptr::null(), + flags: vk::DEBUG_REPORT_ERROR_BIT_EXT | vk::DEBUG_REPORT_WARNING_BIT_EXT | + vk::DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, + pfn_callback: vulkan_debug_callback, + p_user_data: ptr::null_mut(), + }; + let debug_report_loader = DebugReport::new(&entry, &instance) + .expect("Unable to load debug report"); + let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info) + .unwrap(); + let surface = create_surface(&instance, &entry, &window).unwrap(); + let pdevices = instance.enumerate_physical_devices().expect("Physical device error"); + let surface_loader = Surface::new(&entry, &instance) + .expect("Unable to load the Surface extension"); + let (pdevice, queue_family_index) = pdevices.iter() + .map(|pdevice| { + instance.get_physical_device_queue_family_properties(*pdevice) + .iter() + .enumerate() + .filter_map(|(index, ref info)| { + let supports_graphic_and_surface = + info.queue_flags.subset(vk::QUEUE_GRAPHICS_BIT) && + surface_loader.get_physical_device_surface_support_khr(*pdevice, + index as u32, + surface); + match supports_graphic_and_surface { + true => Some((*pdevice, index)), + _ => None, + } + }) + .nth(0) + }) + .filter_map(|v| v) + .nth(0) + .expect("Couldn't find suitable device."); + let queue_family_index = queue_family_index as u32; + let device_extension_names = [CString::new("VK_KHR_swapchain").unwrap()]; + let device_extension_names_raw: Vec<*const i8> = device_extension_names.iter() + .map(|raw_name| raw_name.as_ptr()) + .collect(); + let features = + vk::PhysicalDeviceFeatures { shader_clip_distance: 1, ..Default::default() }; + let priorities = [1.0]; + let queue_info = vk::DeviceQueueCreateInfo { + s_type: vk::StructureType::DeviceQueueCreateInfo, + p_next: ptr::null(), + flags: Default::default(), + queue_family_index: queue_family_index as u32, + p_queue_priorities: priorities.as_ptr(), + queue_count: priorities.len() as u32, + }; + let device_create_info = vk::DeviceCreateInfo { + s_type: vk::StructureType::DeviceCreateInfo, + p_next: ptr::null(), + flags: Default::default(), + queue_create_info_count: 1, + p_queue_create_infos: &queue_info, + enabled_layer_count: 0, + pp_enabled_layer_names: ptr::null(), + enabled_extension_count: device_extension_names_raw.len() as u32, + pp_enabled_extension_names: device_extension_names_raw.as_ptr(), + p_enabled_features: &features, + }; + let device: Device = instance.create_device(pdevice, &device_create_info) + .unwrap(); + let present_queue = device.get_device_queue(queue_family_index as u32, 0); - let depth_image_allocate_info = vk::MemoryAllocateInfo { - s_type: vk::StructureType::MemoryAllocateInfo, - p_next: ptr::null(), - allocation_size: depth_image_memory_req.size, - memory_type_index: depth_image_memory_index, - }; - let depth_image_memory = device.allocate_memory(&depth_image_allocate_info).unwrap(); - device.bind_image_memory(depth_image, depth_image_memory, 0) - .expect("Unable to bind depth image memory"); + let surface_formats = + surface_loader.get_physical_device_surface_formats_khr(pdevice, surface) + .unwrap(); + let surface_format = surface_formats.iter() + .map(|sfmt| { + match sfmt.format { + vk::Format::Undefined => { + vk::SurfaceFormatKHR { + format: vk::Format::B8g8r8Unorm, + color_space: sfmt.color_space, + } + } + _ => sfmt.clone(), + } + }) + .nth(0) + .expect("Unable to find suitable surface format."); + let surface_capabilities = + surface_loader.get_physical_device_surface_capabilities_khr(pdevice, surface) + .unwrap(); + let desired_image_count = surface_capabilities.min_image_count + 1; + assert!(surface_capabilities.min_image_count <= desired_image_count && + surface_capabilities.max_image_count >= desired_image_count, + "Image count err"); + let surface_resolution = match surface_capabilities.current_extent.width { + std::u32::MAX => { + vk::Extent2D { + width: window_width, + height: window_height, + } + } + _ => surface_capabilities.current_extent, + }; + let pre_transform = if surface_capabilities.supported_transforms + .subset(vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR) { + vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR + } else { + surface_capabilities.current_transform + }; + let present_modes = + surface_loader.get_physical_device_surface_present_modes_khr(pdevice, surface) + .unwrap(); + let present_mode = present_modes.iter() + .cloned() + .find(|&mode| mode == vk::PresentModeKHR::Mailbox) + .unwrap_or(vk::PresentModeKHR::Fifo); + let swapchain_loader = Swapchain::new(&instance, &device) + .expect("Unable to load swapchain"); + let swapchain_create_info = vk::SwapchainCreateInfoKHR { + s_type: vk::StructureType::SwapchainCreateInfoKhr, + p_next: ptr::null(), + flags: Default::default(), + surface: surface, + min_image_count: desired_image_count, + image_color_space: surface_format.color_space, + image_format: surface_format.format, + image_extent: surface_resolution.clone(), + image_usage: vk::IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + image_sharing_mode: vk::SharingMode::Exclusive, + pre_transform: pre_transform, + composite_alpha: vk::COMPOSITE_ALPHA_OPAQUE_BIT_KHR, + present_mode: present_mode, + clipped: 1, + old_swapchain: vk::SwapchainKHR::null(), + image_array_layers: 1, + p_queue_family_indices: ptr::null(), + queue_family_index_count: 0, + }; + let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info).unwrap(); + let pool_create_info = vk::CommandPoolCreateInfo { + s_type: vk::StructureType::CommandPoolCreateInfo, + p_next: ptr::null(), + flags: vk::COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, + queue_family_index: queue_family_index, + }; + let pool = device.create_command_pool(&pool_create_info).unwrap(); + let command_buffer_allocate_info = vk::CommandBufferAllocateInfo { + s_type: vk::StructureType::CommandBufferAllocateInfo, + p_next: ptr::null(), + command_buffer_count: 2, + command_pool: pool, + level: vk::CommandBufferLevel::Primary, + }; + let command_buffer_allocate_info = vk::CommandBufferAllocateInfo { + s_type: vk::StructureType::CommandBufferAllocateInfo, + p_next: ptr::null(), + command_buffer_count: 2, + command_pool: pool, + level: vk::CommandBufferLevel::Primary, + }; + let command_buffers = device.allocate_command_buffers(&command_buffer_allocate_info) + .unwrap(); + let setup_command_buffer = command_buffers[0]; + let draw_command_buffer = command_buffers[1]; + + let present_images = swapchain_loader.get_swapchain_images_khr(swapchain).unwrap(); + let present_image_views: Vec = present_images.iter() + .map(|&image| { + let create_view_info = vk::ImageViewCreateInfo { + s_type: vk::StructureType::ImageViewCreateInfo, + p_next: ptr::null(), + flags: Default::default(), + view_type: vk::ImageViewType::Type2d, + format: surface_format.format, + components: vk::ComponentMapping { + r: vk::ComponentSwizzle::R, + g: vk::ComponentSwizzle::G, + b: vk::ComponentSwizzle::B, + a: vk::ComponentSwizzle::A, + }, + subresource_range: vk::ImageSubresourceRange { + aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT, + base_mip_level: 0, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }, + image: image, + }; + device.create_image_view(&create_view_info).unwrap() + }) + .collect(); + let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); + let depth_image_create_info = vk::ImageCreateInfo { + s_type: vk::StructureType::ImageCreateInfo, + p_next: ptr::null(), + flags: vk::IMAGE_CREATE_SPARSE_BINDING_BIT, + image_type: vk::ImageType::Type2d, + format: vk::Format::D16Unorm, + extent: vk::Extent3D { + width: surface_resolution.width, + height: surface_resolution.height, + depth: 1, + }, + mip_levels: 1, + array_layers: 1, + samples: vk::SAMPLE_COUNT_1_BIT, + tiling: vk::ImageTiling::Optimal, + usage: vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + sharing_mode: vk::SharingMode::Exclusive, + queue_family_index_count: 0, + p_queue_family_indices: ptr::null(), + initial_layout: vk::ImageLayout::Undefined, + }; + let depth_image = device.create_image(&depth_image_create_info).unwrap(); + let depth_image_memory_req = device.get_image_memory_requirements(depth_image); + let depth_image_memory_index = + find_memorytype_index(&depth_image_memory_req, + &device_memory_properties, + vk::MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + .expect("Unable to find suitable memory index for depth image."); + + let depth_image_allocate_info = vk::MemoryAllocateInfo { + s_type: vk::StructureType::MemoryAllocateInfo, + p_next: ptr::null(), + allocation_size: depth_image_memory_req.size, + memory_type_index: depth_image_memory_index, + }; + let depth_image_memory = device.allocate_memory(&depth_image_allocate_info).unwrap(); + device.bind_image_memory(depth_image, depth_image_memory, 0) + .expect("Unable to bind depth image memory"); + + let command_buffer_begin_info = vk::CommandBufferBeginInfo { + s_type: vk::StructureType::CommandBufferBeginInfo, + p_next: ptr::null(), + p_inheritance_info: ptr::null(), + flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, + }; + device.begin_command_buffer(setup_command_buffer, &command_buffer_begin_info).unwrap(); + let layout_transition_barrier = vk::ImageMemoryBarrier { + s_type: vk::StructureType::ImageMemoryBarrier, + p_next: ptr::null(), + src_access_mask: Default::default(), + dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, + old_layout: vk::ImageLayout::Undefined, + new_layout: vk::ImageLayout::DepthStencilAttachmentOptimal, + src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, + dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, + image: depth_image, + subresource_range: vk::ImageSubresourceRange { + aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, + base_mip_level: 0, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }, + }; + device.cmd_pipeline_barrier(setup_command_buffer, + vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT, + vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT, + vk::DependencyFlags::empty(), + &[], + &[], + &[layout_transition_barrier]); + let wait_stage_mask = [vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT]; + let fence_create_info = vk::FenceCreateInfo { + s_type: vk::StructureType::FenceCreateInfo, + p_next: ptr::null(), + flags: vk::FenceCreateFlags::empty(), + }; + let submit_fence = device.create_fence(&fence_create_info).unwrap(); + let submit_info = vk::SubmitInfo { + s_type: vk::StructureType::SubmitInfo, + p_next: ptr::null(), + wait_semaphore_count: 0, + p_wait_semaphores: ptr::null(), + signal_semaphore_count: 0, + p_signal_semaphores: ptr::null(), + p_wait_dst_stage_mask: wait_stage_mask.as_ptr(), + command_buffer_count: 1, + p_command_buffers: &setup_command_buffer, + }; + device.end_command_buffer(setup_command_buffer).unwrap(); + device.queue_submit(present_queue, &[submit_info], submit_fence).unwrap(); + device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap(); + let depth_image_view_info = vk::ImageViewCreateInfo { + s_type: vk::StructureType::ImageViewCreateInfo, + p_next: ptr::null(), + flags: Default::default(), + view_type: vk::ImageViewType::Type2d, + format: depth_image_create_info.format, + components: vk::ComponentMapping { + r: vk::ComponentSwizzle::Identity, + g: vk::ComponentSwizzle::Identity, + b: vk::ComponentSwizzle::Identity, + a: vk::ComponentSwizzle::Identity, + }, + subresource_range: vk::ImageSubresourceRange { + aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, + base_mip_level: 0, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }, + image: depth_image, + }; + let depth_image_view = device.create_image_view(&depth_image_view_info).unwrap(); + ExampleBase { + entry: entry, + instance: instance, + device: device, + queue_family_index: queue_family_index, + pdevice: pdevice, + device_memory_properties: device_memory_properties, + window: window, + surface_loader: surface_loader, + surface_format: surface_format, + present_queue: present_queue, + surface_resolution: surface_resolution, + swapchain_loader: swapchain_loader, + swapchain: swapchain, + present_images: present_images, + present_image_views: present_image_views, + pool: pool, + draw_command_buffer: draw_command_buffer, + setup_command_buffer: setup_command_buffer, + depth_image: depth_image, + depth_image_view: depth_image_view, + } + } + } +} +fn main() { + unsafe { + let base = ExampleBase::new(1920, 1080); + let fence_create_info = vk::FenceCreateInfo { + s_type: vk::StructureType::FenceCreateInfo, + p_next: ptr::null(), + flags: vk::FenceCreateFlags::empty(), + }; let command_buffer_begin_info = vk::CommandBufferBeginInfo { s_type: vk::StructureType::CommandBufferBeginInfo, p_next: ptr::null(), p_inheritance_info: ptr::null(), flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, }; - device.begin_command_buffer(setup_command_buffer, &command_buffer_begin_info).unwrap(); - let layout_transition_barrier = vk::ImageMemoryBarrier { - s_type: vk::StructureType::ImageMemoryBarrier, - p_next: ptr::null(), - src_access_mask: Default::default(), - dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | - vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, - old_layout: vk::ImageLayout::Undefined, - new_layout: vk::ImageLayout::DepthStencilAttachmentOptimal, - src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, - dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, - image: depth_image, - subresource_range: vk::ImageSubresourceRange { - aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, - base_mip_level: 0, - level_count: 1, - base_array_layer: 0, - layer_count: 1, - }, - }; - device.cmd_pipeline_barrier(setup_command_buffer, - vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT, - vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT, - vk::DependencyFlags::empty(), - &[], - &[], - &[layout_transition_barrier]); - let wait_stage_mask = [vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT]; - let fence_create_info = vk::FenceCreateInfo { - s_type: vk::StructureType::FenceCreateInfo, - p_next: ptr::null(), - flags: vk::FenceCreateFlags::empty(), - }; - let submit_fence = device.create_fence(&fence_create_info).unwrap(); - let submit_info = vk::SubmitInfo { - s_type: vk::StructureType::SubmitInfo, - p_next: ptr::null(), - wait_semaphore_count: 0, - p_wait_semaphores: ptr::null(), - signal_semaphore_count: 0, - p_signal_semaphores: ptr::null(), - p_wait_dst_stage_mask: wait_stage_mask.as_ptr(), - command_buffer_count: 1, - p_command_buffers: &setup_command_buffer, - }; - device.end_command_buffer(setup_command_buffer).unwrap(); - device.queue_submit(present_queue, &[submit_info], submit_fence).unwrap(); - device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap(); - let depth_image_view_info = vk::ImageViewCreateInfo { - s_type: vk::StructureType::ImageViewCreateInfo, - p_next: ptr::null(), - flags: Default::default(), - view_type: vk::ImageViewType::Type2d, - format: depth_image_create_info.format, - components: vk::ComponentMapping { - r: vk::ComponentSwizzle::Identity, - g: vk::ComponentSwizzle::Identity, - b: vk::ComponentSwizzle::Identity, - a: vk::ComponentSwizzle::Identity, - }, - subresource_range: vk::ImageSubresourceRange { - aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, - base_mip_level: 0, - level_count: 1, - base_array_layer: 0, - layer_count: 1, - }, - image: depth_image, - }; - let depth_image_view = device.create_image_view(&depth_image_view_info).unwrap(); let renderpass_attachments = [vk::AttachmentDescription { - format: surface_format.format, + format: base.surface_format.format, flags: vk::AttachmentDescriptionFlags::empty(), samples: vk::SAMPLE_COUNT_1_BIT, load_op: vk::AttachmentLoadOp::Clear, @@ -460,7 +538,7 @@ fn main() { final_layout: vk::ImageLayout::PresentSrcKhr, }, vk::AttachmentDescription { - format: depth_image_create_info.format, + format: vk::Format::D16Unorm, flags: vk::AttachmentDescriptionFlags::empty(), samples: vk::SAMPLE_COUNT_1_BIT, load_op: vk::AttachmentLoadOp::Clear, @@ -512,10 +590,11 @@ fn main() { dependency_count: 1, p_dependencies: &dependency, }; - let renderpass = device.create_render_pass(&renderpass_create_info).unwrap(); - let framebuffers: Vec = present_image_views.iter() + let renderpass = base.device.create_render_pass(&renderpass_create_info).unwrap(); + let framebuffers: Vec = base.present_image_views + .iter() .map(|&present_image_view| { - let framebuffer_attachments = [present_image_view, depth_image_view]; + let framebuffer_attachments = [present_image_view, base.depth_image_view]; let frame_buffer_create_info = vk::FramebufferCreateInfo { s_type: vk::StructureType::FramebufferCreateInfo, p_next: ptr::null(), @@ -523,11 +602,11 @@ fn main() { render_pass: renderpass, attachment_count: framebuffer_attachments.len() as u32, p_attachments: framebuffer_attachments.as_ptr(), - width: surface_resoultion.width, - height: surface_resoultion.height, + width: base.surface_resolution.width, + height: base.surface_resolution.height, layers: 1, }; - device.create_framebuffer(&frame_buffer_create_info).unwrap() + base.device.create_framebuffer(&frame_buffer_create_info).unwrap() }) .collect(); let index_buffer_data = [0u32, 1, 2]; @@ -541,10 +620,10 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let index_buffer = device.create_buffer(&index_buffer_info).unwrap(); - let index_buffer_memory_req = device.get_buffer_memory_requirements(index_buffer); + let index_buffer = base.device.create_buffer(&index_buffer_info).unwrap(); + let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); let index_buffer_memory_index = find_memorytype_index(&index_buffer_memory_req, - &device_memory_properties, + &base.device_memory_properties, vk::MEMORY_PROPERTY_HOST_VISIBLE_BIT) .expect("Unable to find suitable memorytype for the index buffer."); let index_allocate_info = vk::MemoryAllocateInfo { @@ -553,15 +632,16 @@ fn main() { allocation_size: index_buffer_memory_req.size, memory_type_index: index_buffer_memory_index, }; - let index_buffer_memory = device.allocate_memory(&index_allocate_info).unwrap(); - let index_slice = device.map_memory::(index_buffer_memory, + let index_buffer_memory = base.device.allocate_memory(&index_allocate_info).unwrap(); + let index_slice = base.device + .map_memory::(index_buffer_memory, 0, index_buffer_info.size, vk::MemoryMapFlags::empty()) .unwrap(); index_slice.copy_from_slice(&index_buffer_data); - device.unmap_memory(index_buffer_memory); - device.bind_buffer_memory(index_buffer, index_buffer_memory, 0).unwrap(); + base.device.unmap_memory(index_buffer_memory); + base.device.bind_buffer_memory(index_buffer, index_buffer_memory, 0).unwrap(); let vertex_input_buffer_info = vk::BufferCreateInfo { s_type: vk::StructureType::BufferCreateInfo, @@ -573,12 +653,12 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let vertex_input_buffer = device.create_buffer(&vertex_input_buffer_info).unwrap(); - let vertex_input_buffer_memory_req = - device.get_buffer_memory_requirements(vertex_input_buffer); + let vertex_input_buffer = base.device.create_buffer(&vertex_input_buffer_info).unwrap(); + let vertex_input_buffer_memory_req = base.device + .get_buffer_memory_requirements(vertex_input_buffer); let vertex_input_buffer_memory_index = find_memorytype_index(&vertex_input_buffer_memory_req, - &device_memory_properties, + &base.device_memory_properties, vk::MEMORY_PROPERTY_HOST_VISIBLE_BIT) .expect("Unable to find suitable memorytype for the vertex buffer."); @@ -588,7 +668,8 @@ fn main() { allocation_size: vertex_input_buffer_memory_req.size, memory_type_index: vertex_input_buffer_memory_index, }; - let vertex_input_buffer_memory = device.allocate_memory(&vertex_buffer_allocate_info) + let vertex_input_buffer_memory = base.device + .allocate_memory(&vertex_buffer_allocate_info) .unwrap(); let vertices = [Vertex { pos: [-1.0, 1.0, 0.0, 1.0], @@ -602,14 +683,15 @@ fn main() { pos: [0.0, -1.0, 0.0, 1.0], color: [1.0, 0.0, 0.0, 1.0], }]; - let slice = device.map_memory::(vertex_input_buffer_memory, + let slice = base.device + .map_memory::(vertex_input_buffer_memory, 0, vertex_input_buffer_info.size, vk::MemoryMapFlags::empty()) .unwrap(); slice.copy_from_slice(&vertices); - device.unmap_memory(vertex_input_buffer_memory); - device.bind_buffer_memory(vertex_input_buffer, vertex_input_buffer_memory, 0).unwrap(); + base.device.unmap_memory(vertex_input_buffer_memory); + base.device.bind_buffer_memory(vertex_input_buffer, vertex_input_buffer_memory, 0).unwrap(); let vertex_spv_file = File::open(Path::new("shader/vert.spv")) .expect("Could not find vert.spv."); let frag_spv_file = File::open(Path::new("shader/frag.spv")) @@ -631,10 +713,12 @@ fn main() { code_size: frag_bytes.len(), p_code: frag_bytes.as_ptr() as *const u32, }; - let vertex_shader_module = device.create_shader_module(&vertex_shader_info) + let vertex_shader_module = base.device + .create_shader_module(&vertex_shader_info) .expect("Vertex shader module error"); - let fragment_shader_module = device.create_shader_module(&frag_shader_info) + let fragment_shader_module = base.device + .create_shader_module(&frag_shader_info) .expect("Fragment shader module error"); let layout_create_info = vk::PipelineLayoutCreateInfo { @@ -647,7 +731,7 @@ fn main() { p_push_constant_ranges: ptr::null(), }; - let pipeline_layout = device.create_pipeline_layout(&layout_create_info).unwrap(); + let pipeline_layout = base.device.create_pipeline_layout(&layout_create_info).unwrap(); let shader_entry_name = CString::new("main").unwrap(); let shader_stage_create_infos = @@ -705,14 +789,14 @@ fn main() { let viewports = [vk::Viewport { x: 0.0, y: 0.0, - width: surface_resoultion.width as f32, - height: surface_resoultion.height as f32, + width: base.surface_resolution.width as f32, + height: base.surface_resolution.height as f32, min_depth: 0.0, max_depth: 1.0, }]; let scissors = [vk::Rect2D { offset: vk::Offset2D { x: 0, y: 0 }, - extent: surface_resoultion.clone(), + extent: base.surface_resolution.clone(), }]; let viewport_state_info = vk::PipelineViewportStateCreateInfo { s_type: vk::StructureType::PipelineViewportStateCreateInfo, @@ -822,9 +906,9 @@ fn main() { base_pipeline_handle: vk::Pipeline::null(), base_pipeline_index: 0, }; - let graphics_pipelines = - device.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info]) - .unwrap(); + let graphics_pipelines = base.device + .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info]) + .unwrap(); let graphic_pipeline = graphics_pipelines[0]; @@ -833,22 +917,23 @@ fn main() { p_next: ptr::null(), flags: Default::default(), }; - let present_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap(); - let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap(); + let present_complete_semaphore = + base.device.create_semaphore(&semaphore_create_info).unwrap(); + let rendering_complete_semaphore = + base.device.create_semaphore(&semaphore_create_info).unwrap(); - let draw_fence = device.create_fence(&fence_create_info).unwrap(); - while !window.should_close() { - glfw.poll_events(); - for (_, event) in glfw::flush_messages(&events) { - handle_window_event(&mut window, event); - } - let present_index = swapchain_loader.acquire_next_image_khr(swapchain, + let draw_fence = base.device.create_fence(&fence_create_info).unwrap(); + base.render_loop(|| { + let present_index = base.swapchain_loader + .acquire_next_image_khr(base.swapchain, std::u64::MAX, present_complete_semaphore, vk::Fence::null()) .unwrap(); - device.reset_command_buffer(draw_command_buffer, Default::default()).unwrap(); - device.begin_command_buffer(draw_command_buffer, &command_buffer_begin_info).unwrap(); + base.device.reset_command_buffer(base.draw_command_buffer, Default::default()).unwrap(); + base.device + .begin_command_buffer(base.draw_command_buffer, &command_buffer_begin_info) + .unwrap(); let clear_values = [vk::ClearValue::new_color(vk::ClearColorValue::new_float32([0.0, 0.0, 0.0, 0.0])), vk::ClearValue::new_depth_stencil(vk::ClearDepthStencilValue { @@ -863,31 +948,35 @@ fn main() { framebuffer: framebuffers[present_index as usize], render_area: vk::Rect2D { offset: vk::Offset2D { x: 0, y: 0 }, - extent: surface_resoultion.clone(), + extent: base.surface_resolution.clone(), }, clear_value_count: clear_values.len() as u32, p_clear_values: clear_values.as_ptr(), }; - device.cmd_begin_render_pass(draw_command_buffer, - &render_pass_begin_info, - vk::SubpassContents::Inline); - device.cmd_bind_pipeline(draw_command_buffer, - vk::PipelineBindPoint::Graphics, - graphic_pipeline); - device.cmd_set_viewport(draw_command_buffer, &viewports); - device.cmd_set_scissor(draw_command_buffer, &scissors); - device.cmd_bind_vertex_buffers(draw_command_buffer, &[vertex_input_buffer], &0); - device.cmd_bind_index_buffer(draw_command_buffer, index_buffer, 0, vk::IndexType::Uint32); - device.cmd_draw_indexed(draw_command_buffer, - index_buffer_data.len() as u32, - 1, - 0, - 0, - 1); + base.device.cmd_begin_render_pass(base.draw_command_buffer, + &render_pass_begin_info, + vk::SubpassContents::Inline); + base.device.cmd_bind_pipeline(base.draw_command_buffer, + vk::PipelineBindPoint::Graphics, + graphic_pipeline); + base.device.cmd_set_viewport(base.draw_command_buffer, &viewports); + base.device.cmd_set_scissor(base.draw_command_buffer, &scissors); + base.device + .cmd_bind_vertex_buffers(base.draw_command_buffer, &[vertex_input_buffer], &0); + base.device.cmd_bind_index_buffer(base.draw_command_buffer, + index_buffer, + 0, + vk::IndexType::Uint32); + base.device.cmd_draw_indexed(base.draw_command_buffer, + index_buffer_data.len() as u32, + 1, + 0, + 0, + 1); // Or draw without the index buffer // device.cmd_draw(draw_command_buffer, 3, 1, 0, 0); - device.cmd_end_render_pass(draw_command_buffer); - device.end_command_buffer(draw_command_buffer).unwrap(); + base.device.cmd_end_render_pass(base.draw_command_buffer); + base.device.end_command_buffer(base.draw_command_buffer).unwrap(); let wait_render_mask = [vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT]; let submit_info = vk::SubmitInfo { s_type: vk::StructureType::SubmitInfo, @@ -896,11 +985,12 @@ fn main() { p_wait_semaphores: &present_complete_semaphore, p_wait_dst_stage_mask: wait_render_mask.as_ptr(), command_buffer_count: 1, - p_command_buffers: &draw_command_buffer, + p_command_buffers: &base.draw_command_buffer, signal_semaphore_count: 1, p_signal_semaphores: &rendering_complete_semaphore, }; - device.queue_submit(present_queue, &[submit_info], draw_fence) + base.device + .queue_submit(base.present_queue, &[submit_info], draw_fence) .unwrap(); let mut present_info_err = unsafe { mem::uninitialized() }; let present_info = vk::PresentInfoKHR { @@ -909,46 +999,47 @@ fn main() { wait_semaphore_count: 1, p_wait_semaphores: &rendering_complete_semaphore, swapchain_count: 1, - p_swapchains: &swapchain, + p_swapchains: &base.swapchain, p_image_indices: &present_index, p_results: &mut present_info_err, }; - device.queue_present_khr(present_queue, &present_info).unwrap(); - device.wait_for_fences(&[draw_fence], true, std::u64::MAX) + base.device.queue_present_khr(base.present_queue, &present_info).unwrap(); + base.device + .wait_for_fences(&[draw_fence], true, std::u64::MAX) .unwrap(); - device.reset_fences(&[draw_fence]).unwrap(); - } + base.device.reset_fences(&[draw_fence]).unwrap(); + }); - device.device_wait_idle().unwrap(); - device.destroy_semaphore(present_complete_semaphore); - device.destroy_semaphore(rendering_complete_semaphore); - for pipeline in graphics_pipelines { - device.destroy_pipeline(pipeline); - } - device.destroy_pipeline_layout(pipeline_layout); - device.destroy_shader_module(vertex_shader_module); - device.destroy_shader_module(fragment_shader_module); - device.free_memory(index_buffer_memory); - device.destroy_buffer(index_buffer); - device.free_memory(vertex_input_buffer_memory); - device.destroy_buffer(vertex_input_buffer); - for framebuffer in framebuffers { - device.destroy_framebuffer(framebuffer); - } - device.destroy_render_pass(renderpass); - device.destroy_image_view(depth_image_view); - device.destroy_fence(submit_fence); - device.destroy_fence(draw_fence); - device.free_memory(depth_image_memory); - device.destroy_image(depth_image); - for image_view in present_image_views { - device.destroy_image_view(image_view); - } - device.destroy_command_pool(pool); - swapchain_loader.destroy_swapchain_khr(swapchain); - device.destroy_device(); - surface_loader.destroy_surface_khr(surface); - debug_report_loader.destroy_debug_report_callback_ext(debug_call_back); - instance.destroy_instance(); + // device.device_wait_idle().unwrap(); + // device.destroy_semaphore(present_complete_semaphore); + // device.destroy_semaphore(rendering_complete_semaphore); + // for pipeline in graphics_pipelines { + // device.destroy_pipeline(pipeline); + // } + // device.destroy_pipeline_layout(pipeline_layout); + // device.destroy_shader_module(vertex_shader_module); + // device.destroy_shader_module(fragment_shader_module); + // device.free_memory(index_buffer_memory); + // device.destroy_buffer(index_buffer); + // device.free_memory(vertex_input_buffer_memory); + // device.destroy_buffer(vertex_input_buffer); + // for framebuffer in framebuffers { + // device.destroy_framebuffer(framebuffer); + // } + // device.destroy_render_pass(renderpass); + // device.destroy_image_view(depth_image_view); + // device.destroy_fence(submit_fence); + // device.destroy_fence(draw_fence); + // device.free_memory(depth_image_memory); + // device.destroy_image(depth_image); + // for image_view in present_image_views { + // device.destroy_image_view(image_view); + // } + // device.destroy_command_pool(pool); + // swapchain_loader.destroy_swapchain_khr(swapchain); + // device.destroy_device(); + // surface_loader.destroy_surface_khr(surface); + // debug_report_loader.destroy_debug_report_callback_ext(debug_call_back); + // instance.destroy_instance(); } }