summaryrefslogtreecommitdiff
path: root/src/render/OpenGL.hpp
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-06-25 12:42:32 +0200
committerGitHub <noreply@github.com>2025-06-25 12:42:32 +0200
commitf4f090e4b2f9f0bba5408cbd135d2fff1990be1d (patch)
tree0d7d63cea74a4198f5d99f43f1eaeeda27e38dbf /src/render/OpenGL.hpp
parent5a348fb7dfaf398922c119d21acb7d7f831f8688 (diff)
renderer: reduce a lot of glcalls and cache various states (#10757)
* opengl: cache viewport state according to nvidia docs calling glViewPort unnecessarily on the same already set viewport is wasteful and can cause state changes when not needed. cache it in a struct and only call it when the viewport is actually changing. * opengl: cache glenable/gldisable state avoid making multiple glenable/gldisable calls on already set caps, can cause state changes and incur driver overhead. * opengl: cache glscissor box only call glscissor if the box actually has changed, try to avoid state changes. * opengl: cache gluniform calls cache the gluniform calls, the uniform values are cached in driver per program only the drawcalls setting the uniform yet again with the same value on same location is causing more overhead then caching it ourself and just no oping on it if no changes. * shader: rewrite handling of uniforms and state this is way faster as we don't need to mess with maps (hashing, etc) and instead can just use an array * opengl: stuff and 300 shaders * opengl: typo * opengl: get the uniform locations properly now that the legacy shaders are gone get the uniformlocations for SKIP_CM etc, so they can be properly set and used depending on if cm_enabled is set to false or true, before it was falling back to a legacy shader that didnt even have those uniforms. * opengl: check epsilon on float and remove extra glcall seems an extra unset glcall was added, remove it. and check the float epsilon on the glfloat. * opengl: remove instanced shader draw remove the instanced boolean from the vertex shader, might be neglible differences, needs more benchmark/work to see if its even worth it. * texture: cache texture paramaters parameters where occasionally set twice or more on same texture, short version wrap it and cache it. and move gpu churn to cpu churn. add a bind/unbind to texture aswell. * texture: use fast std::array caching cache the texparameter values in fast array lookups and incase we dont want it cached, apply it anyways. * shader: fix typo and hdr typo actually use Matrix4x2fv in the 4x2fv cache function, and send the proper float array for hdr. * texture: make caching not linear lookup make caching of texture params not linear. * minor style changes * opengl: revert drawarrays revert the mostly code style reduce loc change of drawarrays, and focus on the caching. its a if else case going wrong here breaking blur/contrast amongst others drawing. --------- Co-authored-by: Vaxry <vaxry@vaxry.net>
Diffstat (limited to 'src/render/OpenGL.hpp')
-rw-r--r--src/render/OpenGL.hpp82
1 files changed, 45 insertions, 37 deletions
diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp
index eeea2b24..4c6f55f9 100644
--- a/src/render/OpenGL.hpp
+++ b/src/render/OpenGL.hpp
@@ -83,7 +83,6 @@ enum eMonitorExtraRenderFBs : uint8_t {
struct SPreparedShaders {
std::string TEXVERTSRC;
- std::string TEXVERTSRC300;
std::string TEXVERTSRC320;
SShader m_shQUAD;
SShader m_shRGBA;
@@ -201,6 +200,8 @@ class CHyprOpenGLImpl {
void popMonitorTransformEnabled();
void setRenderModifEnabled(bool enabled);
+ void setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
+ void setCapStatus(int cap, bool status);
void saveMatrix();
void setMatrixScaleTranslate(const Vector2D& translate, const float& scale);
@@ -307,40 +308,47 @@ class CHyprOpenGLImpl {
EGL_CONTEXT_GLES_3_2,
};
- eEGLContextVersion m_eglContextVersion = EGL_CONTEXT_GLES_3_2;
-
- std::vector<SDRMFormat> m_drmFormats;
- bool m_hasModifiers = false;
-
- int m_drmFD = -1;
- std::string m_extensions;
-
- bool m_fakeFrame = false;
- bool m_applyFinalShader = false;
- bool m_blend = false;
- bool m_offloadedFramebuffer = false;
- bool m_cmSupported = true;
-
- bool m_monitorTransformEnabled = false; // do not modify directly
- std::stack<bool> m_monitorTransformStack;
-
- SShader m_finalScreenShader;
- CTimer m_globalTimer;
- GLuint m_currentProgram;
-
- SP<CTexture> m_missingAssetTexture;
- SP<CTexture> m_backgroundTexture;
- SP<CTexture> m_lockDeadTexture;
- SP<CTexture> m_lockDead2Texture;
- SP<CTexture> m_lockTtyTextTexture;
-
- void logShaderError(const GLuint&, bool program = false, bool silent = false);
- void createBGTextureForMonitor(PHLMONITOR);
- void initDRMFormats();
- void initEGL(bool gbm);
- EGLDeviceEXT eglDeviceFromDRMFD(int drmFD);
- void initAssets();
- void initMissingAssetTexture();
+ struct {
+ GLint x = 0;
+ GLint y = 0;
+ GLsizei width = 0;
+ GLsizei height = 0;
+ } m_lastViewport;
+
+ std::unordered_map<int, bool> m_capStatus;
+
+ eEGLContextVersion m_eglContextVersion = EGL_CONTEXT_GLES_3_2;
+
+ std::vector<SDRMFormat> m_drmFormats;
+ bool m_hasModifiers = false;
+
+ int m_drmFD = -1;
+ std::string m_extensions;
+
+ bool m_fakeFrame = false;
+ bool m_applyFinalShader = false;
+ bool m_blend = false;
+ bool m_offloadedFramebuffer = false;
+ bool m_cmSupported = true;
+
+ bool m_monitorTransformEnabled = false; // do not modify directly
+ std::stack<bool> m_monitorTransformStack;
+ SP<CTexture> m_missingAssetTexture;
+ SP<CTexture> m_backgroundTexture;
+ SP<CTexture> m_lockDeadTexture;
+ SP<CTexture> m_lockDead2Texture;
+ SP<CTexture> m_lockTtyTextTexture;
+ SShader m_finalScreenShader;
+ CTimer m_globalTimer;
+ GLuint m_currentProgram;
+
+ void logShaderError(const GLuint&, bool program = false, bool silent = false);
+ void createBGTextureForMonitor(PHLMONITOR);
+ void initDRMFormats();
+ void initEGL(bool gbm);
+ EGLDeviceEXT eglDeviceFromDRMFD(int drmFD);
+ void initAssets();
+ void initMissingAssetTexture();
//
std::optional<std::vector<uint64_t>> getModsForFormat(EGLint format);
@@ -349,9 +357,9 @@ class CHyprOpenGLImpl {
CFramebuffer* blurMainFramebufferWithDamage(float a, CRegion* damage);
CFramebuffer* blurFramebufferWithDamage(float a, CRegion* damage, CFramebuffer& source);
- void passCMUniforms(const SShader&, const NColorManagement::SImageDescription& imageDescription, const NColorManagement::SImageDescription& targetImageDescription,
+ void passCMUniforms(SShader&, const NColorManagement::SImageDescription& imageDescription, const NColorManagement::SImageDescription& targetImageDescription,
bool modifySDR = false, float sdrMinLuminance = -1.0f, int sdrMaxLuminance = -1);
- void passCMUniforms(const SShader&, const NColorManagement::SImageDescription& imageDescription);
+ void passCMUniforms(SShader&, const NColorManagement::SImageDescription& imageDescription);
void renderTextureInternalWithDamage(SP<CTexture>, const CBox& box, float a, const CRegion& damage, int round = 0, float roundingPower = 2.0f, bool discardOpaque = false,
bool noAA = false, bool allowCustomUV = false, bool allowDim = false, GLenum wrapX = GL_CLAMP_TO_EDGE, GLenum wrapY = GL_CLAMP_TO_EDGE);
void renderTexturePrimitive(SP<CTexture> tex, const CBox& box);