Commit Graph

3148 Commits

Author SHA1 Message Date
Benjamin Otte
39f5c5bf49 gpu: Implement tiling for texture nodes
Use the new cache feature to split oversized textures into tiles the
size given by the new device API.

Then number those tiles from left to right and top to bottom and use
that number as the tile id.
2024-07-12 17:31:36 +02:00
Benjamin Otte
392f6855ca gpu: Add gsk_gpu_device_get_tile_size()
This allows managing tiling of images. And I'd like this value to live
somewhere prominent instead of as a hardcoded number in the
nodeprocessor.
2024-07-12 17:31:36 +02:00
Benjamin Otte
1cae48ab93 gpu: Add a tile cache
Nobody is using it yet, but it's the API.

It's very simple and just allows adding tiles by an index. What that
index means is up to the caller.
2024-07-12 17:31:36 +02:00
Benjamin Otte
d0f8ef09a0 gpu: Do a GC run after every tile of large images
When we draw large images, we absolutely do not want to keep memory that
we do not need. So do a GC run after every tile. That otentially slows
down things, but it also improves the chances of not running out of
memory.

Here's the node for the image I managed to create after I applied this
patch:

repeat {
  bounds: 0 0 50000 50000;
  child: text {
    font: "Noto Color Emoji 10000px";
    glyphs: 661 0 0 0 color;
    offset: 0 10000;
    hint-style: none;
  }
}
2024-07-12 16:57:23 +02:00
Benjamin Otte
0516dca116 vulkan: Don't try to use nonexisting formats
Handle the error that new rgba format exists.
2024-07-12 16:56:23 +02:00
Benjamin Otte
ebc6a043c9 gpu: Cleanups 2024-07-12 16:56:23 +02:00
Benjamin Otte
8e2ae79875 gpu: Change function to (transfer full)
Functions should behave as I expect, and I just spent an hour debugging
a refcount issue because I assumed our image creation functions return
refrences. Which is a very sane assumption.
2024-07-12 16:55:59 +02:00
Benjamin Otte
27ac764653 gpu: Don't multiply by 1/x, divide by x
This is less error-prone with floating point math, even though it is
somewhat slower.
2024-07-12 16:55:59 +02:00
Benjamin Otte
e40ad5faa5 gpu: Cache textures when doing copies
The texture and texture-scale node code is creating image copies
for mipmaps and to adapt to the compositing colorstate.

Those texture should be cached.
2024-07-11 14:57:20 +02:00
Benjamin Otte
dd393a4a0e gpu: Split out texture lookup function
It's unused in 3 function and has become somewhat unwieldy.
2024-07-11 14:57:20 +02:00
Benjamin Otte
881954dfca gpu: Rework texture caching
We want to cache textures in the compositing color state, not in their
original color state. However, the compositing color state may change
(think multimonitor setups).

So we additionally keep a cache per colorstate.

That means texture lookup is now a 3-step process:

1. Look up in the compositing colorstate's cache

2. Look up in the general cache

3. Upload
2024-07-11 14:57:20 +02:00
Benjamin Otte
cf12503fec gpu: Don't replace cache items
Instead, keep them. This is not useful yet, but will become so in the
next commits.
2024-07-11 14:57:20 +02:00
Benjamin Otte
ad757cccb6 Don't use GL_SRGB for premultiplied textures
GL_SRGB is doing postmultiplied alpha, so if the texture is
premultiplied, we can't use this optimization.

The optimization still works for unpremultiplied and opaque images,
because those don't do that step.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b801eae00f gpu: All ops obey the ccs now
Remove the macro used for the not-yet converted ops.
2024-07-11 14:57:20 +02:00
Benjamin Otte
2fe9ff7918 gpu: Make mask op obey ccs
No colorstate conversions allowed here, though technically we could use
the alternate color state for the source most of the time, as the mask's
colorstate is only relevant for luminance.
2024-07-11 14:57:20 +02:00
Benjamin Otte
c407582096 gpu: Make blur op obey ccs
Blend ops don't do colorspace conversion, so this commit just hardcodes
that and rewrites the shader to use recent APIs.
2024-07-11 14:57:20 +02:00
Benjamin Otte
0fc3dbaa9b gpu: Make texture op obey ccs
Well, texture ops actually don't do any colorspace stuff, but let's
explicitly hardcode that.
2024-07-11 14:57:20 +02:00
Benjamin Otte
77ed264714 gpu: Introduce gsk_gpu_color_states_create_equal()
This is a function that's meant to be used whenever both color states
of the shader are equal. In that case no colorspace conversion code
needs to be created and shaders can be shared.
2024-07-11 14:57:20 +02:00
Benjamin Otte
a14efce914 gpu: Make blur op obey ccs 2024-07-11 14:57:20 +02:00
Benjamin Otte
08f90a188c gl: Force U8 textures for U8_SRGB depths
The GL renderer is using FLOAT32 instead of GL_SRGB, which is screwing
up the node-editor by making it turn on high bit depth unconditionally.

