Commit Graph

2055 Commits

Author SHA1 Message Date
Benjamin Otte
0e93ad8671 vulkan: Align vertex data
We align the data to a multiple of vertex stride, that way we use more
memory, but we could compute an offset into the vertex buffer without
changing the offset.
2023-06-04 19:42:01 +02:00
Benjamin Otte
d98991a0ad vulkan: Set offsets when counting
We can set the vertex offset while counting the data, this gets rid of
the need of passing all the counting machinery into the actual data
collection code.
2023-06-04 19:42:01 +02:00
Benjamin Otte
1f7dcc1286 vulkan: Simplify switch statement
All branches do the same thing now, so pull them all into the same
branch.
2023-06-04 19:42:01 +02:00
Benjamin Otte
328cdf7b2a vulkan: Simplify collect_vertex_data()
We don't have any size arguments to it, so don't use them.
2023-06-04 19:42:01 +02:00
Benjamin Otte
79a227bc64 vulkan: Remove a function from pipeline impls
That function is available already in the structs we feed to Vulkan.

Store it from there and reuse it.
2023-06-04 19:42:01 +02:00
Benjamin Otte
0fee26252c vulkan: Don't draw fully clipped nodes
... if they are container nodes. Other nodes will get culled by the
vertex shader.
2023-06-04 19:42:01 +02:00
Benjamin Otte
d48b6b9ad5 vulkan: Add optimization for transforms
When attempting a complex transform, check if the clip can be ignored
and do that if possible.

That way we don't cause fallbacks when transforming the clip is too
complex.
2023-06-04 19:42:01 +02:00
Benjamin Otte
d4618ea8a6 vulkan: Don't crash with overly large nodes
... when these nodes are used as children of a complex transform nodes
and we lose the clip.
2023-06-04 19:42:01 +02:00
Benjamin Otte
a73530f952 vulkan: Update texture shader to do AA 2023-06-04 19:42:01 +02:00
Benjamin Otte
3e620a8fe5 vulkan: Split generic code off
No need to duplicate code in shaders when it can be shared.
2023-06-04 19:42:01 +02:00
Benjamin Otte
6d8c8199d9 vulkan: Use rounded rect APIs to improve clips
There are a bunch of intersection APIs available these days.
Let's use them.
2023-06-04 19:42:01 +02:00
Benjamin Otte
968ceb71d5 gsk: Add (private) gsk_rounded_rect_intersection()
The idea is that for a rectangle intersection, each corner of the
result is either entirely part of one original rectangle or it is
an intersection point.

By detecting those 2 cases and treating them differently, we can
simplify the code to compare rounded rectangles.
2023-06-04 19:42:01 +02:00
Benjamin Otte
7f5504bea4 vulkan: Set the initial clip rect
Instead of rendering unclipped, set the clip region to the extents of
the current clip region.
2023-06-04 19:42:01 +02:00
Benjamin Otte
4b2b239550 vulkan: Only draw one rect
Instead of emitting the render commands once per rectangle of the clip
region, just emit them once with the region's extents.

This is generally faster because it emits fewer commands to the GPU,
even though it may touch significantly more pixels.

For a proper method, we'd need to record the commands per clip rectangle
instead of emitting all of them all the time.
2023-06-04 19:42:01 +02:00
Benjamin Otte
23c10d434c vulkan: Use CLAMP_TO_EDGE in sampler
We don't want to clamp to the border, that causes fade-outs at the
edges.
2023-06-04 19:42:01 +02:00
Benjamin Otte
87c9503293 vulkan: Rewrite AA shaders to respect scale
The border and color shaders - the ones that do AA - now multiply their
coordinates by the scale factor, which gives them better rounding
capabilities.

This in particular improves the case where they are used in fractional
scaling situations, where the scale is defined at the root element.
2023-06-04 19:42:01 +02:00
Benjamin Otte
76634cb68b vulkan: Don't allocate no descriptor sets
If we don't need them, exit early.

Shuts up the validation layers when running simple denos without
textures.
2023-06-04 19:42:01 +02:00
Benjamin Otte
52eefdb7d9 vulkan: Only use a single pipeline layout
There's no need to use 3 different ones when they are compatible.
2023-06-04 19:42:01 +02:00
Benjamin Otte
ea9f0a3372 vulkan: Don't cull vertices
We end up with the backside, when we scale(-1) and we still want it to
be visible, just flipped.
2023-06-04 19:42:01 +02:00
Benjamin Otte
8561ff37c4 vulkan: Use scale factor for offscreens and fallbacks
Previously, we just used the defaultscale factor, but now that we're
having it available in push constants, we can read it back for creating
offscreens and rendering fallbacks.

