Struct webrender::texture_cache::TextureCache

source ·
pub struct TextureCache {
    shared_textures: SharedTextures,
    max_texture_size: i32,
    tiling_threshold: i32,
    swizzle: Option<SwizzleSettings>,
    debug_flags: DebugFlags,
    pub next_id: CacheTextureId,
    pub pending_updates: TextureUpdateList,
    now: FrameStamp,
    lru_cache: LRUCache<CacheEntry, AutoCacheEntryMarker>,
    manual_entries: FreeList<CacheEntry, ManualCacheEntryMarker>,
    manual_handles: Vec<FreeListHandle<ManualCacheEntryMarker>>,
    bytes_allocated: [usize; 7],
}
Expand description

General-purpose manager for images in GPU memory. This includes images, rasterized glyphs, rasterized blobs, cached render tasks, etc.

The texture cache is owned and managed by the RenderBackend thread, and produces a series of commands to manipulate the textures on the Renderer thread. These commands are executed before any rendering is performed for a given frame.

Entries in the texture cache are not guaranteed to live past the end of the frame in which they are requested, and may be evicted. The API supports querying whether an entry is still available.

The TextureCache is different from the GpuCache in that the former stores images, whereas the latter stores data and parameters for use in the shaders. This means that the texture cache can be visualized, which is a good way to understand how it works. Enabling gfx.webrender.debug.texture-cache shows a live view of its contents in Firefox.

Fields§

§shared_textures: SharedTextures

Set of texture arrays in different formats used for the shared cache.

§max_texture_size: i32

Maximum texture size supported by hardware.

§tiling_threshold: i32

Maximum texture size before it is considered preferable to break the texture into tiles.

§swizzle: Option<SwizzleSettings>

Settings on using texture unit swizzling.

§debug_flags: DebugFlags

The current set of debug flags.

§next_id: CacheTextureId

The next unused virtual texture ID. Monotonically increasing.

§pending_updates: TextureUpdateList

A list of allocations and updates that need to be applied to the texture cache in the rendering thread this frame.

§now: FrameStamp

The current FrameStamp. Used for cache eviction policies.

§lru_cache: LRUCache<CacheEntry, AutoCacheEntryMarker>

Cache of texture cache handles with automatic lifetime management, evicted in a least-recently-used order.

§manual_entries: FreeList<CacheEntry, ManualCacheEntryMarker>

Cache of texture cache entries with manual liftime management.

§manual_handles: Vec<FreeListHandle<ManualCacheEntryMarker>>

Strong handles for the manual_entries FreeList.

§bytes_allocated: [usize; 7]

Memory usage of allocated entries in all of the shared or standalone textures. Includes both manually and automatically evicted entries.

Implementations§

source§

impl TextureCache

source

const MAX_EVICTIONS_PER_FRAME: usize = 32usize

The maximum number of items that will be evicted per frame. This limit helps avoid jank on frames where we want to evict a large number of items. Instead, we’d prefer to drop the items incrementally over a number of frames, even if that means the total allocated size of the cache is above the desired threshold for a small number of frames.

source

pub fn new( max_texture_size: i32, tiling_threshold: i32, color_formats: TextureFormatPair<ImageFormat>, swizzle: Option<SwizzleSettings>, config: &TextureCacheConfig, ) -> Self

source

pub fn set_debug_flags(&mut self, flags: DebugFlags)

source

pub fn clear_all(&mut self)

Clear all entries in the texture cache. This is a fairly drastic step that should only be called very rarely.

source

pub fn begin_frame( &mut self, stamp: FrameStamp, profile: &mut TransactionProfile, )

Called at the beginning of each frame.

source

pub fn end_frame(&mut self, profile: &mut TransactionProfile)

source

pub fn run_compaction(&mut self, gpu_cache: &mut GpuCache)

source

pub fn request( &mut self, handle: &TextureCacheHandle, gpu_cache: &mut GpuCache, ) -> bool

source

fn get_entry_opt(&self, handle: &TextureCacheHandle) -> Option<&CacheEntry>

source

