impl ParentDevice via macro

This commit is contained in:
teoxoy 2024-06-27 17:01:20 +02:00 committed by Teodor Tanasoaia
parent c3ebfde302
commit f34f7eb658
5 changed files with 29 additions and 93 deletions

View File

@ -8,7 +8,7 @@ use crate::{
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
resource::{
DestroyedResourceError, Labeled, MissingBufferUsageError, MissingTextureUsageError,
ParentDevice, ResourceErrorIdent, TrackingData,
ResourceErrorIdent, TrackingData,
},
resource_log,
snatch::{SnatchGuard, Snatchable},
@ -496,15 +496,10 @@ impl<A: HalApi> Drop for BindGroupLayout<A> {
crate::impl_resource_type!(BindGroupLayout);
crate::impl_labeled!(BindGroupLayout);
crate::impl_parent_device!(BindGroupLayout);
crate::impl_storage_item!(BindGroupLayout);
crate::impl_trackable!(BindGroupLayout);
impl<A: HalApi> ParentDevice<A> for BindGroupLayout<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
impl<A: HalApi> BindGroupLayout<A> {
pub(crate) fn raw(&self) -> &A::BindGroupLayout {
self.raw.as_ref().unwrap()
@ -722,15 +717,10 @@ impl<A: HalApi> PipelineLayout<A> {
crate::impl_resource_type!(PipelineLayout);
crate::impl_labeled!(PipelineLayout);
crate::impl_parent_device!(PipelineLayout);
crate::impl_storage_item!(PipelineLayout);
crate::impl_trackable!(PipelineLayout);
impl<A: HalApi> ParentDevice<A> for PipelineLayout<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
#[repr(C)]
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -933,15 +923,10 @@ impl<A: HalApi> BindGroup<A> {
crate::impl_resource_type!(BindGroup);
crate::impl_labeled!(BindGroup);
crate::impl_parent_device!(BindGroup);
crate::impl_storage_item!(BindGroup);
crate::impl_trackable!(BindGroup);
impl<A: HalApi> ParentDevice<A> for BindGroup<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum GetBindGroupLayoutError {

View File

@ -1185,15 +1185,10 @@ impl<A: HalApi> RenderBundle<A> {
crate::impl_resource_type!(RenderBundle);
crate::impl_labeled!(RenderBundle);
crate::impl_parent_device!(RenderBundle);
crate::impl_storage_item!(RenderBundle);
crate::impl_trackable!(RenderBundle);
impl<A: HalApi> ParentDevice<A> for RenderBundle<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
/// A render bundle's current index buffer state.
///
/// [`RenderBundleEncoder::finish`] records the currently set index buffer here,

View File

@ -36,7 +36,7 @@ use crate::lock::{rank, Mutex};
use crate::snatch::SnatchGuard;
use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::{Labeled, ParentDevice};
use crate::resource::Labeled;
use crate::track::{Tracker, UsageScope};
use crate::LabelHelpers;
use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label};
@ -530,14 +530,9 @@ impl<A: HalApi> CommandBuffer<A> {
crate::impl_resource_type!(CommandBuffer);
crate::impl_labeled!(CommandBuffer);
crate::impl_parent_device!(CommandBuffer);
crate::impl_storage_item!(CommandBuffer);
impl<A: HalApi> ParentDevice<A> for CommandBuffer<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
/// A stream of commands for a render pass or compute pass.
///
/// This also contains side tables referred to by certain commands,

View File

@ -5,7 +5,7 @@ use crate::{
device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures, RenderPassContext},
hal_api::HalApi,
id::{PipelineCacheId, PipelineLayoutId, ShaderModuleId},
resource::{Labeled, ParentDevice, TrackingData},
resource::{Labeled, TrackingData},
resource_log, validation, Label,
};
use arrayvec::ArrayVec;
@ -68,14 +68,9 @@ impl<A: HalApi> Drop for ShaderModule<A> {
crate::impl_resource_type!(ShaderModule);
crate::impl_labeled!(ShaderModule);
crate::impl_parent_device!(ShaderModule);
crate::impl_storage_item!(ShaderModule);
impl<A: HalApi> ParentDevice<A> for ShaderModule<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
impl<A: HalApi> ShaderModule<A> {
pub(crate) fn raw(&self) -> &A::ShaderModule {
self.raw.as_ref().unwrap()
@ -228,15 +223,10 @@ impl<A: HalApi> Drop for ComputePipeline<A> {
crate::impl_resource_type!(ComputePipeline);
crate::impl_labeled!(ComputePipeline);
crate::impl_parent_device!(ComputePipeline);
crate::impl_storage_item!(ComputePipeline);
crate::impl_trackable!(ComputePipeline);
impl<A: HalApi> ParentDevice<A> for ComputePipeline<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
impl<A: HalApi> ComputePipeline<A> {
pub(crate) fn raw(&self) -> &A::ComputePipeline {
self.raw.as_ref().unwrap()
@ -289,15 +279,10 @@ impl<A: HalApi> Drop for PipelineCache<A> {
crate::impl_resource_type!(PipelineCache);
crate::impl_labeled!(PipelineCache);
crate::impl_parent_device!(PipelineCache);
crate::impl_storage_item!(PipelineCache);
crate::impl_trackable!(PipelineCache);
impl<A: HalApi> ParentDevice<A> for PipelineCache<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
/// Describes how the vertex buffer is interpreted.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@ -541,15 +526,10 @@ impl<A: HalApi> Drop for RenderPipeline<A> {
crate::impl_resource_type!(RenderPipeline);
crate::impl_labeled!(RenderPipeline);
crate::impl_parent_device!(RenderPipeline);
crate::impl_storage_item!(RenderPipeline);
crate::impl_trackable!(RenderPipeline);
impl<A: HalApi> ParentDevice<A> for RenderPipeline<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
impl<A: HalApi> RenderPipeline<A> {
pub(crate) fn raw(&self) -> &A::RenderPipeline {
self.raw.as_ref().unwrap()

View File

@ -143,6 +143,17 @@ pub(crate) trait ParentDevice<A: HalApi>: Labeled {
}
}
#[macro_export]
macro_rules! impl_parent_device {
($ty:ident) => {
impl<A: HalApi> $crate::resource::ParentDevice<A> for $ty<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
};
}
pub(crate) trait ResourceType {
const TYPE: &'static str;
}
@ -801,15 +812,10 @@ pub enum CreateBufferError {
crate::impl_resource_type!(Buffer);
crate::impl_labeled!(Buffer);
crate::impl_parent_device!(Buffer);
crate::impl_storage_item!(Buffer);
crate::impl_trackable!(Buffer);
impl<A: HalApi> ParentDevice<A> for Buffer<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
/// A buffer that has been marked as destroyed and is staged for actual deletion soon.
#[derive(Debug)]
pub struct DestroyedBuffer<A: HalApi> {
@ -893,15 +899,10 @@ impl<A: HalApi> Labeled for StagingBuffer<A> {
""
}
}
crate::impl_parent_device!(StagingBuffer);
crate::impl_storage_item!(StagingBuffer);
crate::impl_trackable!(StagingBuffer);
impl<A: HalApi> ParentDevice<A> for StagingBuffer<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
pub type TextureDescriptor<'a> = wgt::TextureDescriptor<Label<'a>, Vec<wgt::TextureFormat>>;
#[derive(Debug)]
@ -1426,15 +1427,10 @@ pub enum CreateTextureError {
crate::impl_resource_type!(Texture);
crate::impl_labeled!(Texture);
crate::impl_parent_device!(Texture);
crate::impl_storage_item!(Texture);
crate::impl_trackable!(Texture);
impl<A: HalApi> ParentDevice<A> for Texture<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
impl<A: HalApi> Borrow<TextureSelector> for Texture<A> {
fn borrow(&self) -> &TextureSelector {
&self.full_range
@ -1594,15 +1590,10 @@ pub enum TextureViewDestroyError {}
crate::impl_resource_type!(TextureView);
crate::impl_labeled!(TextureView);
crate::impl_parent_device!(TextureView);
crate::impl_storage_item!(TextureView);
crate::impl_trackable!(TextureView);
impl<A: HalApi> ParentDevice<A> for TextureView<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
/// Describes a [`Sampler`]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@ -1709,15 +1700,10 @@ pub enum CreateSamplerError {
crate::impl_resource_type!(Sampler);
crate::impl_labeled!(Sampler);
crate::impl_parent_device!(Sampler);
crate::impl_storage_item!(Sampler);
crate::impl_trackable!(Sampler);
impl<A: HalApi> ParentDevice<A> for Sampler<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum CreateQuerySetError {
@ -1755,14 +1741,9 @@ impl<A: HalApi> Drop for QuerySet<A> {
}
}
impl<A: HalApi> ParentDevice<A> for QuerySet<A> {
fn device(&self) -> &Arc<Device<A>> {
&self.device
}
}
crate::impl_resource_type!(QuerySet);
crate::impl_labeled!(QuerySet);
crate::impl_parent_device!(QuerySet);
crate::impl_storage_item!(QuerySet);
crate::impl_trackable!(QuerySet);