Commit Graph

2702 Commits

Author SHA1 Message Date
Benjamin Otte
8032e30a76 gpu: Make linear gradients use variations 2024-01-07 07:22:53 +01:00
Benjamin Otte
2e81e4d452 gpu: Make box shadow shader use variations
Use it do differentiate between inset and outset shadows.
2024-01-07 07:22:53 +01:00
Benjamin Otte
d900407a18 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-07 07:22:53 +01:00
Benjamin Otte
b9651606d3 gpu: Add a cross-fade shader 2024-01-07 07:22:53 +01:00
Benjamin Otte
2a5f6fdde5 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-07 07:22:53 +01:00
Benjamin Otte
6dbbd65ef8 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-07 07:22:53 +01:00
Benjamin Otte
9947760d87 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-07 07:22:53 +01:00
Benjamin Otte
493b83ff24 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-07 07:22:53 +01:00
Benjamin Otte
b65f6eef59 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-07 07:22:53 +01:00
Benjamin Otte
f6ff0ee18c 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-07 07:22:53 +01:00
Benjamin Otte
b388c066dc 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-07 07:22:53 +01:00
Benjamin Otte
9fe011b98f 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-07 07:22:53 +01:00
Benjamin Otte
89ab3a8146 gpu: Optimize solid color fills 2024-01-07 07:22:53 +01:00
Benjamin Otte
5dcaca9b3c 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-07 07:22:53 +01:00
Benjamin Otte
69c8278558 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-07 07:22:53 +01:00
Benjamin Otte
0e9b967bf9 gpu: Add a conic gradient shader 2024-01-07 07:22:53 +01:00
Benjamin Otte
0c32a94d8e 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-07 07:22:53 +01:00
Benjamin Otte
6d20f4bc60 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-07 07:22:53 +01:00
Benjamin Otte
8361949ba1 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-07 07:22:52 +01:00
Benjamin Otte
8372bc00bd 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-07 07:22:52 +01:00
Benjamin Otte
5cf3c70db0 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-07 07:22:52 +01:00
Benjamin Otte
a031011e5e 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-07 07:22:52 +01:00
Benjamin Otte
bd901896ee 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-07 07:22:52 +01:00
Benjamin Otte
cb5c994cd9 rgba: Add a few macros
... and use them.

Those macros hopefully make code more readable.
2024-01-07 07:22:52 +01:00
Benjamin Otte
39a0e27513 gpu: Use ubershader for repeat nodes when possible 2024-01-07 07:22:52 +01:00
Benjamin Otte
832ddb31b7 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-07 07:22:52 +01:00
Benjamin Otte
8bdc7a3289 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-07 07:22:52 +01:00
Benjamin Otte
57521e6242 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-07 07:22:52 +01:00
Benjamin Otte
93d681ae77 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-07 07:22:52 +01:00
Benjamin Otte
a9b27a7de0 gpu: Implement a GdkDmabufDownloader 2024-01-07 07:22:52 +01:00
Benjamin Otte
41d80ac277 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-07 07:22:52 +01:00
Benjamin Otte
cf9b8231bd 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-07 07:22:52 +01:00
Benjamin Otte
c7a69882d3 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-07 07:22:52 +01:00
Benjamin Otte
e5cd813a24 gpu: Add debug messages
Add FALLBACK debug messages when a texture upload format is not
supported.
2024-01-07 07:22:52 +01:00
Benjamin Otte
d4c4e4bbc5 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-07 07:22:52 +01:00
Benjamin Otte
cfcc9658b2 gpu: Make VulkanRealDescriptor keep the frame
There's too much interaction between the two to warrant not having it
around.
2024-01-07 07:22:52 +01:00
Benjamin Otte
d8a0cd24d7 gpu: Add support for blend modes 2024-01-07 07:22:52 +01:00
Benjamin Otte
496ecd68f2 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-07 07:22:52 +01:00
Benjamin Otte
683878c733 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-07 07:22:52 +01:00
Benjamin Otte
38c0e2bdf6 gpu: Update the pipeline cache
When a new shader was compiled, queue a save of the pipeline cache.
2024-01-07 07:22:52 +01:00
Benjamin Otte
f0fc2709d6 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-07 07:22:52 +01:00
Benjamin Otte
1b38cbd410 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-07 07:22:52 +01:00
Georges Basile Stavracas Neto
c2ec97e922 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-07 07:22:52 +01:00
Benjamin Otte
90a278ce46 gpu: Rename some descriptors APIs
We want tosupport buffers here, too, so make the names unambiguous.
2024-01-07 07:22:52 +01:00
Benjamin Otte
2a5fe8cd0c 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-07 07:22:52 +01:00
Benjamin Otte
42d89a0ff1 gpu: Add a color matrix shader
This allows avoiding the uber shader in 2 important cases:

