mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
remove Resource
trait
This commit is contained in:
parent
c63f0a02f2
commit
c3ebfde302
@ -8,7 +8,7 @@ use crate::{
|
||||
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
|
||||
resource::{
|
||||
DestroyedResourceError, Labeled, MissingBufferUsageError, MissingTextureUsageError,
|
||||
ParentDevice, Resource, ResourceErrorIdent, TrackingData,
|
||||
ParentDevice, ResourceErrorIdent, TrackingData,
|
||||
},
|
||||
resource_log,
|
||||
snatch::{SnatchGuard, Snatchable},
|
||||
@ -499,8 +499,6 @@ crate::impl_labeled!(BindGroupLayout);
|
||||
crate::impl_storage_item!(BindGroupLayout);
|
||||
crate::impl_trackable!(BindGroupLayout);
|
||||
|
||||
impl<A: HalApi> Resource for BindGroupLayout<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for BindGroupLayout<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -727,8 +725,6 @@ crate::impl_labeled!(PipelineLayout);
|
||||
crate::impl_storage_item!(PipelineLayout);
|
||||
crate::impl_trackable!(PipelineLayout);
|
||||
|
||||
impl<A: HalApi> Resource for PipelineLayout<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for PipelineLayout<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -940,8 +936,6 @@ crate::impl_labeled!(BindGroup);
|
||||
crate::impl_storage_item!(BindGroup);
|
||||
crate::impl_trackable!(BindGroup);
|
||||
|
||||
impl<A: HalApi> Resource for BindGroup<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for BindGroup<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
|
@ -19,7 +19,7 @@ mod compat {
|
||||
binding_model::BindGroupLayout,
|
||||
device::bgl,
|
||||
hal_api::HalApi,
|
||||
resource::{Labeled, Resource},
|
||||
resource::{Labeled, ParentDevice},
|
||||
};
|
||||
use std::{ops::Range, sync::Arc};
|
||||
|
||||
|
@ -95,7 +95,7 @@ use crate::{
|
||||
id,
|
||||
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
|
||||
pipeline::{PipelineFlags, RenderPipeline, VertexStep},
|
||||
resource::{Buffer, DestroyedResourceError, Labeled, ParentDevice, Resource, TrackingData},
|
||||
resource::{Buffer, DestroyedResourceError, Labeled, ParentDevice, TrackingData},
|
||||
resource_log,
|
||||
snatch::SnatchGuard,
|
||||
track::RenderBundleScope,
|
||||
@ -1188,8 +1188,6 @@ crate::impl_labeled!(RenderBundle);
|
||||
crate::impl_storage_item!(RenderBundle);
|
||||
crate::impl_trackable!(RenderBundle);
|
||||
|
||||
impl<A: HalApi> Resource for RenderBundle<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for RenderBundle<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
|
@ -20,7 +20,7 @@ use crate::{
|
||||
pipeline::ComputePipeline,
|
||||
resource::{
|
||||
self, Buffer, DestroyedResourceError, Labeled, MissingBufferUsageError, ParentDevice,
|
||||
Resource, ResourceErrorIdent, Trackable,
|
||||
ResourceErrorIdent, Trackable,
|
||||
},
|
||||
snatch::SnatchGuard,
|
||||
track::{ResourceUsageCompatibilityError, Tracker, TrackerIndex, UsageScope},
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
device::Device,
|
||||
hal_api::HalApi,
|
||||
init_tracker::*,
|
||||
resource::{DestroyedResourceError, Resource, Texture, Trackable},
|
||||
resource::{DestroyedResourceError, ParentDevice, Texture, Trackable},
|
||||
snatch::SnatchGuard,
|
||||
track::{TextureTracker, Tracker},
|
||||
FastHashMap,
|
||||
|
@ -36,7 +36,7 @@ use crate::lock::{rank, Mutex};
|
||||
use crate::snatch::SnatchGuard;
|
||||
|
||||
use crate::init_tracker::BufferInitTrackerAction;
|
||||
use crate::resource::{Labeled, ParentDevice, Resource};
|
||||
use crate::resource::{Labeled, ParentDevice};
|
||||
use crate::track::{Tracker, UsageScope};
|
||||
use crate::LabelHelpers;
|
||||
use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label};
|
||||
@ -532,8 +532,6 @@ crate::impl_resource_type!(CommandBuffer);
|
||||
crate::impl_labeled!(CommandBuffer);
|
||||
crate::impl_storage_item!(CommandBuffer);
|
||||
|
||||
impl<A: HalApi> Resource for CommandBuffer<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for CommandBuffer<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
|
@ -4,7 +4,6 @@ use crate::command::{
|
||||
};
|
||||
use crate::init_tracker::BufferInitTrackerAction;
|
||||
use crate::pipeline::RenderPipeline;
|
||||
use crate::resource::Resource;
|
||||
use crate::snatch::SnatchGuard;
|
||||
use crate::{
|
||||
api_log,
|
||||
|
@ -17,8 +17,8 @@ use crate::{
|
||||
lock::{rank, Mutex, RwLockWriteGuard},
|
||||
resource::{
|
||||
Buffer, BufferAccessError, BufferMapState, DestroyedBuffer, DestroyedResourceError,
|
||||
DestroyedTexture, Labeled, ParentDevice, Resource, ResourceErrorIdent, StagingBuffer,
|
||||
Texture, TextureInner, Trackable, TrackingData,
|
||||
DestroyedTexture, Labeled, ParentDevice, ResourceErrorIdent, StagingBuffer, Texture,
|
||||
TextureInner, Trackable, TrackingData,
|
||||
},
|
||||
resource_log,
|
||||
track::{self, TrackerIndex},
|
||||
@ -50,8 +50,6 @@ impl<A: HalApi> Labeled for Queue<A> {
|
||||
}
|
||||
crate::impl_storage_item!(Queue);
|
||||
|
||||
impl<A: HalApi> Resource for Queue<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for Queue<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
self.device.as_ref().unwrap()
|
||||
|
@ -24,7 +24,7 @@ use crate::{
|
||||
pool::ResourcePool,
|
||||
registry::Registry,
|
||||
resource::{
|
||||
self, Buffer, Labeled, ParentDevice, QuerySet, Resource, Sampler, Texture, TextureView,
|
||||
self, Buffer, Labeled, ParentDevice, QuerySet, Sampler, Texture, TextureView,
|
||||
TextureViewNotRenderableReason, Trackable, TrackingData,
|
||||
},
|
||||
resource_log,
|
||||
@ -3668,5 +3668,3 @@ impl<A: HalApi> Device<A> {
|
||||
crate::impl_resource_type!(Device);
|
||||
crate::impl_labeled!(Device);
|
||||
crate::impl_storage_item!(Device);
|
||||
|
||||
impl<A: HalApi> Resource for Device<A> {}
|
||||
|
@ -9,7 +9,7 @@ use crate::{
|
||||
id::{markers, AdapterId, DeviceId, Id, Marker, QueueId, SurfaceId},
|
||||
lock::{rank, Mutex},
|
||||
present::Presentation,
|
||||
resource::{Labeled, Resource, ResourceType},
|
||||
resource::{Labeled, ResourceType},
|
||||
resource_log, LabelHelpers, DOWNLEVEL_WARNING_MESSAGE,
|
||||
};
|
||||
|
||||
@ -157,8 +157,6 @@ impl crate::storage::StorageItem for Surface {
|
||||
type Marker = markers::Surface;
|
||||
}
|
||||
|
||||
impl Resource for Surface {}
|
||||
|
||||
impl Surface {
|
||||
pub fn get_capabilities<A: HalApi>(
|
||||
&self,
|
||||
@ -376,8 +374,6 @@ impl<A: HalApi> Labeled for Adapter<A> {
|
||||
}
|
||||
crate::impl_storage_item!(Adapter);
|
||||
|
||||
impl<A: HalApi> Resource for Adapter<A> {}
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum IsSurfaceSupportedError {
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures, RenderPassContext},
|
||||
hal_api::HalApi,
|
||||
id::{PipelineCacheId, PipelineLayoutId, ShaderModuleId},
|
||||
resource::{Labeled, ParentDevice, Resource, TrackingData},
|
||||
resource::{Labeled, ParentDevice, TrackingData},
|
||||
resource_log, validation, Label,
|
||||
};
|
||||
use arrayvec::ArrayVec;
|
||||
@ -70,8 +70,6 @@ crate::impl_resource_type!(ShaderModule);
|
||||
crate::impl_labeled!(ShaderModule);
|
||||
crate::impl_storage_item!(ShaderModule);
|
||||
|
||||
impl<A: HalApi> Resource for ShaderModule<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for ShaderModule<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -233,8 +231,6 @@ crate::impl_labeled!(ComputePipeline);
|
||||
crate::impl_storage_item!(ComputePipeline);
|
||||
crate::impl_trackable!(ComputePipeline);
|
||||
|
||||
impl<A: HalApi> Resource for ComputePipeline<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for ComputePipeline<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -296,8 +292,6 @@ crate::impl_labeled!(PipelineCache);
|
||||
crate::impl_storage_item!(PipelineCache);
|
||||
crate::impl_trackable!(PipelineCache);
|
||||
|
||||
impl<A: HalApi> Resource for PipelineCache<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for PipelineCache<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -550,8 +544,6 @@ crate::impl_labeled!(RenderPipeline);
|
||||
crate::impl_storage_item!(RenderPipeline);
|
||||
crate::impl_trackable!(RenderPipeline);
|
||||
|
||||
impl<A: HalApi> Resource for RenderPipeline<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for RenderPipeline<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
|
@ -20,7 +20,6 @@ use crate::{
|
||||
use hal::CommandEncoder;
|
||||
use smallvec::SmallVec;
|
||||
use thiserror::Error;
|
||||
use wgt::WasmNotSendSync;
|
||||
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
@ -113,8 +112,12 @@ impl std::fmt::Display for ResourceErrorIdent {
|
||||
pub(crate) trait ParentDevice<A: HalApi>: Labeled {
|
||||
fn device(&self) -> &Arc<Device<A>>;
|
||||
|
||||
fn is_equal(self: &Arc<Self>, other: &Arc<Self>) -> bool {
|
||||
Arc::ptr_eq(self, other)
|
||||
}
|
||||
|
||||
fn same_device_as<O: ParentDevice<A>>(&self, other: &O) -> Result<(), DeviceError> {
|
||||
if self.device().is_equal(other.device()) {
|
||||
if Arc::ptr_eq(self.device(), other.device()) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(DeviceError::DeviceMismatch(Box::new(DeviceMismatch {
|
||||
@ -127,7 +130,7 @@ pub(crate) trait ParentDevice<A: HalApi>: Labeled {
|
||||
}
|
||||
|
||||
fn same_device(&self, device: &Arc<Device<A>>) -> Result<(), DeviceError> {
|
||||
if self.device().is_equal(device) {
|
||||
if Arc::ptr_eq(self.device(), device) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(DeviceError::DeviceMismatch(Box::new(DeviceMismatch {
|
||||
@ -186,6 +189,10 @@ pub(crate) trait Trackable: Labeled {
|
||||
/// given index.
|
||||
fn use_at(&self, submit_index: SubmissionIndex);
|
||||
fn submission_index(&self) -> SubmissionIndex;
|
||||
|
||||
fn is_unique(self: &Arc<Self>) -> bool {
|
||||
Arc::strong_count(self) == 1
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
@ -205,18 +212,6 @@ macro_rules! impl_trackable {
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) trait Resource: 'static + Sized + WasmNotSendSync + Labeled {
|
||||
fn ref_count(self: &Arc<Self>) -> usize {
|
||||
Arc::strong_count(self)
|
||||
}
|
||||
fn is_unique(self: &Arc<Self>) -> bool {
|
||||
self.ref_count() == 1
|
||||
}
|
||||
fn is_equal(self: &Arc<Self>, other: &Arc<Self>) -> bool {
|
||||
Arc::ptr_eq(self, other)
|
||||
}
|
||||
}
|
||||
|
||||
/// The status code provided to the buffer mapping callback.
|
||||
///
|
||||
/// This is very similar to `BufferAccessResult`, except that this is FFI-friendly.
|
||||
@ -809,8 +804,6 @@ crate::impl_labeled!(Buffer);
|
||||
crate::impl_storage_item!(Buffer);
|
||||
crate::impl_trackable!(Buffer);
|
||||
|
||||
impl<A: HalApi> Resource for Buffer<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for Buffer<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -903,8 +896,6 @@ impl<A: HalApi> Labeled for StagingBuffer<A> {
|
||||
crate::impl_storage_item!(StagingBuffer);
|
||||
crate::impl_trackable!(StagingBuffer);
|
||||
|
||||
impl<A: HalApi> Resource for StagingBuffer<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for StagingBuffer<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -1438,8 +1429,6 @@ crate::impl_labeled!(Texture);
|
||||
crate::impl_storage_item!(Texture);
|
||||
crate::impl_trackable!(Texture);
|
||||
|
||||
impl<A: HalApi> Resource for Texture<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for Texture<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -1608,8 +1597,6 @@ crate::impl_labeled!(TextureView);
|
||||
crate::impl_storage_item!(TextureView);
|
||||
crate::impl_trackable!(TextureView);
|
||||
|
||||
impl<A: HalApi> Resource for TextureView<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for TextureView<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -1725,8 +1712,6 @@ crate::impl_labeled!(Sampler);
|
||||
crate::impl_storage_item!(Sampler);
|
||||
crate::impl_trackable!(Sampler);
|
||||
|
||||
impl<A: HalApi> Resource for Sampler<A> {}
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for Sampler<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
&self.device
|
||||
@ -1781,8 +1766,6 @@ crate::impl_labeled!(QuerySet);
|
||||
crate::impl_storage_item!(QuerySet);
|
||||
crate::impl_trackable!(QuerySet);
|
||||
|
||||
impl<A: HalApi> Resource for QuerySet<A> {}
|
||||
|
||||
impl<A: HalApi> QuerySet<A> {
|
||||
pub(crate) fn raw(&self) -> &A::QuerySet {
|
||||
self.raw.as_ref().unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user