Commit Graph

102 Commits

Author SHA1 Message Date
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 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 a9003fe69b Add missing `tile_clip` shader to `resources`.
Closes #301.
2020-04-22 09:13:42 -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 6e28552a44 Add missing shaders 2020-02-14 22:10:04 -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 de0662e08e Update `spirv-cross` to upstream master.
A fix has been merged for the issue that was breaking Pathfinder, so we can now
use the master branch.
2019-06-21 07:24:24 -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 bc713a5181 Remove the rustache dependency.
1/3 reduction in binary size for `canvas_minimal`.

Closes #158.
2019-05-26 13:02:52 -07:00
Patrick Walton 25a6c33a1a Remove the object index attribute from the shaders, since it's now unused 2019-05-14 15:22:50 -07:00
Patrick Walton 7a02b78b3d Explicitly specify color texture coordinates for alpha and solid tiles.
This is groundwork for gradients and images.

This commit also refactors the interface for vertex attributes to use named
parameters (via structs), for clarity.
2019-05-14 15:11:04 -07:00
Patrick Walton 376a1c7165 Rename "fill colors" to "paint" in preparation for gradients and images 2019-05-14 11:33:52 -07:00
Patrick Walton 5e64876579 Simplify gridlines in the demo shader 2019-05-02 14:12:13 -07:00
Patrick Walton 6c31e1bc01 In VR mode, render one eye and then reproject to both eyes instead of rendering
twice.

This reduces both CPU and GPU time a lot in exchange for a small loss in
quality.
2019-04-26 17:22:54 -07:00
Patrick Walton c688d04412 Remove the scene assembly thread, and pipeline only fills instead of alpha
tiles.

Removing a thread should make it easier to manually assign threads to CPUs, as
is necessary on devices with poor schedulers like Magic Leap 1.
2019-04-18 13:50:26 -07:00
Patrick Walton db3851d754 Get subpixel AA and gamma correction working in 2D 2019-03-25 16:20:34 -07:00
Patrick Walton 224c8e85b9 Create separate shaders for monochrome and multicolor tiles.
This is preparation for fixing subpixel AA.
2019-03-22 14:28:31 -07:00
Patrick Walton 0458d9a7f2 Factor out bits of the postprocessing shader into includes 2019-03-18 21:40:10 -07:00
Patrick Walton 9c404dfdc1 Add an Android port 2019-03-12 13:55:26 -07:00
Patrick Walton dc69d1197e Tweak debug UI 2019-02-26 15:24:39 -08:00
Patrick Walton e10e2e97d4 Tweak the camera transforms in the 3D view 2019-02-22 11:54:01 -08:00
Patrick Walton c7a1d9e960 Use stencil to integrate the vector scene into the 3D environment 2019-02-19 12:03:02 -08:00
Patrick Walton 3b8ecfd74c WIP before removing barycentric coordinates 2019-02-18 18:13:10 -08:00
Patrick Walton 9af3bac11f Implement depth interpolation, not working yet 2019-02-18 13:42:30 -08:00
Patrick Walton d30743a69c Begin refactoring the demo into a shared library and a platform-specific
entry point.

This will help the upcoming wasm port.
2019-02-15 18:21:46 -08:00
Patrick Walton 93c928bf5c Move Pathfinder to `pathfinder-classic` in preparation for Pathfinder 2 2017-06-27 14:13:11 -07:00
Patrick Walton b86133a4ef Initial experimental support for subpixel antialiasing 2017-02-22 16:31:44 -08:00
Patrick Walton 49408b95cb Add support for subpixel offsets.
Closes #11.
2017-02-20 16:01:15 -08:00
Patrick Walton 6ac37c5085 Support cubic Béziers for fonts with CFF outlines 2017-02-16 19:37:21 -08:00
Patrick Walton 1b10ffdd54 Try to fix Linux/Windows 2017-02-14 12:29:30 -08:00
Patrick Walton 731360bc9d Try to fix RGBA atlas generation in OpenGL 2017-02-13 12:32:15 -08:00
Patrick Walton cd11deab46 Support RGBA atlases, needed for WebRender 2017-02-10 19:07:23 -08:00
Patrick Walton 96daa32b90 Move direction calculation from the TCS to the TES to properly handle cusps 2017-02-09 17:09:19 -08:00
Patrick Walton 5ecfadc3be Update for unorm change in `compute-shader` 2017-02-08 16:29:23 -08:00
Patrick Walton 428a91aefa Get things working on Windows 2017-02-08 13:55:36 -08:00
Patrick Walton e9fd5d6b1b Work around driver bugs on Apple Radeon GPUs 2017-02-07 14:39:36 -08:00
Patrick Walton 65153b65ee Fix subpixel positioning 2017-02-06 18:02:16 -08:00
Patrick Walton 7cd7210304 Fix winding rule to paint negative winding numbers 2017-02-06 15:28:23 -08:00
Patrick Walton 3fb592e05a Fix up examples and tests 2017-02-02 16:40:46 -08:00
Patrick Walton 5bccf88445 Make zooming work better; fix atlas sizing bugs 2017-01-30 18:33:44 -08:00
Patrick Walton 30daf10cdd Fix syntax on Linux; drop GL version to 3.3 2017-01-25 20:25:54 -08:00
Patrick Walton 2f181f23aa Add a draft GLSL accumulation step, currently untested 2017-01-25 19:22:04 -08:00
Patrick Walton 1336bb790e Add a geometry-shader-based path for debugging.
This is useful for testing via llvmpipe or softpipe on Linux, because
no software Mesa backend supports tessellation shaders.
2017-01-25 18:53:11 -08:00
Patrick Walton d5b61e382e Get things basically working 2017-01-25 17:08:00 -08:00
Patrick Walton 50ad78db2a Draft end-to-end support for the new algorithm. Not working yet. 2017-01-24 15:30:14 -08:00
Patrick Walton 1cd3a1e6bd Migrate the glyph buffers to be OpenGL buffers 2017-01-23 22:03:40 -08:00
Patrick Walton 0569831969 Fix shader compilation errors; convert the coverage buffer to a texture 2017-01-23 19:39:51 -08:00
Patrick Walton f1ec3385de Draft shader code for the new tessellation-based algorithm 2017-01-23 15:33:12 -08:00