diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-01-12 22:31:37 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-01-12 22:31:37 +0000 |
| commit | ed9b3675f5619d9888f74dd9f0f1750542f88e34 (patch) | |
| tree | 836b1663f0b6513c108c4e43a6e349cf921107c2 /Graphics/GraphicsEngine | |
| parent | Fixed potential issue with Vulkan queries (diff) | |
| download | DiligentCore-ed9b3675f5619d9888f74dd9f0f1750542f88e34.tar.gz DiligentCore-ed9b3675f5619d9888f74dd9f0f1750542f88e34.zip | |
Added query invalidation through IQuery::Invalidate and AutoInvalidate parameter to IQuery::GetData
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/QueryBase.h | 96 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/Query.h | 24 |
2 files changed, 67 insertions, 53 deletions
diff --git a/Graphics/GraphicsEngine/include/QueryBase.h b/Graphics/GraphicsEngine/include/QueryBase.h index f32c7455..31480f2c 100644 --- a/Graphics/GraphicsEngine/include/QueryBase.h +++ b/Graphics/GraphicsEngine/include/QueryBase.h @@ -107,6 +107,11 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_Query, TDeviceObjectBase) + virtual void Invalidate() override + { + m_State = QueryState::Inactive; + } + bool OnBeginQuery(IDeviceContext* pContext) { if (this->m_Desc.Type == QUERY_TYPE_TIMESTAMP) @@ -166,65 +171,62 @@ public: bool CheckQueryDataPtr(void* pData, Uint32 DataSize) { - if (pData == nullptr) - { - LOG_ERROR_MESSAGE("Query data must not be null"); - return false; - } - if (m_State != QueryState::Complete) { LOG_ERROR_MESSAGE("Attempting to get data of query '", this->m_Desc.Name, "' that has not been ended"); return false; } - if (*reinterpret_cast<QUERY_TYPE*>(pData) != this->m_Desc.Type) + if (pData != nullptr) { - LOG_ERROR_MESSAGE("Incorrect query data structure type."); - return false; - } - - switch (this->m_Desc.Type) - { - case QUERY_TYPE_UNDEFINED: - UNEXPECTED("Undefined query type is unexpected"); + if (*reinterpret_cast<QUERY_TYPE*>(pData) != this->m_Desc.Type) + { + LOG_ERROR_MESSAGE("Incorrect query data structure type."); return false; + } - case QUERY_TYPE_OCCLUSION: - if (DataSize != sizeof(QueryDataOcclusion)) - { - LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataOcclusion), " (aka sizeof(QueryDataOcclusion)) is expected"); - return false; - } - break; - - case QUERY_TYPE_BINARY_OCCLUSION: - if (DataSize != sizeof(QueryDataBinaryOcclusion)) - { - LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataBinaryOcclusion), " (aka sizeof(QueryDataBinaryOcclusion)) is expected"); + switch (this->m_Desc.Type) + { + case QUERY_TYPE_UNDEFINED: + UNEXPECTED("Undefined query type is unexpected"); return false; - } - break; - case QUERY_TYPE_TIMESTAMP: - if (DataSize != sizeof(QueryDataTimestamp)) - { - LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataTimestamp), " (aka sizeof(QueryDataTimestamp)) is expected"); + case QUERY_TYPE_OCCLUSION: + if (DataSize != sizeof(QueryDataOcclusion)) + { + LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataOcclusion), " (aka sizeof(QueryDataOcclusion)) is expected"); + return false; + } + break; + + case QUERY_TYPE_BINARY_OCCLUSION: + if (DataSize != sizeof(QueryDataBinaryOcclusion)) + { + LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataBinaryOcclusion), " (aka sizeof(QueryDataBinaryOcclusion)) is expected"); + return false; + } + break; + + case QUERY_TYPE_TIMESTAMP: + if (DataSize != sizeof(QueryDataTimestamp)) + { + LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataTimestamp), " (aka sizeof(QueryDataTimestamp)) is expected"); + return false; + } + break; + + case QUERY_TYPE_PIPELINE_STATISTICS: + if (DataSize != sizeof(QueryDataPipelineStatistics)) + { + LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataPipelineStatistics), " (aka sizeof(QueryDataPipelineStatistics)) is expected"); + return false; + } + break; + + default: + UNEXPECTED("Unexpected query type"); return false; - } - break; - - case QUERY_TYPE_PIPELINE_STATISTICS: - if (DataSize != sizeof(QueryDataPipelineStatistics)) - { - LOG_ERROR_MESSAGE("The size of query data (", DataSize, ") is incorrect: ", sizeof(QueryDataPipelineStatistics), " (aka sizeof(QueryDataPipelineStatistics)) is expected"); - return false; - } - break; - - default: - UNEXPECTED("Unexpected query type"); - return false; + } } return true; diff --git a/Graphics/GraphicsEngine/interface/Query.h b/Graphics/GraphicsEngine/interface/Query.h index b71e4792..b5f3949e 100644 --- a/Graphics/GraphicsEngine/interface/Query.h +++ b/Graphics/GraphicsEngine/interface/Query.h @@ -178,16 +178,28 @@ public: /// Gets the query data. - /// \param [in] pData - pointer to the query data structure. Depending on the type of the query, - /// this must be the pointer to Diligent::QueryDataOcclusion, Diligent::QueryDataBinaryOcclusion, - /// Diligent::QueryDataTimestamp, or Diligent::QueryDataPipelineStatistics - /// structure. - /// \param [in] DataSize - Size of the data structure. + /// \param [in] pData - Pointer to the query data structure. Depending on the type of the query, + /// this must be the pointer to Diligent::QueryDataOcclusion, Diligent::QueryDataBinaryOcclusion, + /// Diligent::QueryDataTimestamp, or Diligent::QueryDataPipelineStatistics + /// structure. + /// An application may provide nullptr to only check the query status. + /// \param [in] DataSize - Size of the data structure. + /// \param [in] AutoInvalidate - Whether to invalidate the query if the results are available and release associated resources. + /// An application should typically always invalidate completed queries unless + /// it needs to retrieve the same data through GetData() multiple times. + /// A query will not be invalidated if pData is nullptr. + /// /// \return true if the query data is available and false otherwise. /// /// \note In Direct3D11 backend timestamp queries will only be available after FinishFrame is called /// for the frame in which they were collected. - virtual bool GetData(void* pData, Uint32 DataSize) = 0; + /// + /// If AutoInvalidate is set to true, and the data have been retrieved, an application + /// must not call GetData() until it begins and ends the query again. + virtual bool GetData(void* pData, Uint32 DataSize, bool AutoInvalidate = true) = 0; + + /// Invalidates the query and releases associated resources. + virtual void Invalidate() = 0; }; } // namespace Diligent |
