Skip to content

Commit dd73675

Browse files
bors[bot]kvark
andcommitted
Merge #65
65: First bits of wgpu-remote r=grovesNL a=kvark Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com> Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
2 parents 1504542 + ce08429 commit dd73675

File tree

24 files changed

+585
-160
lines changed

24 files changed

+585
-160
lines changed

Cargo.lock

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"wgpu-native",
44
"wgpu-bindings",
5+
"wgpu-remote",
56
"wgpu-rs",
67
"examples",
78
"gfx-examples",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs)
5353
lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
5454
cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST)
5555

56-
wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
56+
wgpu-bindings/*.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
5757
cargo +nightly-2018-12-27 run --manifest-path wgpu-bindings/Cargo.toml
5858

5959
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)

gfx-examples/src/framework.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use log::info;
22

33

4+
#[allow(dead_code)]
45
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
56
use std::mem::size_of;
67
use std::slice::from_raw_parts;

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
newline_style = "Native"
2+
spaces_around_ranges = true

wgpu-bindings/src/main.rs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,51 @@ extern crate cbindgen;
22

33
use std::path::PathBuf;
44

5-
const HEADER: &str = "
6-
#ifdef WGPU_REMOTE
7-
typedef uint32_t WGPUId;
8-
#else
9-
typedef void *WGPUId;
10-
#endif
11-
";
5+
struct Binding<'a> {
6+
library: &'a str,
7+
features: &'a [&'a str],
8+
output: &'a str,
9+
}
10+
11+
const BINDINGS: [Binding; 2] = [
12+
Binding {
13+
library: "wgpu-native",
14+
features: &["local"],
15+
output: "wgpu.h",
16+
},
17+
Binding {
18+
library: "wgpu-remote",
19+
features: &[],
20+
output: "wgpu-remote.h",
21+
},
22+
];
1223

1324
fn main() {
1425
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
15-
let source_dir = crate_dir.parent().unwrap().join("wgpu-native");
26+
let parent = crate_dir.parent().unwrap();
1627

17-
let config = cbindgen::Config {
18-
header: Some(String::from(HEADER.trim())),
19-
enumeration: cbindgen::EnumConfig {
20-
prefix_with_name: true,
21-
..Default::default()
22-
},
23-
export: cbindgen::ExportConfig {
24-
prefix: Some(String::from("WGPU")),
25-
exclude: vec![
26-
// We manually define `Id` is within the header, so exclude it here
27-
String::from("Id"),
28-
],
28+
for bind in &BINDINGS {
29+
let config = cbindgen::Config {
30+
enumeration: cbindgen::EnumConfig {
31+
prefix_with_name: true,
32+
..Default::default()
33+
},
34+
export: cbindgen::ExportConfig {
35+
prefix: Some(String::from("WGPU")),
36+
..Default::default()
37+
},
38+
language: cbindgen::Language::C,
2939
..Default::default()
30-
},
31-
language: cbindgen::Language::C,
32-
..Default::default()
33-
};
40+
};
3441

35-
cbindgen::Builder::new()
36-
.with_crate(source_dir)
37-
.with_config(config)
38-
.with_parse_expand(&["wgpu-native"])
39-
.with_parse_expand_features(&["local"])
40-
.generate()
41-
.unwrap()
42-
.write_to_file(crate_dir.join("wgpu.h"));
42+
println!("Generating {}...", bind.output);
43+
cbindgen::Builder::new()
44+
.with_crate(parent.join(bind.library))
45+
.with_config(config)
46+
.with_parse_expand(&[bind.library])
47+
.with_parse_expand_features(bind.features)
48+
.generate()
49+
.unwrap()
50+
.write_to_file(crate_dir.join(bind.output));
51+
}
4352
}

wgpu-bindings/wgpu-remote.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct WGPUClient WGPUClient;
7+
8+
WGPUDeviceId wgpu_adapter_create_device(const WGPUClient *client,
9+
WGPUAdapterId adapter_id,
10+
const WGPUDeviceDescriptor *desc);
11+
12+
WGPUAdapterId wgpu_instance_get_adapter(const WGPUClient *client,
13+
WGPUInstanceId instance_id,
14+
const WGPUAdapterDescriptor *desc);

wgpu-bindings/wgpu.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#ifdef WGPU_REMOTE
2-
typedef uint32_t WGPUId;
3-
#else
4-
typedef void *WGPUId;
5-
#endif
6-
71
#include <stdarg.h>
82
#include <stdbool.h>
93
#include <stdint.h>
@@ -138,7 +132,8 @@ typedef enum {
138132
WGPUTextureFormat_R8g8b8a8Unorm = 0,
139133
WGPUTextureFormat_R8g8b8a8Uint = 1,
140134
WGPUTextureFormat_B8g8r8a8Unorm = 2,
141-
WGPUTextureFormat_D32FloatS8Uint = 3,
135+
WGPUTextureFormat_D32Float = 3,
136+
WGPUTextureFormat_D32FloatS8Uint = 4,
142137
} WGPUTextureFormat;
143138

144139
typedef enum {
@@ -155,8 +150,13 @@ typedef enum {
155150
WGPUVertexFormat_FloatR32G32B32 = 1,
156151
WGPUVertexFormat_FloatR32G32 = 2,
157152
WGPUVertexFormat_FloatR32 = 3,
153+
WGPUVertexFormat_IntR8G8B8A8 = 4,
158154
} WGPUVertexFormat;
159155

156+
typedef struct WGPUBufferMapAsyncStatus WGPUBufferMapAsyncStatus;
157+
158+
typedef struct WGPUId WGPUId;
159+
160160
typedef WGPUId WGPUDeviceId;
161161

162162
typedef WGPUId WGPUAdapterId;
@@ -171,6 +171,10 @@ typedef struct {
171171

172172
typedef WGPUId WGPUBufferId;
173173

174+
typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, const uint8_t *data, uint8_t *userdata);
175+
176+
typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status, uint8_t *data, uint8_t *userdata);
177+
174178
typedef WGPUId WGPUCommandBufferId;
175179

176180
typedef struct {
@@ -555,11 +559,25 @@ WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDevi
555559

556560
void wgpu_buffer_destroy(WGPUBufferId buffer_id);
557561

562+
void wgpu_buffer_map_read_async(WGPUBufferId buffer_id,
563+
uint32_t start,
564+
uint32_t size,
565+
WGPUBufferMapReadCallback callback,
566+
uint8_t *userdata);
567+
568+
void wgpu_buffer_map_write_async(WGPUBufferId buffer_id,
569+
uint32_t start,
570+
uint32_t size,
571+
WGPUBufferMapWriteCallback callback,
572+
uint8_t *userdata);
573+
558574
void wgpu_buffer_set_sub_data(WGPUBufferId buffer_id,
559575
uint32_t start,
560576
uint32_t count,
561577
const uint8_t *data);
562578

579+
void wgpu_buffer_unmap(WGPUBufferId buffer_id);
580+
563581
void wgpu_command_buffer_copy_buffer_to_buffer(WGPUCommandBufferId command_buffer_id,
564582
WGPUBufferId src,
565583
uint32_t src_offset,
@@ -632,6 +650,8 @@ WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id,
632650

633651
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc);
634652

653+
void wgpu_device_destroy(WGPUBufferId device_id);
654+
635655
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
636656

637657
WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id,

wgpu-native/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ crate-type = ["lib", "cdylib", "staticlib"]
1818
[features]
1919
default = []
2020
local = ["winit", "gfx-backend-empty/winit"]
21+
remote = ["serde"]
2122
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
2223

2324
[dependencies]
25+
arrayvec = "0.4"
2426
bitflags = "1.0"
2527
lazy_static = "1.1.0"
2628
log = "0.4"
@@ -32,4 +34,6 @@ gfx-backend-dx11 = { version = "0.1.0", optional = true }
3234
gfx-backend-dx12 = { version = "0.1.0", optional = true }
3335
gfx-backend-metal = { version = "0.1.0", optional = true }
3436
#rendy-memory = { git = "https://github.com/rustgd/rendy", rev = "ce7dd7f", features = ["gfx-hal"] }
37+
serde = { version = "1.0", features = ["serde_derive"], optional = true }
38+
vec_map = "0.8"
3539
winit = { version = "0.18", optional = true }

wgpu-native/src/binding_model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::track::TrackerSet;
22
use crate::{
3-
LifeGuard, WeaklyStored,
3+
LifeGuard,
44
BindGroupLayoutId, BufferId, SamplerId, TextureViewId,
55
};
66

@@ -50,7 +50,7 @@ pub struct PipelineLayoutDescriptor {
5050

5151
pub struct PipelineLayout<B: hal::Backend> {
5252
pub(crate) raw: B::PipelineLayout,
53-
pub(crate) bind_group_layout_ids: Vec<WeaklyStored<BindGroupLayoutId>>,
53+
pub(crate) bind_group_layout_ids: Vec<BindGroupLayoutId>,
5454
}
5555

5656
#[repr(C)]
@@ -82,7 +82,7 @@ pub struct BindGroupDescriptor {
8282

8383
pub struct BindGroup<B: hal::Backend> {
8484
pub(crate) raw: B::DescriptorSet,
85-
pub(crate) layout_id: WeaklyStored<BindGroupLayoutId>,
85+
pub(crate) layout_id: BindGroupLayoutId,
8686
pub(crate) life_guard: LifeGuard,
8787
pub(crate) used: TrackerSet,
8888
}

0 commit comments

Comments
 (0)