Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 737 vs 741 for /trunk/Source Code/Platform/Video/OpenGL/GLWrapper.cpp

Diff revisions: vs.
  @@ -34,6 +34,16 @@
34 34
35 35 namespace Divide {
36 36
37 + namespace {
38 + /// How many frames of delay do we allow between the current read and write queries
39 + /// The longer the delay, the better the performance but the more out of sync the results
40 + const U32 g_performanceQueryRingLength = 2;
41 + /// Number of queries
42 + const U32 g_performanceQueryCount = 1;
43 + /// ID of the frame duration query
44 + const U32 g_performanceQueryFrameDurationIndex = 0;
45 + };
46 +
37 47 GL_API::GL_API()
38 48 : RenderAPIWrapper(),
39 49 _prevSizeNode(0),
  @@ -42,8 +52,6 @@
42 52 _prevWidthString(0),
43 53 _lineWidthLimit(1),
44 54 _dummyVAO(0),
45 - _queryBackBuffer(0),
46 - _queryFrontBuffer(0),
47 55 _fonsContext(nullptr),
48 56 _GUIGLrenderer(nullptr),
49 57 _swapBufferTimer(Time::ADD_TIMER("Swap Buffer Timer"))
  @@ -55,10 +63,16 @@
55 63 _fontCache.second = -1;
56 64 _samplerBoundMap.fill(0);
57 65 _textureBoundMap.fill(std::make_pair(0, GL_NONE));
66 +
67 + _hardwareQueries.reserve(g_performanceQueryCount);
68 + for (U32 i = 0; i < g_performanceQueryCount; ++i) {
69 + _hardwareQueries.emplace_back(MemoryManager_NEW glHardwareQueryRing(g_performanceQueryRingLength));
70 + }
58 71 }
59 72
60 73 GL_API::~GL_API()
61 74 {
75 + MemoryManager::DELETE_VECTOR(_hardwareQueries);
62 76 }
63 77
64 78 /// FontStash library initialization
  @@ -77,8 +91,9 @@
77 91 /// Prepare the GPU for rendering a frame
78 92 void GL_API::beginFrame() {
79 93 // Start a duration query in debug builds
80 - #ifdef _DEBUG
81 - glBeginQuery(GL_TIME_ELAPSED, _queryID[_queryBackBuffer][0].getID());
94 + #if defined(ENABLE_GPU_VALIDATION)
95 + glBeginQuery(GL_TIME_ELAPSED, _hardwareQueries[g_performanceQueryFrameDurationIndex]->writeQuery().getID());
96 + _hardwareQueries[g_performanceQueryFrameDurationIndex]->incQueue();
82 97 #endif
83 98 // Clear our buffers
84 99 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT /* | GL_STENCIL_BUFFER_BIT*/);
  @@ -102,18 +117,17 @@
102 117 }
103 118
104 119 // End the timing query started in beginFrame() in debug builds
105 - #ifdef _DEBUG
120 + #if defined(ENABLE_GPU_VALIDATION)
106 121 glEndQuery(GL_TIME_ELAPSED);
107 - // Swap query objects. The current time will be available after 4 frames
108 - _queryBackBuffer = GFX_DEVICE.getFrameCount() % PERFORMANCE_COUNTER_BUFFERS;
109 - _queryFrontBuffer = (_queryBackBuffer + 1) % PERFORMANCE_COUNTER_BUFFERS;
110 122 #endif
111 123 }
112 124
113 125 GLuint64 GL_API::getFrameDurationGPU() {
114 - #ifdef _DEBUG
115 - // The returned results are 4 frames old!
116 - glGetQueryObjectui64v(_queryID[_queryFrontBuffer][0].getID(), GL_QUERY_RESULT, &FRAME_DURATION_GPU);
126 + #if defined(ENABLE_GPU_VALIDATION)
127 + // The returned results are 'g_performanceQueryFrameDurationIndex' frames old!
128 + glGetQueryObjectui64v(_hardwareQueries[g_performanceQueryFrameDurationIndex]->readQuery().getID(),
129 + GL_QUERY_RESULT,
130 + &FRAME_DURATION_GPU);
117 131 #endif
118 132
119 133 return FRAME_DURATION_GPU;