Skip to content

Commit f1d459c

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 + df3db1c commit f1d459c

27 files changed

+660
-561
lines changed

Cargo.lock

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

wgpu-core/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ serde = { version = "1.0", features = ["serde_derive"], optional = true }
3636
smallvec = "1.0"
3737
vec_map = "0.8"
3838

39+
[dependencies.wgt]
40+
path = "../wgpu-types"
41+
package = "wgpu-types"
42+
version = "0.1"
43+
3944
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
4045
gfx-backend-metal = { version = "0.4" }
4146
gfx-backend-vulkan = { version = "0.4", optional = true }

wgpu-core/src/binding_model.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,21 @@
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")]
2019
use serde::{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)]
3824
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -50,9 +36,9 @@ pub enum BindingType {
5036
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
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,7 +68,7 @@ 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)]

wgpu-core/src/command/compute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::{
1212
hub::{GfxBackend, Global, Token},
1313
id,
1414
resource::BufferUsage,
15-
BufferAddress,
1615
DynamicOffset,
1716
};
1817

18+
use wgt::BufferAddress;
1919
use hal::command::CommandBuffer as _;
2020
use peek_poke::{Peek, PeekCopy, Poke};
2121

@@ -222,10 +222,10 @@ pub mod compute_ffi {
222222
};
223223
use crate::{
224224
id,
225-
BufferAddress,
226225
DynamicOffset,
227226
RawString,
228227
};
228+
use wgt::BufferAddress;
229229
use std::{convert::TryInto, slice};
230230

231231
/// # Safety

wgpu-core/src/command/render.rs

Lines changed: 3 additions & 3 deletions
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},
23+
pipeline::PipelineFlags,
2424
resource::{BufferUsage, TextureUsage, TextureViewInner},
2525
track::TrackerSet,
26-
BufferAddress,
2726
Color,
2827
DynamicOffset,
2928
Stored,
3029
};
3130