So until someone fixes the GL renderer properly, do this quickfix.
2024-07-11 14:57:20 +02:00
Benjamin Otte
df46eeafdb gpu: Make colormatrix op obey ccs
The colormatrix needs to be applied to unpremultiplied values, so we use
the alternative colorstate for that.
2024-07-11 14:57:20 +02:00
Benjamin Otte
0029286a1e gpu: Remove unused function
The colormatrix shader is no longer used for opacity.
2024-07-11 14:57:20 +02:00
Benjamin Otte
0e46d4eb98 gpu: Pass sampler to the image op
That way, we can use it in one other place where we want to use mipmaps.

I don't really like it because it adds yet another argument,
but then the one new caller was selecting suboptimal shaders, and that's
worse.
2024-07-11 14:57:20 +02:00
Benjamin Otte
f80e3fff92 gpu: Don't use the colormatrix shader for opacity
The colormatrix shade does a whole matrix multiplication, which is
absolutely not necessary.

The convert shader has builtin opacity handling and when the colorstates
match will do no conversion.
2024-07-11 14:57:20 +02:00
Benjamin Otte
504c6ba792 gpu: Don't use color matrix for opacity
We can use the regular image op which will select the fastest shader.
2024-07-11 14:57:20 +02:00
Benjamin Otte
c0aba9aee1 gpu: Make crossfade op obey ccs
I didn't have an idea what to use the alternate color state for, so I
don't use it.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b97cf2b9d9 gpu: Track image colorstate
So far we only track the image colorstate and convert if necessary.

There is no caching of the converted images happening.
2024-07-11 14:57:20 +02:00
Benjamin Otte
f81e7b2112 gpu: Make conic gradient op obey ccs
Straight copy of the linear gradient changes.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b59e4a929e gpu: Make radial gradient op obey ccs
Straight copy of the linear gradient changes.
2024-07-11 14:57:20 +02:00
Benjamin Otte
099d72f037 gpu: Make box shadow op obey ccs 2024-07-11 14:57:20 +02:00
Benjamin Otte
73acb41931 gpu: Make colorize op obey ccs 2024-07-11 14:57:20 +02:00
Benjamin Otte
ebb7fdb099 gpu: Make linear gradient op obey ccs
The alternative color state is used as the interpolation color state.
Colors are transformed into that space on the CPU.

For now we set the interpolation color state to SRGB, because ultimately
we want to let callers specify it, so having something that's easy to
map to that behavior is desirable.
Otherwise we might have chosen to interpolate in the compositing
colorstate.

It also means that we need to premultiply colors on the CPU now because
of the limitations of the shader colorstates APIs.
2024-07-11 14:57:20 +02:00
Benjamin Otte
ec3cb0ad9a gpu: Make border op obey ccs 2024-07-11 14:57:20 +02:00
Benjamin Otte
7ffef6792f gpu: Make rounded-color op obey ccs
This is the same as the color op.
2024-07-11 14:57:20 +02:00
Benjamin Otte
383148dc31 gpu: Make color op obey ccs
This makes use of the GskGpuColorStates by setting the ccs as output
colorstate and the color's colorstate as alternative color state.

The shader adaption is very straightforward because of that.
2024-07-11 14:57:20 +02:00
Benjamin Otte
a31601ccfc gpu: Make clear op obey ccs
This is the first op to obey the compositing color state. This means
from now on until all ops obey the ccs rendering is broken when ccs is
not set to linear.

I'll keep individual ops in seperate commits for easier review, because
they all need different adaptations.
2024-07-11 14:57:20 +02:00
Benjamin Otte
a587492cad gpu: Handle target not being composite colorstate
Render to an offscreen and add a final conversion if the target
colorstate is not a rendering colorstate.

This now allows the GPU renderer to render to any colorstate.
2024-07-11 14:57:20 +02:00
Benjamin Otte
f65d4914e4 gpu: Port convert op to GskGpuColorStates
Make it handle straight alpha, too, by checking if the alt colorspace is
premultiplied - which is the colorspace of the source.
2024-07-11 14:57:20 +02:00
Benjamin Otte
88dc49a5b6 gpu: Print the color states of shader ops
Makes the verbose output (a lot) more verbose, but it makes the
colorstates used in the shaders very visible.

And it will be relevant once people start using different colorstates
everywhere (like oklab for gradients/colors and so on).
2024-07-11 14:57:20 +02:00
Benjamin Otte
91d970e9c5 gpu: Add shaders for the new specialization constant
This adds the following functions:

output_color_from_alt()
alt_color_from_output()
  Converts between the two colors

output_color_alpha()
alt_color_alpha()
  Multiplies a color with an alpha value
2024-07-11 14:57:20 +02:00
Benjamin Otte
6c5ae48a05 gpu: Pass color states as specialization constant
This adds a GdkColorStates that encodes 2 of the default GdkColorStates
and wether their values are premultiplied or not.

Neither do the shaders do anything with this information yet, nor do the
shaders do anything with it yet, this is just the plumbing.
2024-07-11 14:57:20 +02:00
Benjamin Otte
d85ec2cbb4 gpu: create SRGB images
If desired, try creating GL_SRGB images. Pass a try_srgb boolean down to
the image creation functions and have them attempt to create images like
that.

