TimestampQueryPool.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/RHI/FrameGraphExecuteContext.h>
  9. #include <Atom/RPI.Public/GpuQuery/TimestampQueryPool.h>
  10. namespace AZ
  11. {
  12. namespace RPI
  13. {
  14. TimestampQueryPool::TimestampQueryPool(uint32_t queryCapacity, uint32_t queriesPerResult, RHI::QueryType queryType, RHI::PipelineStatisticsFlags statisticsFlags) :
  15. QueryPool(queryCapacity, queriesPerResult, queryType, statisticsFlags)
  16. {
  17. }
  18. QueryPoolPtr AZ::RPI::TimestampQueryPool::CreateTimestampQueryPool(uint32_t queryCount)
  19. {
  20. // The number of RHI Queries required to calculate a single Timestamp Result.
  21. const uint32_t RhiQueriesPerTimestampResult = 2u;
  22. return AZStd::unique_ptr<QueryPool>(aznew TimestampQueryPool(queryCount, RhiQueriesPerTimestampResult, RHI::QueryType::Timestamp, RHI::PipelineStatisticsFlags::None));
  23. }
  24. RHI::ResultCode TimestampQueryPool::BeginQueryInternal(RHI::Interval rhiQueryIndices, const RHI::FrameGraphExecuteContext& context)
  25. {
  26. AZStd::span<const RHI::Ptr<RHI::Query>> rhiQueryArray = GetRhiQueryArray();
  27. AZ::RHI::Ptr<AZ::RHI::Query> beginQuery = rhiQueryArray[rhiQueryIndices.m_min];
  28. return beginQuery->GetDeviceQuery(context.GetDeviceIndex())->WriteTimestamp(*context.GetCommandList());
  29. }
  30. RHI::ResultCode TimestampQueryPool::EndQueryInternal(RHI::Interval rhiQueryIndices, const RHI::FrameGraphExecuteContext& context)
  31. {
  32. AZStd::span<const RHI::Ptr<RHI::Query>> rhiQueryArray = GetRhiQueryArray();
  33. AZ::RHI::Ptr<AZ::RHI::Query> endQuery = rhiQueryArray[rhiQueryIndices.m_max];
  34. return endQuery->GetDeviceQuery(context.GetDeviceIndex())->WriteTimestamp(*context.GetCommandList());
  35. }
  36. }; // Namespace RPI
  37. }; // Namespace AZ