simvx.graphics.material_slots

GPU material SSBO slot allocation, deduplication, and reclamation.

Extracted from :class:~simvx.graphics.scene_adapter.SceneAdapter so the material subsystem (the registry/dedup dicts, the SSBO numpy array, the free-list, and the weakref finalizers) lives on its own cohesive object rather than tangled into the scene-tree traversal adapter.

Module Contents

Classes

MaterialSlotManager

Allocates, deduplicates, and reclaims rows of the bindless material SSBO.

Data

API

simvx.graphics.material_slots.__all__

[‘MaterialSlotManager’]

simvx.graphics.material_slots.log

‘getLogger(…)’

class simvx.graphics.material_slots.MaterialSlotManager(renderer: Any, load_texture: collections.abc.Callable[..., int])[source]

Allocates, deduplicates, and reclaims rows of the bindless material SSBO.

Converts simvx.core :class:Material objects into integer indices into a flat numpy SSBO array, deduplicating by content so two materials with identical rendering properties share one slot. Slots are reclaimed via a weakref.finalize attached to each owning Material, keeping long-running sessions (one Material per frame) from walking the SSBO off the end.

Texture loading is delegated through the load_texture callable supplied at construction (the adapter owns the bindless texture manager); this class owns only material-slot bookkeeping.

Initialization

register(material: simvx.core.Material | None) int[source]

Convert a core Material to a Vulkan material index.

Deduplicates materials by content: two Material objects with identical rendering properties share the same SSBO slot.

release(mat_id: int, slot_idx: int) None[source]

Reclaim a material SSBO slot.

Called by the weakref.finalize attached to a Material when it goes out of scope. Pushes the slot onto the free list, clears the dedup/registry entries, and zeroes the SSBO row so stale colour data doesn’t leak through if the slot is re-used before upload() runs this frame.

upload() None[source]

Upload the material array to the renderer.