Commit Graph

78718 Commits

Author SHA1 Message Date
Benjamin Otte
7a6377d1ff gpu: Use variations for radial gradients 2024-01-04 14:54:27 +01:00
Benjamin Otte
4100436c50 gpu: Use variations for the mask mode 2024-01-04 14:54:27 +01:00
Benjamin Otte
2ce60f1260 gpu: Make linear gradients use variations 2024-01-04 14:54:27 +01:00
Benjamin Otte
88e5b6ba8d gpu: Make box shadow shader use variations
Use it do differentiate between inset and outset shadows.
2024-01-04 14:54:27 +01:00
Benjamin Otte
0268248d9e gpu: Introduce the concept of "variation"
A variation is a #define/specialization constant that every shader can
use to specialize itself as it sees fit.

This commit adds the infrastrcture, future commits will add
implementations.
2024-01-04 14:54:27 +01:00
Benjamin Otte
3976f88fed png: Don't set a size limit when saving
gdk_texture_save_to_png_bytes() cannot fail, so ensure that it doesn't.

Testsuite has been updated to check for this case.

Note that we do not load the PNG file that we generate here.
Loading is a lot more scary than saving after all.
If people want to load oversized PNG files, they should use a real PNG
loader.
2024-01-04 14:54:27 +01:00
Benjamin Otte
5bf21e264e gpu: Add a cross-fade shader 2024-01-04 14:54:27 +01:00
Benjamin Otte
407d08ff0d gpu: Handle a clipping cornercase properly
If we enter the situation where we need to redirect the clipping to an
offscreen, make sure that:

* the ubershader gets only used when beneficial

* we size the offscreen properly and don't let it grow infinitely.

Fixes the clip-intersection-fail-opacity test
2024-01-04 14:54:27 +01:00
Benjamin Otte
2cb7433065 gpu: Handle opacity in the Cairo path
Fixes random calls to add_fallback_node() from code that wants to handle
opacity.

Also makes Cairo nodes work with opacity, of course.
2024-01-04 14:54:27 +01:00
Benjamin Otte
d08e5f7d82 gpu: Handle alpha in image_op() wrapper
There are various places where the alpha is implicitly assumed to be
handled, so just handle it.

As a bonus, this simplifies a bunch of code and makes the texture node
rendering work with alpha.
2024-01-04 14:54:27 +01:00
Benjamin Otte
a21fcd9ca6 gpu: Optimize box-shadow shader
Like in the border shader, don't draw the (potentially large for the
window's shadow) inside part that is transparent.
2024-01-04 14:54:26 +01:00
Benjamin Otte
f8b0c95894 gpu: Replace a fallback with offscreens
Use an offscreen and mask it if the clips get too complicated.

Technically, the code could be improved to set the rounded clip on the
offscreen instead of rendering it as a mask, but that would require more
sophisticated tracking of clip regions by respecting the scissor, and
the current clip handling can't do that yet.

This removes one of the last places where the GPU renderer was still
using Cairo fallbacks.
2024-01-04 14:54:26 +01:00
Benjamin Otte
c46ab19f76 gpu: Add gsk_gpu_node_processor_add_images()
This is for generating descriptors for more than 1 image. The arguments
for this function are very awkward, but I couldn't come up with better
ones and the function isn't that important.

And the calling places still look a lot nicer now.
2024-01-04 14:54:26 +01:00
Benjamin Otte
11232b2611 gpu: Add gsk_gpu_node_processor_init_draw/finish_draw()
These initialize/finish an offscreen and start drawing to it.

It simplifies the process of using offscreens quite a bit that way.
2024-01-04 14:54:26 +01:00
Benjamin Otte
caa898103f gpu: Add stroke support
Same as for fill nodes, we render the stroke to a mask and then run a
mask shader.

The color node child optimization is included already.
2024-01-04 14:54:26 +01:00
Benjamin Otte
2692cb9a6e gpu: Optimize solid color fills 2024-01-04 14:54:26 +01:00
Benjamin Otte
9ba8c95b8b gpu: Add fill node support
For now this uses Cairo to generate a mask and then runs a mask op.

