* 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>
131 lines
10 KiB
C++
131 lines
10 KiB
C++
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <csignal>
|
|
#include <print>
|
|
#include <utility>
|
|
|
|
#include "helpers/memory/Memory.hpp"
|
|
#include "debug/Log.hpp"
|
|
|
|
#ifndef NDEBUG
|
|
#ifdef HYPRLAND_DEBUG
|
|
#define ISDEBUG true
|
|
#else
|
|
#define ISDEBUG false
|
|
#endif
|
|
#else
|
|
#define ISDEBUG false
|
|
#endif
|
|
|
|
#define SPECIAL_WORKSPACE_START (-99)
|
|
|
|
#define PI 3.14159265358979
|
|
|
|
#define STRVAL_EMPTY "[[EMPTY]]"
|
|
|
|
#define WORKSPACE_INVALID -1L
|
|
#define WORKSPACE_NOT_CHANGED -101
|
|
|
|
#define MONITOR_INVALID -1L
|
|
|
|
#define MIN_WINDOW_SIZE 20.0
|
|
|
|
#define LISTENER(name) \
|
|
void listener_##name(wl_listener*, void*); \
|
|
inline wl_listener listen_##name = {.notify = listener_##name}
|
|
#define DYNLISTENFUNC(name) void listener_##name(void*, void*)
|
|
#define DYNLISTENER(name) CHyprWLListener hyprListener_##name
|
|
#define DYNMULTILISTENER(name) wl_listener listen_##name
|
|
|
|
#define VECINRECT(vec, x1, y1, x2, y2) ((vec).x >= (x1) && (vec).x < (x2) && (vec).y >= (y1) && (vec).y < (y2))
|
|
#define VECNOTINRECT(vec, x1, y1, x2, y2) ((vec).x < (x1) || (vec).x >= (x2) || (vec).y < (y1) || (vec).y >= (y2))
|
|
|
|
#define DELTALESSTHAN(a, b, delta) (abs((a) - (b)) < (delta))
|
|
|
|
#define STICKS(a, b) abs((a) - (b)) < 2
|
|
|
|
#define HYPRATOM(name) {name, 0}
|
|
|
|
#define RASSERT(expr, reason, ...) \
|
|
if (!(expr)) { \
|
|
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \
|
|
std::format(reason, ##__VA_ARGS__), __LINE__, \
|
|
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })()); \
|
|
std::print("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
|
|
raise(SIGABRT); \
|
|
}
|
|
|
|
#define ASSERT(expr) RASSERT(expr, "?")
|
|
|
|
// absolutely ridiculous formatter spec parsing
|
|
#define FORMAT_PARSE(specs__, type__) \
|
|
template <typename FormatContext> \
|
|
constexpr auto parse(FormatContext& ctx) { \
|
|
auto it = ctx.begin(); \
|
|
for (; it != ctx.end() && *it != '}'; it++) { \
|
|
switch (*it) { specs__ default : throw std::format_error("invalid format specification"); } \
|
|
} \
|
|
return it; \
|
|
}
|
|
|
|
#define FORMAT_FLAG(spec__, flag__) \
|
|
case spec__: (flag__) = true; break;
|
|
|
|
#define FORMAT_NUMBER(buf__) \
|
|
case '0': \
|
|
case '1': \
|
|
case '2': \
|
|
case '3': \
|
|
case '4': \
|
|
case '5': \
|
|
case '6': \
|
|
case '7': \
|
|
case '8': \
|
|
case '9': (buf__).push_back(*it); break;
|
|
|
|
#if ISDEBUG
|
|
#define UNREACHABLE() \
|
|
{ \
|
|
Debug::log(CRIT, "\n\nMEMORY CORRUPTED: Unreachable failed! (Reached an unreachable position, memory corruption!!!)"); \
|
|
raise(SIGABRT); \
|
|
std::unreachable(); \
|
|
}
|
|
#else
|
|
#define UNREACHABLE() std::unreachable();
|
|
#endif
|
|
|
|
#if ISDEBUG
|
|
|
|
#define GLCALL(__CALL__) \
|
|
{ \
|
|
__CALL__; \
|
|
auto err = glGetError(); \
|
|
if (err != GL_NO_ERROR) { \
|
|
Debug::log(ERR, "[GLES] Error in call at {}@{}: 0x{:x}", __LINE__, \
|
|
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })(), err); \
|
|
} \
|
|
}
|
|
|
|
#else
|
|
|
|
#define GLCALL(__CALL__) \
|
|
{ __CALL__; }
|
|
|
|
#endif
|
|
|
|
#define HYPRUTILS_FORWARD(ns, name) \
|
|
namespace Hyprutils { \
|
|
namespace ns { \
|
|
class name; \
|
|
} \
|
|
}
|
|
|
|
#define AQUAMARINE_VERSION_NUMBER (AQUAMARINE_VERSION_MAJOR * 10000 + AQUAMARINE_VERSION_MINOR * 100 + AQUAMARINE_VERSION_PATCH)
|
|
#define AQUAMARINE_FORWARD(name) \
|
|
namespace Aquamarine { \
|
|
class name; \
|
|
}
|
|
|
|
#define UNLIKELY(expr) (expr) [[unlikely]]
|
|
#define LIKELY(expr) (expr) [[likely]]
|