mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
Make descriptors generic over Label
This commit is contained in:
parent
4c1ea02553
commit
1cc548a7a2
@ -32,10 +32,22 @@ use std::{
|
||||
|
||||
mod life;
|
||||
#[cfg(feature = "trace")]
|
||||
mod trace;
|
||||
pub(crate) mod trace;
|
||||
#[cfg(feature = "trace")]
|
||||
use trace::{Action, Trace};
|
||||
|
||||
pub type Label = *const std::os::raw::c_char;
|
||||
#[cfg(feature = "trace")]
|
||||
fn own_label(label: &Label) -> String {
|
||||
if label.is_null() {
|
||||
String::new()
|
||||
} else {
|
||||
unsafe { ffi::CStr::from_ptr(*label) }
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub const MAX_COLOR_TARGETS: usize = 4;
|
||||
pub const MAX_MIP_LEVELS: usize = 16;
|
||||
pub const MAX_VERTEX_BUFFERS: usize = 16;
|
||||
@ -200,7 +212,7 @@ pub struct Device<B: hal::Backend> {
|
||||
pub(crate) private_features: PrivateFeatures,
|
||||
limits: wgt::Limits,
|
||||
#[cfg(feature = "trace")]
|
||||
trace: Option<Mutex<Trace>>,
|
||||
pub(crate) trace: Option<Mutex<Trace>>,
|
||||
}
|
||||
|
||||
impl<B: GfxBackend> Device<B> {
|
||||
@ -293,7 +305,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
fn create_buffer(
|
||||
&self,
|
||||
self_id: id::DeviceId,
|
||||
desc: &wgt::BufferDescriptor,
|
||||
desc: &wgt::BufferDescriptor<Label>,
|
||||
) -> resource::Buffer<B> {
|
||||
use gfx_memory::{Kind, MemoryUsage};
|
||||
|
||||
@ -365,7 +377,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
fn create_texture(
|
||||
&self,
|
||||
self_id: id::DeviceId,
|
||||
desc: &wgt::TextureDescriptor,
|
||||
desc: &wgt::TextureDescriptor<Label>,
|
||||
) -> resource::Texture<B> {
|
||||
debug_assert_eq!(self_id.backend(), B::VARIANT);
|
||||
|
||||
@ -500,7 +512,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_create_buffer<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::BufferDescriptor,
|
||||
desc: &wgt::BufferDescriptor<Label>,
|
||||
id_in: Input<G, id::BufferId>,
|
||||
) -> id::BufferId {
|
||||
let hub = B::hub(self);
|
||||
@ -515,6 +527,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
let id = hub.buffers.register_identity(id_in, buffer, &mut token);
|
||||
log::info!("Created buffer {:?} with {:?}", id, desc);
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(trace::Action::CreateBuffer {
|
||||
id,
|
||||
desc: desc.map_label(own_label),
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
@ -531,7 +552,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_create_buffer_mapped<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::BufferDescriptor,
|
||||
desc: &wgt::BufferDescriptor<Label>,
|
||||
id_in: Input<G, id::BufferId>,
|
||||
) -> (id::BufferId, *mut u8) {
|
||||
let hub = B::hub(self);
|
||||
@ -675,7 +696,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_create_texture<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::TextureDescriptor,
|
||||
desc: &wgt::TextureDescriptor<Label>,
|
||||
id_in: Input<G, id::TextureId>,
|
||||
) -> id::TextureId {
|
||||
let hub = B::hub(self);
|
||||
@ -688,6 +709,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let ref_count = texture.life_guard.add_ref();
|
||||
|
||||
let id = hub.textures.register_identity(id_in, texture, &mut token);
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(trace::Action::CreateTexture {
|
||||
id,
|
||||
desc: desc.map_label(own_label),
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
@ -719,7 +749,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn texture_create_view<B: GfxBackend>(
|
||||
&self,
|
||||
texture_id: id::TextureId,
|
||||
desc: Option<&wgt::TextureViewDescriptor>,
|
||||
desc: Option<&wgt::TextureViewDescriptor<Label>>,
|
||||
id_in: Input<G, id::TextureViewId>,
|
||||
) -> id::TextureViewId {
|
||||
let hub = B::hub(self);
|
||||
@ -832,7 +862,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_create_sampler<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::SamplerDescriptor,
|
||||
desc: &wgt::SamplerDescriptor<Label>,
|
||||
id_in: Input<G, id::SamplerId>,
|
||||
) -> id::SamplerId {
|
||||
let hub = B::hub(self);
|
||||
@ -868,6 +898,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let ref_count = sampler.life_guard.add_ref();
|
||||
|
||||
let id = hub.samplers.register_identity(id_in, sampler, &mut token);
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(trace::Action::CreateSampler {
|
||||
id,
|
||||
desc: desc.map_label(own_label),
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
@ -2068,6 +2107,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
device.raw.destroy_semaphore(sc.semaphore);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(Action::CreateSwapChain {
|
||||
id: sc_id,
|
||||
desc: desc.clone(),
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
let swap_chain = swap_chain::SwapChain {
|
||||
life_guard: LifeGuard::new(),
|
||||
device_id: Stored {
|
||||
|
@ -2,11 +2,39 @@
|
||||
* 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::id;
|
||||
use std::io::Write as _;
|
||||
|
||||
//TODO: consider a readable Id that doesn't include the backend
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub enum Action {
|
||||
Init { limits: wgt::Limits },
|
||||
Init {
|
||||
limits: wgt::Limits,
|
||||
},
|
||||
CreateBuffer {
|
||||
id: id::BufferId,
|
||||
desc: wgt::BufferDescriptor<String>,
|
||||
},
|
||||
CreateTexture {
|
||||
id: id::TextureId,
|
||||
desc: wgt::TextureDescriptor<String>,
|
||||
},
|
||||
CreateSampler {
|
||||
id: id::SamplerId,
|
||||
desc: wgt::SamplerDescriptor<String>,
|
||||
},
|
||||
CreateSwapChain {
|
||||
id: id::SwapChainId,
|
||||
desc: wgt::SwapChainDescriptor,
|
||||
},
|
||||
GetSwapChainTexture {
|
||||
object_id: id::SwapChainId,
|
||||
view_id: id::TextureViewId,
|
||||
},
|
||||
PresentSwapChain {
|
||||
object_id: id::SwapChainId,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -32,6 +32,8 @@
|
||||
In `present()` we return the swap chain image back and wait on the semaphore.
|
||||
!*/
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
use crate::device::trace::Action;
|
||||
use crate::{
|
||||
conv,
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
@ -154,6 +156,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.texture_views
|
||||
.register_identity(view_id_in, view, &mut token);
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(Action::GetSwapChainTexture {
|
||||
object_id: swap_chain_id,
|
||||
view_id: id,
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
assert!(
|
||||
sc.acquired_view_id.is_none(),
|
||||
"Swap chain image is already acquired"
|
||||
@ -177,6 +188,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let sc = &mut swap_chain_guard[swap_chain_id];
|
||||
let device = &mut device_guard[sc.device_id.value];
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
match device.trace {
|
||||
Some(ref trace) => trace.lock().add(Action::PresentSwapChain {
|
||||
object_id: swap_chain_id,
|
||||
}),
|
||||
None => (),
|
||||
};
|
||||
|
||||
let view_id = sc
|
||||
.acquired_view_id
|
||||
.take()
|
||||
|
@ -541,7 +541,7 @@ pub enum VertexFormat {
|
||||
bitflags::bitflags! {
|
||||
#[repr(transparent)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct BufferUsage: u32 {
|
||||
const MAP_READ = 1;
|
||||
const MAP_WRITE = 2;
|
||||
@ -557,12 +557,24 @@ bitflags::bitflags! {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct BufferDescriptor {
|
||||
pub label: *const std::os::raw::c_char,
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct BufferDescriptor<L> {
|
||||
pub label: L,
|
||||
pub size: BufferAddress,
|
||||
pub usage: BufferUsage,
|
||||
}
|
||||
|
||||
impl<L> BufferDescriptor<L> {
|
||||
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor<K> {
|
||||
BufferDescriptor {
|
||||
label: fun(&self.label),
|
||||
size: self.size,
|
||||
usage: self.usage,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct CommandEncoderDescriptor {
|
||||
@ -767,8 +779,10 @@ pub struct Extent3d {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct TextureDescriptor {
|
||||
pub label: *const std::os::raw::c_char,
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct TextureDescriptor<L> {
|
||||
pub label: L,
|
||||
pub size: Extent3d,
|
||||
pub mip_level_count: u32,
|
||||
pub sample_count: u32,
|
||||
@ -777,6 +791,20 @@ pub struct TextureDescriptor {
|
||||
pub usage: TextureUsage,
|
||||
}
|
||||
|
||||
impl<L> TextureDescriptor<L> {
|
||||
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor<K> {
|
||||
TextureDescriptor {
|
||||
label: fun(&self.label),
|
||||
size: self.size,
|
||||
mip_level_count: self.mip_level_count,
|
||||
sample_count: self.sample_count,
|
||||
dimension: self.dimension,
|
||||
format: self.format,
|
||||
usage: self.usage,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
@ -797,7 +825,8 @@ impl Default for TextureAspect {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct TextureViewDescriptor {
|
||||
pub struct TextureViewDescriptor<L> {
|
||||
pub label: L,
|
||||
pub format: TextureFormat,
|
||||
pub dimension: TextureViewDimension,
|
||||
pub aspect: TextureAspect,
|
||||
@ -807,6 +836,21 @@ pub struct TextureViewDescriptor {
|
||||
pub array_layer_count: u32,
|
||||
}
|
||||
|
||||
impl<L> TextureViewDescriptor<L> {
|
||||
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
|
||||
TextureViewDescriptor {
|
||||
label: fun(&self.label),
|
||||
format: self.format,
|
||||
dimension: self.dimension,
|
||||
aspect: self.aspect,
|
||||
base_mip_level: self.base_mip_level,
|
||||
level_count: self.level_count,
|
||||
base_array_layer: self.base_array_layer,
|
||||
array_layer_count: self.array_layer_count,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
@ -842,7 +886,8 @@ impl Default for FilterMode {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct SamplerDescriptor {
|
||||
pub struct SamplerDescriptor<L> {
|
||||
pub label: L,
|
||||
pub address_mode_u: AddressMode,
|
||||
pub address_mode_v: AddressMode,
|
||||
pub address_mode_w: AddressMode,
|
||||
@ -854,6 +899,23 @@ pub struct SamplerDescriptor {
|
||||
pub compare: CompareFunction,
|
||||
}
|
||||
|
||||
impl<L> SamplerDescriptor<L> {
|
||||
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor<K> {
|
||||
SamplerDescriptor {
|
||||
label: fun(&self.label),
|
||||
address_mode_u: self.address_mode_u,
|
||||
address_mode_v: self.address_mode_v,
|
||||
address_mode_w: self.address_mode_w,
|
||||
mag_filter: self.mag_filter,
|
||||
min_filter: self.min_filter,
|
||||
mipmap_filter: self.mipmap_filter,
|
||||
lod_min_clamp: self.lod_min_clamp,
|
||||
lod_max_clamp: self.lod_max_clamp,
|
||||
compare: self.compare,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
|
Loading…
Reference in New Issue
Block a user