Commit Graph

221 Commits

Author SHA1 Message Date
Benjamin Otte
96b800fa0c gl: Add buffer implementation using persistent mapping
If glBufferStorage() is available, we can replace our usage of
glBufferSubData() with persistently mapped storage via
glMappedBufferRange().

This has 1 disadvantage:

1. It's not supported everywhere, it requires GL 4.4 or
   GL_EXT_buffer_storage. But every GPU of the last 10 years should
   implement it. So we check for it and keep the old code.
   The old code can also be forced via GDK_GL_DISABLE=buffer-storage.

But it has 2 advantages:

1. It is what Vulkan does, so it unifies the two renderers' buffer
   handling.

2. It is a significant performance boost in use cases with large vertex
   buffers. Those are pretty rare, but do happen with lots of text at a
   small font size. An example would be a small font in a maximized VTE
   terminal or the overview in gnome-text-editor.

A custom benchmark tailored for this problem can be created with:

  tests/rendernode-create-tests 1000000 text.node

This creates a node file called "text.node" that draws 1 million text
nodes.
(Creating that test takes a minute or so. A smaller number may be useful
on less powerful hardware than my Intel Tigerlake laptop.)
The difference can then be compared via:

  tools/gtk4-rendernode-tool benchmark --runs=20 text.node
and
  GDK_GL_DISABLE=buffer-storage tools/gtk4-rendernode-tool benchmark --runs=20 text.node

For my laptop, the difference is:
before: 1.1s
after:  0.8s

Related: !7021
2024-03-16 20:55:26 +01:00
Benjamin Otte
f725bdad25 gl: Move GL_ARB_base_instance check
It's a GLContext feature check, not a GpuRenderer thing.

So put it there.
2024-03-16 13:52:28 +01:00
Benjamin Otte
4e453acd4f gl: Remove the BGRA feature
Nobody is using it anymore now that we have format tracking for all
formats.
2024-03-16 13:44:02 +01:00
Benjamin Otte
3a04542146 gl: Add GDK_GL_DISABLE env var
This allows disabling certain GL features for testing, same as with
Vulkan.
2024-03-16 13:44:02 +01:00
Benjamin Otte
d6a1eb1b2f gl: Split out function
This splits feature checks into its own function.

Which in turn allows splitting the check from the actual reaction to the
flags.
2024-03-16 13:44:02 +01:00
Benjamin Otte
141769fb46 gl: Turn has_foo flags into GdkGLFeatures
The goal is to have it mirror GdkVulkanFeatures, and in particular
having an environment variable to turn individual flags off.
2024-03-16 13:44:02 +01:00
Benjamin Otte
0fdb6a9243 gl: Remove an unnecessary make_current()
This function is called only from make_current() after all, so the
context is already current.
2024-03-16 13:44:02 +01:00
Matthias Clasen
a9dfec8478 glcontext: Don't call get_instance_private (NULL)
ubsan does not like this.

See a9175e0c03 for a detailed explanation.
2024-03-15 13:06:34 -04:00
Christian Hergert
2a98928286 gdk/gdkglcontext: include duration of eglSwapBuffers 2024-03-02 00:03:57 +00:00
Alessandro Bono
d957e40a63 gdkglcontext: Include gdkdmabuffourccprivate.h
It includes a fallback list of fourccs. Otherwise we might miss some
DRM_FORMAT definition.
2024-02-13 14:15:32 +01:00
Matthias Clasen
7cf567b4f9 gl: Check for the right extension name
The extension is called GL_OES_vertex_half_float.
2024-02-12 16:13:54 -05:00
Matthias Clasen
f90e77d173 gdk: Enable fractional scaling for GL by default
The ngl renderer has good support for fractional scaling, so we
can enable this by default now.

If you are using the gl renderer, you can disable fractional
scaling with the

GDK_DEBUG=gl-no-fractional

environment variable.
2024-01-25 14:41:04 -05:00
Matthias Clasen
f779832861 Tweak profiling strings
Capitalize our mark names, and use GTK as category.

The justification is: it looks better in sysprof.
2024-01-21 14:02:08 -05:00
Matthias Clasen
6e8a70ada1 Drop gdk_gl_context_has_bgra
This private api turned out to be more problematic than useful,
and it isn't used anymore.
2024-01-21 08:29:33 -05:00
Benjamin Otte
825c97be6c glcontext: Mark RGB16F as not renderable
According to EXT_color_buffer_half_float it should be renderable, but it
fails to glGenerateMipmap() with Mesa 23.3 so just pretend it's not
renderable until that is fixed.

