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"
|
||||
dependencies = [
|
||||
"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)",
|
||||
]
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@ optional = true
|
||||
path = "../wgpu-types"
|
||||
package = "wgpu-types"
|
||||
version = "0.1"
|
||||
features = ["peek-poke"]
|
||||
|
||||
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
||||
gfx-backend-metal = { version = "0.4" }
|
||||
|
||||
@ -6,12 +6,11 @@ use crate::{
|
||||
binding_model::BindGroup,
|
||||
hub::GfxBackend,
|
||||
id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId},
|
||||
DynamicOffset,
|
||||
Stored,
|
||||
};
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use wgt::DynamicOffset;
|
||||
use std::slice;
|
||||
|
||||
pub const DEFAULT_BIND_GROUPS: usize = 4;
|
||||
|
||||
@ -11,10 +11,9 @@ use crate::{
|
||||
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
|
||||
hub::{GfxBackend, Global, Token},
|
||||
id,
|
||||
DynamicOffset,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage};
|
||||
use wgt::{BufferAddress, BufferUsage, DynamicOffset};
|
||||
use hal::command::CommandBuffer as _;
|
||||
use peek_poke::{Peek, PeekCopy, Poke};
|
||||
|
||||
@ -221,10 +220,9 @@ pub mod compute_ffi {
|
||||
};
|
||||
use crate::{
|
||||
id,
|
||||
DynamicOffset,
|
||||
RawString,
|
||||
};
|
||||
use wgt::BufferAddress;
|
||||
use wgt::{BufferAddress, DynamicOffset};
|
||||
use std::{convert::TryInto, slice};
|
||||
|
||||
/// # Safety
|
||||
|
||||
@ -35,6 +35,7 @@ use std::{
|
||||
slice,
|
||||
thread::ThreadId,
|
||||
};
|
||||
use wgt::RenderPassColorAttachmentDescriptorBase;
|
||||
|
||||
|
||||
#[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)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CommandBufferDescriptor {
|
||||
|
||||
@ -21,14 +21,23 @@ use crate::{
|
||||
hub::{GfxBackend, Global, Token},
|
||||
id,
|
||||
pipeline::PipelineFlags,
|
||||
resource::{TextureUsage, TextureViewInner},
|
||||
resource::TextureViewInner,
|
||||
track::TrackerSet,
|
||||
Color,
|
||||
DynamicOffset,
|
||||
Stored,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage, IndexFormat, InputStepMode};
|
||||
use wgt::{
|
||||
BufferAddress,
|
||||
BufferUsage,
|
||||
Color,
|
||||
DynamicOffset,
|
||||
IndexFormat,
|
||||
InputStepMode,
|
||||
LoadOp,
|
||||
RenderPassColorAttachmentDescriptorBase,
|
||||
RenderPassDepthStencilAttachmentDescriptorBase,
|
||||
TextureUsage,
|
||||
};
|
||||
use arrayvec::ArrayVec;
|
||||
use hal::command::CommandBuffer as _;
|
||||
use peek_poke::{Peek, PeekCopy, Poke};
|
||||
@ -43,45 +52,8 @@ use std::{
|
||||
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
|
||||
// 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 RenderPassColorAttachmentDescriptor<'a> =
|
||||
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, OptionRef<'a, id::TextureViewId>>;
|
||||
@ -1156,11 +1128,9 @@ pub mod render_ffi {
|
||||
};
|
||||
use crate::{
|
||||
id,
|
||||
Color,
|
||||
DynamicOffset,
|
||||
RawString,
|
||||
};
|
||||
use wgt::BufferAddress;
|
||||
use wgt::{BufferAddress, Color, DynamicOffset};
|
||||
use std::{convert::TryInto, slice};
|
||||
|
||||
/// # Safety
|
||||
|
||||
@ -7,12 +7,11 @@ use crate::{
|
||||
device::{all_buffer_stages, all_image_stages},
|
||||
hub::{GfxBackend, Global, Token},
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
resource::TextureUsage,
|
||||
Extent3d,
|
||||
Origin3d,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage};
|
||||
use wgt::{BufferAddress, BufferUsage, TextureUsage};
|
||||
use hal::command::CommandBuffer as _;
|
||||
|
||||
use std::iter;
|
||||
|
||||
@ -2,8 +2,25 @@
|
||||
* 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, resource, Color, Extent3d, Features, Origin3d};
|
||||
use wgt::{BlendDescriptor, BlendFactor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat, PrimitiveTopology, StencilOperation, StencilStateFaceDescriptor, TextureFormat, RasterizationStateDescriptor, VertexFormat};
|
||||
use crate::{binding_model, resource, Extent3d, Features, Origin3d};
|
||||
use wgt::{
|
||||
BlendDescriptor,
|
||||
BlendFactor,
|
||||
Color,
|
||||
ColorStateDescriptor,
|
||||
ColorWrite,
|
||||
CompareFunction,
|
||||
CullMode,
|
||||
DepthStencilStateDescriptor,
|
||||
FrontFace,
|
||||
IndexFormat,
|
||||
PrimitiveTopology,
|
||||
StencilOperation,
|
||||
StencilStateFaceDescriptor,
|
||||
TextureFormat,
|
||||
RasterizationStateDescriptor,
|
||||
VertexFormat,
|
||||
};
|
||||
|
||||
pub fn map_buffer_usage(
|
||||
usage: wgt::BufferUsage,
|
||||
@ -47,10 +64,10 @@ pub fn map_buffer_usage(
|
||||
}
|
||||
|
||||
pub fn map_texture_usage(
|
||||
usage: resource::TextureUsage,
|
||||
usage: wgt::TextureUsage,
|
||||
aspects: hal::format::Aspects,
|
||||
) -> hal::image::Usage {
|
||||
use crate::resource::TextureUsage as W;
|
||||
use wgt::TextureUsage as W;
|
||||
use hal::image::Usage as U;
|
||||
|
||||
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(
|
||||
usage: resource::TextureUsage,
|
||||
usage: wgt::TextureUsage,
|
||||
aspects: hal::format::Aspects,
|
||||
) -> hal::image::State {
|
||||
use crate::resource::TextureUsage as W;
|
||||
use wgt::TextureUsage as W;
|
||||
use hal::image::{Access as A, Layout as L};
|
||||
|
||||
let is_color = aspects.contains(hal::format::Aspects::COLOR);
|
||||
@ -567,17 +584,17 @@ pub fn map_texture_state(
|
||||
}
|
||||
|
||||
pub fn map_load_store_ops(
|
||||
load: command::LoadOp,
|
||||
store: command::StoreOp,
|
||||
load: wgt::LoadOp,
|
||||
store: wgt::StoreOp,
|
||||
) -> hal::pass::AttachmentOps {
|
||||
hal::pass::AttachmentOps {
|
||||
load: match load {
|
||||
command::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
||||
command::LoadOp::Load => hal::pass::AttachmentLoadOp::Load,
|
||||
wgt::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear,
|
||||
wgt::LoadOp::Load => hal::pass::AttachmentLoadOp::Load,
|
||||
},
|
||||
store: match store {
|
||||
command::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO!
|
||||
command::StoreOp::Store => hal::pass::AttachmentStoreOp::Store,
|
||||
wgt::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO!
|
||||
wgt::StoreOp::Store => hal::pass::AttachmentStoreOp::Store,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
match desc.format {
|
||||
TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => {
|
||||
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) => {
|
||||
let (usage, image_layout) = match decl.ty {
|
||||
binding_model::BindingType::SampledTexture => (
|
||||
resource::TextureUsage::SAMPLED,
|
||||
wgt::TextureUsage::SAMPLED,
|
||||
hal::image::Layout::ShaderReadOnlyOptimal,
|
||||
),
|
||||
binding_model::BindingType::ReadonlyStorageTexture |
|
||||
binding_model::BindingType::WriteonlyStorageTexture => {
|
||||
(resource::TextureUsage::STORAGE, hal::image::Layout::General)
|
||||
(wgt::TextureUsage::STORAGE, hal::image::Layout::General)
|
||||
}
|
||||
_ => 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>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
_desc: &command::CommandEncoderDescriptor,
|
||||
_desc: &wgt::CommandEncoderDescriptor,
|
||||
id_in: F::Input,
|
||||
) -> id::CommandEncoderId {
|
||||
let hub = B::hub(self);
|
||||
@ -1848,7 +1848,7 @@ impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
surface_id: id::SurfaceId,
|
||||
desc: &swap_chain::SwapChainDescriptor,
|
||||
desc: &wgt::SwapChainDescriptor,
|
||||
) -> id::SwapChainId {
|
||||
log::info!("creating swap chain {:?}", desc);
|
||||
let hub = B::hub(self);
|
||||
@ -1872,7 +1872,7 @@ impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
||||
let num_frames = swap_chain::DESIRED_NUM_FRAMES
|
||||
.max(*caps.image_count.start())
|
||||
.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 {
|
||||
assert!(
|
||||
formats.contains(&config.format),
|
||||
|
||||
@ -31,7 +31,6 @@ pub mod swap_chain;
|
||||
pub mod track;
|
||||
|
||||
pub use hal::pso::read_spirv;
|
||||
use peek_poke::{PeekCopy, Poke};
|
||||
|
||||
use std::{
|
||||
os::raw::c_char,
|
||||
@ -43,7 +42,6 @@ type SubmissionIndex = usize;
|
||||
type Index = u32;
|
||||
type Epoch = u32;
|
||||
|
||||
pub type DynamicOffset = u32;
|
||||
pub type RawString = *const c_char;
|
||||
|
||||
//TODO: make it private. Currently used for swapchain creation impl.
|
||||
@ -110,54 +108,6 @@ struct Stored<T> {
|
||||
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)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Origin3d {
|
||||
|
||||
@ -11,7 +11,7 @@ use crate::{
|
||||
Stored,
|
||||
};
|
||||
|
||||
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat};
|
||||
use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat, TextureUsage};
|
||||
use hal;
|
||||
use rendy_memory::MemoryBlock;
|
||||
|
||||
@ -101,27 +101,6 @@ pub enum TextureDimension {
|
||||
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)]
|
||||
#[derive(Debug)]
|
||||
pub struct TextureDescriptor {
|
||||
|
||||
@ -37,13 +37,12 @@ use crate::{
|
||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||
id::{DeviceId, SwapChainId, TextureViewId},
|
||||
resource,
|
||||
Extent3d,
|
||||
Features,
|
||||
LifeGuard,
|
||||
Stored,
|
||||
};
|
||||
|
||||
use wgt::TextureFormat;
|
||||
use wgt::SwapChainDescriptor;
|
||||
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
|
||||
|
||||
|
||||
@ -61,73 +60,26 @@ pub struct SwapChain<B: hal::Backend> {
|
||||
pub(crate) acquired_framebuffers: Vec<B::Framebuffer>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[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,
|
||||
features: Features,
|
||||
) -> hal::window::SwapchainConfig {
|
||||
let mut config = hal::window::SwapchainConfig::new(
|
||||
self.width,
|
||||
self.height,
|
||||
conv::map_texture_format(self.format, features),
|
||||
num_frames,
|
||||
);
|
||||
//TODO: check for supported
|
||||
config.image_usage = conv::map_texture_usage(self.usage, hal::format::Aspects::COLOR);
|
||||
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
|
||||
config.present_mode = match self.present_mode {
|
||||
PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE,
|
||||
PresentMode::Mailbox => hal::window::PresentMode::MAILBOX,
|
||||
PresentMode::Fifo => hal::window::PresentMode::FIFO,
|
||||
};
|
||||
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,
|
||||
}
|
||||
}
|
||||
pub(crate) fn swap_chain_descriptor_to_hal(
|
||||
desc: &SwapChainDescriptor,
|
||||
num_frames: u32,
|
||||
features: Features,
|
||||
) -> hal::window::SwapchainConfig {
|
||||
let mut config = hal::window::SwapchainConfig::new(
|
||||
desc.width,
|
||||
desc.height,
|
||||
conv::map_texture_format(desc.format, features),
|
||||
num_frames,
|
||||
);
|
||||
//TODO: check for supported
|
||||
config.image_usage = conv::map_texture_usage(desc.usage, hal::format::Aspects::COLOR);
|
||||
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
|
||||
config.present_mode = match desc.present_mode {
|
||||
wgt::PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE,
|
||||
wgt::PresentMode::Mailbox => hal::window::PresentMode::MAILBOX,
|
||||
wgt::PresentMode::Fifo => hal::window::PresentMode::FIFO,
|
||||
};
|
||||
config
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -166,7 +118,7 @@ impl<F: IdentityFilter<TextureViewId>> Global<F> {
|
||||
}
|
||||
Err(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 {
|
||||
suf.configure_swapchain(&device.raw, desc).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/. */
|
||||
|
||||
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 std::{iter, ops::Range};
|
||||
|
||||
@ -301,7 +301,7 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_create_command_encoder(
|
||||
device_id: id::DeviceId,
|
||||
desc: Option<&core::command::CommandEncoderDescriptor>,
|
||||
desc: Option<&wgt::CommandEncoderDescriptor>,
|
||||
) -> id::CommandEncoderId {
|
||||
let desc = &desc.cloned().unwrap_or_default();
|
||||
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(
|
||||
device_id: id::DeviceId,
|
||||
surface_id: id::SurfaceId,
|
||||
desc: &core::swap_chain::SwapChainDescriptor,
|
||||
desc: &wgt::SwapChainDescriptor,
|
||||
) -> id::SwapChainId {
|
||||
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(
|
||||
global: &Global,
|
||||
self_id: id::DeviceId,
|
||||
desc: &core::command::CommandEncoderDescriptor,
|
||||
desc: &wgt::CommandEncoderDescriptor,
|
||||
new_id: id::CommandEncoderId,
|
||||
) {
|
||||
gfx_select!(self_id => global.device_create_command_encoder(self_id, &desc, new_id));
|
||||
|
||||
@ -17,3 +17,4 @@ license = "MPL-2.0"
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
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};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
#[cfg(feature = "peek-poke")]
|
||||
use peek_poke::{PeekCopy, Poke};
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@ -540,3 +542,152 @@ pub struct BufferDescriptor {
|
||||
pub size: BufferAddress,
|
||||
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