Commit Graph

2752 Commits

Author SHA1 Message Date
Luca Bacci
79568d2944 gpu: Disable GL_DEPTH_TEST
The call to enable depth testing was copied from the GL
renderer, but it's not needed.

Fixes #6401
2024-02-19 18:16:35 +01:00
Luca Bacci
ae45be7875 GL renderer: Disable GL_DEPTH_TEST
It was introduced in bbfe4324 to support GtkGLArea. It's not
needed anymore

See #6401
2024-02-19 18:16:35 +01:00
Benjamin Otte
afc7b46264 gpu: Add an epsilon before ceil()ing for offscreen size
Avoids getting the scale wrong when due to a rounding error our
pixel-aligned rectangle is 5.000000003px big and we ceil() to 6px
and produce blurry output.

Fixes #6439
2024-02-14 20:11:59 +01:00
Benjamin Otte
86db9e2ce0 gsk: Use gsk_rect_scale() in more places 2024-02-14 20:11:30 +01:00
Benjamin Otte
cb6c720d37 gpu: Render enough of a scaled texture offscreen
We were not thinking about pixel alignment and the potential later
linear blend for the final composite.

Fixes #6428
2024-02-14 20:11:29 +01:00
Matthias Clasen
fb4023af22 Fix rounded rect intersection code
The code was written under the assumption that the corners of
the rounded rect are disjoint. If they aren't, there are a few
more cases to consider.

Fixes: #6440
2024-02-14 10:37:56 -05:00
Matthias Clasen
72614fdb67 gsk: Normalize node bounds upon creation
We lost this when a bunch of rect code was inlined in
commit 36314f28e2, and as it turns out, that broke some
applications. So, bring it back.

Fixes: #6435
2024-02-13 20:06:16 -05:00
Matthias Clasen
230ee92857 Add gsk_rect_normalize
This is an inline version of graphene_rect_normalize_in_place.
2024-02-13 20:06:16 -05:00
Matthias Clasen
b2d22d8125 Merge branch 'wip/abono/fallthrough' into 'main'
gsk: Remove unnecessary G_GNUC_FALLTHROUGH

See merge request GNOME/gtk!6898
2024-02-13 22:17:50 +00:00
Benjamin Otte
ee34781a13 gpu: Pixel-align the blur rectangle
Fixes blurriness in shadows.

Not sure to do a proper test for this feature. Usually proper pixel
alignment is tested by drawing a crips line and checking that it is
indeed crisp. But we are testing the blur operation here...

Fixes #6380
2024-02-13 21:56:01 +01:00
Benjamin Otte
9fc80a0bd5 gpu: Update blur code to newer internal API
The recommended way to draw offscreens has been init_draw() for a bit,
but apparently this code wasn't updated.
2024-02-13 21:56:01 +01:00
Benjamin Otte
a1dda0ec3c gpu: Adjust shadows clip by shadow offset
When computing the clip of the shadow rect, don't forget that it will
ultimately be offset by the shadow offset.

Fixes #6425
2024-02-13 21:56:01 +01:00
Benjamin Otte
dbbc16947f gpu: Handle one layer of NULL return
This isn't really a useful thing in itself, because none of the callers
handle the NULL return.
But the resulting crash is easier to debug when it's a NULL image than
when add_node() is called on an uninitializes NodeProcessor.
2024-02-13 21:56:01 +01:00
Benjamin Otte
dc47abc60e gpu: Don't oversize node image
There's no need - even if given clip bounds - to render the parts
outside the node.

So clip to the node bounds.
2024-02-13 21:56:01 +01:00
Alessandro Bono
ca9ba3cc80 gsk: Remove unnecessary G_GNUC_FALLTHROUGH
In GSK the following pattern is used four times:
```
  switch (self->filter)
    {
      default:
        g_assert_not_reached ();
        G_GNUC_FALLTHROUGH;
      case GSK_GPU_BLIT_LINEAR:
        filter = GL_LINEAR;
        break;

      case GSK_GPU_BLIT_NEAREST:
        filter = GL_NEAREST;
        break;
    }
```
The G_GNUC_FALLTHROUGH macro is not required. When G_DISABLE_ASSERT
is defined the body of the `default` case is empty, thus there is
no need. When G_DISABLE_ASSERT is not defined the body of the `default`
case contains g_assert_not_reached() thus it won't fallthrough.

This resolves the following:
```
[221/1379] Compiling C object gsk/libgsk.a.p/gpu_gskgpublitop.c.o
[...]
error: fallthrough annotation in unreachable code [-Werror,-Wimplicit-fallthrough]
1 error generated.
```
2024-02-13 18:29:03 +01:00
Matthias Clasen
ea7a61a763 gpu: Print globals when being verbose
This can be helpful to see that there is an enormous scale blowing
things up. We omit the matrix, since it is 16 floats that are hard
to interpret at a glance.
2024-02-13 06:59:58 -05:00
Matthias Clasen
2104d7b062 fixup! gsk: Don't use gpu renderers with llvmpipe 2024-02-12 14:41:14 -05:00
Matthias Clasen
6c4739a2f1 gsk: Don't use gpu renderers with llvmpipe
Unless the renderer has been explicitly selected via the
GSK_RENDERER environment variable, don't use it with llvmpipe.

