Commit Graph

220 Commits

Author SHA1 Message Date
Lee Salzman
23072be7ee Bug 1872646 - Only use DrawTargetWebgl::BeginFrame when actually mutating a canvas. r=aosmond
It's wasteful to call DrawTargetWebgl::BeginFrame if we're locking in a read-only mode. It may
also mess up DrawTargetWebgl's internal profiling if we count a read-only use as an actual frame.

Differential Revision: https://phabricator.services.mozilla.com/D197483
2024-01-02 19:35:04 +00:00
Andrew Osmond
11cefd8d0f Bug 1871613 - Ensure CanvasDrawEventRecorder releases external surface dependencies. r=gfx-reviewers,lsalzman
This patch makes CanvasDrawEventRecorder track what eventCount we
recorded an external surface reference. When the reader has increment
its processedCount above that, we will release our reference as it
should have acquired a strong reference to the data. This was previously
done when we forwarded the texture, but with remote textures, we no
longer have this event. Now we check when we start a new recording, or
attempt to clear cached resources.

Differential Revision: https://phabricator.services.mozilla.com/D197216
2023-12-23 01:34:31 +00:00
Lee Salzman
7b5fd9b289 Bug 1829026 - Optimize circle drawing in DrawTargetWebgl. r=aosmond
Chartjs heavily relies on circle drawing, which dispatches to the FillCircle and
StrokeCircle hooks in DrawTarget. These need to be implemented in DrawTargetWebgl.

Differential Revision: https://phabricator.services.mozilla.com/D194353
2023-12-18 18:10:47 +00:00
Lee Salzman
0306af2160 Bug 1829026 - Update CanvasTranslator to work with DrawTargetWebgl. r=aosmond
This adds the necessary infrastructure for CanvasTranslator to allocate DrawTargetWebgl
instead of just allocating TextureData, and to use RemoteTextureMap to handle sending
the DrawTargetWebgl frames to the compositor.

This optimizes snapshot transport to use fewer copies to and from shmems when we know
the snapshot contents can be sourced from a shmem.

This adds a blocking mechanism separate from deactivation so that existing DrawTargetWebgls
can continue processing events while denying further ones from being created in the event
that allocating further DrawTargetWebgls might cause problems, but so that we don't disrupt
canvases that are already in flight.

PersistentBufferProviderAccelerated still remains the buffer provider for the new setup,
but just allocates a single RecordedTextureData internally. Since DrawTargetWebgl already
does its own swap chain management internally, we do not want to use the multiple texture
client strategy that PersistentBufferProviderShared does.

This adds a fallback mechanism such that if DrawTargetWebgl allocation fails, a TextureData
is allocated instead that still sends results to RemoteTextureMap. This has the advantage
that we don't need to synchronously block in the content process to verify if acceleration
succeeded, as the costs of such blocking are rather extreme and we must still produce the
rendered frame to ensure the user sees the correct result if the speculative acceleration
failed. It then notifies the content process asynchronously via the refresh mechanism to
try to recreate a non-accelerated buffer provider when it is ready.

There is one additional hitch in RemoteTextureMap that we need to add a mechanism to deal
with the setup of the RemoteTextureOwner. When display list building initially needs to get
the remote texture, the RemoteTextureOwner might not exist yet. In this case, we need to add
a block to ensure we wait for that to occur so that we do not render an erroneous result.
Previously, this block was handled in ClientWebGLContext. Since that is no longer used,
the block must be reinstated somewhere else until a non-blocking mechanism for display list
building to proceed with a stub texture host wrapper can be implemented.

Currently this leaves the gfx.canvas.remote and gfx.canvas.accelerated prefs as separate
toggles rather than trying to lump everything into one mechanism. While this may be desirable
in the future, currently Direct2D remote canvas is a separate acceleration mechanism that
needs to co-exist with the WebGL acceleration, and so being able to toggle both on or off
for testing is desirable.