1. opacity - and Adwaita uses that a lot
2. color-matrix - it's used for symbolic icons
2024-01-07 07:22:52 +01:00
Benjamin Otte
9f65cdf3aa gpu: Add support for subsurfaces 2024-01-07 07:22:52 +01:00
Benjamin Otte
35bc08da5e gpu: Rework caching layer
Instead of using an enum, use a usual custom class struct like we use
for GskGpuOp.

As a side effect of that refactoring, the display gained a hash table
for textures where we can't use the render data because the texture is
used in multiple renderers.
The goal here is that a texture is always cached and we can ensure that
there is a 1:1 relation between textures and their GskGpuImage. This is
important in particular for external textures - like dmabufs - where we
absolutely don't want 2 images with 2 device memories, and where we use
toggle references to keep them alive.
2024-01-07 07:22:52 +01:00
Benjamin Otte
723c2493b2 gpu: Handle opacity in a bunch of nodes 2024-01-07 07:22:52 +01:00
Benjamin Otte
245e51099f gpu: Add optimization for opacity nodes
Track the global opacity and allow nodes to handle it themselves.

If the nodes don't, fall back to what we did previously: Use the
ubershader.
2024-01-07 07:22:52 +01:00
Benjamin Otte
a06cd6a821 gpu: Make the uber shader handle affine transforms
Fixes the last (non-blur) Nautilus offscreens in Nautilus.
2024-01-07 07:22:52 +01:00
Benjamin Otte
1c509be875 gpu: Replace clip node fallback with uber or offscreen
We don't need to use a fallback here anymore, we have enough code by now
to do this smarter.
2024-01-07 07:22:52 +01:00
Benjamin Otte
9894417a09 gpu: Split out a function
We want to use it elsewhere.
2024-01-07 07:22:52 +01:00
Benjamin Otte
51f218c877 gpu: Replace fallback with offscreen
We don't need to fallback with transform nodes when the clip is
too complex. We can redirect to an offscreen instead, which doesn't have
a clip.
2024-01-07 07:22:52 +01:00
Benjamin Otte
a8bb0a0ee1 gpu: Split out a function
I want to use it in more places.
2024-01-07 07:22:52 +01:00
Benjamin Otte
b7414dfbdd gpu: Be stricter about texture units
Reserve 3 texture units per immutable sampler (because that's the
maximum per YUV sampler).
Ensure that the max-sampler calculations always include the immutable
samplers, too.
2024-01-07 07:22:52 +01:00
Benjamin Otte
057479c284 gpu: Improve memory handling on Vulkan
We now handle the case where memory is not HOST_CACHED.

We also track the memory type now so we can avoid mapping image memory
that is not HOST_CACHED and use buffer transfers instead.
2024-01-07 07:22:52 +01:00
Benjamin Otte
c5a01cd14b gpu: Make the texture ladder handle 32 textures
So now we can put more textures in one descriptor set even if dynamic
indexing isn't supported.
2024-01-07 07:22:52 +01:00
Benjamin Otte
719ff9eca9 gpu: Require Vulkan 1.2 shaders for dynamic indexing
Shader compilers struggle with compiling code that indexes texture
arrays by indexes, so keep the fallback shaders simple and don't do that
there.

