OcclusionQueryImpl.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2009-2021, 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/OcclusionQueryImpl.h>
  6. #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
  7. namespace anki
  8. {
  9. OcclusionQueryImpl::~OcclusionQueryImpl()
  10. {
  11. if(m_handle)
  12. {
  13. getGrManagerImpl().getOcclusionQueryFactory().deleteQuery(m_handle);
  14. }
  15. }
  16. Error OcclusionQueryImpl::init()
  17. {
  18. ANKI_CHECK(getGrManagerImpl().getOcclusionQueryFactory().newQuery(m_handle));
  19. return Error::NONE;
  20. }
  21. OcclusionQueryResult OcclusionQueryImpl::getResultInternal() const
  22. {
  23. ANKI_ASSERT(m_handle);
  24. U64 out = 0;
  25. VkResult res;
  26. ANKI_VK_CHECKF(res = vkGetQueryPoolResults(getDevice(), m_handle.getQueryPool(), m_handle.getQueryIndex(), 1,
  27. sizeof(out), &out, sizeof(out),
  28. VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
  29. | VK_QUERY_RESULT_PARTIAL_BIT));
  30. OcclusionQueryResult qout = OcclusionQueryResult::NOT_AVAILABLE;
  31. if(res == VK_SUCCESS)
  32. {
  33. qout = (out) ? OcclusionQueryResult::VISIBLE : OcclusionQueryResult::NOT_VISIBLE;
  34. }
  35. else if(res == VK_NOT_READY)
  36. {
  37. qout = OcclusionQueryResult::NOT_AVAILABLE;
  38. }
  39. else
  40. {
  41. ANKI_ASSERT(0);
  42. }
  43. return qout;
  44. }
  45. } // end namespace anki