diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 2f83aef961..a348c050cc 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -195,12 +195,6 @@ impl CommandBuffer { } } -#[repr(C)] -#[derive(Clone, Debug, Default)] -pub struct CommandBufferDescriptor { - pub todo: u32, -} - pub type RawRenderPassColorAttachmentDescriptor = RenderPassColorAttachmentDescriptorBase; @@ -215,7 +209,7 @@ impl Global { pub fn command_encoder_finish( &self, encoder_id: id::CommandEncoderId, - _desc: &CommandBufferDescriptor, + _desc: &wgt::CommandBufferDescriptor, ) -> id::CommandBufferId { let hub = B::hub(self); let mut token = Token::root(); diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 58fe147368..040eb7b799 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -7,11 +7,9 @@ use crate::{ device::{all_buffer_stages, all_image_stages}, hub::{GfxBackend, Global, Token}, id::{BufferId, CommandEncoderId, TextureId}, - Extent3d, - Origin3d, }; -use wgt::{BufferAddress, BufferUsage, TextureUsage}; +use wgt::{BufferAddress, BufferUsage, Extent3d, Origin3d, TextureUsage}; use hal::command::CommandBuffer as _; use std::iter; diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 1380a3f685..2bf74d88ef 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -2,7 +2,7 @@ * 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, resource, Extent3d, Features, Origin3d}; +use crate::{binding_model, Features}; use wgt::{ BlendDescriptor, BlendFactor, @@ -12,13 +12,15 @@ use wgt::{ CompareFunction, CullMode, DepthStencilStateDescriptor, + Extent3d, FrontFace, IndexFormat, + Origin3d, PrimitiveTopology, + RasterizationStateDescriptor, StencilOperation, StencilStateFaceDescriptor, TextureFormat, - RasterizationStateDescriptor, VertexFormat, }; @@ -450,7 +452,7 @@ fn checked_u32_as_u16(value: u32) -> u16 { } pub fn map_texture_dimension_size( - dimension: resource::TextureDimension, + dimension: wgt::TextureDimension, Extent3d { width, height, @@ -459,7 +461,7 @@ pub fn map_texture_dimension_size( array_size: u32, sample_size: u32, ) -> hal::image::Kind { - use crate::resource::TextureDimension::*; + use wgt::TextureDimension::*; use hal::image::Kind as H; match dimension { D1 => { @@ -624,15 +626,15 @@ pub fn map_color_u32(color: &Color) -> [u32; 4] { ] } -pub fn map_filter(filter: resource::FilterMode) -> hal::image::Filter { +pub fn map_filter(filter: wgt::FilterMode) -> hal::image::Filter { match filter { - resource::FilterMode::Nearest => hal::image::Filter::Nearest, - resource::FilterMode::Linear => hal::image::Filter::Linear, + wgt::FilterMode::Nearest => hal::image::Filter::Nearest, + wgt::FilterMode::Linear => hal::image::Filter::Linear, } } -pub fn map_wrap(address: resource::AddressMode) -> hal::image::WrapMode { - use crate::resource::AddressMode as Am; +pub fn map_wrap(address: wgt::AddressMode) -> hal::image::WrapMode { + use wgt::AddressMode as Am; use hal::image::WrapMode as W; match address { Am::ClampToEdge => W::Clamp, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index b9ca86209a..f138b6d282 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -18,7 +18,7 @@ use crate::{ Stored, }; -use wgt::{BufferAddress, InputStepMode, TextureFormat}; +use wgt::{BufferAddress, InputStepMode, TextureDimension, TextureFormat}; use arrayvec::ArrayVec; use copyless::VecHelper as _; use hal::{ @@ -359,7 +359,7 @@ impl Device { fn create_texture( &self, self_id: id::DeviceId, - desc: &resource::TextureDescriptor, + desc: &wgt::TextureDescriptor, ) -> resource::Texture { debug_assert_eq!(self_id.backend(), B::VARIANT); @@ -388,7 +388,7 @@ impl Device { // 2D textures with array layer counts that are multiples of 6 could be cubemaps // Following gpuweb/gpuweb#68 always add the hint in that case - if desc.dimension == resource::TextureDimension::D2 && desc.array_layer_count % 6 == 0 { + if desc.dimension == TextureDimension::D2 && desc.array_layer_count % 6 == 0 { view_capabilities |= hal::image::ViewCapabilities::KIND_CUBE; }; @@ -649,7 +649,7 @@ impl> Global { pub fn device_create_texture( &self, device_id: id::DeviceId, - desc: &resource::TextureDescriptor, + desc: &wgt::TextureDescriptor, id_in: F::Input, ) -> id::TextureId { let hub = B::hub(self); @@ -695,7 +695,7 @@ impl> Global { pub fn texture_create_view( &self, texture_id: id::TextureId, - desc: Option<&resource::TextureViewDescriptor>, + desc: Option<&wgt::TextureViewDescriptor>, id_in: F::Input, ) -> id::TextureViewId { let hub = B::hub(self); @@ -806,7 +806,7 @@ impl> Global { pub fn device_create_sampler( &self, device_id: id::DeviceId, - desc: &resource::SamplerDescriptor, + desc: &wgt::SamplerDescriptor, id_in: F::Input, ) -> id::SamplerId { let hub = B::hub(self); diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 2cd1dcfdf1..827ba8fe96 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -108,36 +108,6 @@ struct Stored { ref_count: RefCount, } -#[repr(C)] -#[derive(Clone, Copy, Debug)] -pub struct Origin3d { - pub x: u32, - pub y: u32, - pub z: u32, -} - -impl Origin3d { - pub const ZERO: Self = Origin3d { - x: 0, - y: 0, - z: 0, - }; -} - -impl Default for Origin3d { - fn default() -> Self { - Origin3d::ZERO - } -} - -#[repr(C)] -#[derive(Clone, Copy, Debug)] -pub struct Extent3d { - pub width: u32, - pub height: u32, - pub depth: u32, -} - #[repr(C)] #[derive(Debug)] pub struct U32Array { diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 4a923e8bf9..36c56b5af4 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -5,13 +5,17 @@ use crate::{ id::{DeviceId, SwapChainId, TextureId}, track::DUMMY_SELECTOR, - Extent3d, LifeGuard, RefCount, Stored, }; -use wgt::{BufferAddress, BufferUsage, CompareFunction, TextureFormat, TextureUsage}; +use wgt::{ + BufferAddress, + BufferUsage, + TextureFormat, + TextureUsage, +}; use hal; use rendy_memory::MemoryBlock; @@ -93,26 +97,6 @@ impl Borrow<()> for Buffer { } } -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -pub enum TextureDimension { - D1, - D2, - D3, -} - -#[repr(C)] -#[derive(Debug)] -pub struct TextureDescriptor { - pub size: Extent3d, - pub array_layer_count: u32, - pub mip_level_count: u32, - pub sample_count: u32, - pub dimension: TextureDimension, - pub format: TextureFormat, - pub usage: TextureUsage, -} - #[derive(Debug)] pub struct Texture { pub(crate) raw: B::Image, @@ -137,32 +121,6 @@ impl Borrow for Texture { } } -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -pub enum TextureAspect { - All, - StencilOnly, - DepthOnly, -} - -impl Default for TextureAspect { - fn default() -> Self { - TextureAspect::All - } -} - -#[repr(C)] -#[derive(Debug)] -pub struct TextureViewDescriptor { - pub format: TextureFormat, - pub dimension: wgt::TextureViewDimension, - pub aspect: TextureAspect, - pub base_mip_level: u32, - pub level_count: u32, - pub base_array_layer: u32, - pub array_layer_count: u32, -} - #[derive(Debug)] pub(crate) enum TextureViewInner { Native { @@ -198,47 +156,6 @@ impl Borrow<()> for TextureView { } } -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -pub enum AddressMode { - ClampToEdge = 0, - Repeat = 1, - MirrorRepeat = 2, -} - -impl Default for AddressMode { - fn default() -> Self { - AddressMode::ClampToEdge - } -} - -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -pub enum FilterMode { - Nearest = 0, - Linear = 1, -} - -impl Default for FilterMode { - fn default() -> Self { - FilterMode::Nearest - } -} - -#[repr(C)] -#[derive(Debug)] -pub struct SamplerDescriptor<'a> { - pub address_mode_u: AddressMode, - pub address_mode_v: AddressMode, - pub address_mode_w: AddressMode, - pub mag_filter: FilterMode, - pub min_filter: FilterMode, - pub mipmap_filter: FilterMode, - pub lod_min_clamp: f32, - pub lod_max_clamp: f32, - pub compare: Option<&'a CompareFunction>, -} - #[derive(Debug)] pub struct Sampler { pub(crate) raw: B::Sampler, diff --git a/wgpu-native/src/command.rs b/wgpu-native/src/command.rs index e1b3a3132f..8001b4caa7 100644 --- a/wgpu-native/src/command.rs +++ b/wgpu-native/src/command.rs @@ -15,7 +15,7 @@ use core::{gfx_select, id}; #[no_mangle] pub extern "C" fn wgpu_command_encoder_finish( encoder_id: id::CommandEncoderId, - desc: Option<&core::command::CommandBufferDescriptor>, + desc: Option<&wgt::CommandBufferDescriptor>, ) -> id::CommandBufferId { let desc = &desc.cloned().unwrap_or_default(); gfx_select!(encoder_id => GLOBAL.command_encoder_finish(encoder_id, desc)) @@ -43,7 +43,7 @@ pub extern "C" fn wgpu_command_encoder_copy_buffer_to_texture( command_encoder_id: id::CommandEncoderId, source: &core::command::BufferCopyView, destination: &core::command::TextureCopyView, - copy_size: core::Extent3d, + copy_size: wgt::Extent3d, ) { gfx_select!(command_encoder_id => GLOBAL.command_encoder_copy_buffer_to_texture( command_encoder_id, @@ -57,7 +57,7 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_buffer( command_encoder_id: id::CommandEncoderId, source: &core::command::TextureCopyView, destination: &core::command::BufferCopyView, - copy_size: core::Extent3d, + copy_size: wgt::Extent3d, ) { gfx_select!(command_encoder_id => GLOBAL.command_encoder_copy_texture_to_buffer( command_encoder_id, @@ -71,7 +71,7 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_texture( command_encoder_id: id::CommandEncoderId, source: &core::command::TextureCopyView, destination: &core::command::TextureCopyView, - copy_size: core::Extent3d, + copy_size: wgt::Extent3d, ) { gfx_select!(command_encoder_id => GLOBAL.command_encoder_copy_texture_to_texture( command_encoder_id, diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 975ff314b7..7b68796743 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -225,7 +225,7 @@ pub extern "C" fn wgpu_buffer_destroy(buffer_id: id::BufferId) { #[no_mangle] pub extern "C" fn wgpu_device_create_texture( device_id: id::DeviceId, - desc: &core::resource::TextureDescriptor, + desc: &wgt::TextureDescriptor, ) -> id::TextureId { gfx_select!(device_id => GLOBAL.device_create_texture(device_id, desc, PhantomData)) } @@ -238,7 +238,7 @@ pub extern "C" fn wgpu_texture_destroy(texture_id: id::TextureId) { #[no_mangle] pub extern "C" fn wgpu_texture_create_view( texture_id: id::TextureId, - desc: Option<&core::resource::TextureViewDescriptor>, + desc: Option<&wgt::TextureViewDescriptor>, ) -> id::TextureViewId { gfx_select!(texture_id => GLOBAL.texture_create_view(texture_id, desc, PhantomData)) } @@ -251,7 +251,7 @@ pub extern "C" fn wgpu_texture_view_destroy(texture_view_id: id::TextureViewId) #[no_mangle] pub extern "C" fn wgpu_device_create_sampler( device_id: id::DeviceId, - desc: &core::resource::SamplerDescriptor, + desc: &wgt::SamplerDescriptor, ) -> id::SamplerId { gfx_select!(device_id => GLOBAL.device_create_sampler(device_id, desc, PhantomData)) } diff --git a/wgpu-remote/src/server.rs b/wgpu-remote/src/server.rs index e47eade19b..25b1a9582f 100644 --- a/wgpu-remote/src/server.rs +++ b/wgpu-remote/src/server.rs @@ -152,7 +152,7 @@ pub extern "C" fn wgpu_server_device_create_encoder( pub extern "C" fn wgpu_server_encoder_finish( global: &Global, self_id: id::CommandEncoderId, - desc: &core::command::CommandBufferDescriptor, + desc: &wgt::CommandBufferDescriptor, ) { gfx_select!(self_id => global.command_encoder_finish(self_id, desc)); } @@ -349,7 +349,7 @@ pub extern "C" fn wgpu_server_render_pipeline_destroy( pub extern "C" fn wgpu_server_device_create_texture( global: &Global, self_id: id::DeviceId, - desc: &core::resource::TextureDescriptor, + desc: &wgt::TextureDescriptor, new_id: id::TextureId, ) { gfx_select!(self_id => global.device_create_texture(self_id, desc, new_id)); @@ -359,7 +359,7 @@ pub extern "C" fn wgpu_server_device_create_texture( pub extern "C" fn wgpu_server_texture_create_view( global: &Global, self_id: id::TextureId, - desc: Option<&core::resource::TextureViewDescriptor>, + desc: Option<&wgt::TextureViewDescriptor>, new_id: id::TextureViewId, ) { gfx_select!(self_id => global.texture_create_view(self_id, desc, new_id)); @@ -385,7 +385,7 @@ pub extern "C" fn wgpu_server_texture_view_destroy( pub extern "C" fn wgpu_server_device_create_sampler( global: &Global, self_id: id::DeviceId, - desc: &core::resource::SamplerDescriptor, + desc: &wgt::SamplerDescriptor, new_id: id::SamplerId, ) { gfx_select!(self_id => global.device_create_sampler(self_id, desc, new_id)); diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a7c21e47dd..8330ba9f47 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -691,3 +691,126 @@ impl Color { a: 1.0, }; } + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum TextureDimension { + D1, + D2, + D3, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct Origin3d { + pub x: u32, + pub y: u32, + pub z: u32, +} + +impl Origin3d { + pub const ZERO: Self = Origin3d { + x: 0, + y: 0, + z: 0, + }; +} + +impl Default for Origin3d { + fn default() -> Self { + Origin3d::ZERO + } +} + +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct Extent3d { + pub width: u32, + pub height: u32, + pub depth: u32, +} + +#[repr(C)] +#[derive(Debug)] +pub struct TextureDescriptor { + pub size: Extent3d, + pub array_layer_count: u32, + pub mip_level_count: u32, + pub sample_count: u32, + pub dimension: TextureDimension, + pub format: TextureFormat, + pub usage: TextureUsage, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum TextureAspect { + All, + StencilOnly, + DepthOnly, +} + +impl Default for TextureAspect { + fn default() -> Self { + TextureAspect::All + } +} + +#[repr(C)] +#[derive(Debug)] +pub struct TextureViewDescriptor { + pub format: TextureFormat, + pub dimension: TextureViewDimension, + pub aspect: TextureAspect, + pub base_mip_level: u32, + pub level_count: u32, + pub base_array_layer: u32, + pub array_layer_count: u32, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum AddressMode { + ClampToEdge = 0, + Repeat = 1, + MirrorRepeat = 2, +} + +impl Default for AddressMode { + fn default() -> Self { + AddressMode::ClampToEdge + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum FilterMode { + Nearest = 0, + Linear = 1, +} + +impl Default for FilterMode { + fn default() -> Self { + FilterMode::Nearest + } +} + +#[repr(C)] +#[derive(Debug)] +pub struct SamplerDescriptor<'a> { + pub address_mode_u: AddressMode, + pub address_mode_v: AddressMode, + pub address_mode_w: AddressMode, + pub mag_filter: FilterMode, + pub min_filter: FilterMode, + pub mipmap_filter: FilterMode, + pub lod_min_clamp: f32, + pub lod_max_clamp: f32, + pub compare: Option<&'a CompareFunction>, +} + +#[repr(C)] +#[derive(Clone, Debug, Default)] +pub struct CommandBufferDescriptor { + pub todo: u32, +}