There's not much of a performance difference anyway between those two
methods.
2024-01-07 07:22:52 +01:00
Benjamin Otte
d50e235753 gpu: Add back single descriptors set usage with descriptor indexing 2024-01-07 07:22:51 +01:00
Benjamin Otte
ae2020aca2 gpu: Make descriptor-indexing optional
Do extra work if it's not available.
2024-01-07 07:22:51 +01:00
Benjamin Otte
450524f6cf gpu: Remove UPDATE_AFTER_BIND flag
We don't update after binding.
2024-01-07 07:22:51 +01:00
Benjamin Otte
be09cebb09 gpu: Handle multiple image descriptors
In the case where descriptor indexing is not enabled and the number of
max images is small (or we use extensive amounts of immutable samplers),
we need to be able to switch descriptors.

This patch makes that possible.
2024-01-07 07:22:51 +01:00
Benjamin Otte
6230ff0fc4 gpu: Cache GL state
That way we don't need to setup the textures and program for every
command.
2024-01-07 07:22:51 +01:00
Benjamin Otte
1733671295 gpu: Add a CommandState struct to the command vfuncs
This way, we can make it writable and track things like the active
textures and the current program.

We don't do that yet, but we can.
2024-01-07 07:22:51 +01:00
Benjamin Otte
78a7127b96 gpu: Handle missing support nor nonuniform texture accesses
We compile custom shaders for Vulkan 1.0 that don't require the
extension.

We  also ensure that our accesses are uniform by only executing one
shader at a time.
2024-01-07 07:22:51 +01:00
Benjamin Otte
94063cbe92 gpu: Change the meson code for how SPIR-V is built
This does the same thing, but in a way that's a bit more flexible.
And it prepares the next commit...
2024-01-07 07:22:51 +01:00
Benjamin Otte
98c88780bc gpu: Set max samplers/buffers based on features
If we run older code, we don't have enough samplers and buffers
available. So make sure to reflect that.
2024-01-07 07:22:51 +01:00
Benjamin Otte
95e36af46b gpu: Update shader code for different buffer/sampler sizes
Use specialization constants for that.
2024-01-07 07:22:51 +01:00
Benjamin Otte
47a13e601f gpu: Make PipelineLayout objects do more things
Let the objects track the number of samplers or buffers needed.

This is a required step for making Vulkan work with less featureful
(read: mobile) implementations.
2024-01-07 07:22:51 +01:00
Benjamin Otte
a301f18ebf gpu: Track position fwidth explicitly
This is relevant went encountering repeat nodes, where the repeat cutoff
will make the fwidth of the position go wild otherwise.

Gradients require more work now, because we need to compute offsets
twice - once for the pixel, once for the offst.
2024-01-07 07:22:51 +01:00
Benjamin Otte
6cbf4667a4 gpu: Add support for dmabuf import to GL 2024-01-07 07:22:51 +01:00
Benjamin Otte
ef20b706e2 gpu: Prepare GL rendering for samplerExternalEOS
Carry an n_external_textures variable around when selecting programs and
compile different programs for different amounts of external textures.

For now, this code is unused, but dmabufs will need it.
2024-01-07 07:22:51 +01:00
Benjamin Otte
979e4207f3 gpu: Add importing of GL textures to the GL renderer
syncing with the GLsync is kind of a hack (because we just do it on
import), but it works.
2024-01-07 07:22:51 +01:00
Benjamin Otte
c29237c75d gpu: Add support for texture-scale nodes
This adds GSK_GPU_IMAGE_CAN_MIPMAP and GSK_GPU_IMAGE_MIPMAP flags and
support to ensure_image() and image creation functions for creating a
mipmapped image.

Mipmaps are created using the new mipmap op that uses
glGenerateMipmap() on GL and equivalent blit ops on Vulkan.

This is then used to ensure the image is mipmapped when rendering it
with a texture-scale node.
2024-01-07 07:22:51 +01:00
Benjamin Otte
99aa5f398b gpu: Add blitting support
Add GSK_GPU_IMAGE_NO_BLIT flag for textures that can't be blitted from.

