diff --git a/Cargo.lock b/Cargo.lock index 42272bac2..3e156bc1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,6 +206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "examples" version = "0.1.0" dependencies = [ + "wgpu 0.1.0", "wgpu-native 0.1.0", ] @@ -908,6 +909,13 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wgpu" +version = "0.1.0" +dependencies = [ + "wgpu-native 0.1.0", +] + [[package]] name = "wgpu-bindings" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b54bc44fd..1847568b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,6 @@ members = [ "wgpu-native", "wgpu-bindings", + "wgpu-rs", "examples", ] diff --git a/README.md b/README.md index 920ef49ec..ea2c12626 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # WebGPU -[![Build Status](https://travis-ci.org/gfx-rs/wgpu-native.svg)](https://travis-ci.org/gfx-rs/wgpu-native) -[![Gitter](https://badges.gitter.im/gfx-rs/gfx.svg)](https://gitter.im/gfx-rs/gfx) +[![Build Status](https://travis-ci.org/gfx-rs/wgpu.svg)](https://travis-ci.org/gfx-rs/wgpu) +[![Gitter](https://badges.gitter.im/gfx-rs/webgpu.svg)](https://gitter.im/gfx-rs/webgpu) 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 [satellite](https://github.com/gfx-rs/gfx-memory) libraries. The corresponding WebIDL specification can be found at [gpuweb project](https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl). + +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 diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e6b9f6d4d..4d4a5bf8c 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -14,9 +14,10 @@ path = "hello_triangle_rust/main.rs" [features] default = [] remote = ["wgpu-native/remote"] -metal = ["wgpu-native/metal"] -dx12 = ["wgpu-native/dx12"] -vulkan = ["wgpu-native/vulkan"] +metal = ["wgpu-native/gfx-backend-metal"] +dx12 = ["wgpu-native/gfx-backend-dx12"] +vulkan = ["wgpu-native/gfx-backend-vulkan"] [dependencies] wgpu-native = { path = "../wgpu-native" } +wgpu = { path = "../wgpu-rs" } diff --git a/examples/hello_triangle_rust/main.rs b/examples/hello_triangle_rust/main.rs index 313e68029..c6d078691 100644 --- a/examples/hello_triangle_rust/main.rs +++ b/examples/hello_triangle_rust/main.rs @@ -1,40 +1,20 @@ -extern crate wgpu_native; -use wgpu_native::*; - +extern crate wgpu; fn main() { - let instance = wgpu_create_instance(); - let adapter = wgpu_instance_get_adapter( - instance, - AdapterDescriptor { - power_preference: PowerPreference::LowPower, + let instance = wgpu::Instance::new(); + let adapter = instance.get_adapter( + wgpu::AdapterDescriptor { + power_preference: wgpu::PowerPreference::LowPower, }, ); - let device = wgpu_adapter_create_device( - adapter, - DeviceDescriptor { - extensions: Extensions { + let device = adapter.create_device( + wgpu::DeviceDescriptor { + extensions: wgpu::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 _vs = device.create_shader_module(vs_bytes); 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(), - }, - }, - ); + let _fs = device.create_shader_module(fs_bytes); } diff --git a/wgpu-native/Cargo.toml b/wgpu-native/Cargo.toml index 1ddbec910..cfdc410f6 100644 --- a/wgpu-native/Cargo.toml +++ b/wgpu-native/Cargo.toml @@ -12,9 +12,6 @@ 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" diff --git a/wgpu-rs/Cargo.toml b/wgpu-rs/Cargo.toml new file mode 100644 index 000000000..4fb139f38 --- /dev/null +++ b/wgpu-rs/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "wgpu" +version = "0.1.0" +authors = [ + "Dzmitry Malyshau ", + "Joshua Groves ", +] + +[lib] + +[features] +default = [] +metal = ["wgpu-native/gfx-backend-metal"] +dx12 = ["wgpu-native/gfx-backend-dx12"] +vulkan = ["wgpu-native/gfx-backend-vulkan"] + +[dependencies] +wgpu-native = { path = "../wgpu-native" } diff --git a/wgpu-rs/src/lib.rs b/wgpu-rs/src/lib.rs new file mode 100644 index 000000000..e8305c6bf --- /dev/null +++ b/wgpu-rs/src/lib.rs @@ -0,0 +1,61 @@ +extern crate wgpu_native as wgn; + +pub use wgn::{ + Color, Origin3d, Extent3d, + AdapterDescriptor, Extensions, DeviceDescriptor, PowerPreference, + ShaderModuleDescriptor, +}; + + +pub struct Instance { + id: wgn::InstanceId, +} + +pub struct Adapter { + id: wgn::AdapterId, +} + +pub struct Device { + id: wgn::DeviceId, +} + +pub struct ShaderModule { + id: wgn::ShaderModuleId, +} + + +impl Instance { + pub fn new() -> Self { + Instance { + id: wgn::wgpu_create_instance(), + } + } + + pub fn get_adapter(&self, desc: AdapterDescriptor) -> Adapter { + Adapter { + id: wgn::wgpu_instance_get_adapter(self.id, desc), + } + } +} + +impl Adapter { + pub fn create_device(&self, desc: DeviceDescriptor) -> Device { + Device { + id: wgn::wgpu_adapter_create_device(self.id, desc), + } + } +} + +impl Device { + pub fn create_shader_module(&self, spv: &[u8]) -> ShaderModule { + let desc = wgn::ShaderModuleDescriptor{ + code: wgn::ByteArray { + bytes: spv.as_ptr(), + length: spv.len(), + }, + }; + ShaderModule { + id: wgn::wgpu_device_create_shader_module(self.id, desc), + } + } +}