Commit Graph

146 Commits

Author SHA1 Message Date
Michael Pfaff 5e41738e4c Improve C API
I ran `cargo fmt` on the project, which in hindsight was a poor choice.
I'm not correcting it right now.
2024-08-09 03:17:33 -04:00
Andrea Frigido d0f8005169
Update license field following SPDX 2.1 license expression standard (#540) 2024-02-06 16:59:01 +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 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
Antonio Scandurra cc54fa6e03 Add missing Metal shader to resources/MANIFEST
Co-Authored-By: Nathan Sobo <nathansobo@gmail.com>
2020-05-28 16:11:23 +02:00
Patrick Walton 2ad02b0b78 Only define `precision highp sampler2D` in OpenGL ES.
Closes #309.
2020-05-08 16:59:40 -07:00
Patrick Walton 84cd92aea4 Update the resource manifest for recent changes 2020-05-08 14:17:13 -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
Patrick Walton a91da6fdb4 Publish `pathfinder_resources` to crates.io 2020-04-17 12:33:22 -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 a196f1eff8 Fix spriting imperfections in the thumbnails in the NanoVG 2020-04-09 12:15:39 -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 ae97ccea5a Improve ergonomics of the canvas font interface, and use the right fonts in the
NanoVG demo.
2020-04-01 16:25:13 -07:00
Patrick Walton f823cb9474 Rename `SIL Open Font License.txt` to `LICENSE-SIL` for consistency 2020-04-01 13:24:07 -07:00
Patrick Walton 956b9020e8 Rename `overpass-regular.otf` to `Overpass-Regular.otf` 2020-04-01 13:22:29 -07:00
Patrick Walton a1f0ae097a Add thumbnail images to the NanoVG demo 2020-03-30 16:18:41 -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 2beb2bb126 Apply path transforms to paints 2020-03-03 14:26:38 -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 0f35d9c817 Add an embedded resource loader that places resources directly in the binary.
This is useful for WebGL and for downstream crates.io use.
2020-02-28 17:10:53 -08:00
Patrick Walton ee6c7e0797 Explicitly cast `aTessCoord` to `vec2` for WebGL compatibility 2020-02-28 12:49:21 -08:00
Patrick Walton d2ae183ed6 Update README 2020-02-28 09:46:42 -08:00
Patrick Walton b4681dcf8f Add a PNG version of the logo 2020-02-28 09:44:09 -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 b16300bf02 Move the SWF assets into `resources/`. 2019-06-21 09:32:48 -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 8ec4f04deb Make `canvas-text` use a custom font 2019-06-20 21:34:46 -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
Alan Jeffrey 45d7f7ad9a Make the backgrounds of the demo SVGs off-white 2019-06-07 12:23:55 -05: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 ebdb12404a Add missing "actual size" texture 2019-05-08 17:51:59 -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
Alan Jeffrey bd70cb0135 Changed some of the magicleap demo SVGs 2019-04-15 12:43:41 -04:00
Patrick Walton c5ccd0f6e0 Add partial support for transparent background colors. 2019-04-10 14:43:36 -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 6ca5dc5f62 Add basic barrel distortion support for VR 2019-03-20 13:41:04 -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 64b480fe32 Some more work on the site 2019-03-01 14:58:02 -08:00
Patrick Walton dc69d1197e Tweak debug UI 2019-02-26 15:24:39 -08:00
Patrick Walton 92777c6346 Make rects rounded and optimize PNGs 2019-02-26 13:48:35 -08:00
Patrick Walton f6af769486 Add screenshot functionality. 2019-02-25 11:33:26 -08:00
Patrick Walton aef7dd1353 Allow the background color to be changed in the demo 2019-02-22 18:21:03 -08:00
Patrick Walton e10e2e97d4 Tweak the camera transforms in the 3D view 2019-02-22 11:54:01 -08:00
Patrick Walton 0da196aa92 Scale the SVG appropriately in the demo 2019-02-21 20:19:42 -08:00
Patrick Walton c7a1d9e960 Use stencil to integrate the vector scene into the 3D environment 2019-02-19 12:03:02 -08:00