Use a blit op to do image copies otherwise.
2024-01-07 07:22:51 +01:00
Benjamin Otte
b4a1ed2a70 gpu: Add straight alpha support
Add a GSK_GPU_IMAGE_STRAIGHT_ALPHA and use it for images that have
straight alpha.
Make sure those images get passed through a premultiplying pass with
the new straight alpha shader.

Also remove the old Postprocess flags from the Vulkan image that were a
leftover from copying that code from the old Vulkan renderer.
2024-01-07 07:22:51 +01:00
Benjamin Otte
f05a8927f3 gpu: Work around Ycbcr not working with dynamically uniform indices
There's a well hidden line in the spec that says in
https://registry.khronos.org/vulkan/specs/1.3/html/chap15.html#interfaces-resources-descset

  If the combined image sampler enables sampler Y′CBCR conversion,
  it **must** be indexed only by constant integral expressions when
  aggregated into arrays in shader code, irrespective of the
  shaderSampledImageArrayDynamicIndexing feature.

So we'll use the same trick that we use for old GL here and do an
if dance that gives us dynamically uniform expressions.
2024-01-07 07:22:51 +01:00
Benjamin Otte
a2368803fa gpu: Add dmabuf import for Vulkan
This now uses all the previously added features to allow displaying YUV
images.

Also add a utility function that turns an image into a toggle ref for a
texture. This makes sure that reffing the image also refs the texture
and that ensures that textures stay alive as long as the image is in
use.
2024-01-07 07:22:51 +01:00
Benjamin Otte
32d35b1d01 gpu: Handle flags for images
For now, the flags are just there because, and nobody uses them yet.
The only flag is EXTERNAL, which for now I'm using for YUV buffers,
though it's a bit undefined what that means.
2024-01-07 07:22:51 +01:00
Benjamin Otte
528e246f1a gpu: Add a mipmap sampler
It's not used yet, but the sampler infrastructure needs to be expanded,
so I decided to split this out to easier find regressions.
2024-01-07 07:22:51 +01:00
Benjamin Otte
03f820d26c gpu: Add support for immutable samplers to Vulkan
Images can now have samplers - meaning they must be rendered with that
sampler. It also means that sampler must be handled as an immutable
sampler in descriptorsets.
These samplers can be created with a samplerYcbcrConversion, so code has
been added to pass that conversion when creating the imageview.

Also add code to GskVulkanFrame to track immutable samplers.

Nobody is making use of this yet.
2024-01-07 07:22:51 +01:00
Benjamin Otte
bf39fa3b3b gpu: Hook up immutable samplers to shaders
Define an array with a compile-time-constant variable size for the
immutable samplers.

A bunch of work is necessary to ensure that at least one element is in
the sampler array, because the GLSL code
  sampler2D immutable_textures[0];
is invalid.
2024-01-07 07:22:51 +01:00
Benjamin Otte
d2229e2aed gpu: Add GskVulkanPipelineLayout
This allows having different layouts sothat we can support immutable
samplers, whcih are required for multiplane and YUV formats.

We don't use them yet.
2024-01-07 07:22:51 +01:00
Benjamin Otte
9eac147426 gpu: Add a cache for YcbcrConversions
We index them only by VkFormat for now because we don't have another
differentiator.

It's unused so far.
2024-01-07 07:22:51 +01:00
Benjamin Otte
1b1abba313 gpu: Add an "external" allocator to Vulkan
The allocator is supposed to be used with externally allocated vkMemory
objects that are meant to be freed normally - in particular dmabufs.
2024-01-07 07:22:51 +01:00
Benjamin Otte
223d1343de gpu: Add GdkDisplay::vulkan_features
use it to collect the optional features we are interested in and turn
them on only if available.

