Commit Graph

141 Commits

Author SHA1 Message Date
Patrick Walton 6299d2c36b Clear the canvas to the background color if no drawing command did so.
Closes #318.
2020-05-07 21:36:13 -07:00
Patrick Walton 520817e909 Add OpenGL 4.3 support to the GL backend, enabling compute shader on
non-Metal platforms
2020-05-07 16:33:03 -07:00
Patrick Walton 478008dcf0 Use all four channels in the mask texture.
Each bundle of four pixels on a scanline is packed into the RGBA channels of
the mask texture. The area LUT is also expanded to be RGBA so that four pixels'
worth of areas can be looked up at once.

Nice improvement on `paris-30k` from MPVG.

Closes #262.
2020-05-05 13:11:37 -07:00
Patrick Walton ac83f79d94 Add a compute shader path, optimize GPU memory management, and switch from SDL
to `surfman`.

This is a large commit; explanations of each change follow.

This adds an optional compute shader path, off by default, for rendering fills
to alpha masks. It usually does not improve performance at present, but it
provides a good baseline for further optimizations. Later improvements will
likely aim to avoid writes to the mask texture entirely. Supporting
infrastructure for compute shader has been added to `pathfinder_gpu` for the
OpenGL and Metal backends.

The Metal backend has been optimized to avoid unneccessary buffer allocations
and reflection. As part of this, argument buffers have been removed, as the
current SPIRV-Cross compiler no longer requires them.

The GPU renderer has been improved to avoid stalls. Now, separate buffers are
allocated for each fill batch and for each frame. This can be extended in the
future to allow for separate buffers for tile draw operations as well.

SDL usage has been removed in favor of the native Rust `surfman` and `winit`.
Because `surfman` allows for selection of the integrated GPU on multi-GPU
system, it is chosen by default. The demo supports a new
`--high-performance-gpu` option to opt into the discrete GPU.
2020-04-30 13:33:29 -07:00
Patrick Walton 104869a6e9 Move the mask enable flag to the tile to reduce drawcall count 2020-04-22 11:04:16 -07:00
Patrick Walton cd09177ead Implement the infrastructure needed to support multiple clip paths.
This also lays the groundwork needed to reduce batch breaks between solid and
alpha tiles.
2020-04-21 18:25:20 -07:00
Patrick Walton 6c996981a3 Fix some transform issues and implement transformed radial gradients in SVG.
In particular, this fixes the usvg-to-Pathfinder transform conversion and the
definition of `Transform2F::row_major()`.

Makes `drops.svg` from the MPVG samples work.
2020-04-20 16:40:02 -07:00
Sebastian K 582f025c91 Update WebGL backend for recent changes 2020-04-16 12:02:42 -07:00
Patrick Walton 0fec0061e6 Clamp radial gradient t values to [0.0, 1.0] instead of rendering transparent
black
2020-04-14 16:13:32 -07:00
Patrick Walton cdbe2fbb6b Introduce the concept of a base color in order to handle canvas shadow alpha
correctly
2020-04-13 18:31:25 -07:00
Patrick Walton 895f73096e Switch back to instanced drawing for tiles.
Improves tile build time by something around 2x in the NanoVG demo.
2020-04-08 17:16:54 -07:00
Patrick Walton 6eb0232aad Add `precision highp sampler2D` everywhere so our winding numbers don't get clipped
Closes #280.
2020-03-27 14:53:00 -07:00
Patrick Walton 55df287fec Move radial gradients from the CPU to the GPU 2020-03-26 21:24:20 -07:00
Patrick Walton 0c93045f50 Replace the individual tile shaders with an ubershader 2020-03-25 21:59:51 -07:00
Patrick Walton 2548ab853a Unify solid tiles and render target tiles.
This commit also removes old shaders from the manifest.
2020-03-05 12:22:01 -08:00
Patrick Walton f607b607b0 Composite render targets using tiles, taking the Z-buffer into account.
We can do more tile-based optimization, but this should be enough to ensure a
correct rendering.

This temporarily breaks subpixel AA, but it should be fixable by modifying
`blur.fs.glsl`.

