1 // Copyright 2012 Dolphin Emulator Project
2 // Licensed under GPLv2+
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <memory>
8 #include "Common/CommonTypes.h"
9 
10 enum PerfQueryType
11 {
12   PQ_ZCOMP_INPUT_ZCOMPLOC = 0,
13   PQ_ZCOMP_OUTPUT_ZCOMPLOC,
14   PQ_ZCOMP_INPUT,
15   PQ_ZCOMP_OUTPUT,
16   PQ_BLEND_INPUT,
17   PQ_EFB_COPY_CLOCKS,
18   PQ_NUM_MEMBERS
19 };
20 
21 enum PerfQueryGroup
22 {
23   PQG_ZCOMP_ZCOMPLOC,
24   PQG_ZCOMP,
25   PQG_EFB_COPY_CLOCKS,
26   PQG_NUM_MEMBERS,
27 };
28 
29 class PerfQueryBase
30 {
31 public:
PerfQueryBase()32   PerfQueryBase() : m_query_count(0) {}
~PerfQueryBase()33   virtual ~PerfQueryBase() {}
34 
35   // Checks if performance queries are enabled in the gameini configuration.
36   // NOTE: Called from CPU+GPU thread
37   static bool ShouldEmulate();
38 
39   // Begin querying the specified value for the following host GPU commands
40   // The call to EnableQuery() should be placed immediately before the draw command, otherwise
41   // there is a risk of GPU resets if the query is left open and the buffer is submitted during
42   // resource binding (D3D12/Vulkan).
EnableQuery(PerfQueryGroup type)43   virtual void EnableQuery(PerfQueryGroup type) {}
44 
45   // Stop querying the specified value for the following host GPU commands
DisableQuery(PerfQueryGroup type)46   virtual void DisableQuery(PerfQueryGroup type) {}
47 
48   // Reset query counters to zero and drop any pending queries
ResetQuery()49   virtual void ResetQuery() {}
50 
51   // Return the measured value for the specified query type
52   // NOTE: Called from CPU thread
GetQueryResult(PerfQueryType type)53   virtual u32 GetQueryResult(PerfQueryType type) { return 0; }
54 
55   // Request the value of any pending queries - causes a pipeline flush and thus should be used
56   // carefully!
FlushResults()57   virtual void FlushResults() {}
58 
59   // True if there are no further pending query results
60   // NOTE: Called from CPU thread
IsFlushed()61   virtual bool IsFlushed() const { return true; }
62 
63 protected:
64   // TODO: sloppy
65   volatile u32 m_query_count;
66   volatile u32 m_results[PQG_NUM_MEMBERS];
67 };
68 
69 extern std::unique_ptr<PerfQueryBase> g_perf_query;
70