Differential Revision: https://phabricator.services.mozilla.com/D194352
2023-12-18 18:10:46 +00:00
Lee Salzman
cebb5ebe88 Bug 1829026 - Support using DrawTargetWebgl via remote canvas. r=aosmond
This mostly restructures DrawTargetWebgl to no longer rely upon ClientWebGLContext.
Instead, it must directly interact with WebGLContext which requires some noisy changes
of the GL rendering API used.

In addition, this restructures SharedContextWebgl so that it can be explicitly
allocated and further DrawTargetWebgls can be allocated that feed off of it.

This is all towards the ultimate goal of relying on remote canvas infrastructure for
remoting instead.

Differential Revision: https://phabricator.services.mozilla.com/D194351
2023-12-18 18:10:46 +00:00
Sebastian Hengst
cdce9d5ae9 Backed out 10 changesets (bug 1829026) for causing bug 1869760 and bug 1869738. a=backout
Backed out changeset 4c619422efe5 (bug 1829026)
Backed out changeset 77da89c7dab7 (bug 1829026)
Backed out changeset 19d28d8f75a4 (bug 1829026)
Backed out changeset 674b60ba54b1 (bug 1829026)
Backed out changeset 31935f164ef0 (bug 1829026)
Backed out changeset 13c9bf69085f (bug 1829026)
Backed out changeset 330a6732fc0b (bug 1829026)
Backed out changeset 974c08a3791b (bug 1829026)
Backed out changeset 3ba040642ddc (bug 1829026)
Backed out changeset 9d9b3a68858c (bug 1829026)
2023-12-13 19:20:00 +01:00
Lee Salzman
6f85b64281 Bug 1829026 - Optimize circle drawing in DrawTargetWebgl. r=aosmond
Chartjs heavily relies on circle drawing, which dispatches to the FillCircle and
StrokeCircle hooks in DrawTarget. These need to be implemented in DrawTargetWebgl.

Differential Revision: https://phabricator.services.mozilla.com/D194353
2023-12-12 07:35:03 +00:00
Lee Salzman
ccc64b116d Bug 1829026 - Support using DrawTargetWebgl via remote canvas. r=aosmond
This mostly restructures DrawTargetWebgl to no longer rely upon ClientWebGLContext.
Instead, it must directly interact with WebGLContext which requires some noisy changes
of the GL rendering API used.

In addition, this restructures SharedContextWebgl so that it can be explicitly
allocated and further DrawTargetWebgls can be allocated that feed off of it.

This is all towards the ultimate goal of relying on remote canvas infrastructure for
remoting instead.

Differential Revision: https://phabricator.services.mozilla.com/D194351
2023-12-12 07:35:02 +00:00
Cosmin Sabou
088aba68e8 Backed out 8 changesets (bug 1829026) for causing several mochitest failures. CLOSED TREE
Backed out changeset 790ba6aa65e4 (bug 1829026)
Backed out changeset 2ff1f5f41380 (bug 1829026)
Backed out changeset de6ddf5eb2a7 (bug 1829026)
Backed out changeset 773e7b31ac6e (bug 1829026)
Backed out changeset e09602ab096d (bug 1829026)
Backed out changeset fe16d4ac1049 (bug 1829026)
Backed out changeset c0fe0aea86c2 (bug 1829026)
Backed out changeset 53d6f69055f1 (bug 1829026)
2023-12-05 16:08:36 +02:00
Lee Salzman
a0e2a74c15 Bug 1829026 - Optimize circle drawing in DrawTargetWebgl. r=aosmond
Chartjs heavily relies on circle drawing, which dispatches to the FillCircle and
StrokeCircle hooks in DrawTarget. These need to be implemented in DrawTargetWebgl.

