mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Move more shared types into wgpu-types
This commit is contained in:
parent
e4df6ee288
commit
b58c15815b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -742,6 +742,7 @@ name = "wgpu-types"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"peek-poke 0.2.0 (git+https://github.com/kvark/peek-poke?rev=969bd7fe2be1a83f87916dc8b388c63cfd457075)",
|
||||||
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ optional = true
|
|||||||
path = "../wgpu-types"
|
path = "../wgpu-types"
|
||||||
package = "wgpu-types"
|
package = "wgpu-types"
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
|
features = ["peek-poke"]
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
||||||
gfx-backend-metal = { version = "0.4" }
|
gfx-backend-metal = { version = "0.4" }
|
||||||
|
|||||||
@ -6,12 +6,11 @@ use crate::{
|
|||||||
binding_model::BindGroup,
|
binding_model::BindGroup,
|
||||||
hub::GfxBackend,
|
hub::GfxBackend,
|
||||||
id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId},
|
id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId},
|
||||||
DynamicOffset,
|
|
||||||
Stored,
|
Stored,
|
||||||
};
|
};
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
use wgt::DynamicOffset;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
pub const DEFAULT_BIND_GROUPS: usize = 4;
|
pub const DEFAULT_BIND_GROUPS: usize = 4;
|
||||||
|
|||||||
@ -11,10 +11,9 @@ use crate::{
|
|||||||
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
|
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
|
||||||
hub::{GfxBackend, Global, Token},
|
hub::{GfxBackend, Global, Token},
|
||||||
id,
|
id,
|
||||||
DynamicOffset,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use wgt::{BufferAddress, BufferUsage};
|
use wgt::{BufferAddress, BufferUsage, DynamicOffset};
|
||||||
use hal::command::CommandBuffer as _;
|
use hal::command::CommandBuffer as _;
|
||||||
use peek_poke::{Peek, PeekCopy, Poke};
|
use peek_poke::{Peek, PeekCopy, Poke};
|
||||||
|
|
||||||
@ -221,10 +220,9 @@ pub mod compute_ffi {
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
id,
|
id,
|
||||||
DynamicOffset,
|
|
||||||
RawString,
|
RawString,
|
||||||
};
|
};
|
||||||
use wgt::BufferAddress;
|
use wgt::{BufferAddress, DynamicOffset};
|
||||||
use std::{convert::TryInto, slice};
|
use std::{convert::TryInto, slice};
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|||||||
@ -35,6 +35,7 @@ use std::{
|
|||||||
slice,
|
slice,
|
||||||
thread::ThreadId,
|
thread::ThreadId,
|
||||||
};
|
};
|
||||||
|
use wgt::RenderPassColorAttachmentDescriptorBase;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, peek_poke::PeekCopy, peek_poke::Poke)]
|
#[derive(Clone, Copy, Debug, peek_poke::PeekCopy, peek_poke::Poke)]
|
||||||
@ -194,14 +195,6 @@ impl<B: GfxBackend> CommandBuffer<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Debug, Default)]
|
|
||||||
pub struct CommandEncoderDescriptor {
|
|
||||||
// MSVC doesn't allow zero-sized structs
|
|
||||||
// We can remove this when we actually have a field
|
|
||||||
pub todo: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct CommandBufferDescriptor {
|
pub struct CommandBufferDescriptor {
|
||||||
|
|||||||
@ -21,14 +21,23 @@ use crate::{
|
|||||||
hub::{GfxBackend, Global, Token},
|
hub::{GfxBackend, Global, Token},
|
||||||
id,
|
id,
|
||||||
pipeline::PipelineFlags,
|
pipeline::PipelineFlags,
|
||||||
resource::{TextureUsage, TextureViewInner},
|
resource::TextureViewInner,
|
||||||
track::TrackerSet,
|
track::TrackerSet,
|
||||||
Color,
|
|
||||||
DynamicOffset,
|
|
||||||
Stored,
|
Stored,
|
||||||
};
|
};
|
||||||
|
|
||||||
use wgt::{BufferAddress, BufferUsage, IndexFormat, InputStepMode};
|
use wgt::{
|
||||||
|
BufferAddress,
|
||||||
|
BufferUsage,
|
||||||
|
Color,
|
||||||
|
DynamicOffset,
|
||||||
|
IndexFormat,
|
||||||
|
InputStepMode,
|
||||||
|
LoadOp,
|
||||||
|
RenderPassColorAttachmentDescriptorBase,
|
||||||
|
RenderPassDepthStencilAttachmentDescriptorBase,
|
||||||
|
TextureUsage,
|
||||||
|
};
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use hal::command::CommandBuffer as _;
|
use hal::command::CommandBuffer as _;
|
||||||
use peek_poke::{Peek, PeekCopy, Poke};
|
use peek_poke::{Peek, PeekCopy, Poke};
|
||||||
@ -43,45 +52,8 @@ use std::{
|
|||||||
slice,
|
slice,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PeekCopy, Poke)]
|
|
||||||
pub enum LoadOp {
|
|
||||||
Clear = 0,
|
|
||||||
Load = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PeekCopy, Poke)]
|
|
||||||
pub enum StoreOp {
|
|
||||||
Clear = 0,
|
|
||||||
Store = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, PeekCopy, Poke)]
|
|
||||||
pub struct RenderPassColorAttachmentDescriptorBase<T, R> {
|
|
||||||
pub attachment: T,
|
|
||||||
pub resolve_target: R,
|
|
||||||
pub load_op: LoadOp,
|
|
||||||
pub store_op: StoreOp,
|
|
||||||
pub clear_color: Color,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Debug, PeekCopy, Poke)]
|
|
||||||
pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
|
|
||||||
pub attachment: T,
|
|
||||||
pub depth_load_op: LoadOp,
|
|
||||||
pub depth_store_op: StoreOp,
|
|
||||||
pub clear_depth: f32,
|
|
||||||
pub stencil_load_op: LoadOp,
|
|
||||||
pub stencil_store_op: StoreOp,
|
|
||||||
pub clear_stencil: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
//Note: this could look better if `cbindgen` wasn't confused by &T used in place of
|
//Note: this could look better if `cbindgen` wasn't confused by &T used in place of
|
||||||
// a generic paramter, it's not able to mange
|
// a generic parameter, it's not able to manage
|
||||||
pub type OptionRef<'a, T> = Option<&'a T>;
|
pub type OptionRef<'a, T> = Option<&'a T>;
|
||||||
pub type RenderPassColorAttachmentDescriptor<'a> =
|
pub type RenderPassColorAttachmentDescriptor<'a> =
|
||||||
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, OptionRef<'a, id::TextureViewId>>;
|
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, OptionRef<'a, id::TextureViewId>>;
|
||||||
@ -1156,11 +1128,9 @@ pub mod render_ffi {
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
id,
|
id,
|
||||||
Color,
|
|
||||||
DynamicOffset,
|
|
||||||
RawString,
|
RawString,
|
||||||
};
|
};
|
||||||
use wgt::BufferAddress;
|
use wgt::{BufferAddress, Color, DynamicOffset};
|
||||||
use std::{convert::TryInto, slice};
|
use std::{convert::TryInto, slice};
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|||||||
@ -7,12 +7,11 @@ use crate::{
|
|||||||
device::{all_buffer_stages, all_image_stages},
|
device::{all_buffer_stages, all_image_stages},
|
||||||
hub::{GfxBackend, Global, Token},
|
hub::{GfxBackend, Global, Token},
|
||||||
id::{BufferId, CommandEncoderId, TextureId},
|
id::{BufferId, CommandEncoderId, TextureId},
|
||||||
resource::TextureUsage,
|
|
||||||
Extent3d,
|
Extent3d,
|
||||||
Origin3d,
|
Origin3d,
|
||||||
};
|
};
|
||||||
|
|
||||||
use wgt::{BufferAddress, BufferUsage};
|
use wgt::{BufferAddress, BufferUsage, TextureUsage};
|
||||||
use hal::command::CommandBuffer as _;
|
use hal::command::CommandBuffer as _;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|||||||
@ -2,8 +2,25 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::{binding_model, command, resource, Color, Extent3d, Features, Origin3d};
|
use crate::{binding_model, resource, Extent3d, Features, Origin3d};
|
||||||
use wgt::{BlendDescriptor, BlendFactor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat, PrimitiveTopology, StencilOperation, StencilStateFaceDescriptor, TextureFormat, RasterizationStateDescriptor, VertexFormat};
|
use wgt::{
|
||||||
|
BlendDescriptor,
|
||||||
|
BlendFactor,
|
||||||
|
Color,
|
||||||
|
ColorStateDescriptor,
|
||||||
|
ColorWrite,
|
||||||
|
CompareFunction,
|
||||||
|
CullMode,
|
||||||
|
DepthStencilStateDescriptor,
|
||||||
|
FrontFace,
|
||||||
|
IndexFormat,
|
||||||
|
PrimitiveTopology,
|
||||||
|
StencilOperation,
|
||||||
|
StencilStateFaceDescriptor,
|
||||||
|
TextureFormat,
|
||||||
|
RasterizationStateDescriptor,
|
||||||
|
VertexFormat,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn map_buffer_usage(
|
pub fn map_buffer_usage(
|
||||||
usage: wgt::BufferUsage,
|
usage: wgt::BufferUsage,
|
||||||
@ -47,10 +64,10 @@ pub fn map_buffer_usage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_texture_usage(
|
pub fn map_texture_usage(
|
||||||
usage: resource::TextureUsage,
|
usage: wgt::TextureUsage,
|
||||||
aspects: hal::format::Aspects,
|
aspects: hal::format::Aspects,
|
||||||
) -> hal::image::Usage {
|
) -> hal::image::Usage {
|
||||||
use crate::resource::TextureUsage as W;
|
use wgt::TextureUsage as W;
|
||||||
use hal::image::Usage as U;
|
use hal::image::Usage as U;
|
||||||
|
|
||||||
let mut value = U::empty();
|
let mut value = U::empty();
|
||||||
@ -524,10 +541,10 @@ pub fn map_buffer_state(usage: wgt::BufferUsage) -> hal::buffer::State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_texture_state(
|
pub fn map_texture_state(
|
||||||
usage: resource::TextureUsage,
|
usage: wgt::TextureUsage,
|
||||||
aspects: hal::format::Aspects,
|
aspects: hal::format::Aspects,
|
||||||
) -> hal::image::State {
|
) -> hal::image::State {
|
||||||
use crate::resource::TextureUsage as W;
|
use wgt::TextureUsage as W;
|
||||||
use hal::image::{Access as A, Layout as L};
|
use hal::image::{Access as A, Layout as L};
|
||||||
|
|
||||||
let is_color = aspects.contains(hal::format::Aspects::COLOR);
|
let is_color = aspects.contains(hal::format::Aspects::COLOR);
|
||||||
@ -567,17 +584,17 @@ pub fn map_texture_state(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_load_store_ops(
|
pub fn map_load_store_ops(
|
||||||
load: command::LoadOp,
|
load: wgt::LoadOp,
|
||||||
store: command::StoreOp,
|
store: wgt::StoreOp,
|
||||||
) -> hal::pass::AttachmentOps {
|
) -> hal::pass::AttachmentOps {
|
||||||
hal::pass::AttachmentOps {
|
hal::pass::AttachmentOps {
|
||||||
load: match load {
|
load: match load {
|
||||||
command::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
wgt::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
||||||
command::LoadOp::Load => hal::pass::AttachmentLoadOp::Load,
|
wgt::LoadOp::Load => hal::pass::AttachmentLoadOp::Load,
|
||||||
},
|
},
|
||||||
store: match store {
|
store: match store {
|
||||||
command::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO!
|
wgt::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO!
|
||||||
command::StoreOp::Store => hal::pass::AttachmentStoreOp::Store,
|
wgt::StoreOp::Store => hal::pass::AttachmentStoreOp::Store,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -367,7 +367,7 @@ impl<B: GfxBackend> Device<B> {
|
|||||||
match desc.format {
|
match desc.format {
|
||||||
TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => {
|
TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => {
|
||||||
assert!(!desc.usage.intersects(
|
assert!(!desc.usage.intersects(
|
||||||
resource::TextureUsage::COPY_SRC | resource::TextureUsage::COPY_DST
|
wgt::TextureUsage::COPY_SRC | wgt::TextureUsage::COPY_DST
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -1098,12 +1098,12 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
|||||||
binding_model::BindingResource::TextureView(id) => {
|
binding_model::BindingResource::TextureView(id) => {
|
||||||
let (usage, image_layout) = match decl.ty {
|
let (usage, image_layout) = match decl.ty {
|
||||||
binding_model::BindingType::SampledTexture => (
|
binding_model::BindingType::SampledTexture => (
|
||||||
resource::TextureUsage::SAMPLED,
|
wgt::TextureUsage::SAMPLED,
|
||||||
hal::image::Layout::ShaderReadOnlyOptimal,
|
hal::image::Layout::ShaderReadOnlyOptimal,
|
||||||
),
|
),
|
||||||
binding_model::BindingType::ReadonlyStorageTexture |
|
binding_model::BindingType::ReadonlyStorageTexture |
|
||||||
binding_model::BindingType::WriteonlyStorageTexture => {
|
binding_model::BindingType::WriteonlyStorageTexture => {
|
||||||
(resource::TextureUsage::STORAGE, hal::image::Layout::General)
|
(wgt::TextureUsage::STORAGE, hal::image::Layout::General)
|
||||||
}
|
}
|
||||||
_ => panic!("Mismatched texture binding for {:?}", decl),
|
_ => panic!("Mismatched texture binding for {:?}", decl),
|
||||||
};
|
};
|
||||||
@ -1235,7 +1235,7 @@ impl<F: IdentityFilter<id::CommandEncoderId>> Global<F> {
|
|||||||
pub fn device_create_command_encoder<B: GfxBackend>(
|
pub fn device_create_command_encoder<B: GfxBackend>(
|
||||||
&self,
|
&self,
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
_desc: &command::CommandEncoderDescriptor,
|
_desc: &wgt::CommandEncoderDescriptor,
|
||||||
id_in: F::Input,
|
id_in: F::Input,
|
||||||
) -> id::CommandEncoderId {
|
) -> id::CommandEncoderId {
|
||||||
let hub = B::hub(self);
|
let hub = B::hub(self);
|
||||||
@ -1848,7 +1848,7 @@ impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
|||||||
&self,
|
&self,
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
surface_id: id::SurfaceId,
|
surface_id: id::SurfaceId,
|
||||||
desc: &swap_chain::SwapChainDescriptor,
|
desc: &wgt::SwapChainDescriptor,
|
||||||
) -> id::SwapChainId {
|
) -> id::SwapChainId {
|
||||||
log::info!("creating swap chain {:?}", desc);
|
log::info!("creating swap chain {:?}", desc);
|
||||||
let hub = B::hub(self);
|
let hub = B::hub(self);
|
||||||
@ -1872,7 +1872,7 @@ impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
|||||||
let num_frames = swap_chain::DESIRED_NUM_FRAMES
|
let num_frames = swap_chain::DESIRED_NUM_FRAMES
|
||||||
.max(*caps.image_count.start())
|
.max(*caps.image_count.start())
|
||||||
.min(*caps.image_count.end());
|
.min(*caps.image_count.end());
|
||||||
let mut config = desc.to_hal(num_frames, device.features);
|
let mut config = swap_chain::swap_chain_descriptor_to_hal(&desc, num_frames, device.features);
|
||||||
if let Some(formats) = formats {
|
if let Some(formats) = formats {
|
||||||
assert!(
|
assert!(
|
||||||
formats.contains(&config.format),
|
formats.contains(&config.format),
|
||||||
|
|||||||
@ -31,7 +31,6 @@ pub mod swap_chain;
|
|||||||
pub mod track;
|
pub mod track;
|
||||||
|
|
||||||
pub use hal::pso::read_spirv;
|
pub use hal::pso::read_spirv;
|
||||||
use peek_poke::{PeekCopy, Poke};
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
os::raw::c_char,
|
os::raw::c_char,
|
||||||
@ -43,7 +42,6 @@ type SubmissionIndex = usize;
|
|||||||
type Index = u32;
|
type Index = u32;
|
||||||
type Epoch = u32;
|
type Epoch = u32;
|
||||||
|
|
||||||
pub type DynamicOffset = u32;
|
|
||||||
pub type RawString = *const c_char;
|
pub type RawString = *const c_char;
|
||||||
|
|
||||||
//TODO: make it private. Currently used for swapchain creation impl.
|
//TODO: make it private. Currently used for swapchain creation impl.
|
||||||
@ -110,54 +108,6 @@ struct Stored<T> {
|
|||||||
ref_count: RefCount,
|
ref_count: RefCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Copy, Debug, PeekCopy, Poke)]
|
|
||||||
pub struct Color {
|
|
||||||
pub r: f64,
|
|
||||||
pub g: f64,
|
|
||||||
pub b: f64,
|
|
||||||
pub a: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Color {
|
|
||||||
pub const TRANSPARENT: Self = Color {
|
|
||||||
r: 0.0,
|
|
||||||
g: 0.0,
|
|
||||||
b: 0.0,
|
|
||||||
a: 0.0,
|
|
||||||
};
|
|
||||||
pub const BLACK: Self = Color {
|
|
||||||
r: 0.0,
|
|
||||||
g: 0.0,
|
|
||||||
b: 0.0,
|
|
||||||
a: 1.0,
|
|
||||||
};
|
|
||||||
pub const WHITE: Self = Color {
|
|
||||||
r: 1.0,
|
|
||||||
g: 1.0,
|
|
||||||
b: 1.0,
|
|
||||||
a: 1.0,
|
|
||||||
};
|
|
||||||
pub const RED: Self = Color {
|
|
||||||
r: 1.0,
|
|
||||||
g: 0.0,
|
|
||||||
b: 0.0,
|
|
||||||
a: 1.0,
|
|
||||||
};
|
|
||||||
pub const GREEN: Self = Color {
|
|
||||||
r: 0.0,
|
|
||||||
g: 1.0,
|
|
||||||
b: 0.0,
|
|
||||||
a: 1.0,
|
|
||||||
};
|
|
||||||
pub const BLUE: Self = Color {
|
|
||||||
r: 0.0,
|
|
||||||
g: 0.0,
|
|
||||||
b: 1.0,
|
|
||||||
a: 1.0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Origin3d {
|
pub struct Origin3d {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use crate::{
|
|||||||
Stored,
|
Stored,
|
||||||
};
|
};
|
||||||
|
|
||||||
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat};
|
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat, TextureUsage};
|
||||||
use hal;
|
use hal;
|
||||||
use rendy_memory::MemoryBlock;
|
use rendy_memory::MemoryBlock;
|
||||||
|
|
||||||
@ -101,27 +101,6 @@ pub enum TextureDimension {
|
|||||||
D3,
|
D3,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags::bitflags! {
|
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct TextureUsage: u32 {
|
|
||||||
const COPY_SRC = 1;
|
|
||||||
const COPY_DST = 2;
|
|
||||||
const SAMPLED = 4;
|
|
||||||
const STORAGE = 8;
|
|
||||||
const OUTPUT_ATTACHMENT = 16;
|
|
||||||
const NONE = 0;
|
|
||||||
/// The combination of all read-only usages.
|
|
||||||
const READ_ALL = Self::COPY_SRC.bits | Self::SAMPLED.bits;
|
|
||||||
/// The combination of all write-only and read-write usages.
|
|
||||||
const WRITE_ALL = Self::COPY_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.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 | Self::OUTPUT_ATTACHMENT.bits;
|
|
||||||
const UNINITIALIZED = 0xFFFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TextureDescriptor {
|
pub struct TextureDescriptor {
|
||||||
|
|||||||
@ -37,13 +37,12 @@ use crate::{
|
|||||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||||
id::{DeviceId, SwapChainId, TextureViewId},
|
id::{DeviceId, SwapChainId, TextureViewId},
|
||||||
resource,
|
resource,
|
||||||
Extent3d,
|
|
||||||
Features,
|
Features,
|
||||||
LifeGuard,
|
LifeGuard,
|
||||||
Stored,
|
Stored,
|
||||||
};
|
};
|
||||||
|
|
||||||
use wgt::TextureFormat;
|
use wgt::SwapChainDescriptor;
|
||||||
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
|
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
|
||||||
|
|
||||||
|
|
||||||
@ -61,75 +60,28 @@ pub struct SwapChain<B: hal::Backend> {
|
|||||||
pub(crate) acquired_framebuffers: Vec<B::Framebuffer>,
|
pub(crate) acquired_framebuffers: Vec<B::Framebuffer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
pub(crate) fn swap_chain_descriptor_to_hal(
|
||||||
#[derive(Copy, Clone, Debug)]
|
desc: &SwapChainDescriptor,
|
||||||
pub enum PresentMode {
|
|
||||||
/// The presentation engine does **not** wait for a vertical blanking period and
|
|
||||||
/// the request is presented immediately. This is a low-latency presentation mode,
|
|
||||||
/// but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the
|
|
||||||
/// selected platform and backend. Not optimal for mobile.
|
|
||||||
Immediate = 0,
|
|
||||||
/// The presentation engine waits for the next vertical blanking period to update
|
|
||||||
/// the current image, but frames may be submitted without delay. This is a low-latency
|
|
||||||
/// presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo`
|
|
||||||
/// if unavailable on the selected platform and backend. Not optimal for mobile.
|
|
||||||
Mailbox = 1,
|
|
||||||
/// The presentation engine waits for the next vertical blanking period to update
|
|
||||||
/// the current image. The framerate will be capped at the display refresh rate,
|
|
||||||
/// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
|
|
||||||
Fifo = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SwapChainDescriptor {
|
|
||||||
pub usage: resource::TextureUsage,
|
|
||||||
pub format: TextureFormat,
|
|
||||||
pub width: u32,
|
|
||||||
pub height: u32,
|
|
||||||
pub present_mode: PresentMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SwapChainDescriptor {
|
|
||||||
pub(crate) fn to_hal(
|
|
||||||
&self,
|
|
||||||
num_frames: u32,
|
num_frames: u32,
|
||||||
features: Features,
|
features: Features,
|
||||||
) -> hal::window::SwapchainConfig {
|
) -> hal::window::SwapchainConfig {
|
||||||
let mut config = hal::window::SwapchainConfig::new(
|
let mut config = hal::window::SwapchainConfig::new(
|
||||||
self.width,
|
desc.width,
|
||||||
self.height,
|
desc.height,
|
||||||
conv::map_texture_format(self.format, features),
|
conv::map_texture_format(desc.format, features),
|
||||||
num_frames,
|
num_frames,
|
||||||
);
|
);
|
||||||
//TODO: check for supported
|
//TODO: check for supported
|
||||||
config.image_usage = conv::map_texture_usage(self.usage, hal::format::Aspects::COLOR);
|
config.image_usage = conv::map_texture_usage(desc.usage, hal::format::Aspects::COLOR);
|
||||||
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
|
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
|
||||||
config.present_mode = match self.present_mode {
|
config.present_mode = match desc.present_mode {
|
||||||
PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE,
|
wgt::PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE,
|
||||||
PresentMode::Mailbox => hal::window::PresentMode::MAILBOX,
|
wgt::PresentMode::Mailbox => hal::window::PresentMode::MAILBOX,
|
||||||
PresentMode::Fifo => hal::window::PresentMode::FIFO,
|
wgt::PresentMode::Fifo => hal::window::PresentMode::FIFO,
|
||||||
};
|
};
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_texture_desc(&self) -> resource::TextureDescriptor {
|
|
||||||
resource::TextureDescriptor {
|
|
||||||
size: Extent3d {
|
|
||||||
width: self.width,
|
|
||||||
height: self.height,
|
|
||||||
depth: 1,
|
|
||||||
},
|
|
||||||
mip_level_count: 1,
|
|
||||||
array_layer_count: 1,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: resource::TextureDimension::D2,
|
|
||||||
format: self.format,
|
|
||||||
usage: self.usage,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SwapChainOutput {
|
pub struct SwapChainOutput {
|
||||||
@ -166,7 +118,7 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
|
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
|
||||||
let desc = sc.desc.to_hal(sc.num_frames, device.features);
|
let desc = swap_chain_descriptor_to_hal(&sc.desc, sc.num_frames, device.features);
|
||||||
unsafe {
|
unsafe {
|
||||||
suf.configure_swapchain(&device.raw, desc).unwrap();
|
suf.configure_swapchain(&device.raw, desc).unwrap();
|
||||||
suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap()
|
suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap()
|
||||||
|
|||||||
@ -3,8 +3,9 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use super::{range::RangedStates, PendingTransition, ResourceState, Unit};
|
use super::{range::RangedStates, PendingTransition, ResourceState, Unit};
|
||||||
use crate::{device::MAX_MIP_LEVELS, id::TextureId, resource::TextureUsage};
|
use crate::{device::MAX_MIP_LEVELS, id::TextureId};
|
||||||
|
|
||||||
|
use wgt::TextureUsage;
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
|
||||||
use std::{iter, ops::Range};
|
use std::{iter, ops::Range};
|
||||||
|
|||||||
@ -301,7 +301,7 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wgpu_device_create_command_encoder(
|
pub extern "C" fn wgpu_device_create_command_encoder(
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
desc: Option<&core::command::CommandEncoderDescriptor>,
|
desc: Option<&wgt::CommandEncoderDescriptor>,
|
||||||
) -> id::CommandEncoderId {
|
) -> id::CommandEncoderId {
|
||||||
let desc = &desc.cloned().unwrap_or_default();
|
let desc = &desc.cloned().unwrap_or_default();
|
||||||
gfx_select!(device_id => GLOBAL.device_create_command_encoder(device_id, desc, PhantomData))
|
gfx_select!(device_id => GLOBAL.device_create_command_encoder(device_id, desc, PhantomData))
|
||||||
@ -357,7 +357,7 @@ pub extern "C" fn wgpu_device_create_compute_pipeline(
|
|||||||
pub extern "C" fn wgpu_device_create_swap_chain(
|
pub extern "C" fn wgpu_device_create_swap_chain(
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
surface_id: id::SurfaceId,
|
surface_id: id::SurfaceId,
|
||||||
desc: &core::swap_chain::SwapChainDescriptor,
|
desc: &wgt::SwapChainDescriptor,
|
||||||
) -> id::SwapChainId {
|
) -> id::SwapChainId {
|
||||||
gfx_select!(device_id => GLOBAL.device_create_swap_chain(device_id, surface_id, desc))
|
gfx_select!(device_id => GLOBAL.device_create_swap_chain(device_id, surface_id, desc))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,7 +142,7 @@ pub extern "C" fn wgpu_server_buffer_destroy(global: &Global, self_id: id::Buffe
|
|||||||
pub extern "C" fn wgpu_server_device_create_encoder(
|
pub extern "C" fn wgpu_server_device_create_encoder(
|
||||||
global: &Global,
|
global: &Global,
|
||||||
self_id: id::DeviceId,
|
self_id: id::DeviceId,
|
||||||
desc: &core::command::CommandEncoderDescriptor,
|
desc: &wgt::CommandEncoderDescriptor,
|
||||||
new_id: id::CommandEncoderId,
|
new_id: id::CommandEncoderId,
|
||||||
) {
|
) {
|
||||||
gfx_select!(self_id => global.device_create_command_encoder(self_id, &desc, new_id));
|
gfx_select!(self_id => global.device_create_command_encoder(self_id, &desc, new_id));
|
||||||
|
|||||||
@ -17,3 +17,4 @@ license = "MPL-2.0"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
serde = { version = "1.0", features = ["serde_derive"], optional = true }
|
serde = { version = "1.0", features = ["serde_derive"], optional = true }
|
||||||
|
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075", optional = true }
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
use std::{io, slice};
|
use std::{io, slice};
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
#[cfg(feature = "peek-poke")]
|
||||||
|
use peek_poke::{PeekCopy, Poke};
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
@ -540,3 +542,152 @@ pub struct BufferDescriptor {
|
|||||||
pub size: BufferAddress,
|
pub size: BufferAddress,
|
||||||
pub usage: BufferUsage,
|
pub usage: BufferUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
pub struct CommandEncoderDescriptor {
|
||||||
|
// MSVC doesn't allow zero-sized structs
|
||||||
|
// We can remove this when we actually have a field
|
||||||
|
pub todo: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DynamicOffset = u32;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub enum PresentMode {
|
||||||
|
/// The presentation engine does **not** wait for a vertical blanking period and
|
||||||
|
/// the request is presented immediately. This is a low-latency presentation mode,
|
||||||
|
/// but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the
|
||||||
|
/// selected platform and backend. Not optimal for mobile.
|
||||||
|
Immediate = 0,
|
||||||
|
/// The presentation engine waits for the next vertical blanking period to update
|
||||||
|
/// the current image, but frames may be submitted without delay. This is a low-latency
|
||||||
|
/// presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo`
|
||||||
|
/// if unavailable on the selected platform and backend. Not optimal for mobile.
|
||||||
|
Mailbox = 1,
|
||||||
|
/// The presentation engine waits for the next vertical blanking period to update
|
||||||
|
/// the current image. The framerate will be capped at the display refresh rate,
|
||||||
|
/// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
|
||||||
|
Fifo = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct TextureUsage: u32 {
|
||||||
|
const COPY_SRC = 1;
|
||||||
|
const COPY_DST = 2;
|
||||||
|
const SAMPLED = 4;
|
||||||
|
const STORAGE = 8;
|
||||||
|
const OUTPUT_ATTACHMENT = 16;
|
||||||
|
const NONE = 0;
|
||||||
|
/// The combination of all read-only usages.
|
||||||
|
const READ_ALL = Self::COPY_SRC.bits | Self::SAMPLED.bits;
|
||||||
|
/// The combination of all write-only and read-write usages.
|
||||||
|
const WRITE_ALL = Self::COPY_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.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 | Self::OUTPUT_ATTACHMENT.bits;
|
||||||
|
const UNINITIALIZED = 0xFFFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct SwapChainDescriptor {
|
||||||
|
pub usage: TextureUsage,
|
||||||
|
pub format: TextureFormat,
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub present_mode: PresentMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
|
||||||
|
pub enum LoadOp {
|
||||||
|
Clear = 0,
|
||||||
|
Load = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
|
||||||
|
pub enum StoreOp {
|
||||||
|
Clear = 0,
|
||||||
|
Store = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
|
||||||
|
pub struct RenderPassColorAttachmentDescriptorBase<T, R> {
|
||||||
|
pub attachment: T,
|
||||||
|
pub resolve_target: R,
|
||||||
|
pub load_op: LoadOp,
|
||||||
|
pub store_op: StoreOp,
|
||||||
|
pub clear_color: Color,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
|
||||||
|
pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
|
||||||
|
pub attachment: T,
|
||||||
|
pub depth_load_op: LoadOp,
|
||||||
|
pub depth_store_op: StoreOp,
|
||||||
|
pub clear_depth: f32,
|
||||||
|
pub stencil_load_op: LoadOp,
|
||||||
|
pub stencil_store_op: StoreOp,
|
||||||
|
pub clear_stencil: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "peek-poke", derive(PeekCopy, Poke))]
|
||||||
|
pub struct Color {
|
||||||
|
pub r: f64,
|
||||||
|
pub g: f64,
|
||||||
|
pub b: f64,
|
||||||
|
pub a: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Color {
|
||||||
|
pub const TRANSPARENT: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 0.0,
|
||||||
|
};
|
||||||
|
pub const BLACK: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const WHITE: Self = Color {
|
||||||
|
r: 1.0,
|
||||||
|
g: 1.0,
|
||||||
|
b: 1.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const RED: Self = Color {
|
||||||
|
r: 1.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const GREEN: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 1.0,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
pub const BLUE: Self = Color {
|
||||||
|
r: 0.0,
|
||||||
|
g: 0.0,
|
||||||
|
b: 1.0,
|
||||||
|
a: 1.0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user