For now we add the dmabuf features, but we don't use them yet.
2024-01-07 07:22:51 +01:00
Benjamin Otte
f0f6af1cf8 gpu: Create Vulkan samplers on-demand 2024-01-07 07:22:51 +01:00
Benjamin Otte
82eed5d672 gpu: Make Vulkan image formats check use newer functions
This is just an update of all vkGetFoo() calls to use vkGetFoo2().
2024-01-07 07:22:51 +01:00
Benjamin Otte
38f64c2357 gpu: Move caching to the upload_texture() function
So when uploading a texture, we will automatically put it into the cache
now.
2024-01-07 07:22:51 +01:00
Benjamin Otte
daadaf8448 gpu: Factor out uploading textures into a vfunc
This way GL and Vulkan can run custom code to import GL textures and
dmabufs.

This function also decides if and how to cache the textures it creates.
2024-01-07 07:22:51 +01:00
Benjamin Otte
e86fa6a072 gpu: Apply clip to ubershader bounds
Fixes excessive bounds when using the ubershader for huge nodes
contained inside clip nodes.
2024-01-07 07:22:51 +01:00
Benjamin Otte
1b3eb3ecd1 gpu: Fail to create images that are too big
It's up to the renderers to handle the NULL return value.
2024-01-07 07:22:51 +01:00
Benjamin Otte
94539e6f08 gpu: Allow texture uploads to fail
The main reason here is that we want to not fail when the texture size
is larger than the supported GpuImage size.

When that happens, for now we just fallback slowly - ulitmately to
drawing with Cairo, which is going to be clipped.
2024-01-07 07:22:51 +01:00
Benjamin Otte
f5af3fe933 gpu: Add render_texture() fallback impl for huge sizes
This copies over the GLRenderer approach of step-by-step filling a
memorytexture.

It just adds some extra niceties by respecting the best format.
2024-01-07 07:22:51 +01:00
Benjamin Otte
bbad290518 gpu: Add gsk_gpu_device_get_max_image_size()
... and initialize it properly.
2024-01-07 07:22:51 +01:00
Benjamin Otte
334e380d31 gpu: Handle overlapping rounded rect corners
Have a fallback in place for the most egregious abuses of rounded
corners, like
  0 0 50 50 / 50 0
and the like.

Fixes obscure border colors.
2024-01-07 07:22:51 +01:00
Benjamin Otte
d8db673fb7 gpu: Add a box shadow shader
Code was inspired mainly by
  https://madebyevan.com/shaders/fast-rounded-rectangle-shadows/
and
  https://pcwalton.github.io/_posts/2015-12-21-drawing-css-box-shadows-in-webrender.html

So far the results aren't cached, that's the task of future commits.
2024-01-07 07:22:51 +01:00
Benjamin Otte
268ad54c6a gpu: Add a rounded color shader
There's multiple uses I want it for:

1. Generating the box-shadow area for blurring
2. Generating masks for rounded-rect masking
3. Optimizing the common use case of rounded-clip + color