So do that.
2023-06-04 19:42:01 +02:00
Benjamin Otte
a09580b9ef vulkan: Split scale from matrix
Now, the scale is no longer part of the matrix. This allows shaders to
transform points by the scale which increases accuracy for antialiasing.
2023-06-04 19:42:01 +02:00
Benjamin Otte
0511227379 vulkan: Keep the modelview as a GskTransform
This allows doing more optimized math on it.
2023-06-04 19:42:01 +02:00
Benjamin Otte
4183ce0b52 vulkan: Split modelview and projection
This is adding extra work, but the benefits should become visible
in future commits.
2023-06-04 19:42:01 +02:00
Benjamin Otte
57222cc64c vulkan: Add scale to push constants
This way, it can be pushed to the shaders
2023-06-04 19:42:01 +02:00
Benjamin Otte
b3c1284382 vulkan: Move scale into the state object 2023-06-04 19:42:01 +02:00
Benjamin Otte
b02e054592 vulkan: Add offset to the Vulkan clip checks
This was forgotten when tracking the offset was added, so code was
actually selecting the wrong shaders.
2023-06-04 19:42:01 +02:00
Benjamin Otte
870ee06d1f vulkan: Move offset into the state object 2023-06-04 19:42:01 +02:00
Benjamin Otte
8d586be693 vulkan: Add a new GskVulkanParseState
It's a 1:1 replacement for GskVulkanPushConstants, just without the
indirection through a different file.

GskVulkanPushConstants as a struct is gone now.
The file still exists to handle the push_constants operation.
2023-06-04 19:42:01 +02:00
Benjamin Otte
94ab11b999 vulkan: Don't store push constants in RenderOp
Instead, only store the values that are needed.
2023-06-04 19:42:01 +02:00
Benjamin Otte
9b1dcd3872 vulkan: Split out gsk_vulkan_render_pass_append_push_constants()
Simplifies the code and makes future refactoring easier
2023-06-04 19:42:01 +02:00
Benjamin Otte
c37171f4d6 vulkan: Pass values to push directly
Don't require a GskVulkanPushConstants there.
2023-06-04 19:42:01 +02:00
Benjamin Otte
c479f93372 vulkan: Add a static assert
We don't want to make the push constants larger than what the spec
guarantees. And that is 128 bytes, see value for
maxPushConstantsSize in table 55 of
https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#limits-minmax
2023-06-04 19:42:01 +02:00
Benjamin Otte
186e056c56 vulkan: Handle clip properly for offscreens
This was broken in the last commit.
2023-06-04 19:42:01 +02:00
Benjamin Otte
d8b9c3ae96 vulkan: Track offset in the renderpass
This avoids emitting lots of push constant updates as most of the
transforms we have are simple translations to adjust drawing for the
next widget.
2023-06-04 19:42:01 +02:00
Benjamin Otte
5de6f12e88 vulkan: Pass scale to offscreens
Create offscreens with enough pixels for the given scale and ensure
the scale is passed on.

This improves text rendering on offscreens quite a bit.
2023-06-04 19:42:01 +02:00
Benjamin Otte
5422c12577 vulkan: Clean up scale handling
1. Use a graphene_vec2_t
2. Ensure it's always positive
3. Don't break with fallback

The scale value is nothing more than an indication of how many pixels to
assume per unit of a node.
2023-06-04 19:42:01 +02:00
Benjamin Otte
bb145b9bc1 vulkan: Fix typo 2023-06-04 19:42:01 +02:00
Benjamin Otte
a55fda0b49 vulkan: Don't store unused matrices
We can compute it when needed, so do that.
2023-06-04 19:42:01 +02:00
Benjamin Otte
5b93a32f90 vulkan: Remove unneeded argument
The initial matrix can be computed as needed, so we don't need to
precompute it.
2023-06-04 19:42:01 +02:00
Benjamin Otte
495ee1be3d vulkan: Don't explode without vertex data
If no buffer has any vertex data (read: if nothing gets drawn), don't
try to allocate a 0 bytes buffer.
2023-06-04 19:42:01 +02:00
Benjamin Otte
7f1bd1f047 vulkan: Handle empty child bounds in repeat node
Also add test to the testsuite for it.
2023-06-04 19:42:01 +02:00
Benjamin Otte
da147dca92 vulkan: Fix repeat nodes 2023-06-04 19:42:01 +02:00
Benjamin Otte
8ba5ff98aa vulkan: Don't transform the viewport rect
We don't want to render the offscreen trnsformed, we want to render it
as-is.