When it is not possible to create srgb images in the given format, just
fall back to regular images. The calling code is meant to check the
GSK_GPU_IMAGE_SRGB flags to determine the actual format of the resulting
image.
2024-07-11 14:57:20 +02:00
Benjamin Otte
05b79bc378 gpu: Handle SRGB in render_texture()
When GDK_MEMORY_U8_SRGB is desired by the node, and a SRGB image is
created, pick SRGB_LINEAR as the colorspace to pass to frame_render().
2024-07-11 14:57:20 +02:00
Matthias Clasen
3ba63315d5 gpu: Pass compositing color states
Make the node processor and the pattern writer track the current
compositing color state. Color state nodes change it. We pass
the surface color state down via the frame apis.

The name of the variable is "ccs" for "compositing color space". It's an
unused variable name and it's common enough to deserve a short and sweet
name.
2024-07-11 14:57:20 +02:00
Benjamin Otte
eccdb594eb gpu: Remove straightalpha shader
As the new convert shader can do everything this shader could, use it
instead.
2024-07-11 14:57:20 +02:00
Matthias Clasen
a78796f22c gpu: Add a color convert shader
This shader converts between two color states, by using the
same functions that we use on the cpu. The conversion to perform
is passed as part of the variation.

As premultiplication is part of color states on the shader, we also
encode the premultiplication in the shader.
And because opacity is a useful optimization, we also allow setting
opacity.

For now, the only possible color states are srgb and srgb-linear.
2024-07-11 14:57:20 +02:00
Benjamin Otte
4fa6f791f4 cairo: Use the draw context's color state
This just passes through the sRGB set by the GDK backends instead of
hardcoding sRGB, so no functional changes.
2024-07-11 14:57:20 +02:00
Benjamin Otte
6287eaa745 cairo: Add colorstate to GskRenderNode::draw and use it
This adds the following:
- ccs argument to GskRenderNode::draw
  This is the compositing color state to use when drawing.

- make implementations use the CCS argument
  FIXME: Some implementations are missing

- gsk_render_node_draw_with_color_state()
  Draws a node with any color state, by switching to its compositing
  color state, drawing in that color state and then converting to the
  desired color state.
  This does draw the result OVER the previous contents in the passed in
  color state, so this function should be called with the target being
  empty.

- gsk_render_node_draw_ccs()
  This needs to be passed a css and then draws with that ccs.
  The main use for this is chaining up in rendernode draw()
  implementations.

- split out shared Cairo functions into gdkcairoprivate.h
  gskrendernode.c and gskrendernodeimpl.c need the same functions.
  Plus, there's various code in GDK that wants to use it, so put it in
  gdk/ not in gsk/

gsk_render_node_draw() now calls gsk_render_node_draw_with_color_state()
with GDK_COLOR_STATE_SRGB.
2024-07-11 14:57:20 +02:00
Benjamin Otte
ab7d969700 gdk: Add color state arg to gdk_texture_download_surface()
All callers set it to SRGB at the moment.
2024-07-11 14:57:20 +02:00
Matthias Clasen
5a7d7cc9f5 gsk: Show srgb information in verbose output
Show which offscreens are using an srgb format.
2024-07-11 14:57:20 +02:00
Benjamin Otte
1bbf5f7a17 gdk: Add GDK_MEMORY_NONE depth
That's basically the "undefined" value. We need that when drawing
nothing, which so far only happens with empty container nodes.

But empty container nodes can be children of other nodes, and that makes
things propagate. So instead of catching them, force the whole rest of
the code to deal with an undefined depth.

We also can't just set a random depth, because that will cause merging
to fail.
2024-07-11 14:57:20 +02:00
Matthias Clasen
db3b3c62bb ngl: Mark backbuffers as srgb
When the surface tells us that a surface is using an sRGB backbuffer,
set the corresponding flag on the backbuffer.
2024-07-11 14:57:20 +02:00
Matthias Clasen
de76045939 vulkan: Mark swapchain images as GSK_GPU_IMAGE_SRGB
Detect if an SRGB format is in use and mark the images as such.

So far this doesn't happen, but once it does, things will work.
2024-07-11 14:57:20 +02:00
Benjamin Otte
16c29a7db5 texture: Add gdk_texture_get_depth()
... and use it.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b5b0002d24 rendernode: Return the right depth for colors
This makes sure we return U8_SRGB for GdkRGBA colors with linear
compositing.
2024-07-11 14:57:19 +02:00
Benjamin Otte
a7ceb8ce66 gdk: Add GDK_MEMORY_U8_SRGB depth
This is an experiment for now, but it seems that encoding srgb inside
the depth makes sense, as we not just use depth to decide on the
GL fbconfigs/Vulkan formats to pick, depth also encodes how the [0...1]
color values are quantized when stored.

Let's see where this goes.
2024-07-11 14:57:19 +02:00
Benjamin Otte
6dea23128a gpu: Add the GSK_GPU_IMAGE_SRGB flag
This commit just adds the flag, but I wanted to make it an individual
commit to explain the purpose:

