Commit Graph

824 Commits

Author SHA1 Message Date
Matthias Clasen
ab1fba6fdc gl: When loading a texture, really create a mipmap
If we need a mipmap, and we find an existing texture that can't
mipmap, we need to recreate it.
2024-01-03 12:26:13 -05:00
Matthias Clasen
cfa53de9af gl: Check if texture has a mipmap
When reusing an exiting texture, check if it has a mipmap, in case
we need one.
2024-01-03 12:22:28 -05:00
Benjamin Otte
96a71d515b gl: Track if mipmap generation is allowed
... and if it isn't, switch to a format that does allow mipmaps.
2024-01-03 16:56:43 +01:00
Benjamin Otte
b830ca8fab gl: Pass correct format/type to function
Instead of querying the format again and potentially coming out with a
different format, use the one we queried in the calling function.
2024-01-03 16:56:31 +01:00
Benjamin Otte
af014007f4 gl: Remove old Cairo fallback drawing code
We use gsk_render_node_draw_fallback() now which does all of that for
us.
2023-12-26 17:28:08 +01:00
Benjamin Otte
1385ffd2c2 gsk: Repurpose GSK_DEBUG=cairo
Use it to overlay an error pattern over all Cairo drawing done by
renderers.

This has 2 purposes:
1. It allows detecting fallbacks in GPU renderers.
2. Application code can use it to detect where it is using Cairo
   drawing.

As such, it is meant to trigger both with cairo nodes as well as when
renderers fallback for regular nodes.

The old use of the debug flag - which were 2 not very useful print
statements - was removed.
2023-12-26 05:31:05 +01:00
Benjamin Otte
d2a85abf79 Merge branch 'wip/otte/dmabuf-refactoring' into 'main'
dmabuf refactoring

See merge request GNOME/gtk!6678
2023-12-20 10:25:29 +00:00
Benjamin Otte
74620ffc46 dmabufdownloader: Add a close() function
We need to unrealize renderers before unreffing them. This vfunc takes
care of that.
2023-12-20 10:59:25 +01:00
Benjamin Otte
ce04dfad41 renderer: Move function into only caller
The convert_texture() path only works for the GL renderer, the new
renderers potentially use dmabuf textures as result of render_texture(),
so they need to be smarter here.
2023-12-20 10:59:25 +01:00
Benjamin Otte
568eed9477 dmabuf: Turn the downloader into an interface
This way, we can move the actual downloader code into GSK - by just
implementing the interface in the GskGLRenderer.
2023-12-20 10:59:25 +01:00
Matthias Clasen
9166e90bd4 Merge branch 'gles-glyph-upload' into 'main'
gsk: Fix icon and glyph upload with GLES

Closes #6216

See merge request GNOME/gtk!6674
2023-12-18 12:34:58 +00:00
Matthias Clasen
6ad15fe6d0 gsk: Fix icon and glyph upload with GLES
We can't avoid a copy here, unfortunately.

Fixes: #6216
2023-12-17 21:53:10 -05:00
Matthias Clasen
79009d4158 gsk: Handle straight-alpha dmabufs
This omission was noticed by Benjamin Otte. Add a premultiply
uniform to the external shader, and add a separate premultiply
shader for the non-external case.
2023-12-15 07:40:27 -05:00
Benjamin Otte
4dfc07ef57 memoryformat: Fix variable types
Use the same types that GL uses.
2023-12-12 01:49:41 +01:00
Benjamin Otte
cf4b0a27f8 glcontext: Only swizzle when we can
Don't use the recently added swizzle optimization if we're using a GL
version that is too old to support swizzling (GLES 2).
2023-12-12 01:49:41 +01:00
Benjamin Otte
393ee574b6 gl: Print debug for CPU conversions of textures
When the GL renderer cannot upload a given format, print a FALLBACK
debug message with the failed format and the alternative that was
picked, for example:

Unsupported format b8g8r8a8, converting on CPU to b8g8r8a8-premultiplied

