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](https://github.com/gfx-rs/wgpu-rs/issues/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 <josh@joshgroves.com>
This commit is contained in:
bors[bot]
2020-03-11 03:07:17 +00:00
committed by GitHub
28 changed files with 753 additions and 646 deletions

11
Cargo.lock generated
View File

@@ -710,6 +710,7 @@ dependencies = [
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wgpu-types 0.1.0",
]
[[package]]
@@ -723,6 +724,7 @@ dependencies = [
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-window-handle 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"wgpu-core 0.1.0",
"wgpu-types 0.1.0",
]
[[package]]
@@ -732,6 +734,15 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wgpu-core 0.1.0",
"wgpu-types 0.1.0",
]
[[package]]
name = "wgpu-types"
version = "0.1.0"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@@ -3,4 +3,5 @@ members = [
"wgpu-core",
"wgpu-native",
"wgpu-remote",
"wgpu-types",
]

View File

@@ -17,6 +17,7 @@ license = "MPL-2.0"
[features]
default = []
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
serde = ["wgt/serde", "serde_crate"]
#NOTE: glutin feature is not stable, use at your own risk
#glutin = ["gfx-backend-gl/glutin"]
@@ -32,10 +33,20 @@ parking_lot = "0.9"
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075" }
rendy-memory = "0.5"
rendy-descriptor = "0.5"
serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "1.0"
vec_map = "0.8"
[dependencies.serde_crate]
package = "serde"
version = "1.0"
features = ["serde_derive"]
optional = true
[dependencies.wgt]
path = "../wgpu-types"
package = "wgpu-types"
version = "0.1"
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.4" }
gfx-backend-vulkan = { version = "0.4", optional = true }

View File