Closes #271.
2020-03-02 20:10:10 -08:00
Patrick Walton ee6c7e0797 Explicitly cast `aTessCoord` to `vec2` for WebGL compatibility 2020-02-28 12:49:21 -08:00
Patrick Walton b998449885 Remove unused #define 2020-02-26 18:46:48 -08:00
Patrick Walton 3a014d78eb Implement a blur filter for canvas shadows 2020-02-26 18:43:41 -08:00
Patrick Walton 77b3555828 Separate opacity out from paint.
This allows `globalAlpha` to work on render targets.
2020-02-26 12:43:07 -08:00
Patrick Walton 1deb53fa9c Implement the remaining Porter-Duff compositing operators 2020-02-25 18:37:23 -08:00
Patrick Walton 0a3f64eb44 Implement the difference and exclusion blend modes 2020-02-25 14:55:58 -08:00
Patrick Walton a8e33d3d3d Add the soft light blend mode 2020-02-25 14:39:06 -08:00
Patrick Walton 9b4217300f Implement the source-in, destination-in, source-out, and destination-atop blend
modes to round out the assortment of Porter-Duff blend modes
2020-02-25 12:52:11 -08:00
Patrick Walton 02012431ca Implement color dodge and color burn blend modes 2020-02-25 11:37:42 -08:00
Patrick Walton 5b228ed825 Implement multiply, screen, hard light, and overlay blend modes. 2020-02-24 21:23:17 -08:00
Patrick Walton 00b7a2ee5a Factor out 3-element selection into a `select3()` function 2020-02-24 21:21:30 -08:00
Patrick Walton c96cb62f47 Factor out common functions used in tile alpha shaders 2020-02-24 19:42:32 -08:00
Patrick Walton 5421525eaa Implement the HSL filters (called "non-separable blend modes" in the spec).
These cannot be implemented with the standard OpenGL blending functions, so we
have to do them manually in a shader, which requires a good deal of machinery
to create intermediate framebuffers and so forth.
2020-02-24 15:37:44 -08:00
Patrick Walton 36538d5748 Implement a few more blend modes and switch to premultiplied alpha for layer
compositing
2020-02-20 22:22:15 -08:00
Patrick Walton 16a2de88df Rename "postprocessing" to "effects" and start initial work on composite ops 2020-02-20 14:22:07 -08:00
Patrick Walton 3ad1c25796 Implement the even-odd fill rule 2020-02-17 14:44:48 -08:00
Patrick Walton 677c607a8c Get clips working for canvas 2020-02-16 13:45:15 -08:00
Patrick Walton a8019a1a1a Fix mask positioning on OpenGL 2020-02-15 18:00:25 -08:00
Patrick Walton 631e16ce9b Fix flipped Y axis in mask texture positioning 2020-02-15 14:08:22 -08:00
Patrick Walton 0883f54e2d Add a separate mask blit step, in preparation for supporting clips.
We can elide this in the future if there are no clips, but it isn't a huge
performance regression right now, so let's just unconditionally do it.
2020-02-14 21:56:43 -08:00
Patrick Walton 5a21557a6d Implement basic linear gradients.
This is not a very efficient implementation yet, but it seems to work.
2020-02-10 16:01:05 -08:00
Patrick Walton a66ed4c073 Specify tile texture coordinates as an affine transform.
Part of the groundwork for gradients.
2020-02-05 13:59:32 -08:00
Patrick Walton b269723254 Switch to per-pixel texture lookup for paints.
This is a prerequisite for supporting gradients and images.
2020-02-04 21:50:13 -08:00
Patrick Walton 222fa89b23 Use a 3D transform in the tile vertex shaders.
This opens the door to caching tiles at different zoom levels (issue #191).
2019-06-25 11:32:39 -07:00
Patrick Walton d86ff9011a Update the postprocessing shader and vertex array for the Metal changes.
Closes #201.
2019-06-21 18:04:18 -07:00
Patrick Walton 487577a11b Add Metal support.
This commit substantially reworks the `pathfinder_gpu` API to better support
modern APIs like Metal. It should open the door to `gfx-rs`, `wgpu`, Vulkan,
and D3D12 backends relatively straightforwardly.

A new example, `canvas_metal_minimal`, has been added.

Note that the new Metal shaders require a patched version of `spirv-cross` to
build properly. An upstream patch is forthcoming.
2019-06-20 11:47:22 -07:00
Patrick Walton 9f9233c153 Add Metal shaders, cross-compiled from the GLSL via SPIR-V.
The Metal shaders are checked into the repository for convenience, but they
should not be directly edited. Instead, edit the corresponding GLSL shader in
the top-level `shaders/` directory, and rerun `make` in there.
2019-06-05 18:29:25 -07:00
Patrick Walton ade3b5fbb9 Remove Pathfinder 2 shaders 2019-02-08 14:44:25 -08:00
Patrick Walton bc3f6b6ae5 New tiling mostly working 2018-12-02 12:44:02 -08:00
Patrick Walton 79e69c6916 WIP Newton's method for stencil AAA 2018-12-01 11:48:22 -08:00
Manish Goregaokar 8ed4e96ff9 Various review cleanups 2018-04-02 19:10:19 -07:00
Manish Goregaokar 2b0b699fa0 Turn off lighting for VR 2018-04-02 19:10:11 -07:00
Manish Goregaokar 7e115826a1 Remove dependence on frag_depth 2018-04-02 19:10:04 -07:00
Patrick Walton 6e13fb171c Use a lookup table to do area calculations instead of Loop-Blinn-style
distance-to-edge for stencil analytic antialiasing.

This improves the rendering quality of stencil AAA significantly.

Additionally, this adds an approximation of Core Graphics' (macOS')
defringing filter.

