Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::IO::BlockCache Class Reference

Inherits AZ::IO::StreamStackEntry.

Classes

struct  Section
 

Public Member Functions

 BlockCache (u64 cacheSize, u32 blockSize, u32 alignment, bool onlyEpilogWrites)
 
 BlockCache (BlockCache &&rhs)=delete
 
 BlockCache (const BlockCache &rhs)=delete
 
BlockCacheoperator= (BlockCache &&rhs)=delete
 
BlockCacheoperator= (const BlockCache &rhs)=delete
 
void QueueRequest (FileRequest *request) override
 
bool ExecuteRequests () override
 
void UpdateStatus (Status &status) const override
 Gets a combined status update from all the nodes in the stack.
 
void UpdateCompletionEstimates (AZStd::chrono::steady_clock::time_point now, AZStd::vector< FileRequest * > &internalPending, StreamerContext::PreparedQueue::iterator pendingBegin, StreamerContext::PreparedQueue::iterator pendingEnd) override
 
void AddDelayedRequests (AZStd::vector< FileRequest * > &internalPending)
 
void UpdatePendingRequestEstimations ()
 
void FlushCache (const RequestPath &filePath)
 
void FlushEntireCache ()
 
void CollectStatistics (AZStd::vector< Statistic > &statistics) const override
 
double CalculateHitRatePercentage () const
 
double CalculateCacheableRatePercentage () const
 
s32 CalculateAvailableRequestSlots () const
 
- Public Member Functions inherited from AZ::IO::StreamStackEntry
 StreamStackEntry (AZStd::string &&name)
 
virtual const AZStd::stringGetName () const
 Returns the name that uniquely identifies this entry.
 
virtual void SetNext (AZStd::shared_ptr< StreamStackEntry > next)
 
virtual AZStd::shared_ptr< StreamStackEntryGetNext () const
 
virtual void SetContext (StreamerContext &context)
 
virtual void PrepareRequest (FileRequest *request)
 
virtual void QueueRequest (FileRequest *request)
 
virtual bool ExecuteRequests ()
 
virtual void UpdateStatus (Status &status) const
 Gets a combined status update from all the nodes in the stack.
 
virtual void UpdateCompletionEstimates (AZStd::chrono::steady_clock::time_point now, AZStd::vector< FileRequest * > &internalPending, StreamerContext::PreparedQueue::iterator pendingBegin, StreamerContext::PreparedQueue::iterator pendingEnd)
 
virtual void CollectStatistics (AZStd::vector< Statistic > &statistics) const
 

Protected Types

enum class  CacheResult { ReadFromCache , CacheMiss , Queued , Delayed }
 
using TimePoint = AZStd::chrono::steady_clock::time_point
 

Protected Member Functions

void ReadFile (FileRequest *request, Requests::ReadData &data)
 
void ContinueReadFile (FileRequest *request, u64 fileLength)
 
CacheResult ReadFromCache (FileRequest *request, Section &section, const RequestPath &filePath)
 
CacheResult ReadFromCache (FileRequest *request, Section &section, u32 cacheBlock)
 
CacheResult ServiceFromCache (FileRequest *request, Section &section, const RequestPath &filePath, bool sharedRead)
 
void CompleteRead (FileRequest &request)
 
bool SplitRequest (Section &prolog, Section &main, Section &epilog, const RequestPath &filePath, u64 fileLength, u64 offset, u64 size, u8 *buffer) const
 
u8 * GetCacheBlockData (u32 index)
 
void TouchBlock (u32 index)
 
AZ::u32 RecycleOldestBlock (const RequestPath &filePath, u64 offset)
 
u32 FindInCache (const RequestPath &filePath, u64 offset) const
 
bool IsCacheBlockInFlight (u32 index) const
 
void ResetCacheEntry (u32 index)
 
void ResetCache ()
 
void Report (const Requests::ReportData &data) const
 

Protected Attributes

AZStd::unordered_multimap< FileRequest *, Sectionm_pendingRequests
 Map of the file requests that are being processed and the sections of the parent requests they'll complete.
 
AZStd::deque< Sectionm_delayedSections
 List of file sections that were delayed because the cache was full.
 
AZ::Statistics::RunningStatistic m_hitRateStat
 
