1 // Copyright 2016 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <array>
8 #include <memory>
9 
10 #include "Common/CommonTypes.h"
11 #include "VideoBackends/Vulkan/Constants.h"
12 #include "VideoCommon/PerfQueryBase.h"
13 
14 namespace Vulkan
15 {
16 class PerfQuery : public PerfQueryBase
17 {
18 public:
19   PerfQuery();
20   ~PerfQuery();
21 
GetInstance()22   static PerfQuery* GetInstance() { return static_cast<PerfQuery*>(g_perf_query.get()); }
23 
24   bool Initialize();
25 
26   void EnableQuery(PerfQueryGroup type) override;
27   void DisableQuery(PerfQueryGroup type) override;
28   void ResetQuery() override;
29   u32 GetQueryResult(PerfQueryType type) override;
30   void FlushResults() override;
31   bool IsFlushed() const override;
32 
33 private:
34   // u32 is used for the sample counts.
35   using PerfQueryDataType = u32;
36 
37   // when testing in SMS: 64 was too small, 128 was ok
38   // TODO: This should be size_t, but the base class uses u32s
39   static const u32 PERF_QUERY_BUFFER_SIZE = 512;
40 
41   struct ActiveQuery
42   {
43     u64 fence_counter;
44     PerfQueryType query_type;
45     bool has_value;
46   };
47 
48   bool CreateQueryPool();
49   void ReadbackQueries();
50   void ReadbackQueries(u32 query_count);
51   void PartialFlush(bool blocking);
52 
53   VkQueryPool m_query_pool = VK_NULL_HANDLE;
54   u32 m_query_readback_pos = 0;
55   u32 m_query_next_pos = 0;
56   std::array<ActiveQuery, PERF_QUERY_BUFFER_SIZE> m_query_buffer = {};
57   std::array<PerfQueryDataType, PERF_QUERY_BUFFER_SIZE> m_query_result_buffer = {};
58 };
59 
60 }  // namespace Vulkan
61