Fixes CI from failing.
2024-01-03 16:05:25 +01:00
Benjamin Otte
25f99f35f6 glcontext: RGB32F is not renderable
I naively assumed the EXT_color_buffer_float and
EXT_color_buffer_half_float extensions would mirror each other, but they
do not. The float extension explicitly excludes RGB32F from the
renderable formats.
2024-01-03 16:05:25 +01:00
Benjamin Otte
b719f3bd60 glcontext: Fix a mixup of flags
I swapped RENDERABLE and FILTERABLE when building this table.
2024-01-03 16:05:25 +01:00
Benjamin Otte
210c71b856 egl: Split out a function
This makes no sense by itself, but we want to create the EGLImage at
DmabufTexture construction so that we can actually reject dmabufs that
we can't create EGLImages for.

This will make it possible to bail when the stride limitation for AMD
GPUs hits.
2023-12-20 01:51:46 +01:00
Benjamin Otte
5485d806c5 glcontext: Add gdk_gl_context_get_memory_flags()
Checks which features of a given memory format are supported by
the current GL implementation.

We check:
 * usable: Can be used as a texture with NEAREST filter
 * renderable: Can be used as a render target
 * filterable: Can be used with GL_LINEAR

In normal GL, all formats are all of these things, but GLES is a lot
more picky.

So far nobody uses this.
2023-12-11 07:33:26 +01:00
Matthias Clasen
a90a6c4517 Address various static analysis complaints
These were picked out of the scan_build logs in ci.
2023-11-22 00:07:47 -05:00
Matthias Clasen
f04c819439 Drop the gl-legacy debug value
The consensus is that we can do without this.
2023-11-20 08:02:02 -05:00
Matthias Clasen
699c6d6159 Use GLES by default
With the advent of dmabuf support, using GLES has become more
attractive, since we can use its external texture support to
support more dmabuf formats.

You can go back to the previous preference order by setting

    GDK_DEBUG=gl-prefer-gl
2023-11-19 08:07:03 -05:00
Matthias Clasen
fcdbab3f69 gl: Tweak debug values for GL api selection
Replace GDK_DEBUG=gl-gles with GDK_DEBUG=gl-disable-gl, and add
a GDK_DEBUG=gl-disable-gles to match.
2023-11-19 08:07:02 -05:00
Matthias Clasen
b24ae31716 dmabuf: Improve consistency of debug messages
Make sure all our dmabuf debug messages are display-scoped so the
inspector doesn't trigger them, use the same formatting throughout,
and improve consistency of wording here and there.
2023-11-12 13:02:58 +01:00
Benjamin Otte
a9e4993184 Merge branch 'wip/otte/enable-debug' into 'main'
Remove G_ENABLE_DEBUG around debug checks

See merge request GNOME/gtk!6546
2023-11-07 15:12:11 +00:00
Benjamin Otte
cd7e1c1387 dmabuf: Modify gdk_gl_context_import_dmabuf()
Move a bunch of code - namely the target selection - into the function.

I want to use the same code in the NGL renderer, so no need to duplicate
it.
2023-11-07 05:12:57 +01:00
Benjamin Otte
61207f81c3 dmabuf: Set same YUV colorspace as elsewhere
We use ITU.601 full range everywhere, so ensure it's used here, too.
2023-11-07 05:12:57 +01:00
Benjamin Otte
310ab7b531 Remove G_ENABLE_DEBUG around debug checks
It started out as busywork, but it does many separate things. If I could
start over, I'd take them apart into multiple commits:

1. Remove G_ENABLE_DEBUG around GDK_DEBUG_*() calls
   This is not needed at all, the calls themselves take care of it.

2. Remove G_ENABLE_DEBUG around profiling code
   This now enables profiling support in release builds.

3. Stop poking _gdk_debug_flags and use GDK_DEBUG_CHECK()
   This was old code that was never updated.

4. Make !G_ENABLE_DEBUG turn off GDK_DEBUG_CHECK()
   The code used to
     #define GDK_DEBUG_CHECK(...) false
     #define GDK_DEBUG(...)
   which would compile away all the code inside those macros. This
   means a lot of variable definitions and debug utility functions
   would suddenly no longer be used and cause compiler errors.
2023-11-05 11:16:23 +01:00
Matthias Clasen
6e236b9459 Revert "gl context: Check for more GL extensions"
This reverts commit b8b5835fc6.
2023-10-29 14:44:46 -04:00
Matthias Clasen
11715760f9 Revert "glcontext: Better debug spew"
This reverts commit 30e14f73fa.
2023-10-29 14:44:29 -04:00
Matthias Clasen
30e14f73fa glcontext: Better debug spew
Print out all the extensions we checked.
2023-10-22 22:41:53 -04:00
Benjamin Otte
a579e3bc6d build: Fix up header includes
These weren't fixed in the merge request in
  https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6489
