pub struct ResourceManager {
pub vertex_layout_cache: HashMap<VertexLayoutSignature, u64, FxBuildHasher>,
pub system_textures: SystemTextures,
/* private fields */
}Fields§
§vertex_layout_cache: HashMap<VertexLayoutSignature, u64, FxBuildHasher>Vertex layout cache: Signature -> ID
system_textures: SystemTexturesGlobal system fallback textures and Group 3 bind-group infrastructure.
See SystemTextures for the full list of data-semantic fallback
textures and the screen bind-group layout / samplers.
Implementations§
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn prepare_skeleton(&mut self, skeleton: &Skeleton)
pub fn prepare_skeleton(&mut self, skeleton: &Skeleton)
Upload skeleton data (current and previous frame joints) to GPU.
Sourcepub fn register_internal_texture_direct(&mut self, id: u64, view: TextureView)
pub fn register_internal_texture_direct(&mut self, id: u64, view: TextureView)
Register an internally generated texture (e.g. Render Target)
These textures do not need CPU upload, have no version control,
and their lifetime is managed by the caller.
Typically called before a RenderPass executes.
Suitable for: Pass-private resources where the Pass itself holds and maintains ID stability. Highest performance, no hash lookup.
Sourcepub fn register_internal_texture_by_name(
&mut self,
name: &str,
view: TextureView,
) -> u64
pub fn register_internal_texture_by_name( &mut self, name: &str, view: TextureView, ) -> u64
Suitable for: Cross-pass shared resources (e.g. “SceneColor”).
Internally maintains a Name -> ID mapping.
pub fn register_internal_texture(&mut self, view: TextureView) -> u64
pub fn release_internal_texture(&mut self, id: u64)
Sourcepub fn get_texture_view<'a>(&'a self, source: &TextureSource) -> &'a TextureView
pub fn get_texture_view<'a>(&'a self, source: &TextureSource) -> &'a TextureView
Unified helper method for retrieving TextureView
Prioritizes Asset-converted textures, then registered internal textures, finally returns Dummy
Sourcepub fn prepare_mesh(
&mut self,
assets: &AssetServer,
mesh: &mut Mesh,
skeleton: Option<&Skeleton>,
) -> Option<BindGroupContext>
pub fn prepare_mesh( &mut self, assets: &AssetServer, mesh: &mut Mesh, skeleton: Option<&Skeleton>, ) -> Option<BindGroupContext>
Prepare basic resources for a Mesh
Uses an “Ensure -> Collect IDs -> Check Fingerprint -> Rebind” pattern
pub fn get_or_create_layout( &mut self, entries: &[BindGroupLayoutEntry], ) -> (BindGroupLayout, u64)
pub fn create_bind_group( &self, layout: &BindGroupLayout, builder: &ResourceBuilder<'_>, ) -> (BindGroup, u64)
Sourcepub fn prepare_global(
&mut self,
assets: &AssetServer,
scene: &Scene,
render_state: &RenderState,
) -> u32
pub fn prepare_global( &mut self, assets: &AssetServer, scene: &Scene, render_state: &RenderState, ) -> u32
Prepare global binding resources
Uses an “Ensure -> Collect IDs -> Check Fingerprint -> Rebind” pattern
pub fn get_global_state( &self, render_state_id: u32, scene_id: u32, ) -> Option<&GpuGlobalState>
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn write_buffer_internal(
device: &Device,
queue: &Queue,
gpu_buffers: &mut SlotMap<GpuBufferHandle, GpuBuffer>,
buffer_index: &mut HashMap<u64, GpuBufferHandle, FxBuildHasher>,
frame_index: u64,
buffer_ref: &BufferRef,
data: &[u8],
) -> (GpuBufferHandle, EnsureResult)
pub fn write_buffer_internal( device: &Device, queue: &Queue, gpu_buffers: &mut SlotMap<GpuBufferHandle, GpuBuffer>, buffer_index: &mut HashMap<u64, GpuBufferHandle, FxBuildHasher>, frame_index: u64, buffer_ref: &BufferRef, data: &[u8], ) -> (GpuBufferHandle, EnsureResult)
Upload data for the buffer identified by buffer_ref, creating or
resizing the GPU-side buffer as needed.
This is a static method that borrows only the fields it touches,
allowing callers to hold references to other ResourceManager members
concurrently (e.g. model_allocator).
Sourcepub fn ensure_buffer<T>(
&mut self,
cpu_buffer: &CpuBuffer<T>,
) -> (GpuBufferHandle, EnsureResult)where
T: GpuData,
pub fn ensure_buffer<T>(
&mut self,
cpu_buffer: &CpuBuffer<T>,
) -> (GpuBufferHandle, EnsureResult)where
T: GpuData,
Ensure the GPU buffer for a [CpuBuffer] exists and contains the
latest data.
Uses the CpuBuffer’s internal atomic handle cache for an O(1) fast
path on subsequent calls (no hash lookup required).
Sourcepub fn ensure_buffer_ref(
&mut self,
buffer_ref: &BufferRef,
data: &[u8],
) -> (GpuBufferHandle, EnsureResult)
pub fn ensure_buffer_ref( &mut self, buffer_ref: &BufferRef, data: &[u8], ) -> (GpuBufferHandle, EnsureResult)
Ensure a GPU buffer from a BufferRef and raw byte data.
Used by generic interfaces (e.g. MaterialTrait) that don’t hold a
CpuBuffer.
Sourcepub fn ensure_buffer_id<T>(&mut self, cpu_buffer: &CpuBuffer<T>) -> u64where
T: GpuData,
pub fn ensure_buffer_id<T>(&mut self, cpu_buffer: &CpuBuffer<T>) -> u64where
T: GpuData,
Convenience wrapper returning only the physical resource ID.
Sourcepub fn prepare_attribute(&mut self, attr: &Attribute) -> EnsureResult
pub fn prepare_attribute(&mut self, attr: &Attribute) -> EnsureResult
Ensure the GPU buffer for a geometry attribute is created and current.
pub fn prepare_index(&mut self, indices: &IndexAttribute) -> EnsureResult
Sourcepub fn prepare_uniform_slot_data(
&mut self,
slot_id: u64,
data: &[u8],
label: &str,
) -> EnsureResult
pub fn prepare_uniform_slot_data( &mut self, slot_id: u64, data: &[u8], label: &str, ) -> EnsureResult
Ensure a uniform slot buffer exists, creating it on first access and uploading new data on subsequent calls when content differs.
Sourcepub fn get_gpu_buffer_by_cpu_id(&self, cpu_id: u64) -> Option<&GpuBuffer>
pub fn get_gpu_buffer_by_cpu_id(&self, cpu_id: u64) -> Option<&GpuBuffer>
Look up a [GpuBuffer] by the CPU-side buffer ID.
This goes through the buffer_index reverse map and is slightly
slower than a direct gpu_buffers.get(handle).
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn resolve_gpu_environment(
&mut self,
assets: &AssetServer,
environment: &Environment,
) -> f32
pub fn resolve_gpu_environment( &mut self, assets: &AssetServer, environment: &Environment, ) -> f32
Resolve (or create) the GpuEnvironment for the current scene environment.
This must be called before prepare_global so that the uniform buffer
can be populated with the correct env_map_max_mip_level, and so that
real resource IDs are available for BindGroup creation.
All GPU textures (cube, PMREM) are created here; IBLComputePass only
writes into them — it never creates or removes cache entries.
Returns the resolved env_map_max_mip_level (0.0 if no env map).
Sourcepub fn ensure_brdf_lut(&mut self) -> u64
pub fn ensure_brdf_lut(&mut self) -> u64
Ensure the global BRDF LUT texture exists.
Creates the texture on first call and sets needs_brdf_compute.
Returns the resource ID of the BRDF LUT view.
Sourcepub fn get_env_map_max_mip_level(&self, source: Option<TextureSource>) -> f32
pub fn get_env_map_max_mip_level(&self, source: Option<TextureSource>) -> f32
Get the env_map_max_mip_level for a given environment source.
Source§impl ResourceManager
impl ResourceManager
pub fn get_geometry(&self, handle: GeometryHandle) -> Option<&GpuGeometry>
pub fn get_or_create_vertex_layout_id( &mut self, layout: &GeneratedVertexLayout, ) -> u64
Source§impl ResourceManager
impl ResourceManager
pub fn get_material(&self, handle: MaterialHandle) -> Option<&GpuMaterial>
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn prepare_texture(
&mut self,
assets: &AssetServer,
handle: TextureHandle,
) -> ResourceState
pub fn prepare_texture( &mut self, assets: &AssetServer, handle: TextureHandle, ) -> ResourceState
Prepare GPU resources for a Texture asset.
Performs a two-level query: first retrieves the Texture config
(always immediately available after AssetServer::load_texture),
then checks whether the underlying Image has finished decoding.
If the image is not yet ready, no binding is created and the
material system falls back to a placeholder texture.
Version tracking ensures GPU resources are only rebuilt when the underlying data actually changes.
pub fn get_texture_binding( &self, handle: TextureHandle, ) -> Option<&TextureBinding>
pub fn get_image(&self, image_handle: ImageHandle) -> Option<&GpuImage>
Source§impl ResourceManager
impl ResourceManager
pub fn new( device: Device, queue: Queue, anisotropy_clamp: u16, ) -> ResourceManager
pub fn next_frame(&mut self)
pub fn frame_index(&self) -> u64
pub fn flush_model_buffers(&mut self)
Sourcepub fn allocate_model_uniform(&mut self, data: DynamicModelUniforms) -> u32
pub fn allocate_model_uniform(&mut self, data: DynamicModelUniforms) -> u32
Allocate a Model Uniform slot, returning the byte offset
Sourcepub fn model_buffer_id(&self) -> u64
pub fn model_buffer_id(&self) -> u64
Get the current Model Buffer ID for cache validation
Sourcepub fn get_cached_bind_group(
&self,
cached_bind_group_id: u64,
) -> Option<&BindGroupContext>
pub fn get_cached_bind_group( &self, cached_bind_group_id: u64, ) -> Option<&BindGroupContext>
Quickly retrieve BindGroup data by cached ID
pub fn prune(&mut self, ttl_frames: u64)
Auto Trait Implementations§
impl !Freeze for ResourceManager
impl !RefUnwindSafe for ResourceManager
impl Send for ResourceManager
impl Sync for ResourceManager
impl Unpin for ResourceManager
impl UnsafeUnpin for ResourceManager
impl !UnwindSafe for ResourceManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.