@@ -4,38 +4,24 @@
use crate::{
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId},
resource::TextureViewDimension,
track::{DUMMY_SELECTOR, TrackerSet},
BufferAddress,
FastHashMap,
LifeGuard,
RefCount,
Stored,
};
use wgt::BufferAddress;
use arrayvec::ArrayVec;
use rendy_descriptor::{DescriptorRanges, DescriptorSet};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_crate::{Deserialize, Serialize};
use std::borrow::Borrow;
pub const MAX_BIND_GROUPS: usize = 4;
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ShaderStage: u32 {
const NONE = 0;
const VERTEX = 1;
const FRAGMENT = 2;
const COMPUTE = 4;
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub enum BindingType {
UniformBuffer = 0,
StorageBuffer = 1,
@@ -47,12 +33,12 @@ pub enum BindingType {
#[repr(C)]
#[derive(Clone, Debug, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct BindGroupLayoutBinding {
pub binding: u32,
pub visibility: ShaderStage,
pub visibility: wgt::ShaderStage,
pub ty: BindingType,
pub texture_dimension: TextureViewDimension,
pub texture_dimension: wgt::TextureViewDimension,
pub multisampled: bool,
pub dynamic: bool,
}
@@ -82,12 +68,12 @@ pub struct PipelineLayoutDescriptor {
#[derive(Debug)]
pub struct PipelineLayout<B: hal::Backend> {
pub(crate) raw: B::PipelineLayout,
pub(crate) bind_group_layout_ids: ArrayVec<[BindGroupLayoutId; MAX_BIND_GROUPS]>,
pub(crate) bind_group_layout_ids: ArrayVec<[BindGroupLayoutId; wgt::MAX_BIND_GROUPS]>,
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct BufferBinding {
pub buffer: BufferId,
pub offset: BufferAddress,
@@ -96,7 +82,7 @@ pub struct BufferBinding {
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub enum BindingResource {
Buffer(BufferBinding),
Sampler(SamplerId),
@@ -105,7 +91,7 @@ pub enum BindingResource {
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct BindGroupBinding {
pub binding: u32,
pub resource: BindingResource,

View File

@@ -11,11 +11,10 @@ use crate::{
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
hub::{GfxBackend, Global, Token},
id,
resource::BufferUsage,
BufferAddress,
DynamicOffset,
};
use wgt::{BufferAddress, BufferUsage};
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekCopy, Poke};
@@ -222,10 +221,10 @@ pub mod compute_ffi {
};
use crate::{
id,
BufferAddress,
DynamicOffset,
RawString,
};
use wgt::BufferAddress;
use std::{convert::TryInto, slice};
/// # Safety

View File

@@ -20,15 +20,15 @@ use crate::{
},
hub::{GfxBackend, Global, Token},
id,
pipeline::{IndexFormat, InputStepMode, PipelineFlags},
resource::{BufferUsage, TextureUsage, TextureViewInner},
pipeline::PipelineFlags,
resource::{TextureUsage, TextureViewInner},
track::TrackerSet,
BufferAddress,
Color,
DynamicOffset,
Stored,
};
use wgt::{BufferAddress, BufferUsage, IndexFormat, InputStepMode};
use arrayvec::ArrayVec;
use hal::command::CommandBuffer as _;
use peek_poke::{Peek, PeekCopy, Poke};
@@ -1166,11 +1166,11 @@ pub mod render_ffi {
};
use crate::{
id,
BufferAddress,
Color,
DynamicOffset,
RawString,
};
use wgt::BufferAddress;
use std::{convert::TryInto, slice};
/// # Safety

View File

@@ -7,12 +7,12 @@ use crate::{
device::{all_buffer_stages, all_image_stages},
hub::{GfxBackend, Global, Token},
id::{BufferId, CommandEncoderId, TextureId},
resource::{BufferUsage, TextureUsage},
BufferAddress,
resource::TextureUsage,
Extent3d,
Origin3d,
};
use wgt::{BufferAddress, BufferUsage};
use hal::command::CommandBuffer as _;
use std::iter;

View File

@@ -2,12 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use crate::{binding_model, command, pipeline, resource, Color, Extent3d, Features, Origin3d};
use crate::{binding_model, command, resource, Color, Extent3d, Features, Origin3d};
use wgt::{BlendDescriptor, BlendFactor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat, PrimitiveTopology, StencilOperation, StencilStateFaceDescriptor, TextureFormat, RasterizationStateDescriptor, VertexFormat};
pub fn map_buffer_usage(
usage: resource::BufferUsage,
usage: wgt::BufferUsage,
) -> (hal::buffer::Usage, hal::memory::Properties) {
use crate::resource::BufferUsage as W;
use wgt::BufferUsage as W;
use hal::buffer::Usage as U;
use hal::memory::Properties as P;
@@ -104,9 +105,9 @@ pub fn map_binding_type(
}
pub fn map_shader_stage_flags(
shader_stage_flags: binding_model::ShaderStage,
shader_stage_flags: wgt::ShaderStage,
) -> hal::pso::ShaderStageFlags {
use crate::binding_model::ShaderStage as Ss;
use wgt::ShaderStage as Ss;
use hal::pso::ShaderStageFlags as H;
let mut value = H::empty();
@@ -139,9 +140,9 @@ pub fn map_extent(extent: Extent3d) -> hal::image::Extent {
}
pub fn map_primitive_topology(
primitive_topology: pipeline::PrimitiveTopology,
primitive_topology: PrimitiveTopology,
) -> hal::pso::Primitive {
use crate::pipeline::PrimitiveTopology as Pt;
use wgt::PrimitiveTopology as Pt;
use hal::pso::Primitive as H;
match primitive_topology {
Pt::PointList => H::PointList,
@@ -153,11 +154,11 @@ pub fn map_primitive_topology(
}
pub fn map_color_state_descriptor(
desc: &pipeline::ColorStateDescriptor,
desc: &ColorStateDescriptor,
) -> hal::pso::ColorBlendDesc {
let color_mask = desc.write_mask;
let blend_state = if desc.color_blend != pipeline::BlendDescriptor::REPLACE
|| desc.alpha_blend != pipeline::BlendDescriptor::REPLACE
let blend_state = if desc.color_blend != BlendDescriptor::REPLACE
|| desc.alpha_blend != BlendDescriptor::REPLACE
{
Some(hal::pso::BlendState {
color: map_blend_descriptor(&desc.color_blend),
@@ -172,8 +173,8 @@ pub fn map_color_state_descriptor(
}
}
fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask {
use crate::pipeline::ColorWrite as Cw;
fn map_color_write_flags(flags: ColorWrite) -> hal::pso::ColorMask {
use wgt::ColorWrite as Cw;
use hal::pso::ColorMask as H;
let mut value = H::empty();
@@ -192,8 +193,8 @@ fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask {
value
}
fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::BlendOp {
use crate::pipeline::BlendOperation as Bo;
fn map_blend_descriptor(blend_desc: &BlendDescriptor) -> hal::pso::BlendOp {
use wgt::BlendOperation as Bo;
use hal::pso::BlendOp as H;
match blend_desc.operation {
Bo::Add => H::Add {
@@ -213,8 +214,8 @@ fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::Ble
}
}
fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor {
use crate::pipeline::BlendFactor as Bf;
fn map_blend_factor(blend_factor: BlendFactor) -> hal::pso::Factor {
use wgt::BlendFactor as Bf;
use hal::pso::Factor as H;
match blend_factor {
Bf::Zero => H::Zero,
@@ -234,11 +235,11 @@ fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor {
}
pub fn map_depth_stencil_state_descriptor(
desc: &pipeline::DepthStencilStateDescriptor,
desc: &DepthStencilStateDescriptor,
) -> hal::pso::DepthStencilDesc {
hal::pso::DepthStencilDesc {
depth: if desc.depth_write_enabled
|| desc.depth_compare != resource::CompareFunction::Always
|| desc.depth_compare != CompareFunction::Always
{
Some(hal::pso::DepthTest {
fun: map_compare_function(desc.depth_compare),
@@ -250,8 +251,8 @@ pub fn map_depth_stencil_state_descriptor(
depth_bounds: false, // TODO
stencil: if desc.stencil_read_mask != !0
|| desc.stencil_write_mask != !0
|| desc.stencil_front != pipeline::StencilStateFaceDescriptor::IGNORE
|| desc.stencil_back != pipeline::StencilStateFaceDescriptor::IGNORE
|| desc.stencil_front != StencilStateFaceDescriptor::IGNORE
|| desc.stencil_back != StencilStateFaceDescriptor::IGNORE
{
Some(hal::pso::StencilTest {
faces: hal::pso::Sided {
@@ -273,7 +274,7 @@ pub fn map_depth_stencil_state_descriptor(
}
fn map_stencil_face(
stencil_state_face_desc: &pipeline::StencilStateFaceDescriptor,
stencil_state_face_desc: &StencilStateFaceDescriptor,
) -> hal::pso::StencilFace {
hal::pso::StencilFace {
fun: map_compare_function(stencil_state_face_desc.compare),
@@ -283,8 +284,8 @@ fn map_stencil_face(
}
}
pub fn map_compare_function(compare_function: resource::CompareFunction) -> hal::pso::Comparison {
use crate::resource::CompareFunction as Cf;
pub fn map_compare_function(compare_function: CompareFunction) -> hal::pso::Comparison {
use wgt::CompareFunction as Cf;
use hal::pso::Comparison as H;
match compare_function {
Cf::Never => H::Never,
@@ -298,8 +299,8 @@ pub fn map_compare_function(compare_function: resource::CompareFunction) -> hal:
}
}
fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal::pso::StencilOp {
use crate::pipeline::StencilOperation as So;
fn map_stencil_operation(stencil_operation: StencilOperation) -> hal::pso::StencilOp {
use wgt::StencilOperation as So;
use hal::pso::StencilOp as H;
match stencil_operation {
So::Keep => H::Keep,
@@ -314,10 +315,10 @@ fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal::
}
pub(crate) fn map_texture_format(
texture_format: resource::TextureFormat,
texture_format: TextureFormat,
features: Features,
) -> hal::format::Format {
use crate::resource::TextureFormat as Tf;
use wgt::TextureFormat as Tf;
use hal::format::Format as H;
match texture_format {
// Normal 8 bit formats
@@ -393,8 +394,8 @@ pub(crate) fn map_texture_format(
}
}
pub fn map_vertex_format(vertex_format: pipeline::VertexFormat) -> hal::format::Format {
use crate::pipeline::VertexFormat as Vf;
pub fn map_vertex_format(vertex_format: VertexFormat) -> hal::format::Format {
use wgt::VertexFormat as Vf;
use hal::format::Format as H;
match vertex_format {
Vf::Uchar2 => H::Rg8Uint,
@@ -482,9 +483,9 @@ pub fn map_texture_dimension_size(
}
pub fn map_texture_view_dimension(
dimension: resource::TextureViewDimension,
dimension: wgt::TextureViewDimension,
) -> hal::image::ViewKind {
use crate::resource::TextureViewDimension::*;
use wgt::TextureViewDimension::*;
use hal::image::ViewKind as H;
match dimension {
D1 => H::D1,
@@ -496,8 +497,8 @@ pub fn map_texture_view_dimension(
}
}
pub fn map_buffer_state(usage: resource::BufferUsage) -> hal::buffer::State {
use crate::resource::BufferUsage as W;
pub fn map_buffer_state(usage: wgt::BufferUsage) -> hal::buffer::State {
use wgt::BufferUsage as W;
use hal::buffer::Access as A;
let mut access = A::empty();
@@ -628,19 +629,19 @@ pub fn map_wrap(address: resource::AddressMode) -> hal::image::WrapMode {
}
pub fn map_rasterization_state_descriptor(
desc: &pipeline::RasterizationStateDescriptor,
desc: &RasterizationStateDescriptor,
) -> hal::pso::Rasterizer {
hal::pso::Rasterizer {
depth_clamping: false,
polygon_mode: hal::pso::PolygonMode::Fill,
cull_face: match desc.cull_mode {
pipeline::CullMode::None => hal::pso::Face::empty(),
pipeline::CullMode::Front => hal::pso::Face::FRONT,
pipeline::CullMode::Back => hal::pso::Face::BACK,
CullMode::None => hal::pso::Face::empty(),
CullMode::Front => hal::pso::Face::FRONT,
CullMode::Back => hal::pso::Face::BACK,
},
front_face: match desc.front_face {
pipeline::FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
pipeline::FrontFace::Cw => hal::pso::FrontFace::Clockwise,
FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
FrontFace::Cw => hal::pso::FrontFace::Clockwise,
},
depth_bias: if desc.depth_bias != 0
|| desc.depth_bias_slope_scale != 0.0
@@ -658,9 +659,9 @@ pub fn map_rasterization_state_descriptor(
}
}
pub fn map_index_format(index_format: pipeline::IndexFormat) -> hal::IndexType {
pub fn map_index_format(index_format: IndexFormat) -> hal::IndexType {
match index_format {
pipeline::IndexFormat::Uint16 => hal::IndexType::U16,
pipeline::IndexFormat::Uint32 => hal::IndexType::U32,
IndexFormat::Uint16 => hal::IndexType::U16,
IndexFormat::Uint32 => hal::IndexType::U32,
}
}

View File

@@ -12,13 +12,13 @@ use crate::{
resource,
swap_chain,
track::{BufferState, TextureState, TrackerSet},
BufferAddress,
FastHashMap,
Features,
LifeGuard,
Stored,
};
use wgt::{BufferAddress, CompareFunction, InputStepMode, TextureFormat};
use arrayvec::ArrayVec;
use copyless::VecHelper as _;
use hal::{
@@ -105,7 +105,7 @@ impl RenderPassContext {
pub(crate) type RenderPassKey = AttachmentData<hal::pass::Attachment>;
pub(crate) type FramebufferKey = AttachmentData<id::TextureViewId>;
pub(crate) type RenderPassContext = AttachmentData<resource::TextureFormat>;
pub(crate) type RenderPassContext = AttachmentData<TextureFormat>;
type BufferMapResult = Result<*mut u8, hal::device::MapError>;
type BufferMapPendingCallback = (resource::BufferMapOperation, BufferMapResult);
@@ -300,14 +300,14 @@ impl<B: GfxBackend> Device<B> {
fn create_buffer(
&self,
self_id: id::DeviceId,
desc: &resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
) -> resource::Buffer<B> {
debug_assert_eq!(self_id.backend(), B::VARIANT);
let (usage, _memory_properties) = conv::map_buffer_usage(desc.usage);
let rendy_usage = {
use rendy_memory::MemoryUsageValue as Muv;
use resource::BufferUsage as Bu;
use wgt::BufferUsage as Bu;
if !desc.usage.intersects(Bu::MAP_READ | Bu::MAP_WRITE) {
Muv::Data
@@ -365,7 +365,7 @@ impl<B: GfxBackend> Device<B> {
// Ensure `D24Plus` textures cannot be copied
match desc.format {
resource::TextureFormat::Depth24Plus | resource::TextureFormat::Depth24PlusStencil8 => {
TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => {
assert!(!desc.usage.intersects(
resource::TextureUsage::COPY_SRC | resource::TextureUsage::COPY_DST
));
@@ -493,7 +493,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
pub fn device_create_buffer<B: GfxBackend>(
&self,
device_id: id::DeviceId,
desc: &resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
id_in: F::Input,
) -> id::BufferId {
let hub = B::hub(self);
@@ -514,7 +514,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
.init(
id,
ref_count,
BufferState::with_usage(resource::BufferUsage::empty()),
BufferState::with_usage(wgt::BufferUsage::empty()),
)
.unwrap();
id
@@ -523,13 +523,13 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
pub fn device_create_buffer_mapped<B: GfxBackend>(
&self,
device_id: id::DeviceId,
desc: &resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
id_in: F::Input,
) -> (id::BufferId, *mut u8) {
let hub = B::hub(self);
let mut token = Token::root();
let mut desc = desc.clone();
desc.usage |= resource::BufferUsage::MAP_WRITE;
desc.usage |= wgt::BufferUsage::MAP_WRITE;
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
@@ -550,7 +550,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
.buffers.init(
id,
ref_count,
BufferState::with_usage(resource::BufferUsage::MAP_WRITE),
BufferState::with_usage(wgt::BufferUsage::MAP_WRITE),
)
.unwrap();
@@ -571,7 +571,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
let (mut buffer_guard, _) = hub.buffers.write(&mut token);
let device = &device_guard[device_id];
let mut buffer = &mut buffer_guard[buffer_id];
assert!(buffer.usage.contains(resource::BufferUsage::MAP_WRITE));
assert!(buffer.usage.contains(wgt::BufferUsage::MAP_WRITE));
//assert!(buffer isn't used by the GPU);
match map_buffer(
@@ -606,7 +606,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
let (mut buffer_guard, _) = hub.buffers.write(&mut token);
let device = &device_guard[device_id];
let mut buffer = &mut buffer_guard[buffer_id];
assert!(buffer.usage.contains(resource::BufferUsage::MAP_READ));
assert!(buffer.usage.contains(wgt::BufferUsage::MAP_READ));
//assert!(buffer isn't used by the GPU);
match map_buffer(
@@ -825,7 +825,7 @@ impl<F: IdentityFilter<id::SamplerId>> Global<F> {
),
lod_bias: hal::image::Lod(0.0),
lod_range: hal::image::Lod(desc.lod_min_clamp) .. hal::image::Lod(desc.lod_max_clamp),
comparison: if desc.compare_function == resource::CompareFunction::Always {
comparison: if desc.compare_function == CompareFunction::Always {
None
} else {
Some(conv::map_compare_function(desc.compare_function))
@@ -1039,13 +1039,13 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
binding_model::BindingResource::Buffer(ref bb) => {
let (alignment, usage) = match decl.ty {
binding_model::BindingType::UniformBuffer => {
(BIND_BUFFER_ALIGNMENT, resource::BufferUsage::UNIFORM)
(BIND_BUFFER_ALIGNMENT, wgt::BufferUsage::UNIFORM)
}
binding_model::BindingType::StorageBuffer => {
(BIND_BUFFER_ALIGNMENT, resource::BufferUsage::STORAGE)
(BIND_BUFFER_ALIGNMENT, wgt::BufferUsage::STORAGE)
}
binding_model::BindingType::ReadonlyStorageBuffer => {
(BIND_BUFFER_ALIGNMENT, resource::BufferUsage::STORAGE_READ)
(BIND_BUFFER_ALIGNMENT, wgt::BufferUsage::STORAGE_READ)
}
binding_model::BindingType::Sampler
| binding_model::BindingType::SampledTexture
@@ -1527,8 +1527,8 @@ impl<F: IdentityFilter<id::RenderPipelineId>> Global<F> {
binding: i as u32,
stride: vb_state.stride as u32,
rate: match vb_state.step_mode {
pipeline::InputStepMode::Vertex => hal::pso::VertexInputRate::Vertex,
pipeline::InputStepMode::Instance => hal::pso::VertexInputRate::Instance(1),
InputStepMode::Vertex => hal::pso::VertexInputRate::Vertex,
InputStepMode::Instance => hal::pso::VertexInputRate::Instance(1),
},
});
let desc_atts =
@@ -1969,7 +1969,7 @@ impl<F> Global<F> {
pub fn buffer_map_async<B: GfxBackend>(
&self,
buffer_id: id::BufferId,
usage: resource::BufferUsage,
usage: wgt::BufferUsage,
range: std::ops::Range<BufferAddress>,
operation: resource::BufferMapOperation,
) {
@@ -1981,12 +1981,12 @@ impl<F> Global<F> {
let (mut buffer_guard, _) = hub.buffers.write(&mut token);
let buffer = &mut buffer_guard[buffer_id];
if usage.contains(resource::BufferUsage::MAP_READ) {
assert!(buffer.usage.contains(resource::BufferUsage::MAP_READ));
if usage.contains(wgt::BufferUsage::MAP_READ) {
assert!(buffer.usage.contains(wgt::BufferUsage::MAP_READ));
}
if usage.contains(resource::BufferUsage::MAP_WRITE) {
assert!(buffer.usage.contains(resource::BufferUsage::MAP_WRITE));
if usage.contains(wgt::BufferUsage::MAP_WRITE) {
assert!(buffer.usage.contains(wgt::BufferUsage::MAP_WRITE));
}
if buffer.pending_mapping.is_some() {

View File

@@ -29,11 +29,11 @@ use crate::{
pipeline::{ComputePipeline, RenderPipeline},
resource::{Buffer, Sampler, Texture, TextureView},
swap_chain::SwapChain,
Backend,
Epoch,
Index,
};
use wgt::Backend;
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use vec_map::VecMap;

View File

@@ -2,9 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use crate::{Backend, Epoch, Index};
use crate::{Epoch, Index};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_crate::{Deserialize, Serialize};
use wgt::Backend;
use std::{fmt, marker::PhantomData, mem};
const BACKEND_BITS: usize = 3;
@@ -12,7 +13,7 @@ const EPOCH_MASK: u32 = (1 << (32 - BACKEND_BITS)) - 1;
type Dummy = crate::backend::Empty;
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct Id<T>(u64, PhantomData<T>);
impl<T> Id<T> {

View File

@@ -4,16 +4,16 @@
use crate::{
backend,
binding_model::MAX_BIND_GROUPS,
device::{Device, BIND_BUFFER_ALIGNMENT},
hub::{GfxBackend, Global, IdentityFilter, Token},
id::{AdapterId, DeviceId},
power,
Backend,
};
use wgt::{Backend, BackendBit, DeviceDescriptor, PowerPreference, RequestAdapterOptions};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_crate::{Deserialize, Serialize};
use hal::{
self,
@@ -101,85 +101,9 @@ pub struct Adapter<B: hal::Backend> {
pub(crate) raw: hal::adapter::Adapter<B>,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum PowerPreference {
Default = 0,
LowPower = 1,
HighPerformance = 2,
}
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RequestAdapterOptions {
pub power_preference: PowerPreference,
}
impl Default for RequestAdapterOptions {
fn default() -> Self {
RequestAdapterOptions {
power_preference: PowerPreference::Default,
}
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Extensions {
pub anisotropic_filtering: bool,
}
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Limits {
pub max_bind_groups: u32,
}
impl Default for Limits {
fn default() -> Self {
Limits {
max_bind_groups: MAX_BIND_GROUPS as u32,
}
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DeviceDescriptor {
pub extensions: Extensions,
pub limits: Limits,
}
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BackendBit: u32 {
const VULKAN = 1 << Backend::Vulkan as u32;
const GL = 1 << Backend::Gl as u32;
const METAL = 1 << Backend::Metal as u32;
const DX12 = 1 << Backend::Dx12 as u32;
const DX11 = 1 << Backend::Dx11 as u32;
/// Vulkan + METAL + DX12
const PRIMARY = Self::VULKAN.bits | Self::METAL.bits | Self::DX12.bits;
/// OpenGL + DX11
const SECONDARY = Self::GL.bits | Self::DX11.bits;
}
}
impl From<Backend> for BackendBit {
fn from(backend: Backend) -> Self {
BackendBit::from_bits(1 << backend as u32).unwrap()
}
}
/// Metadata about a backend adapter.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub struct AdapterInfo {
/// Adapter name
pub name: String,
@@ -214,7 +138,7 @@ impl AdapterInfo {
/// Supported physical device types
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate="serde_crate"))]
pub enum DeviceType {
/// Other
Other,

View File

@@ -30,9 +30,6 @@ pub mod resource;
pub mod swap_chain;
pub mod track;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use hal::pso::read_spirv;
use peek_poke::{PeekCopy, Poke};
@@ -46,19 +43,6 @@ type SubmissionIndex = usize;
type Index = u32;
type Epoch = u32;
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Backend {
Empty = 0,
Vulkan = 1,
Metal = 2,
Dx12 = 3,
Dx11 = 4,
Gl = 5,
}
pub type BufferAddress = u64;
pub type DynamicOffset = u32;
pub type RawString = *const c_char;
@@ -222,13 +206,13 @@ macro_rules! gfx_select {
($id:expr => $global:ident.$method:ident( $($param:expr),+ )) => {
match $id.backend() {
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
$crate::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),+ ),
wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),+ ),
#[cfg(any(target_os = "ios", target_os = "macos"))]
$crate::Backend::Metal => $global.$method::<$crate::backend::Metal>( $($param),+ ),
wgt::Backend::Metal => $global.$method::<$crate::backend::Metal>( $($param),+ ),
#[cfg(windows)]
$crate::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),+ ),
wgt::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),+ ),
#[cfg(windows)]
$crate::Backend::Dx11 => $global.$method::<$crate::backend::Dx11>( $($param),+ ),
wgt::Backend::Dx11 => $global.$method::<$crate::backend::Dx11>( $($param),+ ),
_ => unreachable!()
}
};

View File

@@ -5,224 +5,10 @@
use crate::{
device::RenderPassContext,
id::{PipelineLayoutId, ShaderModuleId},
resource,
BufferAddress,
RawString,
U32Array,
U32Array
};
pub type ShaderLocation = u32;
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum BlendFactor {
Zero = 0,
One = 1,
SrcColor = 2,
OneMinusSrcColor = 3,
SrcAlpha = 4,
OneMinusSrcAlpha = 5,
DstColor = 6,
OneMinusDstColor = 7,
DstAlpha = 8,
OneMinusDstAlpha = 9,
SrcAlphaSaturated = 10,
BlendColor = 11,
OneMinusBlendColor = 12,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum BlendOperation {
Add = 0,
Subtract = 1,
ReverseSubtract = 2,
Min = 3,
Max = 4,
}
impl Default for BlendOperation {
fn default() -> Self {
BlendOperation::Add
}
}
bitflags::bitflags! {
#[repr(transparent)]
pub struct ColorWrite: u32 {
const RED = 1;
const GREEN = 2;
const BLUE = 4;
const ALPHA = 8;
const COLOR = 7;
const ALL = 15;
}
}
impl Default for ColorWrite {
fn default() -> Self {
ColorWrite::ALL
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct BlendDescriptor {
pub src_factor: BlendFactor,
pub dst_factor: BlendFactor,
pub operation: BlendOperation,
}
impl BlendDescriptor {
pub const REPLACE: Self = BlendDescriptor {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::Zero,
operation: BlendOperation::Add,
};
pub fn uses_color(&self) -> bool {
match (self.src_factor, self.dst_factor) {
(BlendFactor::BlendColor, _)
| (BlendFactor::OneMinusBlendColor, _)
| (_, BlendFactor::BlendColor)
| (_, BlendFactor::OneMinusBlendColor) => true,
(_, _) => false,
}
}
}
impl Default for BlendDescriptor {
fn default() -> Self {
BlendDescriptor::REPLACE
}
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct ColorStateDescriptor {
pub format: resource::TextureFormat,
pub alpha_blend: BlendDescriptor,
pub color_blend: BlendDescriptor,
pub write_mask: ColorWrite,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum StencilOperation {
Keep = 0,
Zero = 1,
Replace = 2,
Invert = 3,
IncrementClamp = 4,
DecrementClamp = 5,
IncrementWrap = 6,
DecrementWrap = 7,
}
impl Default for StencilOperation {
fn default() -> Self {
StencilOperation::Keep
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct StencilStateFaceDescriptor {
pub compare: resource::CompareFunction,
pub fail_op: StencilOperation,
pub depth_fail_op: StencilOperation,
pub pass_op: StencilOperation,
}
impl StencilStateFaceDescriptor {
pub const IGNORE: Self = StencilStateFaceDescriptor {
compare: resource::CompareFunction::Always,
fail_op: StencilOperation::Keep,
depth_fail_op: StencilOperation::Keep,
pass_op: StencilOperation::Keep,
};
}
impl Default for StencilStateFaceDescriptor {
fn default() -> Self {
StencilStateFaceDescriptor::IGNORE
}
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct DepthStencilStateDescriptor {
pub format: resource::TextureFormat,
pub depth_write_enabled: bool,
pub depth_compare: resource::CompareFunction,
pub stencil_front: StencilStateFaceDescriptor,
pub stencil_back: StencilStateFaceDescriptor,
pub stencil_read_mask: u32,
pub stencil_write_mask: u32,
}
impl DepthStencilStateDescriptor {
pub fn needs_stencil_reference(&self) -> bool {
!self.stencil_front.compare.is_trivial() || !self.stencil_back.compare.is_trivial()
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum IndexFormat {
Uint16 = 0,
Uint32 = 1,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum VertexFormat {
Uchar2 = 1,
Uchar4 = 3,
Char2 = 5,
Char4 = 7,
Uchar2Norm = 9,
Uchar4Norm = 11,
Char2Norm = 14,
Char4Norm = 16,
Ushort2 = 18,
Ushort4 = 20,
Short2 = 22,
Short4 = 24,
Ushort2Norm = 26,
Ushort4Norm = 28,
Short2Norm = 30,
Short4Norm = 32,
Half2 = 34,
Half4 = 36,
Float = 37,
Float2 = 38,
Float3 = 39,
Float4 = 40,
Uint = 41,
Uint2 = 42,
Uint3 = 43,
Uint4 = 44,
Int = 45,
Int2 = 46,
Int3 = 47,
Int4 = 48,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum InputStepMode {
Vertex = 0,
Instance = 1,
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct VertexAttributeDescriptor {
pub offset: BufferAddress,
pub format: VertexFormat,
pub shader_location: ShaderLocation,
}
use wgt::{BufferAddress, ColorStateDescriptor, DepthStencilStateDescriptor, IndexFormat, InputStepMode, PrimitiveTopology, RasterizationStateDescriptor, VertexAttributeDescriptor};
#[repr(C)]
#[derive(Debug)]
@@ -267,53 +53,6 @@ pub struct ComputePipeline<B: hal::Backend> {
pub(crate) layout_id: PipelineLayoutId,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum PrimitiveTopology {
PointList = 0,
LineList = 1,
LineStrip = 2,
TriangleList = 3,
TriangleStrip = 4,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum FrontFace {
Ccw = 0,
Cw = 1,
}
impl Default for FrontFace {
fn default() -> Self {
FrontFace::Ccw
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum CullMode {
None = 0,
Front = 1,
Back = 2,
}
impl Default for CullMode {
fn default() -> Self {
CullMode::None
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
pub struct RasterizationStateDescriptor {
pub front_face: FrontFace,
pub cull_mode: CullMode,
pub depth_bias: i32,
pub depth_bias_slope_scale: f32,
pub depth_bias_clamp: f32,
}
#[repr(C)]
#[derive(Debug)]
pub struct RenderPipelineDescriptor {

View File

@@ -5,56 +5,20 @@
use crate::{
id::{DeviceId, SwapChainId, TextureId},
track::DUMMY_SELECTOR,
BufferAddress,
Extent3d,
LifeGuard,
RefCount,
Stored,
};
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat};
use hal;
use rendy_memory::MemoryBlock;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_crate::{Deserialize, Serialize};
use std::{borrow::Borrow, fmt};
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BufferUsage: u32 {
const MAP_READ = 1;
const MAP_WRITE = 2;
const COPY_SRC = 4;
const COPY_DST = 8;
const INDEX = 16;
const VERTEX = 32;
const UNIFORM = 64;
const STORAGE = 128;
const INDIRECT = 256;
const STORAGE_READ = 512;
const NONE = 0;
/// The combination of all read-only usages.
const READ_ALL = Self::MAP_READ.bits | Self::COPY_SRC.bits |
Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits |
Self::STORAGE_READ.bits | Self::INDIRECT.bits;
/// The combination of all write-only and read-write usages.
const WRITE_ALL = Self::MAP_WRITE.bits | Self::COPY_DST.bits | Self::STORAGE.bits;
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is not ordered, then even if it doesn't change between draw calls, there
/// still need to be pipeline barriers inserted for synchronization.
const ORDERED = Self::READ_ALL.bits;
}
}
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct BufferDescriptor {
pub size: BufferAddress,
pub usage: BufferUsage,
}
#[repr(C)]
#[derive(Debug)]
pub enum BufferMapAsyncStatus {
@@ -139,69 +103,6 @@ pub enum TextureDimension {
D3,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum TextureFormat {
// Normal 8 bit formats
R8Unorm = 0,
R8Snorm = 1,
R8Uint = 2,
R8Sint = 3,
// Normal 16 bit formats
R16Unorm = 4,
R16Snorm = 5,
R16Uint = 6,
R16Sint = 7,
R16Float = 8,
Rg8Unorm = 9,
Rg8Snorm = 10,
Rg8Uint = 11,
Rg8Sint = 12,
// Normal 32 bit formats
R32Uint = 13,
R32Sint = 14,
R32Float = 15,
Rg16Unorm = 16,
Rg16Snorm = 17,
Rg16Uint = 18,
Rg16Sint = 19,
Rg16Float = 20,
Rgba8Unorm = 21,
Rgba8UnormSrgb = 22,
Rgba8Snorm = 23,
Rgba8Uint = 24,
Rgba8Sint = 25,
Bgra8Unorm = 26,
Bgra8UnormSrgb = 27,
// Packed 32 bit formats
Rgb10a2Unorm = 28,
Rg11b10Float = 29,
// Normal 64 bit formats
Rg32Uint = 30,
Rg32Sint = 31,
Rg32Float = 32,
Rgba16Unorm = 33,
Rgba16Snorm = 34,
Rgba16Uint = 35,
Rgba16Sint = 36,
Rgba16Float = 37,
// Normal 128 bit formats
Rgba32Uint = 38,
Rgba32Sint = 39,
Rgba32Float = 40,
// Depth and stencil formats
Depth32Float = 41,
Depth24Plus = 42,
Depth24PlusStencil8 = 43,
}
bitflags::bitflags! {
#[repr(transparent)]
pub struct TextureUsage: u32 {
@@ -273,23 +174,11 @@ impl Default for TextureAspect {
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TextureViewDimension {
D1,
D2,
D2Array,
Cube,
CubeArray,
D3,
}
#[repr(C)]
#[derive(Debug)]
pub struct TextureViewDescriptor {
pub format: TextureFormat,
pub dimension: TextureViewDimension,
pub dimension: wgt::TextureViewDimension,
pub aspect: TextureAspect,
pub base_mip_level: u32,
pub level_count: u32,
@@ -359,28 +248,6 @@ impl Default for FilterMode {
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum CompareFunction {
Never = 0,
Less = 1,
Equal = 2,
LessEqual = 3,
Greater = 4,
NotEqual = 5,
GreaterEqual = 6,
Always = 7,
}
impl CompareFunction {
pub fn is_trivial(self) -> bool {
match self {
CompareFunction::Never | CompareFunction::Always => true,
_ => false,
}
}
}
#[repr(C)]
#[derive(Debug)]
pub struct SamplerDescriptor {

View File

@@ -43,6 +43,7 @@ use crate::{
Stored,
};
use wgt::TextureFormat;
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
@@ -83,7 +84,7 @@ pub enum PresentMode {
#[derive(Clone, Debug)]
pub struct SwapChainDescriptor {
pub usage: resource::TextureUsage,
pub format: resource::TextureFormat,
pub format: TextureFormat,
pub width: u32,
pub height: u32,
pub present_mode: PresentMode,

View File

@@ -3,7 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use super::{PendingTransition, ResourceState, Unit};
use crate::{id::BufferId, resource::BufferUsage};
use crate::id::BufferId;
use wgt::BufferUsage;
//TODO: store `hal::buffer::State` here to avoid extra conversions
pub type BufferState = Unit<BufferUsage>;
@@ -112,7 +114,7 @@ impl ResourceState for BufferState {
#[cfg(test)]
mod test {
use super::*;
use crate::{id::TypedId, Backend};
use crate::{id::TypedId};
#[test]
fn change() {
@@ -120,7 +122,7 @@ mod test {
first: Some(BufferUsage::INDEX),
last: BufferUsage::STORAGE,
};
let id = TypedId::zip(0, 0, Backend::Empty);
let id = TypedId::zip(0, 0, wgt::Backend::Empty);
assert!(bs.change(id, (), BufferUsage::VERTEX, None).is_err());
bs.change(id, (), BufferUsage::VERTEX, Some(&mut Vec::new()))
.unwrap();

View File

@@ -11,7 +11,6 @@ use crate::{
hub::Storage,
id::{BindGroupId, SamplerId, TextureViewId, TypedId},
resource,
Backend,
Epoch,
FastHashMap,
Index,
@@ -173,7 +172,7 @@ pub struct ResourceTracker<S: ResourceState> {
/// Temporary storage for collecting transitions.
temp: Vec<PendingTransition<S>>,
/// The backend variant for all the tracked resources.
backend: Backend,
backend: wgt::Backend,
}
impl<S: ResourceState + fmt::Debug> fmt::Debug for ResourceTracker<S> {
@@ -190,7 +189,7 @@ impl<S: ResourceState + fmt::Debug> fmt::Debug for ResourceTracker<S> {
impl<S: ResourceState> ResourceTracker<S> {
/// Create a new empty tracker.
pub fn new(backend: Backend) -> Self {
pub fn new(backend: wgt::Backend) -> Self {
ResourceTracker {
map: FastHashMap::default(),
temp: Vec::new(),
@@ -295,7 +294,7 @@ impl<S: ResourceState> ResourceTracker<S> {
/// Make sure that a resource is tracked, and return a mutable
/// reference to it.
fn get_or_insert<'a>(
self_backend: Backend,
self_backend: wgt::Backend,
map: &'a mut FastHashMap<Index, Resource<S>>,
id: S::Id,
ref_count: &RefCount,
@@ -472,7 +471,7 @@ pub struct TrackerSet {
impl TrackerSet {
/// Create an empty set.
pub fn new(backend: Backend) -> Self {
pub fn new(backend: wgt::Backend) -> Self {
TrackerSet {
buffers: ResourceTracker::new(backend),
textures: ResourceTracker::new(backend),
@@ -510,7 +509,7 @@ impl TrackerSet {
self.samplers.merge_extend(&other.samplers).unwrap();
}
pub fn backend(&self) -> Backend {
pub fn backend(&self) -> wgt::Backend {
self.buffers.backend
}
}

View File

@@ -25,6 +25,11 @@ path = "../wgpu-core"
package = "wgpu-core"
version = "0.1"
[dependencies.wgt]
path = "../wgpu-types"
package = "wgpu-types"
version = "0.1"
[dependencies]
arrayvec = "0.5"
lazy_static = "1.1"

View File

@@ -23,9 +23,9 @@ exclude = ["BufferMapResult"]
[parse]
parse_deps = true
include = ["wgpu-core"]
include = ["wgpu-core", "wgpu-types"]
extra_bindings = ["wgpu-core"]
extra_bindings = ["wgpu-core", "wgpu-types"]
[fn]

View File

@@ -25,10 +25,10 @@ pub extern "C" fn wgpu_command_encoder_finish(
pub extern "C" fn wgpu_command_encoder_copy_buffer_to_buffer(
command_encoder_id: id::CommandEncoderId,
source: id::BufferId,
source_offset: core::BufferAddress,
source_offset: wgt::BufferAddress,
destination: id::BufferId,
destination_offset: core::BufferAddress,
size: core::BufferAddress,
destination_offset: wgt::BufferAddress,
size: wgt::BufferAddress,
) {
gfx_select!(command_encoder_id => GLOBAL.command_encoder_copy_buffer_to_buffer(
command_encoder_id,

View File

@@ -4,6 +4,7 @@
use crate::GLOBAL;
use wgt::{BackendBit, DeviceDescriptor, Limits, RequestAdapterOptions};
use core::{gfx_select, hub::Token, id};
use std::{marker::PhantomData, slice};
@@ -143,7 +144,7 @@ pub extern "C" fn wgpu_create_surface_from_windows_hwnd(
))
}
pub fn wgpu_enumerate_adapters(mask: core::instance::BackendBit) -> Vec<id::AdapterId> {
pub fn wgpu_enumerate_adapters(mask: BackendBit) -> Vec<id::AdapterId> {
GLOBAL.enumerate_adapters(core::instance::AdapterInputs::Mask(mask, || PhantomData))
}
@@ -152,8 +153,8 @@ pub fn wgpu_enumerate_adapters(mask: core::instance::BackendBit) -> Vec<id::Adap
/// This function is unsafe as it calls an unsafe extern callback.
#[no_mangle]
pub unsafe extern "C" fn wgpu_request_adapter_async(
desc: Option<&core::instance::RequestAdapterOptions>,
mask: core::instance::BackendBit,
desc: Option<&RequestAdapterOptions>,
mask: BackendBit,
callback: RequestAdapterCallback,
userdata: *mut std::ffi::c_void,
) {
@@ -170,7 +171,7 @@ pub unsafe extern "C" fn wgpu_request_adapter_async(
#[no_mangle]
pub extern "C" fn wgpu_adapter_request_device(
adapter_id: id::AdapterId,
desc: Option<&core::instance::DeviceDescriptor>,
desc: Option<&DeviceDescriptor>,
) -> id::DeviceId {
let desc = &desc.cloned().unwrap_or_default();
gfx_select!(adapter_id => GLOBAL.adapter_request_device(adapter_id, desc, PhantomData))
@@ -188,15 +189,15 @@ pub extern "C" fn wgpu_adapter_destroy(adapter_id: id::AdapterId) {
#[no_mangle]
pub extern "C" fn wgpu_device_get_limits(
_device_id: id::DeviceId,
limits: &mut core::instance::Limits,
limits: &mut Limits,
) {
*limits = core::instance::Limits::default(); // TODO
*limits = Limits::default(); // TODO
}
#[no_mangle]
pub extern "C" fn wgpu_device_create_buffer(
device_id: id::DeviceId,
desc: &core::resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
) -> id::BufferId {
gfx_select!(device_id => GLOBAL.device_create_buffer(device_id, desc, PhantomData))
}
@@ -208,7 +209,7 @@ pub extern "C" fn wgpu_device_create_buffer(
#[no_mangle]
pub unsafe extern "C" fn wgpu_device_create_buffer_mapped(
device_id: id::DeviceId,
desc: &core::resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
mapped_ptr_out: *mut *mut u8,
) -> id::BufferId {
let (id, ptr) = gfx_select!(device_id => GLOBAL.device_create_buffer_mapped(device_id, desc, PhantomData));
@@ -374,8 +375,8 @@ pub extern "C" fn wgpu_device_destroy(device_id: id::DeviceId) {
#[no_mangle]
pub extern "C" fn wgpu_buffer_map_read_async(
buffer_id: id::BufferId,
start: core::BufferAddress,
size: core::BufferAddress,
start: wgt::BufferAddress,
size: wgt::BufferAddress,
callback: core::device::BufferMapReadCallback,
userdata: *mut u8,
) {
@@ -384,14 +385,14 @@ pub extern "C" fn wgpu_buffer_map_read_async(
callback(status, data, userdata)
}),
);
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, core::resource::BufferUsage::MAP_READ, start .. start + size, operation))
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, wgt::BufferUsage::MAP_READ, start .. start + size, operation))
}
#[no_mangle]
pub extern "C" fn wgpu_buffer_map_write_async(
buffer_id: id::BufferId,
start: core::BufferAddress,
size: core::BufferAddress,
start: wgt::BufferAddress,
size: wgt::BufferAddress,
callback: core::device::BufferMapWriteCallback,
userdata: *mut u8,
) {
@@ -400,7 +401,7 @@ pub extern "C" fn wgpu_buffer_map_write_async(
callback(status, data, userdata)
}),
);
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, core::resource::BufferUsage::MAP_WRITE, start .. start + size, operation))
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, wgt::BufferUsage::MAP_WRITE, start .. start + size, operation))
}
#[no_mangle]

View File

@@ -19,6 +19,13 @@ default = []
path = "../wgpu-core"
package = "wgpu-core"
version = "0.1"
features = ["serde"]
[dependencies.wgt]
path = "../wgpu-types"
package = "wgpu-types"
version = "0.1"
features = ["serde"]
[dependencies]
log = "0.4"

View File

@@ -24,9 +24,9 @@ exclude = ["BufferMapResult"]
[parse]
parse_deps = true
include = ["wgpu-core"]
include = ["wgpu-core", "wgpu-types"]
extra_bindings = ["wgpu-core"]
extra_bindings = ["wgpu-core", "wgpu-types"]
[fn]
prefix = "WGPU_INLINE"

View File

@@ -5,9 +5,10 @@
use core::{
hub::IdentityManager,
id,
Backend,
};
use wgt::Backend;
pub use core::command::{
compute_ffi::*,
render_ffi::*,

View File

@@ -43,7 +43,7 @@ pub extern "C" fn wgpu_server_poll_all_devices(global: &Global, force_wait: bool
#[no_mangle]
pub unsafe extern "C" fn wgpu_server_instance_request_adapter(
global: &Global,
desc: &core::instance::RequestAdapterOptions,
desc: &wgt::RequestAdapterOptions,
ids: *const id::AdapterId,
id_length: usize,
) -> i8 {
@@ -61,7 +61,7 @@ pub unsafe extern "C" fn wgpu_server_instance_request_adapter(
pub extern "C" fn wgpu_server_adapter_request_device(
global: &Global,
self_id: id::AdapterId,
desc: &core::instance::DeviceDescriptor,
desc: &wgt::DeviceDescriptor,
new_id: id::DeviceId,
) {
gfx_select!(self_id => global.adapter_request_device(self_id, desc, new_id));
@@ -84,7 +84,7 @@ pub extern "C" fn wgpu_server_device_destroy(global: &Global, self_id: id::Devic
pub extern "C" fn wgpu_server_device_create_buffer(
global: &Global,
self_id: id::DeviceId,
desc: &core::resource::BufferDescriptor,
desc: &wgt::BufferDescriptor,
new_id: id::BufferId,
) {
gfx_select!(self_id => global.device_create_buffer(self_id, desc, new_id));
@@ -99,9 +99,9 @@ pub unsafe extern "C" fn wgpu_server_device_set_buffer_sub_data(
global: &Global,
self_id: id::DeviceId,
buffer_id: id::BufferId,
offset: core::BufferAddress,
offset: wgt::BufferAddress,
data: *const u8,
size: core::BufferAddress,
size: wgt::BufferAddress,
) {
let slice = slice::from_raw_parts(data, size as usize);
gfx_select!(self_id => global.device_set_buffer_sub_data(self_id, buffer_id, offset, slice));
@@ -115,8 +115,8 @@ pub unsafe extern "C" fn wgpu_server_device_set_buffer_sub_data(
pub extern "C" fn wgpu_server_buffer_map_read(
global: &Global,
buffer_id: id::BufferId,
start: core::BufferAddress,
size: core::BufferAddress,
start: wgt::BufferAddress,
size: wgt::BufferAddress,
callback: core::device::BufferMapReadCallback,
userdata: *mut u8,
) {
@@ -127,7 +127,7 @@ pub extern "C" fn wgpu_server_buffer_map_read(
);
gfx_select!(buffer_id => global.buffer_map_async(
buffer_id,
core::resource::BufferUsage::MAP_READ,
wgt::BufferUsage::MAP_READ,
start .. start + size,
operation
));
@@ -182,10 +182,10 @@ pub unsafe extern "C" fn wgpu_server_encoder_copy_buffer_to_buffer(
global: &Global,
self_id: id::CommandEncoderId,
source_id: id::BufferId,
source_offset: core::BufferAddress,
source_offset: wgt::BufferAddress,
destination_id: id::BufferId,
destination_offset: core::BufferAddress,
size: core::BufferAddress,
destination_offset: wgt::BufferAddress,
size: wgt::BufferAddress,
) {
gfx_select!(self_id => global.command_encoder_copy_buffer_to_buffer(self_id, source_id, source_offset, destination_id, destination_offset, size));
}

19
wgpu-types/Cargo.toml Normal file
View File

@@ -0,0 +1,19 @@
[package]
name = "wgpu-types"
version = "0.1.0"
authors = [
"Dzmitry Malyshau <kvark@mozilla.com>",
"Joshua Groves <josh@joshgroves.com>",
]
edition = "2018"
description = "WebGPU types"
homepage = "https://github.com/gfx-rs/wgpu"
repository = "https://github.com/gfx-rs/wgpu"
keywords = ["graphics"]
license = "MPL-2.0"
[lib]
[dependencies]
bitflags = "1.0"
serde = { version = "1.0", features = ["serde_derive"], optional = true }

548
wgpu-types/src/lib.rs Normal file
View File

@@ -0,0 +1,548 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::{io, slice};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Backend {
Empty = 0,
Vulkan = 1,
Metal = 2,
Dx12 = 3,
Dx11 = 4,
Gl = 5,
BrowserWebGpu = 6,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum PowerPreference {
Default = 0,
LowPower = 1,
HighPerformance = 2,
}
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RequestAdapterOptions {
pub power_preference: PowerPreference,
}
impl Default for RequestAdapterOptions {
fn default() -> Self {
RequestAdapterOptions {
power_preference: PowerPreference::Default,
}
}
}
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BackendBit: u32 {
const VULKAN = 1 << Backend::Vulkan as u32;
const GL = 1 << Backend::Gl as u32;
const METAL = 1 << Backend::Metal as u32;
const DX12 = 1 << Backend::Dx12 as u32;
const DX11 = 1 << Backend::Dx11 as u32;
const BROWSER_WEBGPU = 1 << Backend::BrowserWebGpu as u32;
/// Vulkan + Metal + DX12 + Browser WebGPU
const PRIMARY = Self::VULKAN.bits
| Self::METAL.bits
| Self::DX12.bits
| Self::BROWSER_WEBGPU.bits;
/// OpenGL + DX11
const SECONDARY = Self::GL.bits | Self::DX11.bits;
}
}
impl From<Backend> for BackendBit {
fn from(backend: Backend) -> Self {
BackendBit::from_bits(1 << backend as u32).unwrap()
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Extensions {
pub anisotropic_filtering: bool,
}
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Limits {
pub max_bind_groups: u32,
}
pub const MAX_BIND_GROUPS: usize = 4;
impl Default for Limits {
fn default() -> Self {
Limits {
max_bind_groups: MAX_BIND_GROUPS as u32,
}
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DeviceDescriptor {
pub extensions: Extensions,
pub limits: Limits,
}
// TODO: This is copy/pasted from gfx-hal, so we need to find a new place to put
// this function
pub fn read_spirv<R: io::Read + io::Seek>(mut x: R) -> io::Result<Vec<u32>> {
let size = x.seek(io::SeekFrom::End(0))?;
if size % 4 != 0 {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"input length not divisible by 4",
));
}
if size > usize::max_value() as u64 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "input too long"));
}
let words = (size / 4) as usize;
let mut result = Vec::<u32>::with_capacity(words);
x.seek(io::SeekFrom::Start(0))?;
unsafe {
// Writing all bytes through a pointer with less strict alignment when our type has no
// invalid bitpatterns is safe.
x.read_exact(slice::from_raw_parts_mut(
result.as_mut_ptr() as *mut u8,
words * 4,
))?;
result.set_len(words);
}
const MAGIC_NUMBER: u32 = 0x07230203;
if result.len() > 0 && result[0] == MAGIC_NUMBER.swap_bytes() {
for word in &mut result {
*word = word.swap_bytes();
}
}
if result.len() == 0 || result[0] != MAGIC_NUMBER {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"input missing SPIR-V magic number",
));
}
Ok(result)
}
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ShaderStage: u32 {
const NONE = 0;
const VERTEX = 1;
const FRAGMENT = 2;
const COMPUTE = 4;
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TextureViewDimension {
D1,
D2,
D2Array,
Cube,
CubeArray,
D3,
}
pub type BufferAddress = u64;
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum BlendFactor {
Zero = 0,
One = 1,
SrcColor = 2,
OneMinusSrcColor = 3,
SrcAlpha = 4,
OneMinusSrcAlpha = 5,
DstColor = 6,
OneMinusDstColor = 7,
DstAlpha = 8,
OneMinusDstAlpha = 9,
SrcAlphaSaturated = 10,
BlendColor = 11,
OneMinusBlendColor = 12,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum BlendOperation {
Add = 0,
Subtract = 1,
ReverseSubtract = 2,
Min = 3,
Max = 4,
}
impl Default for BlendOperation {
fn default() -> Self {
BlendOperation::Add
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct BlendDescriptor {
pub src_factor: BlendFactor,
pub dst_factor: BlendFactor,
pub operation: BlendOperation,
}
impl BlendDescriptor {
pub const REPLACE: Self = BlendDescriptor {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::Zero,
operation: BlendOperation::Add,
};
pub fn uses_color(&self) -> bool {
match (self.src_factor, self.dst_factor) {
(BlendFactor::BlendColor, _)
| (BlendFactor::OneMinusBlendColor, _)
| (_, BlendFactor::BlendColor)
| (_, BlendFactor::OneMinusBlendColor) => true,
(_, _) => false,
}
}
}
impl Default for BlendDescriptor {
fn default() -> Self {
BlendDescriptor::REPLACE
}
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct ColorStateDescriptor {
pub format: TextureFormat,
pub alpha_blend: BlendDescriptor,
pub color_blend: BlendDescriptor,
pub write_mask: ColorWrite,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum PrimitiveTopology {
PointList = 0,
LineList = 1,
LineStrip = 2,
TriangleList = 3,
TriangleStrip = 4,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum FrontFace {
Ccw = 0,
Cw = 1,
}
impl Default for FrontFace {
fn default() -> Self {
FrontFace::Ccw
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum CullMode {
None = 0,
Front = 1,
Back = 2,
}
impl Default for CullMode {
fn default() -> Self {
CullMode::None
}
}
#[repr(C)]
#[derive(Clone, Debug, Default)]
pub struct RasterizationStateDescriptor {
pub front_face: FrontFace,
pub cull_mode: CullMode,
pub depth_bias: i32,
pub depth_bias_slope_scale: f32,
pub depth_bias_clamp: f32,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum TextureFormat {
// Normal 8 bit formats
R8Unorm = 0,
R8Snorm = 1,
R8Uint = 2,
R8Sint = 3,
// Normal 16 bit formats
R16Unorm = 4,
R16Snorm = 5,
R16Uint = 6,
R16Sint = 7,
R16Float = 8,
Rg8Unorm = 9,
Rg8Snorm = 10,
Rg8Uint = 11,
Rg8Sint = 12,
// Normal 32 bit formats
R32Uint = 13,
R32Sint = 14,
R32Float = 15,
Rg16Unorm = 16,
Rg16Snorm = 17,
Rg16Uint = 18,
Rg16Sint = 19,
Rg16Float = 20,
Rgba8Unorm = 21,
Rgba8UnormSrgb = 22,
Rgba8Snorm = 23,
Rgba8Uint = 24,
Rgba8Sint = 25,
Bgra8Unorm = 26,
Bgra8UnormSrgb = 27,
// Packed 32 bit formats
Rgb10a2Unorm = 28,
Rg11b10Float = 29,
// Normal 64 bit formats
Rg32Uint = 30,
Rg32Sint = 31,
Rg32Float = 32,
Rgba16Unorm = 33,
Rgba16Snorm = 34,
Rgba16Uint = 35,
Rgba16Sint = 36,
Rgba16Float = 37,
// Normal 128 bit formats
Rgba32Uint = 38,
Rgba32Sint = 39,
Rgba32Float = 40,
// Depth and stencil formats
Depth32Float = 41,
Depth24Plus = 42,
Depth24PlusStencil8 = 43,
}
bitflags::bitflags! {
#[repr(transparent)]
pub struct ColorWrite: u32 {
const RED = 1;
const GREEN = 2;
const BLUE = 4;
const ALPHA = 8;
const COLOR = 7;
const ALL = 15;
}
}
impl Default for ColorWrite {
fn default() -> Self {
ColorWrite::ALL
}
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct DepthStencilStateDescriptor {
pub format: TextureFormat,
pub depth_write_enabled: bool,
pub depth_compare: CompareFunction,
pub stencil_front: StencilStateFaceDescriptor,
pub stencil_back: StencilStateFaceDescriptor,
pub stencil_read_mask: u32,
pub stencil_write_mask: u32,
}
impl DepthStencilStateDescriptor {
pub fn needs_stencil_reference(&self) -> bool {
!self.stencil_front.compare.is_trivial() || !self.stencil_back.compare.is_trivial()
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum IndexFormat {
Uint16 = 0,
Uint32 = 1,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum StencilOperation {
Keep = 0,
Zero = 1,
Replace = 2,
Invert = 3,
IncrementClamp = 4,
DecrementClamp = 5,
IncrementWrap = 6,
DecrementWrap = 7,
}
impl Default for StencilOperation {
fn default() -> Self {
StencilOperation::Keep
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct StencilStateFaceDescriptor {
pub compare: CompareFunction,
pub fail_op: StencilOperation,
pub depth_fail_op: StencilOperation,
pub pass_op: StencilOperation,
}
impl StencilStateFaceDescriptor {
pub const IGNORE: Self = StencilStateFaceDescriptor {
compare: CompareFunction::Always,
fail_op: StencilOperation::Keep,
depth_fail_op: StencilOperation::Keep,
pass_op: StencilOperation::Keep,
};
}
impl Default for StencilStateFaceDescriptor {
fn default() -> Self {
StencilStateFaceDescriptor::IGNORE
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum CompareFunction {
Never = 0,
Less = 1,
Equal = 2,
LessEqual = 3,
Greater = 4,
NotEqual = 5,
GreaterEqual = 6,
Always = 7,
}
impl CompareFunction {
pub fn is_trivial(self) -> bool {
match self {
CompareFunction::Never | CompareFunction::Always => true,
_ => false,
}
}
}
pub type ShaderLocation = u32;
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum InputStepMode {
Vertex = 0,
Instance = 1,
}
#[repr(C)]
#[derive(Clone, Debug)]
pub struct VertexAttributeDescriptor {
pub offset: BufferAddress,
pub format: VertexFormat,
pub shader_location: ShaderLocation,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum VertexFormat {
Uchar2 = 1,
Uchar4 = 3,
Char2 = 5,
Char4 = 7,
Uchar2Norm = 9,
Uchar4Norm = 11,
Char2Norm = 14,
Char4Norm = 16,
Ushort2 = 18,
Ushort4 = 20,
Short2 = 22,
Short4 = 24,
Ushort2Norm = 26,
Ushort4Norm = 28,
Short2Norm = 30,
Short4Norm = 32,
Half2 = 34,
Half4 = 36,
Float = 37,
Float2 = 38,
Float3 = 39,
Float4 = 40,
Uint = 41,
Uint2 = 42,
Uint3 = 43,
Uint4 = 44,
Int = 45,
Int2 = 46,
Int3 = 47,
Int4 = 48,
}
bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BufferUsage: u32 {
const MAP_READ = 1;
const MAP_WRITE = 2;
const COPY_SRC = 4;
const COPY_DST = 8;
const INDEX = 16;
const VERTEX = 32;
const UNIFORM = 64;
const STORAGE = 128;
const INDIRECT = 256;
const STORAGE_READ = 512;
const NONE = 0;
/// The combination of all read-only usages.
const READ_ALL = Self::MAP_READ.bits | Self::COPY_SRC.bits |
Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits |
Self::STORAGE_READ.bits | Self::INDIRECT.bits;
/// The combination of all write-only and read-write usages.
const WRITE_ALL = Self::MAP_WRITE.bits | Self::COPY_DST.bits | Self::STORAGE.bits;
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is not ordered, then even if it doesn't change between draw calls, there
/// still need to be pipeline barriers inserted for synchronization.
const ORDERED = Self::READ_ALL.bits;
}
}
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct BufferDescriptor {
pub size: BufferAddress,
pub usage: BufferUsage,
}