This is different from just using fallback in that the child is rendered
with the GPU and not via fallback.
2024-01-04 14:54:26 +01:00
Benjamin Otte
58953432d3 gpu: Add a radial gradient shader
This is mainly copy/paste, so now this almost identical gradient code
exists 3 times.
That's kinda suboptimal.
2024-01-04 14:54:26 +01:00
Benjamin Otte
ac6d854a3a gpu: Add a conic gradient shader 2024-01-04 14:54:26 +01:00
Benjamin Otte
89b65ec9b9 gpu: Split linear gradient shader into 2 parts
A generic part that can be shared by all gradient shaders that does the
color stop handling and a gradient-specific part that needs to be
implemented individually by each gradient implementation.
2024-01-04 14:54:25 +01:00
Benjamin Otte
0ed32f4d2d gpu: Change the cairo upload op prototype
Make it take a draw function instead of a node.

This way, we can draw more fancy stuff with Cairo.
2024-01-04 14:54:25 +01:00
Benjamin Otte
6cabaad562 gpu: Handle >7 color stops
If there are more than 7 color stops, we can split the gradient into
multiple gradients with color stops like so:
  0, 1, 2, 3, 4, 5, transparent
  transparent, 6, 7, 8, 9, 10, transparent
  ...
  transparent, n-2, n-1, n
and use the new BLEND_ADD to draw them on top of each other.

Adapt the testcae that tests this to use colors that work with the fancy
algorithm we use now, so that BLEND_ADD and transitions to transparent
do not cause issues.
2024-01-04 14:54:25 +01:00
Benjamin Otte
801225c3d3 gpu: Make the ubershader use the correct coordinates
Instead of scaled coordinates, use the unscaled ones.

This ensure that gradients get computed correctly as they are not safe
against nonorthogonal transforms - like scales with different scale
factors.
2024-01-04 14:54:25 +01:00
Benjamin Otte
66b783cc7e gpu: Make blend modes configurable
For now, we only have OVER and ADD blend modes. This commit doesn't use
ADD, it just sets up all the machinery and refactors things.
2024-01-04 14:54:25 +01:00
Benjamin Otte
136d3d9439 gpu: Add a linear-gradient shader
The shader can only deal with up to 7 color stops - but that's good
enough for the real world.

Plus, we have the uber shader.

And if that fails, we can still fall back to Cairo.

The code also doesn't handle repeating linear gradients yet.
2024-01-04 14:54:25 +01:00
Benjamin Otte
ec5aa5e736 gpu: Add a mask shader
This shader can take over from the ubershader. And it can be used
instead of launching the ubershader when no offscreens are necessary.

Also includes an optimization that uses the colorize shader when
appropriate.
2024-01-04 14:54:25 +01:00
Benjamin Otte
f862f66e4a rgba: Add a few macros
... and use them.

Those macros hopefully make code more readable.
2024-01-04 14:54:25 +01:00
Benjamin Otte
73143dc7ab gpu: Use ubershader for repeat nodes when possible 2024-01-04 14:54:25 +01:00
Benjamin Otte
ee54f5a50a gpu: Add a repeat node renderer
The ubershader has some corner cases where it can't be used, in
particular when the child is massively larger than the repeat node and
the repeat node is used to clip lots of the source.
2024-01-04 14:54:25 +01:00
Benjamin Otte
db93fd6b7b renderer: Add Vulkan renderer to the list of renderers
It's better than the Cairo renderer, so use it instead.

It's still only picked once GL fails, so it will probably only ever be
picked when people use GDK_DEBUG=gl-disable, but at least it will be
picked.
2024-01-04 14:54:24 +01:00
Benjamin Otte
fb6ee45064 renderer: Split function
per-backend renderers and GL renderers are a different thing, so treat
them as such.

Also, try the GL renderer unconditionally. The renderer initialization
code will take care of GL not being available.
2024-01-04 14:54:24 +01:00
Benjamin Otte
f6f43cd374 vulkan: Add a Vulkan downloader
This is using the Vulkan renderer.