Makes it easier to figure out what's happening, especially when using
old GLES versions that don't support all formats.
2023-12-12 01:49:41 +01:00
Benjamin Otte
e3c85be53f memoryformat: Add gdk_memory_format_get_fallbacks()
Track fallback formats to use in the memoryformat directly instead of
using in the GL uploading code.

First of all, this allows sharing the code and ensuring all our
renderers use the same fallback mechanism.

But also, this allows tracking fallbacks per-format which is useful
because the fallback formats aren't really a tree. We want to make
FLOAT16 fall back to FLOAT32 when not available, but we also want
FLOAT32 fall back to FLOAT16.
By tracking the fallbacks per-format, we can achieve that.
2023-12-12 01:49:40 +01:00
Benjamin Otte
0f5fda2277 memoryformat: Introduce new (private) API
Add gdk_memory_format_get_premultiplied() and
gdk_memory_format_get_straight() which return the matching
premultiplied/straight format.

Use this to pick the premultiplied format when uploading GL textures.

And remove the duplication in the dmabuf code, where we can now use
these functions instead of tracking both the premultiplied and straight
alpha versions.
2023-12-12 01:49:40 +01:00
Benjamin Otte
5688b7b4bb gl: Add a new alternative format
Add an "RGBA" format that just maps to the swizzled version of the
default format.

This way, BGR gets mapped to RGB + swizzling first before trying to map
it to the default format for the depth.

The benefit here is that this format has the same memory width, so
uploading/downloading code can treat it equivalent to the original
format and there's no conversion neccessary later.
2023-12-12 01:49:40 +01:00
Benjamin Otte
3a1349e8ef gl: Make gdk_memory_format_gl_format() no longer check support
Now that we have gdk_gl_context_get_memory_flags() and code can use that
function, make the code do that.

Remove support checks from gdk_memory_format_gl_format().

This is an initial naive port that doesn't try to make use of the finer-grained
flags yet.
2023-12-11 07:33:26 +01:00
Matthias Clasen
00ebd51d06 gsk: Be more careful about texture slice formats
We need to make sure that all our textures have the same memory
format, or we'll run into trouble in the upload code, at least
on GLES, which isn't as forgiving about format mismatches.

Related: #6238
2023-11-28 14:16:21 -05:00
Matthias Clasen
108eb43b01 gsk: Add some more proiler marks
These should help us determine if time is spent converting or
uploading textures.
2023-11-27 17:50:28 -05:00
Matthias Clasen
2bfd4a88d6 Fix some more static analysis warnings 2023-11-24 16:36:46 -05:00
Matthias Clasen
36314f28e2 gsk: Some more rect inlining 2023-11-24 10:35:57 -05:00
Benjamin Otte
1b08fda93e renderer: Remove offload argument from render()
It turns out it's not needed, because all relevant information for
subsurfaces is already available by querying the subsurface itself.
2023-11-14 21:54:35 +01:00
Benjamin Otte
f6b6176ec0 gl: Handle subsurfaces without GskOffload 2023-11-14 21:51:07 +01:00
Benjamin Otte
ef77a6fa73 gl: Don't punch hole if the subsurface is above
Saves some work.
2023-11-14 20:22:24 +01:00
Benjamin Otte
9185f15cd9 renderer: Add a supports_offload flag
This flag must be set when creating the class or offloading
will be disabled for this renderer.

Set that flag for the GL renderer.