The SRGB flag is meant to be used for images that have an SRGB format.
In Vulkan terms, that means VK_FORMAT_*_SRGB.
In GL, it means GL_SRGB or GL_SRGB_ALPHA.

As these formats have been madatory since GL 3.0, we can (ab)use them
uncoditionally. Images in these formats are renderable, too, so it's
not just usable for uploading.

What these images allow is treating the data as sRGB while shaders
access them as linear, thereby getting sRGB<=>linear conversions for
free.

It is also possible to switch off the linearization of these images and
treat them as sRGB, which allows all sorts of shenanigans, though one
has to be careful if that turning off applies to the relevant GL/Vulkan
code in question.
2024-07-11 14:57:19 +02:00
Benjamin Otte
2f4e19d514 gdk: Allow querying GL SRGB formats
Nobody is using this yet.
2024-07-11 14:57:19 +02:00
Benjamin Otte
1273413c7b vulkan: Import GL textures via dmabufs
If the GL texture is exportable to a dmabuf, we can just use our dmabuf
importing code to get that texture into Vulkan.
There is no need to go via host memory in that case.

And if it doesn't work, we just fall back, like before.
2024-07-11 14:14:35 +02:00
Benjamin Otte
ef3f48a2be vulkan: Refactor gsk_vulkan_image_new_for_dmabuf()
It now works with just a dmabuf and doesn't take a texture anymore.

Which means it can be used from other codepaths in the future.
2024-07-11 14:14:35 +02:00
Benjamin Otte
fff78b60e9 gpu: All nodes are implemented
Unimplemented nodes are a failure now.

We make this a soft failure with a g_warning() so that during
development when adding new nodes, the renderer doesn't instantly crash,
but instead prnts a warning.

But we do consider unimplemented nodes a bug now.

Because of that, add_fallback_node() is now renamed to add_cairo_node().
2024-07-11 13:34:37 +02:00
Benjamin Otte
9abc7fc80b gpu: Don't hand Cairo invalid nodes
When encountering an invalid node, exit asap. Don't draw it with Cairo,
Cairo won't know what to do with it either.
2024-07-11 13:34:37 +02:00
Benjamin Otte
d8059ebdd2 gpu: "Implement" GL shader nodes
Instead of falling back to Cairo, draw the pink error rectangle
directly.
2024-07-11 13:34:36 +02:00
Matthias Clasen
8c988a7b07 Take all transforms into account
When determining which way is up for the offloaded texture, we
must take all transforms into account - the ones outside the
subsurface node, and the ones inside.
2024-07-10 22:11:13 +02:00
Benjamin Otte
4f2b639a24 gpu: We can handle 90 degree rotations quite easily 2024-07-10 22:06:24 +02:00
Benjamin Otte
3e01924ca3 gpu: Handle dihedral transforms in occlusion culling 2024-07-10 22:06:24 +02:00
Matthias Clasen
4d2884bde7 offload: Support dihedral transforms
When looking for the texture transform, allow dihedral transforms,
and pass them along when attaching to the subsurface.
2024-07-10 21:34:12 +02:00
Benjamin Otte
6065165060 Add gdk_dihedral_swaps_xy
This function determines if a dihedral transform swaps x and y.
2024-07-10 21:34:12 +02:00
Benjamin Otte
9272bf96f6 gpu: Handle affine transforms without touching matrix
By moving negative affines to be treated like dihedrals, because they
also need support of the modelview, we can free up the affine branch for
doing work without it.

Not a big win I guess, but it makes scaling more efficient.
2024-07-10 21:34:12 +02:00
Benjamin Otte
ae3efb2d2f gpu: Implement transform support for dihedral transforms
This allows handling them without ever needing to offscreen for losing
the clip, because the clip can always be transformed.

Also, all the optimizations keep working, like occlusion culling,
clears, and so on.

The main benefit of this work is the ability for offloading to now
handle dihedral transforms of the video buffer.

The other big advantage is that we can now start our rendering with a
dihedral transform from the compositor.
2024-07-10 21:34:12 +02:00
Benjamin Otte
b9ecae84f5 gpu: Shuffle some transform flags around
No need to check for negative numbers now that we can just use the
category that doesn't give us any.
2024-07-10 21:34:12 +02:00
Benjamin Otte
cd3286c71a gpu: Switch to GskFineTransformCategory
This is purely replacing the enums, no functional changes.
2024-07-10 21:34:12 +02:00
Benjamin Otte
83c2766e3f rendernode: Handle rotation transforms in opacity calculations
Tests included.
2024-07-10 21:34:12 +02:00
Benjamin Otte
5f719c8ea3 transform: Implement transform_point() for dihedrals
No longer using the default path and risking rounding issues.
2024-07-10 21:34:12 +02:00
Benjamin Otte
555f7d5404 transform: Implement transform_bounds() for dihedrals
No longer using the default path and risking rounding issues.
2024-07-10 21:34:12 +02:00
Benjamin Otte
3bcfc5539c transform: Add gsk_transform_to_dihedral()
I hate everything about this.