31+
use wgt::{BufferAddress, 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::{
88
hub::{GfxBackend, Global, Token},
99
id::{BufferId, CommandEncoderId, TextureId},
1010
resource::{BufferUsage, TextureUsage},
11-
BufferAddress,
1211
Extent3d,
1312
Origin3d,
1413
};
1514

15+
use wgt::BufferAddress;
1616
use hal::command::CommandBuffer as _;
1717

1818
use std::iter;

wgpu-core/src/conv.rs

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use crate::{binding_model, command, pipeline, resource, Color, Extent3d, Features, Origin3d};
5+
use crate::{binding_model, command, resource, Color, Extent3d, Features, Origin3d};
6+
use wgt::{BlendDescriptor, BlendFactor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat, PrimitiveTopology, StencilOperation, StencilStateFaceDescriptor, TextureFormat, RasterizationStateDescriptor, VertexFormat};
67

78
pub fn map_buffer_usage(
89
usage: resource::BufferUsage,
@@ -104,9 +105,9 @@ pub fn map_binding_type(
104105
}
105106

106107
pub fn map_shader_stage_flags(
107-
shader_stage_flags: binding_model::ShaderStage,
108+
shader_stage_flags: wgt::ShaderStage,
108109
) -> hal::pso::ShaderStageFlags {
109-
use crate::binding_model::ShaderStage as Ss;
110+
use wgt::ShaderStage as Ss;
110111
use hal::pso::ShaderStageFlags as H;
111112

112113
let mut value = H::empty();
@@ -139,9 +140,9 @@ pub fn map_extent(extent: Extent3d) -> hal::image::Extent {
139140
}
140141

141142
pub fn map_primitive_topology(
142-
primitive_topology: pipeline::PrimitiveTopology,
143+
primitive_topology: PrimitiveTopology,
143144
) -> hal::pso::Primitive {
144-
use crate::pipeline::PrimitiveTopology as Pt;
145+
use wgt::PrimitiveTopology as Pt;
145146
use hal::pso::Primitive as H;
146147
match primitive_topology {
147148
Pt::PointList => H::PointList,
@@ -153,11 +154,11 @@ pub fn map_primitive_topology(
153154
}
154155

155156
pub fn map_color_state_descriptor(
156-
desc: &pipeline::ColorStateDescriptor,
157+
desc: &ColorStateDescriptor,
157158
) -> hal::pso::ColorBlendDesc {
158159
let color_mask = desc.write_mask;
159-
let blend_state = if desc.color_blend != pipeline::BlendDescriptor::REPLACE
160-
|| desc.alpha_blend != pipeline::BlendDescriptor::REPLACE
160+
let blend_state = if desc.color_blend != BlendDescriptor::REPLACE
161+
|| desc.alpha_blend != BlendDescriptor::REPLACE
161162
{
162163
Some(hal::pso::BlendState {
163164
color: map_blend_descriptor(&desc.color_blend),
@@ -172,8 +173,8 @@ pub fn map_color_state_descriptor(
172173
}
173174
}
174175

175-
fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask {
176-
use crate::pipeline::ColorWrite as Cw;
176+
fn map_color_write_flags(flags: ColorWrite) -> hal::pso::ColorMask {
177+
use wgt::ColorWrite as Cw;
177178
use hal::pso::ColorMask as H;
178179

179180
let mut value = H::empty();
@@ -192,8 +193,8 @@ fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask {
192193
value
193194
}
194195

195-
fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::BlendOp {
196-
use crate::pipeline::BlendOperation as Bo;
196+
fn map_blend_descriptor(blend_desc: &BlendDescriptor) -> hal::pso::BlendOp {
197+
use wgt::BlendOperation as Bo;
197198
use hal::pso::BlendOp as H;
198199
match blend_desc.operation {
199200
Bo::Add => H::Add {
@@ -213,8 +214,8 @@ fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::Ble
213214
}
214215
}
215216

216-
fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor {
217-
use crate::pipeline::BlendFactor as Bf;
217+
fn map_blend_factor(blend_factor: BlendFactor) -> hal::pso::Factor {
218+
use wgt::BlendFactor as Bf;
218219
use hal::pso::Factor as H;
219220
match blend_factor {
220221
Bf::Zero => H::Zero,
@@ -234,11 +235,11 @@ fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor {
234235
}
235236

236237
pub fn map_depth_stencil_state_descriptor(
237-
desc: &pipeline::DepthStencilStateDescriptor,
238+
desc: &DepthStencilStateDescriptor,
238239
) -> hal::pso::DepthStencilDesc {
239240
hal::pso::DepthStencilDesc {
240241
depth: if desc.depth_write_enabled
241-
|| desc.depth_compare != resource::CompareFunction::Always
242+
|| desc.depth_compare != CompareFunction::Always
242243
{
243244
Some(hal::pso::DepthTest {
244245
fun: map_compare_function(desc.depth_compare),
@@ -250,8 +251,8 @@ pub fn map_depth_stencil_state_descriptor(
250251
depth_bounds: false, // TODO
251252
stencil: if desc.stencil_read_mask != !0
252253
|| desc.stencil_write_mask != !0
253-
|| desc.stencil_front != pipeline::StencilStateFaceDescriptor::IGNORE
254-
|| desc.stencil_back != pipeline::StencilStateFaceDescriptor::IGNORE
254+
|| desc.stencil_front != StencilStateFaceDescriptor::IGNORE
255+
|| desc.stencil_back != StencilStateFaceDescriptor::IGNORE
255256
{
256257
Some(hal::pso::StencilTest {
257258
faces: hal::pso::Sided {
@@ -273,7 +274,7 @@ pub fn map_depth_stencil_state_descriptor(
273274
}
274275

275276
fn map_stencil_face(
276-
stencil_state_face_desc: &pipeline::StencilStateFaceDescriptor,
277+
stencil_state_face_desc: &StencilStateFaceDescriptor,
277278
) -> hal::pso::StencilFace {
278279
hal::pso::StencilFace {
279280
fun: map_compare_function(stencil_state_face_desc.compare),
@@ -283,8 +284,8 @@ fn map_stencil_face(
283284
}
284285
}
285286

286-
pub fn map_compare_function(compare_function: resource::CompareFunction) -> hal::pso::Comparison {
287-
use crate::resource::CompareFunction as Cf;
287+
pub fn map_compare_function(compare_function: CompareFunction) -> hal::pso::Comparison {
288+
use wgt::CompareFunction as Cf;
288289
use hal::pso::Comparison as H;
289290
match compare_function {
290291
Cf::Never => H::Never,
@@ -298,8 +299,8 @@ pub fn map_compare_function(compare_function: resource::CompareFunction) -> hal:
298299
}
299300
}
300301

301-
fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal::pso::StencilOp {
302-
use crate::pipeline::StencilOperation as So;
302+
fn map_stencil_operation(stencil_operation: StencilOperation) -> hal::pso::StencilOp {
303+
use wgt::StencilOperation as So;
303304
use hal::pso::StencilOp as H;
304305
match stencil_operation {
305306
So::Keep => H::Keep,
@@ -314,10 +315,10 @@ fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal::
314315
}
315316

316317
pub(crate) fn map_texture_format(
317-
texture_format: resource::TextureFormat,
318+
texture_format: TextureFormat,
318319
features: Features,
319320
) -> hal::format::Format {
320-
use crate::resource::TextureFormat as Tf;
321+
use wgt::TextureFormat as Tf;
321322
use hal::format::Format as H;
322323
match texture_format {
323324
// Normal 8 bit formats
@@ -393,8 +394,8 @@ pub(crate) fn map_texture_format(
393394
}
394395
}
395396

396-
pub fn map_vertex_format(vertex_format: pipeline::VertexFormat) -> hal::format::Format {
397-
use crate::pipeline::VertexFormat as Vf;
397+
pub fn map_vertex_format(vertex_format: VertexFormat) -> hal::format::Format {
398+
use wgt::VertexFormat as Vf;
398399
use hal::format::Format as H;
399400
match vertex_format {
400401
Vf::Uchar2 => H::Rg8Uint,
@@ -482,9 +483,9 @@ pub fn map_texture_dimension_size(
482483
}
483484

484485
pub fn map_texture_view_dimension(
485-
dimension: resource::TextureViewDimension,
486+
dimension: wgt::TextureViewDimension,
486487
) -> hal::image::ViewKind {
487-
use crate::resource::TextureViewDimension::*;
488+
use wgt::TextureViewDimension::*;
488489
use hal::image::ViewKind as H;
489490
match dimension {
490491
D1 => H::D1,
@@ -628,19 +629,19 @@ pub fn map_wrap(address: resource::AddressMode) -> hal::image::WrapMode {
628629
}
629630

630631
pub fn map_rasterization_state_descriptor(
631-
desc: &pipeline::RasterizationStateDescriptor,
632+
desc: &RasterizationStateDescriptor,
632633
) -> hal::pso::Rasterizer {
633634
hal::pso::Rasterizer {
634635
depth_clamping: false,
635636
polygon_mode: hal::pso::PolygonMode::Fill,
636637
cull_face: match desc.cull_mode {
637-
pipeline::CullMode::None => hal::pso::Face::empty(),
638-
pipeline::CullMode::Front => hal::pso::Face::FRONT,
639-
pipeline::CullMode::Back => hal::pso::Face::BACK,
638+
CullMode::None => hal::pso::Face::empty(),
639+
CullMode::Front => hal::pso::Face::FRONT,
640+
CullMode::Back => hal::pso::Face::BACK,
640641
},
641642
front_face: match desc.front_face {
642-
pipeline::FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
643-
pipeline::FrontFace::Cw => hal::pso::FrontFace::Clockwise,
643+
FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
644+
FrontFace::Cw => hal::pso::FrontFace::Clockwise,
644645
},
645646
depth_bias: if desc.depth_bias != 0
646647
|| desc.depth_bias_slope_scale != 0.0
@@ -658,9 +659,9 @@ pub fn map_rasterization_state_descriptor(
658659
}
659660
}
660661

661-
pub fn map_index_format(index_format: pipeline::IndexFormat) -> hal::IndexType {
662+
pub fn map_index_format(index_format: IndexFormat) -> hal::IndexType {
662663
match index_format {
663-
pipeline::IndexFormat::Uint16 => hal::IndexType::U16,
664-
pipeline::IndexFormat::Uint32 => hal::IndexType::U32,
664+
IndexFormat::Uint16 => hal::IndexType::U16,
665+
IndexFormat::Uint32 => hal::IndexType::U32,
665666
}
666667
}

0 commit comments

Comments
 (0)