We lose the correct scale factor, but that requires some separate work,
so for now it gets a bit blurry on hidpi.
2023-06-04 19:42:01 +02:00
Benjamin Otte
34f4493c36 vulkan: Make quarks global variables
I don't want to ensure there's a RenderPass available everywhere and
recreate the quarks in each, I just want to use them.
2023-06-04 19:42:01 +02:00
Benjamin Otte
314923d4b5 vulkan: Split out a function
We can now create offscreens explicitly.
2023-06-04 19:42:00 +02:00
Benjamin Otte
d2f45dae96 vulkan: offscreens are used as color attachments
... so set the corresponding flag.

Also name the function "new_for_offscreen()" because thats what this
function is about, "texture" is ambiguous.
2023-06-04 19:42:00 +02:00
Benjamin Otte
0e31cf9542 vulkan: compute new modelview directly
no need to go through a GskTransform
2023-06-04 19:42:00 +02:00
Benjamin Otte
af901a10e3 vulkan: Make border shader handle fractional widths
We were rounding widths properly, make sure we always round up.
2023-06-04 19:42:00 +02:00
Benjamin Otte
3d1a607367 vulkan: Don't round corners when growing rounded rect
If the corner is set to 0, keep it there.
2023-06-04 19:42:00 +02:00
Benjamin Otte
1be21a33d9 vulkan: Rewrite rounded rectangle to use SDF distance
We can use this to properly compute distance in scaled situations.
We also now compute coverage with (imperfect) antialiasing.
2023-06-04 19:42:00 +02:00
Benjamin Otte
64bcdb713c vulkan: Start rework on shaders to allow antialiased drawing
This introduces the rect object and adds a rect_distance() and
rect_coverage() function.

_distance() returns the signed distance tp the rectangle.
_coverage() returns the coverage of a pixel centered at that position.

Note that the pixel size is computed using dFdx/dFdy.
2023-06-04 19:42:00 +02:00
Benjamin Otte
4a868736f9 vulkan: Render whole texture
When the node bounds were a non-integer size, the texture would get
ceil()ed pixels, but various viewport or scissor computations might
floor() instead, leaving the right/bottom row of pixels untouched.
Make sure those functions ceil(), too.
2023-06-04 19:42:00 +02:00
Benjamin Otte
cfeaa0ac72 renderer: return_if_fail() if the given texture size is 0
All renderers SEGV currently when that happens.
2023-06-04 19:42:00 +02:00
Matthias Clasen
957fa87fce gsk: Support straight alpha textures
This is not the optimal way of doing it: we're
reuploading the texture with client-side conversion.
But it fits nicely into our current handling of mipmaps.

We can do better once we use shaders for colorspace
conversions.
2023-05-31 14:37:33 -04:00
Matthias Clasen
0f61c52593 gdk: Simplify gdk_memory_format_gl_format
Make the callers of this function check for
straight alpha themselves, and only do the
version compatibility check here. This makes
the function usable in contexts where straight
alpha is acceptable.
2023-05-30 14:49:45 -04:00
Matthias Clasen
a4bae6a62d gsk: Use matching memory format
memory_format_gl_format returns the new memory
format if it made a change, we should not drop
that on the floor.
2023-05-30 14:41:01 -04:00
Sophie Herold
ef8c835762 gsk: Support swizzle for gray and alpha formats
Swizzling is needed to display one channel memory formats
as gray etc.
2023-05-30 14:41:01 -04:00
Matthias Clasen
c2a8620660 gsk: Mark some variables as unused
Hopefully that shuts up clang.
2023-05-18 13:29:28 -04:00
Matthias Clasen
4d66598f31 Merge branch 'matthiasc/for-main' into 'main'
gsk: Cosmetics

See merge request GNOME/gtk!5983
2023-05-17 00:58:48 +00:00
Matthias Clasen
2ec1bd7248 Merge branch 'gl-renderer-more-defensive' into 'main'
gsk: Stop setting uniforms when we are out of batches

See merge request GNOME/gtk!5981
2023-05-17 00:29:40 +00:00
Matthias Clasen
4a8a6e9f70 gsk: Don't build unused functions
The only caller is #if 0 ed, so don't build
these functions.
2023-05-16 20:13:57 -04:00
Matthias Clasen
0a9d25c9e8 gsk: Cosmetics
Get the context from the driver.
2023-05-16 20:13:57 -04:00
Matthias Clasen
71a231b71d gsk: Stop setting uniforms when we are out of batches
When the command queue is out of batches, there is
no point in doing further work like allocating uniforms.

This helps us avoid assertions in the uniform code
that we would hit when we run out of uniform space
too.
2023-05-16 20:03:19 -04:00
Benjamin Otte
112fe06323 glrenderer: Remove unused function
Thanks, macos CI.

