144: Rewrite bindings generation r=grovesNL a=kvark

This PR is shaping wgpu-remote to become distantly usable, introduces an example that tests it on CI.

It also rewrites our binding generation to use `cbindgen.toml` configuration, which goes in line with Gecko use case (even though they are going to have a separate configuration).

The `ClientFactory` is introduced so that we can have multiple clients (say, one page per client) talking to the same server on a dedicated thread within the GPU process.

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot]
2019-05-01 02:14:57 +00:00
31 changed files with 458 additions and 329 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@
.vscode
.vs
build
ffi/dawn*.h

View File

@@ -43,4 +43,4 @@ before_install:
script:
- cargo test
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (brew update && brew upgrade cmake && brew install glfw3 && cd wgpu-native && cargo build --features=local,gfx-backend-metal && cd ../examples/hello_triangle_c && mkdir build && cd build && cmake .. && make); fi
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (brew update && brew upgrade cmake && brew install glfw3 && make ffi-examples); fi

100
Cargo.lock generated
View File

@@ -26,14 +26,6 @@ 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 = "approx"
version = "0.3.1"
@@ -141,21 +133,6 @@ name = "byteorder"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cbindgen"
version = "0.7.1"
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.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cc"
version = "1.0.30"
@@ -176,20 +153,6 @@ dependencies = [
"rand 0.6.5 (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"
@@ -560,11 +523,6 @@ dependencies = [
"uuid 0.7.2 (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 = "kernel32-sys"
version = "0.2.2"
@@ -1054,11 +1012,6 @@ dependencies = [
"stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ryu"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "same-file"
version = "1.0.4"
@@ -1103,16 +1056,6 @@ dependencies = [
"syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.39"
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.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha2"
version = "0.7.1"
@@ -1189,11 +1132,6 @@ dependencies = [
"lock_api 0.1.5 (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.13.11"
@@ -1256,14 +1194,6 @@ dependencies = [
"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 = "thread_local"
version = "0.3.6"
@@ -1272,14 +1202,6 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typenum"
version = "1.10.0"
@@ -1290,11 +1212,6 @@ name = "ucd-util"
version = "0.1.3"
source = "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.1.0"
@@ -1395,13 +1312,6 @@ dependencies = [
"wgpu-native 0.2.6",
]
[[package]]
name = "wgpu-bindings"
version = "0.1.0"
dependencies = [
"cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wgpu-native"
version = "0.2.6"
@@ -1561,7 +1471,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
"checksum andrew 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "142e9e6a99ad0d63a4cf6ce58a4c979f472c5815cbf7e5ca4e47b26a10dc728e"
"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 approx 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3c57ff1a5b00753647aebbbcf4ea67fa1e711a65ea7a30eb90dbf07de2485aee"
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
@@ -1576,11 +1485,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
"checksum cbindgen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "32e01024aaf5390d6a8145047371a4f5b0063a14c1e411bc731353bd2278ca44"
"checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum cgmath 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283944cdecc44bf0b8dd010ec9af888d3b4f142844fdbe026c20ef68148d6fe7"
"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 cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a"
"checksum cocoa 0.18.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cf79daa4e11e5def06e55306aa3601b87de6b5149671529318da048f67cdd77b"
@@ -1618,7 +1525,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f82db24b0c53ee2d54b420bb9258f2b787611fe3e7a28d514b5ea54fe65cd365"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
@@ -1676,14 +1582,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusttype 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ce3926a2057b315b3e8bca6d1cec1e97f19436a8f9127621cd538cda9c96a38b"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"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.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560"
"checksum serde_derive 1.0.58 (registry+https://github.com/rust-lang/crates.io-index)" = "ac38f51a52a556cd17545798e29536885fb1a3fa63d6399f5ef650f4a7d35901"
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0"
"checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
@@ -1693,19 +1597,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum stb_truetype 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "69b7df505db8e81d54ff8be4693421e5b543e08214bd8d99eb761fcb4d5668ba"
"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.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b"
"checksum syn 0.15.27 (registry+https://github.com/rust-lang/crates.io-index)" = "525bd55255f03c816e5d7f615587bd13030c7103354fadb104993dcee6a788ec"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
"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 thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
"checksum uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0238db0c5b605dd1cf51de0f21766f97fba2645897024461d6a00c036819a768"

View File

@@ -1,7 +1,6 @@
[workspace]
members = [
"wgpu-native",
"wgpu-bindings",
"wgpu-remote",
"wgpu-rs",
"examples",

View File

@@ -30,9 +30,9 @@ else
endif
.PHONY: all check test doc clear lib-native lib-rust examples-native examples-rust gfx
.PHONY: all check test doc clear lib-native lib-remote lib-rust examples-rust examples-gfx gfx ffi-examples
all: examples-native examples-rust examples-gfx
all: examples-rust examples-gfx ffi-examples
check:
cargo check --all
@@ -50,19 +50,29 @@ clear:
lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs)
cargo build --manifest-path wgpu-native/Cargo.toml --features "local,$(FEATURE_NATIVE)"
lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs)
cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST)
lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST)
wgpu-bindings/*.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
ffi/wgpu.h: wgpu-native/cbindgen.toml $(wildcard wgpu-native/**/*.rs)
cbindgen wgpu-native >ffi/wgpu.h
ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs)
cbindgen wgpu-remote >ffi/wgpu-remote.h
wgpu-bindings/*.h: Cargo.lock $(wildcard wgpu-bindings/src/*.rs) lib-native lib-remote
cargo +nightly run --manifest-path wgpu-bindings/Cargo.toml
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)
#$(MAKE) -C examples
ffi-examples: lib-native lib-remote ffi/wgpu.h ffi/wgpu-remote.h
cd examples/hello_triangle_c && mkdir -p build && cd build && cmake .. && make
cd examples/hello_remote_c && mkdir -p build && cd build && cmake .. && make
examples-rust: lib-rust examples/Cargo.toml $(wildcard wgpu-native/**/*.rs)
examples-rust: examples/Cargo.toml $(wildcard wgpu-native/**/*.rs wgpu-rs/**/*.rs)
cargo build --manifest-path examples/Cargo.toml --features $(FEATURE_RUST)
examples-gfx: lib-rust gfx-examples/Cargo.toml $(wildcard gfx-examples/*.rs)
examples-gfx: examples-rust gfx-examples/Cargo.toml $(wildcard gfx-examples/*.rs)
cargo build --manifest-path gfx-examples/Cargo.toml --features $(FEATURE_RUST)
gfx:

View File

@@ -7,7 +7,6 @@ This is an experimental [WebGPU](https://www.w3.org/community/gpu/) implementati
The implementation consists of the following parts:
- `wgpu-native` - the native implementation of WebGPU as a C API library
- `wgpu-bindings` - automatic generator of actual C headers
- `wgpu-remote` - remoting layer to work with WebGPU across the process boundary
- `wgpu-rs` - idiomatic Rust wrapper of the native library

View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.11b)
project(hello_remote)
set(TARGET_NAME hello_remote)
add_executable(hello_remote main.c)
find_package(glfw3)
find_library(WGPU_LIBRARY wgpu_remote
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug"
)
target_link_libraries(${TARGET_NAME} ${WGPU_LIBRARY})

View File

@@ -0,0 +1,20 @@
#include "./../../ffi/wgpu-remote.h"
#include <stdio.h>
int main() {
WGPUInfrastructure infra = wgpu_initialize();
if (!infra.factory || !infra.server || infra.error) {
printf("Cannot initialize WGPU: %s", infra.error);
return 1;
}
WGPUClient* client = wgpu_client_create(infra.factory);
//TODO: do something meaningful
wgpu_client_destroy(infra.factory, client);
wgpu_terminate(infra.factory);
return 0;
}

View File

@@ -1,4 +1,4 @@
#include "./../../wgpu-bindings/wgpu.h"
#include "./../../ffi/wgpu.h"
#include <stdio.h>
#define WGPU_TARGET_MACOS 1
@@ -156,7 +156,7 @@ int main() {
return 1;
}
WGPUSurfaceId surface = {};
WGPUSurfaceId surface;
#if WGPU_TARGET == WGPU_TARGET_MACOS
{
@@ -183,6 +183,8 @@ int main() {
surface = wgpu_instance_create_surface_from_windows_hwnd(
instance, hinstance, hwnd);
}
#else
#error "Unsupported WGPU_TARGET"
#endif
WGPUSwapChainId swap_chain = wgpu_device_create_swap_chain(device, surface,
@@ -219,7 +221,7 @@ int main() {
});
wgpu_render_pass_set_pipeline(rpass, render_pipeline);
wgpu_render_pass_set_bind_group(rpass, 0, bind_group);
wgpu_render_pass_set_bind_group(rpass, 0, bind_group, NULL, 0);
wgpu_render_pass_draw(rpass, 3, 1, 0, 0);
WGPUQueueId queue = wgpu_device_get_queue(device);
WGPUCommandBufferId cmd_buf = wgpu_render_pass_end_pass(rpass);

73
ffi/wgpu-remote.h Normal file
View File

@@ -0,0 +1,73 @@
/* Generated with cbindgen:0.8.3 */
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef enum {
WGPUPowerPreference_Default = 0,
WGPUPowerPreference_LowPower = 1,
WGPUPowerPreference_HighPerformance = 2,
} WGPUPowerPreference;
typedef struct WGPUClient WGPUClient;
typedef struct WGPUClientFactory WGPUClientFactory;
typedef struct WGPUServer WGPUServer;
typedef struct WGPUTrackPermit WGPUTrackPermit;
typedef uint32_t WGPUIndex;
typedef uint32_t WGPUEpoch;
typedef struct {
WGPUIndex _0;
WGPUEpoch _1;
} WGPUId;
typedef WGPUId WGPUDeviceId;
typedef WGPUId WGPUAdapterId;
typedef struct {
bool anisotropic_filtering;
} WGPUExtensions;
typedef struct {
WGPUExtensions extensions;
} WGPUDeviceDescriptor;
typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
typedef struct {
WGPUClientFactory *factory;
WGPUServer *server;
const uint8_t *error;
} WGPUInfrastructure;
WGPUDeviceId wgpu_client_adapter_create_device(const WGPUClient *client,
WGPUAdapterId adapter_id,
const WGPUDeviceDescriptor *desc);
WGPUClient *wgpu_client_create(const WGPUClientFactory *factory);
void wgpu_client_destroy(const WGPUClientFactory *factory, WGPUClient *client);
WGPUAdapterId wgpu_client_get_adapter(const WGPUClient *client, const WGPUAdapterDescriptor *desc);
WGPUInfrastructure wgpu_initialize(void);
void wgpu_server_process(const WGPUServer *server);
void wgpu_terminate(WGPUClientFactory *factory);

View File

@@ -1,10 +1,12 @@
/* Generated with cbindgen:0.8.3 */
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define WGPUBITS_PER_BYTE 8
#define WGPUMAX_BIND_GROUPS 4
#define WGPUMAX_COLOR_TARGETS 4
@@ -55,6 +57,13 @@ typedef enum {
WGPUBorderColor_OpaqueWhite = 2,
} WGPUBorderColor;
typedef enum {
WGPUBufferMapAsyncStatus_Success,
WGPUBufferMapAsyncStatus_Error,
WGPUBufferMapAsyncStatus_Unknown,
WGPUBufferMapAsyncStatus_ContextLost,
} WGPUBufferMapAsyncStatus;
typedef enum {
WGPUCompareFunction_Never = 0,
WGPUCompareFunction_Less = 1,
@@ -244,7 +253,7 @@ typedef enum {
WGPUVertexFormat_Int4 = 48,
} WGPUVertexFormat;
typedef struct WGPUBufferMapAsyncStatus WGPUBufferMapAsyncStatus;
typedef struct WGPUTrackPermit WGPUTrackPermit;
typedef uint32_t WGPUIndex;
@@ -319,6 +328,12 @@ typedef struct {
float b;
float a;
} WGPUColor;
#define WGPUColor_TRANSPARENT (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 0 }
#define WGPUColor_BLACK (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 1 }
#define WGPUColor_WHITE (WGPUColor){ .r = 1, .g = 1, .b = 1, .a = 1 }
#define WGPUColor_RED (WGPUColor){ .r = 1, .g = 0, .b = 0, .a = 1 }
#define WGPUColor_GREEN (WGPUColor){ .r = 0, .g = 1, .b = 0, .a = 1 }
#define WGPUColor_BLUE (WGPUColor){ .r = 0, .g = 0, .b = 1, .a = 1 }
typedef struct {
WGPUTextureViewId attachment;
@@ -396,6 +411,9 @@ typedef struct {
} WGPUBindGroupDescriptor;
typedef uint32_t WGPUShaderStageFlags;
#define WGPUShaderStageFlags_VERTEX 1
#define WGPUShaderStageFlags_FRAGMENT 2
#define WGPUShaderStageFlags_COMPUTE 4
typedef struct {
uint32_t binding;
@@ -409,6 +427,16 @@ typedef struct {
} WGPUBindGroupLayoutDescriptor;
typedef uint32_t WGPUBufferUsageFlags;
#define WGPUBufferUsageFlags_MAP_READ 1
#define WGPUBufferUsageFlags_MAP_WRITE 2
#define WGPUBufferUsageFlags_TRANSFER_SRC 4
#define WGPUBufferUsageFlags_TRANSFER_DST 8
#define WGPUBufferUsageFlags_INDEX 16
#define WGPUBufferUsageFlags_VERTEX 32
#define WGPUBufferUsageFlags_UNIFORM 64
#define WGPUBufferUsageFlags_STORAGE 128
#define WGPUBufferUsageFlags_NONE 0
#define WGPUBufferUsageFlags_WRITE_ALL 2 + 8 + 128
typedef struct {
uint32_t size;
@@ -455,6 +483,12 @@ typedef struct {
} WGPUBlendDescriptor;
typedef uint32_t WGPUColorWriteFlags;
#define WGPUColorWriteFlags_RED 1
#define WGPUColorWriteFlags_GREEN 2
#define WGPUColorWriteFlags_BLUE 4
#define WGPUColorWriteFlags_ALPHA 8
#define WGPUColorWriteFlags_COLOR 7
#define WGPUColorWriteFlags_ALL 15
typedef struct {
WGPUTextureFormat format;
@@ -542,6 +576,14 @@ typedef WGPUId WGPUSurfaceId;
typedef WGPUSurfaceId WGPUSwapChainId;
typedef uint32_t WGPUTextureUsageFlags;
#define WGPUTextureUsageFlags_TRANSFER_SRC 1
#define WGPUTextureUsageFlags_TRANSFER_DST 2
#define WGPUTextureUsageFlags_SAMPLED 4
#define WGPUTextureUsageFlags_STORAGE 8
#define WGPUTextureUsageFlags_OUTPUT_ATTACHMENT 16
#define WGPUTextureUsageFlags_NONE 0
#define WGPUTextureUsageFlags_WRITE_ALL 2 + 8 + 16
#define WGPUTextureUsageFlags_UNINITIALIZED 65535
typedef struct {
WGPUTextureUsageFlags usage;
@@ -570,6 +612,9 @@ typedef struct {
} WGPUSwapChainOutput;
typedef uint32_t WGPUTextureAspectFlags;
#define WGPUTextureAspectFlags_COLOR 1
#define WGPUTextureAspectFlags_DEPTH 2
#define WGPUTextureAspectFlags_STENCIL 4
typedef struct {
WGPUTextureFormat format;
@@ -581,79 +626,9 @@ typedef struct {
uint32_t array_count;
} WGPUTextureViewDescriptor;
#define WGPUBufferUsageFlags_INDEX 16
#define WGPUBufferUsageFlags_MAP_READ 1
#define WGPUBufferUsageFlags_MAP_WRITE 2
#define WGPUBufferUsageFlags_NONE 0
#define WGPUBufferUsageFlags_STORAGE 128
#define WGPUBufferUsageFlags_TRANSFER_DST 8
#define WGPUBufferUsageFlags_TRANSFER_SRC 4
#define WGPUBufferUsageFlags_UNIFORM 64
#define WGPUBufferUsageFlags_VERTEX 32
#define WGPUColorWriteFlags_ALL 15
#define WGPUColorWriteFlags_ALPHA 8
#define WGPUColorWriteFlags_BLUE 4
#define WGPUColorWriteFlags_COLOR 7
#define WGPUColorWriteFlags_GREEN 2
#define WGPUColorWriteFlags_RED 1
#define WGPUColor_BLACK (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 1 }
#define WGPUColor_BLUE (WGPUColor){ .r = 0, .g = 0, .b = 1, .a = 1 }
#define WGPUColor_GREEN (WGPUColor){ .r = 0, .g = 1, .b = 0, .a = 1 }
#define WGPUColor_RED (WGPUColor){ .r = 1, .g = 0, .b = 0, .a = 1 }
#define WGPUColor_TRANSPARENT (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 0 }
#define WGPUColor_WHITE (WGPUColor){ .r = 1, .g = 1, .b = 1, .a = 1 }
#define WGPUPipelineFlags_BLEND_COLOR 1
#define WGPUShaderStageFlags_COMPUTE 4
#define WGPUShaderStageFlags_FRAGMENT 2
#define WGPUShaderStageFlags_VERTEX 1
#define WGPUTextureAspectFlags_COLOR 1
#define WGPUTextureAspectFlags_DEPTH 2
#define WGPUTextureAspectFlags_STENCIL 4
#define WGPUTextureUsageFlags_NONE 0
#define WGPUTextureUsageFlags_OUTPUT_ATTACHMENT 16
#define WGPUTextureUsageFlags_SAMPLED 4
#define WGPUTextureUsageFlags_STORAGE 8
#define WGPUTextureUsageFlags_TRANSFER_DST 2
#define WGPUTextureUsageFlags_TRANSFER_SRC 1
#define WGPUTextureUsageFlags_UNINITIALIZED 65535
#define WGPUTrackPermit_EXTEND (WGPUTrackPermit){ .bits = 1 }
#define WGPUTrackPermit_REPLACE (WGPUTrackPermit){ .bits = 2 }
WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDeviceDescriptor *desc);
@@ -715,7 +690,9 @@ WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id,
uint32_t index,
WGPUBindGroupId bind_group_id);
WGPUBindGroupId bind_group_id,
const uint32_t *offsets_ptr,
uintptr_t offsets_count);
void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id);
@@ -769,6 +746,11 @@ WGPUSurfaceId wgpu_instance_create_surface_from_windows_hwnd(WGPUInstanceId inst
void *hinstance,
void *hwnd);
#if defined(WGPU_WINDOW_WINIT)
WGPUSurfaceId wgpu_instance_create_surface_from_winit(WGPUInstanceId instance_id,
const WGPUWindow *window);
#endif
WGPUSurfaceId wgpu_instance_create_surface_from_xlib(WGPUInstanceId instance_id,
const void **display,
uint64_t window);
@@ -797,7 +779,9 @@ WGPUCommandBufferId wgpu_render_pass_end_pass(WGPURenderPassId pass_id);
void wgpu_render_pass_set_bind_group(WGPURenderPassId pass_id,
uint32_t index,
WGPUBindGroupId bind_group_id);
WGPUBindGroupId bind_group_id,
const uint32_t *offsets_ptr,
uintptr_t offsets_count);
void wgpu_render_pass_set_blend_color(WGPURenderPassId pass_id, const WGPUColor *color);

View File

@@ -1,14 +0,0 @@
[package]
name = "wgpu-bindings"
version = "0.1.0"
authors = [
"Dzmitry Malyshau <kvark@mozilla.com>",
"Joshua Groves <josh@joshgroves.com>",
]
edition = "2018"
[features]
default = []
[dependencies]
cbindgen = "0.7.1"

View File

@@ -1,52 +0,0 @@
extern crate cbindgen;
use std::path::PathBuf;
struct Binding<'a> {
library: &'a str,
features: &'a [&'a str],
output: &'a str,
}
const BINDINGS: [Binding; 2] = [
Binding {
library: "wgpu-native",
features: &["local"],
output: "wgpu.h",
},
Binding {
library: "wgpu-remote",
features: &[],
output: "wgpu-remote.h",
},
];
fn main() {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let parent = crate_dir.parent().unwrap();
for bind in &BINDINGS {
let config = cbindgen::Config {
enumeration: cbindgen::EnumConfig {
prefix_with_name: true,
..Default::default()
},
export: cbindgen::ExportConfig {
prefix: Some(String::from("WGPU")),
..Default::default()
},
language: cbindgen::Language::C,
..Default::default()
};
println!("Generating {}...", bind.output);
cbindgen::Builder::new()
.with_crate(parent.join(bind.library))
.with_config(config)
.with_parse_expand(&[bind.library])
.with_parse_expand_features(bind.features)
.generate()
.unwrap()
.write_to_file(crate_dir.join(bind.output));
}
}

View File

@@ -1,14 +0,0 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct WGPUClient WGPUClient;
WGPUDeviceId wgpu_adapter_create_device(const WGPUClient *client,
WGPUAdapterId adapter_id,
const WGPUDeviceDescriptor *desc);
WGPUAdapterId wgpu_instance_get_adapter(const WGPUClient *client,
WGPUInstanceId instance_id,
const WGPUAdapterDescriptor *desc);

View File

@@ -29,7 +29,7 @@ copyless = "0.1"
lazy_static = "1.1.0"
log = "0.4"
parking_lot = { version = "0.7" }
gfx-hal = "0.1.0"
hal = { package = "gfx-hal", version = "0.1" }
gfx-backend-empty = { version = "0.1.1" }
gfx-backend-vulkan = { version = "0.1", optional = true }
gfx-backend-dx11 = { version = "0.1", optional = true }

31
wgpu-native/cbindgen.toml Normal file
View File

@@ -0,0 +1,31 @@
header = ""
include_version = true
braces = "SameLine"
line_length = 100
tab_width = 2
language = "C"
[export]
prefix = "WGPU"
[parse]
parse_deps = false
[parse.expand]
features = ["local"]
[fn]
[struct]
derive_eq = true
[enum]
prefix_with_name = true
derive_helper_methods = true
[macro_expansion]
bitflags = true
[defines]
"feature = window-winit" = "WGPU_WINDOW_WINIT"
"feature = remote" = "WGPU_REMOTE"

View File

@@ -42,6 +42,7 @@ pub struct BindGroupLayoutDescriptor {
pub struct BindGroupLayout<B: hal::Backend> {
pub(crate) raw: B::DescriptorSetLayout,
pub(crate) bindings: Vec<BindGroupLayoutBinding>,
pub(crate) dynamic_count: usize,
}
#[repr(C)]
@@ -87,4 +88,5 @@ pub struct BindGroup<B: hal::Backend> {
pub(crate) layout_id: BindGroupLayoutId,
pub(crate) life_guard: LifeGuard,
pub(crate) used: TrackerSet,
pub(crate) dynamic_count: usize,
}

View File

@@ -12,7 +12,8 @@ use crate::{
use hal::{self, command::RawCommandBuffer};
use std::iter;
use std::{iter, slice};
pub struct ComputePass<B: hal::Backend> {
raw: B::CommandBuffer,
@@ -56,13 +57,23 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group(
pass_id: ComputePassId,
index: u32,
bind_group_id: BindGroupId,
offsets: &[u32],
offsets_ptr: *const u32,
offsets_count: usize,
) {
let mut pass_guard = HUB.compute_passes.write();
let pass = &mut pass_guard[pass_id];
let bind_group_guard = HUB.bind_groups.read();
let bind_group = &bind_group_guard[bind_group_id];
assert_eq!(bind_group.dynamic_count, offsets_count);
let offsets = if offsets_count != 0 {
unsafe {
slice::from_raw_parts(offsets_ptr, offsets_count)
}
} else {
&[]
};
//Note: currently, WebGPU compute passes have synchronization defined
// at a dispatch granularity, so we insert the necessary barriers here.

View File

@@ -224,13 +224,23 @@ pub extern "C" fn wgpu_render_pass_set_bind_group(
pass_id: RenderPassId,
index: u32,
bind_group_id: BindGroupId,
offsets: &[u32],
offsets_ptr: *const u32,
offsets_count: usize,
) {
let mut pass_guard = HUB.render_passes.write();
let pass = &mut pass_guard[pass_id];
let bind_group_guard = HUB.bind_groups.read();
let bind_group = &bind_group_guard[bind_group_id];
assert_eq!(bind_group.dynamic_count, offsets_count);
let offsets = if offsets_count != 0 {
unsafe {
slice::from_raw_parts(offsets_ptr, offsets_count)
}
} else {
&[]
};
pass.trackers.consume_by_extend(&bind_group.used);
if let Some((pipeline_layout_id, follow_up)) =

View File

@@ -452,6 +452,7 @@ pub fn map_texture_dimension_size(
}
}
#[cfg(feature = "local")]
pub fn map_texture_view_dimension(
dimension: resource::TextureViewDimension,
) -> hal::image::ViewKind {
@@ -467,6 +468,7 @@ pub fn map_texture_view_dimension(
}
}
#[cfg(feature = "local")]
pub fn map_texture_aspect_flags(aspect: resource::TextureAspectFlags) -> hal::format::Aspects {
use crate::resource::TextureAspectFlags as Taf;
use hal::format::Aspects;

View File

@@ -856,6 +856,7 @@ pub extern "C" fn wgpu_texture_create_default_view(texture_id: TextureId) -> Tex
id
}
#[no_mangle]
pub extern "C" fn wgpu_texture_destroy(texture_id: TextureId) {
let texture_guard = HUB.textures.read();
@@ -952,6 +953,14 @@ pub fn device_create_bind_group_layout(
binding_model::BindGroupLayout {
raw,
bindings: bindings.to_vec(),
dynamic_count: bindings
.iter()
.filter(|b| match b.ty {
binding_model::BindingType::UniformBufferDynamic |
binding_model::BindingType::StorageBufferDynamic => true,
_ => false,
})
.count(),
}
}
@@ -1091,6 +1100,7 @@ pub fn device_create_bind_group(
layout_id: desc.layout,
life_guard: LifeGuard::new(),
used,
dynamic_count: bind_group_layout.dynamic_count,
}
}

View File

@@ -171,23 +171,23 @@ impl<T> Registry<T> {
#[derive(Default)]
pub struct Hub {
pub(crate) instances: Arc<Registry<InstanceHandle>>,
pub(crate) adapters: Arc<Registry<AdapterHandle>>,
pub(crate) devices: Arc<Registry<DeviceHandle>>,
pub(crate) pipeline_layouts: Arc<Registry<PipelineLayoutHandle>>,
pub(crate) bind_group_layouts: Arc<Registry<BindGroupLayoutHandle>>,
pub(crate) bind_groups: Arc<Registry<BindGroupHandle>>,
pub(crate) shader_modules: Arc<Registry<ShaderModuleHandle>>,
pub(crate) command_buffers: Arc<Registry<CommandBufferHandle>>,
pub(crate) render_pipelines: Arc<Registry<RenderPipelineHandle>>,
pub(crate) compute_pipelines: Arc<Registry<ComputePipelineHandle>>,
pub(crate) render_passes: Arc<Registry<RenderPassHandle>>,
pub(crate) compute_passes: Arc<Registry<ComputePassHandle>>,
pub(crate) buffers: Arc<Registry<BufferHandle>>,
pub(crate) textures: Arc<Registry<TextureHandle>>,
pub(crate) texture_views: Arc<Registry<TextureViewHandle>>,
pub(crate) samplers: Arc<Registry<SamplerHandle>>,
pub(crate) surfaces: Arc<Registry<SurfaceHandle>>,
pub instances: Arc<Registry<InstanceHandle>>,
pub adapters: Arc<Registry<AdapterHandle>>,
pub devices: Arc<Registry<DeviceHandle>>,
pub pipeline_layouts: Arc<Registry<PipelineLayoutHandle>>,
pub bind_group_layouts: Arc<Registry<BindGroupLayoutHandle>>,
pub bind_groups: Arc<Registry<BindGroupHandle>>,
pub shader_modules: Arc<Registry<ShaderModuleHandle>>,
pub command_buffers: Arc<Registry<CommandBufferHandle>>,
pub render_pipelines: Arc<Registry<RenderPipelineHandle>>,
pub compute_pipelines: Arc<Registry<ComputePipelineHandle>>,
pub render_passes: Arc<Registry<RenderPassHandle>>,
pub compute_passes: Arc<Registry<ComputePassHandle>>,
pub buffers: Arc<Registry<BufferHandle>>,
pub textures: Arc<Registry<TextureHandle>>,
pub texture_views: Arc<Registry<TextureViewHandle>>,
pub samplers: Arc<Registry<SamplerHandle>>,
pub surfaces: Arc<Registry<SurfaceHandle>>,
}
lazy_static! {

View File

@@ -19,18 +19,21 @@ pub enum PowerPreference {
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
pub struct AdapterDescriptor {
pub power_preference: PowerPreference,
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
pub struct Extensions {
pub anisotropic_filtering: bool,
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
pub struct DeviceDescriptor {
pub extensions: Extensions,
@@ -40,14 +43,15 @@ pub fn create_instance() -> ::back::Instance {
::back::Instance::create("wgpu", 1)
}
#[no_mangle]
#[cfg(feature = "local")]
#[no_mangle]
pub extern "C" fn wgpu_create_instance() -> InstanceId {
let inst = create_instance();
HUB.instances.register_local(inst)
}
#[cfg(all(feature = "local", feature = "window-winit"))]
#[cfg(feature = "window-winit")]
#[no_mangle]
pub extern "C" fn wgpu_instance_create_surface_from_winit(
instance_id: InstanceId,

View File

@@ -17,9 +17,6 @@ extern crate gfx_backend_metal as back;
#[cfg(feature = "gfx-backend-vulkan")]
extern crate gfx_backend_vulkan as back;
extern crate gfx_hal as hal;
//extern crate rendy_memory;
mod binding_model;
mod command;
mod conv;
@@ -35,7 +32,7 @@ pub use self::binding_model::*;
pub use self::command::*;
pub use self::device::*;
#[cfg(feature = "remote")]
pub use self::hub::{Id, IdentityManager, Registry, HUB};
pub use self::hub::{IdentityManager, Registry, HUB};
pub use self::instance::*;
pub use self::pipeline::*;
pub use self::resource::*;
@@ -44,6 +41,7 @@ pub use self::swap_chain::*;
use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};
type SubmissionIndex = usize;
//TODO: make it private. Currently used for swapchain creation impl.

View File

@@ -39,6 +39,7 @@ pub struct BufferDescriptor {
pub usage: BufferUsageFlags,
}
#[repr(C)]
pub enum BufferMapAsyncStatus {
Success,
Error,
@@ -172,6 +173,7 @@ pub struct TextureDescriptor {
}
pub(crate) enum TexturePlacement<B: hal::Backend> {
#[cfg_attr(feature = "remote", allow(unused))]
SwapChain(SwapChainLink<Mutex<SwapImageEpoch>>),
Memory(B::Memory),
Void,

View File

@@ -7,11 +7,18 @@ authors = [
]
edition = "2018"
[lib]
crate-type = ["lib", "cdylib", "staticlib"]
[features]
default = []
vulkan = ["wgpu-native/gfx-backend-vulkan"]
dx11 = ["wgpu-native/gfx-backend-dx11"]
dx12 = ["wgpu-native/gfx-backend-dx12"]
metal = ["wgpu-native/gfx-backend-metal"]
[dependencies]
wgpu-native = { path = "../wgpu-native", features = ["remote"] }
wgpu-native = { path = "../wgpu-native", version = "0.2", features = ["remote"] }
ipc-channel = "0.11"
log = "0.4"
parking_lot = { version = "0.7" }

25
wgpu-remote/cbindgen.toml Normal file
View File

@@ -0,0 +1,25 @@
header = ""
include_version = true
braces = "SameLine"
line_length = 100
tab_width = 2
language = "C"
[export]
prefix = "WGPU"
[parse]
parse_deps = true
include = ["wgpu_native"]
[fn]
[struct]
derive_eq = true
[enum]
prefix_with_name = true
derive_helper_methods = true
[macro_expansion]
bitflags = true

View File

@@ -1,54 +1,126 @@
use ipc_channel::ipc::IpcSender;
//TODO: remove once `cbindgen` is smart enough
extern crate wgpu_native as wgn;
use crate::server::Server;
use ipc_channel::ipc;
use log::error;
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use wgpu_native as wgn;
use std::ptr;
mod server;
#[derive(Serialize, Deserialize)]
pub enum InstanceMessage {
enum InstanceMessage {
Create(wgn::InstanceId),
InstanceGetAdapter(wgn::InstanceId, wgn::AdapterDescriptor, wgn::AdapterId),
AdapterCreateDevice(wgn::AdapterId, wgn::DeviceDescriptor, wgn::DeviceId),
Destroy(wgn::InstanceId),
}
/// A message on the timeline of devices, queues, and resources.
#[derive(Serialize, Deserialize)]
pub enum GlobalMessage {
enum GlobalMessage {
Instance(InstanceMessage),
//Device(DeviceMessage),
//Queue(QueueMessage),
//Texture(TextureMessage),
//Command(CommandMessage),
Terminate,
}
#[derive(Default)]
pub struct IdentityHub {
struct IdentityHub {
adapters: wgn::IdentityManager,
devices: wgn::IdentityManager,
}
pub struct Client {
channel: IpcSender<GlobalMessage>,
channel: ipc::IpcSender<GlobalMessage>,
instance_id: wgn::InstanceId,
identity: Mutex<IdentityHub>,
}
impl Client {
pub fn new(channel: IpcSender<GlobalMessage>) -> Self {
Client {
channel,
identity: Mutex::new(IdentityHub::default()),
pub struct ClientFactory {
channel: ipc::IpcSender<GlobalMessage>,
instance_identities: Mutex<wgn::IdentityManager>,
}
#[repr(C)]
pub struct Infrastructure {
pub factory: *mut ClientFactory,
pub server: *mut Server,
pub error: *const u8,
}
#[no_mangle]
pub extern "C" fn wgpu_initialize() -> Infrastructure {
match ipc::channel() {
Ok((sender, receiver)) => {
let factory = ClientFactory {
channel: sender,
instance_identities: Mutex::new(wgn::IdentityManager::default()),
};
let server = Server::new(receiver);
Infrastructure {
factory: Box::into_raw(Box::new(factory)),
server: Box::into_raw(Box::new(server)),
error: ptr::null(),
}
}
Err(e) => {
error!("WGPU initialize failed: {:?}", e);
Infrastructure {
factory: ptr::null_mut(),
server: ptr::null_mut(),
error: ptr::null(), //TODO_remote_
}
}
}
}
#[no_mangle]
pub extern "C" fn wgpu_instance_get_adapter(
pub extern "C" fn wgpu_terminate(factory: *mut ClientFactory) {
let factory = unsafe {
Box::from_raw(factory)
};
let _ = factory.channel.send(GlobalMessage::Terminate);
}
#[no_mangle]
pub extern "C" fn wgpu_client_create(factory: &ClientFactory) -> *mut Client {
let instance_id = factory.instance_identities.lock().alloc();
let msg = GlobalMessage::Instance(InstanceMessage::Create(instance_id));
factory.channel.send(msg).unwrap();
let client = Client {
channel: factory.channel.clone(),
instance_id,
identity: Mutex::new(IdentityHub::default()),
};
Box::into_raw(Box::new(client))
}
#[no_mangle]
pub extern "C" fn wgpu_client_destroy(factory: &ClientFactory, client: *mut Client) {
let client = unsafe {
Box::from_raw(client)
};
factory.instance_identities.lock().free(client.instance_id);
let msg = GlobalMessage::Instance(InstanceMessage::Destroy(client.instance_id));
client.channel.send(msg).unwrap();
}
#[no_mangle]
pub extern "C" fn wgpu_client_get_adapter(
client: &Client,
instance_id: wgn::InstanceId,
desc: &wgn::AdapterDescriptor,
) -> wgn::AdapterId {
let id = client.identity.lock().adapters.alloc();
let msg = GlobalMessage::Instance(InstanceMessage::InstanceGetAdapter(
instance_id,
client.instance_id,
desc.clone(),
id,
));
@@ -57,7 +129,7 @@ pub extern "C" fn wgpu_instance_get_adapter(
}
#[no_mangle]
pub extern "C" fn wgpu_adapter_create_device(
pub extern "C" fn wgpu_client_adapter_create_device(
client: &Client,
adapter_id: wgn::AdapterId,
desc: &wgn::DeviceDescriptor,

View File

@@ -1,27 +1,33 @@
use crate::{GlobalMessage, InstanceMessage}
use crate::{GlobalMessage, InstanceMessage};
use ipc_channel::ipc::IpcReceiver;
use wgn;
struct Server {
pub struct Server {
channel: IpcReceiver<GlobalMessage>,
instance_id: wgn::IntanceId,
}
impl Server {
pub fn new(channel: IpcReceiver<GlobalMessage>) -> Self {
pub(crate) fn new(channel: IpcReceiver<GlobalMessage>) -> Self {
Server {
channel,
instance_id: wgn::wgpu_create_instance(),
}
}
}
pub fn process(message: GlobalMessage) {
enum ControlFlow {
Continue,
Terminate,
}
fn process(message: GlobalMessage) -> ControlFlow {
match message {
GlobalMessage::Instance(msg) => match msg {
InstanceMessage::Create(instance_id) => {
let instance = wgn::create_instance();
wgn::HUB.instances.register(instance_id, instance);
}
InstanceMessage::InstanceGetAdapter(instance_id, ref desc, id) => {
let adapter = wgn::instance_get_adapter(instance_id, desc);
wgn::HUB.adapters.register(id, adapter);
@@ -30,6 +36,23 @@ pub fn process(message: GlobalMessage) {
let device = wgn::adapter_create_device(adapter_id, desc);
wgn::HUB.devices.register(id, device);
}
InstanceMessage::Destroy(instance_id) => {
wgn::HUB.instances.unregister(instance_id);
}
},
GlobalMessage::Terminate => return ControlFlow::Terminate,
}
ControlFlow::Continue
}
#[no_mangle]
pub extern "C" fn wgpu_server_process(server: &Server) {
while let Ok(message) = server.channel.try_recv() {
match process(message) {
ControlFlow::Continue => {},
ControlFlow::Terminate => break,
}
}
}

View File

@@ -16,12 +16,12 @@ license = "MPL-2.0"
[features]
default = []
metal-auto-capture = ["wgpu-native/metal-auto-capture"]
metal = ["wgpu-native/gfx-backend-metal"]
dx11 = ["wgpu-native/gfx-backend-dx11"]
dx12 = ["wgpu-native/gfx-backend-dx12"]
vulkan = ["wgpu-native/gfx-backend-vulkan"]
metal-auto-capture = ["wgn/metal-auto-capture"]
metal = ["wgn/gfx-backend-metal"]
dx11 = ["wgn/gfx-backend-dx11"]
dx12 = ["wgn/gfx-backend-dx12"]
vulkan = ["wgn/gfx-backend-vulkan"]
[dependencies]
wgpu-native = { version = "0.2.5", path = "../wgpu-native", features = ["local", "window-winit"] }
wgn = { package = "wgpu-native", version = "0.2.5", path = "../wgpu-native", features = ["local", "window-winit"] }
arrayvec = "0.4"

View File

@@ -1,6 +1,3 @@
extern crate arrayvec;
extern crate wgpu_native as wgn;
use arrayvec::ArrayVec;
use std::ffi::CString;
@@ -839,7 +836,13 @@ impl CommandEncoder {
impl<'a> RenderPass<'a> {
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup, offsets: &[u32]) {
wgn::wgpu_render_pass_set_bind_group(self.id, index, bind_group.id, offsets);
wgn::wgpu_render_pass_set_bind_group(
self.id,
index,
bind_group.id,
offsets.as_ptr(),
offsets.len(),
);
}
pub fn set_pipeline(&mut self, pipeline: &RenderPipeline) {
@@ -903,7 +906,13 @@ impl<'a> Drop for RenderPass<'a> {
impl<'a> ComputePass<'a> {
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup, offsets: &[u32]) {
wgn::wgpu_compute_pass_set_bind_group(self.id, index, bind_group.id, offsets);
wgn::wgpu_compute_pass_set_bind_group(
self.id,
index,
bind_group.id,
offsets.as_ptr(),
offsets.len(),
);
}
pub fn set_pipeline(&mut self, pipeline: &ComputePipeline) {