|
15 | 15 |
|
16 | 16 | #include <memory> |
17 | 17 | #include <unordered_map> |
| 18 | +#include <array> |
18 | 19 |
|
19 | 20 | Q_LOGGING_CATEGORY(BBDX_TEXTURE_COMPARER, "kwin_effect_better_blur_dx.texture_comparer", QtInfoMsg) |
20 | 21 |
|
@@ -48,28 +49,34 @@ static inline const char* glslFormatString(GLenum internalFormat) { |
48 | 49 | std::unique_ptr<BBDX::TextureComparer::WindowData> BBDX::TextureComparer::WindowData::create() { |
49 | 50 | std::unique_ptr<WindowData> windowData{new WindowData{}}; |
50 | 51 |
|
51 | | - glGenBuffers(1, &windowData->counterBuffer); |
| 52 | + glGenBuffers(SLOTS, windowData->m_counterBuffers.data()); |
| 53 | + glGenQueries(SLOTS, windowData->m_queries.data()); |
52 | 54 |
|
53 | 55 | // allocate a single GLuint (the change counter) |
54 | | - glBindBuffer(GL_SHADER_STORAGE_BUFFER, windowData->counterBuffer); |
55 | | - glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLuint), nullptr, GL_DYNAMIC_DRAW); |
| 56 | + for (const auto &buffer : windowData->m_counterBuffers) { |
| 57 | + glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer); |
| 58 | + glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLuint), nullptr, GL_DYNAMIC_DRAW); |
| 59 | + } |
56 | 60 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); |
57 | 61 |
|
58 | | - glGenQueries(1, &windowData->query); |
59 | | - |
60 | 62 | return windowData; |
61 | 63 | } |
62 | 64 |
|
63 | 65 | BBDX::TextureComparer::WindowData::~WindowData() { |
64 | | - if (counterBuffer > 0) { |
65 | | - glDeleteBuffers(1, &counterBuffer); |
66 | | - } |
| 66 | + glDeleteBuffers(SLOTS, m_counterBuffers.data()); |
| 67 | + glDeleteQueries(SLOTS, m_queries.data()); |
| 68 | +} |
| 69 | + |
67 | 70 |
|
68 | | - if (query > 0) { |
69 | | - glDeleteQueries(1, &query); |
| 71 | +std::pair<GLuint, GLuint> BBDX::TextureComparer::WindowData::getSlot() { |
| 72 | + const int slot = m_nextSlot; |
| 73 | + |
| 74 | + if (++m_nextSlot >= SLOTS) { |
| 75 | + m_nextSlot = 0; |
70 | 76 | } |
71 | | -} |
72 | 77 |
|
| 78 | + return {m_counterBuffers[slot], m_queries[slot]}; |
| 79 | +} |
73 | 80 |
|
74 | 81 | std::unique_ptr<BBDX::TextureComparer::ComputeShader> BBDX::TextureComparer::buildComputeShader(GLenum textureFormat) { |
75 | 82 | qCDebug(BBDX_TEXTURE_COMPARER) << "Creating texture compare instance for" << glslFormatString(textureFormat); |
@@ -180,11 +187,14 @@ std::unique_ptr<BBDX::TextureComparer> BBDX::TextureComparer::create() { |
180 | 187 | return textureComparer; |
181 | 188 | } |
182 | 189 |
|
183 | | -void BBDX::TextureComparer::compareAndUpdate(const WindowData *windowData, KWin::GLTexture *freshBlit, KWin::GLTexture *cachedBlit, const KWin::Region &localDirtyRegionGL, const KWin::EffectWindow *window) { |
| 190 | +void BBDX::TextureComparer::compareAndUpdate(const std::pair<GLuint, GLuint> &windowDataSlot, KWin::GLTexture *freshBlit, KWin::GLTexture *cachedBlit, const KWin::Region &localDirtyRegionGL, const KWin::EffectWindow *window) { |
184 | 191 | #if !defined(BBDX_DEBUG) |
185 | 192 | Q_UNUSED(window); |
186 | 193 | #endif |
187 | 194 |
|
| 195 | + const GLuint counterBuffer{windowDataSlot.first}; |
| 196 | + const GLuint query{windowDataSlot.second}; |
| 197 | + |
188 | 198 | const auto textureFormat = freshBlit->internalFormat(); |
189 | 199 |
|
190 | 200 | // lazily create compute shader instances in case we need |
@@ -212,10 +222,10 @@ void BBDX::TextureComparer::compareAndUpdate(const WindowData *windowData, KWin: |
212 | 222 |
|
213 | 223 | // reset and bind counter |
214 | 224 | const GLuint zero = 0; |
215 | | - glBindBuffer(GL_SHADER_STORAGE_BUFFER, windowData->counterBuffer); |
| 225 | + glBindBuffer(GL_SHADER_STORAGE_BUFFER, counterBuffer); |
216 | 226 | glClearBufferSubData(GL_SHADER_STORAGE_BUFFER, GL_R32UI, 0, sizeof(GLuint), GL_RED_INTEGER, GL_UNSIGNED_INT, &zero); |
217 | 227 | // slot 2 - matching compute shader |
218 | | - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, windowData->counterBuffer); |
| 228 | + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, counterBuffer); |
219 | 229 |
|
220 | 230 | // prepare compute shader |
221 | 231 | GLint prevProgram{}; |
@@ -262,7 +272,7 @@ void BBDX::TextureComparer::compareAndUpdate(const WindowData *windowData, KWin: |
262 | 272 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
263 | 273 | glDepthMask(GL_FALSE); |
264 | 274 |
|
265 | | - glBeginQuery(GL_ANY_SAMPLES_PASSED, windowData->query); |
| 275 | + glBeginQuery(GL_ANY_SAMPLES_PASSED, query); |
266 | 276 | glDrawArrays(GL_POINTS, 0, 1); |
267 | 277 | glEndQuery(GL_ANY_SAMPLES_PASSED); |
268 | 278 |
|
|
0 commit comments