(We should have a Fedora clang build.)
2023-05-17 01:52:42 +02:00
Matthias Clasen
9dd83ab354 gsk: Fix a crash
When we start ignoring batches, we must do it everywhere,
or we may run into assertions. This was triggered by an
enormous text node tree produced by tests/rendernode-create.
2023-05-16 17:33:21 -04:00
Benjamin Otte
2b0e3a5b1a nodeparser: Move an error check
By putting the check earlier, it will be emitted for the right token.
2023-05-16 18:53:53 +02:00
Benjamin Otte
2b0ad09423 vulkan: Make projection matrix match GL
Vulkan has a different initial coordinate system to GL.

GL:
(-1, 1, -1) +------+.
            |`.    | `.
            |  `·--|---·
            |   :  |   :
            +------+.  :
             `. :    `.:
               `·------· (1, -1, 1)

Vulkan:
(-1, -1, 0) +------+.
            |`.    | `.
            |  `·--|---·
            |   :  |   :
            +------+.  :
             `. :    `.:
               `·------· (1, 1, 1)

so adjust the near and far plane we pass to
graphene_matrix_init_ortho() to make it end up with the same
projection as the GL renderer.
2023-05-16 18:53:27 +02:00
Benjamin Otte
8d528350b9 rendernode: clip when drawing shadows
Ensures the shadow stays small.
2023-05-16 18:53:27 +02:00
Benjamin Otte
d51c92f54d build: Make shaders depend on their includes
This does not do any proper dependency tracking, it just makes every
shader depend on every include shader.

But that's good enough for now.
2023-05-16 18:53:27 +02:00
Benjamin Otte
b9bd7124c0 vulkan: Fix typo in clipping code 2023-05-16 18:53:27 +02:00
Matthias Clasen
9faf1a0377 gsk: Comment out some debug code
The calls of these functions are #ifdef'ed out,
so no point in compiling these functions.
2023-05-11 06:13:42 -04:00
Matthias Clasen
aee214b09d gsk: Fix some renderer gotchas
unrealize() needs to clean up the surface that was set
in realize(), and both need to emit property change
notification.
2023-05-10 20:21:54 -04:00
Matthias Clasen
845f4b1536 gsk: Drop an unused function 2023-05-10 20:21:12 -04:00
Matthias Clasen
1a93efecf3 gsk: Dispose the driver when the display is closed
This was the intention, but the object data by itself
does not achieve that: We do run dispose on the display
when it is closed, but object data is only cleared in
finalize. So listen to the ::closed signal and remove
the driver ourselves.

Fix up the drivers dispose implementation enough for
that to actually work.
2023-05-10 20:21:12 -04:00
Matthias Clasen
97bc4f77c6 gsk: Fix a refcounting mishap
This may fix #5823
2023-05-09 06:56:09 -04:00
Matthias Clasen
5a156e6b5f rendernodeparser: Handle shader nodes better
Avoid criticals when editing shader nodes in
the node editor.
2023-05-06 14:33:45 -04:00
Benjamin Otte
2a950dec71 Merge branch 'wip/otte/update-texture' into 'main'
Add texture update regions

See merge request GNOME/gtk!5880
2023-05-06 00:59:25 +00:00
Matthias Clasen
e9f5a3e9e2 gsk: Introduce a constant
We need this number in a couple of places,
so pull it out as a constant.
2023-05-05 12:05:10 -04:00
Matthias Clasen
2b85c49fb1 gsk: Add a few assertions
Make sure we don't overflow our fixed-size arrays.
2023-05-05 12:05:10 -04:00
Matthias Clasen
d7c3235cd0 gsk: Add some debug helpers 2023-05-05 12:05:09 -04:00
Matthias Clasen
81fd9741ff gsk: Better handling of offscreens
Take the scale into account for sizing the
offscreens for masks, blends and cross-fades.
2023-05-05 11:37:23 -04:00
Matthias Clasen
ce6569d1a6 gsk: Avoid some offscreens
We don't have to be too conservative when checking
if a rect is contained in a rounded rect, we have
a precise api for this.
2023-05-04 22:30:12 -04:00
Benjamin Otte
cc7a35cd30 Merge branch 'wip/otte/for-main' into 'main'
build: Use generated SPIR-V files

Closes #5798

See merge request GNOME/gtk!5910
2023-05-02 18:09:13 +00:00
Benjamin Otte
f99ecd3739 vulkan: Compute offscreen texture coords properly
Most of the time we want to compute them based on the child node we
render to the offscreen, but not always.
For blend and cross-fade nodes, they need to be computed based on the
node's bounds.

Fixes widget-factory page fade animation weirdly resizing the fading
pages.
2023-05-02 19:44:06 +02:00
Benjamin Otte
9b558b50b8 vulkan: Rebuild SPIR-V files
It's been a while since somebody last compiled them, glslc should be
somewhat newer by now.
2023-05-02 08:47:10 +02:00
Benjamin Otte
7ce2eeac47 build: Use generated SPIR-V files
We weren't looking in the build dir for generated files.

