Skip to content

Commit a74de20

Browse files
bors[bot]grovesNL
andauthored
Merge #514
514: Move some types into shared wgpu-types crate r=kvark a=grovesNL As we discussed a while ago, we need to be able to share some types between wgpu-core/wgpu-native/wgpu-remote/wgpu-rs. The problem is that we want to avoid a dependency on wgpu-core and wgpu-native when building [wgpu-rs for the wasm32-unknown-unknown target](gfx-rs/wgpu-rs#101). We can avoid this by moving all shared types into a separate crate which is exposed on all targets. Let me know if we should use some other approach or organize the types somehow. This isn't complete yet, but it might be easier to integrate this over several PRs instead of diverging my branch too far. Co-authored-by: Joshua Groves <[email protected]>
2 parents 79e9ab7 + 24caf76 commit a74de20

28 files changed

+753
-646
lines changed

Cargo.lock

+11
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
@@ -3,4 +3,5 @@ members = [
33
"wgpu-core",
44
"wgpu-native",
55
"wgpu-remote",
6+
"wgpu-types",
67
]

wgpu-core/Cargo.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ license = "MPL-2.0"
1717
[features]
1818
default = []
1919
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
20+
serde = ["wgt/serde", "serde_crate"]
2021
#NOTE: glutin feature is not stable, use at your own risk
2122
#glutin = ["gfx-backend-gl/glutin"]
2223

@@ -32,10 +33,20 @@ parking_lot = "0.9"
3233
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075" }
3334
rendy-memory = "0.5"
3435
rendy-descriptor = "0.5"
35-
serde = { version = "1.0", features = ["serde_derive"], optional = true }
3636
smallvec = "1.0"
3737
vec_map = "0.8"
3838

39+
[dependencies.serde_crate]
40+
package = "serde"
41+
version = "1.0"
42+
features = ["serde_derive"]
43+
optional = true
44+
45+
[dependencies.wgt]
46+
path = "../wgpu-types"
47+
package = "wgpu-types"
48+
version = "0.1"
49+
3950
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
4051
gfx-backend-metal = { version = "0.4" }
4152
gfx-backend-vulkan = { version = "0.4", optional = true }

wgpu-core/src/binding_model.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,24 @@
44

55
use crate::{
66
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId},
7-
resource::TextureViewDimension,
87
track::{DUMMY_SELECTOR, TrackerSet},
9-
BufferAddress,
108
FastHashMap,
119
LifeGuard,
1210
RefCount,
1311
Stored,
1412
};
1513

14+
use wgt::BufferAddress;
1615
use arrayvec::ArrayVec;
1716
use rendy_descriptor::{DescriptorRanges, DescriptorSet};
1817

1918
#[cfg(feature = "serde")]
20-
use serde::{Deserialize, Serialize};
19+
use serde_crate::{Deserialize, Serialize};
2120
use std::borrow::Borrow;
2221