Is is xy or yx now?
Do I need to combine(a, b) or combine(b, a)?
2024-07-10 14:38:48 +02:00
Benjamin Otte
3221a8bdab gdk: Rename GdkTextureTransform to GdkDihedral
... and put it into its own header.

We want to use it in more places and the name and location are awkward.
2024-07-10 12:36:07 +02:00
Benjamin Otte
930f059f5e transform: Introduce GskFineTransformCategory
This category does a finer-grained categorization than
GskTransformCategory, but it is deliberatedly made to allow
easy backwards compatibility.

The reason for the categories is that they fit our renderers more
fine.

In particular, it allows implementing wl_output_transform support more
efficiently, thereby allowing rendering buffers the right way for
rotated phone screens or monitors.
2024-07-10 12:36:07 +02:00
Benjamin Otte
9a6e61e510 rect: There's no coverage witout overlap
The rectangles need to touch/overlap in both directions, otherwise
there's no coverage that covers both rectangles.

Test included.

Fixes rendering glitches in various apps when redrawing.

Fixes: #6849
2024-07-10 00:28:33 +02:00
Matthias Clasen
ed4f51436c Merge branch 'matthiasc/for-main' into 'main'
Add a missing include

Closes #6842

See merge request GNOME/gtk!7433
2024-07-09 03:04:25 +00:00
Matthias Clasen
7837354c6c Add a missing include
When building without Vulkan, we don't get this include for free.
So add it explicitly.

Fixes: #6842
2024-07-08 22:18:11 -04:00
Benjamin Otte
5dc6f134c5 gpu: Make offscreening code use process()
... instead of init_draw(); add_node(); finish_node();

We hook into the infrastructure one step earlier and close to where the
default renderer_render() and renderer_render_texture() arrive in the
nodeprocessor.

Why is this relevant?
Because process() does occlusion culling.

TL;DR: offscreens do culling now
2024-07-08 23:22:55 +02:00
Benjamin Otte
6daeb7e504 gpu: Transition exported textures into GENERAL layout
We import them as general, so they should be exported like that.

This was a longstanding issue that I never got around to fixing and I'm
touching this code anyway atm.
See commit 3aa6c27c26 for more details.
2024-07-08 23:22:41 +02:00
Benjamin Otte
fcf59ad135 gpu: Allow NULL as clear color
NULL disables clearing. We only implement this for GL as in Vulkan we'd
need to create different renderpasses with different attachment
descriptions and that would require more plumbing.
2024-07-08 23:07:36 +02:00
Benjamin Otte
1dd905d976 gpu: Fix wrong rect check in occlusion fallback path
We need to check that the clip is inside the opaque region, not that the
opaque region is inside the clip.

Test included, using the only not that hits the fallback path with an
opaque region smaller than its bounds.
2024-07-08 23:07:36 +02:00
Benjamin Otte
155f7cdeec gpu: Chceck if a container node is opaque as fallback
Sometimes container nodes contain lots of overlapping opaque items. In
that case we can use the container node itself as the first node even
though none of the children cover the whole paint area.

The use case for this is a grid of cells like in a terminal where all
the cells are opaque and we want to avoid drawing the background behind
them.
2024-07-08 23:07:36 +02:00
Benjamin Otte
6d564075f3 gsk: texture-scale nodes with non-integer bounds aren't opaque
Due to the way the intermediate offscreen gets drawn, we might end up
with seams at the edges.

And I don't think it's worth spending more time on than saying "not
opaque".

Fixes the compare-render testsuite

New testcase included.
2024-07-08 15:28:14 +02:00
Benjamin Otte
4cdf7aa65a rendernode: Add containernode->opaque and fill it at startup
We want to operate with opacities, so it makes sense to have this radily
available.

And we're doing a walk over all children on creation anyway, so why not
just capture the rect there.
2024-07-08 15:28:14 +02:00
Benjamin Otte
329dc9e0cf gpu: Change get_opaque() implementation of containers
We want to be able to express opaque grids. This means that the app
provides either a row of columns of opaque nodes or a column of rows,
and then the containers will magically figure it out.

The main use case for this is terminals, which are uilt using cells. And
when there's a transparent background configured but the contents are
opaque, it'd be nice if we could figure that out.

Also remove the 80% requirement. It is rather arbitrary and while it
helps for some cases, the aforementioned grid would suffer.
2024-07-08 15:28:14 +02:00
Benjamin Otte
e02de45537 gpu: Add GSK_GPU_DISABLE=occlusion
This simply disables add_first_node() usage.

Useful to find bugs in its implementation or track performance
with/without it.
2024-07-08 15:28:14 +02:00
Benjamin Otte
29fbda49bb gpu: Implement add_first_node() for rounded clip nodes
This is a bit more expensive than clip nodes, because we have to check
the rounded edges are outside of the clip.
2024-07-08 15:28:14 +02:00
Benjamin Otte
1b155341bd gpu: Implement add_first_node() for clip nodes
Clip nodes often appear in the widget tree.

And the implementation can be trivial because of the sanity checks
already performed before calling the vfunc.
2024-07-08 15:28:14 +02:00
Benjamin Otte
96c02c1eb4 gpu: Implement add_first_node() for transform nodes
This is required because transform nodes appear everywhere.

