Remote example and improved header, tested on CI

This commit is contained in:
Dzmitry Malyshau
2019-04-29 22:41:09 -04:00
parent 5ec6f35368
commit 52ee3e019c
21 changed files with 450 additions and 57 deletions

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 ci-examples); fi

View File

@@ -30,7 +30,7 @@ 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 ci-examples examples-native examples-rust examples-gfx gfx
all: examples-native examples-rust examples-gfx
@@ -50,15 +50,24 @@ 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
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)
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)
cargo build --manifest-path examples/Cargo.toml --features $(FEATURE_RUST)

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,18 @@
#include "./../../wgpu-bindings/wgpu-native.h"
#include "./../../wgpu-bindings/wgpu-remote.h"
#include <stdio.h>
int main() {
WGPUInfrastructure infra = wgpu_initialize();
if (!infra.client || !infra.server || infra.error) {
printf("Cannot initialize WGPU: %s", infra.error);
return 1;
}
//TODO: do something meaningful
wgpu_terminate(infra.client);
return 0;
}

View File

@@ -219,7 +219,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);

View File

@@ -1,23 +1,33 @@
extern crate cbindgen;
use cbindgen::ItemType as It;
use std::path::PathBuf;
struct Binding<'a> {
library: &'a str,
features: &'a [&'a str],
output: &'a str,
item_types: &'a [It],
}
const BINDINGS: [Binding; 2] = [
const BINDINGS: [Binding; 3] = [
Binding {
library: "wgpu-native",
features: &["local"],
output: "wgpu.h",
item_types: &[It::Enums, It::Constants, It::Structs, It::Typedefs, It::Functions],
},
Binding {
library: "wgpu-native",
features: &["remote"],
output: "wgpu-native.h",
item_types: &[It::Enums, It::Constants, It::Structs, It::Typedefs],
},
Binding {
library: "wgpu-remote",
features: &[],
output: "wgpu-remote.h",
item_types: &[It::Enums, It::Constants, It::Structs, It::Typedefs, It::OpaqueItems, It::Functions],
},
];
@@ -33,6 +43,7 @@ fn main() {
},
export: cbindgen::ExportConfig {
prefix: Some(String::from("WGPU")),
item_types: bind.item_types.to_vec(),
..Default::default()
},
language: cbindgen::Language::C,

196
wgpu-bindings/wgpu-native.h Normal file
View File

@@ -0,0 +1,196 @@
#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
typedef enum {
WGPUBufferMapAsyncStatus_Success,
WGPUBufferMapAsyncStatus_Error,
WGPUBufferMapAsyncStatus_Unknown,
WGPUBufferMapAsyncStatus_ContextLost,
} WGPUBufferMapAsyncStatus;
typedef enum {
WGPUPowerPreference_Default = 0,
WGPUPowerPreference_LowPower = 1,
WGPUPowerPreference_HighPerformance = 2,
} WGPUPowerPreference;
typedef uint32_t WGPUIndex;
typedef uint32_t WGPUEpoch;
typedef struct {
WGPUIndex _0;
WGPUEpoch _1;
} WGPUId;
typedef WGPUId WGPUAdapterId;
typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
typedef struct {
bool anisotropic_filtering;
} WGPUExtensions;
typedef struct {
WGPUExtensions extensions;
} WGPUDeviceDescriptor;
typedef struct {
WGPUAdapterId adapter;
WGPUAdapterDescriptor adapter_desc;
WGPUDeviceDescriptor device_desc;
} WGPUForcedExports;
typedef WGPUId WGPUBindGroupId;
typedef WGPUId WGPUBufferId;
typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, const uint8_t *data, uint8_t *userdata);
typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status, uint8_t *data, uint8_t *userdata);
typedef WGPUId WGPUCommandBufferId;
typedef struct {
WGPUBufferId buffer;
uint32_t offset;
uint32_t row_pitch;
uint32_t image_height;
} WGPUBufferCopyView;
typedef WGPUId WGPUTextureId;
typedef struct {
float x;
float y;
float z;
} WGPUOrigin3d;
typedef struct {
WGPUTextureId texture;
uint32_t level;
uint32_t slice;
WGPUOrigin3d origin;
} WGPUTextureCopyView;
typedef struct {
uint32_t width;
uint32_t height;
uint32_t depth;
} WGPUExtent3d;
typedef WGPUCommandBufferId WGPUCommandEncoderId;
typedef WGPUId WGPUComputePassId;
typedef WGPUId WGPUComputePipelineId;
typedef WGPUId WGPUDeviceId;
typedef WGPUDeviceId WGPUQueueId;
typedef WGPUId WGPURenderPassId;
typedef struct {
float r;
float g;
float b;
float a;
} WGPUColor;
typedef WGPUId WGPURenderPipelineId;
typedef WGPUId WGPUTextureViewId;
typedef struct {
WGPUTextureId texture_id;
WGPUTextureViewId view_id;
} WGPUSwapChainOutput;
typedef WGPUId WGPUSurfaceId;
typedef WGPUSurfaceId WGPUSwapChainId;
#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 }

View File

