TimestampQueryPool.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RPI.Public/GpuQuery/TimestampQueryPool.h>
  9. namespace AZ
  10. {
  11. namespace RPI
  12. {
  13. TimestampQueryPool::TimestampQueryPool(uint32_t queryCapacity, uint32_t queriesPerResult, RHI::QueryType queryType, RHI::PipelineStatisticsFlags statisticsFlags) :
  14. QueryPool(queryCapacity, queriesPerResult, queryType, statisticsFlags)
  15. {
  16. }
  17. QueryPoolPtr AZ::RPI::TimestampQueryPool::CreateTimestampQueryPool(uint32_t queryCount)
  18. {
  19. // The number of RHI Queries required to calculate a single Timestamp Result.
  20. const uint32_t RhiQueriesPerTimestampResult = 2u;
  21. return AZStd::unique_ptr<QueryPool>(aznew TimestampQueryPool(queryCount, RhiQueriesPerTimestampResult, RHI::QueryType::Timestamp, RHI::PipelineStatisticsFlags::None));
  22. }
  23. RHI::ResultCode TimestampQueryPool::BeginQueryInternal(RHI::Interval rhiQueryIndices, RHI::CommandList& commandList)
  24. {
  25. AZStd::span<const RHI::Ptr<RHI::Query>> rhiQueryArray = GetRhiQueryArray();
  26. AZ::RHI::Ptr<AZ::RHI::Query> beginQuery = rhiQueryArray[rhiQueryIndices.m_min];
  27. return beginQuery->WriteTimestamp(commandList);
  28. }
  29. RHI::ResultCode TimestampQueryPool::EndQueryInternal(RHI::Interval rhiQueryIndices, RHI::CommandList& commandList)
  30. {
  31. AZStd::span<const RHI::Ptr<RHI::Query>> rhiQueryArray = GetRhiQueryArray();
  32. AZ::RHI::Ptr<AZ::RHI::Query> endQuery = rhiQueryArray[rhiQueryIndices.m_max];
  33. return endQuery->WriteTimestamp(commandList);
  34. }
  35. }; // Namespace RPI
  36. }; // Namespace AZ