We just exit for all transforms that can't transform the clip rect
losslessly. Both because they are rare and because we'd make the
coverage possibilities much lower.
2024-07-08 15:28:14 +02:00
Benjamin Otte
116d662e0f gpu: Add early exit to add_first_node()
A node must cover the full clip region to be eligible for being the
first opaque node.

Do an early exit for all nodes that aren't big enough for that.
2024-07-08 15:28:14 +02:00
Benjamin Otte
d81cd4751f gpu: Add add_first_node for colors
Color nodes can set the default background of the renderpass, instead of
doing a clear op or running a shader.
2024-07-08 15:28:14 +02:00
Benjamin Otte
dd33068943 gpu: Implement add_first_node for containers
Containers can walk the list of children back to front, trying to find
the topmost node that fully covers the viewport.

And then they can skip drawing all the nodes before that one.
2024-07-08 15:28:14 +02:00
Benjamin Otte
09c1e51b8a gpu: Add gsk_gpu_node_processor_add_first_node()
Asks a node to add itself if it is fully covering the clip rectangle.
In that case, it is the first node that needs to be added.

If the node is not fully covering the clip, it should not draw itself,
because there might be stuff needing to be drawn below.

If a node adds itself, it should call gsk_gpu_render_pass_begin_op().
2024-07-08 15:28:14 +02:00
Benjamin Otte
af9a9422c4 gpu: Allow passing a background color to renderpasses
It's not used yet, everybody is passing GDK_RGBA_TRANSPARENT.
2024-07-08 15:28:14 +02:00
Benjamin Otte
df3c85ea7f gpu: Move renderpass handling into the nodeprocessor
There's no need for the frame to do this.
2024-07-08 15:28:14 +02:00
Benjamin Otte
b14a115fc0 container: Implement get_opaque_rect()
We find the first child that covers >80% of the container and return
that.

This is a nice speedup for the common case of a GtkWindow being covered
by a large opaque background.
It will fall apart for fancy themes that play with transparency or for
small windows because the shadow region gets too large.

But then we just scan the whole node tree.

We could think about adapting the 80% number, because that wasn't chosen
with any real scientific data behind it.
2024-07-08 15:28:14 +02:00
Benjamin Otte
355a88d002 roundedclip: Implement get_opaque_rect
This takes both the vertical and horizontal rectangle that isn't
covering the rounded corners and intersects both with the child's opaque
rect.
And then it returns the larger of the two.

This means the small slices of a window near the left/right (or
top/bottom) will never be covered, but if we wanted that, we'd need to
use something else than a rectangle - either a region or actually a
rounded rect.

But that is a lot more expensive to implement.
2024-07-08 15:28:14 +02:00
Benjamin Otte
1014b3d972 rendernode: Implement a bunch of simple opque_rect getters
Not much to write home about here.
2024-07-08 15:28:14 +02:00
Benjamin Otte
1a2b1575d6 rendernode: Add fully-opaque flag
Allows rendernodes to advertise themselves as fully opaque.

This is used as a fast path for get_opaque_rect().
2024-07-08 15:28:14 +02:00
Benjamin Otte
9c032bec89 gsk: Add gsk_render_node_get_opaque_rect()
Gets a rectangle inside the rendernode that is opaque.

This function only adds the API. So far, no implementation exists.
2024-07-08 15:28:14 +02:00
Matthias Clasen
5a59548d72 Merge branch 'fix-offload-transforms' into 'main'
offload: Don't assert things that might fail

Closes #6824

See merge request GNOME/gtk!7407
2024-07-08 12:58:28 +00:00
Matthias Clasen
880c33a777 offload: Don't assert things that might fail
We can in fact meet complex transforms here. Asserting that they
are simple doesn't make it so. Instead, simply bail out if a
transform is too complex; in this case we can't offload anyway,
so no need to walk the tree further.

Test included.

Fixes: #6824
2024-07-08 08:15:02 -04:00
Matthias Clasen
3a97b44321 Merge branch 'glshader-docs-typo' into 'main'
gskglshader: Fix typo in deprecation docs

See merge request GNOME/gtk!7426
2024-07-08 10:58:33 +00:00
Benjamin Otte
058252e895 vulkan: Can't blit to/from formats with a swizzle
Fixes grayscale images appearing red on some hardware.

Related: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11467
2024-07-08 10:51:37 +02:00
Benjamin Otte
c594de8302 vulkan: Code more defensively
Check for identity swizzle too, even though we don't use it.
2024-07-08 10:51:37 +02:00
Sebastian Dröge
8eaf05a3ef gskglshader: Fix typo in deprecation docs 2024-07-08 09:21:43 +03:00
Benjamin Otte
ba05963729 gpu: Make get_node_as_image() always return premultiplied images
We wanted premultiplied images in all cases anyway, and moving that
requirement means we can also move the caching code for re-caching
textures into the texture specific code.
2024-07-07 14:39:07 +02:00
Benjamin Otte
f14f7e7df6 gpu: Add GSK_GPU_DISABLE=offscreen
This uses offscreens for every call to get_node_as_image().