Only the last one is implemented in this commit.
2024-01-07 07:22:50 +01:00
Benjamin Otte
64a67ac3a8 gpu: Turn globals into macros
This way, we can be more flexible in refactoring how we handle globals
(guess what we're gonna do next).
2024-01-07 07:22:50 +01:00
Benjamin Otte
74ac95dc32 gpu: Don't try to be smart
Don't try to use all those fancy GL features like glMapBuffer() and
such. Just malloc() some buffer memory and glBufferSubData() it later.

That works everywhere and is faster than (almost?) any combination of
fancy new buffer APIs. And yes I'm frustrated because I played with
those flags and none of them were better than this.

Doubles the framerate on my discrete AMD GPU.
2024-01-07 07:22:50 +01:00
Benjamin Otte
7f817fce0a gpu: Use GL_STREAM_DRAW for the push constants buffer
This seems to hit a bunch of optimizations and makes push constants
slightly faster.
2024-01-07 07:22:50 +01:00
Benjamin Otte
5549a7ab5f gpu: Merge ops on GL, too
Just like on Vulkan, try to minimize the glDrawArrays() calls by merging
adjacent ops.
2024-01-07 07:22:50 +01:00
Benjamin Otte
53821da4d6 gpu: Refactor image handling
Introduce a new GskGpuImageDescriptors object that tracks descriptors
for a set of images that can be managed by the GPU.
Then have each GskGpuShaderOp just reference the descriptors object they are
using, so that the coe can set things up properly.

To reference an image, the ops now just reference their descriptor -
which is the uint32 we've been sending to the shaders since forever.
2024-01-07 07:22:50 +01:00
Benjamin Otte
f518d780ed gpu: Add atlas support
... and use it for glyphs.
2024-01-07 07:22:50 +01:00
Benjamin Otte
9045431bde gpu: Add a GL optimization
Use glDrawArraysInstancedBaseInstance() to draw. (Yay for GL naming.)
That allows setting up the offset in the vertex array without having to
glVertexAttribPointer() everything again.

However, this is only supported since GL 4.2 and not at all in stock GLES,
so we need to have code that can work without it.
Fortunately, it is mandatory in Vulkan, so every recent GPU supports it.
And if that GPU has a proper driver, it will also expose the GL extension
for it.
(Hint: You can check https://opengles.gpuinfo.org/listextensions.php for
how many proper drivers exist outside of Mesa.)
2024-01-07 07:22:50 +01:00
Benjamin Otte
8271687ef6 gpu: Make border shader usable for inset/outset
... and use it for those when unblurred.
2024-01-07 07:22:50 +01:00
Benjamin Otte
8043d4d6e0 gpu: Add GSK_GPU_SKIP=merge
Disables merging of ops for vkCmdDraw().
2024-01-07 07:22:50 +01:00
Benjamin Otte
e7a59d92ac gpu: Add GSK_GPU_SKIP env var
The env var allows skipping various optimizations in the GPU shader.

This is useful for testing during development when trying to figure
out how to make a renderer as fast as possible.

We could also use it to enable/disable optimizations depending on GL
version or so, but I didn't think about that too much yet.
2024-01-07 07:22:50 +01:00
Benjamin Otte
e3bac4063c gpu: Copy the clear trick from the Vulkan shader
When drawing opaque color regions that are large enough, use
vkCmdClearAttachments()/glClear() instead of a shader. This speeds up
background rendering on particular on older GPUs.

See the commit messages of
  bb2cd7225e
  ce042f7ba1
  0edd7547c1
for a further discussion of performance impacts.
2024-01-07 07:22:50 +01:00
Benjamin Otte
48012a1ce4 gpu: Add a color shader
We don't want to use the pattern shader for simple colors, slow GPUs do
not like this at all.
2024-01-07 07:22:50 +01:00
Benjamin Otte
63f6e75b38 gpu: Implement blur nodes
With the work already done with shadow nodes, this one was easy.
2024-01-07 07:22:50 +01:00
Benjamin Otte
23c1ec07e7 gpu: Implement shadow nodes 2024-01-07 07:22:50 +01:00
Benjamin Otte
7431a58617 gpu: Change sorting for ops
The previous algorithm would reverse the order of subpasses, whcih leads
to unexpected behavior if dependent subpasses are not added as children
of a subpass, but just as a previous subpass - like when a subpass is
used multiple times later.

An example for this is a shadow node with multiple shadows - the source
of the shadow is used by the multiple shadows.

So ensure that adjacent subpasses stay in the same order.
2024-01-07 07:22:50 +01:00
Benjamin Otte
30e9d98f0d gpu: Add a "transparent" sampler
This is using the equivalent of EXTEND_NONE, but I wasn't sure what to
call it.

It's unused atm.
2024-01-07 07:22:50 +01:00
Benjamin Otte
43d0b0fb3c gpu: Turn off optimizing in glslc
The code generated by glslc -O is optimized worse by Mesa than
code generated unoptimized.

So generate unoptimized code until somebody figures out what's going
wrong here.
2024-01-07 07:22:50 +01:00
Benjamin Otte
d47c8613b0 gpu: Add support for mask patterns 2024-01-07 07:22:50 +01:00
Benjamin Otte
e01311a565 gpu: Add support for cross-fades 2024-01-07 07:22:50 +01:00
Benjamin Otte
0876089f8f gpu: Add repeat nodes
They're done using the pattern shader.

The pattern shader now gained a stack where vec4's can be pushed and
popped back later, which allows storing the position before computing
the new position inside the repeat node's child.
2024-01-07 07:22:50 +01:00
Benjamin Otte
b7a8c2207e gpu: Introduce gsk_texture() shader function/macro
Due to GLES and old GL not allowing non-constant texture array
lookups,we need to turn the array lookup into a big switch statementin
those versions, and that requires putting the texture() call into that
switch.

But with that trick, we can use texture IDs in GLSL.
2024-01-07 07:22:50 +01:00
Benjamin Otte
5ab8fde0bc gpu: Add colorize shader
... and use it for glyphs.

The name is a slight variation of the "coloring" name from the GL
renderer.
The functionality is exactly what the "glyph" shader from the Vulkan
renderer does.
2024-01-07 07:22:50 +01:00
Benjamin Otte
d1d1af1a62 gpu: Improve conic gradient rendering
1. Compute the fwidth() twice with offset offsets
   That way, we avoid glitches at the boundary between 0.0 and 1.0,
   because by offsetting it by 0.5, that boundary goes away.
   Then we take the min() of both which gives us the one we care about.

2. Set the gradient to repeating
   By doing that, we don't get values at the 0.0/1.0 boundary clamped,
   but things smoothly transition.
   This smoothes the line at that boundary and makes it look just like
   every other line.
2024-01-07 07:22:50 +01:00
Benjamin Otte
88618952c5 gpu: Round offscreens to pixel boundaries
Instead of strictly rounding to the given clip rectangle, increase the
rectangle to the next pixel boundary.

Also add docs that the clip_bounds do not influence the actual size of
the returned image.
2024-01-07 07:22:50 +01:00
Benjamin Otte
92d1df94fa gpu: Add GskGpuPatternWriter
It's just an object that encapsulates everything needed to create (the
data for) a pattern op.