Differential Revision: https://phabricator.services.mozilla.com/D194353
2023-12-05 09:37:04 +00:00
Lee Salzman
25a6117f6d Bug 1829026 - Support using DrawTargetWebgl via remote canvas. r=aosmond
This mostly restructures DrawTargetWebgl to no longer rely upon ClientWebGLContext.
Instead, it must directly interact with WebGLContext which requires some noisy changes
of the GL rendering API used.

In addition, this restructures SharedContextWebgl so that it can be explicitly
allocated and further DrawTargetWebgls can be allocated that feed off of it.

This is all towards the ultimate goal of relying on remote canvas infrastructure for
remoting instead.

Differential Revision: https://phabricator.services.mozilla.com/D194351
2023-12-05 09:37:03 +00:00
Jamie Nicol
9b80930982 Bug 1859736 - Reuse WGR::PathBuilder instance in DrawTargetWebgl. r=gfx-reviewers,lsalzman
This avoids some expensive vector reallocations.

Differential Revision: https://phabricator.services.mozilla.com/D191283
2023-10-23 18:37:02 +00:00
Jamie Nicol
714a40e23b Bug 1857447 - Avoid redundant UniformData calls in DrawTargetWebgl. r=lsalzman
Calling ClientWebGLContext::UniformData() many times causes the
command buffer to fill up and we spend a fair amount of time flushing
the old buffer and allocating a new one, as well as serializing the
values.

The uniforms themselves are very small but they add up over a large
number of calls. We already have some code to track whether the
uniform values are dirty to avoid some redundancy, but a) this doesn't
cover every uniform, and b) we invalidate them all when switching
program.

This patch makes us track the value of every uniform that gets set
dynamically, and tracks the values separately for each program
used. It then uses these to avoid calling UniformData redundantly.

Differential Revision: https://phabricator.services.mozilla.com/D190269
2023-10-06 15:12:48 +00:00
Lee Salzman
db33f6ffeb Bug 1845309 - Use highp for texcoords in DrawTargetWebgl shaders. r=jrmuizel
This issue was originally reported by Asahi Lina, and they also proposed the original
version of these changes. I have reworked them a bit just to clean up how clip TCs
are passed down so that distance AA does not have to be highp.

Their original comment describing the issue were, in part:

"See DrawTargetWebgl::SharedContext::CreateShaders in dom/canvas/DrawTargetWebgl.cpp. The fragment shaders specify precision mediump float; and then don't use overriding precision qualifiers anywhere. This causes the texcoords to use fp16 precision on GPUs that support it, which is not sufficient for correct rendering."

"Note that this is a common mistake and the Mesa GPU driver we've been developing actually includes a heuristic that fixes the first instance of the problem (where the varying is used as a texcoord directly), but not the second one where there is an intermediate clamp(). It is that second one that is breaking Google Sheets."

Differential Revision: https://phabricator.services.mozilla.com/D187694
2023-09-07 18:10:24 +00:00
Lee Salzman
2617575ca5 Bug 1850727 - Only clear last clip mask when destroying clip mask. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D187366
2023-09-04 17:39:16 +00:00
Lee Salzman
45eb2f0103 Bug 1850727 - Ignore the clip mask when drawing a stroke mask. r=aosmond
The clip mask state was leaking into the drawing of the stroke mask texture.
This caused the stroke mask to be erroneously clipped out.

Differential Revision: https://phabricator.services.mozilla.com/D187254
2023-09-02 19:19:20 +00:00
Butkovits Atila
d0ff1ffd4d Backed out changeset 0d100cd406fa (bug 1850727) for causing reftest failures at 1850727-1.html. CLOSED TREE 2023-09-02 10:35:54 +03:00
Lee Salzman
284d25fdab Bug 1850727 - Ignore the clip mask when drawing a stroke mask. r=aosmond
The clip mask state was leaking into the drawing of the stroke mask texture.
This caused the stroke mask to be erroneously clipped out.

