diff --git a/.gitignore b/.gitignore index db4a59b658..621da21d84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/*.rs.bk #Cargo.lock .vscode +build diff --git a/Cargo.lock b/Cargo.lock index c5914c520f..42272bac23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,6 +3,14 @@ name = "android_glue" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ash" version = "0.24.4" @@ -13,6 +21,16 @@ dependencies = [ "shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "atty" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "backtrace" version = "0.3.9" @@ -22,7 +40,7 @@ dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -49,6 +67,21 @@ name = "byteorder" version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cbindgen" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cc" version = "1.0.25" @@ -59,6 +92,20 @@ name = "cfg-if" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "clap" +version = "2.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -86,7 +133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (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.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "objc 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -118,7 +165,7 @@ dependencies = [ [[package]] name = "core-graphics" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -155,6 +202,13 @@ name = "either" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "examples" +version = "0.1.0" +dependencies = [ + "wgpu-native 0.1.0", +] + [[package]] name = "failure" version = "0.1.2" @@ -226,7 +280,7 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "spirv_cross 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "winit 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "wio 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -247,7 +301,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -255,7 +309,7 @@ dependencies = [ "objc 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "spirv_cross 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "spirv_cross 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "storage-map 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "winit 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -271,7 +325,7 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "winit 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)", "xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -306,6 +360,11 @@ dependencies = [ "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itoa" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "0.2.11" @@ -330,7 +389,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -364,7 +423,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -375,7 +434,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "cocoa 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-graphics 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -457,7 +516,7 @@ dependencies = [ "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -500,7 +559,7 @@ dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -508,11 +567,32 @@ name = "rand_core" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "redox_syscall" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "relevant" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "remove_dir_all" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.9" @@ -526,6 +606,11 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ryu" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "scopeguard" version = "0.3.3" @@ -544,6 +629,43 @@ name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "serde" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive_internals" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_json" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "shared_library" version = "0.1.9" @@ -587,7 +709,7 @@ dependencies = [ [[package]] name = "spirv_cross" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -606,6 +728,11 @@ dependencies = [ "lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "0.10.8" @@ -615,6 +742,16 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.14.9" @@ -625,6 +762,14 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synstructure" version = "0.9.0" @@ -636,6 +781,50 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tempfile" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "termion" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "textwrap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "toml" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.0.4" @@ -654,6 +843,11 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.4" @@ -714,6 +908,13 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wgpu-bindings" +version = "0.1.0" +dependencies = [ + "cbindgen 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wgpu-native" version = "0.1.0" @@ -725,11 +926,13 @@ dependencies = [ "gfx-backend-vulkan 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)", "gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)", "gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory?rev=483d64d)", + "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -763,7 +966,7 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "smithay-client-toolkit 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.20.12 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -772,7 +975,7 @@ name = "wio" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -813,21 +1016,25 @@ dependencies = [ [metadata] "checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ash 0.24.4 (registry+https://github.com/rust-lang/crates.io-index)" = "11f080bc0414ee1b6b959442cb36478d56c6e6b9bb2b04079a5048d9acc91a30" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" "checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" "checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" +"checksum cbindgen 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f1f920442b99c6eb6208905a2b71b055e4c8f170287fbe7c7ceb9b6cd206878d" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" +"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cocoa 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cd1afb83b2de9c41e5dfedb2bcccb779d433b958404876009ae4b01746ff23" "checksum cocoa 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53a840785348e998a1433d1f9d0b350fd83e91711fae8507c76ce510afc77e72" "checksum core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc3532ec724375c7cb7ff0a097b714fde180bb1f6ed2ab27cfcd99ffca873cd2" "checksum core-foundation-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a3fb15cdbdd9cf8b82d97d0296bb5cd3631bba58d6e31650a002a8e7fb5721f9" "checksum core-graphics 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92801c908ea6301ae619ed842a72e01098085fc321b9c2f3f833dad555bba055" -"checksum core-graphics 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de51fc45f0de4bc07e7ecdb172f0559e0f19ca016a0059577a149b11a2f05324" +"checksum core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "62ceafe1622ffc9a332199096841d0ff9912ec8cf8f9cde01e254a7d5217cd10" "checksum derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67b3d6d0e84e53a5bdc263cc59340541877bb541706a191d762bfac6a481bdde" "checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a" "checksum downcast-rs 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "18df8ce4470c189d18aa926022da57544f31e154631eb4cfe796aea97051fe6c" @@ -847,6 +1054,7 @@ dependencies = [ "checksum gfx-hal 0.1.0 (git+https://github.com/gfx-rs/gfx?rev=a435a05)" = "" "checksum gfx-memory 0.1.0 (git+https://github.com/gfx-rs/gfx-memory?rev=483d64d)" = "" "checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc" +"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" @@ -871,25 +1079,42 @@ dependencies = [ "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum relevant 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c2b087c662aa6d36c6bb22c44a97911196ffd4a1df324c1fabdbcb80d18b0302" +"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" +"checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" +"checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" +"checksum serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d30ec34ac923489285d24688c7a9c0898d16edff27fc1f1bd854edeff6ca3b7f" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" "checksum smithay-client-toolkit 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1609083d6bca3991a3c648d80ae16e1764d70881c3321bee1c915149073d605" "checksum spirv_cross 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1c2c0be48967fec392de4749ac34a2da758aaa359ca648abaa47b90b36845013" -"checksum spirv_cross 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e1b0b4e01f61e50a6e223fde32934883df4086004174a1fc522fc97bda2ce938" +"checksum spirv_cross 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cc3aef2f7822a4fdd4174f547700f208bbc0f0871c59b754573717c92fd29f4" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum storage-map 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cb94f167ccba0941876c8e722e888be8b4c05511ffdacc8cfcd4c647adfd424d" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)" = "58fd09df59565db3399efbba34ba8a2fec1307511ebd245d0061ff9d42691673" +"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" +"checksum tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "55c1195ef8513f3273d55ff59fe5da6940287a0d7a98331254397f464833675b" +"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" +"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wayland-client 0.20.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e7516a23419a55bd2e6d466c75a6a52c85718e5013660603289c2b8bee794b12" @@ -897,7 +1122,7 @@ dependencies = [ "checksum wayland-protocols 0.20.12 (registry+https://github.com/rust-lang/crates.io-index)" = "bd4d31a96be6ecdbaddbf35200f5af2daee01be592afecd8feaf443d417e9230" "checksum wayland-scanner 0.20.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e674d85ae9c67cbbc590374d8f2e20a7a02fff87ce3a31fc52213afece8d05ad" "checksum wayland-sys 0.20.12 (registry+https://github.com/rust-lang/crates.io-index)" = "87c82ee658aa657fdfd7061f22e442030d921cfefc5bad68bcf41973e67922f7" -"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winit 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba44cf306b981badc781894ab5d6fda54764a0512cbbf8db4685d329014143fa" diff --git a/Cargo.toml b/Cargo.toml index d34dc82b63..b54bc44fdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,6 @@ [workspace] members = [ "wgpu-native", + "wgpu-bindings", + "examples", ] diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 0000000000..e6b9f6d4d2 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "examples" +version = "0.1.0" +authors = [ + "Dzmitry Malyshau ", + "Joshua Groves ", +] +publish = false + +[[bin]] +name = "hello_triangle" +path = "hello_triangle_rust/main.rs" + +[features] +default = [] +remote = ["wgpu-native/remote"] +metal = ["wgpu-native/metal"] +dx12 = ["wgpu-native/dx12"] +vulkan = ["wgpu-native/vulkan"] + +[dependencies] +wgpu-native = { path = "../wgpu-native" } diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000000..c78b661b4b --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,14 @@ +all: hello_world_c + +CC=gcc +CFLAGS=-I. +DEPS=./../wgpu-bindings/wgpu.h +OUTDIR=./build +LINK_ARGS=-L ./../target/debug -lwgpu_native + +%.o: %.c $(DEPS) + $(CC) $(LINK_ARGS) -c -o $(OUTDIR)/$@ $< $(CFLAGS) + +hello_world_c: hello_triangle_c/main.c + mkdir -p $(OUTDIR) + $(CC) $(LINK_ARGS) -o $(OUTDIR)/$@ $^ $(CFLAGS) diff --git a/wgpu-native/examples/data/hello_triangle.frag b/examples/data/hello_triangle.frag similarity index 100% rename from wgpu-native/examples/data/hello_triangle.frag rename to examples/data/hello_triangle.frag diff --git a/wgpu-native/examples/data/hello_triangle.frag.spv b/examples/data/hello_triangle.frag.spv similarity index 100% rename from wgpu-native/examples/data/hello_triangle.frag.spv rename to examples/data/hello_triangle.frag.spv diff --git a/wgpu-native/examples/data/hello_triangle.vert b/examples/data/hello_triangle.vert similarity index 100% rename from wgpu-native/examples/data/hello_triangle.vert rename to examples/data/hello_triangle.vert diff --git a/wgpu-native/examples/data/hello_triangle.vert.spv b/examples/data/hello_triangle.vert.spv similarity index 100% rename from wgpu-native/examples/data/hello_triangle.vert.spv rename to examples/data/hello_triangle.vert.spv diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c new file mode 100644 index 0000000000..ef451a0b43 --- /dev/null +++ b/examples/hello_triangle_c/main.c @@ -0,0 +1,42 @@ +#include +#include "./../../wgpu-bindings/wgpu.h" + +WGPUByteArray read_file(const char *name) +{ + FILE *file = fopen(name, "rb"); + fseek(file, 0, SEEK_END); + long length = ftell(file); + unsigned char *bytes = malloc(length); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, length, file); + fclose(file); + WGPUByteArray ret = { + .bytes = bytes, + .length = length, + }; + return ret; +} + +int main() +{ + WGPUInstanceId instance = wgpu_create_instance(); + WGPUAdapterDescriptor adapter_desc = { + .power_preference = WGPUPowerPreference_LowPower, + }; + WGPUAdapterId adapter = wgpu_instance_get_adapter(instance, adapter_desc); + WGPUDeviceDescriptor device_desc = { + .extensions = { + .anisotropic_filtering = false, + }, + }; + WGPUDeviceId device = wgpu_adapter_create_device(adapter, device_desc); + WGPUShaderModuleDescriptor vs_desc = { + .code = read_file("./../data/hello_triangle.vert.spv"), + }; + WGPUShaderModuleId _vs = wgpu_device_create_shader_module(device, vs_desc); + WGPUShaderModuleDescriptor fs_desc = { + .code = read_file("./../data/hello_triangle.frag.spv"), + }; + WGPUShaderModuleId _fs = wgpu_device_create_shader_module(device, fs_desc); + return 0; +} diff --git a/examples/hello_triangle_rust/main.rs b/examples/hello_triangle_rust/main.rs new file mode 100644 index 0000000000..313e680294 --- /dev/null +++ b/examples/hello_triangle_rust/main.rs @@ -0,0 +1,40 @@ +extern crate wgpu_native; +use wgpu_native::*; + +fn main() { + let instance = wgpu_create_instance(); + let adapter = wgpu_instance_get_adapter( + instance, + AdapterDescriptor { + power_preference: PowerPreference::LowPower, + }, + ); + let device = wgpu_adapter_create_device( + adapter, + DeviceDescriptor { + extensions: Extensions { + anisotropic_filtering: false, + }, + }, + ); + let vs_bytes = include_bytes!("./../data/hello_triangle.vert.spv"); + let _vs = wgpu_device_create_shader_module( + device, + ShaderModuleDescriptor { + code: ByteArray { + bytes: vs_bytes.as_ptr(), + length: vs_bytes.len(), + }, + }, + ); + let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv"); + let _fs = wgpu_device_create_shader_module( + device, + ShaderModuleDescriptor { + code: ByteArray { + bytes: fs_bytes.as_ptr(), + length: fs_bytes.len(), + }, + }, + ); +} diff --git a/wgpu-bindings/Cargo.toml b/wgpu-bindings/Cargo.toml new file mode 100644 index 0000000000..7ab66cfdb2 --- /dev/null +++ b/wgpu-bindings/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "wgpu-bindings" +version = "0.1.0" +authors = [ + "Dzmitry Malyshau ", + "Joshua Groves ", +] + +[features] +default = [] + +[dependencies] +cbindgen = "0.6.3" diff --git a/wgpu-bindings/src/main.rs b/wgpu-bindings/src/main.rs new file mode 100644 index 0000000000..42a5d402f2 --- /dev/null +++ b/wgpu-bindings/src/main.rs @@ -0,0 +1,41 @@ +extern crate cbindgen; + +use std::path::PathBuf; + +const HEADER: &str = " +#ifdef WGPU_REMOTE + typedef uint32_t WGPUId; +#else + typedef void *WGPUId; +#endif +"; + +fn main() { + let mut crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + crate_dir.push("../wgpu-native"); + + let config = cbindgen::Config { + header: Some(String::from(HEADER.trim())), + enumeration: cbindgen::EnumConfig { + prefix_with_name: true, + ..Default::default() + }, + export: cbindgen::ExportConfig { + prefix: Some(String::from("WGPU")), + exclude: vec![ + // We manually define `Id` is within the header, so exclude it here + String::from("Id"), + ], + ..Default::default() + }, + language: cbindgen::Language::C, + ..Default::default() + }; + + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_config(config) + .generate() + .unwrap() + .write_to_file("wgpu.h"); +} diff --git a/wgpu-bindings/wgpu.h b/wgpu-bindings/wgpu.h new file mode 100644 index 0000000000..4c776af9e8 --- /dev/null +++ b/wgpu-bindings/wgpu.h @@ -0,0 +1,63 @@ +#ifdef WGPU_REMOTE + typedef uint32_t WGPUId; +#else + typedef void *WGPUId; +#endif + +#include +#include +#include + +typedef enum { + WGPUPowerPreference_Default = 0, + WGPUPowerPreference_LowPower = 1, + WGPUPowerPreference_HighPerformance = 2, +} WGPUPowerPreference; + +typedef WGPUId WGPUDeviceId; + +typedef WGPUId WGPUAdapterId; + +typedef struct { + bool anisotropic_filtering; +} WGPUExtensions; + +typedef struct { + WGPUExtensions extensions; +} WGPUDeviceDescriptor; + +typedef WGPUId WGPUComputePassId; + +typedef WGPUId WGPURenderPassId; + +typedef WGPUId WGPUCommandBufferId; + +typedef WGPUId WGPUInstanceId; + +typedef WGPUId WGPUShaderModuleId; + +typedef struct { + const uint8_t *bytes; + uintptr_t length; +} WGPUByteArray; + +typedef struct { + WGPUByteArray code; +} WGPUShaderModuleDescriptor; + +typedef struct { + WGPUPowerPreference power_preference; +} WGPUAdapterDescriptor; + +WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, WGPUDeviceDescriptor desc); + +WGPUComputePassId wgpu_command_buffer_begin_compute_pass(void); + +WGPURenderPassId wgpu_command_buffer_begin_render_pass(WGPUCommandBufferId command_buffer); + +WGPUInstanceId wgpu_create_instance(void); + +WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id, + WGPUShaderModuleDescriptor desc); + +WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, WGPUAdapterDescriptor desc); diff --git a/wgpu-native/Cargo.toml b/wgpu-native/Cargo.toml index 3f6d853c44..1ddbec9108 100644 --- a/wgpu-native/Cargo.toml +++ b/wgpu-native/Cargo.toml @@ -6,11 +6,20 @@ authors = [ "Joshua Groves ", ] +[lib] +crate-type = ["lib", "cdylib", "staticlib"] + [features] default = [] +remote = ["parking_lot"] +metal = ["gfx-backend-metal"] +dx12 = ["gfx-backend-dx12"] +vulkan = ["gfx-backend-vulkan"] [dependencies] bitflags = "1.0" +lazy_static = "1.1.0" +parking_lot = { version = "0.6", optional = true } gfx-hal = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05" } # required by gfx-memory gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05" } gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "a435a05", optional = true } diff --git a/wgpu-native/examples/hello_triangle.rs b/wgpu-native/examples/hello_triangle.rs deleted file mode 100644 index 7eaa1bf350..0000000000 --- a/wgpu-native/examples/hello_triangle.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate wgpu_native as wgn; - -fn main() { - let instance = wgn::create_instance(); - let adapter = wgn::instance_get_adapter(instance, wgn::AdapterDescriptor { - power_preference: wgn::PowerPreference::LowPower, - }); - let device = wgn::adapter_create_device(adapter, wgn::DeviceDescriptor { - extensions: wgn::Extensions { - anisotropic_filtering: false, - }, - }); - let _vs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor { - code: include_bytes!("./data/hello_triangle.vert.spv"), - }); - let _fs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor { - code: include_bytes!("./data/hello_triangle.frag.spv"), - }); -} diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index 577dcf43a3..ca8df90529 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -1,6 +1,6 @@ use hal; -use {BindGroupLayoutHandle, BufferHandle, SamplerHandle, TextureViewHandle}; +use {BindGroupLayoutId, BufferId, SamplerId, TextureViewId}; bitflags! { #[repr(transparent)] @@ -13,7 +13,7 @@ bitflags! { } #[repr(C)] -pub enum BindingType { +pub enum BindingType { UniformBuffer = 0, Sampler = 1, SampledTexture = 2, @@ -38,7 +38,7 @@ pub struct BindGroupLayout { #[repr(C)] pub struct PipelineLayoutDescriptor<'a> { - pub bind_group_layouts: &'a [BindGroupLayoutHandle], + pub bind_group_layouts: &'a [BindGroupLayoutId], } pub struct PipelineLayout { @@ -47,7 +47,7 @@ pub struct PipelineLayout { #[repr(C)] pub struct BufferBinding { - pub buffer: BufferHandle, + pub buffer: BufferId, pub offset: u32, pub size: u32, } @@ -55,8 +55,8 @@ pub struct BufferBinding { #[repr(C)] pub enum BindingResource { Buffer(BufferBinding), - Sampler(SamplerHandle), - TextureView(TextureViewHandle), + Sampler(SamplerId), + TextureView(TextureViewId), } #[repr(C)] diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index df2f0c01a8..daff85ff3e 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -1,25 +1,7 @@ use hal; -use {CommandBuffer, CommandBufferHandle, ComputePassHandle}; - +use {CommandBuffer, CommandBufferId, ComputePassId}; pub struct ComputePass { raw: B::CommandBuffer, } - -pub extern "C" -fn compute_pass_dispatch( - pass: ComputePassHandle, groups_x: u32, groups_y: u32, groups_z: u32 -) { - unimplemented!() -} - -pub extern "C" -fn compute_pass_end(pass: ComputePassHandle) -> CommandBufferHandle { - match pass.unbox() { - Some(pass) => CommandBufferHandle::new(CommandBuffer { - raw: pass.raw, - }), - None => CommandBufferHandle::null(), - } -} diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index ea31b64a6e..e70a017c1a 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -6,9 +6,10 @@ pub use self::render::*; use hal; -use {BufferHandle, Color, CommandBufferHandle, ComputePassHandle, Origin3d, - RenderPassHandle, TextureViewHandle, TextureHandle}; - +use { + BufferId, Color, CommandBufferId, ComputePassId, Origin3d, RenderPassId, TextureId, + TextureViewId, +}; #[repr(C)] pub enum LoadOp { @@ -23,7 +24,7 @@ pub enum StoreOp { #[repr(C)] pub struct RenderPassColorAttachmentDescriptor { - pub attachment: TextureViewHandle, + pub attachment: TextureViewId, pub load_op: LoadOp, pub store_op: StoreOp, pub clear_color: Color, @@ -31,7 +32,7 @@ pub struct RenderPassColorAttachmentDescriptor { #[repr(C)] pub struct RenderPassDepthStencilAttachmentDescriptor { - pub attachment: TextureViewHandle, + pub attachment: TextureViewId, pub depth_load_op: LoadOp, pub depth_store_op: StoreOp, pub clear_depth: f32, @@ -48,7 +49,7 @@ pub struct RenderPassDescriptor<'a> { #[repr(C)] pub struct BufferCopyView { - pub buffer: BufferHandle, + pub buffer: BufferId, pub offset: u32, pub row_pitch: u32, pub image_height: u32, @@ -56,7 +57,7 @@ pub struct BufferCopyView { #[repr(C)] pub struct TextureCopyView { - pub texture: TextureHandle, + pub texture: TextureId, pub level: u32, pub slice: u32, pub origin: Origin3d, @@ -70,15 +71,14 @@ pub struct CommandBuffer { #[repr(C)] pub struct CommandBufferDescriptor; -pub extern "C" -fn command_buffer_begin_render_pass( - command_buffer: CommandBufferHandle -) -> RenderPassHandle { +#[no_mangle] +pub extern "C" fn wgpu_command_buffer_begin_render_pass( + command_buffer: CommandBufferId, +) -> RenderPassId { unimplemented!() } -pub extern "C" -fn command_buffer_begin_compute_pass( -) -> ComputePassHandle { +#[no_mangle] +pub extern "C" fn wgpu_command_buffer_begin_compute_pass() -> ComputePassId { unimplemented!() } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index a6c1e19a5b..f77d1edcd4 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -1,32 +1,7 @@ use hal; -use {CommandBuffer, CommandBufferHandle, RenderPassHandle}; - +use {CommandBuffer, CommandBufferId, RenderPassId}; pub struct RenderPass { raw: B::CommandBuffer, } - -pub extern "C" -fn render_pass_draw( - pass: RenderPassHandle, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32 -) { - unimplemented!() -} - -pub extern "C" -fn render_pass_draw_indexed( - pass: RenderPassHandle, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32 -) { - unimplemented!() -} - -pub extern "C" -fn render_pass_end(pass: RenderPassHandle) -> CommandBufferHandle { - match pass.unbox() { - Some(pass) => CommandBufferHandle::new(CommandBuffer { - raw: pass.raw, - }), - None => CommandBufferHandle::null(), - } -} diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index 39d55b2ca8..238d6a8f06 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -2,11 +2,12 @@ use hal; use resource; - -pub(crate) fn map_buffer_usage(usage: resource::BufferUsageFlags) -> (hal::buffer::Usage, hal::memory::Properties) { - use resource::BufferUsageFlags as W; +pub(crate) fn map_buffer_usage( + usage: resource::BufferUsageFlags, +) -> (hal::buffer::Usage, hal::memory::Properties) { use hal::buffer::Usage as U; use hal::memory::Properties as P; + use resource::BufferUsageFlags as W; let mut hal_memory = P::empty(); if usage.contains(W::MAP_READ) { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index bb4c310af4..15bc100854 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -1,12 +1,11 @@ use hal::{self, Device as _Device, QueueGroup}; use {conv, memory, pipeline, resource}; -use {BufferHandle, CommandBufferHandle, DeviceHandle, ShaderModuleHandle}; - +use registry::{self, Registry}; +use {BufferId, CommandBufferId, DeviceId, ShaderModuleId}; #[repr(C)] -pub struct CommandBufferDescriptor { -} +pub struct CommandBufferDescriptor {} pub struct Device { device: B::Device, @@ -28,35 +27,20 @@ impl Device { } } -pub extern "C" -fn device_create_buffer( - device: DeviceHandle, desc: resource::BufferDescriptor -) -> BufferHandle { - let (usage, memory_properties) = conv::map_buffer_usage(desc.usage); - let buffer = device.device.create_buffer(desc.size as u64, usage).unwrap(); - BufferHandle::new(resource::Buffer { - raw: buffer, - memory_properties, - }) -} - pub struct ShaderModule { pub raw: B::ShaderModule, } -pub extern "C" -fn device_create_shader_module( - device: DeviceHandle, desc: pipeline::ShaderModuleDescriptor -) -> ShaderModuleHandle { - let shader = device.device.create_shader_module(desc.code).unwrap(); - ShaderModuleHandle::new(ShaderModule { - raw: shader, - }) -} - -pub extern "C" -fn device_create_command_buffer( - device: DeviceHandle, desc: CommandBufferDescriptor -) -> CommandBufferHandle { - unimplemented!() +#[no_mangle] +pub extern "C" fn wgpu_device_create_shader_module( + device_id: DeviceId, + desc: pipeline::ShaderModuleDescriptor, +) -> ShaderModuleId { + let device = registry::DEVICE_REGISTRY.get_mut(device_id); + let shader = device + .device + .create_shader_module(unsafe { + ::std::slice::from_raw_parts(desc.code.bytes, desc.code.length) + }).unwrap(); + registry::SHADER_MODULE_REGISTRY.register(ShaderModule { raw: shader }) } diff --git a/wgpu-native/src/handle.rs b/wgpu-native/src/handle.rs deleted file mode 100644 index 6716ff5a78..0000000000 --- a/wgpu-native/src/handle.rs +++ /dev/null @@ -1,113 +0,0 @@ -use std::{borrow, cmp, fmt, ops, ptr}; -#[cfg(feature = "nightly")] -use std::sync::{Arc, Mutex}; - -#[cfg(feature = "nightly")] -use hal::backend::FastHashMap; - -#[cfg(feature = "nightly")] -lazy_static! { - static ref REGISTRY: Arc>> = Arc::new(Mutex::new(FastHashMap::default())); -} - -#[repr(C)] -pub struct Handle(*mut T); - -#[cfg(feature = "nightly")] -impl Handle<()> { - pub fn report_leaks() { - println!("Leaked handles:"); - let mut map = REGISTRY.lock().unwrap(); - for (_, type_id) in map.drain() { - println!("\t{:?}", type_id); - } - } -} - -impl Handle { - pub fn new(value: T) -> Self { - let ptr = Box::into_raw(Box::new(value)); - #[cfg(feature = "nightly")] - { - use std::intrinsics::type_name; - let name = unsafe { type_name::() }; - REGISTRY.lock().unwrap().insert(ptr as _, name); - } - Handle(ptr) - } - - pub fn null() -> Self { - Handle(ptr::null_mut()) - } - - pub fn unbox(self) -> Option { - if self.0.is_null() { - None - } else { - #[cfg(feature = "nightly")] - { - REGISTRY.lock().unwrap().remove(&(self.0 as _)).unwrap(); - } - Some(*unsafe { Box::from_raw(self.0) }) - } - } - - pub fn as_ref(&self) -> Option<&T> { - unsafe { self.0.as_ref() } - } -} - -impl Handle { - #[cfg(feature = "nightly")] - #[inline] - fn check(&self) { - assert!(REGISTRY.lock().unwrap().contains_key(&(self.0 as _))); - } - #[cfg(not(feature = "nightly"))] - #[inline] - fn check(&self) { - debug_assert!(!self.0.is_null()); - } -} - -impl Clone for Handle { - fn clone(&self) -> Self { - Handle(self.0) - } -} - -impl Copy for Handle {} - -impl ops::Deref for Handle { - type Target = T; - fn deref(&self) -> &T { - self.check(); - unsafe { &*self.0 } - } -} - -impl ops::DerefMut for Handle { - fn deref_mut(&mut self) -> &mut T { - self.check(); - unsafe { &mut *self.0 } - } -} - -impl borrow::Borrow for Handle { - fn borrow(&self) -> &T { - self.check(); - unsafe { &*self.0 } - } -} - -impl cmp::PartialEq for Handle { - fn eq(&self, other: &Self) -> bool { - self.0.eq(&other.0) - } -} - -impl fmt::Debug for Handle { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "Handle({:p})", self.0) - } -} diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index de11a2baba..a6a43f288f 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -1,7 +1,7 @@ use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice}; -use {AdapterHandle, Device, DeviceHandle, InstanceHandle}; - +use registry::{self, Registry}; +use {AdapterId, Device, DeviceId, InstanceId}; #[repr(C)] pub enum PowerPreference { @@ -25,23 +25,33 @@ pub struct DeviceDescriptor { pub extensions: Extensions, } -pub extern "C" -fn create_instance() -> InstanceHandle { - #[cfg(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal"))] +#[no_mangle] +pub extern "C" fn wgpu_create_instance() -> InstanceId { + #[cfg(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" + ))] { let inst = ::back::Instance::create("wgpu", 1); - InstanceHandle::new(inst) + registry::INSTANCE_REGISTRY.register(inst) } - #[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))] + #[cfg(not(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" + )))] { unimplemented!() } } -pub extern "C" -fn instance_get_adapter( - instance: InstanceHandle, desc: AdapterDescriptor -) -> AdapterHandle { +#[no_mangle] +pub extern "C" fn wgpu_instance_get_adapter( + instance_id: InstanceId, + desc: AdapterDescriptor, +) -> AdapterId { + let instance = registry::INSTANCE_REGISTRY.get_mut(instance_id); let (mut low, mut high, mut other) = (None, None, None); for adapter in instance.enumerate_adapters() { match adapter.info.device_type { @@ -53,17 +63,18 @@ fn instance_get_adapter( let some = match desc.power_preference { PowerPreference::LowPower => low.or(high), - PowerPreference::HighPerformance | - PowerPreference::Default => high.or(low), + PowerPreference::HighPerformance | PowerPreference::Default => high.or(low), }; - AdapterHandle::new(some.or(other).unwrap()) + registry::ADAPTER_REGISTRY.register(some.or(other).unwrap()) } -pub extern "C" -fn adapter_create_device( - mut adapter: AdapterHandle, desc: DeviceDescriptor -) -> DeviceHandle { +#[no_mangle] +pub extern "C" fn wgpu_adapter_create_device( + adapter_id: AdapterId, + desc: DeviceDescriptor, +) -> DeviceId { + let mut adapter = registry::ADAPTER_REGISTRY.get_mut(adapter_id); let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap(); let mem_props = adapter.physical_device.memory_properties(); - DeviceHandle::new(Device::new(device, queue_group, mem_props)) + registry::DEVICE_REGISTRY.register(Device::new(device, queue_group, mem_props)) } diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index 55a7b63532..db405f85a2 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -1,24 +1,33 @@ -#[macro_use] extern crate bitflags; +#[macro_use] +extern crate bitflags; +#[macro_use] +extern crate lazy_static; +#[cfg(feature = "remote")] +extern crate parking_lot; -#[cfg(feature = "gfx-backend-vulkan")] -extern crate gfx_backend_vulkan as back; #[cfg(feature = "gfx-backend-dx12")] extern crate gfx_backend_dx12 as back; +#[cfg(not(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" +)))] +extern crate gfx_backend_empty as back; #[cfg(feature = "gfx-backend-metal")] extern crate gfx_backend_metal as back; -#[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))] -extern crate gfx_backend_empty as back; +#[cfg(feature = "gfx-backend-vulkan")] +extern crate gfx_backend_vulkan as back; extern crate gfx_hal as hal; extern crate gfx_memory as memory; mod binding_model; -mod conv; mod command; +mod conv; mod device; -mod handle; mod instance; mod pipeline; +mod registry; mod resource; pub use self::binding_model::*; @@ -29,7 +38,7 @@ pub use self::pipeline::*; pub use self::resource::*; use back::Backend as B; -use handle::Handle; +use registry::Id; #[repr(C)] pub struct Color { @@ -53,29 +62,39 @@ pub struct Extent3d { pub depth: f32, } -pub type InstanceHandle = Handle; -pub type AdapterHandle = Handle>; -pub type DeviceHandle = Handle>; -pub type BufferHandle = Handle>; +#[repr(C)] +pub struct ByteArray { + pub bytes: *const u8, + pub length: usize, +} + +pub type InstanceId = Id; +pub(crate) type InstanceHandle = back::Instance; +pub type AdapterId = Id; +pub(crate) type AdapterHandle = hal::Adapter; +pub type DeviceId = Id; +pub(crate) type DeviceHandle = Device; +pub type BufferId = Id; // Resource -pub type TextureViewHandle = Handle; -pub type TextureHandle = Handle; -pub type SamplerHandle = Handle; +pub type TextureViewId = Id; +pub type TextureId = Id; +pub type SamplerId = Id; // Binding model -pub type BindGroupLayoutHandle = Handle; -pub type PipelineLayoutHandle = Handle>; +pub type BindGroupLayoutId = Id; +pub type PipelineLayoutId = Id; // Pipeline -pub type BlendStateHandle = Handle; -pub type DepthStencilStateHandle = Handle; -pub type InputStateHandle = Handle; -pub type ShaderModuleHandle = Handle>; -pub type AttachmentStateHandle = Handle; -pub type ComputePipelineHandle = Handle; -pub type RenderPipelineHandle = Handle; +pub type BlendStateId = Id; +pub type DepthStencilStateId = Id; +pub type InputStateId = Id; +pub type ShaderModuleId = Id; +pub(crate) type ShaderModuleHandle = ShaderModule; +pub type AttachmentStateId = Id; +pub type ComputePipelineId = Id; +pub type RenderPipelineId = Id; -pub type CommandBufferHandle = Handle>; -pub type RenderPassHandle = Handle>; -pub type ComputePassHandle = Handle>; +pub type CommandBufferId = Id; +pub type RenderPassId = Id; +pub type ComputePassId = Id; diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index 976c93f227..0d94aa2ace 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -1,8 +1,7 @@ use hal; use resource; -use {BlendStateHandle, DepthStencilStateHandle, PipelineLayoutHandle}; - +use {BlendStateId, ByteArray, DepthStencilStateId, PipelineLayoutId}; #[repr(C)] pub enum BlendFactor { @@ -142,8 +141,8 @@ pub struct InputState { } #[repr(C)] -pub struct ShaderModuleDescriptor<'a> { - pub code: &'a [u8], +pub struct ShaderModuleDescriptor { + pub code: ByteArray, } #[repr(C)] @@ -163,16 +162,16 @@ pub enum ShaderStage { } #[repr(C)] -pub struct PipelineStageDescriptor<'a> { - pub module: ShaderModuleDescriptor<'a>, +pub struct PipelineStageDescriptor { + pub module: ShaderModuleDescriptor, pub stage: ShaderStage, pub entry_point: *const ::std::os::raw::c_char, } #[repr(C)] pub struct ComputePipelineDescriptor<'a> { - pub layout: PipelineLayoutHandle, - pub stages: &'a [PipelineStageDescriptor<'a>], + pub layout: PipelineLayoutId, + pub stages: &'a [PipelineStageDescriptor], } pub struct ComputePipeline { @@ -190,11 +189,11 @@ pub enum PrimitiveTopology { #[repr(C)] pub struct RenderPipelineDescriptor<'a> { - pub layout: PipelineLayoutHandle, - pub stages: &'a [PipelineStageDescriptor<'a>], + pub layout: PipelineLayoutId, + pub stages: &'a [PipelineStageDescriptor], pub primitive_topology: PrimitiveTopology, - pub blend_state: &'a [BlendStateHandle], - pub depth_stencil_state: DepthStencilStateHandle, + pub blend_state: &'a [BlendStateId], + pub depth_stencil_state: DepthStencilStateId, pub attachment_state: AttachmentState, } diff --git a/wgpu-native/src/registry.rs b/wgpu-native/src/registry.rs new file mode 100644 index 0000000000..08a072ec98 --- /dev/null +++ b/wgpu-native/src/registry.rs @@ -0,0 +1,102 @@ +use std::marker::PhantomData; +use std::os::raw::c_void; +#[cfg(feature = "remote")] +use std::sync::Arc; +#[cfg(feature = "remote")] +use parking_lot::{Mutex, MutexGuard, MappedMutexGuard}; +use std::{borrow, cmp, fmt, ops, ptr}; + +use hal::backend::FastHashMap; +use {AdapterHandle, DeviceHandle, InstanceHandle, ShaderModuleHandle}; + +#[cfg(not(feature = "remote"))] +pub(crate) type Id = *mut c_void; +#[cfg(feature = "remote")] +pub(crate) type Id = u32; + +#[cfg(not(feature = "remote"))] +type RegistryItem<'a, T> = &'a mut T; +#[cfg(feature = "remote")] +type RegistryItem<'a, T> = MappedMutexGuard<'a, T>; + +pub(crate) trait Registry { + fn new() -> Self; + fn register(&self, handle: T) -> Id; + fn get_mut(&self, id: Id) -> RegistryItem; +} + +#[cfg(not(feature = "remote"))] +pub(crate) struct LocalRegistry { + marker: PhantomData, +} + +#[cfg(not(feature = "remote"))] +impl Registry for LocalRegistry { + fn new() -> Self { + LocalRegistry { + marker: PhantomData, + } + } + + fn register(&self, handle: T) -> Id { + ::std::boxed::Box::into_raw(Box::new(handle)) as *mut _ as *mut c_void + } + + fn get_mut(&self, id: Id) -> RegistryItem { + unsafe { (id as *mut T).as_mut() }.unwrap() + } +} + +#[cfg(feature = "remote")] +struct Registrations { + next_id: Id, + tracked: FastHashMap, +} + +#[cfg(feature = "remote")] +impl Registrations { + fn new() -> Self { + Registrations { + next_id: 0, + tracked: FastHashMap::default(), + } + } +} + +#[cfg(feature = "remote")] +pub(crate) struct RemoteRegistry { + registrations: Arc>>, +} + +#[cfg(feature = "remote")] +impl Registry for RemoteRegistry { + fn new() -> Self { + RemoteRegistry { + registrations: Arc::new(Mutex::new(Registrations::new())), + } + } + + fn register(&self, handle: T) -> Id { + let mut registrations = self.registrations.lock(); + let id = registrations.next_id; + registrations.tracked.insert(id, handle); + registrations.next_id += 1; + id + } + + fn get_mut(&self, id: Id) -> RegistryItem { + MutexGuard::map(self.registrations.lock(), |r| r.tracked.get_mut(&id).unwrap()) + } +} + +#[cfg(not(feature = "remote"))] +type ConcreteRegistry = LocalRegistry; +#[cfg(feature = "remote")] +type ConcreteRegistry = RemoteRegistry; + +lazy_static! { + pub(crate) static ref ADAPTER_REGISTRY: ConcreteRegistry = ConcreteRegistry::new(); + pub(crate) static ref DEVICE_REGISTRY: ConcreteRegistry = ConcreteRegistry::new(); + pub(crate) static ref INSTANCE_REGISTRY: ConcreteRegistry = ConcreteRegistry::new(); + pub(crate) static ref SHADER_MODULE_REGISTRY: ConcreteRegistry = ConcreteRegistry::new(); +} diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index defc23431b..6913af1009 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -1,7 +1,6 @@ use hal; -use {Extent3d}; - +use Extent3d; bitflags! { #[repr(transparent)]