Commit Graph

142 Commits

Author SHA1 Message Date
Lee Salzman
2d2fbf6a35 Bug 1834079 - Move stroke fallback heuristic to after we attempt AA-Stroke. r=jrmuizel
We have a heuristic that falls back from stroking certain paths with acceleration because
both WGR and the texture cache can have slow output as the size of the path increases in
screen area. AA-Stroke tends to have better output for these paths, or at least, this heuristic
tends to have a detrimental effect on AA-Stroke usage and performance in important tests.
Lets move the heuristic to after we use AA-Stroke for now.

Differential Revision: https://phabricator.services.mozilla.com/D178549
2023-05-19 21:08:45 +00:00
Narcis Beleuzu
c2b53cef14 Backed out changeset cdb59ad562ed (bug 1834079) for wr failure on devicepixel.html CLOSED TREE 2023-05-19 20:53:29 +03:00
Lee Salzman
47c9b349e6 Bug 1834079 - Move stroke fallback heuristic to after we attempt AA-Stroke. r=jrmuizel
We have a heuristic that falls back from stroking certain paths with acceleration because
both WGR and the texture cache can have slow output as the size of the path increases in
screen area. AA-Stroke tends to have better output for these paths, or at least, this heuristic
tends to have a detrimental effect on AA-Stroke usage and performance in important tests.
Lets move the heuristic to after we use AA-Stroke for now.

Differential Revision: https://phabricator.services.mozilla.com/D178549
2023-05-19 16:17:53 +00:00
Lee Salzman
5abbad6d84 Bug 1831414 - Ensure patterns get transformed when using WGR. r=aosmond,gfx-reviewers,ahale
Differential Revision: https://phabricator.services.mozilla.com/D177342
2023-05-06 21:02:57 +00:00
Lee Salzman
7437eceb36 Bug 1831391 - Only treat WebGL context as clear on new frame if its still valid. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D177310
2023-05-05 20:01:47 +00:00
Lee Salzman
5833d07410 Bug 1825293 - Treat alpha textures as luminance for bitmap data. r=aosmond
For cases where bitmaps are compressed down to alpha textures, the underlying
assumption is that these were supposed to be treated as luminance data as well
in the shader, or rather, the alpha represents both the opacity and intensity.
We weren't properly swizzling in the shader to accomplish this. This fixes that.

Differential Revision: https://phabricator.services.mozilla.com/D176986
2023-05-03 14:05:26 +00:00
Lee Salzman
d2671b47c1 Bug 1829468 - Avoid uploading directly to framebuffer texture. r=aosmond
It seems that using a texture as a backing surface for a framebuffer
while simultaneously trying to use TexSubImage to upload to it aggravates
OpenGL driver bugs regarding the underlying representation of that
texture.

Given that I couldn't find an expedient way to preserve that optimized
upload path, instead we have to fallback to just uploading the sampling
rect of the surface to a transient texture that is then drawn via shader
to framebuffer.

Differential Revision: https://phabricator.services.mozilla.com/D176240
2023-04-25 13:58:47 +00:00
Lee Salzman
1801a6bc0f Bug 1828904 - Only accelerate with clear if rect is sufficiently large. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D176073
2023-04-20 19:19:15 +00:00
Lee Salzman
1a8180292f Bug 1829058 - Cache scissor state in DrawTargetWebgl. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D175986
2023-04-20 14:27:52 +00:00
Lee Salzman
3a27b37e62 Bug 1828137 - Support accelerating large clearRects if they encompass entire viewport. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D175727
2023-04-18 15:08:27 +00:00
Lee Salzman
769f7821de Bug 1821512 - Fix Skia usage for API changes. r=jrmuizel
This just tries to address fairly random changes in the Skia API and correct
our usage of it in Moz2D and some other places.

Differential Revision: https://phabricator.services.mozilla.com/D173324
2023-04-16 15:34:50 +00:00
Natalia Csoregi
a05ee28985 Backed out 6 changesets (bug 1821512) for failures on browser_screenshots_test_full_page.js. CLOSED TREE
Backed out changeset a31f2795710e (bug 1821512)
Backed out changeset 3985c29a6490 (bug 1821512)
Backed out changeset 0d9814a43a4d (bug 1821512)
Backed out changeset e5570884e8e4 (bug 1821512)
Backed out changeset efc92c86fafd (bug 1821512)
Backed out changeset 3222f6498a44 (bug 1821512)
2023-04-16 11:30:32 +03:00
Lee Salzman
4433d5f17e Bug 1821512 - Fix Skia usage for API changes. r=jrmuizel
This just tries to address fairly random changes in the Skia API and correct
our usage of it in Moz2D and some other places.