It also clarifies which code does what, because now the NodeProcessor
and the PatternWriter are 2 different things.
2024-01-07 07:22:50 +01:00
Benjamin Otte
187db92a88 gpu: Make shader image access a vfunc
That allows shaders to handle textures differently.

In particularly, it will allow the pattern shader to take a huge amount
of textures.
2024-01-07 07:22:50 +01:00
Benjamin Otte
a9b8551e70 gpu: Add clip pattern
So now we can clip inside an opacity node without needing fallback.
2024-01-07 07:22:50 +01:00
Benjamin Otte
0cac75aff1 gpu: Passthrough subsurface nodes
We don't support subsurfaces for now, so we can just ignore the nodes.
2024-01-07 07:22:50 +01:00
Benjamin Otte
6cf3f6ebff gpu: Add support for debug nodes
Passthrough is always easy.
2024-01-07 07:22:50 +01:00
Benjamin Otte
3efe1bef93 gpu: Add a border shader
Pretty much a copy of the Vulkan border shader.

A notable change is that the input arguments are changed, because GL
gets confused if you put a mat4 at the end.
2024-01-07 07:22:50 +01:00
Benjamin Otte
16c804c5e3 gpu: Handle nested buffer writes
when doing get_node_as_image(), that may spawn a new buffer writer that
writes into the samme buffer when rendering an offscreen with patterns.

So as a more or less hacky workaround, we now abort the current buffer
write and restart it once we've created the image.
2024-01-07 07:22:50 +01:00
Benjamin Otte
28f4666366 gpu: Implement conic gradients 2024-01-07 07:22:50 +01:00
Benjamin Otte
72a5927d38 gpu: Add radial gradients 2024-01-07 07:22:50 +01:00
Benjamin Otte
7473617ffb gpu: Add linear gradients to pattern shader
This copy/pastes the gist of the Vulkan gradient renderer.
2024-01-07 07:22:50 +01:00
Benjamin Otte
7d43e4e56a gpu: Add glyphs support
This is very rudimentary, but it's a step in the direction of getting
text going.