Actually make sure that we look in the build dir *first*, otherwise
glib-compile-resources will still use the wrong files.
2023-05-02 08:41:43 +02:00
Matthias Clasen
17d2ba94d6 stop using deprecated pango api 2023-05-01 23:49:42 -04:00
Benjamin Otte
e4040adbe7 rendernode: Implement texture diffing for scale nodes 2023-05-02 00:30:58 +02:00
Benjamin Otte
1883035d34 texture: Add gdk_texture_diff()
... and use it in rendernodes.

Setting up textures for diffing is done via gdk_texture_set_diff() which
should only be used during texture construction.

Note that the pointers to next/previous are allowed to dangle if one of
the textures is finalized, but that's fine because we always check both
textures' links to each other before we consider the pointer valid.
2023-05-01 22:24:14 +02:00
Matthias Clasen
b79d4a3a22 gsk: Fix rendering big textures with offsets
When slicing the texture, the GL renderer was
forgetting to apply the viewport origin. This
shows up when rendering things with negative
scales, leading to negative origins.
2023-05-01 14:46:30 -04:00
Matthias Clasen
319762b908 gsk: Extract scales properly from 2D transforms
We have the code to do it properly.
2023-05-01 13:45:20 -04:00
Matthias Clasen
e453a989df Improve rounded rect intersection
Move the rounded rect/rect intersection code to
gskroundedrect.c, make it more precise, and add
tests for it.

Update the callers in the GL renderer.
2023-05-01 13:45:20 -04:00
Matthias Clasen
f56328a6cc gsk: Fix mask transform handling
We must reset the modelview transform when
offscreen, or else we end up applying
it twice.
2023-05-01 13:45:20 -04:00
Matthias Clasen
552df197c4 gsk: Fix blend transform handling
We must reset the modelview transform when
rendering offscreen, or else we end up applying
it twice.
2023-05-01 13:45:20 -04:00
Matthias Clasen
4214067d52 gsk: Fix cross-fade transform handling
We must reset the modelview transform when
rendering offscreen, or else we end up applying
it twice.
2023-05-01 13:44:55 -04:00
Matthias Clasen
d9a2b74b4a gsk: More fixes
Work towards handling negative scales and
denormalized rects everywhere.
2023-05-01 13:43:33 -04:00
Matthias Clasen
4e501d2d44 gsk: Transform rounded rects better 2023-05-01 13:43:33 -04:00
Matthias Clasen
ad65db901a gsk: Normalize rects in GLSL
Our coverage computation only works for well-behaved
rects and rounded rects. But our modelview transform
might flip x or y around, causing things to fail.

Add functions to normalize rects and rounded rects,
and use it whenever we transform a rounded rect in GLSL.
2023-05-01 13:43:33 -04:00
Matthias Clasen
2f96a08b3f gsk: Plug a few memory leaks 2023-04-30 18:21:23 -04:00
Benjamin Otte
3198330188 rendernode: Add diffing for affine transforms
This will be needed most importantly for inverted textures,
like in GLArea.
2023-04-29 05:10:51 +02:00
Benjamin Otte
76777cdd18 Merge branch 'wip/otte/texturebuilder' into 'main'
Add GdkGLTextureBuilder

See merge request GNOME/gtk!5862
2023-04-28 15:58:10 +00:00
Matthias Clasen
92a9f8cd7e gldriver: Add a sync when creating textures 2023-04-28 06:23:45 +02:00
Matthias Clasen
051b463c9a Fix various bitfield warnings
clang rightly complains about using gboolean
as type for bitfields, since it is signed.
Avoid that.
2023-04-27 13:42:03 +02:00
Matthias Clasen
8292b846d5 gsk: Synchronize when using textures
Pass the GLsync object from texture into our
command queue, and when executing the queue,
wait on the sync object the first time we
use its associated texture.
2023-04-27 06:57:02 +02:00
Benjamin Otte
76e5fd0ece glrenderer: Port to GdkGLTextureBuilder 2023-04-27 06:40:47 +02:00
Benjamin Otte
3aefed39b1 glcontext: Use GdkGLVersion elsewhere
... and add a convenience API to generate GL versions from strings to
make the gdk_gl_context_check() API nicer.
2023-04-27 02:13:32 +02:00
Matthias Clasen
74c0171edf gsk: Don't misuse bitwise operators
We should use && for booleans, not &=.
2023-04-25 16:43:02 +02:00
Matthias Clasen
2263db6259 gsk: Don't misuse bitwise operators
We should use || for booleans, not |=.
2023-04-25 13:45:37 +02:00
Matthias Clasen
83091c4f15 gsk: Use explicit switches
This makes it harder to forget to add new
node types here.
2023-04-19 09:19:12 +02:00
Matthias Clasen
503a5de7d1 gsk: Mask nodes support 2d transforms
When adding mask nodes, I overlooked that
we have two separate functions for determining
what transforms a node supports without offlines.