@@ -5,10 +5,23 @@
typedef struct WGPUClient WGPUClient;
typedef struct WGPUServer WGPUServer;
typedef struct {
WGPUClient *client;
WGPUServer *server;
const uint8_t *error;
} WGPUInfrastructure;
WGPUDeviceId wgpu_adapter_create_device(const WGPUClient *client,
WGPUAdapterId adapter_id,
const WGPUDeviceDescriptor *desc);
WGPUInfrastructure wgpu_initialize(void);
WGPUAdapterId wgpu_instance_get_adapter(const WGPUClient *client,
WGPUInstanceId instance_id,
const WGPUAdapterDescriptor *desc);
void wgpu_server_process(const WGPUServer *server);
void wgpu_terminate(WGPUClient *client);

View File

@@ -55,6 +55,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,8 +251,6 @@ typedef enum {
WGPUVertexFormat_Int4 = 48,
} WGPUVertexFormat;
typedef struct WGPUBufferMapAsyncStatus WGPUBufferMapAsyncStatus;
typedef uint32_t WGPUIndex;
typedef uint32_t WGPUEpoch;
@@ -713,10 +718,6 @@ void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t
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);
void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id);
WGPUInstanceId wgpu_create_instance(void);
@@ -797,7 +798,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

@@ -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

@@ -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

@@ -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,

View File

@@ -35,7 +35,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::*;
@@ -46,6 +46,25 @@ use std::sync::atomic::{AtomicUsize, Ordering};
type SubmissionIndex = usize;
//TODO: remove this structure and entry point.
// They are currently needed to force `cbindgen` to export some of
// the types when building with `remote` feature excluding the
// functions export (as a `wgpu-remote.h` dependency).
#[cfg(feature = "remote")]
#[repr(C)]
#[derive(Debug)]
pub struct ForcedExports {
pub adapter: AdapterId,
pub adapter_desc: AdapterDescriptor,
pub device_desc: DeviceDescriptor,
}
#[cfg(feature = "remote")]
#[no_mangle]
pub extern "C" fn forced_exports(fe: ForcedExports) {
println!("{:?}", fe);
}
//TODO: make it private. Currently used for swapchain creation impl.
#[derive(Debug)]
pub struct RefCount(ptr::NonNull<AtomicUsize>);

View File

@@ -39,6 +39,7 @@ pub struct BufferDescriptor {
pub usage: BufferUsageFlags,
}
#[repr(C)]
pub enum BufferMapAsyncStatus {
Success,
Error,

View File

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

View File

@@ -1,18 +1,26 @@
use ipc_channel::ipc::IpcSender;
use crate::server::Server;
use ipc_channel::ipc;
use log::error;
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use wgn;
use std::ptr;
mod server;
use wgpu_native as wgn;
#[derive(Serialize, Deserialize)]
pub enum InstanceMessage {
enum InstanceMessage {
InstanceGetAdapter(wgn::InstanceId, wgn::AdapterDescriptor, wgn::AdapterId),
AdapterCreateDevice(wgn::AdapterId, wgn::DeviceDescriptor, wgn::DeviceId),
Terminate,
}
/// A message on the timeline of devices, queues, and resources.
#[derive(Serialize, Deserialize)]
pub enum GlobalMessage {
enum GlobalMessage {
Instance(InstanceMessage),
//Device(DeviceMessage),
//Queue(QueueMessage),
@@ -21,34 +29,78 @@ pub enum GlobalMessage {
}
#[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 {
fn new(
channel: ipc::IpcSender<GlobalMessage>,
instance_id: wgn::InstanceId,
) -> Self {
Client {
channel,
instance_id,
identity: Mutex::new(IdentityHub::default()),
}
}
}
#[repr(C)]
pub struct Infrastructure {
pub client: *mut Client,
pub server: *mut Server,
pub error: *const u8,
}
#[no_mangle]
pub extern "C" fn wgpu_initialize() -> Infrastructure {
match ipc::channel() {
Ok((sender, receiver)) => {
let instance_id = wgn::IdentityManager::default().alloc(); // TODO: static
let client = Client::new(sender, instance_id);
let server = Server::new(receiver, instance_id);
Infrastructure {
client: Box::into_raw(Box::new(client)),
server: Box::into_raw(Box::new(server)),
error: ptr::null(),
}
}
Err(e) => {
error!("WGPU initialize failed: {:?}", e);
Infrastructure {
client: ptr::null_mut(),
server: ptr::null_mut(),
error: ptr::null(), //TODO
}
}
}
}
#[no_mangle]
pub extern "C" fn wgpu_terminate(client: *mut Client) {
let client = unsafe {
Box::from_raw(client)
};
let _ = client.channel.send(GlobalMessage::Instance(InstanceMessage::Terminate));
}
#[no_mangle]
pub extern "C" fn wgpu_instance_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,
));

View File

@@ -1,25 +1,29 @@
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>, instance_id: wgn::InstanceId) -> Self {
let instance = wgn::create_instance();
wgn::HUB.instances.register(instance_id, instance);
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::InstanceGetAdapter(instance_id, ref desc, id) => {
@@ -30,6 +34,20 @@ pub fn process(message: GlobalMessage) {
let device = wgn::adapter_create_device(adapter_id, desc);
wgn::HUB.devices.register(id, device);
}
InstanceMessage::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,5 +1,5 @@
extern crate arrayvec;
extern crate wgpu_native as wgn;
extern crate wgn;
use arrayvec::ArrayVec;
@@ -839,7 +839,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) {