Commit graph

367 commits

Author SHA1 Message Date
Derek Foreman
5d51042e6b timeline: Make an enum for the timepoint strings
I'll be adding perfetto instrumentation, which will want to know the
timepoint name without having to parse it.

For now, just pass an enum and add a helper function to convert to strings.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2025-01-24 12:22:13 +00:00
Loïc Molinari
e8dae983b7 renderers: Catch backend programming errors with asserts
Add asserts ensuring that outputs aren't created or destroyed twice
and that a valid pair of output/renderbuffer is passed to
repaint_output().

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
1656158d6d gl-renderer: Update renderbuffers in dedicated function
Accumulate renderbuffer damages and select a GL renderbuffer for
repaint in a dedicated function.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
4ee40b653f gl-renderer: Coalesce renderbuffer window retrieval functions
Coalesce gl_renderer_create_renderbuffer_window() and
output_get_window_renderbuffer() into a single
gl_renderer_get_renderbuffer_window() function.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
8567b960fd gl-renderer: Rename dummy renderbuffers to window renderbuffers
Use the term window instead of dummy to make it clear we're dealing
with buffers allocated by the window-system.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
96c49d91a5 libweston: Enforce renderbuffer size
Although backends can create renderbuffers of any size, they always
request the output's current mode size (including decorations).
Letting backends ask for a different size than the output has a few
read-back related design issues like for instance weston_renderer's
read_pixels() API users, currently assuming the output size and
without knowledge of renderbuffers, can retrieve cropped images if a
backend asks for a smaller size. Same issue for the output capture
subsystem.

This commit proposes to fix these issues by simply, albeit perhaps
radically, removing the width and height parameters from
create_renderbuffer(), enforcing the current mode's size of the
associated output.

The VNC and PipeWire backends now also access the output size via the
current mode, not through the width and height variables. This has the
benefit of unifying the backends, as well as the renderers, in their
use of output sizes.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
4eddce5557 libweston: Unify renderbuffer creation API
The Pixman renderer creates renderbuffers with the create_image() and
create_image_from_ptr() functions. The recent addition of the GL
renderer's create_fbo() function, which is pretty similar to the
Pixman ones, brings the opportunity to unify Pixman and GL renderers.

This commit proposes a common renderer function create_renderbuffer()
to create a renderbuffer of the specified format with an optional user
provided destination buffer.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
91da8560eb gl-renderer: Leave FBOs bound in init utilities on success
This avoids having to re-bind them in functions that reuse them
immediately afterwards and does not affect any other parts of code.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
1f1c219d5c gl-renderer: Don't set min/mag filters in gl_fbo_texture_init()
This is most often set again at render time.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
51d217a9b4 gl-renderer: Adapt gl_fbo_texture_*() to new FBO utilities
This commit makes gl_fbo_texture_init() and gl_fbo_texture_fini()
consistent with the new FBO handling utilities by using the same
conventions: output parameters, variable names, descriptions.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
1f4d291850 gl-renderer: Remove glGetError() check from gl_fbo_image_init()
Remove the glGetError() check from gl_fbo_image_init() after the call
to glEGLImageTargetRenderbufferStorageOES(). It would probably just
return a previous error queued by an unrelated GL call because the
error flags aren't cleared. So instead of obfuscating the code, this
commit removes that check and relies instead on the framebuffer
completeness check which will better report issues.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
0688343dec gl-renderer: Add FBO handling utilities
Add generic gl_fbo_init(), gl_fbo_image_init() and gl_fbo_fini()
utilities to the GL renderer and make use of these in the renderbuffer
creation functions.

This also fixes a framebuffer object leak on dma-buf renderbuffer
creation when the EGLImageTargetRenderbufferStorageOES() call fails.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
1c7274deed gl-renderer: Make surface_copy_content() render to a GL renderbuffer
There's no need to render the surface content to a GL texture so make
it render to a GL renderbuffer instead.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:31 +01:00
Loïc Molinari
092076f6f5 gl-renderer: Regroup renderbuffer creation functions
Move gl_renderer_create_renderuffer_dmabuf() along with the other
renderbuffer creation functions, using a common naming pattern.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:34:27 +01:00
Loïc Molinari
c5e6fa7103 gl-renderer: Move common renderbuffer init to dedicated func
Avoid code duplication in renderbuffer creation functions.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
83a1a0293a gl-renderer: Use a union to store type specific renderbuffer data
This makes type specific accesses more explicit and less verbose than
the container_of/base alternative which was needed when the base
renderbuffer type was exposed in libweston-internal.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
2bfaac0f5c gl-renderer: Skip non-dummy rbs in get_dummy_renderbuffer()
No backends currently create FBO or dma-buf renderbuffers on outputs
associated to a window. This is theoretically possible though and
should be allowed by the GL renderer. This commit prevents
output_get_dummy_renderbuffer() from mixing up renderbuffer types.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
47035a776c gl-renderer: Don't accumulate damages on stale renderbuffers
Stale renderbuffers are kept in the renderbuffer list until they're
destroyed by the backend. In the meantime, they shouldn't accumulate
damages since they won't be used anymore.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
a49b2e5a0d libweston: Deal with renderbuffer discards using an event handler
It's currently assumed by backends that renderers discard
renderbuffers on resize. This commit introduces a new
weston_renderbuffer_discarded_func callback that must be passed at
renderbuffer creation in order to be notified of discarded events from
the renderer. This discarded event could potentially be reused later
by renderers on other occasions without having to change backends once
they get proper support for that.