Since we claim that mask nodes support general
transform, they must certainly support 2d transforms
as well.
2023-04-19 08:13:55 +02:00
Benjamin Otte
8965d6c7f8 gl: Only allow RGB(A)8 on GLES2
GLES2 has no idea what 16bit textures even are, let alone floating point.
2023-04-17 05:57:44 +02:00
Benjamin Otte
d7309a009c glrenderer: Don't try to use float framebuffers on GLES2
GLES doesn't know what that is.
2023-04-17 05:57:44 +02:00
Benjamin Otte
d37b9619e2 gles: Don't use vertex array objects
They're not needed and GLES doesn't technically support them, even
though GTK had been using them via epoxy sneakily using the
GL_OES_vertex_array_object extension behind our back.
2023-04-15 17:55:20 +02:00
Georges Basile Stavracas Neto
94b1a78378 gsk/vulkan/render: Download image before reset
gsk_vulkan_render_download_target() currently resets the uploader
objects before downloading the image that it produces. This is
problematic because there might be unreleased buffers and images
in the command queue.

In particular, this can make validation layers complain about the
glyph atlas - of all things! - upload buffer being released while
still being used by the command queue.

Fix that by resetting the uploader after downloading the image.
2023-04-14 16:43:04 -03:00
Georges Basile Stavracas Neto
496c8f4a11 gsk/vulkan/glyphcache: Rework glyphs
The current implementation of the glyph cache deals with atlases by
padding them with 1 pixel at the beginning, at the end, and between
each glyph.

That's cool and all, however, there's a very subtle problem with
this approach: the contents of the atlas are garbage, so this padding
is filled with garbage memory!

Rework the Vulkan glyph cache to draw each and every glyph in a
surface that has 1 pixel border of padding around it. Ensure the
surface is completely black by drawing a rectangle before handing
it to Pango to draw the glyph. Update tx and ty to pick the texture
position adjusted to the 1 pixel padding. The atlas now starts at
position (0, 0), since each glyph individually contains its own padding.

To improve legibility, add a PADDING define and use it everywhere.
2023-04-08 20:13:13 -03:00
Georges Basile Stavracas Neto
8b6f69946c gsk/vulkan/pipeline: Simplify pipeline creation
Nothing uses gsk_vulkan_pipeline_new_full() anymore.
2023-04-08 20:13:13 -03:00
Georges Basile Stavracas Neto
48129298f0 gsk/vulkan: Use default blend factors
Vulkan renders text using VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA and
VK_BLEND_FACTOR_SRC_ALPHA, but that implies per-channel alpha
blending, which currently produces the wrong results when blending
glyphs with the images beneath them.

Use the default pipeline constructors, which implies using the
ONE and ONE_MINUS_SRC_ALPHA.
2023-04-08 20:13:13 -03:00
Georges Basile Stavracas Neto
c77c8d6309 gsk/vulkan: Cosmetics
Reorder code to match the order used in shaders.
2023-04-08 20:13:13 -03:00
Benjamin Otte
4d86954fb5 rendernode: Cosmetics
Simplify a function.
2023-04-03 19:27:58 +02:00
Benjamin Otte
6e8c3fc3ff rendernode: Get rid of GskRenderNodeTypeInfo
Instead, use class_init functions.
2023-04-03 19:27:58 +02:00
Benjamin Otte
0d139a81c7 rendernode: Remove instance_init() function
It's not used.
2023-04-03 19:27:58 +02:00
Georges Basile Stavracas Neto
5c27a0dd2b vulkan: Support fractional scaling
Basically what GL does, but without any debug or feature flag
to gatekeep it, since the Vulkan backend itself is experimental
already.

Ceil surface sizes, and floor coordinates, to the fractional scale
value.
2023-04-03 11:10:27 -03:00
Georges Basile Stavracas Neto
db1d278100 gsk/vulkan/renderpass: Don't scale scissor and render area
The rects passed to the clip region are in buffer coordinates, and
must not be scaled. Consider the following scenario: Wayland, with
a 1024x768@2 window. That gives us a 2048x1536 raw image. To setup
the Vulkan render pass code, we'd scale 2048x1536 *again*, to an
unreasonable 4196x3072, which is (1) incorrect and (2) really
incorrect and (3) can lead to crashes at best, full GPU resets
at worst - and a GPU reset is incredibly not fun!