There's lots of things missing still.
2024-01-07 07:22:50 +01:00
Benjamin Otte
8fd2a267ae gpu: Add a utility function for colors in patterns
... and use it.
2024-01-07 07:22:50 +01:00
Benjamin Otte
3809e6efb9 gpu: Add color-matrix handling to pattern shader 2024-01-07 07:22:50 +01:00
Benjamin Otte
9224efd95e gpu: Make pattern creation always succeed
If creation fails, create an offscreen image instead and draw that as a
texture.

Because offscreens basically always succeed, we can pretty much assume
success everywhere - apart from pattern creation functions that also
create images, because they can run out of shader space.
2024-01-07 07:22:50 +01:00
Benjamin Otte
4cbd384e39 gpu: Have a get_node_as_pattern() function
... and use it to replace all the individual parts of code that get the
node as a pattern.
2024-01-07 07:22:50 +01:00
Benjamin Otte
12010a597b gpu: Add a texture pattern
Needs a lot of infrastructure for handling images, but we're handling
images now.
2024-01-07 07:22:50 +01:00
Benjamin Otte
720ac700b3 gpu: Move the pattern code into the nodeprocessor
We need the nodeprocessor infrastructure to create patterns, so keeping
it in a different source file would just cause header headaches.
2024-01-07 07:22:50 +01:00
Benjamin Otte
373a6ab9f1 gpu: Add a texture cache
... and use it when drawing textures.

We'll need it in other places later, but for now that's what we have.
2024-01-07 07:22:50 +01:00
Benjamin Otte
57c1c95e75 gpu: Make frames carry a timestamp
Frames now carry a timestamp for when they are used.

This is mainly intended to attach timestamps to cached items (textures
or glyphs), but it could in theory also be used when profiling.

We use wallclock time here, not server time, because it's cheaper and
because we're more intereseted in the local machine we're rendering on.
2024-01-07 07:22:50 +01:00
Benjamin Otte
ffc117564b gpu: Make patterns do opacity nodes
Of course, for now this only works for opacity nodes that contain color
nodes, but we're still building up to ore useful stuff here.
2024-01-07 07:22:50 +01:00
Benjamin Otte
ee3367697d gpu: Move pattern code into its own file
Now we can extend the pattern creation easily - and we can add new
patterns quickly later.

Plus, we need to keep this file in sync with pattern.glsl and it's neat
when those 2 files reference only each other.
2024-01-07 07:22:50 +01:00
Benjamin Otte
c6e19f0384 gpu: Add float array to shaders and add an ubershader
... and use it for a naive color node implementation using both
so I can test it actually works.
2024-01-07 07:22:50 +01:00
Benjamin Otte
9df265acdc gpu: Clip fallback nodes to current clip
Avoids uploading parts of the node that aren't visible.
2024-01-07 07:22:49 +01:00
Benjamin Otte
461d9b4052 gpu: Set scissor rect before clearing
The render area that restricts clearing on Vulkan needs to be respected
by the GL renderer, too.
2024-01-07 07:22:49 +01:00
Benjamin Otte
0ed45c5f40 gpu: Move global syncing out
This is necessary so that fallback code can properly sync itself,
instead of just add_node().

Fixes a bunch of glitches when fallbacks would be used.
2024-01-07 07:22:49 +01:00
Benjamin Otte
73ac2d0a1c gpu: Add a flip_y argument to shader execution
Because GL flips its shit sometimes (ie when it's the framebuffer),
pass the height of the target as the flip variable, so commands
that need to operate on the pixels can flip the y axis around this value.
2024-01-07 07:22:49 +01:00
Benjamin Otte
57ab670991 gpu: Add handling for (rounded) clip node(s)
This is again mostly a copy of the Vulkan renderer.

It's a bit awkward codewise with the new invalidation framework,
because we need to cache the previous values individually now,
but it's a lot more finegrained, and we don't emit globals multiple
times when clips are nested.
2024-01-07 07:22:49 +01:00