Closes #73.
2018-03-19 14:35:36 -07:00
Patrick Walton db6986ca1f Take the orientation of a path into account when computing normals 2018-03-07 11:21:08 -08:00
Patrick Walton aa3ecf28a5 Quantize to subpixel boundaries.
This doesn't break meshes the way the previous "discard if too thin"
code did. It fixes several issues observed on Wikipedia when using
Pathfinder in Firefox.

Closes #72.
2018-03-06 19:20:19 -08:00
Patrick Walton b60275e5ea Convert cubic curves to quadratic ones in fonts 2018-03-06 13:10:29 -08:00
Patrick Walton 5d3c1f6d59 Abstract away `FontKey` so WebRender can more easily use this; switch
from angle measurement to scale-dependent hull height
2018-03-05 11:27:18 -08:00
Patrick Walton 48aceb6291 Fix zoomed-in rotation for text by taking extended path transforms into
account in the MCAA shader.
2018-02-21 17:00:37 -08:00
Patrick Walton 4e1a9a9bad Add a new varying to the stencil AAA fragment shader for simplicity.
The new `vXDist` values *can* be deduced simply from the `vUV` values
and first-order derivatives thereof, and therefore they're technically
redundant. However, calculating them in this way increases the
complexity and ALU load in the fragment shader. It's simpler to just
compute the additional values in the vertex shader and use
interpolation.
2018-02-21 16:27:49 -08:00
Patrick Walton a84b7c7cbd Replace ECAA with "Stencil AAA", a distance-based antialiasing
technique similar to the new MCAA.

This new technique simplifies the code significantly by unifying lines,
curves, and transformed curves. Blog posts forthcoming.
2018-02-17 10:45:25 -08:00
Patrick Walton 5879d9778d Replace the MCAA shader with an extended Loop-Blinn approach and an
approximation of area based on approximate first-order line distance.

This enables support for full affine transforms in MCAA. It also greatly
simplifies the shader and reduces the amount of work that the GPU needs
to do for fragment shading.

Experimental testing has shown the area approximation to be accurate to
about 4%.
2018-02-02 18:28:41 -08:00
Patrick Walton 5bd68dec65 Port Pathfinder to use Lyon for Bézier curve math.
This removes a whole lot of code from `pathfinder_path_utils`. Hopefully
the remaining code can go upstream.

These changes regress quality of stroke widths for cubic curves, because
they move fill-to-stroke conversion before cubic-to-quadratic
conversion. To fix that, we will need to recursively subdivide when
doing fill-to-stroke conversion.
2018-01-29 12:47:47 -08:00
Patrick Walton 6a640eca74 Simplify the B-quad vertex position VBO to have a uniform format, and
enable early Z for SVG.

Additionally, this switches the B-quad patches for XCAA to be convex
hulls instead of bounding boxes, reducing fragment shader load.

This is a large speedup for the Ghostscript tiger demo: 5x or more.

Closes #33.
2018-01-11 19:25:02 -08:00
Patrick Walton d821991c01 Clean up `common.inc.glsl` a bit 2018-01-05 12:18:50 -08:00
Patrick Walton f3841ef402 Document more shader parameters 2018-01-04 18:07:14 -08:00
Patrick Walton 67d29803b5 Document most uniforms in shaders 2018-01-04 17:32:20 -08:00
Patrick Walton c5187deedd Use the monochrome MCAA mode for the Material Design icons SVG demo.
This avoids ugly pixel snapping.
2018-01-03 20:53:25 -08:00
Patrick Walton 11913a20f1 Merge MCAA monochrome and multicolor shaders.
Not only is this a lot simpler, it's faster too!
2018-01-03 15:22:28 -08:00
Patrick Walton 017a2e2f8c Provide brief documentation of each shader 2017-12-30 20:32:51 -05:00
Patrick Walton a81c69c34e Document the blit shaders 2017-12-28 11:46:44 -05:00
Patrick Walton 9515451e7a Remove render tasks entirely. 2017-12-28 11:44:46 -05:00
Patrick Walton 097e909d07 In multicolor XCAA, cap the slope to a reasonable amount to prevent line segments from shooting way up or down 2017-12-19 13:47:57 -08:00
Patrick Walton ddd1c89294 Use one side for the X position in the multicolor MCAA vertex shader to avoid cracks 2017-12-19 10:54:30 -08:00
Patrick Walton cfe72f486e Use a single-pass pixel-snapping MCAA algorithm instead of a multipass
ECAA algorithm for multicolor SVG.

This is much faster than both Skia and the previous XCAA algorithm
while maintaining slightly higher quality than the latter.