This is useful both for benchmarking benefits of those implementations
as well as checking that the node-specific paths produce identical
results.
2024-07-07 14:39:07 +02:00
Benjamin Otte
daa97d4b79 gpu: Refactor functions
gsk_gpu_node_processor_ensure_image() was a weird amalgamation of stuff
withe weird required and disallowed flags.

Refactor it to make the two operations we actually do there more
explicit: Removing straight alpha and generating mipmaps.

This untangling is also desirable in the future when we also want to
handle colorstates here.
2024-07-07 14:39:07 +02:00
Benjamin Otte
4822b85cb0 gpu: Make gsk_gpu_node_processor_get_node_as_image() more restrictive
Always return premultiplied images.

2 fallback cases for clip and transform nodes did not require that. If
those cases turn out to be important, they can call
gsk_gpu_get_node_as_image() directly as that's the more flexible option.
2024-07-07 14:39:07 +02:00
Benjamin Otte
7f61d7ac8b gpu: Implement get_node_as_image() for subsurface nodes
Pass through to the child instead of offscreening.

I mainly implemented it for the assertion, because this might be a
sneaky way to introduce bugs without exhaustive checking that we don't
offload stuff that is offscreened.

No actual bugs that I'm aware of, so no tests.
Strictly defensive coding.
2024-07-07 14:39:04 +02:00
Benjamin Otte
010ca5feef gpu: Implement get_node_as_image() for debug nodes
Just pass through to the child instead of offscreening.
2024-07-07 12:54:05 +02:00
Benjamin Otte
31a907be35 gpu: Make sure textures used as image are mipmapped
When getting a texture as image, we were always returning the texture
unconditionally.

However, we want to mipmap textures when the scale factor is too large,
and this code path did not do that.

The same codepath on the GL renderer doesn't do that either, so the test
is disabled for it.
2024-07-07 12:54:05 +02:00
Benjamin Otte
ab37fed974 gpu: vfuncify get_node_as_image()
The switch statement was ugly.

Plus, the code should be close to the add_node() vfunc implementation,
so they can be modified together.

See future commits for an example where this matters.
2024-07-07 12:54:05 +02:00
Benjamin Otte
d7308f2d73 gsk: Rename GSK_DEBUG=glyphcache to GSK_DEBUG=cache
1. I mistype it all the time
2. It's shorter
3. We use it for all caching these days, not just glyphs.
2024-07-07 05:24:45 +02:00
Benjamin Otte
012c4b9425 gpu: Remove the ubershader
It didn't bring any noticable benefits and it isn't compatible with the
way we intend to do colorstate support.

And nobody seems to want to spend time on it, so let's get rid of it.

We can bring it back later if someone wants to work on it.
2024-07-07 05:19:32 +02:00
Benjamin Otte
16c2e0a642 gl: Use GdkTextureDownloader
Cairo surfaces are so outdated.
2024-07-05 13:55:18 +02:00
Benjamin Otte
32625381fa gsk: Deprecate GskGLShader and the rendernode
The new renderers don't support them due to the required complexity of
integrating them with Vulkan and the assumptions those nodes make about
the renderer (the GL renderer exports its internal APIs into the
GLShader).

There haven't been any complaints that I'm aware of since 4.14 was
released where the default renderer does not support the nodes, so usage
in public seems to be close to nonexistant.

The 2 uses I know of were workarounds about missing features in GTK that
have stopped since GTK now supports them:

1. GStreamer used in to do premultiplication when the old GL renderer
   did not do so in hardware but on the CPU.
2. Adwaita used it for masking before the mask node wa added in 4.10.
2024-07-04 21:28:06 +02:00
Benjamin Otte
0f55b3bc18 Merge branch 'wip/otte/for-main' into 'main'
gpu: Split out the cache

See merge request GNOME/gtk!7411
2024-07-03 19:51:10 +00:00
Benjamin Otte
9c249fefc3 gpu: Improve periodic cache debug message
I was watching the log in my terminal and nothing happened.
And I wasn't sure if that was because nothing was printed or because the
same thing was printed every few seconds.

