TimestampQueryImpl.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/Vulkan/TimestampQueryImpl.h>
  6. #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
  7. namespace anki {
  8. TimestampQueryImpl::~TimestampQueryImpl()
  9. {
  10. if(m_handle)
  11. {
  12. getGrManagerImpl().getTimestampQueryFactory().deleteQuery(m_handle);
  13. }
  14. }
  15. Error TimestampQueryImpl::init()
  16. {
  17. ANKI_CHECK(getGrManagerImpl().getTimestampQueryFactory().newQuery(m_handle));
  18. m_timestampPeriod = U64(getGrManagerImpl().getPhysicalDeviceProperties().limits.timestampPeriod);
  19. return Error::kNone;
  20. }
  21. TimestampQueryResult TimestampQueryImpl::getResultInternal(Second& timestamp) const
  22. {
  23. ANKI_ASSERT(m_handle);
  24. timestamp = -1.0;
  25. VkResult res;
  26. U64 value;
  27. ANKI_VK_CHECKF(res = vkGetQueryPoolResults(getVkDevice(), m_handle.getQueryPool(), m_handle.getQueryIndex(), 1, sizeof(value), &value,
  28. sizeof(value), VK_QUERY_RESULT_64_BIT));
  29. TimestampQueryResult qout = TimestampQueryResult::kNotAvailable;
  30. if(res == VK_SUCCESS)
  31. {
  32. value *= m_timestampPeriod;
  33. timestamp = Second(value) / Second(1000000000);
  34. qout = TimestampQueryResult::kAvailable;
  35. }
  36. else if(res == VK_NOT_READY)
  37. {
  38. qout = TimestampQueryResult::kNotAvailable;
  39. }
  40. else
  41. {
  42. ANKI_ASSERT(0);
  43. }
  44. return qout;
  45. }
  46. } // end namespace anki