Differential Revision: https://phabricator.services.mozilla.com/D173324
2023-04-16 04:00:00 +00:00
Iulian Moraru
af50da8673 Backed out 6 changesets (bug 1821512) for causing multiple failures. CLOSED TREE
Backed out changeset 97295a57babe (bug 1821512)
Backed out changeset 698104c7a5d1 (bug 1821512)
Backed out changeset 09aa18e47bf6 (bug 1821512)
Backed out changeset 20b46afb225f (bug 1821512)
Backed out changeset b531f604ea4c (bug 1821512)
Backed out changeset 0a7c0b0773d4 (bug 1821512)
2023-04-11 10:10:41 +03:00
Lee Salzman
2fc44a0d2f Bug 1821512 - Fix Skia usage for API changes. r=jrmuizel
This just tries to address fairly random changes in the Skia API and correct
our usage of it in Moz2D and some other places.

Differential Revision: https://phabricator.services.mozilla.com/D173324
2023-04-11 05:00:05 +00:00
Jamie Nicol
443e931b81 Bug 1826134 - Avoid interleaving glBufferSubData calls with draw calls in DrawTargetWebgl. r=gfx-reviewers,jgilbert,lsalzman
DrawTargetWebgl renders a path by uploading vertex data to the back of
a large VBO using glBufferSubData then issuing a draw call, orphaning
the buffer when it becomes full. This results in many glBufferSubData
calls being interleaved with draw calls. On Mali GPUs this causes
severe performance issues as the driver is unable to determine that
any pending draw calls do not reference the updated region of the
buffer, and therefore must create a copy of the buffer for each
update.

However, since *we* know that we never overwrite a region that is
referenced by a submitted draw call, we can force the driver to avoid
making these copies. We do so by adding a new function
UnsynchronizedBufferSubData(), which acts like BufferSubData so long
as this rule is followed. Internally, this uses glMapBufferRange with
GL_MAP_UNSYNCHRONIZED_BIT, allowing the driver to omit the extraneous
copies.

Differential Revision: https://phabricator.services.mozilla.com/D174685
2023-04-07 07:25:50 +00:00
Lee Salzman
46a7d5fadc Bug 1826420 - Fast-path non-aligned clip rects in DrawTargetWebgl. r=gfx-reviewers,aosmond
This adds interpolants to the AA distance calculation to handle the AA'ing of
the clip rect.

Differential Revision: https://phabricator.services.mozilla.com/D174650
2023-04-05 15:52:36 +00:00
Lee Salzman
3e5a0bc2f3 Bug 1816775 - Handle OP_CLEAR in DrawTargetWebgl. r=aosmond,gfx-reviewers
This implements OP_CLEAR by ensuring the shader always outputs a mask value that
represents coverage. Clear color is then blended in proportion to the coverage
value.

Depends on D171025

Differential Revision: https://phabricator.services.mozilla.com/D172956
2023-03-31 07:51:00 +00:00
Andi-Bogdan Postelnicu
fccbbc6b44 Bug 1660405 - Move away from mozilla::IsFinite in favor of std::isfinite. r=sergesanspaille
Differential Revision: https://phabricator.services.mozilla.com/D173036
2023-03-22 11:35:33 +00:00
Stanca Serban
98c675ed3f Backed out 7 changesets (bug 1660405) for causing bustages on Linux x64 opt. CLOSED TREE
Backed out changeset ad1a5f59214f (bug 1660405)
Backed out changeset a39e95f0aafe (bug 1660405)
Backed out changeset 48629ee0d70d (bug 1660405)
Backed out changeset 8419b99aab60 (bug 1660405)
Backed out changeset 535cc12c8bed (bug 1660405)
Backed out changeset e27052da4927 (bug 1660405)
Backed out changeset 11b0f9cf8091 (bug 1660405)
2023-03-22 13:05:53 +02:00
Andi-Bogdan Postelnicu
2e64d79ba8 Bug 1660405 - Move away from mozilla::IsFinite in favor of std::isfinite. r=sergesanspaille
Differential Revision: https://phabricator.services.mozilla.com/D173036
2023-03-22 09:27:57 +00:00
Lee Salzman
cc2bddc65e Bug 1821240 - Don't clear DrawTargetWebgl if already clear. r=aosmond,gfx-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D172086
2023-03-09 16:34:49 +00:00
Lee Salzman
db5c4f6c86 Bug 1820546 - Avoid fallbacks in DrawTargetWebgl::CopySurface. r=aosmond,gfx-reviewers
This implements some optimizations targeted at Canvas2D's putImageData:

1) Track whether the canvas is in the initially clear state so that we avoid
reading back from the WebGL framebuffer into the Skia framebuffer when a
fallback does occur or when a data snapshot is needed.

2) For surfaces that are too large to upload to a texture, directly use
glTexSubImage2D to draw data to the WebGL framebuffer, bypassing a separate
texture upload.

3) Disregard the surface size limits for SurfacePatterns containing a
compatible texture handle.

Differential Revision: https://phabricator.services.mozilla.com/D171773
2023-03-07 08:51:44 +00:00
Lee Salzman
defc1793b9 Bug 1777849 - Don't attempt to recreate DrawTargetWebgl's SharedContext again if WebGL initialization fails. r=ahale
If the user does not actually support WebGL 2, attempting to create a DrawTargetWebgl will always fail.
However, each time it goes to create a DrawTargetWebgl, it will try to initialize a WebGL 2 context again.
Each time it does this, if the user is using GLX, it will call XCreatePixmap and glXCreateContextAttribs,
which can run afoul of a libX11 race condition. This will happen on every page load where a new canvas is
encountered.

It would be better to note that the failure is non-recoverable and not try to use DrawTargetWebgl on
subsequent attempts. Here we set the sContextInitError value to indicate there are non-recoverable
errors, after which it will bypass attempting creation the next time.

This means the worst exposure the user will have to the libX11 race condition is once per process lifetime,
which should greatly reduce the incidence.

Differential Revision: https://phabricator.services.mozilla.com/D171016
2023-02-26 07:20:19 +00:00
Lee Salzman
f9b677c590 Bug 1817873 - Use line join for closed single line paths. r=aosmond
If we choose to accelerate a single line path, we need to take care not to use
the line cap when the path is closed. When the path is closed, we need to use
the line join instead.

Differential Revision: https://phabricator.services.mozilla.com/D170469
2023-02-21 18:03:37 +00:00
Lee Salzman
809ea4c52b Bug 1817455 - Limit rect precision to avoid shader rounding diverging from path fallback. r=gfx-reviewers,aosmond
Rectangle with large floating-point values can start to lose mantissa bits when transformed directly
by the vertex shader, pushed through the viewport transform, and then clipped later. OTOH, the path
fallback (WGR/AA-Stroke or Skia) does not stress floating-point precision as much, so generally
returns more correct results in these cases. This becomes noticeable when the same rectangle is
filled and then subsequently stroked, since the fill may use the rect shader, while the the stroke
will fall back to using a path.

To avoid hitting this issue, this checks if a rect's coordinate are outside as certain reasonable
limit, and if so, falls back to relying on path geometry to handle transform and clipping safely.
If within the limit, the shader precision loss doesn't noticeably impact the results so it is still
safe to use the fast-path.

Differential Revision: https://phabricator.services.mozilla.com/D170270
2023-02-20 21:30:08 +00:00
Jeff Muizelaar
1280a5a7ef Bug 1813774 - Actually hook up rasterization truncation support. r=lsalzman
I think this got blown away after my previous session debugging
why it didn't work.

Differential Revision: https://phabricator.services.mozilla.com/D168308
2023-01-31 14:38:03 +00:00
Lee Salzman
d243580bc7 Bug 1812970 - Avoid using Skia's deprecated clip ops. r=jrmuizel
Skia upstream removed deprecated clip ops that could be used to replace
the clipping stack and bypass clips. We shouldn't really need to do this
anymore, as we can work around it just using public APIs.

The only SkCanvas operation that allows us to bypass clipping is
writePixels, which still allows us to implement CopySurface/putImageData.

Other instances where we were using the replace op for DrawTargetWebgl
layering support can just be worked around by creating a separate
DrawTargetSkia pointing to the same pixel data, but on which no clipping
or transforms are applied so that we can freely do drawing operations
on it to the base layer pixel data regardless of any user-applied clipping.

