2022-04-04 19:44:25 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "../defines.hpp"
|
|
|
|
|
#include "../helpers/Monitor.hpp"
|
|
|
|
|
#include "../helpers/Color.hpp"
|
2025-04-16 01:37:48 +01:00
|
|
|
#include "../helpers/time/Timer.hpp"
|
2024-06-19 16:20:06 +02:00
|
|
|
#include "../helpers/math/Math.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "../helpers/Format.hpp"
|
2024-07-21 13:09:54 +02:00
|
|
|
#include "../helpers/sync/SyncTimeline.hpp"
|
2025-06-22 03:03:28 +10:00
|
|
|
#include <GLES3/gl32.h>
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <cstdint>
|
2022-04-04 19:44:25 +02:00
|
|
|
#include <list>
|
2025-03-29 03:19:35 +03:00
|
|
|
#include <string>
|
2022-04-05 20:49:15 +02:00
|
|
|
#include <unordered_map>
|
2025-06-15 12:11:28 +02:00
|
|
|
#include <stack>
|
2024-04-27 12:43:12 +01:00
|
|
|
#include <map>
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2022-07-10 15:41:26 +02:00
|
|
|
#include <cairo/cairo.h>
|
|
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
#include "Shader.hpp"
|
2022-04-05 14:33:54 +02:00
|
|
|
#include "Texture.hpp"
|
2022-04-05 20:49:15 +02:00
|
|
|
#include "Framebuffer.hpp"
|
2023-11-24 10:54:21 +00:00
|
|
|
#include "Renderbuffer.hpp"
|
2024-12-22 17:12:09 +01:00
|
|
|
#include "pass/Pass.hpp"
|
2023-11-24 10:54:21 +00:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
|
#include <EGL/eglext.h>
|
2023-11-24 10:54:21 +00:00
|
|
|
#include <GLES2/gl2ext.h>
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <aquamarine/buffer/Buffer.hpp>
|
2025-01-30 12:30:12 +01:00
|
|
|
#include <hyprutils/os/FileDescriptor.hpp>
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2023-07-20 17:47:49 +02:00
|
|
|
#include "../debug/TracyDefines.hpp"
|
2025-03-14 02:15:18 +03:00
|
|
|
#include "../protocols/core/Compositor.hpp"
|
2023-07-20 17:47:49 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
struct gbm_device;
|
2022-11-06 17:58:56 +00:00
|
|
|
class CHyprRenderer;
|
|
|
|
|
|
2022-04-04 21:45:35 +02:00
|
|
|
inline const float fullVerts[] = {
|
2022-12-16 17:17:31 +00:00
|
|
|
1, 0, // top right
|
|
|
|
|
0, 0, // top left
|
|
|
|
|
1, 1, // bottom right
|
|
|
|
|
0, 1, // bottom left
|
2022-05-02 16:54:40 +02:00
|
|
|
};
|
2022-12-16 17:17:31 +00:00
|
|
|
inline const float fanVertsFull[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f};
|
2022-04-04 21:45:35 +02:00
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eDiscardMode : uint8_t {
|
2023-06-12 00:30:31 +07:00
|
|
|
DISCARD_OPAQUE = 1,
|
|
|
|
|
DISCARD_ALPHA = 1 << 1
|
2023-03-17 23:16:13 +00:00
|
|
|
};
|
|
|
|
|
|
2023-04-12 12:41:23 +01:00
|
|
|
struct SRenderModifData {
|
2024-12-07 18:51:18 +01:00
|
|
|
enum eRenderModifType : uint8_t {
|
2024-01-07 18:35:44 +01:00
|
|
|
RMOD_TYPE_SCALE, /* scale by a float */
|
|
|
|
|
RMOD_TYPE_SCALECENTER, /* scale by a float from the center */
|
|
|
|
|
RMOD_TYPE_TRANSLATE, /* translate by a Vector2D */
|
|
|
|
|
RMOD_TYPE_ROTATE, /* rotate by a float in rad from top left */
|
|
|
|
|
RMOD_TYPE_ROTATECENTER, /* rotate by a float in rad from center */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<eRenderModifType, std::any>> modifs;
|
|
|
|
|
|
|
|
|
|
void applyToBox(CBox& box);
|
2024-04-03 14:09:58 +01:00
|
|
|
void applyToRegion(CRegion& rg);
|
|
|
|
|
float combinedScale();
|
|
|
|
|
|
|
|
|
|
bool enabled = true;
|
2023-04-12 12:41:23 +01:00
|
|
|
};
|
|
|
|
|
|
2024-12-22 17:12:09 +01:00
|
|
|
enum eMonitorRenderFBs : uint8_t {
|
|
|
|
|
FB_MONITOR_RENDER_MAIN = 0,
|
|
|
|
|
FB_MONITOR_RENDER_CURRENT = 1,
|
|
|
|
|
FB_MONITOR_RENDER_OUT = 2,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum eMonitorExtraRenderFBs : uint8_t {
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_OFFLOAD = 0,
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_MIRROR,
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_MIRROR_SWAP,
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_OFF_MAIN,
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_MONITOR_MIRROR,
|
|
|
|
|
FB_MONITOR_RENDER_EXTRA_BLUR,
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-29 03:19:35 +03:00
|
|
|
struct SPreparedShaders {
|
|
|
|
|
std::string TEXVERTSRC;
|
|
|
|
|
std::string TEXVERTSRC320;
|
2025-05-08 00:07:35 +02:00
|
|
|
SShader m_shQUAD;
|
|
|
|
|
SShader m_shRGBA;
|
|
|
|
|
SShader m_shPASSTHRURGBA;
|
|
|
|
|
SShader m_shMATTE;
|
|
|
|
|
SShader m_shRGBX;
|
|
|
|
|
SShader m_shEXT;
|
|
|
|
|
SShader m_shBLUR1;
|
|
|
|
|
SShader m_shBLUR2;
|
|
|
|
|
SShader m_shBLURPREPARE;
|
|
|
|
|
SShader m_shBLURFINISH;
|
|
|
|
|
SShader m_shSHADOW;
|
|
|
|
|
SShader m_shBORDER1;
|
|
|
|
|
SShader m_shGLITCH;
|
|
|
|
|
SShader m_shCM;
|
2025-03-29 03:19:35 +03:00
|
|
|
};
|
|
|
|
|
|
2022-06-29 12:54:53 +02:00
|
|
|
struct SMonitorRenderData {
|
2023-11-24 10:54:21 +00:00
|
|
|
CFramebuffer offloadFB;
|
2023-07-19 20:09:49 +02:00
|
|
|
CFramebuffer mirrorFB; // these are used for some effects,
|
|
|
|
|
CFramebuffer mirrorSwapFB; // etc
|
2023-10-21 14:15:48 +01:00
|
|
|
CFramebuffer offMainFB;
|
2024-04-24 17:29:41 +02:00
|
|
|
CFramebuffer monitorMirrorFB; // used for mirroring outputs, does not contain artifacts like offloadFB
|
2024-12-22 17:12:09 +01:00
|
|
|
CFramebuffer blurFB;
|
2022-06-29 12:54:53 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CTexture> stencilTex = makeShared<CTexture>();
|
2022-07-31 23:44:04 +02:00
|
|
|
|
2022-12-18 12:41:13 +00:00
|
|
|
bool blurFBDirty = true;
|
|
|
|
|
bool blurFBShouldRender = false;
|
2022-06-29 12:54:53 +02:00
|
|
|
};
|
|
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
struct SCurrentRenderData {
|
2025-05-10 18:31:26 +01:00
|
|
|
PHLMONITORREF pMonitor;
|
|
|
|
|
Mat3x3 projection;
|
|
|
|
|
Mat3x3 savedProjection;
|
|
|
|
|
Mat3x3 monitorProjection;
|
2025-03-14 02:15:18 +03:00
|
|
|
|
2025-05-10 18:31:26 +01:00
|
|
|
// FIXME: raw pointer galore!
|
2025-03-14 02:15:18 +03:00
|
|
|
SMonitorRenderData* pCurrentMonData = nullptr;
|
|
|
|
|
CFramebuffer* currentFB = nullptr; // current rendering to
|
|
|
|
|
CFramebuffer* mainFB = nullptr; // main to render to
|
|
|
|
|
CFramebuffer* outFB = nullptr; // out to render to (if offloaded, etc)
|
|
|
|
|
|
|
|
|
|
CRegion damage;
|
2025-04-11 00:34:50 +02:00
|
|
|
CRegion finalDamage; // damage used for funal off -> main
|
2025-03-14 02:15:18 +03:00
|
|
|
|
|
|
|
|
SRenderModifData renderModif;
|
|
|
|
|
float mouseZoomFactor = 1.f;
|
|
|
|
|
bool mouseZoomUseMouse = true; // true by default
|
|
|
|
|
bool useNearestNeighbor = false;
|
|
|
|
|
bool blockScreenShader = false;
|
|
|
|
|
bool simplePass = false;
|
|
|
|
|
|
|
|
|
|
Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1);
|
|
|
|
|
Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1);
|
|
|
|
|
|
|
|
|
|
CBox clipBox = {}; // scaled coordinates
|
|
|
|
|
CRegion clipRegion;
|
|
|
|
|
|
|
|
|
|
uint32_t discardMode = DISCARD_OPAQUE;
|
|
|
|
|
float discardOpacity = 0.f;
|
|
|
|
|
|
|
|
|
|
PHLLSREF currentLS;
|
|
|
|
|
PHLWINDOWREF currentWindow;
|
|
|
|
|
WP<CWLSurfaceResource> surface;
|
2022-04-04 19:44:25 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
class CEGLSync {
|
|
|
|
|
public:
|
2025-04-30 11:35:25 -05:00
|
|
|
static UP<CEGLSync> create();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-04-30 11:35:25 -05:00
|
|
|
~CEGLSync();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
syncobj: use eventfd instead of stalling fd checks (#9437)
* syncobj: cleanup and use uniqueptrs
cleanup a bit missing removals if resource not good, erasing from
containers etc. make use of unique ptrs instead. and add default
destructors.
* syncobj: rework syncobj entirerly
remove early buffer release that was breaking explicit sync, the buffer
needs to exist until the surface commit event has been emitted and draw
calls added egl sync points, move to eventfd signaling instead of
stalling sync point checks, and recommit pending commits if waiting on a
signal. add a CDRMSyncPointState helper class. move a few weak pointers
to shared pointers so they dont destruct before we need to use them.
* syncobj: queue pending states for eventfd
eventfd requires us to queue pending stats until ready and then apply to
current, and also when no ready state exist commit the client commit on
the current existing buffer, if there is one.
* syncobj: clear current buffer damage
clear current buffer damage on current buffer commits.
* syncobj: cleanup code and fix hyprlock
remove unused code, and ensure we dont commit a empty texture causing
locksession protocol and gtk4-layer-shell misbehaving.
* syncobj: ensure buffers are cleaned up
ensure the containers having the various buffers actually gets cleaned
up from their containers, incase the CSignal isnt signaled because of
expired smart pointers or just wrong order destruction because mishaps.
also move the acquire/point setting to buffer attaching. instead of on
precommit.
* syncobj: remove unused code, optimize
remove unused code and merge sync fds if fence is valid, remove manual
directscanout buffer dropping that signals release point on pageflip, it
can cause us to signal the release point while still keeping the current
buffer and rendering it yet again causing wrong things.
* syncobj: delay buffer release on non syncobj
delay buffer releases on non syncobj surfaces until next commit, and
check on async buffers if syncobj and drop and signal the release point
on backend buffer release.
* syncobj: ensure we follow protocol
ensure we follow protocol by replacing acquire/release points if they
arrive late and replace already existing ones. also remove unneded
brackets, and dont try to manual lock/release buffers when it comes to
explicit protocol. it doesnt care about buffer releases only about
acquire and release points and signaling them.
* syncobj: lets not complicate things
set points in precommit, before checking protocol errors and we catch
any pending acquire/release points arriving late.
* syncobj: move SSurfaceState to types
remove destructor resource destroying, let resources destroys them on
their events, and move SSurfaceStates to types/SurfaceState.hpp
* syncobj: actually store the merged fd
have to actually store the mergedfd to use it.
* syncobj: cleanup a bit around fences
ensure the current asynchronous buffer is actually released on pageflip
not the previous. cleanup a bit FD handling in
commitPendingAndDoExplicitSync, and reuse the in fence when syncing
surfaces.
* syncobjs: ensure fence FD doesnt leak
calling resetexplicitfence without properly ensuring the FD is closed
before will leak it, store it per monitor and let it close itself with
the CFileDescriptor class.
* syncobj: ensure buffers are actually released
buffers were never being sent released properly.
* types: Defer buffer sync releaser until unlock
* syncobj: store directscanout fence in monitor
ensure the infence fd survives the scope of attemptdirectscanout so it
doesnt close before it should have.
* syncobj: check if if acquire is expired
we might hit a race to finish on exit where the timeline just has
destructed but the buffer waiter is still pending. and such we
removeAllWaiters null dereferences.
* syncobj: code style changes
remove quack comment, change to m_foo and use a std::vector and
weakpointer in the waiter for removal instead of a std::list.
* syncobj: remove unused async buffer drop
remove unused async buffer drop, only related to directscanout and is
handled elsewhere.
---------
Co-authored-by: Lee Bousfield <ljbousfield@gmail.com>
2025-03-14 15:08:20 +01:00
|
|
|
Hyprutils::OS::CFileDescriptor& fd();
|
2025-04-30 11:35:25 -05:00
|
|
|
Hyprutils::OS::CFileDescriptor&& takeFd();
|
|
|
|
|
bool isValid();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CEGLSync() = default;
|
|
|
|
|
|
2025-04-30 11:35:25 -05:00
|
|
|
Hyprutils::OS::CFileDescriptor m_fd;
|
|
|
|
|
EGLSyncKHR m_sync = EGL_NO_SYNC_KHR;
|
|
|
|
|
bool m_valid = false;
|
2024-08-06 14:52:19 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
friend class CHyprOpenGLImpl;
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-26 17:56:43 +00:00
|
|
|
class CGradientValueData;
|
|
|
|
|
|
2022-04-04 19:44:25 +02:00
|
|
|
class CHyprOpenGLImpl {
|
2022-12-16 17:17:31 +00:00
|
|
|
public:
|
2022-04-04 19:44:25 +02:00
|
|
|
CHyprOpenGLImpl();
|
2024-07-29 19:19:47 +02:00
|
|
|
~CHyprOpenGLImpl();
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
struct SRectRenderData {
|
|
|
|
|
const CRegion* damage = nullptr;
|
|
|
|
|
int round = 0;
|
|
|
|
|
float roundingPower = 2.F;
|
|
|
|
|
bool blur = false;
|
|
|
|
|
float blurA = 1.F;
|
|
|
|
|
bool xray = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct STextureRenderData {
|
|
|
|
|
const CRegion* damage = nullptr;
|
|
|
|
|
SP<CWLSurfaceResource> surface = nullptr;
|
|
|
|
|
float a = 1.F;
|
|
|
|
|
bool blur = false;
|
|
|
|
|
float blurA = 1.F, overallA = 1.F;
|
|
|
|
|
int round = 0;
|
|
|
|
|
float roundingPower = 2.F;
|
|
|
|
|
bool discardActive = false;
|
|
|
|
|
bool allowCustomUV = false;
|
|
|
|
|
bool allowDim = true;
|
|
|
|
|
bool noAA = false;
|
|
|
|
|
bool blockBlurOptimization = false;
|
|
|
|
|
GLenum wrapX = GL_CLAMP_TO_EDGE, wrapY = GL_CLAMP_TO_EDGE;
|
2025-07-31 18:07:59 +02:00
|
|
|
bool cmBackToSRGB = false;
|
|
|
|
|
SP<CMonitor> cmBackToSRGBSource;
|
2025-07-31 16:23:09 +02:00
|
|
|
};
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
struct SBorderRenderData {
|
|
|
|
|
int round = 0;
|
|
|
|
|
float roundingPower = 2.F;
|
|
|
|
|
int borderSize = 1;
|
|
|
|
|
float a = 1.0;
|
|
|
|
|
int outerRound = -1; /* use round */
|
|
|
|
|
};
|
2023-11-04 19:35:49 +00:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void begin(PHLMONITOR, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {});
|
|
|
|
|
void beginSimple(PHLMONITOR, const CRegion& damage, SP<CRenderbuffer> rb = nullptr, CFramebuffer* fb = nullptr);
|
|
|
|
|
void end();
|
2025-06-15 12:11:28 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void renderRect(const CBox&, const CHyprColor&, SRectRenderData data);
|
|
|
|
|
void renderTexture(SP<CTexture>, const CBox&, STextureRenderData data);
|
|
|
|
|
void renderRoundedShadow(const CBox&, int round, float roundingPower, int range, const CHyprColor& color, float a = 1.0);
|
|
|
|
|
void renderBorder(const CBox&, const CGradientValueData&, SBorderRenderData data);
|
|
|
|
|
void renderBorder(const CBox&, const CGradientValueData&, const CGradientValueData&, float lerp, SBorderRenderData data);
|
|
|
|
|
void renderTextureMatte(SP<CTexture> tex, const CBox& pBox, CFramebuffer& matte);
|
2022-04-04 21:45:35 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void pushMonitorTransformEnabled(bool enabled);
|
|
|
|
|
void popMonitorTransformEnabled();
|
2023-04-12 12:41:23 +01:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void setRenderModifEnabled(bool enabled);
|
|
|
|
|
void setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
|
|
|
|
void setCapStatus(int cap, bool status);
|
2023-07-20 13:49:28 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void saveMatrix();
|
|
|
|
|
void setMatrixScaleTranslate(const Vector2D& translate, const float& scale);
|
|
|
|
|
void restoreMatrix();
|
2022-04-05 20:49:15 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void blend(bool enabled);
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
bool shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow);
|
2022-04-19 19:01:23 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void clear(const CHyprColor&);
|
|
|
|
|
void clearWithTex();
|
|
|
|
|
void scissor(const CBox&, bool transform = true);
|
|
|
|
|
void scissor(const pixman_box32*, bool transform = true);
|
|
|
|
|
void scissor(const int x, const int y, const int w, const int h, bool transform = true);
|
2022-08-01 12:16:33 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void destroyMonitorResources(PHLMONITORREF);
|
2022-08-01 12:23:09 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void markBlurDirtyForMonitor(PHLMONITOR);
|
2022-09-13 15:25:42 +02:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void preWindowPass();
|
|
|
|
|
bool preBlurQueued();
|
|
|
|
|
void preRender(PHLMONITOR);
|
2022-12-01 13:36:07 +00:00
|
|
|
|
2025-07-31 16:23:09 +02:00
|
|
|
void saveBufferForMirror(const CBox&);
|
|
|
|
|
void renderMirrored();
|
|
|
|
|
|
|
|
|
|
void applyScreenShader(const std::string& path);
|
|
|
|
|
|
|
|
|
|
void bindOffMain();
|
|
|
|
|
void renderOffToMain(CFramebuffer* off);
|
|
|
|
|
void bindBackOnMain();
|
2023-10-21 14:15:48 +01:00
|
|
|
|
2025-04-24 14:48:08 -04:00
|
|
|
SP<CTexture> loadAsset(const std::string& file);
|
|
|
|
|
SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "", int maxWidth = 0, int weight = 400);
|
2024-02-23 01:02:32 +00:00
|
|
|
|
2025-04-24 14:48:08 -04:00
|
|
|
void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {});
|
2025-01-01 17:26:05 +01:00
|
|
|
|
2025-04-24 14:48:08 -04:00
|
|
|
void ensureBackgroundTexturePresence();
|
2025-01-14 17:52:19 +01:00
|
|
|
|
2025-04-24 14:48:08 -04:00
|
|
|
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
|
|
|
|
|
std::vector<SDRMFormat> getDRMFormats();
|
|
|
|
|
EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs);
|
2023-12-01 17:20:56 +00:00
|
|
|
|
2025-04-24 14:48:08 -04:00
|
|
|
bool initShaders();
|
2025-05-12 05:15:47 -07:00
|
|
|
|
|
|
|
|
GLuint createProgram(const std::string&, const std::string&, bool dynamic = false, bool silent = false);
|
|
|
|
|
GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false);
|
|
|
|
|
void useProgram(GLuint prog);
|
|
|
|
|
|
2025-06-19 13:46:42 +02:00
|
|
|
void ensureLockTexturesRendered(bool load);
|
|
|
|
|
|
2025-07-19 12:38:41 +02:00
|
|
|
bool explicitSyncSupported();
|
|
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
bool m_shadersInitialized = false;
|
2025-04-24 14:48:08 -04:00
|
|
|
SP<SPreparedShaders> m_shaders;
|
2025-03-29 03:19:35 +03:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
SCurrentRenderData m_renderData;
|
2022-04-04 19:44:25 +02:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
Hyprutils::OS::CFileDescriptor m_gbmFD;
|
|
|
|
|
gbm_device* m_gbmDevice = nullptr;
|
|
|
|
|
EGLContext m_eglContext = nullptr;
|
|
|
|
|
EGLDisplay m_eglDisplay = nullptr;
|
|
|
|
|
EGLDeviceEXT m_eglDevice = nullptr;
|
|
|
|
|
uint m_failedAssetsNo = 0;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
bool m_reloadScreenShader = true; // at launch it can be set
|
2022-12-01 13:36:07 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
std::map<PHLWINDOWREF, CFramebuffer> m_windowFramebuffers;
|
|
|
|
|
std::map<PHLLSREF, CFramebuffer> m_layerFramebuffers;
|
|
|
|
|
std::map<PHLMONITORREF, SMonitorRenderData> m_monitorRenderResources;
|
|
|
|
|
std::map<PHLMONITORREF, CFramebuffer> m_monitorBGFBs;
|
2022-04-05 20:49:15 +02:00
|
|
|
|
2023-11-24 10:54:21 +00:00
|
|
|
struct {
|
|
|
|
|
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES = nullptr;
|
2024-06-08 10:07:59 +02:00
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = nullptr;
|
|
|
|
|
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = nullptr;
|
2023-11-24 12:37:10 +00:00
|
|
|
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = nullptr;
|
2024-06-08 10:07:59 +02:00
|
|
|
PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT = nullptr;
|
|
|
|
|
PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT = nullptr;
|
2024-07-21 13:09:54 +02:00
|
|
|
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = nullptr;
|
|
|
|
|
PFNEGLDEBUGMESSAGECONTROLKHRPROC eglDebugMessageControlKHR = nullptr;
|
|
|
|
|
PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT = nullptr;
|
|
|
|
|
PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT = nullptr;
|
|
|
|
|
PFNEGLQUERYDISPLAYATTRIBEXTPROC eglQueryDisplayAttribEXT = nullptr;
|
|
|
|
|
PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR = nullptr;
|
|
|
|
|
PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR = nullptr;
|
|
|
|
|
PFNEGLDUPNATIVEFENCEFDANDROIDPROC eglDupNativeFenceFDANDROID = nullptr;
|
|
|
|
|
PFNEGLWAITSYNCKHRPROC eglWaitSyncKHR = nullptr;
|
2025-05-05 23:44:49 +02:00
|
|
|
} m_proc;
|
2023-11-24 10:54:21 +00:00
|
|
|
|
2023-12-02 14:51:35 +00:00
|
|
|
struct {
|
2024-06-08 10:07:59 +02:00
|
|
|
bool EXT_read_format_bgra = false;
|
|
|
|
|
bool EXT_image_dma_buf_import = false;
|
|
|
|
|
bool EXT_image_dma_buf_import_modifiers = false;
|
2024-07-21 13:09:54 +02:00
|
|
|
bool KHR_display_reference = false;
|
|
|
|
|
bool IMG_context_priority = false;
|
|
|
|
|
bool EXT_create_context_robustness = false;
|
2025-07-19 12:38:41 +02:00
|
|
|
bool EGL_ANDROID_native_fence_sync_ext = false;
|
2025-05-05 23:44:49 +02:00
|
|
|
} m_exts;
|
2023-12-02 14:51:35 +00:00
|
|
|
|
2025-05-05 23:44:49 +02:00
|
|
|
SP<CTexture> m_screencopyDeniedTexture;
|
2025-04-08 19:39:53 +02:00
|
|
|
|
2025-03-26 14:28:19 +00:00
|
|
|
enum eEGLContextVersion : uint8_t {
|
|
|
|
|
EGL_CONTEXT_GLES_2_0 = 0,
|
|
|
|
|
EGL_CONTEXT_GLES_3_0,
|
|
|
|
|
EGL_CONTEXT_GLES_3_2,
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-20 14:51:10 +02:00
|
|
|
eEGLContextVersion m_eglContextVersion = EGL_CONTEXT_GLES_3_2;
|
|
|
|
|
|
|
|
|
|
private:
|
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 {
|
|
|
|
|
GLint x = 0;
|
|
|
|
|
GLint y = 0;
|
|
|
|
|
GLsizei width = 0;
|
|
|
|
|
GLsizei height = 0;
|
|
|
|
|
} m_lastViewport;
|
|
|
|
|
|
|
|
|
|
std::unordered_map<int, bool> m_capStatus;
|
|
|
|
|
|
|
|
|
|
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();
|
2024-06-14 21:59:21 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
std::optional<std::vector<uint64_t>> getModsForFormat(EGLint format);
|
2022-04-14 16:43:29 +02:00
|
|
|
|
2022-05-02 16:54:40 +02:00
|
|
|
// returns the out FB, can be either Mirror or MirrorSwap
|
2023-08-25 17:43:23 +02:00
|
|
|
CFramebuffer* blurMainFramebufferWithDamage(float a, CRegion* damage);
|
2025-05-10 18:31:26 +01:00
|
|
|
CFramebuffer* blurFramebufferWithDamage(float a, CRegion* damage, CFramebuffer& source);
|
2022-05-02 16:54:40 +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
|
|
|
void passCMUniforms(SShader&, const NColorManagement::SImageDescription& imageDescription, const NColorManagement::SImageDescription& targetImageDescription,
|
2025-06-15 13:15:18 +03:00
|
|
|
bool modifySDR = false, float sdrMinLuminance = -1.0f, int sdrMaxLuminance = -1);
|
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
|
|
|
void passCMUniforms(SShader&, const NColorManagement::SImageDescription& imageDescription);
|
2025-07-31 16:23:09 +02:00
|
|
|
void renderTexturePrimitive(SP<CTexture> tex, const CBox& box);
|
|
|
|
|
void renderSplash(cairo_t* const, cairo_surface_t* const, double offset, const Vector2D& size);
|
|
|
|
|
void renderRectInternal(const CBox&, const CHyprColor&, const SRectRenderData& data);
|
|
|
|
|
void renderRectWithBlurInternal(const CBox&, const CHyprColor&, const SRectRenderData& data);
|
|
|
|
|
void renderRectWithDamageInternal(const CBox&, const CHyprColor&, const SRectRenderData& data);
|
|
|
|
|
void renderTextureInternal(SP<CTexture>, const CBox&, const STextureRenderData& data);
|
|
|
|
|
void renderTextureWithBlurInternal(SP<CTexture>, const CBox&, const STextureRenderData& data);
|
|
|
|
|
|
|
|
|
|
void preBlurForCurrentMonitor();
|
2022-11-06 17:58:56 +00:00
|
|
|
|
|
|
|
|
friend class CHyprRenderer;
|
2024-12-22 17:12:09 +01:00
|
|
|
friend class CTexPassElement;
|
|
|
|
|
friend class CPreBlurElement;
|
|
|
|
|
friend class CSurfacePassElement;
|
2022-04-04 19:44:25 +02:00
|
|
|
};
|
|
|
|
|
|
2025-01-23 21:55:41 +01:00
|
|
|
inline UP<CHyprOpenGLImpl> g_pHyprOpenGL;
|