[core] Make Hub members and related types pub(crate), not pub. (#5502)

This commit is contained in:
Jim Blandy 2024-04-10 16:52:16 -07:00 committed by GitHub
parent 8289711b65
commit b7519bb73b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 41 additions and 40 deletions

View File

@ -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> {

View File

@ -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> {

View File

@ -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,
}

View File

@ -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> {

View File

@ -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)]

View File

@ -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();

View File

@ -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()),

View File

@ -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,
{