to the change from
  https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6514
2023-10-23 03:12:09 +02:00
Matthias Clasen
8fb0ab2b43 gl context: Add private dmabuf API
Add API to import a dmabuf into a texture,
and to export a texture to a dmabuf.

All this is implemented using the relevant
EGL and GL extensions.
2023-10-22 16:39:24 -04:00
Matthias Clasen
b8b5835fc6 gl context: Check for more GL extensions
These will be used in future commits.
2023-10-22 16:39:24 -04:00
Matthias Clasen
b8ffceaebb glcontext: Add api to check for vertex arrays
Vertex arrays are available in GL and in GLES >= 3.

We don't check for the GLES extension that provided
vertex arrays in older GLES, since that requires
using different API.

This api avoids version checks all over the place.
2023-10-19 22:43:13 -04:00
Matthias Clasen
d55fa0dfef glcontext: Check for GL_EXT_texture_format_BGRA8888
Check for this GLES extension and add a private getter.
2023-10-19 13:55:18 -04:00
Benjamin Otte
e720008dca glcontext: Add gdk_gl_context_get_glsl_version_string()
This is in preparation for the new renderer.
2023-09-26 11:08:59 +02:00
Benjamin Otte
d1c7376b05 gdkcontext: Make has_unpack_subimage() do the version check
Makes the code look simpler when we actually use that function.
2023-08-12 23:13:23 +02:00
Benjamin Otte
ce5d74d7df glcontext: Fix typo in Apple extension name 2023-07-03 22:02:44 +02:00
Benjamin Otte
090cd2238a gdk: Replace prefers_high_depth with depth
Now that we track depth, we can also pass it into the GDK frame code.

For now it's just passed along, code acts the same as with
prefers_high_depth.
2023-06-18 14:28:39 +02:00
Matthias Clasen
a9f9fb2022 gl: Free all tracked buffers
This was overlooked when the number of tracked
buffers was bumped from 2 to 4 in 46e3454eb7.
2023-06-04 22:17:56 -04:00
Benjamin Otte
7573a9d2a7 gl: Rewrite update area tracking code
Make it more generic. That way we could dynamically change the number of
buffers we track.

We don't do that yet though.
2023-05-24 21:44:29 +02:00
Matthias Clasen
5071e6154c glcontext: Add a way to check for GLsync 2023-04-27 06:54:49 +02:00
Benjamin Otte
7c7a3d67ca glcontext: assert all contexts set the version on realize()
Now that all contexts do that, insist that they keep doing it.

And because they keep doing it, we can support querying the GL version
from gdk_gl_context_get_version() without requiring the context to be
made current.
2023-04-27 02:13:32 +02:00
Benjamin Otte
5f833f1d31 glcontext: Compute matching version the simple way
Do it all in one function instead of requiring two different ones.
2023-04-27 02:13:32 +02:00
Benjamin Otte
34662fc4b0 egl: Make sure highest possible GL version is created
The EGL spec states:

    The context returned must be the specified version, or a later
    version which is backwards compatible with that version.
    Even if a later version is returned, the specified version
    must correspond to a defined version of the client API.

GTK has so far been relying on EGL implementations returning a
later version, because that is what Mesa does.
But ANGLE does not do that and only provides the minimum version, which
means Windows EGL has been forced to use a lower EGL version for no
reason.

So fix this and try versions in order from highest to lowest.
2023-04-27 02:13:32 +02:00
Benjamin Otte
3aefed39b1 glcontext: Use GdkGLVersion elsewhere
... and add a convenience API to generate GL versions from strings to
make the gdk_gl_context_check() API nicer.
2023-04-27 02:13:32 +02:00
Benjamin Otte
f86429177a gdk: Introduce GdkGLVersion
... and use it.

Makes the code simpler.
2023-04-27 02:13:32 +02:00
Marc-André Lureau
d69cdf6c05 gdk: drop libangle GLES minimum version
GLES 2.0 version is fine now with current gtk according to B. Otte.
Let's use the same minimum requirement for all implementations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Matthias Clasen
4746ffc4eb Make fractional scaling for GL opt-in
Fractional scaling with the GL renderer is
experimental for now, so we disable it unless
GDK_DEBUG=gl-fractional is set.

This will give us time to work out the kinks.
2023-04-02 11:05:57 -04:00