Skip to content

Commit

Permalink
Global manager for instance names on the remote client
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Apr 30, 2019
1 parent 52ee3e0 commit 0011d9f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ else
endif


.PHONY: all check test doc clear lib-native lib-remote lib-rust ci-examples examples-native examples-rust examples-gfx gfx
.PHONY: all check test doc clear lib-native lib-remote lib-rust ci-examples examples-rust examples-gfx gfx

all: examples-native examples-rust examples-gfx
all: ci-examples examples-rust examples-gfx

check:
cargo check --all
Expand All @@ -59,9 +59,6 @@ lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
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

ci-examples:
cargo build --manifest-path wgpu-native/Cargo.toml --features=local,$(FEATURE_NATIVE)
cargo build --manifest-path wgpu-remote/Cargo.toml --features=$(FEATURE_RUST)
Expand Down
4 changes: 3 additions & 1 deletion examples/hello_triangle_c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int main() {
return 1;
}

WGPUSurfaceId surface = {};
WGPUSurfaceId surface;

#if WGPU_TARGET == WGPU_TARGET_MACOS
{
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 0 additions & 3 deletions wgpu-native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions wgpu-remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ metal = ["wgn/gfx-backend-metal"]
[dependencies]
wgn = { package = "wgpu-native", path = "../wgpu-native", features = ["remote"] }
ipc-channel = "0.11"
lazy_static = "1"
log = "0.4"
parking_lot = { version = "0.7" }
serde = { version = "1.0", features = ["serde_derive"] }
8 changes: 7 additions & 1 deletion wgpu-remote/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::server::Server;

use ipc_channel::ipc;
use lazy_static::lazy_static;
use log::error;
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
Expand All @@ -11,6 +12,10 @@ use std::ptr;
mod server;


lazy_static! {
static ref INSTANCE_IDENTITIES: Mutex<wgn::IdentityManager> = Mutex::new(wgn::IdentityManager::default());
}

#[derive(Serialize, Deserialize)]
enum InstanceMessage {
InstanceGetAdapter(wgn::InstanceId, wgn::AdapterDescriptor, wgn::AdapterId),
Expand Down Expand Up @@ -64,7 +69,7 @@ pub struct Infrastructure {
pub extern "C" fn wgpu_initialize() -> Infrastructure {
match ipc::channel() {
Ok((sender, receiver)) => {
let instance_id = wgn::IdentityManager::default().alloc(); // TODO: static
let instance_id = INSTANCE_IDENTITIES.lock().alloc();
let client = Client::new(sender, instance_id);
let server = Server::new(receiver, instance_id);
Infrastructure {
Expand All @@ -90,6 +95,7 @@ pub extern "C" fn wgpu_terminate(client: *mut Client) {
let client = unsafe {
Box::from_raw(client)
};
INSTANCE_IDENTITIES.lock().free(client.instance_id);
let _ = client.channel.send(GlobalMessage::Instance(InstanceMessage::Terminate));
}

Expand Down
3 changes: 0 additions & 3 deletions wgpu-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate arrayvec;
extern crate wgn;

use arrayvec::ArrayVec;

use std::ffi::CString;
Expand Down

0 comments on commit 0011d9f

Please sign in to comment.