It is important that we allow explicit setting to override
this, so we can continue to use ngl in ci, where we don't
have hw and want to test with llvmpipe.

This should address many of the "performance is terrible in
GNOME OS" complaints that are coming from people running in
VMs, etc.
2024-02-12 14:19:57 -05:00
Matthias Clasen
925d2ba9ae Merge branch 'wip/otte/for-main' into 'main'
gpu: Avoid offscreens for disjoint containers

See merge request GNOME/gtk!6889
2024-02-12 12:58:14 +00:00
Benjamin Otte
2fe1f47e6d gpu: Avoid offscreens for disjoint containers
When opacity is set but the container is disjoint - ie no children
overlap - don't redirect into an offscreen, because it's not necessary.
2024-02-12 08:34:18 +01:00
Matthias Clasen
1db696be79 offload: Find and use source rectangle
Look for nodes like subsurface { clip { texture {} } }, and use
the clip to provide a source rectangle for subsetting the texture.

Update affected tests, and add a new one.
2024-02-11 21:44:47 -05:00
Matthias Clasen
9a30ea1f69 subsurface: Have a source rectangle
This will let us use a subset of the full texture, which can
be necessary in the case that converters put padding around
content in dmabufs. The naming follows the Wayland viewporter
spec.

For now, make all callers pass the full texture rect.
2024-02-11 21:44:27 -05:00
Matthias Clasen
0495359eca subsurface: Rename rect to dest
We are going to introduce another rect, so better to be clear in
naming. We are following the naming of the Wayland viewporter spec
and call the rectangle that we drawing into the dest(ination).
2024-02-11 21:43:51 -05:00
Matthias Clasen
5b55456b75 Rework diffing one more time
Pass the surface along. We need it to identify the inspector case
in gsk_subsurface_node_diff.
2024-02-11 20:48:59 -05:00
Matthias Clasen
26c25cc6b7 Simplify gsk_subsurface_node_diff
Most of the time, the subsurfaces will be the same. And if they
aren't, can_diff() will return FALSE anyway.
2024-02-11 20:24:28 -05:00
Matthias Clasen
f8e89f2224 offload: Do diff collection later
We were collecting diffs based on the can_offload/can_raise
information, but attaching the texture to the subsurface can
fail (e.g. if its not a dmabuf texture), in which case can_offload
turned out to be wrong. So move the diff collection to the end
and do it based on the whether we actually succeeded in attaching
the texture.
2024-02-11 20:24:28 -05:00
Benjamin Otte
30afac9a6b offload: No need to pass the offload to the diff
We can just check if the subsurfaces contain content - and if they do,
they will be offloading and we can ignore the diff.

This essentially reverts 48740de71a
2024-02-11 20:24:28 -05:00
Benjamin Otte
dac56dd757 offload: Change the way we compute damage regions
Instead of relying on diffing subsurface nodes, we track damage
generated by offloaded contents inside GskOffload.

There are 3 stages a subsurface node can be in:

1. not offloaded
   Drawing is done by the renderer
2. offloaded above
   The renderer draws nothing
3. offloaded below
   The renderer needs to punch a hole.

Whenever the stage changes, we need to repaint.
And that can happen without the subsurface's contents changing, like
when a widget is put above the subsurface and it needs to to go from
offloaded above to below.

So we now recruit GskOffload for tracking these changes, instead of
relying on the subsurface diffing.

But we still need the subsurface diffing code to work for the
non-offloaded case, because then the offloading code is not used.
So we keep using it whenever that happens.

Not that when a subsurface transitions between being offloaded and not
being offloaded, we may diff it twice - once in the offload code and
once in the node diffing - but that shouldn't matter.
2024-02-11 20:24:28 -05:00
Benjamin Otte
e4ca3a285e gsk: Split out a function
I want to use it elsewhere.

I didn't come up with a better name, if anyone knows one, please
rename.
2024-02-11 20:24:28 -05:00
Benjamin Otte
30b5a33444 rendernode: Fix subsurface diff code 2024-02-11 20:24:28 -05:00
Benjamin Otte
e647ebae87 rendernode: Do full diff when starting/stopping offload
When a subsurface goes from not offloaded to offloaded (or vice versa),
we need to add the whole node to the diff region, because we switch from
whatever contents were drawn to a punched hole.
2024-02-11 20:24:28 -05:00
Matthias Clasen
865564b32f gsk: Make matrix transforms roundtrip better
When we parse a 2D matrix, we produce a 2D transform, and we
can easily regenerate a 2D matrix from it.

