Commit Graph

78680 Commits

Author SHA1 Message Date
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
Benjamin Otte
8bb3cca512 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-04 14:54:22 +01:00
Benjamin Otte
6dc9736b37 gpu: Add support for subsurfaces 2024-01-04 14:54:22 +01:00
Benjamin Otte
cd054a6e6d 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-04 14:54:22 +01:00
Benjamin Otte
2e11cf754c gpu: Handle opacity in a bunch of nodes 2024-01-04 14:54:22 +01:00
Benjamin Otte
880aaab037 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-04 14:54:22 +01:00
Benjamin Otte
a295d59db8 gpu: Make the uber shader handle affine transforms
Fixes the last (non-blur) Nautilus offscreens in Nautilus.
2024-01-04 14:54:22 +01:00
Benjamin Otte
13e6ecb330 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-04 14:54:22 +01:00
Benjamin Otte
88c25199ce gpu: Split out a function
We want to use it elsewhere.
2024-01-04 14:54:22 +01:00
Benjamin Otte
743dfc276a 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-04 14:54:21 +01:00
Benjamin Otte
134d809a7d gpu: Split out a function
I want to use it in more places.
2024-01-04 14:54:21 +01:00
Benjamin Otte
3936e7ee7d 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-04 14:54:21 +01:00
Benjamin Otte
a5c7339920 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-04 14:54:21 +01:00
Benjamin Otte
e8fb0e71c9 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-04 14:54:21 +01:00
Benjamin Otte
9d0b15273d 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-04 14:54:21 +01:00
Benjamin Otte
168be35bed gpu: Add back single descriptors set usage with descriptor indexing 2024-01-04 14:54:21 +01:00
Benjamin Otte
9777188ae4 gpu: Make descriptor-indexing optional
Do extra work if it's not available.
2024-01-04 14:54:21 +01:00
Benjamin Otte
21f52cacf9 gpu: Remove UPDATE_AFTER_BIND flag
We don't update after binding.
2024-01-04 14:54:21 +01:00
Benjamin Otte
5ed293e3df 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-04 14:54:21 +01:00
Benjamin Otte
c51c3b2660 gpu: Cache GL state
That way we don't need to setup the textures and program for every
command.
2024-01-04 14:54:20 +01:00
Benjamin Otte
5dc455f011 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-04 14:54:20 +01:00
Benjamin Otte
fbd972498f 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-04 14:54:20 +01:00
Benjamin Otte
b87d82de7e 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-04 14:54:20 +01:00
Benjamin Otte
c165b9d47c gpu: Add GDK_VULKAN_SKIP env var
The variable forces skipping of optional Vulkan features. This is useful
for testing.

Also debug-print the features in use.
2024-01-04 14:54:20 +01:00
Benjamin Otte
37d4e29c44 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-04 14:54:20 +01:00
Benjamin Otte
1923cad9f7 gpu: Add Vulkan feature flags for more advanced features
Code continues if those features aren't available, buit is probably
broken.
2024-01-04 14:54:20 +01:00
Benjamin Otte
9349ba8330 gpu: Update shader code for different buffer/sampler sizes
Use specialization constants for that.
2024-01-04 14:54:20 +01:00
Benjamin Otte
0c72233a9d 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-04 14:54:20 +01:00
Benjamin Otte
9733b8d4e1 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-04 14:54:20 +01:00
Benjamin Otte
4d9ff5e46a gpu: Add support for dmabuf import to GL 2024-01-04 14:54:19 +01:00
Benjamin Otte
9cf776d02e 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-04 14:54:19 +01:00
Benjamin Otte
55dbbabd0c 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-04 14:54:19 +01:00
Benjamin Otte
46baaa9337 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-04 14:54:19 +01:00
Benjamin Otte
697f2b8e95 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-04 14:54:19 +01:00
Benjamin Otte
9af809a7ff testsuite: Add a test to check scaling behavior
Various GL texture formats do not support linear scaling or mipmap
generation.

Add a test that checks this.
2024-01-04 14:54:19 +01:00
Benjamin Otte
2e25936383 testsuite: Update memorytexture text to use new renderers
1. Refactor checks for GL support

2. Add NGL and Vulkan
2024-01-04 01:36:13 +01:00
Benjamin Otte
7652dbcacf 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-04 01:36:13 +01:00
Benjamin Otte
8df8e1283f 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-04 01:36:13 +01:00
Benjamin Otte
2199822d5f 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-04 01:36:13 +01:00