From 0b52aa9d137b03017313e028accc92dc5d536440 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sat, 30 Dec 2023 11:25:16 +0100 Subject: Initial rebase without effects --- include/render/fx_renderer/matrix.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include/render/fx_renderer') diff --git a/include/render/fx_renderer/matrix.h b/include/render/fx_renderer/matrix.h index 6931e8d..c3bae42 100644 --- a/include/render/fx_renderer/matrix.h +++ b/include/render/fx_renderer/matrix.h @@ -3,7 +3,13 @@ #include +/** + * Writes a 2D orthographic projection matrix to mat of (width, height) with a + * specified wl_output_transform. + * + * Equivalent to glOrtho(0, width, 0, height, 1, -1) with the transform applied. + */ void matrix_projection(float mat[static 9], int width, int height, - enum wl_output_transform transform); + enum wl_output_transform transform); #endif -- cgit v1.2.3 From b6a990da71b5b0947650a50dcf1a083acfce868c Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sat, 30 Dec 2023 12:45:04 +0100 Subject: Added fx_texture and fx_framebuffer --- include/render/fx_renderer/fx_renderer.h | 99 ++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-) (limited to 'include/render/fx_renderer') diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index f569aa9..ffd31da 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -57,19 +58,70 @@ struct box_shadow_shader { GLint corner_radius; }; +struct fx_framebuffer { + bool initialized; + + GLuint fbo; + GLuint rbo; + + struct wlr_buffer *wlr_buffer; + struct fx_renderer *renderer; + struct wl_list link; // fx_renderer.buffers + struct wlr_addon addon; + + EGLImageKHR image; +}; + +struct fx_texture { + struct wlr_texture wlr_texture; + struct fx_renderer *fx_renderer; + struct wl_list link; // fx_renderer.textures + + // Basically: + // GL_TEXTURE_2D == mutable + // GL_TEXTURE_EXTERNAL_OES == immutable + GLuint target; + GLuint tex; + + EGLImageKHR image; + + bool has_alpha; + + // Only affects target == GL_TEXTURE_2D + uint32_t drm_format; // used to interpret upload data + // If imported from a wlr_buffer + struct wlr_buffer *buffer; + struct wlr_addon buffer_addon; +}; + struct fx_renderer { float projection[9]; + int viewport_width, viewport_height; + + struct wlr_output *wlr_output; + + struct wlr_egl *egl; + struct fx_stencilbuffer stencil_buffer; + struct wl_list textures; // fx_texture.link + struct wl_list buffers; // fx_framebuffer.link + + // The FBO and texture used by wlroots + GLuint wlr_main_buffer_fbo; + struct wlr_gles2_texture_attribs wlr_main_texture_attribs; + struct wlr_addon addon; struct { bool OES_egl_image_external; + bool OES_egl_image; } exts; struct { PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES; } procs; struct { @@ -82,18 +134,55 @@ struct fx_renderer { } shaders; }; -void fx_renderer_init_addon(struct wlr_egl *egl, struct wlr_addon_set *addons, - const void * owner); +/// +/// fx_framebuffer +/// + +struct fx_framebuffer fx_framebuffer_create(void); + +void fx_framebuffer_bind(struct fx_framebuffer *buffer); + +void fx_framebuffer_bind_wlr_fbo(struct fx_renderer *renderer); + +void fx_framebuffer_update(struct fx_renderer *fx_renderer, struct fx_framebuffer *fx_buffer, + int width, int height); + +void fx_framebuffer_add_stencil_buffer(struct fx_framebuffer *buffer, int width, int height); + +void fx_framebuffer_release(struct fx_framebuffer *buffer); + +/// +/// fx_texture +/// + +struct fx_texture *fx_get_texture(struct wlr_texture *wlr_texture); + +struct fx_texture *fx_texture_from_buffer(struct fx_renderer *fx_renderer, + struct wlr_buffer *buffer); + +void fx_texture_destroy(struct fx_texture *texture); + +bool wlr_texture_is_fx(struct wlr_texture *wlr_texture); + +void wlr_gles2_texture_get_fx_attribs(struct fx_texture *texture, + struct wlr_gles2_texture_attribs *attribs); + +/// +/// fx_renderer +/// + +void fx_renderer_init_addon(struct wlr_egl *egl, struct wlr_output *output, + struct wlr_addon_set *addons, const void * owner); struct fx_renderer *fx_renderer_addon_find(struct wlr_addon_set *addons, const void * owner); -struct fx_renderer *fx_renderer_create(struct wlr_egl *egl); - -void fx_renderer_fini(struct fx_renderer *renderer); +struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *output); void fx_renderer_begin(struct fx_renderer *renderer, int width, int height); +void fx_renderer_end(struct fx_renderer *renderer); + void fx_renderer_clear(const float color[static 4]); void fx_renderer_scissor(struct wlr_box *box); -- cgit v1.2.3 From 51c7078b9ec413ebd8316501f01ccf769a090f64 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Sun, 31 Dec 2023 00:32:39 +0100 Subject: Converted fx_renderer to impl wlr_renderer Makes the fx_renderer the default renderer for everything, no wlr_gles2 rendering. This includes wlr_render_pass (fx_render_pass in our case) --- include/render/fx_renderer/fx_renderer.h | 230 +++++++++++++++---------------- include/render/fx_renderer/shaders.h | 69 ++++++++++ include/render/fx_renderer/util.h | 11 ++ 3 files changed, 192 insertions(+), 118 deletions(-) create mode 100644 include/render/fx_renderer/shaders.h create mode 100644 include/render/fx_renderer/util.h (limited to 'include/render/fx_renderer') diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index ffd31da..6483f12 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -4,74 +4,63 @@ #include #include #include +#include #include -#include +#include #include #include #include + #include "render/fx_renderer/fx_stencilbuffer.h" +#include "render/fx_renderer/shaders.h" +#include "render/pass.h" #include "types/fx/shadow_data.h" -enum fx_tex_shader_source { - SHADER_SOURCE_TEXTURE_RGBA = 1, - SHADER_SOURCE_TEXTURE_RGBX = 2, - SHADER_SOURCE_TEXTURE_EXTERNAL = 3, -}; - -struct quad_shader { - GLuint program; - GLint proj; - GLint color; - GLint pos_attrib; +struct fx_pixel_format { + uint32_t drm_format; + // optional field, if empty then internalformat = format + GLint gl_internalformat; + GLint gl_format, gl_type; + bool has_alpha; }; -struct tex_shader { - GLuint program; - GLint proj; - GLint tex; - GLint alpha; - GLint pos_attrib; - GLint tex_attrib; - GLint size; - GLint position; - GLint radius; -}; +bool is_fx_pixel_format_supported(const struct fx_renderer *renderer, + const struct fx_pixel_format *format); +const struct fx_pixel_format *get_fx_format_from_drm(uint32_t fmt); +const struct fx_pixel_format *get_fx_format_from_gl( + GLint gl_format, GLint gl_type, bool alpha); +const uint32_t *get_fx_shm_formats(const struct fx_renderer *renderer, + size_t *len); -struct stencil_mask_shader { - GLuint program; - GLint proj; - GLint color; - GLint pos_attrib; - GLint half_size; - GLint position; - GLint radius; -}; - -struct box_shadow_shader { - GLuint program; - GLint proj; - GLint color; - GLint pos_attrib; - GLint position; - GLint size; - GLint blur_sigma; - GLint corner_radius; -}; +/// +/// fx_framebuffer +/// struct fx_framebuffer { - bool initialized; - - GLuint fbo; - GLuint rbo; - - struct wlr_buffer *wlr_buffer; + struct wlr_buffer *buffer; struct fx_renderer *renderer; struct wl_list link; // fx_renderer.buffers - struct wlr_addon addon; EGLImageKHR image; + GLuint rbo; + GLuint fbo; + + struct wlr_addon addon; }; +struct fx_framebuffer *fx_framebuffer_get_or_create(struct fx_renderer *renderer, + struct wlr_buffer *wlr_buffer); + +void fx_framebuffer_bind(struct fx_framebuffer *buffer); + +void fx_framebuffer_bind_wlr_fbo(struct fx_renderer *renderer); + +void fx_framebuffer_destroy(struct fx_framebuffer *buffer); + +/// +/// fx_texture +/// + struct fx_texture { struct wlr_texture wlr_texture; struct fx_renderer *fx_renderer; @@ -94,34 +83,62 @@ struct fx_texture { struct wlr_addon buffer_addon; }; -struct fx_renderer { - float projection[9]; +struct fx_texture_attribs { + GLenum target; /* either GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES */ + GLuint tex; - int viewport_width, viewport_height; + bool has_alpha; +}; - struct wlr_output *wlr_output; +struct fx_texture *fx_get_texture(struct wlr_texture *wlr_texture); - struct wlr_egl *egl; +struct wlr_texture *fx_texture_from_buffer(struct wlr_renderer *wlr_renderer, + struct wlr_buffer *buffer); - struct fx_stencilbuffer stencil_buffer; +void fx_texture_destroy(struct fx_texture *texture); - struct wl_list textures; // fx_texture.link - struct wl_list buffers; // fx_framebuffer.link +bool wlr_texture_is_fx(struct wlr_texture *wlr_texture); - // The FBO and texture used by wlroots - GLuint wlr_main_buffer_fbo; - struct wlr_gles2_texture_attribs wlr_main_texture_attribs; +void fx_texture_get_attribs(struct wlr_texture *texture, + struct fx_texture_attribs *attribs); - struct wlr_addon addon; +/// +/// fx_renderer +/// +struct fx_renderer { + struct wlr_renderer wlr_renderer; + + float projection[9]; + struct wlr_egl *egl; + int drm_fd; + + const char *exts_str; struct { + bool EXT_read_format_bgra; + bool KHR_debug; bool OES_egl_image_external; bool OES_egl_image; + bool EXT_texture_type_2_10_10_10_REV; + bool OES_texture_half_float_linear; + bool EXT_texture_norm16; + bool EXT_disjoint_timer_query; } exts; struct { PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + PFNGLDEBUGMESSAGECALLBACKKHRPROC glDebugMessageCallbackKHR; + PFNGLDEBUGMESSAGECONTROLKHRPROC glDebugMessageControlKHR; + PFNGLPOPDEBUGGROUPKHRPROC glPopDebugGroupKHR; + PFNGLPUSHDEBUGGROUPKHRPROC glPushDebugGroupKHR; PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES; + PFNGLGETGRAPHICSRESETSTATUSKHRPROC glGetGraphicsResetStatusKHR; + PFNGLGENQUERIESEXTPROC glGenQueriesEXT; + PFNGLDELETEQUERIESEXTPROC glDeleteQueriesEXT; + PFNGLQUERYCOUNTEREXTPROC glQueryCounterEXT; + PFNGLGETQUERYOBJECTIVEXTPROC glGetQueryObjectivEXT; + PFNGLGETQUERYOBJECTUI64VEXTPROC glGetQueryObjectui64vEXT; + PFNGLGETINTEGER64VEXTPROC glGetInteger64vEXT; } procs; struct { @@ -132,60 +149,35 @@ struct fx_renderer { struct box_shadow_shader box_shadow; struct stencil_mask_shader stencil_mask; } shaders; -}; - -/// -/// fx_framebuffer -/// - -struct fx_framebuffer fx_framebuffer_create(void); - -void fx_framebuffer_bind(struct fx_framebuffer *buffer); - -void fx_framebuffer_bind_wlr_fbo(struct fx_renderer *renderer); - -void fx_framebuffer_update(struct fx_renderer *fx_renderer, struct fx_framebuffer *fx_buffer, - int width, int height); - -void fx_framebuffer_add_stencil_buffer(struct fx_framebuffer *buffer, int width, int height); - -void fx_framebuffer_release(struct fx_framebuffer *buffer); - -/// -/// fx_texture -/// - -struct fx_texture *fx_get_texture(struct wlr_texture *wlr_texture); - -struct fx_texture *fx_texture_from_buffer(struct fx_renderer *fx_renderer, - struct wlr_buffer *buffer); - -void fx_texture_destroy(struct fx_texture *texture); - -bool wlr_texture_is_fx(struct wlr_texture *wlr_texture); - -void wlr_gles2_texture_get_fx_attribs(struct fx_texture *texture, - struct wlr_gles2_texture_attribs *attribs); -/// -/// fx_renderer -/// + struct wl_list buffers; // fx_framebuffer.link + struct wl_list textures; // fx_texture.link -void fx_renderer_init_addon(struct wlr_egl *egl, struct wlr_output *output, - struct wlr_addon_set *addons, const void * owner); + struct fx_stencilbuffer stencil_buffer; -struct fx_renderer *fx_renderer_addon_find(struct wlr_addon_set *addons, - const void * owner); + struct fx_framebuffer *current_buffer; + uint32_t viewport_width, viewport_height; +}; -struct fx_renderer *fx_renderer_create(struct wlr_egl *egl, struct wlr_output *output); +bool wlr_renderer_is_fx(struct wlr_renderer *wlr_renderer); -void fx_renderer_begin(struct fx_renderer *renderer, int width, int height); +struct fx_renderer *fx_get_renderer( + struct wlr_renderer *wlr_renderer); +struct fx_render_timer *fx_get_render_timer( + struct wlr_render_timer *timer); +struct fx_texture *fx_get_texture( + struct wlr_texture *wlr_texture); -void fx_renderer_end(struct fx_renderer *renderer); +struct wlr_renderer *fx_renderer_create_with_drm_fd(int drm_fd); +struct wlr_renderer *fx_renderer_create(struct wlr_backend *backend); +struct wlr_renderer *fx_renderer_create_egl(struct wlr_egl *egl); -void fx_renderer_clear(const float color[static 4]); +struct wlr_egl *wlr_fx_renderer_get_egl(struct wlr_renderer *renderer); -void fx_renderer_scissor(struct wlr_box *box); +void push_fx_debug_(struct fx_renderer *renderer, + const char *file, const char *func); +#define push_fx_debug(renderer) push_fx_debug_(renderer, _WLR_FILENAME, __func__) +void pop_fx_debug(struct fx_renderer *renderer); // Initialize the stenciling work void fx_renderer_stencil_mask_init(void); @@ -200,17 +192,19 @@ void fx_renderer_stencil_enable(void); void fx_renderer_stencil_disable(void); -bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer, - struct wlr_texture *wlr_texture, const struct wlr_fbox *src_box, - const struct wlr_box *dst_box, const float matrix[static 9], - float opacity, int corner_radius); +/// +/// Render Timer +/// -void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *box, - const float color[static 4], const float projection[static 9]); +struct fx_render_timer { + struct wlr_render_timer base; + struct fx_renderer *renderer; + struct timespec cpu_start; + struct timespec cpu_end; + GLuint id; + GLint64 gl_cpu_end; +}; -void fx_render_box_shadow(struct fx_renderer *renderer, - const struct wlr_box *box, const struct wlr_box *stencil_box, - const float matrix[static 9], int corner_radius, - struct shadow_data *shadow_data); +bool wlr_render_timer_is_fx(struct wlr_render_timer *timer); #endif diff --git a/include/render/fx_renderer/shaders.h b/include/render/fx_renderer/shaders.h new file mode 100644 index 0000000..584b18e --- /dev/null +++ b/include/render/fx_renderer/shaders.h @@ -0,0 +1,69 @@ +#ifndef _FX_SHADERS_H +#define _FX_SHADERS_H + +#include +#include + +struct fx_renderer; + +GLuint compile_shader(GLuint type, const GLchar *src); + +GLuint link_program(const GLchar *frag_src); + +bool check_gl_ext(const char *exts, const char *ext); + +void load_gl_proc(void *proc_ptr, const char *name); + +enum fx_tex_shader_source { + SHADER_SOURCE_TEXTURE_RGBA = 1, + SHADER_SOURCE_TEXTURE_RGBX = 2, + SHADER_SOURCE_TEXTURE_EXTERNAL = 3, +}; + +struct quad_shader { + GLuint program; + GLint proj; + GLint color; + GLint pos_attrib; +}; + +struct tex_shader { + GLuint program; + GLint proj; + GLint tex_proj; + GLint tex; + GLint alpha; + GLint pos_attrib; + GLint size; + GLint position; + GLint radius; +}; + +struct stencil_mask_shader { + GLuint program; + GLint proj; + GLint tex_proj; + GLint tex; + GLint pos_attrib; + GLint half_size; + GLint position; + GLint color; + GLint radius; +}; + +struct box_shadow_shader { + GLuint program; + GLint proj; + GLint tex_proj; + GLint tex; + GLint pos_attrib; + GLint position; + GLint size; + GLint color; + GLint blur_sigma; + GLint corner_radius; +}; + +bool link_shaders(struct fx_renderer *renderer); + +#endif diff --git a/include/render/fx_renderer/util.h b/include/render/fx_renderer/util.h new file mode 100644 index 0000000..c0afc69 --- /dev/null +++ b/include/render/fx_renderer/util.h @@ -0,0 +1,11 @@ +#ifndef _FX_UTIL_H +#define _FX_UTIL_H + +#include +#include +#include + +bool open_preferred_drm_fd(struct wlr_backend *backend, int *drm_fd_ptr, + bool *own_drm_fd); + +#endif -- cgit v1.2.3 From 1a6918f948be034e65c50af8969d090b5e762dc1 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Tue, 2 Jan 2024 01:15:34 +0100 Subject: Integrated the stencil rb into fx_framebuffer Every fx_framebuffer will now have a stencil buffer --- include/render/fx_renderer/fx_renderer.h | 4 +--- include/render/fx_renderer/fx_stencilbuffer.h | 20 -------------------- 2 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 include/render/fx_renderer/fx_stencilbuffer.h (limited to 'include/render/fx_renderer') diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index 6483f12..d62d6b4 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -11,7 +11,6 @@ #include #include -#include "render/fx_renderer/fx_stencilbuffer.h" #include "render/fx_renderer/shaders.h" #include "render/pass.h" #include "types/fx/shadow_data.h" @@ -44,6 +43,7 @@ struct fx_framebuffer { EGLImageKHR image; GLuint rbo; GLuint fbo; + GLuint sb; // Stencil struct wlr_addon addon; }; @@ -153,8 +153,6 @@ struct fx_renderer { struct wl_list buffers; // fx_framebuffer.link struct wl_list textures; // fx_texture.link - struct fx_stencilbuffer stencil_buffer; - struct fx_framebuffer *current_buffer; uint32_t viewport_width, viewport_height; }; diff --git a/include/render/fx_renderer/fx_stencilbuffer.h b/include/render/fx_renderer/fx_stencilbuffer.h deleted file mode 100644 index 6909f96..0000000 --- a/include/render/fx_renderer/fx_stencilbuffer.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef FX_STENCILBUFFER_H -#define FX_STENCILBUFFER_H - -#include -#include -#include - -struct fx_stencilbuffer { - GLuint rb; - int width; - int height; -}; - -struct fx_stencilbuffer fx_stencilbuffer_create(void); - -void fx_stencilbuffer_init(struct fx_stencilbuffer *stencil_buffer, int width, int height); - -void fx_stencilbuffer_release(struct fx_stencilbuffer *stencil_buffer); - -#endif -- cgit v1.2.3 From c15af4a182314d8384fc6b28e7c3fc58c0352b83 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Tue, 2 Jan 2024 01:19:48 +0100 Subject: Added back shadow effect --- include/render/fx_renderer/fx_renderer.h | 13 ------------- include/render/fx_renderer/shaders.h | 8 ++------ 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'include/render/fx_renderer') diff --git a/include/render/fx_renderer/fx_renderer.h b/include/render/fx_renderer/fx_renderer.h index d62d6b4..4d99866 100644 --- a/include/render/fx_renderer/fx_renderer.h +++ b/include/render/fx_renderer/fx_renderer.h @@ -177,19 +177,6 @@ void push_fx_debug_(struct fx_renderer *renderer, #define push_fx_debug(renderer) push_fx_debug_(renderer, _WLR_FILENAME, __func__) void pop_fx_debug(struct fx_renderer *renderer); -// Initialize the stenciling work -void fx_renderer_stencil_mask_init(void); - -// Close the mask -void fx_renderer_stencil_mask_close(bool draw_inside_mask); - -// Finish stenciling and clear the buffer -void fx_renderer_stencil_mask_fini(void); - -void fx_renderer_stencil_enable(void); - -void fx_renderer_stencil_disable(void); - /// /// Render Timer /// diff --git a/include/render/fx_renderer/shaders.h b/include/render/fx_renderer/shaders.h index 584b18e..92a14d5 100644 --- a/include/render/fx_renderer/shaders.h +++ b/include/render/fx_renderer/shaders.h @@ -42,24 +42,20 @@ struct tex_shader { struct stencil_mask_shader { GLuint program; GLint proj; - GLint tex_proj; - GLint tex; + GLint color; GLint pos_attrib; GLint half_size; GLint position; - GLint color; GLint radius; }; struct box_shadow_shader { GLuint program; GLint proj; - GLint tex_proj; - GLint tex; + GLint color; GLint pos_attrib; GLint position; GLint size; - GLint color; GLint blur_sigma; GLint corner_radius; }; -- cgit v1.2.3