pub struct AtlasSet<U: Hash + Eq + Clone = String, Data: Copy + Default = i32> {
Show 15 fields pub texture: Texture, pub texture_view: TextureView, pub layers: Vec<Atlas>, pub extent: Extent3d, pub store: Slab<(Allocation<Data>, U)>, pub lookup: HashMap<U, usize>, pub cache: LruCache<usize, usize>, pub last_used: HashSet<usize>, pub format: TextureFormat, pub max_layers: usize, pub deallocations_limit: usize, pub layer_check_limit: usize, pub layer_free_limit: usize, pub use_ref_count: bool, pub texture_group: TextureGroup,
}
Expand description

AtlasSet is used to hold and contain the data of many Atlas layers. Each Atlas keeps track of the allocations allowed. Each allocation is a given Width/Height as well as Position that a Texture image can fit within the atlas.

We try to use Store to keep all Allocations localized so if they need to be unloaded, migrated or replaced then the system can prevent improper rendering using a outdated Allocation. We will also attempt to keep track of reference counts loading the Index and try to keep track of LRU cache and a list of last used Indexs. This will help reduce errors and can help to reduce Vram and Later Reduce Fragmentation of the Atlas.

FRAGMENTATION************* Fragmentation of a Atlas is when you Deallocate and Allocate new image textures into the Atlas. As this occurs there is a possibility that Small spots that can not be used in the Atlas to appear. These small Sections might get merged into larger Sections upon Deallocation of neighboring Allocations, But in some Cases these might over run the Atlas cuasing use to use way more Vram than is needed. To fix this we must migrate all loaded Allocations to a new Atlas and either move the old atlas to the back of the list for reuse or unload it. We can accomplish knowing when to migrate the atlas by setting a deallocations_limit. We also can know when to unload a empty layer by using the layer_free_limit. This will allow us to control VRam usage.

TODO Keep track of Indexs within an Atlas. TODO Create Migration Check function. TODO Add way to tell if any texture needs to migrate. TODO Add limitations to a migrating texture so we only move a bit at a time. TODO Add Ability to Tell user through API that Vertexs and Indicies need to be TODO reloaded upon migration changes.

Fields§

§texture: Texture

Texture in GRAM

§texture_view: TextureView

Texture View for WGPU

§layers: Vec<Atlas>

Layers of texture.

§extent: Extent3d

Holds the Original Texture Size and layer information.

§store: Slab<(Allocation<Data>, U)>

Store the Allocations se we can easily remove and update them. use a Generation id to avoid conflict if users use older allocation id’s. Also stores the Key associated with the Allocation.

§lookup: HashMap<U, usize>

for key to index lookups.

§cache: LruCache<usize, usize>

keeps a list of least used allocations so we can unload them when need be. Also include the RefCount per ID lookup. we use this to keep track of when Fonts need to be unloaded. this only helps to get memory back but does not fix fragmentation of the Atlas.

§last_used: HashSet<usize>

List of allocations used in the last frame to ensure we dont unload what is in use.

§format: TextureFormat

Format the Texture uses.

§max_layers: usize

When the System will Error if reached. This is the max allowed Layers Default is 256 as Most GPU allow a max of 256.

§deallocations_limit: usize

Limit of deallocations allowed before we attempt to migrate the textures allocations to fix fragmentation. TODO Think of better way to figure out fragmentations.

§layer_check_limit: usize

amount of layers in memory before we start checking for fragmentations.

§layer_free_limit: usize

When we should free empty layers. this must be more than 1 otherwise will cause issues.

§use_ref_count: bool

uses the refcount to unload rather than the unused. must exist for fonts to unload correctly and must be set to false for them.

§texture_group: TextureGroup

Texture Bind group for Atlas

Implementations§

source§

impl<U: Hash + Eq + Clone, Data: Copy + Default> AtlasSet<U, Data>

source

pub fn new( renderer: &mut GpuRenderer, format: TextureFormat, use_ref_count: bool ) -> Self

source

pub fn upload_allocation( &mut self, buffer: &[u8], allocation: &Allocation<Data>, renderer: &GpuRenderer )

source

pub fn clear(&mut self)

source

pub fn trim(&mut self)

source

pub fn promote_by_key(&mut self, key: U)

source

pub fn promote(&mut self, id: usize)

source

pub fn lookup(&self, key: &U) -> Option<usize>

Get the ID of a image if it is loaded.

source

pub fn peek_by_key(&mut self, key: &U) -> Option<&(Allocation<Data>, U)>

source

pub fn peek(&mut self, id: usize) -> Option<&(Allocation<Data>, U)>

source

pub fn contains_key(&mut self, key: &U) -> bool

source

pub fn contains(&mut self, id: usize) -> bool

source

pub fn get_by_key(&mut self, key: &U) -> Option<Allocation<Data>>

source

pub fn get(&mut self, id: usize) -> Option<Allocation<Data>>

source

pub fn remove_by_key(&mut self, key: &U) -> Option<usize>

Removing will leave anything using the texture inable to load the correct texture if a new texture is loaded in the olds place. TODO Redo texture system so texture allocations are not held by the images but instead TODO are held by the system so we can reload images later on if they got unloaded.

returns the layer id if removed otherwise None for everything else.

source

pub fn remove(&mut self, id: usize) -> Option<usize>

source

pub fn upload( &mut self, key: U, bytes: &[u8], width: u32, height: u32, data: Data, renderer: &GpuRenderer ) -> Option<usize>

source

pub fn upload_with_alloc( &mut self, key: U, bytes: &[u8], width: u32, height: u32, data: Data, renderer: &GpuRenderer ) -> Option<(usize, Allocation<Data>)>

source

pub fn size(&self) -> UVec3

source

pub fn bind_group(&self) -> &BindGroup

Auto Trait Implementations§

§

impl<U, Data> Freeze for AtlasSet<U, Data>

§

impl<U = String, Data = i32> !RefUnwindSafe for AtlasSet<U, Data>

§

impl<U, Data> Send for AtlasSet<U, Data>
where U: Send, Data: Send,

§

impl<U, Data> Sync for AtlasSet<U, Data>
where U: Sync, Data: Sync,

§

impl<U, Data> Unpin for AtlasSet<U, Data>
where U: Unpin, Data: Unpin,

§

impl<U = String, Data = i32> !UnwindSafe for AtlasSet<U, Data>

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 + Sync + Send>

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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

§

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,