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§
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
impl TextureCache
sourceconst MAX_EVICTIONS_PER_FRAME: usize = 32usize
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.
pub fn new( max_texture_size: i32, tiling_threshold: i32, color_formats: TextureFormatPair<ImageFormat>, swizzle: Option<SwizzleSettings>, config: &TextureCacheConfig, ) -> Self
pub fn set_debug_flags(&mut self, flags: DebugFlags)
sourcepub fn clear_all(&mut self)
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.
sourcepub fn begin_frame(
&mut self,
stamp: FrameStamp,
profile: &mut TransactionProfile,
)
pub fn begin_frame( &mut self, stamp: FrameStamp, profile: &mut TransactionProfile, )
Called at the beginning of each frame.
pub fn end_frame(&mut self, profile: &mut TransactionProfile)
pub fn run_compaction(&mut self, gpu_cache: &mut GpuCache)
pub fn request( &mut self, handle: &TextureCacheHandle, gpu_cache: &mut GpuCache, ) -> bool
fn get_entry_opt(&self, handle: &TextureCacheHandle) -> Option<&CacheEntry>
fn get_entry_opt_mut( &mut self, handle: &TextureCacheHandle, ) -> Option<&mut CacheEntry>
pub fn needs_upload(&self, handle: &TextureCacheHandle) -> bool
pub fn max_texture_size(&self) -> i32
pub fn tiling_threshold(&self) -> i32
pub fn pending_updates(&mut self) -> TextureUpdateList
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, )
pub fn is_allocated(&self, handle: &TextureCacheHandle) -> bool
pub fn get_allocated_size(&self, handle: &TextureCacheHandle) -> Option<usize>
pub fn get(&self, handle: &TextureCacheHandle) -> CacheItem
sourcepub fn get_cache_location(
&self,
handle: &TextureCacheHandle,
) -> (CacheTextureId, DeviceIntRect, Swizzle, GpuCacheHandle, [f32; 4])
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.
sourcefn evict_impl(&mut self, entry: CacheEntry)
fn evict_impl(&mut self, entry: CacheEntry)
Internal helper function to evict a strong texture cache handle
sourcepub fn evict_handle(&mut self, handle: &TextureCacheHandle)
pub fn evict_handle(&mut self, handle: &TextureCacheHandle)
Evict a texture cache handle that was previously set to be in manual eviction mode.
pub fn dump_color8_linear_as_svg(&self, output: &mut dyn Write) -> Result<()>
pub fn dump_color8_glyphs_as_svg(&self, output: &mut dyn Write) -> Result<()>
pub fn dump_alpha8_glyphs_as_svg(&self, output: &mut dyn Write) -> Result<()>
pub fn dump_alpha8_linear_as_svg(&self, output: &mut dyn Write) -> Result<()>
sourcefn get_eviction_threshold(&self, budget_type: BudgetType) -> usize
fn get_eviction_threshold(&self, budget_type: BudgetType) -> usize
Get the eviction threshold, in bytes, for the given budget type.
sourcefn should_continue_evicting(
&self,
budget_type: BudgetType,
eviction_count: usize,
) -> Option<u64>
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.
sourcefn evict_items_from_cache_if_required(
&mut self,
profile: &mut TransactionProfile,
)
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
fn free(&mut self, entry: &CacheEntry)
Allocate a block from the shared cache.
sourcepub fn alloc_render_target(
&mut self,
size: DeviceIntSize,
format: ImageFormat,
) -> CacheTextureId
pub fn alloc_render_target( &mut self, size: DeviceIntSize, format: ImageFormat, ) -> CacheTextureId
Allocate a render target via the pending updates sent to the renderer
sourcepub fn free_render_target(&mut self, id: CacheTextureId)
pub fn free_render_target(&mut self, id: CacheTextureId)
Free an existing render target
sourcefn allocate_standalone_entry(
&mut self,
params: &CacheAllocParams,
) -> (CacheEntry, BudgetType)
fn allocate_standalone_entry( &mut self, params: &CacheAllocParams, ) -> (CacheEntry, BudgetType)
Allocates a new standalone cache entry.
sourcefn allocate(
&mut self,
params: &CacheAllocParams,
handle: &mut TextureCacheHandle,
eviction: Eviction,
)
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.
pub fn report_memory(&self, ops: &mut MallocSizeOfOps) -> usize
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextureCache
impl !RefUnwindSafe for TextureCache
impl !Send for TextureCache
impl !Sync for TextureCache
impl Unpin for TextureCache
impl !UnwindSafe for TextureCache
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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