Commit Graph

101 Commits

Author SHA1 Message Date
Matthias Clasen
1c90bb522e ngl: Handle negative scales
Scale factors can be negative, but we were not
looking out for that, triggering an assertion when
trying to create a render target with negative
width of height. Avoid that.

Fixes: #4096
2021-07-15 16:40:13 -04:00
Matthias Clasen
c799452973 ngl: Do nothing for transparent text nodes
Like the previous commit - a transparent text node
will not produce any visible pixels, so bail out early.
2021-07-15 13:18:23 -04:00
Matthias Clasen
fd48afb77d ngl: Do nothing for transparent color nodes
No need to send commands to the GPU to render transparency.
2021-07-15 13:18:23 -04:00
Matthias Clasen
fc9c34897a ngl: Make the C half-float implementation accessible
Make this accessible for tests.
2021-07-13 09:03:49 -04:00
Matthias Clasen
f45c0b9609 gsk: Another vbo_size overflow fix
We can overflow vbo_size not just by batching
too much, but also by producing humongous text
nodes. Split them up.
2021-06-29 15:22:40 -04:00
Matthias Clasen
9ea162034a gsk: Use the right limit for batch size
We use 16 bits, so G_MAXINT16 is one bit short.
Just make it explicit as 0xffff.
2021-06-29 15:21:45 -04:00
Matthias Clasen
bd5e5beee0 gsk: Don't overflow vbo_count
We use 16 bits to store vbo_count, so we can't create
batches that have more than 65535 vertices. Pay attention
to that limit when merging batches.
2021-06-28 15:00:41 -04:00
Matthias Clasen
7a493f151d Revert "gsk: Respect max element vertices limitation"
This reverts commit f58fc6b22e.
2021-06-28 14:50:58 -04:00
Matthias Clasen
f58fc6b22e gsk: Respect max element vertices limitation
We are pretty good at batching commands now, and we can easily
produce batches that exceed the maximum number of elements per
draw call that the hw can handle. Query that number, and respect
it when merging batches.

This fixes the rendering of the overview map in GtkSourceView.
2021-06-18 06:50:59 -07:00
Matthias Clasen
2d266d107b gsk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Matthias Clasen
4a0d3d7acc docs: Reduce redundancy
Remove a boatload of "or %NULL" from nullable parameters
and return values. gi-docgen generates suitable text from
the annotation that we don't need to duplicate.