On output resize, once a discarded event handler fails (returns false)
on a renderbuffer, all the remaining renderbuffers in the output list
go stale and weston_renderer_resize_output() ultimately returns false
for backends to be notified of the failure.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
b9e199b47d libweston: Use explicit renderbuffer destruction
Renderbuffers currently have a libweston-internal base data structure
with a ref-counting system to handle their lifetime. The problem is
that renderers keep a ref to all renderbuffers in a list per output
(to deal with damages) and that it prevents backends from releasing
renderbuffer resources when not needed anymore. Renderbuffers are then
only released (last ref removed) when the output is destroyed or
resized. dma-buf renderbuffers even expose a dedicated function
remove_renderbuffer_dmabuf() to explictly request the release of their
resources.

This commit proposes to get rid of the ref-counting system by exposing
a single entry point to explicitly destroy all types of renderbuffers
from the renderer.

Instead of removing a renderbuffer from its output list and dropping
its ref when the output is resized, this commit also introduces the
concept of stale renderbuffers which consists in releasing the
resources of a renderbuffer when it's discarded by the renderer while
keeping it in the output list, with a stale state, until it's
explicitly destroyed.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Loïc Molinari
1619a4a1e5 libweston: Let renderers manage renderbuffers' damage
Move the responsibility for damaging the entire area of new
renderbuffers from backends to renderers.

There's one little drawback: VNC damage logging can't log the
accumulated renderbuffer damage anymore, but I guess this should
somehow be done as an option in the renderers.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-21 14:21:40 +01:00
Marius Vlad
207fed2710 Revert "shared/helpers.h: Migrate helpers.h to libweston"
This is problematic as we don't have namespacing for these and some of
the macros can interfere with other defines.

This reverts commit 8634c7e349.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2025-01-17 10:18:26 +02:00
Loïc Molinari
4be294bd69 gl-renderer: Move list init after feature flags setup
Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
8d21829f49 gl-renderer: Add GPU timeline feature flag
This flag ensures support for both the GL_ANDROID_native_fence_sync
and the GL_EXT_disjoint_timer_query extensions at run-time. The GL
features log now reports that flag so the warning log has been
removed.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
169bb00bbd gl-renderer: Add color transforms feature flag
Replace gl_supports_color_transforms with a feature flag.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
7f01f9e18e gl-renderer: Add async read-back feature flag
Replace has_pbo with a feature flag.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
090c01da87 gl-renderer: Load GL function pointers with GET_PROC_ADDRESS()
Use the same macro than for the EGL function pointers.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
d7dcc2eaa7 gl-renderer: Remove GL extension booleans
Now that the GL extensions are stored in the gl_extensions bitfield,
there's no need to use booleans anymore.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
0026986cce gl-renderer: Check for GL_OES_EGL_image support
This commit ensures GL_OES_EGL_image is available before setting up
dma-buf renderer functions because it's not implied by the presence of
the EGL_EXT_image_dma_buf_import extension.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
aaf968bf58 gl-renderer: Slightly improve color transforms check
GL_OES_texture_3D isn't used because of the complexity implied for
correct OpenGL ES 2 support (see commit 734c2278), so there's no need
to check for it. The check also now avoids checking for
GL_EXT_color_buffer_half_float on OpenGL ES 3.2 which includes support
for 16-bit FP renderbuffers by default.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
02b4eccd05 gl-renderer: Add EGL_KHR_get_all_proc_addresses checks
The GL renderer supports OpenGL ES from version 2.0 to 3.2. It's meant
to correctly link on systems with only OpenGL ES 2, so OpenGL ES 3
symbols can't be used directly. eglGetProcAddress() is currently
defined to not support the querying of non-extension OpenGL ES
functions. Support for that is exposed by the
KHR_get_all_proc_addresses extension. This commit ensures OpenGL ES 3
function addresses can be retrieved by eglGetProcAddress() by checking
for that extension at run-time.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
4ae493ff25 gl-renderer: Store GL extensions as flags
A new gl_extensions bitfield is added to the renderer to store the
flags supported by the GL implementation. This allows the GL renderer
to easily check for extension support whenever needed.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
db5c06bd16 gl-renderer: Remove branch never taken
Don't flag EGL_PBUFFER_BIT to get the EGL config if the
EGL_KHR_surfaceless_context extension isn't available. The branch is
never taken because the extension is required and if it isn't
available, the function would have already returned.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
4f7f888d6c gl-renderer: Improve EGL_WL_bind_wayland_display extension handling
Get the EGL_WL_bind_wayland_display extension function addresses after
checking for extension availability.