Differential Revision: https://phabricator.services.mozilla.com/D168039
2023-01-28 11:24:54 +00:00
Jeff Muizelaar
57a1004505 Bug 1803375. Use different coordinates when running on AMD. r=lsalzman,jgilbert
This updates the version wpf-gpu-raster which adds support for
GPUs/drivers that use truncation instead of rounding when converting
vertices to fixed point.

It also adds the GL vendor to InitContextResult so that we can detect
AMD on macOS and tell wpf-gpu-raster that truncation is going to happen.

Differential Revision: https://phabricator.services.mozilla.com/D167503
2023-01-27 01:45:17 +00:00
Lee Salzman
70ba777d1a Bug 1806392 - Add a debug indicator for Accelerated Canvas2D. r=aosmond
This adds a debug indicator controlled by the pref gfx.canvas.accelerated.debug.
A green square is drawn in the upper right corner of the canvas to let us know if
acceleration is being used or not.

Differential Revision: https://phabricator.services.mozilla.com/D165018
2022-12-19 13:59:14 +00:00
Lee Salzman
53ada74867 Bug 1806058 - Add blocklist for Accelerated Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D164881
2022-12-16 20:15:49 +00:00
Lee Salzman
940e74869b Bug 1805231 - Handle zero-length capped lines. r=aosmond
Avoid causing a divide-by-zero when a stroked line is zero-length and only the cap is rendered.

Differential Revision: https://phabricator.services.mozilla.com/D164536
2022-12-13 18:43:06 +00:00
Lee Salzman
1dd5ff25d5 Bug 1752841 - Add ExtractSubrect API to SourceSurface. r=jrmuizel
CanvasRenderingContext2D relies upon CreateSimilarDrawTarget to create extract
a subrect from a surface to draw. However, DrawTargetWebgl does not return an
accelerated DT for that API as creating an entirely new context can be quite
expensive.

To work around this, this adds a specific ExtractSubrect API for SourceSurface
that can bypass the entire need to create a temporary DrawTarget to copy into.

Differential Revision: https://phabricator.services.mozilla.com/D164118
2022-12-07 21:06:32 +00:00
Lee Salzman
489c98bb18 Bug 1804340 - Generate path vertexes into pre-allocated output buffer. r=jrmuizel
This pre-allocates a vertex output buffer in DrawTargetWebgl so that we can generate
wpf-gpu-raster and aa-stroke output into it. This way, they don't have to realloc
a Vec for pushes or changing into a boxed slice. This can net 5-10% on profiles for
the demos noted in the bug.

Depends on D163989

Differential Revision: https://phabricator.services.mozilla.com/D163990
2022-12-07 00:53:55 +00:00
Lee Salzman
fc0208ec9c Bug 1803843 - Improve path cache reuse in DrawTargetWebgl. r=jrmuizel
This increases the amount of quantization applied to path cache entries
to 0.25 increments (2 bits of subpixel precision), leading to 4x4=16
subpixel buckets in total along both axes.

Differential Revision: https://phabricator.services.mozilla.com/D163749
2022-12-03 08:47:24 +00:00
Lee Salzman
8e69c8b8ca Bug 1803604 - Use aa-stroke to accelerate stroked paths in Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D163609
2022-12-03 08:21:50 +00:00
Cosmin Sabou
83bb7f69c7 Backed out 2 changesets (bug 1803604) for causing talos crashes on pdfpaint.
Backed out changeset 0be171a7d6ac (bug 1803604)
Backed out changeset 9c9e6c4e7864 (bug 1803604)
2022-12-03 02:59:04 +02:00
Lee Salzman
8f780c31c9 Bug 1803604 - Use aa-stroke to accelerate stroked paths in Canvas2D. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D163609
2022-12-02 19:49:38 +00:00
Lee Salzman
70d581c04f Bug 1802625 - Allow strokes to be cached as textures even when GPU stroking is off. r=jrmuizel
This fixes an incidental bug with the pref to turn off GPU stroking. It's not supposed to disable
caching strokes as textures. This allows that to work again even if prefed off.

Differential Revision: https://phabricator.services.mozilla.com/D163307
2022-11-29 20:26:41 +00:00
Lee Salzman
7e9ef6f378 Bug 1802625 - Hide GPU path stroking behind a pref. r=jrmuizel
It seems like this is slow for now until we implement a better way than WPF-gpu-raster
for stroking paths. Just hide this behind a pref so we can at least test it but not
impact performance as badly.

