opengl: move from unordered_set to array
setCapStatus is a a heavy used function in hot rendering paths, it shows up in profiling as using a bit of cpu just because of unordered_set hashing etc, move to a enum and array and cache only the heavily used ones.
This commit is contained in:
parent
b627885788
commit
eb25dfd399
2 changed files with 35 additions and 11 deletions
|
|
@ -3170,18 +3170,36 @@ void CHyprOpenGLImpl::setViewport(GLint x, GLint y, GLsizei width, GLsizei heigh
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprOpenGLImpl::setCapStatus(int cap, bool status) {
|
void CHyprOpenGLImpl::setCapStatus(int cap, bool status) {
|
||||||
// check if the capability status is already set to the desired status
|
const auto getCapIndex = [cap]() {
|
||||||
auto it = m_capStatus.find(cap);
|
switch (cap) {
|
||||||
bool currentStatus = (it != m_capStatus.end()) ? it->second : false; // default to 'false' if not found
|
case GL_BLEND: return CAP_STATUS_BLEND;
|
||||||
|
case GL_SCISSOR_TEST: return CAP_STATUS_SCISSOR_TEST;
|
||||||
|
case GL_STENCIL_TEST: return CAP_STATUS_STENCIL_TEST;
|
||||||
|
default: return CAP_STATUS_END;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (currentStatus == status)
|
auto idx = getCapIndex();
|
||||||
|
|
||||||
|
if (idx == CAP_STATUS_END) {
|
||||||
|
if (status)
|
||||||
|
glEnable(cap);
|
||||||
|
else
|
||||||
|
glDisable(cap);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_capStatus[idx] == status)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_capStatus[cap] = status;
|
if (status) {
|
||||||
|
m_capStatus[idx] = status;
|
||||||
// Enable or disable the capability based on status
|
glEnable(cap);
|
||||||
auto func = status ? [](int c) { glEnable(c); } : [](int c) { glDisable(c); };
|
} else {
|
||||||
func(cap);
|
m_capStatus[idx] = status;
|
||||||
|
glDisable(cap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(PHLMONITOR pMonitor) {
|
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(PHLMONITOR pMonitor) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
@ -341,6 +340,13 @@ class CHyprOpenGLImpl {
|
||||||
|
|
||||||
eEGLContextVersion m_eglContextVersion = EGL_CONTEXT_GLES_3_2;
|
eEGLContextVersion m_eglContextVersion = EGL_CONTEXT_GLES_3_2;
|
||||||
|
|
||||||
|
enum eCachedCapStatus : uint8_t {
|
||||||
|
CAP_STATUS_BLEND = 0,
|
||||||
|
CAP_STATUS_SCISSOR_TEST,
|
||||||
|
CAP_STATUS_STENCIL_TEST,
|
||||||
|
CAP_STATUS_END
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct {
|
struct {
|
||||||
GLint x = 0;
|
GLint x = 0;
|
||||||
|
|
@ -349,7 +355,7 @@ class CHyprOpenGLImpl {
|
||||||
GLsizei height = 0;
|
GLsizei height = 0;
|
||||||
} m_lastViewport;
|
} m_lastViewport;
|
||||||
|
|
||||||
std::unordered_map<int, bool> m_capStatus;
|
std::array<bool, CAP_STATUS_END> m_capStatus;
|
||||||
|
|
||||||
std::vector<SDRMFormat> m_drmFormats;
|
std::vector<SDRMFormat> m_drmFormats;
|
||||||
bool m_hasModifiers = false;
|
bool m_hasModifiers = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue