TimestampQueryImpl.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2009-2020, 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. {
  9. TimestampQueryImpl::~TimestampQueryImpl()
  10. {
  11. if(m_handle)
  12. {
  13. getGrManagerImpl().getTimestampQueryFactory().deleteQuery(m_handle);
  14. }
  15. }
  16. Error TimestampQueryImpl::init()
  17. {
  18. ANKI_CHECK(getGrManagerImpl().getTimestampQueryFactory().newQuery(m_handle));
  19. m_timestampPeriod = U64(getGrManagerImpl().getPhysicalDeviceProperties().limits.timestampPeriod);
  20. return Error::NONE;
  21. }
  22. TimestampQueryResult TimestampQueryImpl::getResultInternal(Second& timestamp) const
  23. {
  24. ANKI_ASSERT(m_handle);
  25. timestamp = -1.0;
  26. VkResult res;
  27. U64 value;
  28. ANKI_VK_CHECKF(res = vkGetQueryPoolResults(getDevice(), m_handle.getQueryPool(), m_handle.getQueryIndex(), 1,
  29. sizeof(value), &value, sizeof(value), VK_QUERY_RESULT_64_BIT));
  30. TimestampQueryResult qout = TimestampQueryResult::NOT_AVAILABLE;
  31. if(res == VK_SUCCESS)
  32. {
  33. value *= m_timestampPeriod;
  34. timestamp = Second(value) / Second(1000000000);
  35. qout = TimestampQueryResult::AVAILABLE;
  36. }
  37. else if(res == VK_NOT_READY)
  38. {
  39. qout = TimestampQueryResult::NOT_AVAILABLE;
  40. }
  41. else
  42. {
  43. ANKI_ASSERT(0);
  44. }
  45. return qout;
  46. }
  47. } // end namespace anki