Open 3D Engine Atom Gem API Reference 26.05.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RPI::Query Class Reference

#include <Query.h>

Inherits AZStd::intrusive_base.

Public Member Functions

 AZ_TYPE_INFO (Query, "{DC956F7F-5C9C-40FC-9200-D8C75E238135}")
 
 AZ_CLASS_ALLOCATOR (Query, AZ::SystemAllocator)
 
 Query (RPI::QueryPool *queryPool, RHI::Interval rhiQueryIndices, RHI::QueryType queryType, RHI::QueryPoolScopeAttachmentType attachmentType, RHI::ScopeAttachmentAccess attachmentAccess)
 
 Query (Query &&other)=delete
 
 Query (const Query &other)=delete
 
Queryoperator= (const Query &other)=delete
 
RHI::QueryType GetQueryType () const
 Returns the QueryType.
 
QueryResultCode AddToFrameGraph (RHI::FrameGraphInterface frameGraph)
 Adds the RHI Query to the scope builder.
 
QueryResultCode BeginQuery (const RHI::FrameGraphExecuteContext &context)
 Begins the RHI Query for recording.
 
QueryResultCode EndQuery (const RHI::FrameGraphExecuteContext &context)
 Ends the RHI Query for recording.
 
QueryResultCode GetLatestResult (void *queryResult, uint32_t resultSizeInBytes, int deviceIndex)
 
template<typename T >
QueryResultCode GetLatestResult (T &queryResult, int deviceIndex)
 
QueryResultCode GetLatestResultAndWait (void *queryResult, uint32_t resultSizeInBytes, int deviceIndex)
 
template<typename T >
QueryResultCode GetLatestResultAndWait (T &queryResult, int deviceIndex)
 
void UnregisterFromPool ()
 Removes the reference of this instance in the RPI QueryPool where it was created.
 

Friends

class QueryPool
 

Detailed Description

The RPI Query references multiple RHI Queries by their indices. The amount of referenced RHI Queries depends on the maximum number of GPU frames that can be buffered before the CPU will stall, and the RPI Query's type (RHI Query indices count = QueryType * Maximum buffered GPU frames). The RHI Query indices are divided into multiple SubQueries. Each SubQuery is responsible to readback one or more RHI Queries to calculate a single result, of one frame. The number of RHI Queries referenced by a SubQuery depends on the type of the RPI Query (e.g Timestamps require two RHI Queries for a single result, while PipelineStatistics only require one RHI Query for a single result). When RPI Queries are being recorded (i.e BeginQuery() and EndQuery()), it takes at least one frame for the results of the RPI Query to be available for readback. The RPI Query utilizes the CPU stall that occurs when the amount of buffered frames reaches its limit to ensure that the the RHI Queries that were submitted RHI::Limits::Device::FrameCountMax ago are ready for readback (e.g if an RPI Query is used to record a Timestamp on frame 3, the CPU stall will ensure that the result of the Timestamp will be available on frame 6). The RPI Query will instantiate multiple SubQueries, one for each buffered frame. The SubQuery that is used for recording, will cache the FrameIndex in which it was used for recording.

Member Function Documentation

◆ GetLatestResult() [1/2]

template<typename T >
QueryResultCode AZ::RPI::Query::GetLatestResult ( T &  queryResult,
int  deviceIndex 
)
inline

Returns the earliest possible query result without stalling the thread. Result might be a few frames old. Note: When trying to retrieve query results without any queries being ready for readback, the system will return QueryCode::Fail.

Parameters
[in/out]queryResult The user provided structure where the data is copied to.

◆ GetLatestResult() [2/2]

QueryResultCode AZ::RPI::Query::GetLatestResult ( void *  queryResult,
uint32_t  resultSizeInBytes,
int  deviceIndex 
)

Returns the earliest possible query result without stalling the thread. Result might be a few frames old. Note: When trying to retrieve query results without any queries being ready for readback, the system will return QueryCode::Fail.

Parameters
[out]queryResultThe user provided structure where the data is copied to.
[in]resultSizeInBytesThe size of the data in bytes.

◆ GetLatestResultAndWait() [1/2]

template<typename T >
QueryResultCode AZ::RPI::Query::GetLatestResultAndWait ( T &  queryResult,
int  deviceIndex 
)
inline

Returns the result of the earliest possible query. It might stall the calling thread, depending if the query result is available for polling Note1: When trying to retrieve query results without any queries being ready for readback, the system will return QueryCode::Fail. Note2: If this call stalls, it's possible to continue to use the query instance on a separate thread, but it's the user's responsibility to make sure the pool isn't deleted while the thread is stalling.

Parameters
[in/out]queryResult The user provided pointer where the data is copied to.

◆ GetLatestResultAndWait() [2/2]

QueryResultCode AZ::RPI::Query::GetLatestResultAndWait ( void *  queryResult,
uint32_t  resultSizeInBytes,
int  deviceIndex 
)

Returns the result of the earliest possible query. It might stall the calling thread, depending if the query result is available for polling Note1: When trying to retrieve query results without any queries being ready for readback, the system will return QueryCode::Fail. Note2: If this call stalls, it's possible to continue to use the query instance on a separate thread, but it's the user's responsibility to make sure the pool isn't deleted while the thread is stalling.

Parameters
[out]queryResultThe user provided pointer where the data is copied to.
[in]resultSizeInBytesThe size of the data in bytes.

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