fn get_entry_opt_mut( &mut self, handle: &TextureCacheHandle, ) -> Option<&mut CacheEntry>

source

pub fn needs_upload(&self, handle: &TextureCacheHandle) -> bool

source

pub fn max_texture_size(&self) -> i32

source

pub fn tiling_threshold(&self) -> i32

source

pub fn pending_updates(&mut self) -> TextureUpdateList

source

pub fn update( &mut self, handle: &mut TextureCacheHandle, descriptor: ImageDescriptor, filter: TextureFilter, data: Option<CachedImageData>, user_data: [f32; 4], dirty_rect: ImageDirtyRect, gpu_cache: &mut GpuCache, eviction_notice: Option<&EvictionNotice>, uv_rect_kind: UvRectKind, eviction: Eviction, shader: TargetShader, )

source

pub fn is_allocated(&self, handle: &TextureCacheHandle) -> bool

source

pub fn get_allocated_size(&self, handle: &TextureCacheHandle) -> Option<usize>

source

pub fn get(&self, handle: &TextureCacheHandle) -> CacheItem

source

pub fn get_cache_location( &self, handle: &TextureCacheHandle, ) -> (CacheTextureId, DeviceIntRect, Swizzle, GpuCacheHandle, [f32; 4])

A more detailed version of get(). This allows access to the actual device rect of the cache allocation.

Returns a tuple identifying the texture, the layer, the region, and its GPU handle.

source

fn evict_impl(&mut self, entry: CacheEntry)

Internal helper function to evict a strong texture cache handle

source

pub fn evict_handle(&mut self, handle: &TextureCacheHandle)

Evict a texture cache handle that was previously set to be in manual eviction mode.

source

pub fn dump_color8_linear_as_svg(&self, output: &mut dyn Write) -> Result<()>

source

pub fn dump_color8_glyphs_as_svg(&self, output: &mut dyn Write) -> Result<()>

source

pub fn dump_alpha8_glyphs_as_svg(&self, output: &mut dyn Write) -> Result<()>

source

pub fn dump_alpha8_linear_as_svg(&self, output: &mut dyn Write) -> Result<()>

source

fn get_eviction_threshold(&self, budget_type: BudgetType) -> usize

Get the eviction threshold, in bytes, for the given budget type.

source

fn should_continue_evicting( &self, budget_type: BudgetType, eviction_count: usize, ) -> Option<u64>

Returns whether to continue eviction and how cold an item need to be to be evicted.

If the None is returned, stop evicting. If the Some(n) is returned, continue evicting if the coldest item hasn’t been used for more than n frames.

source

fn evict_items_from_cache_if_required( &mut self, profile: &mut TransactionProfile, )

Evict old items from the shared and standalone caches, if we’re over a threshold memory usage value

source

fn free(&mut self, entry: &CacheEntry)

source

fn allocate_from_shared_cache( &mut self, params: &CacheAllocParams, ) -> (CacheEntry, BudgetType)

Allocate a block from the shared cache.

source

pub fn is_allowed_in_shared_cache( &self, filter: TextureFilter, descriptor: &ImageDescriptor, ) -> bool

source

pub fn alloc_render_target( &mut self, size: DeviceIntSize, format: ImageFormat, ) -> CacheTextureId

Allocate a render target via the pending updates sent to the renderer

source

pub fn free_render_target(&mut self, id: CacheTextureId)

Free an existing render target

source

fn allocate_standalone_entry( &mut self, params: &CacheAllocParams, ) -> (CacheEntry, BudgetType)

Allocates a new standalone cache entry.

source

fn allocate( &mut self, params: &CacheAllocParams, handle: &mut TextureCacheHandle, eviction: Eviction, )

Allocates a cache entry for the given parameters, and updates the provided handle to point to the new entry.

source

pub fn shared_alpha_expected_format(&self) -> ImageFormat

source

pub fn shared_color_expected_format(&self) -> ImageFormat

source

pub fn report_memory(&self, ops: &mut MallocSizeOfOps) -> usize

Trait Implementations§

source§

impl Serialize for TextureCache

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

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

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

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

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.