Hyprland/src/render/Shader.hpp

140 lines
4.4 KiB
C++
Raw Normal View History

2022-04-04 19:44:25 +02:00
#pragma once
#include "../defines.hpp"
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>
2025-06-25 12:42:32 +02:00
#include <array>
#include <variant>
2022-04-04 19:44:25 +02:00
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>
2025-06-25 12:42:32 +02:00
enum eShaderUniform : uint8_t {
SHADER_PROJ = 0,
SHADER_COLOR,
SHADER_ALPHA_MATTE,
SHADER_TEX_TYPE,
SHADER_SKIP_CM,
SHADER_SOURCE_TF,
SHADER_TARGET_TF,
SHADER_SRC_TF_RANGE,
SHADER_DST_TF_RANGE,
SHADER_TARGET_PRIMARIES,
SHADER_MAX_LUMINANCE,
SHADER_SRC_REF_LUMINANCE,
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>
2025-06-25 12:42:32 +02:00
SHADER_DST_MAX_LUMINANCE,
SHADER_DST_REF_LUMINANCE,
SHADER_SDR_SATURATION,
SHADER_SDR_BRIGHTNESS,
SHADER_CONVERT_MATRIX,
SHADER_TEX,
SHADER_ALPHA,
SHADER_POS_ATTRIB,
SHADER_TEX_ATTRIB,
SHADER_MATTE_TEX_ATTRIB,
SHADER_DISCARD_OPAQUE,
SHADER_DISCARD_ALPHA,
SHADER_DISCARD_ALPHA_VALUE,
SHADER_SHADER_VAO,
SHADER_SHADER_VBO_POS,
SHADER_SHADER_VBO_UV,
SHADER_TOP_LEFT,
SHADER_BOTTOM_RIGHT,
SHADER_FULL_SIZE,
SHADER_FULL_SIZE_UNTRANSFORMED,
SHADER_RADIUS,
SHADER_RADIUS_OUTER,
SHADER_ROUNDING_POWER,
SHADER_THICK,
SHADER_HALFPIXEL,
SHADER_RANGE,
SHADER_SHADOW_POWER,
SHADER_USE_ALPHA_MATTE,
SHADER_APPLY_TINT,
SHADER_TINT,
SHADER_GRADIENT,
SHADER_GRADIENT_LENGTH,
SHADER_ANGLE,
SHADER_GRADIENT2,
SHADER_GRADIENT2_LENGTH,
SHADER_ANGLE2,
SHADER_GRADIENT_LERP,
SHADER_TIME,
SHADER_DISTORT,
SHADER_WL_OUTPUT,
SHADER_CONTRAST,
SHADER_PASSES,
SHADER_VIBRANCY,
SHADER_VIBRANCY_DARKNESS,
SHADER_BRIGHTNESS,
SHADER_NOISE,
SHADER_POINTER,
SHADER_POINTER_SHAPE,
SHADER_POINTER_SWITCH_TIME,
SHADER_POINTER_SHAPE_PREVIOUS,
SHADER_POINTER_PRESSED_POSITIONS,
SHADER_POINTER_HIDDEN,
SHADER_POINTER_KILLING,
SHADER_POINTER_PRESSED_TIMES,
SHADER_POINTER_PRESSED_KILLED,
SHADER_POINTER_PRESSED_TOUCHED,
SHADER_POINTER_INACTIVE_TIMEOUT,
SHADER_POINTER_LAST_ACTIVE,
SHADER_POINTER_SIZE,
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>
2025-06-25 12:42:32 +02:00
SHADER_LAST,
};
2023-06-14 13:29:12 +02:00
renderer: shader code refactor (#12926) * shader: begin the shader refactor make SShader a class and rename it to CShader, move createprogram, compileshader, logshadererror to CShader. * shader: move uniform creation to CShader move uniform creation to CShader, reduces tons of duplicated effort, however forcing uniform names to be same in all shaders. * shader: move to array based frag handling use an array with an enum so it gets easier dealing with multiple shaders, move creating program to a for loop and array, reduces line of code a lot. * shader: use shared ptr for frags with smart pointers we can now rename useProgram to useShader and return the shader directly, means only place we have to decide the shader frag is when calling useShader. easier for future shader splitting to reduce branching. * shader: move unneded public members to private move structs and uniforms to private add a get/set for initialtime and add a getUniformLocation to make the code tell what its doing, instead of direct array getting when all we wanted to get was its value, also limits the setting of uniformLocations to the createProgram as it should be. * shader: fix style nits set first enum member to 0 , remove extra {} * shader: dont show a failed notif on success the logic got inverted in the refactor here. * shader: split CM shader to rgba/rgbx variants split shader to rgba/rgbx variants, use bool, and reduce branching. * shader: split up blurprepare CM and non CM split up blurprepare, remove skipcm, move gain to gain.glsl. remove ternary operator and reduce branching by using step() and mix() use vec3 for gain, make brightness a cheap mulitplication with max. * shader: split up border to CM/noncm variants splitup border shader to CM/noncm variant, move common used things to border.glsl , there is room for optimisations here but its a complex shader im putting it for future PR. * shader: touchup blurfinish make brightness a cheap multiplication instead of branching. mod is redundant, fract in hash already returns a value in [0.0, 1.0]
2026-01-12 18:27:16 +01:00
class CShader {
public:
CShader();
~CShader();
2023-06-14 13:29:12 +02:00
renderer: shader code refactor (#12926) * shader: begin the shader refactor make SShader a class and rename it to CShader, move createprogram, compileshader, logshadererror to CShader. * shader: move uniform creation to CShader move uniform creation to CShader, reduces tons of duplicated effort, however forcing uniform names to be same in all shaders. * shader: move to array based frag handling use an array with an enum so it gets easier dealing with multiple shaders, move creating program to a for loop and array, reduces line of code a lot. * shader: use shared ptr for frags with smart pointers we can now rename useProgram to useShader and return the shader directly, means only place we have to decide the shader frag is when calling useShader. easier for future shader splitting to reduce branching. * shader: move unneded public members to private move structs and uniforms to private add a get/set for initialtime and add a getUniformLocation to make the code tell what its doing, instead of direct array getting when all we wanted to get was its value, also limits the setting of uniformLocations to the createProgram as it should be. * shader: fix style nits set first enum member to 0 , remove extra {} * shader: dont show a failed notif on success the logic got inverted in the refactor here. * shader: split CM shader to rgba/rgbx variants split shader to rgba/rgbx variants, use bool, and reduce branching. * shader: split up blurprepare CM and non CM split up blurprepare, remove skipcm, move gain to gain.glsl. remove ternary operator and reduce branching by using step() and mix() use vec3 for gain, make brightness a cheap mulitplication with max. * shader: split up border to CM/noncm variants splitup border shader to CM/noncm variant, move common used things to border.glsl , there is room for optimisations here but its a complex shader im putting it for future PR. * shader: touchup blurfinish make brightness a cheap multiplication instead of branching. mod is redundant, fract in hash already returns a value in [0.0, 1.0]
2026-01-12 18:27:16 +01:00
bool createProgram(const std::string& vert, const std::string& frag, bool dynamic = false, bool silent = false);
void setUniformInt(eShaderUniform location, GLint v0);
void setUniformFloat(eShaderUniform location, GLfloat v0);
void setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1);
void setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2);
void setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
void setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 9> value);
void setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 8> value);
void setUniform1fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
void setUniform2fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
void setUniform4fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
void destroy();
GLuint program() const;
GLint getUniformLocation(eShaderUniform location) const;
int getInitialTime() const;
void setInitialTime(int time);
2023-06-14 13:29:12 +02:00
renderer: shader code refactor (#12926) * shader: begin the shader refactor make SShader a class and rename it to CShader, move createprogram, compileshader, logshadererror to CShader. * shader: move uniform creation to CShader move uniform creation to CShader, reduces tons of duplicated effort, however forcing uniform names to be same in all shaders. * shader: move to array based frag handling use an array with an enum so it gets easier dealing with multiple shaders, move creating program to a for loop and array, reduces line of code a lot. * shader: use shared ptr for frags with smart pointers we can now rename useProgram to useShader and return the shader directly, means only place we have to decide the shader frag is when calling useShader. easier for future shader splitting to reduce branching. * shader: move unneded public members to private move structs and uniforms to private add a get/set for initialtime and add a getUniformLocation to make the code tell what its doing, instead of direct array getting when all we wanted to get was its value, also limits the setting of uniformLocations to the createProgram as it should be. * shader: fix style nits set first enum member to 0 , remove extra {} * shader: dont show a failed notif on success the logic got inverted in the refactor here. * shader: split CM shader to rgba/rgbx variants split shader to rgba/rgbx variants, use bool, and reduce branching. * shader: split up blurprepare CM and non CM split up blurprepare, remove skipcm, move gain to gain.glsl. remove ternary operator and reduce branching by using step() and mix() use vec3 for gain, make brightness a cheap mulitplication with max. * shader: split up border to CM/noncm variants splitup border shader to CM/noncm variant, move common used things to border.glsl , there is room for optimisations here but its a complex shader im putting it for future PR. * shader: touchup blurfinish make brightness a cheap multiplication instead of branching. mod is redundant, fract in hash already returns a value in [0.0, 1.0]
2026-01-12 18:27:16 +01:00
private:
GLuint m_program = 0;
float m_initialTime = 0;
std::array<GLint, SHADER_LAST> m_uniformLocations;
2023-06-14 13:29:12 +02:00
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>
2025-06-25 12:42:32 +02:00
struct SUniformMatrix3Data {
GLsizei count = 0;
GLboolean transpose = false;
std::array<GLfloat, 9> value = {};
};
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>
2025-06-25 12:42:32 +02:00
struct SUniformMatrix4Data {
GLsizei count = 0;
GLboolean transpose = false;
std::array<GLfloat, 8> value = {};
};
struct SUniformVData {
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>
2025-06-25 12:42:32 +02:00
GLsizei count = 0;
std::vector<float> value;
};
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>
2025-06-25 12:42:32 +02:00
//
std::array<std::variant<std::monostate, GLint, GLfloat, std::array<GLfloat, 2>, std::array<GLfloat, 3>, std::array<GLfloat, 4>, SUniformMatrix3Data, SUniformMatrix4Data,
SUniformVData>,
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>
2025-06-25 12:42:32 +02:00
SHADER_LAST>
uniformStatus;
//
renderer: shader code refactor (#12926) * shader: begin the shader refactor make SShader a class and rename it to CShader, move createprogram, compileshader, logshadererror to CShader. * shader: move uniform creation to CShader move uniform creation to CShader, reduces tons of duplicated effort, however forcing uniform names to be same in all shaders. * shader: move to array based frag handling use an array with an enum so it gets easier dealing with multiple shaders, move creating program to a for loop and array, reduces line of code a lot. * shader: use shared ptr for frags with smart pointers we can now rename useProgram to useShader and return the shader directly, means only place we have to decide the shader frag is when calling useShader. easier for future shader splitting to reduce branching. * shader: move unneded public members to private move structs and uniforms to private add a get/set for initialtime and add a getUniformLocation to make the code tell what its doing, instead of direct array getting when all we wanted to get was its value, also limits the setting of uniformLocations to the createProgram as it should be. * shader: fix style nits set first enum member to 0 , remove extra {} * shader: dont show a failed notif on success the logic got inverted in the refactor here. * shader: split CM shader to rgba/rgbx variants split shader to rgba/rgbx variants, use bool, and reduce branching. * shader: split up blurprepare CM and non CM split up blurprepare, remove skipcm, move gain to gain.glsl. remove ternary operator and reduce branching by using step() and mix() use vec3 for gain, make brightness a cheap mulitplication with max. * shader: split up border to CM/noncm variants splitup border shader to CM/noncm variant, move common used things to border.glsl , there is room for optimisations here but its a complex shader im putting it for future PR. * shader: touchup blurfinish make brightness a cheap multiplication instead of branching. mod is redundant, fract in hash already returns a value in [0.0, 1.0]
2026-01-12 18:27:16 +01:00
void logShaderError(const GLuint&, bool program = false, bool silent = false);
GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false);
void getUniformLocations();
void createVao();
void setUniformfv(eShaderUniform location, GLsizei count, const std::vector<float>& value, GLsizei vec_size);
};