23-
pub const MAX_BIND_GROUPS: usize = 4;
24-
25-
bitflags::bitflags! {
26-
#[repr(transparent)]
27-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28-
pub struct ShaderStage: u32 {
29-
const NONE = 0;
30-
const VERTEX = 1;
31-
const FRAGMENT = 2;
32-
const COMPUTE = 4;
33-
}
34-
}
35-
3622
#[repr(C)]
3723
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
38-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
3925
pub enum BindingType {
4026
UniformBuffer = 0,
4127
StorageBuffer = 1,
@@ -47,12 +33,12 @@ pub enum BindingType {
4733

4834
#[repr(C)]
4935
#[derive(Clone, Debug, Hash, PartialEq)]
50-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
36+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
5137
pub struct BindGroupLayoutBinding {
5238
pub binding: u32,
53-
pub visibility: ShaderStage,
39+
pub visibility: wgt::ShaderStage,
5440
pub ty: BindingType,
55-
pub texture_dimension: TextureViewDimension,
41+
pub texture_dimension: wgt::TextureViewDimension,
5642
pub multisampled: bool,
5743
pub dynamic: bool,
5844
}
@@ -82,12 +68,12 @@ pub struct PipelineLayoutDescriptor {
8268
#[derive(Debug)]
8369
pub struct PipelineLayout<B: hal::Backend> {
8470
pub(crate) raw: B::PipelineLayout,
85-
pub(crate) bind_group_layout_ids: ArrayVec<[BindGroupLayoutId; MAX_BIND_GROUPS]>,
71+
pub(crate) bind_group_layout_ids: ArrayVec<[BindGroupLayoutId; wgt::MAX_BIND_GROUPS]>,
8672
}
8773

8874
#[repr(C)]
8975
#[derive(Debug)]
90-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
76+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
9177
pub struct BufferBinding {
9278
pub buffer: BufferId,
9379
pub offset: BufferAddress,
@@ -96,7 +82,7 @@ pub struct BufferBinding {
9682

9783
#[repr(C)]
9884
#[derive(Debug)]
99-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
85+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
10086
pub enum BindingResource {
10187
Buffer(BufferBinding),
10288
Sampler(SamplerId),
@@ -105,7 +91,7 @@ pub enum BindingResource {
10591

10692
#[repr(C)]
10793
#[derive(Debug)]
108-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
94+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
10995
pub struct BindGroupBinding {
11096
pub binding: u32,
11197
pub resource: BindingResource,

wgpu-core/src/command/compute.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ use crate::{
1111
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
1212
hub::{GfxBackend, Global, Token},
1313
id,
14-
resource::BufferUsage,
15-
BufferAddress,
1614
DynamicOffset,
1715
};
1816

17+
use wgt::{BufferAddress, BufferUsage};
1918
use hal::command::CommandBuffer as _;
2019
use peek_poke::{Peek, PeekCopy, Poke};
2120

@@ -222,10 +221,10 @@ pub mod compute_ffi {
222221
};
223222
use crate::{
224223
id,
225-
BufferAddress,
226224
DynamicOffset,
227225
RawString,
228226
};
227+
use wgt::BufferAddress;
229228
use std::{convert::TryInto, slice};
230229

231230
/// # Safety

wgpu-core/src/command/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ use crate::{
2020
},
2121
hub::{GfxBackend, Global, Token},
2222
id,
23-
pipeline::{IndexFormat, InputStepMode, PipelineFlags},
24-
resource::{BufferUsage, TextureUsage, TextureViewInner},
23+
pipeline::PipelineFlags,
24+
resource::{TextureUsage, TextureViewInner},
2525
track::TrackerSet,
26-
BufferAddress,
2726
Color,
2827
DynamicOffset,
2928
Stored,
3029
};
3130

31+
use wgt::{BufferAddress, BufferUsage, IndexFormat, InputStepMode};
3232
use arrayvec::ArrayVec;
3333
use hal::command::CommandBuffer as _;
3434
use peek_poke::{Peek, PeekCopy, Poke};
@@ -1166,11 +1166,11 @@ pub mod render_ffi {
11661166
};
11671167
use crate::{
11681168
id,
1169-
BufferAddress,
11701169
Color,
11711170
DynamicOffset,
11721171
RawString,
11731172
};
1173+
use wgt::BufferAddress;
11741174
use std::{convert::TryInto, slice};
11751175

11761176
/// # Safety

wgpu-core/src/command/transfer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::{
77
device::{all_buffer_stages, all_image_stages},
88
hub::{GfxBackend, Global, Token},
99
id::{BufferId, CommandEncoderId, TextureId},
10-
resource::{BufferUsage, TextureUsage},
11-
BufferAddress,
10+
resource::TextureUsage,
1211
Extent3d,
1312
Origin3d,
1413
};
1514

15+
use wgt::{BufferAddress, BufferUsage};
1616
use hal::command::CommandBuffer as _;
1717

1818
use std::iter;

0 commit comments

Comments
 (0)