Fixes the Cairo and Vulkan renderer not showing Video.
2023-11-14 13:06:05 +01:00
Matthias Clasen
904d44074f gsk gl: Handle subsurfaces during rendering
During rendering, restack offloaded subsurfaces below the main
surface, and clear the area so they peek through. After rendering,
raise the last subsurface if we haven't drawn over it.
2023-11-13 22:17:36 +01:00
Matthias Clasen
c636baf6f5 gsk gl: Make it possible to clear a rectangle
Add a blend mode to the draw command, so it can draw transparent
black. This will be used to erase the area on top of a subsurface
when we do passthrough.
2023-11-13 22:17:36 +01:00
Matthias Clasen
b7c2528ad1 gsk: Prepare subsurface offload
Use a GskOffloadInfo to update subsurfaces (and collect info about
them). Pass that info to both the diff and the render vfuncs.
2023-11-13 22:17:36 +01:00
Matthias Clasen
d0a675ab01 gsk: Add subsurface nodes
Also show them in the inspector recorder, with some information.
2023-11-13 22:17:35 +01:00
Matthias Clasen
e8894ad383 gsk: Robustness fix
I was seeing empty regions being passed as scissor.
2023-11-13 22:17:35 +01:00
Matthias Clasen
b766f92026 gsk: Use some more inline helpers 2023-11-13 22:17:35 +01: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
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
Benjamin Otte
7ba4ba05e1 gl: Fix padding in icon library
The previous code would not pad the left side with the left column of
pixels but with the top row.

Test attached.
2023-10-31 00:50:00 +01:00
Matthias Clasen
06dda4e12b Merge branch 'memory-format-swizzle-check' into 'main'
gl: Check all swizzle values

See merge request GNOME/gtk!6524
2023-10-26 02:38:35 +00:00
Matthias Clasen
358779dfb2 dmabuf: No mipmaps for dmabuf textures
Calling glGenerateMipmap on imported dmabufs does not work, so
don't do it.
2023-10-24 22:03:31 -04:00
Benjamin Otte
2d874e601c Merge branch 'wip/otte/for-main' into 'main'
gl: Remove optimization that does the wrong thing

See merge request GNOME/gtk!6528
2023-10-24 02:51:02 +00:00
Benjamin Otte
dd7a38069f gl: Remove optimization that does the wrong thing
Drawing a texture-scale node like a texture node when the filter is set
to "linear" doesn't work, because the texture node switches to
trilinear when mipmaps are available.
2023-10-24 01:37:38 +02:00
Benjamin Otte
51a181af7a Merge branch 'wip/otte/for-main' into 'main'
dmabuf: Seek back to the start

See merge request GNOME/gtk!6526
2023-10-23 19:57:21 +00:00
Benjamin Otte
8fcd9bc0c4 gl: Make sure render_texture() sets the right format for high depth
Setting the format got lost when converting this coe to the texture
builder, because that codepaths avods the texture sniffing and always
uses RGBA8.
2023-10-23 21:22:17 +02:00
Matthias Clasen
677e78bdce gl: Check all swizzle values
There is no reason not check the alpha swizzle for being different
from its default value. I am thinking about implementing RGBx
upload with a swizzle of rgb1, and that would break here.
2023-10-23 07:55:39 -04:00
Matthias Clasen
4d1ef63009 gsk: Ensure dmabuf formats are initialized
We just poking at display members here, there is no guarantee that
dmabuf formats have been initialized. So do it explicitly.

This prevents a crash in the inspector when viewing a recorded frame
containing a dmabuf texture, since the inspector uses a separate
display connection.
2023-10-22 22:48:18 -04:00
Matthias Clasen
33bc276639 Merge branch 'dmabuf-texture-gl-downloader' into 'main'
dmabuf: Add an EGL downloader

See merge request GNOME/gtk!6489
2023-10-22 21:13:58 +00:00
Matthias Clasen
06822581f7 gsk: Use external textures
When we are running under GLES, we can use GL_TEXTURE_EXTERNAL_OES
to support YUV formats.

Since we don't want to deal with the combinatorial explosion of
compiling all our shaders with all combinations  of sampler2D vs
samplerExternalOES for all their textures, we copy the external
textures to a regular texture before using them.
2023-10-22 16:50:43 -04:00
Matthias Clasen
976143fbe9 gsk: Add a shader for external textures
This shader uses samplerExternalOES to sample an external texture
and blit it into a 'normal' texture. It only works in GLES, but
we won't use it outside of GLES.
2023-10-22 16:42:17 -04:00