Commit Graph

159 Commits

Author SHA1 Message Date
John Vandenberg 91d821a1f2
fix typos (#556) 2024-03-05 10:56:30 +00:00
Patrick Walton f1f9df5ce5
Merge pull request #441 from tangmi/build-shader-docs
Add docs for building shaders on Windows
2020-10-06 16:55:11 -07:00
Michael Tang 9d69e67a0e Wording 2020-09-12 14:01:57 -07:00
Michael Tang 493a2b9243 Add note on when this document is relevant 2020-09-12 13:59:16 -07:00
Michael Tang 157332c667 Add note about line endings 2020-09-12 13:54:29 -07:00
Michael Tang f8209946e3 Update documentation for building shaders 2020-09-12 13:49:28 -07:00
Patrick Walton 0e82acda2b Allow radial gradients to be evaluated with any nonzero discriminant, not just
ones with magnitude above `EPSILON`.

Closes #399.
2020-07-23 13:45:20 -07:00
Sebastian K dd0ac124d8 Add ColorMatrix filter 2020-07-23 12:46:59 -07:00
Patrick Walton 6a32f8c055 Stop clamping radial gradient t values to [0.0, 1.0].
Closes #393.
2020-07-16 10:30:39 -07:00
Patrick Walton 13ae83d6c5 Combine the Z-buffer and fill indirect draw params buffers to reduce the number
of SSBO bindings.

Apparently Mesa RadeonSI drivers have a limit of 8 SSBOs.

Closes #373.
2020-07-02 11:57:45 -07:00
Patrick Walton 37c3c62762 Implement nested SVG clip paths in the D3D11 backend.
Partially addresses #372.
2020-07-01 18:26:24 -07:00
Patrick Walton 42289eec6e Fix Metal memory management and the `canvas_metal_minimal`, `canvas_nanovg`,
and `macos_app` examples.

`winit` does not create an autorelease pool, so the Metal backend had not taken
the presence of one into account. Now the Metal backend creates and flushes
autorelease pools as necessary.

Closes #334.
Closes #376.
2020-06-29 12:48:49 -07:00
Patrick Walton 3bb4a47757 Remove old shaders 2020-06-23 13:15:59 -07:00
Patrick Walton 79326025af Rework the blit shader 2020-06-23 13:15:59 -07:00
Patrick Walton 61833168e5 Update the debug UI 2020-06-23 13:15:59 -07:00
Patrick Walton ff7c13c8fb Add a new compute-based D3D11 backend 2020-06-23 13:10:06 -07:00
Patrick Walton 754a44ae22 Rename the existing renderer to `d3d9` in preparation for the D3D11 branch 2020-06-23 13:10:05 -07:00
Patrick Walton 2ad02b0b78 Only define `precision highp sampler2D` in OpenGL ES.
Closes #309.
2020-05-08 16:59:40 -07:00
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