This adds a few missing nullable annotations too.
2021-05-20 20:45:06 -04:00
Matthias Clasen
66b4f0cac4 ngl: Reuse texture coordinates
When uploading glyphs, reuse the position that
we get from gsk_ngl_texture_library_pack, instead
of recomputing it.
2021-05-15 22:23:14 -04:00
Matthias Clasen
81e0206465 ngl: Be consistent about padding
Make gsk_ngl_texture_library_pack always return
the position including the padding. And compute
texture coordinates accurately in all cases (we
were fudging the padding for standalone textures.
2021-05-15 22:21:26 -04:00
Matthias Clasen
cb1babeeba ngl: Add padding between cached glyphs
Without this, adjacent items in the cache sometimes
bleed into the texture for a glyph.
2021-05-15 22:15:05 -04:00
Matthias Clasen
8e7bc8d742 Improve transformed offscreen rendering
Preserve the scale for 2D transforms to
avoid a pixellated appearance.
2021-05-13 19:37:16 -04:00
Matthias Clasen
930ff499ee Confine -mf16c to a single source file
We can't use this flag for any code that may get run
outside the __builtin_cpu_supports() check, and meson
doesn't allow per-file cflags. So we have to split this
code off into its own static library.
2021-05-05 18:58:23 -04:00
Alexander Mikhaylenko
ae7f380396 gsk: Fix shader gresource paths
They were never updated after having been moved.
2021-04-19 20:01:33 +05:00
Matthias Clasen
4465ee5414 Merge branch 'ngl-crash' into 'master'
ngl: Fix a rare assertion violation

Closes #3853

See merge request GNOME/gtk!3434
2021-04-13 22:02:44 +00:00
Matthias Clasen
c66b030427 ngl: Fix a rare assertion violation
When we clean up the uniform allocations after a frame,
it can happen that our space requirements actually increase,
due to padding that depends on the order of allocations.

Instead of asserting that it doesn't happen, just make
it work by growing our allocation.

Fixes: #3853
2021-04-12 22:53:48 -04:00
Emmanuele Bassi
31e08d4629 gsk/ngl: Build with G_DISABLE_ASSERT enabled 2021-04-12 21:23:18 -04:00
Chun-wei Fan
d5ced21264 gsk/ngl/fp16.c: Implement runtime F16C detection on MSVC
We need to use __cpuid() to check for the presence of F16C instructions on
Visual Studio builds, and call the half_to_float4() or float_to_half4()
implementation accordingly, as the __builtin_cpu...() functions are strictly
for GCC or CLang only.

Also, since __m128i_u is not a standard intrisics type across the board, just
use __m128i on Visual Studio as it is safe to do so there for use for
_mm_loadl_epi64().

Like running on Darwin, we cannot use the alias __attribute__ as __attribute__
is also for GCC and CLang only.
2021-04-12 18:13:42 +08:00
Matthias Clasen
849692b24b ngl: Fix unevenly scaled shadows
Ensure that we don't cut them off at the edges.
2021-04-11 22:35:02 -04:00
Matthias Clasen
f3bf4e4876 ngl: Don't slice unsliceable shadows
When the corners are too big to make slicing work,
don't do it, since it leads to broken results.
2021-04-11 22:10:33 -04:00
Matthias Clasen
46270d3dcd ngl: Fix a case of flipped shadow
In the non-sliced case, we were rendering the shadow
upside down.
2021-04-11 22:10:33 -04:00
Matthias Clasen
da6096faaf ngl: Add code to dump shadows
This can be helpful in understanding shadow bugs.
2021-04-11 21:13:47 -04:00
Matthias Clasen
1d9c581f10 ngl: Allow passing bounds to update_clip
update_clip only uses the bounds of the node that
we are currently passing. This opens the door to
updating the clip while handling a single node.
2021-04-11 12:54:17 -04:00
Matthias Clasen
6bfb57db16 ngl: Small optimization for shadows
When 9-slicing shadows, omit the center tile when it is
entirely contained in the outline (that is not always
the case, depending on corners and offsets).
2021-04-11 12:54:07 -04:00
Matthias Clasen
aaf17fd3d0 ngl: Small optimization
We really want equality here.
2021-04-11 12:50:50 -04:00
Matthias Clasen
bfe4aea981 ngl: Add a program change counter
Count how often we change programs during a frame.
2021-04-09 00:52:18 -04:00
Matthias Clasen
0caa28c1de ngl: Optimize underlines in text
Opportunistically use the coloring program for
drawing underlines instead of the color program.
This avoids program changes in the middle of
text.

For the Emoji text scrolling benchmark, this reduces
the program changes per frame from > 1000 to around 100.
2021-04-08 23:37:51 -04:00
Matthias Clasen
d8ba4b4114 ngl: Reserve a pixel in texture atlases
This will be used for coloring from the texture.
2021-04-08 23:34:37 -04:00
Matthias Clasen
e7963945bb ngl: Fix an oversight
All the rest of debug spew goes to stderr here.
2021-04-08 23:34:37 -04:00
Matthias Clasen
2d7169fd5f Work around compiler shortcomings on macOS
alias attributes don't work on Darwin, so
do without.
2021-04-07 22:38:47 -04:00
Matthias Clasen
885a6b8ebc gsk: Add runtime checks for F16C
Use an IFUNC resolver to determine whether we can use
intrinsics for FP16 conversion. This requires the functions
to be no longer inline.

Sadly, it turns out that __builtin_cpu_supports ("f16c")
doesn't compile on the systems where we want it to prevent
us from getting a SIGILL at runtime.
2021-04-07 22:21:23 -04:00
Matthias Clasen
9d81c129fc Add an option to disable F16C
And add a compile time check for the presence of this
CPU feature.
2021-04-07 22:21:23 -04:00
Matthias Clasen
38c6fe2ce4 Move color conversion up
Doing the color conversion early lets us reuse
the results whenever we do more than one draw
per node.
2021-04-07 21:30:43 -04:00
Matthias Clasen
7fe7b7ac7d ngl: Use a constant for (fp16)-1
No need to convert that again for every glyph.
2021-04-07 21:30:43 -04:00
Matthias Clasen
ae7f52d301 ngl: Reduce vertex storage
We only have one shader that uses the color2 attribute,
and it doesn't use the uv attribute, so save vertex
memory by putting those in the same space.

This reduce the per vertex space from 32 to 24 bytes.
2021-04-07 21:30:43 -04:00
Matthias Clasen
8b1fcb58e8 ngl: Use fp16 for colors
This reduces the size of our Vertex struct from
48 to 32 bytes. It would be nicer if we could store
the colors in fp16 format in the rendernodes, and
avoid conversion here. But this is still good.
2021-04-07 21:30:43 -04:00
Matthias Clasen
a1ece16143 ngl: Fix an oversight
We were special-casing 2D affine transforms,
but overlooked even simpler transforms.
2021-04-05 08:47:53 -04:00
Matthias Clasen
8d603dfe99 ngl: Avoid huge intermediate textures
Instead of rendering the unclipped child to a texture
(and risking blowing the texture size limit, and bad
downscaling), just render the clipped region, and live
with the fact that we can't cache the rendered texture.

This avoid bad artifacts when scrolling long textviews
in rounded clips.
2021-04-02 19:33:44 -04:00
Matthias Clasen
3ff04976e3 ngl: Plug a memory leak
This was introduced in f9457af128.
2021-04-02 18:41:53 -04:00
Matthias Clasen
54ff4fd45f ngl: Fix downscaled textures
It is not pretty, but at least it works now.
2021-04-02 18:33:01 -04:00
Matthias Clasen
f9457af128 ngl: Fix offscreen rendering with transforms
There was confusion here about the handling of the
modelview transform. The modelview transform we are
getting is already set up for rendering the node
we are given, so keep it - except for possible adding
an extra scale on top when the texture would otherwise
be too big.
2021-03-31 14:36:24 -04:00
Matthias Clasen
94f0a4ef2c ngl: Be explicit about offscreen clipping
Explicitly set all the input arguments.
This makes it clearer what is going on.
2021-03-31 14:34:16 -04:00
Matthias Clasen
53e75936cb ngl: Add sonme comments
The GskNglRenderOffscreen struct is a mix of in and
out arguments. Better annotate that a little bit.
2021-03-31 14:32:47 -04:00
Matthias Clasen
ba4e66d189 ngl: Avoid a goto
Reshuffle the code slightly, so we can use a continue
instead.
2021-03-30 00:34:52 -04:00
Matthias Clasen
2c33550048 gsk: Avoid empty glyphs early
Strip out PANGO_GLYPH_EMPTY when text nodes are
constructed. Then we don't have to check this special
case in the inner loop in visit_text_node.
2021-03-30 00:34:52 -04:00
Matthias Clasen
3add99a9a8 ngl: Speed up glyph loop
Move some work out of the loop in visit_text_node.
This takes advantage of the fact that the yoffset
of most glyphs is zero, so yphase generally does
not change in a line of text.
2021-03-30 00:19:28 -04:00
Matthias Clasen
d4ea2e848d ngl: We only need two bits for phases
We use 4 phases, so 2 bits are enough.
2021-03-30 00:19:28 -04:00