AZ::Statistics::RunningStatistic m_cacheableStat
 
u8 * m_cache
 
u64 m_cacheSize
 
u32 m_blockSize
 
u32 m_alignment
 
u32 m_numBlocks
 
s32 m_numInFlightRequests { 0 }
 
AZStd::unique_ptr< RequestPath[]> m_cachedPaths
 The file path associated with a cache block.
 
AZStd::unique_ptr< u64[]> m_cachedOffsets
 The offset into the file the cache blocks starts at.
 
AZStd::unique_ptr< TimePoint[]> m_blockLastTouched
 The last time the cache block was read from.
 
AZStd::unique_ptr< FileRequest *[]> m_inFlightRequests
 The file request that's currently read data into the cache block. If null, the block has been read.
 
s32 m_numMetaDataRetrievalInProgress { 0 }
 The number of requests waiting for meta data to be retrieved.
 
bool m_onlyEpilogWrites
 Whether or not only the epilog ever writes to the cache.
 
- Protected Attributes inherited from AZ::IO::StreamStackEntry
AZStd::string m_name
 The name that uniquely identifies this entry.
 
AZStd::shared_ptr< StreamStackEntrym_next
 The next entry in the stack.
 
StreamerContextm_context
 Context information for the entire streaming stack.
 

Static Protected Attributes

static constexpr u32 s_fileNotCached = static_cast<u32>(-1)
 

Member Enumeration Documentation

◆ CacheResult

enum class AZ::IO::BlockCache::CacheResult
strongprotected
Enumerator
ReadFromCache 

Data was found in the cache and reused.

CacheMiss 

Data wasn't found in the cache and no sub request was queued.

Queued 

A sub request was created or appended and queued for processing on the next entry in the streamer stack.

Delayed 

There's no more room to queue a new request, so delay the request until a slot becomes available.

Member Function Documentation

◆ CollectStatistics()

void AZ::IO::BlockCache::CollectStatistics ( AZStd::vector< Statistic > &  statistics) const
overridevirtual

Collect various statistics on this stack entry. These are for profiling and debugging purposes only.

Reimplemented from AZ::IO::StreamStackEntry.

◆ ExecuteRequests()

bool AZ::IO::BlockCache::ExecuteRequests ( )
overridevirtual

Executes one or more queued requests. This is needed for synchronously executing requests, but asynchronous requests can already be running from the PrepareRequest call in which case this call is ignored.

Returns
True if a request was processed, otherwise false.

Reimplemented from AZ::IO::StreamStackEntry.

◆ QueueRequest()

void AZ::IO::BlockCache::QueueRequest ( FileRequest request)
overridevirtual

Queues a request to be executed at a later point when ExecuteRequests is called. This can include splitting up the request in more fine-grained steps.

Reimplemented from AZ::IO::StreamStackEntry.

◆ UpdateCompletionEstimates()

void AZ::IO::BlockCache::UpdateCompletionEstimates ( AZStd::chrono::steady_clock::time_point  now,
AZStd::vector< FileRequest * > &  internalPending,
StreamerContext::PreparedQueue::iterator  pendingBegin,
StreamerContext::PreparedQueue::iterator  pendingEnd 
)
overridevirtual

Updates the estimate of the time the requests will complete. This generally works by bubbling up the estimation and each stack entry adding it's additional overhead if any. When chaining this call, first call the next entry in the stack before adding the current entry's estimate.

Parameters
nowThe current time. This is captured once to avoid repeatedly querying the system clock.
internalPendingThe requests that are pending in the stream stack. These are always estimated as coming after the queued requests. Because this call will go from the top of the stack to the bottom, but estimation is calculated from the bottom to the top, this list should be processed in reverse order.
pendingBeginIterator pointing to the start of the requests that are waiting for a processing slot in the stack.
pendingEndIterator pointing to the end of the requests that are waiting for a processing slot in the stack.

Reimplemented from AZ::IO::StreamStackEntry.

◆ UpdateStatus()

void AZ::IO::BlockCache::UpdateStatus ( Status status) const
overridevirtual

Gets a combined status update from all the nodes in the stack.

Reimplemented from AZ::IO::StreamStackEntry.


The documentation for this class was generated from the following file: