mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
[core] Make Hub
members and related types pub(crate), not pub. (#5502)
This commit is contained in:
parent
8289711b65
commit
b7519bb73b
@ -462,8 +462,6 @@ pub struct BindGroupLayoutDescriptor<'a> {
|
||||
pub entries: Cow<'a, [wgt::BindGroupLayoutEntry]>,
|
||||
}
|
||||
|
||||
pub type BindGroupLayouts<A> = crate::storage::Storage<BindGroupLayout<A>>;
|
||||
|
||||
/// Bind group layout.
|
||||
#[derive(Debug)]
|
||||
pub struct BindGroupLayout<A: HalApi> {
|
||||
|
@ -34,9 +34,9 @@ use thiserror::Error;
|
||||
use super::Device;
|
||||
|
||||
pub struct Queue<A: HalApi> {
|
||||
pub device: Option<Arc<Device<A>>>,
|
||||
pub raw: Option<A::Queue>,
|
||||
pub info: ResourceInfo<Queue<A>>,
|
||||
pub(crate) device: Option<Arc<Device<A>>>,
|
||||
pub(crate) raw: Option<A::Queue>,
|
||||
pub(crate) info: ResourceInfo<Queue<A>>,
|
||||
}
|
||||
|
||||
impl<A: HalApi> Resource for Queue<A> {
|
||||
|
@ -45,7 +45,7 @@ impl GlobalReport {
|
||||
|
||||
pub struct Global {
|
||||
pub instance: Instance,
|
||||
pub surfaces: Registry<Surface>,
|
||||
pub(crate) surfaces: Registry<Surface>,
|
||||
pub(crate) hubs: Hubs,
|
||||
}
|
||||
|
||||
|
@ -169,23 +169,23 @@ impl HubReport {
|
||||
///
|
||||
/// [`A::hub(global)`]: HalApi::hub
|
||||
pub struct Hub<A: HalApi> {
|
||||
pub adapters: Registry<Adapter<A>>,
|
||||
pub devices: Registry<Device<A>>,
|
||||
pub queues: Registry<Queue<A>>,
|
||||
pub pipeline_layouts: Registry<PipelineLayout<A>>,
|
||||
pub shader_modules: Registry<ShaderModule<A>>,
|
||||
pub bind_group_layouts: Registry<BindGroupLayout<A>>,
|
||||
pub bind_groups: Registry<BindGroup<A>>,
|
||||
pub command_buffers: Registry<CommandBuffer<A>>,
|
||||
pub render_bundles: Registry<RenderBundle<A>>,
|
||||
pub render_pipelines: Registry<RenderPipeline<A>>,
|
||||
pub compute_pipelines: Registry<ComputePipeline<A>>,
|
||||
pub query_sets: Registry<QuerySet<A>>,
|
||||
pub buffers: Registry<Buffer<A>>,
|
||||
pub staging_buffers: Registry<StagingBuffer<A>>,
|
||||
pub textures: Registry<Texture<A>>,
|
||||
pub texture_views: Registry<TextureView<A>>,
|
||||
pub samplers: Registry<Sampler<A>>,
|
||||
pub(crate) adapters: Registry<Adapter<A>>,
|
||||
pub(crate) devices: Registry<Device<A>>,
|
||||
pub(crate) queues: Registry<Queue<A>>,
|
||||
pub(crate) pipeline_layouts: Registry<PipelineLayout<A>>,
|
||||
pub(crate) shader_modules: Registry<ShaderModule<A>>,
|
||||
pub(crate) bind_group_layouts: Registry<BindGroupLayout<A>>,
|
||||
pub(crate) bind_groups: Registry<BindGroup<A>>,
|
||||
pub(crate) command_buffers: Registry<CommandBuffer<A>>,
|
||||
pub(crate) render_bundles: Registry<RenderBundle<A>>,
|
||||
pub(crate) render_pipelines: Registry<RenderPipeline<A>>,
|
||||
pub(crate) compute_pipelines: Registry<ComputePipeline<A>>,
|
||||
pub(crate) query_sets: Registry<QuerySet<A>>,
|
||||
pub(crate) buffers: Registry<Buffer<A>>,
|
||||
pub(crate) staging_buffers: Registry<StagingBuffer<A>>,
|
||||
pub(crate) textures: Registry<Texture<A>>,
|
||||
pub(crate) texture_views: Registry<TextureView<A>>,
|
||||
pub(crate) samplers: Registry<Sampler<A>>,
|
||||
}
|
||||
|
||||
impl<A: HalApi> Hub<A> {
|
||||
|
@ -91,8 +91,7 @@ pub fn as_option_slice<T: Marker>(ids: &[Id<T>]) -> &[Option<Id<T>>] {
|
||||
|
||||
/// An identifier for a wgpu object.
|
||||
///
|
||||
/// An `Id<T>` value identifies a value stored in a [`Global`]'s [`Hub`]'s [`Storage`].
|
||||
/// `Storage` implements [`Index`] and [`IndexMut`], accepting `Id` values as indices.
|
||||
/// An `Id<T>` value identifies a value stored in a [`Global`]'s [`Hub`].
|
||||
///
|
||||
/// ## Note on `Id` typing
|
||||
///
|
||||
@ -112,10 +111,7 @@ pub fn as_option_slice<T: Marker>(ids: &[Id<T>]) -> &[Option<Id<T>>] {
|
||||
/// [`Global`]: crate::global::Global
|
||||
/// [`Hub`]: crate::hub::Hub
|
||||
/// [`Hub<A>`]: crate::hub::Hub
|
||||
/// [`Storage`]: crate::storage::Storage
|
||||
/// [`Texture<A>`]: crate::resource::Texture
|
||||
/// [`Index`]: std::ops::Index
|
||||
/// [`IndexMut`]: std::ops::IndexMut
|
||||
/// [`Registry`]: crate::hub::Registry
|
||||
/// [`Empty`]: hal::api::Empty
|
||||
#[repr(transparent)]
|
||||
|
@ -37,7 +37,7 @@ impl RegistryReport {
|
||||
/// any other dependent resource
|
||||
///
|
||||
#[derive(Debug)]
|
||||
pub struct Registry<T: Resource> {
|
||||
pub(crate) struct Registry<T: Resource> {
|
||||
identity: Arc<IdentityManager<T::Marker>>,
|
||||
storage: RwLock<Storage<T>>,
|
||||
backend: Backend,
|
||||
@ -146,16 +146,20 @@ impl<T: Resource> Registry<T> {
|
||||
pub(crate) fn write<'a>(&'a self) -> RwLockWriteGuard<'a, Storage<T>> {
|
||||
self.storage.write()
|
||||
}
|
||||
pub fn unregister_locked(&self, id: Id<T::Marker>, storage: &mut Storage<T>) -> Option<Arc<T>> {
|
||||
pub(crate) fn unregister_locked(
|
||||
&self,
|
||||
id: Id<T::Marker>,
|
||||
storage: &mut Storage<T>,
|
||||
) -> Option<Arc<T>> {
|
||||
self.identity.free(id);
|
||||
storage.remove(id)
|
||||
}
|
||||
pub fn force_replace(&self, id: Id<T::Marker>, mut value: T) {
|
||||
pub(crate) fn force_replace(&self, id: Id<T::Marker>, mut value: T) {
|
||||
let mut storage = self.storage.write();
|
||||
value.as_info_mut().set_id(id);
|
||||
storage.force_replace(id, value)
|
||||
}
|
||||
pub fn force_replace_with_error(&self, id: Id<T::Marker>, label: &str) {
|
||||
pub(crate) fn force_replace_with_error(&self, id: Id<T::Marker>, label: &str) {
|
||||
let mut storage = self.storage.write();
|
||||
storage.remove(id);
|
||||
storage.insert_error(id, label);
|
||||
@ -167,7 +171,7 @@ impl<T: Resource> Registry<T> {
|
||||
value
|
||||
}
|
||||
|
||||
pub fn label_for_resource(&self, id: Id<T::Marker>) -> String {
|
||||
pub(crate) fn label_for_resource(&self, id: Id<T::Marker>) -> String {
|
||||
let guard = self.storage.read();
|
||||
|
||||
let type_name = guard.kind();
|
||||
|
@ -58,7 +58,7 @@ use std::{
|
||||
/// [`Device`]: crate::device::resource::Device
|
||||
/// [`Buffer`]: crate::resource::Buffer
|
||||
#[derive(Debug)]
|
||||
pub struct ResourceInfo<T: Resource> {
|
||||
pub(crate) struct ResourceInfo<T: Resource> {
|
||||
id: Option<Id<T::Marker>>,
|
||||
tracker_index: TrackerIndex,
|
||||
tracker_indices: Option<Arc<SharedTrackerIndexAllocator>>,
|
||||
@ -144,7 +144,7 @@ impl<T: Resource> ResourceInfo<T> {
|
||||
|
||||
pub(crate) type ResourceType = &'static str;
|
||||
|
||||
pub trait Resource: 'static + Sized + WasmNotSendSync {
|
||||
pub(crate) trait Resource: 'static + Sized + WasmNotSendSync {
|
||||
type Marker: Marker;
|
||||
const TYPE: ResourceType;
|
||||
fn as_info(&self) -> &ResourceInfo<Self>;
|
||||
@ -373,10 +373,10 @@ pub type BufferAccessResult = Result<(), BufferAccessError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct BufferPendingMapping<A: HalApi> {
|
||||
pub range: Range<wgt::BufferAddress>,
|
||||
pub op: BufferMapOperation,
|
||||
pub(crate) range: Range<wgt::BufferAddress>,
|
||||
pub(crate) op: BufferMapOperation,
|
||||
// hold the parent alive while the mapping is active
|
||||
pub _parent_buffer: Arc<Buffer<A>>,
|
||||
pub(crate) _parent_buffer: Arc<Buffer<A>>,
|
||||
}
|
||||
|
||||
pub type BufferDescriptor<'a> = wgt::BufferDescriptor<Label<'a>>;
|
||||
@ -737,7 +737,7 @@ pub(crate) enum TextureInner<A: HalApi> {
|
||||
}
|
||||
|
||||
impl<A: HalApi> TextureInner<A> {
|
||||
pub fn raw(&self) -> Option<&A::Texture> {
|
||||
pub(crate) fn raw(&self) -> Option<&A::Texture> {
|
||||
match self {
|
||||
Self::Native { raw } => Some(raw),
|
||||
Self::Surface { raw: Some(tex), .. } => Some(tex.borrow()),
|
||||
|
@ -29,11 +29,14 @@ pub(crate) struct InvalidId;
|
||||
|
||||
/// A table of `T` values indexed by the id type `I`.
|
||||
///
|
||||
/// `Storage` implements [`std::ops::Index`], accepting `Id` values as
|
||||
/// indices.
|
||||
///
|
||||
/// The table is represented as a vector indexed by the ids' index
|
||||
/// values, so you should use an id allocator like `IdentityManager`
|
||||
/// that keeps the index values dense and close to zero.
|
||||
#[derive(Debug)]
|
||||
pub struct Storage<T>
|
||||
pub(crate) struct Storage<T>
|
||||
where
|
||||
T: Resource,
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user