There are a couple of known issues:

* Vertical inflection points of hairlines with very steep slopes can
  become very light or even drop out occasionally. I suspect this is due
  to floating point error.

* Rarely, single columns of pixels can disappear from a mesh. Cause TBD.

Besides these bugs, this technique can be cleaned up and probably made
faster, but it's a sizable improvement as is.
2017-12-18 17:37:14 -08:00
Tristan Hume dd934211af Fixes #51 by introducing a variable for an early return boolean.
This works around a bug in the macOS Nvidia shader compiler
in 2014 rMBPs.
2017-12-05 21:09:58 -05:00
Patrick Walton ac95b04061 Fix accidental `x`/`y` swap in the ECAA multi edge mask curve shader 2017-12-04 11:55:47 -08:00
Patrick Walton 9b59ce2443 Fix rotation artefacts by rendering curves in two passes, clipping at X
inflection points as necessary.
2017-12-03 16:59:35 -08:00
Patrick Walton 801c25305f Pack left and right normal angles into one vec2 in `computeECAAQuadPosition` 2017-12-02 13:21:13 -08:00
Patrick Walton 7e0d003a95 Refactor the XCAA vertex shaders themselves, now that the common XCAA
infrastructure has been refactored
2017-12-02 13:14:01 -08:00
Patrick Walton dc5e3a0093 Refactor the XCAA shaders some more 2017-12-02 13:05:11 -08:00
Patrick Walton 86660572bd Upgrade ST-transforms to affine transforms where possible, and add
incomplete rotation support to the text demo
2017-11-29 17:06:52 -08:00
Patrick Walton 58260beb8c Only run the ECAA mask shader on edge pixels 2017-11-28 17:05:59 -08:00
Patrick Walton 6942bb51ca Add support for full 3D transforms, including rotation, to SVG in XCAA mode. 2017-11-28 16:15:06 -08:00
Patrick Walton 0e9144286e Fix the calculation of `dP` in the XCAA multicolor edge mask. 2017-11-27 15:43:47 -08:00
Patrick Walton 6e70b983c3 Remove incorrect commented-out shader code 2017-11-21 15:54:18 -08:00
Patrick Walton 7bd3a48110 Don't clip curves to the left and right sides of the pixel column twice 2017-11-21 15:51:27 -08:00
Patrick Walton 86df78f939 Flesh out the integration test more 2017-11-17 17:06:59 -08:00
Patrick Walton 8c1b3e9cb5 Optimize and better document the exact antialiasing calculation 2017-11-14 18:02:26 -08:00
Patrick Walton bc99fdf02b Enable early Z in the XCAA multicolor direct interior pass 2017-11-11 14:45:28 -08:00
Patrick Walton 575d4c2366 Fix regression involving NaN when doing curve clipping 2017-11-11 09:38:06 -08:00
Patrick Walton 37cdc9bc5c Optimize the signed area calculation 2017-11-10 23:09:54 -08:00
Patrick Walton 1f5dbe33e8 Apply optimizations to the multi-edge mask shader too 2017-11-10 22:09:29 -08:00
Patrick Walton fc2ac12fc0 Optimize the XCAA fragment shaders a bit 2017-11-10 19:25:47 -08:00
Patrick Walton 75474b19e6 Add the normal angle to the shaders used in the 3D demo 2017-11-10 15:03:43 -08:00
Patrick Walton 3bcd05a5ed Update the XCAA multi direct shaders to support normals.
Fixes XCAA in the SVG demo.
2017-11-09 16:42:53 -08:00
Patrick Walton 8e7eb6ca60 Support stem darkening in SSAA mode.
The normals are incorrect right now in some cases, but it looks OK-ish.
2017-11-09 16:20:15 -08:00
Patrick Walton e5b76726d9 Use the LUT to gamma correct text, and fix stem darkening math 2017-11-07 17:24:19 -08:00
Patrick Walton 8a1e3bc8b2 Add some basic Phong shading to the monument 2017-11-03 18:49:25 -07:00
Patrick Walton 4cbc2a8800 Add partial support for clip paths in the SVG demo.
At the moment, this only works when antialiasing is off.
2017-11-03 14:14:29 -07:00
Patrick Walton 579528ebdc Remove one direct rendering pass from the multicolor XCAA path 2017-10-31 12:41:38 -07:00
Patrick Walton 2604151521 Replace the multicolor (SVG) XCAA with a multipass compositing algorithm 2017-10-30 15:28:35 -07:00
Patrick Walton e4b531f3a0 Do some work on shader documentation 2017-10-26 20:30:47 -07:00
Patrick Walton 0506365cc7 Fix blending in the text demo.
As a nice added cleanup, this commit standardizes on the red channel for
all monochrome textures.
2017-10-26 20:15:51 -07:00