Let the EGL display setup end before trying to bind the Wayland
display in gl-renderer.c. The EGL features log will now report the
extension as supported even if the bind subsequently fails, in which
case a warning is logged.

This commit also avoids calling query_buffer() if the display isn't
bound in fill_buffer_info(), it would otherwise fail or even segfault
if the EGL_WL_bind_wayland_display extension isn't available.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
94ca770c2a gl-renderer: Add explicit sync feature flag
This feature flag is for explicit sync support.

We replace the explicit sync warning by logging supported fence syncs
along with the report EGL features report.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
3d0d850980 gl-renderer: Add swap buffers with damage feature flag
This second feature flag ensures that either the
EGL_EXT_swap_buffers_with_damage or EGL_EXT_swap_buffers_with_damage
extension is available.

Some function pointer addresses are currently retrieved depending on
the availabilty of their associated extension and some others are
retrieved unconditionally. For consistency reasons, we'll try from now
on in this commit set to first load function pointers depending on the
associated extension availability and then flag features once all the
addresses are retrieved.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
4a4a9b94d6 gl-renderer: Add no config context feature flag
This commit introduces feature flags. While an extension flag only
ensures the availability of an extension at run-time, a feature flag
ensures the availability of a minimal OpenGL ES version and/or
extensions in order to easily check for the availability of a specific
feature at run-time.

This first feature ensures the availability of either the
EGL_KHR_no_config_context or EGL_MESA_configless_context extensions.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
c56c104f7a gl-renderer: Remove EGL extension booleans
Now that the EGL extensions are stored in the egl_*_extensions
bitfields, there's no need to use booleans anymore.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
00f7bf91d8 gl-renderer: Add extension flag parser
This new utility parses extension strings and fills a bitfield of
matched flags. This will be used to store EGL and GL extension flags.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Loïc Molinari
39a199293e gl-renderer: Move versioning utils to internal header
Next commits will need this outside of gl-renderer.c.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2025-01-14 13:24:39 +00:00
Tomek Bury
b14461b13b gl-renderer: make DMABUF allocator optional
The dmabuf allocator pulls in libgbm which lives inside Mesa and is built
as a non-standalone part Mesa. This makes gl-renderer hard-wired to Mesa.

The allocator is only used by an optional pipewire backend so make
the allocator optional too.

Signed-off-by: Tomek Bury <tomek.bury@gmail.com>
2024-12-03 13:41:50 +00:00
Marius Vlad
bf7b2311e7 gl-renderer: Take direct-display into consideration
The buffer_init function added with commit 83b37c0ac4, "renderers: pull
dmabuf initial setup out of attach", doesn't take into consideration the
the buffer's direct-display property.

Previously, gl_renderer_attach_dmabuf, wasn't being called when dmabuf's
direct-display  was turned on, but with commit 83b37c0ac4 this has been changed.

So with commit 83b37c0ac4, linux_dmabuf_buffer_get_user_data will never
return a valid gb (gl buffer state), causing a crash using
direct-display extension. This adds an explicit check to return early
when this happens.

Fixes: 83b37c0ac4, "renderers: pull dmabuf initial setup out of attach"
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2024-12-01 23:17:50 +02:00
Marius Vlad
8634c7e349 shared/helpers.h: Migrate helpers.h to libweston
As weston_windowed_output_get_api needs ARRAY_LENGTH() move helpers to a
libweston/ so other users can re-use that instead of re-defining these
all over. Easier for other front-ends to make use of them.

With this change windowed-output-api.h also includes the helpers header.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2024-11-25 11:26:35 +00:00
Loïc Molinari
bb6abf3c33 gl-renderer: Clean up comments
Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-08-12 10:44:55 +00:00
Loïc Molinari
0078a20f17 gl-renderer: Fix debug clear on shadow buffers
The shadow buffer must be blitted entirely when debug clear is on.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-08-12 10:44:55 +00:00
Loïc Molinari
c65284bf9d gl-renderer: Fix debug clear region
The debug clear region must be generated out of the current render
buffer's damage region, not out of the current damage region, unless
shadow 16F is enabled.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-08-12 10:44:55 +00:00
Loïc Molinari
215d552ce1 gl-renderer: Don't use eglSetDamageRegion() on surfaceless outputs
eglSetDamageRegion() requires a postable surface and shouldn't be
called with EGL_NO_SURFACE.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-08-12 10:44:55 +00:00
Loïc Molinari
fb4cccc290 gl-renderer: Assume default GL texture unit
Revert active unit to default value right after use so that other
functions can assume the default state. A best practices section is
added to the internal header for reference.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-07-29 14:20:43 +00:00
Loïc Molinari
b755345a46 gl-renderer: Assume fixed wireframe tex unit
The wireframe unit can only be used by the wireframe texture so
there's no need to bind it anymore before use.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-07-29 14:20:43 +00:00
Loïc Molinari
16390dbae1 gl-renderer: Avoid GL_ as a prefix for constants
Avoid prefixing constants with GL_ as it could be confused with OpenGL
constants.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
2024-07-29 14:20:43 +00:00