Differential Revision: https://phabricator.services.mozilla.com/D163248
2022-11-28 20:31:02 +00:00
Lee Salzman
61d16aa3be Bug 1801539 - Attempt to cache the state of the clip mask for when mask is regenerated. r=aosmond
For use-cases that repeatedly pop and re-push the same clips over and over, we can regenerate the
same mask that is already still stored, because we only detect that clip state changed, rather than
that it changed to exactly the same state it was previously.

This just remembers the previous state of the clip stack at the time the clip mask was generated
so that we can compare the previous and current state. If they're the same, we can assume there
is no need to regenerate the clip mask again and simply reuse it.

Differential Revision: https://phabricator.services.mozilla.com/D162699
2022-11-28 17:55:07 +00:00
Lee Salzman
6964f87eaf Bug 1801584 - Avoid relying on WebGL line smoothing. r=jrmuizel
WebGL doesn't reliably implement line smoothing, so we can't rely on it, making it
useless for canvas lines. Instead, just fall back to emulating it manually with paths.

Differential Revision: https://phabricator.services.mozilla.com/D162540
2022-11-28 17:54:44 +00:00
Lee Salzman
18e352a611 Bug 1801588 - Ensure region outside mask but inside clip is cleared for copy op. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D162536
2022-11-28 17:54:29 +00:00
Lee Salzman
d2518aee80 Bug 1801548 - Ignore round cap-style for sufficiently thin lines. r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D162498
2022-11-28 17:54:14 +00:00
Lee Salzman
2b59df83a4 Bug 1801446 - Limit the maximum complexity of paths used with wpf-gpu-raster. r=jrmuizel
Some paths may contain so many types that their vertex representation far exceeds their
software rasterized representation in memory size. As a sanity-check, we should just set
a hard limit on the maximum allowed complexity of a path that we attempt to supply to
wpf-gpu-raster. Beyond that, we will instead just rasterize in software and upload
to a texture which can be more performant.

Differential Revision: https://phabricator.services.mozilla.com/D162481
2022-11-22 05:25:59 +00:00
Lee Salzman
44cc796509 Bug 1800826 - Remove all clips when reusing a target in Canvas2D. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D162237
2022-11-17 03:10:35 +00:00
Lee Salzman
56e89ddb81 Bug 1800581 - Use optimized snapshots for drawImage if canvases share internal context. r=aosmond
By default, BorrowSnapshot is pessimistic and forces DrawTargetWebgl to return a data snapshot on
the assumption that the snapshot might be used off thread. However, if we actually know the DrawTarget
we're going to be drawing the snapshot to, then we can check if they're both DrawTargetWebgls with
the same internal SharedContext. In that case, we can use a SourceSurfaceWebgl snapshot which can
pass through a GPU texture to the target. This requires us to plumb the DrawTarget down through
SurfaceFromElement all the way to DrawTargetWebgl to make this decision.

Differential Revision: https://phabricator.services.mozilla.com/D162176
2022-11-17 03:07:18 +00:00
Lee Salzman
954f87098c Bug 1799402 - Use WGR to rasterize paths in DrawTargetWebgl. r=jrmuizel
This adds a path vertex buffer where triangle list output from WGR is stored.
Each PathCacheEntry can potentially reference a range of vertexes in this buffer
corresponding to triangles for that entry. When this buffer is full, it gets
orphaned and clears corresponding cache entries, so that it can start anew.

Differential Revision: https://phabricator.services.mozilla.com/D161479
2022-11-12 08:06:44 +00:00
Iulian Moraru
f876a9fbe3 Backed out 3 changesets (bug 1799402) for causing windows build bustages. CLOSED TREE
Backed out changeset e51cd76008ef (bug 1799402)
Backed out changeset 3ff660b475ff (bug 1799402)
Backed out changeset 9cfa7581565e (bug 1799402)
2022-11-12 08:33:24 +02:00
Lee Salzman
d603ff9f26 Bug 1799402 - Use WGR to rasterize paths in DrawTargetWebgl. r=jrmuizel
This adds a path vertex buffer where triangle list output from WGR is stored.
Each PathCacheEntry can potentially reference a range of vertexes in this buffer
corresponding to triangles for that entry. When this buffer is full, it gets
orphaned and clears corresponding cache entries, so that it can start anew.

Differential Revision: https://phabricator.services.mozilla.com/D161479
2022-11-12 05:42:30 +00:00