mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #523
523: Move more types into wgpu-types r=kvark a=grovesNL Co-authored-by: Joshua Groves <josh@joshgroves.com>
This commit is contained in:
@@ -195,12 +195,6 @@ impl<B: GfxBackend> CommandBuffer<B> {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CommandBufferDescriptor {
|
||||
pub todo: u32,
|
||||
}
|
||||
|
||||
pub type RawRenderPassColorAttachmentDescriptor =
|
||||
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, id::TextureViewId>;
|
||||
|
||||
@@ -215,7 +209,7 @@ impl<F> Global<F> {
|
||||
pub fn command_encoder_finish<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
_desc: &CommandBufferDescriptor,
|
||||
_desc: &wgt::CommandBufferDescriptor,
|
||||
) -> id::CommandBufferId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<B: GfxBackend> Device<B> {
|
||||
fn create_texture(
|
||||
&self,
|
||||
self_id: id::DeviceId,
|
||||
desc: &resource::TextureDescriptor,
|
||||
desc: &wgt::TextureDescriptor,
|
||||
) -> resource::Texture<B> {
|
||||
debug_assert_eq!(self_id.backend(), B::VARIANT);
|
||||
|
||||
@@ -388,7 +388,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
|
||||
// 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<F: IdentityFilter<id::TextureId>> Global<F> {
|
||||
pub fn device_create_texture<B: GfxBackend>(
|
||||
&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<F: IdentityFilter<id::TextureViewId>> Global<F> {
|
||||
pub fn texture_create_view<B: GfxBackend>(
|
||||
&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<F: IdentityFilter<id::SamplerId>> Global<F> {
|
||||
pub fn device_create_sampler<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &resource::SamplerDescriptor,
|
||||
desc: &wgt::SamplerDescriptor,
|
||||
id_in: F::Input,
|
||||
) -> id::SamplerId {
|
||||
let hub = B::hub(self);
|
||||
|
||||
@@ -108,36 +108,6 @@ struct Stored<T> {
|
||||
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 {
|
||||
|
||||
@@ -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<B: hal::Backend> Borrow<()> for Buffer<B> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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<B: hal::Backend> {
|
||||
pub(crate) raw: B::Image,
|
||||
@@ -137,32 +121,6 @@ impl<B: hal::Backend> Borrow<hal::image::SubresourceRange> for Texture<B> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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<B: hal::Backend> {
|
||||
Native {
|
||||
@@ -198,47 +156,6 @@ impl<B: hal::Backend> Borrow<()> for TextureView<B> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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<B: hal::Backend> {
|
||||
pub(crate) raw: B::Sampler,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user