Now that we pass the right clip regions at the right coordinates
at all times, remove the extra scaling from the render pass.
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
dde029c3d1 gsk/vulkan: Cosmetics
No functional changes. Use a variable that already exists instead
of calling gdk_draw_context_get_surface() again. Cleanup some
newlines.
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
a2a05acc6b gsk/vulkan/renderer: Pass appropriate clip region
This part of the Vulkan renderer is almost exactly equal to the GL
renderer, and the GL renderer already does that since at least
2a38cecd33. Copy that into the Vulkan renderer.

A nice side effect from this commit is that resizing a window now
actually works again.

Sneak in a trivial cleanup by using a variable to hold the draw
index.
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
840c72d74d gsk/vulkan/buffer: Pass aligned memory value
This was a tricky one to figure out, but it's pretty simple to
understand (I hope!).

So, this AMD card I'm using requires buffer memory sizes to be
aligned to 16 bytes. Intel is aligned to 4 bytes I think, but
AMD - or at least this AMD model in particular - uses 16 bytes
for alignment.

When creating a a particular texture (I did not determin which one
specifically!) a buffer of size 1276 bytes is requested.

1276 / 16 = 79.75, which is clearly not aligned to the required
16 bytes.

We request Vulkan to create a buffer of 1276 bytes for us, it
figures out that it's not aligned, and creates a buffer of 1280
bytes, which is aligned. The extra 4 bytes are wasted, but that's
okay. We immediately query this buffer for this exact information,
using vkGetBufferMemoryRequirements(), and proceed to create actual
memory to back this buffer up.

The buffer tells us we must use 1280 bytes, so we pass 1280 bytes
and everyone is happy, right? Of course not. We pass 1276 bytes,
and Vulkan is subtly unhappy at us.

Fix that by passing the value that Vulkan asks us to use, i.e.,
the size returned by vkGetBufferMemoryRequirements().
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
56c643306a gsk/vulkan/glyphcache: Ceil glyph surface size
This is what GL does, and for a reason: it can lead to width or
height for very small glyphs. Also, switch to dividing by a float
(1024.0) instead of an integer (1024).
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
57587c00b4 gsk/vulkanimage: Set buffer row length and height
This doesn't make any difference now, but will allow us to copy
subregions more easily. This is not obvious, but here's a quick
explanation:

Leaving 'bufferRowLength' and 'bufferImageHeight' implies that
Vulkan will assume the size passed in the 'imageExtent' field.
Right now, this assumption is correct - the only user of this
function is the glyph cache, and it only copies and uploads
exact rects. Next commits will change that assumption, so we
must pass 'buffer*' fields, and tell Vulkan, "this part of the
buffer represents an image of width x height, and I want the
subregion (x, y, smallerWidth, smallerHeight) of this image".
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
724d07ef8a gsk/vulkan/image: Use UNDEFINED for initial layout
When creating an image using gsk_vulkan_image_new_for_framebuffer(),
it passes VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.

However, this is a mistake. The spec demands that the initial
layout must be either VK_IMAGE_LAYOUT_UNDEFINED or
VK_IMAGE_LAYOUT_PREINITIALIZED.

Apparently this was an oversight from commit b97fb75146, since the
commit message even documents that, and all other calls pass either
VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.

Create framebuffer images using VK_IMAGE_LAYOUT_UNDEFINED, which is
what was originally expected.
2023-04-03 10:59:45 -03:00
Georges Basile Stavracas Neto
a33ddd54ac gsk/vulkan/image: Cosmetics 2023-04-02 19:29:55 -03:00
Matthias Clasen
4746ffc4eb Make fractional scaling for GL opt-in
Fractional scaling with the GL renderer is
experimental for now, so we disable it unless
GDK_DEBUG=gl-fractional is set.

This will give us time to work out the kinks.
2023-04-02 11:05:57 -04:00
Matthias Clasen
fa58dd9256 Use fractional scale for the GL renderer
This commit combines changes in the Wayland backend,
the GL context frontend, and the GL renderer to switch
them all to use the fractional scale.

In the Wayland backend, we now use the fractional scale
to size the EGL window.

In the GL frontend code, we use the fractional scale to
scale the damage region and surface in begin/end_frame.

And in the GL renderer, we replace gdk_surface_get_scale_factor()
with gdk_surface_get_scale().
2023-04-02 09:22:56 -04:00
Matthias Clasen
519cde95f0 gsk: Cosmetics
Rename scale_factor to scale in various places,
now that it is no longer an int but a float.
2023-04-02 09:06:56 -04:00
Matthias Clasen
01108d4148 gsk: Pass scale as float to the command queue 2023-04-02 09:06:56 -04:00
Georges Basile Stavracas Neto
70e6bcce16 Merge branch 'gbsneto/mildly-mid-vulkan-fixes' into 'main'
Vulkan transform / scale fixes