It also allows claiming support for all the formats that only Vulkan
supports, but that neither GL nor native mmap can handle.
2024-01-04 14:54:24 +01:00
Benjamin Otte
0473a429ac gpu: Implement a GdkDmabufDownloader 2024-01-04 14:54:24 +01:00
Benjamin Otte
d225f40acd gpu: Add a boolean flag allow_dmabuf to the downloadop
It can be set to force the downloadop to not create dmabuf textures.
2024-01-04 14:54:24 +01:00
Benjamin Otte
2bcee1e69e gpu: Update to memoryformat Vulkan code
The existing code for setting up formats was copied from the old Vulkan
renderer and never updated.
2024-01-04 14:54:24 +01:00
Benjamin Otte
9a81ed9ab1 testsuite: Add new renderers to the scaling test 2024-01-04 14:54:24 +01:00
Benjamin Otte
fb9c4c15be gpu: Reorganize format handling
Add GSK_GPU_IMAGE_RENDERABLE and GSK_GPU_IMAGE_FILTERABLE and make sure
to check formats for this feature.

This requires reorganizing code to actually do this work instead of just
pretending formats are supported.

This fixes GLES upload tests with NGL.
2024-01-04 14:54:24 +01:00
Benjamin Otte
f2ac427035 gpu: Add debug messages
Add FALLBACK debug messages when a texture upload format is not
supported.
2024-01-04 14:54:24 +01:00
Benjamin Otte
95d7c7de3a vulkan: Use vulkan feature flags for incremental present
I did it because it unifies the code.

But it also gains the benefit of being debuggable because it can
now be turned off via GDK_VULKAN_SKIP=incremental-present
2024-01-04 14:54:24 +01:00
Benjamin Otte
80a2cbb447 gpu: sync dmabufs via semaphores
This ensures both that we signal a semaphore for a dmabuf when we export
an image and that we import semaphores for dmabufs and wait on them.

Fixes Vulkan node-editor displaying the Vulkan renderer in the sidebar.
2024-01-04 14:54:23 +01:00
Benjamin Otte
14a1c53358 gpu: Make VulkanRealDescriptor keep the frame
There's too much interaction between the two to warrant not having it
around.
2024-01-04 14:54:23 +01:00
Benjamin Otte
fcb8e920c8 gpu: Add support for blend modes 2024-01-04 14:54:23 +01:00
Benjamin Otte
8003d875ee gpu: Make Vulkan renderer provide dmabuf textures
Make gsk_renderer_render_texture() create a dmabuf texture if that is
possible.

If it isn't (ie if we're not on Linux or if dmabufs are otherwise not
working) fall back to the previous code of creating a memory texture.
2024-01-04 14:54:23 +01:00
Benjamin Otte
ce08750906 gpu: Add gsk_gpu_device_create_download_image()
This way, we can differentiate between regular offscreens and images
that are meant to be used for gsk_renderer_render_texture() or similar.
2024-01-04 14:54:23 +01:00
Benjamin Otte
15c72b32bd gpu: Update the pipeline cache
When a new shader was compiled, queue a save of the pipeline cache.
2024-01-04 14:54:23 +01:00
Benjamin Otte
21841872f4 gpu: Implement support for multiple storage buffers
When using the uber shader a lot, we may overflow the (only 16kB large)
storage buffer.

Stop crashing when that happens and instead just allocate a new one.
2024-01-04 14:54:23 +01:00
Benjamin Otte
9ef440a577 gpu: Handle storage buffers via descriptors
This makes the (currently single) storage buffer handled by
GskGpuDescriptors.
A side effect is that we now have support for multiple buffers in place.
We just have to use it.

Mixed into this commit is a complete rework of the pattern writer.
Instead of writing straight into the buffer (complete with repeatedly
backtracking when we have to do offscreens), write into a temporary
buffer and copy into the storage buffer on committing.
2024-01-04 14:54:23 +01:00
Georges Basile Stavracas Neto
83b922f2ee gpu/renderer: Improve scale detection
The GL branch should eventually call into gdk_gl_context_get_scale(),
which is what checks for GDK_DEBUG=gl-fractional; whereas the Vulkan
branch needs no change.
2024-01-04 14:54:23 +01:00
Benjamin Otte
a6bcc2208a gpu: Rename some descriptors APIs
We want tosupport buffers here, too, so make the names unambiguous.
2024-01-04 14:54:22 +01:00
Benjamin Otte
f7f61fadb3 gpu: Only run uber shaders if beneficial
If we have the choice between running the ubershader or a normal shader
with offscreens, make the choice depend on if the ubershader would
offscreen anyway.
If so, just run the normal shader.

This really gets rid of all ubershader invocations in Adwaita
widget-factory.
2024-01-04 14:54:22 +01:00