Skip to content

Commit aa14f7f

Browse files
bors[bot]kvark
andauthored
Merge #381
381: Separate Native from the Core r=grovesNL a=kvark Fixes #379 (haven't figured out how to build remote static lib to test the example, but that's not as important at this stage, since we have Gecko). Fixes #168 Related to #2 and #8 This is a major refactor that moves out the core Rust API into a separate crate. It also changes the export semantics of wgpu-core in a way that the modules are exposed, and all the functionality is now represented as methods of `Global`. The "local" feature is transformed into a type system as a generic parameter `<F>` on the hubs. Pros: - "local" feature is gone - we can change the core API more often, this doesn't necessarily require the `native` breaking version bump, and it would be very handy when adding Gecko-related changes - Gecko needs less stuff to compile (remote + core) - no collision of library names (native with or without the local feature) - less problem with crate types - cleaner semantics: each crate is either C or Rust, but not both Cons: - more generics, I wouldn't be surprised this regresses the build times visibly Co-authored-by: Dzmitry Malyshau <[email protected]>
2 parents f221a65 + 6c632d1 commit aa14f7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5873
-6055
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ before_install:
5858
script:
5959
- cargo test
6060
# TODO: enable GL backend
61-
- (cd wgpu-native && cargo check --all-features)
62-
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (cd wgpu-native && cargo check --features gfx-backend-vulkan); fi
61+
- (cd wgpu-core && cargo check --all-features)
62+
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (cd wgpu-native && cargo check --features vulkan-portability); fi
6363
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cargo check --release; fi
6464
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen; fi
6565
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME == "windows" ]]; then

Cargo.lock

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3+
"wgpu-core",
34
"wgpu-native",
45
"wgpu-remote",
56
]

Makefile

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ BUILD_DIR:=build
88
CLEAN_FFI_DIR:=
99
CREATE_BUILD_DIR:=
1010

11-
WILDCARD_WGPU_NATIVE:=$(wildcard wgpu-native/**/*.rs)
12-
WILDCARD_WGPU_NATIVE_AND_REMOTE:=$(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs)
11+
WILDCARD_WGPU_NATIVE:=$(wildcard wgpu-native/**/*.rs wgpu-core/**/*.rs)
12+
WILDCARD_WGPU_REMOTE:=$(wildcard wgpu-remote/**/*.rs wgpu-core/**/*.rs)
1313

1414
ifeq (,$(TARGET))
1515
CHECK_TARGET_FLAG=
@@ -30,7 +30,8 @@ endif
3030
example-compute example-triangle example-remote \
3131
run-example-compute run-example-triangle run-example-remote
3232

33-
all: example-compute example-triangle example-remote
33+
#TODO: example-remote
34+
all: example-compute example-triangle
3435

3536
check:
3637
cargo check --all
@@ -46,15 +47,15 @@ clear:
4647
$(CLEAN_FFI_DIR)
4748

4849
lib-native: Cargo.lock wgpu-native/Cargo.toml $(WILDCARD_WGPU_NATIVE)
49-
cargo build --manifest-path wgpu-native/Cargo.toml --features local
50+
cargo build --manifest-path wgpu-native/Cargo.toml
5051

51-
lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
52+
lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_REMOTE)
5253
cargo build --manifest-path wgpu-remote/Cargo.toml
5354

5455
$(FFI_DIR)/wgpu.h: wgpu-native/cbindgen.toml $(WILDCARD_WGPU_NATIVE)
5556
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu.h wgpu-native
5657

57-
$(FFI_DIR)/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
58+
$(FFI_DIR)/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_REMOTE)
5859
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu-remote.h wgpu-remote
5960

6061
example-compute: lib-native $(FFI_DIR)/wgpu.h examples/compute/main.c

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ This is an active GitHub mirror of the WebGPU native implementation in Rust, whi
99
This is an experimental [WebGPU](https://www.w3.org/community/gpu/) implementation as a native static library. It's written in Rust and is based on [gfx-hal](https://github.com/gfx-rs/gfx) and [Rendy](https://github.com/amethyst/rendy) libraries. The corresponding WebIDL specification can be found at [gpuweb project](https://github.com/gpuweb/gpuweb/blob/master/spec/index.bs).
1010

1111
The implementation consists of the following parts:
12-
1. `wgpu-native` - the native implementation of WebGPU as a C API library
13-
2. `wgpu-remote` - remoting layer to work with WebGPU across the process boundary
14-
3. `ffi` - the C headers generated by [cbindgen](https://github.com/eqrion/cbindgen) for both of the libraries
12+
1. `wgpu-core` - internal Rust API for WebGPU implementations to use
13+
2. `wgpu-native` - the native implementation of WebGPU as a C API library
14+
3. `wgpu-remote` - remoting layer to work with WebGPU across the process boundary
15+
4. `ffi` - the C headers generated by [cbindgen](https://github.com/eqrion/cbindgen) for both of the libraries
1516

1617
## Supported Platforms
1718

examples/compute/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ int main(
5959
WGPUAdapterId adapter = { 0 };
6060
wgpu_request_adapter_async(
6161
NULL,
62+
2 | 4 | 8,
6263
request_adapter_callback,
6364
(void *) &adapter
6465
);

examples/remote/main.c

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ int main() {
3131

3232
WGPURequestAdapterOptions options = {
3333
.power_preference = WGPUPowerPreference_LowPower,
34-
.backends = 2 | 4 | 8,
3534
};
3635
char index = wgpu_server_instance_request_adapter(server, &options, ids, count);
3736
if (index < 0) {

examples/triangle/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ int main() {
4646
wgpu_request_adapter_async(
4747
&(WGPURequestAdapterOptions){
4848
.power_preference = WGPUPowerPreference_LowPower,
49-
.backends = 2 | 4 | 8,
5049
},
50+
2 | 4 | 8,
5151
request_adapter_callback,
5252
(void *) &adapter
5353
);

ffi/wgpu-remote.h

-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ typedef enum {
2727

2828
typedef struct WGPUClient WGPUClient;
2929

30-
typedef struct WGPUGlobal WGPUGlobal;
31-
3230
typedef uint64_t WGPUId_Adapter_Dummy;
3331

3432
typedef WGPUId_Adapter_Dummy WGPUAdapterId;
@@ -55,11 +53,8 @@ typedef struct {
5553
WGPULimits limits;
5654
} WGPUDeviceDescriptor;
5755

58-
typedef uint32_t WGPUBackendBit;
59-
6056
typedef struct {
6157
WGPUPowerPreference power_preference;
62-
WGPUBackendBit backends;
6358
} WGPURequestAdapterOptions;
6459

6560
WGPU_INLINE

0 commit comments

Comments
 (0)