See merge request GNOME/gtk!5757
2023-04-01 18:23:12 +00:00
Georges Basile Stavracas Neto
f3b8bd8a98 gsk/gl/renderjob: Decompose matrix for 3D transforms
While this can be more expensive, it's also correct.
2023-04-01 14:47:29 -03:00
Georges Basile Stavracas Neto
ee1730dd49 gsk/vulkan/renderpass: Update scales from transform node
Retrieve the scale from the transform node, and store it as long
as the transform node is being visited. This applies the proper
scale to text nodes.
2023-04-01 14:47:29 -03:00
Georges Basile Stavracas Neto
e0aaf9bc83 gsk/vulkan/renderpass: Refactor scale
Instead of tracking a single scale, track x and y scales separately.
Factor out gsk_vulkan_render_pass_new() into a private function that
receives both scales, and pass 'scale_factor' for both.
2023-04-01 14:46:56 -03:00
Matthias Clasen
a1c5a806b3 Convert headers to #pragma once
The conversion was done by guard2one.
2023-03-31 15:11:10 -04:00
Georges Basile Stavracas Neto
b1a8c0e686 gsk/vulkan/renderpass: Factor out node implementations
This is mostly a cosmetic change, and the goal is twofold:

 1. Make it easier to spot unimplemented render node types; and
 2. Prepare for a small rework

The implementation for each node now lives in specific functions,
like the GL renderer; unlike the GL renderer, however, we use a
node type vtable to map GskRenderNodeType → implementation. Render
node without an implementation map to NULL, and use the fallback
implementation. Render nodes that fail any check and return FALSE
also use fallback implementation.
2023-03-31 14:00:33 -03:00
Georges Basile Stavracas Neto
c85599e2e8 gsk/vulkanglyphcache: Cleanup maths
A trivial cleanup to match what the GL renderer does
2023-03-30 17:13:35 -03:00
Georges Basile Stavracas Neto
981e94505c vulkan/glyphcache: Add padding around ink rect
This is what the GL renderer does, and it gets rid of the cutout
characters.
2023-03-30 17:13:35 -03:00
Benjamin Otte
1449e487d3 Merge branch 'wip/otte/node-naming' into 'main'
node format: Allow naming textures and nodes

See merge request GNOME/gtk!5740
2023-03-29 11:28:15 +00:00
Benjamin Otte
0d6a6a5997 rendernodeparser: Detect duplicates and print them by name
If we encounter a node or texture the 1st time and they are going
to be used again, give them a name.

Then, when encountering them again, print them by name instead
of duplicating them.
2023-03-29 03:53:52 +02:00
Benjamin Otte
5a0c4de07f rendernodeparser: Add support for reusing nodes
We extend the syntax for nodes from:
  <node-type> { ... }
to
  <node-type> { ... }
  <node-type> <string> { ... }
  <string>;
where the first is the same as before, the 2nd defines a named node and
the last references a previously defined node.
Or to give an example:
  color "node" {
    bounds: 0 0 10 10;
    color: red;
  }
  transform {
    bounds: 20 0 10 10;
    child: "node";
  }
This will draw the red box twice, once at (0,0) and once at
(20,0).

The intended use for this is both shortening generated node files as
well as allowing to write tests that reuse nodes, in particular when
dealing with caches.
2023-03-29 03:53:52 +02:00
Benjamin Otte
348a68599a rendernodeparser: Add support for reusing textures
We extend the syntax for textures from just:
  <url>
to
  [<string>] <url>
  <string>
where the first defines a named texture while the second references a
texture.
Or to give an example:
  texture {
    bounds: 0 0 10 10;
    texture: "foo" url("foo.png");
  }
  texture {
    bounds: 20 0 10 10;
    texture: "foo";
  }
This will draw the texture "foo.png" twice, once at (0,0) and once at
(20,0).

The intended use for this is both shortening generated node files as
well as allowing to write tests that reuse textures, in particular when
mixing them in texture and texture-scale nodes.
2023-03-29 03:53:52 +02:00
Benjamin Otte
8590b1ef11 rendernodeparser: Add a Context object
... and pass it through all the parsing functions.

So far it's unused, this is just the plumbing.
2023-03-29 03:53:52 +02:00
Benjamin Otte
d1f27c281d rendernodeparser: Split out a function
This code was copy/pasted, so unify it.
2023-03-29 03:53:52 +02:00
Benjamin Otte
76ff2f5410 rendernodeparser: Emit error when failing to resolve URL 2023-03-29 03:53:52 +02:00
Benjamin Otte
1605b07ff5 rendernodeparser: Failing to parse a string is an error
Testcase included.
2023-03-29 03:53:52 +02:00