Differential Revision: https://phabricator.services.mozilla.com/D187254
2023-09-02 06:44:02 +00:00
Cristian Tuns
31ede82f9f Backed out changeset 843e65079be1 (bug 1850727) for causing build bustages in DrawTargetWebgl.cpp CLOSED TREE 2023-09-01 10:47:04 -04:00
Lee Salzman
63545125e1 Bug 1850727 - Ignore the clip mask when drawing a stroke mask. r=aosmond
The clip mask state was leaking into the drawing of the stroke mask texture.
This caused the stroke mask to be erroneously clipped out.

Differential Revision: https://phabricator.services.mozilla.com/D187254
2023-09-01 14:17:44 +00:00
sotaro
d0d700d9d2 Bug 1841380 - Limit the number of DrawTargetWebgls r=gfx-reviewers,lsalzman
A lot of DrawTargetWebgl allocations cause a lot of WebGL framebuffer allocations.
The allocations could cause out of resource problems.

Differential Revision: https://phabricator.services.mozilla.com/D183108
2023-07-11 02:13:56 +00:00
Lee Salzman
5d378f6973 Bug 1838136 - Improving path cache hashing. r=aosmond
Paths with the same shape but different locations can often hash to the same bucket.
Add a couple initial points from the path to the hash to distribute them better.
This results in a substantially improved hash distribution.

Differential Revision: https://phabricator.services.mozilla.com/D180849
2023-06-13 17:36:19 +00:00
Lee Salzman
dc8766500b Bug 1837728 - Allow alpha directly on stroked lines and rects. r=aosmond
For lines and rects, we don't have to worry about AARect generating overlapping
triangles when alpha is used. In these cases we can avoid drawing to a mask first
and avoid a performance cliff.

Differential Revision: https://phabricator.services.mozilla.com/D180525
2023-06-10 18:30:47 +00:00
Lee Salzman
6b34e45577 Bug 1837068 - Always advance path vertex offset. r=aosmond
Since we use unsynchronized BufferSubData, the wrong data can be used for some draw calls.
Ensure the path vertex offset is always advanced to avoid any races.

Differential Revision: https://phabricator.services.mozilla.com/D180436
2023-06-09 16:48:00 +00:00
Lee Salzman
5f60165581 Bug 1837068 - Support alpha strokes by rendering with AAStroke to a mask render target. r=aosmond
Since AAStroke can't deal with non-opaque stroked path, we first generate a normal opaque, anti-aliased
stroked path with AAStroke and render it to a cache texture bound to a render target. We can then later
just use that texture with alpha to support the initial alpha stroke request.

One caveat is that trying to both render to a texture bound to a framebuffer and also upload directly to
it with texSubImage2D can expose bugs in some OpenGL drivers that have different underlying representations
for data textures and for render target textures. To avoid this problem, we segregate the texture cache
pages based on whether they are used as render targets or for direct data uploads.

This ultimately all avoids the fallback of having to draw the alpha stroke in software with Skia and
then upload it to a texture. For stroked paths with large hollow areas, uploading a Skia surface whose
bounds contain the full stroke can cause a lot of uploading of unnecessary pixel data. This allows us
to only upload the triangle mesh for AAStroke and otherwise keep generation solely on the GPU.

Differential Revision: https://phabricator.services.mozilla.com/D180143
2023-06-07 19:47:04 +00:00
sotaro
8e5ae9706b Bug 1834342 - Flush pending commands in DrawTargetWebgl::~DrawTargetWebgl() r=gfx-reviewers,lsalzman
By flushing pending commands, release memory that is allocated for DrawTargetWebgl.

Differential Revision: https://phabricator.services.mozilla.com/D179335
2023-05-30 03:09:12 +00:00
Lee Salzman
7f70c02f53 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-20 02:30:12 +00:00
Narcis Beleuzu
f608d53d3a Backed out changeset a3eb3df78c8b (bug 1834079) for xpc crashes 2023-05-20 03:43:50 +03:00
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