Skip to main content

ResourceManager

Struct ResourceManager 

Source
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: SystemTextures

Global 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

Source

pub fn prepare_skeleton(&mut self, skeleton: &Skeleton)

Upload skeleton data (current and previous frame joints) to GPU.

Source

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.

Source

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.

Source

pub fn register_internal_texture(&mut self, view: TextureView) -> u64

Source

pub fn release_internal_texture(&mut self, id: u64)

Source

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

Source

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

Source

pub fn get_or_create_layout( &mut self, entries: &[BindGroupLayoutEntry], ) -> (BindGroupLayout, u64)

Source

pub fn create_bind_group( &self, layout: &BindGroupLayout, builder: &ResourceBuilder<'_>, ) -> (BindGroup, u64)

Source

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

Source

pub fn get_global_state( &self, render_state_id: u32, scene_id: u32, ) -> Option<&GpuGlobalState>

Source§

impl ResourceManager

Source

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).

Source

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).

Source

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.

Source

pub fn ensure_buffer_id<T>(&mut self, cpu_buffer: &CpuBuffer<T>) -> u64
where T: GpuData,

Convenience wrapper returning only the physical resource ID.

Source

pub fn prepare_attribute(&mut self, attr: &Attribute) -> EnsureResult

Ensure the GPU buffer for a geometry attribute is created and current.

Source

pub fn prepare_index(&mut self, indices: &IndexAttribute) -> EnsureResult

Source

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.

Source

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

Source

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).

Source

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.

Source

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

Source

pub fn get_geometry(&self, handle: GeometryHandle) -> Option<&GpuGeometry>

Source

pub fn get_or_create_vertex_layout_id( &mut self, layout: &GeneratedVertexLayout, ) -> u64

Source§

impl ResourceManager

Source

pub fn get_material(&self, handle: MaterialHandle) -> Option<&GpuMaterial>

Source§

impl ResourceManager

Source

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.

Source

pub fn get_texture_binding( &self, handle: TextureHandle, ) -> Option<&TextureBinding>

Source

pub fn get_image(&self, image_handle: ImageHandle) -> Option<&GpuImage>

Source§

impl ResourceManager

Source

pub fn new( device: Device, queue: Queue, anisotropy_clamp: u16, ) -> ResourceManager

Source

pub fn next_frame(&mut self)

Source

pub fn frame_index(&self) -> u64

Source

pub fn flush_model_buffers(&mut self)

Source

pub fn allocate_model_uniform(&mut self, data: DynamicModelUniforms) -> u32

Allocate a Model Uniform slot, returning the byte offset

Source

pub fn model_buffer_id(&self) -> u64

Get the current Model Buffer ID for cache validation

Source

pub fn get_cached_bind_group( &self, cached_bind_group_id: u64, ) -> Option<&BindGroupContext>

Quickly retrieve BindGroup data by cached ID

Source

pub fn prune(&mut self, ttl_frames: u64)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,