Tests included.
2024-02-11 19:39:19 -05:00
Benjamin Otte
1b9002afd3 ngl: Check for GL 3.3
The default check is still for GL 3.0 and we don't support that.
2024-02-11 20:04:54 +01:00
Benjamin Otte
6ed4eece04 gpu: debug-print the used shader clip
When using GSK_DEBUG=verbose, print the clip mode used in the shader.

Use cute little unicode indicators to not overload the debug output.
2024-02-11 20:04:54 +01:00
Benjamin Otte
cfaddb5d47 gpu: Use nodprocessor infrastructure for offscreening
The just copied over function can just use the same infrastructure as
the other functions we already have that create slightly adjusted
offscreens.
2024-02-11 20:04:54 +01:00
Benjamin Otte
7c861d8b59 gpu: Don't clip again after already clipping
The 2 callers of gsk_gpu_get_node_as_image() were already computing the
minimum clip region and in particular aligning it to the pixel grid, so
intersecting with node bounds again was causing that alignment to be
busted.
2024-02-11 20:04:54 +01:00
Benjamin Otte
1c3457adfb gpu: Fix sizing of fractionally scaled backbuffer
When using a window size and scale that don't multiply to an integer, we
were using the wrong method to adjust it.

The Wayland fractional scaling spec just says:

> For toplevel surfaces, the size is rounded halfway away from zero.

This is meant to be interpreted as "create a large enough buffer to hold
partial pixels) and the compositor will blend it mapping to the pixel
grid" even if that means the buffer slightly overhangs.

Example:
A 11 units wide window at 150% will need a 11 * 1.5 = 16.5 pixel wide
buffer. This should be rounded to 17 pixels but rendered as if only 16.5
pixels are occupied by the window, not as if all 17 pixels are occupied.
2024-02-11 20:04:54 +01:00
Benjamin Otte
a2e46c4d39 gpu: Move function
It is only used by the nodeprocessor, so put it where it belongs.
2024-02-11 20:04:54 +01:00
Benjamin Otte
df1d024059 Revert "gpu: Fix scale fluctuation"
This commit is wrong.
It does achieve what it sets out to do, but the method doesn't work.

It confused multiple things in one commit, the commit message only
describes the symptoms it tries to fix and not why the fix is correct,
it includes no tests and it wsn't properly reviewed.

Related: !6871
2024-02-11 20:04:54 +01:00
Matthias Clasen
87b66de109 Merge branch 'mip_size' into 'main'
gsk: Fix blit sizes while generating mipmaps on vk

See merge request GNOME/gtk!6875
2024-02-10 19:13:36 +00:00
M Henning
d08412aaa4 gsk: Fix blit sizes while generating mipmaps on vk
A few lines later we already had the correct equation for the size.
See vulkan 1.3 spec section 12.3.2 "Image Mip Level Sizing"
2024-02-10 10:59:44 -05:00
Matthias Clasen
ac65495434 Merge branch 'fix-scale-fluctuation' into 'main'
gpu: Fix scale fluctuation

See merge request GNOME/gtk!6871
2024-02-10 12:08:52 +00:00
Matthias Clasen
1ac82528d9 gpu: Fix scale fluctuation
We want to use a viewport that gives us the right scale back.
This fixes problems where glyph lookups were inefficient because
the scale part of the key would fluctuate ever so slightly.
2024-02-09 19:49:54 -05:00
Matthias Clasen
be2dcdd897 offload: Fix our tree walk
We were not finding an overlaid spinner, since it is implemented
as a texture in a (most of the time) non-affine transform, and
we were aborting our treewalk when we see such transforms.

Instead, don't abort the walk on any transforms, but check if we
are in an affine context before deciding to offload a subsurface.
2024-02-09 12:43:38 -05:00
Matthias Clasen
46cb0c5fc8 offload: Small optimization
Don't transform bounds more often than necessary.
2024-02-09 12:19:16 -05:00
Benjamin Otte
9c0ca8803d gpu: Punch hole with a clear again
This reinstates the clear op when possible so we can avoid blending
changes and benefit for large areas, when the clip is appropriate.

Related: #6375
2024-02-09 04:28:32 +01:00
Benjamin Otte
5b184a10a9 gpu: Add a CLEAR blend mode for subsurface hole punching
The previous code was ignoring non-scissor clips, which would make it
overeager at punching holes.

It also was not working with fractional coordinates.

Fixes #6375
2024-02-09 04:28:32 +01:00
Benjamin Otte
269662c888 gpu: Scale the border offset
The shader was forgetting to apply global scale to the offset, which
would cause lines to be offset improperly on hidpi.

Fixes #6412
2024-02-09 04:28:32 +01:00
Guido Günther
3cce78d02c gpu: Print actually checked GLES version
We check for 3.0 not 2.0.
2024-02-08 16:24:50 +01:00
Benjamin Otte
19fccb13c3 gpu: GL < 4.0 needs the ifelse ladder for textures
GL 4.0 (section 4.1.7) allows dynamically uniform expressions as texture
indexes, GL 3.3 (again section 4.1.7) requires constants.

Related: #6401
2024-02-07 19:09:07 +01:00