Fix that by printing a timestamp, so that in a few seconds something
else will be printed.
2024-07-03 20:36:56 +02:00
Benjamin Otte
eae7ee6c25 gpu: Track atlas differently
Previously we tracked the dead pixels, but that meant we didn't know the
alive pixels (because there's also unused pixels never accounted for).
And we would free the current atlas randomly due to that.

Now we track if any pixels are alive, and if so, we never gc the current
atlas.
2024-07-03 20:36:56 +02:00
Benjamin Otte
bf7f302ff5 gpu: gc atlas, too
After 60s, we gc the atlas, too. This ensures that after that time, we
free all cache resources, so if an application gets moved to the
background, it will no longer use GPU resources. (Well, at least the
cache won't.)
2024-07-03 19:55:18 +02:00
Benjamin Otte
0d6981bd54 gpu: Make the cache track if it's empty
Only if a non-stale item is in the cache do we consider the cache not
empty.

Once the cache is empty, the device frees it and stops running the
periodic GC.
2024-07-03 19:55:18 +02:00
Benjamin Otte
148d7bcc25 gpu: Don't remove gc timeout unless cache is empty
If the cache isn't empty, we want to rerun the GC.
2024-07-03 19:55:18 +02:00
Benjamin Otte
71161b6352 gpu: Split cache and device
This is for 3 reasons:

1. Separation of concerns
   The device is meant to manage the Vulkan/GL device and check stuff
   like image sizes.
   Caching is not part of that.

2. Refcounting
   Images etc want to reference the device, but the cache wants to
   reference images. If the cache is the device, that's a refcycle.

3. Flexibility
   It's now easier to implement >1 cache, say one per depth or one per
   color state.
2024-07-03 19:55:15 +02:00
Benjamin Otte
dd33a2f280 rendernode: Make sure depth variable has enough bits
This will be relevant when we add new values to it.
2024-07-03 19:55:15 +02:00
Emmanuele Bassi
554045de6e Use the appropriate annotations for a callback closure
The (closure) annotation with an parameter is meant to be used on the
callback argument, and point to the user data argument.
2024-07-03 17:21:04 +01:00
Matthias Clasen
f9856d547f gsk: Avoid a crash
The subsurface in subsurface nodes can be NULL, so check before
poking at it.
2024-07-02 15:52:51 -04:00
Benjamin Otte
9f7254a2d0 gl: Fix wrong drawing of mask node corner case
An empty mask with inverted-alpha means the source is visible.
2024-07-02 02:04:06 +02:00
Benjamin Otte
43c2b53811 rendernode: Remove default empty draw function
No node ever wants to draw nothing. So make sure code crashes if the
draw func is not set instead of silently drawing nothing.
2024-07-01 20:30:25 +02:00
Benjamin Otte
33d87bc22e gdk: Add GDK_N_DEPTHS to the enum
We are indexing arrays by the number of depths, and when adding depths
we don't want to forget to grow those arrays.
2024-07-01 20:07:22 +02:00
Maximiliano Sandoval
9126bf2c9d
docs: gsk: Add docstring for BroadwayRenderer 2024-06-29 15:14:33 +02:00
Maximiliano Sandoval
c73ff197e0
gsk: meson: Document renderers
These contain docstrings.
2024-06-29 15:14:32 +02:00
Benjamin Otte
72a4fae8dc vulkan: More slight refactoring
This applies the same refactoring as commit
5fbdec2a29 to another function.
2024-06-29 07:13:27 -04:00
Matthias Clasen
36c7d05445 gpu: Keep actual clear values in clear op
Keeping the GdkRGBA requires doing later conversions, which isn't
necessary if we just keep the already converted float[4].

It also prepares for future color states, where the color will need to
be converted using the colorstate.
2024-06-29 07:12:28 -04:00
Matthias Clasen
f3d5683f67 rendernode: Fix container nodes preferred depth
The current code injects an implicit GDK_MEMORY_U8 into this.
It is harmless now, but may not be in future. So avoid it.
2024-06-29 07:12:10 -04:00
Benjamin Otte
120887979d rendernode: Set proper values for fill and stroke nodes
Fill and stroke nodes were not reporting proper offscreen-for-opacity
and preferred depth.

This was unlikely to have been noticed as their child is usually a solid
color.
2024-06-29 07:12:10 -04:00
Matthias Clasen
51012c1802 ngl: Export dmabuf textures from render_texture
We want dmabufs because we can import them into Vulkan, amongst
other things.
2024-06-22 08:02:31 -04:00
Matthias Clasen
6f5c610858 gsk: Give up automatic font subsetting
Despite my best effort, it seems impossible to make ci and local
builds agree on what font subsetter and fonts to use, so make this
opt-in for now: If you want to produce a node file with embedded
fonts, set GSK_SUBSET_FONTS=1.
2024-06-21 18:45:32 -04:00
Matthias Clasen
b1a840bec0 Try to avoid aliasing with system fonts
The rendernode parser creates its own fontmap for the fonts that
we deserialize from blobs. But we were using the system fontconfig
configuration for it, leading to system fonts still being found.
This is bad, and causes test failures in ci. Try with an empty
fontconfig configuration instead.
2024-06-21 18:17:11 -04:00
Benjamin Otte
5fbdec2a29 vulkan: Slight refactoring for future changes
No functional changes.
2024-06-21 19:53:46 +02:00
Matthias Clasen
d1d4d80a1d Simply some internal api
The only caller of gdk_memory_texture_from_texture doesn't use
the second argument.
2024-06-19 02:06:14 -04:00
Matthias Clasen
a63a201812 Fix a crash in rendernode serialization
This snuck in with a6ffd6b3b2.
2024-06-17 22:09:30 -04:00
Matthias Clasen
f09caced9b Drop debug spew 2024-06-17 21:44:33 -04:00
Matthias Clasen
36993ac707 gpu: Print some more details
Print the variations of mask and blendmode operations.
Just because we can.
2024-06-15 14:00:46 -04:00
Matthias Clasen
34fb08af6e Fix a copy-paste error
This was obviously meant to compare two different colors.
2024-06-14 12:30:06 -04:00