Commit Graph

220 Commits

Author SHA1 Message Date
Patrick Walton 2421de6616 Enable compute shader by default if the OpenGL version is high enough. 2020-05-08 12:16:31 -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 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 f8405d81c0 Bump the number of fills per batch up 2020-05-04 20:01:08 -07:00
Patrick Walton 6407bf5871 Reduce the size of buffers 2020-05-04 20:01:08 -07:00
Patrick Walton d0842f2f4d Generalize the buffer allocator to support multiple size classes, and use it
for tile compositing too.
2020-05-04 15:48:47 -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 84bf4341c2 Micro-optimize line fill primitive generation to avoid calls to `floorf()` and
`ceilf()`
2020-04-23 18:35:17 -07:00
Patrick Walton 24deb36e9a Supply solid tiles with the appropriate filter.
Fixes `embrace.svg` in MPVG.
2020-04-22 12:53:35 -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 564533ff29 Switch from Rust MPSC channels to `crossbeam-channel`.
7x performance improvement in contour.svg from MPVG!
2020-04-21 09:57:47 -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 1cd5966d3d Publish `pathfinder_content` and `pathfinder_renderer` to crates.io 2020-04-17 13:23:45 -07:00
Patrick Walton 5819b8dc60 Stop reallocating texture pages every frame 2020-04-17 11:50:46 -07:00
Patrick Walton 07ce2a2536 Add a scene field to render target IDs to reduce the chance of misuse 2020-04-16 16:54:52 -07:00
Patrick Walton afe1a64f68 Allow multiple tile pages.
Closes #151.
2020-04-15 20:13:37 -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 47919db8f3 Fix frame time measurement in the GL backend, and add it to the NanoVG demo 2020-04-09 17:49:28 -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 eb2b622615 Remove `draw_render_target()` in favor of the standard tile-based rendering
path
2020-04-03 13:05:53 -07:00
Patrick Walton cd37791d72 Implement the `drawImage()` method on canvas.
Closes #223.
2020-04-02 16:30:49 -07:00
Patrick Walton ba7fe4be39 Add the ability to merge scenes together, and expose it to the canvas API.
Closes #268.
2020-04-02 14:04:58 -07:00
Sebastian K 29c6a2e428 Transform paints by the render transform 2020-04-02 11:17:03 -07:00
Patrick Walton 794dd55038 Add some implicit conversions between scalars and vectors where appropriate 2020-04-01 17:20:32 -07:00
Patrick Walton 3d71703950 Stop copying images every frame on CPU.
We can avoid reuploading them to the GPU every frame as well, but this is a
bigger, and easier, win for now.
2020-04-01 13:01:08 -07:00
Patrick Walton bf2fd6569b Fix tests 2020-03-31 17:17:25 -07:00
Patrick Walton 32a56eab85 Stop leaking textures and framebuffers in the OpenGL backend.
Closes #264.

Possibly addresses #286.
2020-03-31 17:14:28 -07:00
Patrick Walton 2f6071c059 Make solid tiles not use mask 1.
Fixes random garbage appearing in the thumbnails in the NanoVG demo.
2020-03-31 14:16:04 -07:00
Patrick Walton 93f5fbc6d2 Add convenience constructors: `vec2f`, `vec2i`, `Vector2F::zero()`,
`Vector2I::zero()`
2020-03-31 11:29:21 -07:00
Patrick Walton a1f0ae097a Add thumbnail images to the NanoVG demo 2020-03-30 16:18:41 -07:00
Patrick Walton 7b53cc6731 Close all subpaths right before filling them.
Closes #269.
2020-03-27 14:50:02 -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 0f5de612f9
Merge pull request #281 from zimond/master
Use instant crate to build for wasm32 target
2020-03-09 17:17:09 -07:00
Patrick Walton 0b0c45a49a Collapse linear gradients down to a single 256x1 sliver instead of a 256x256
square
2020-03-05 16:58:26 -08: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 9935c9fdff Don't distinguish between render targets and other images in the texture atlas
allocator
2020-03-04 19:41:24 -08:00
Patrick Walton a8f7438cd9 Remove transforms from paths.
Paints aren't scale-invariant when rendered into the texture atlas, so they
actually do need individual transforms.
2020-03-04 16:28:21 -08:00
Patrick Walton 27357a23d3 Separate the `AddPaintData` render command into different subcommands 2020-03-04 15:50:53 -08:00
Patrick Walton e50039f4c2 Create framebuffers for every texture page 2020-03-04 12:35:07 -08:00
Patrick Walton a3736859ba Rename "paint texture" to just "texture page" 2020-03-04 12:09:08 -08:00
乌戈 22f9c3bf6e Use instant crate to build for wasm32 target 2020-03-05 01:54:36 +08:00
Patrick Walton d0f4579864 Move `RenderTargetId` out of the `pattern` module 2020-03-03 15:50:48 -08:00
Patrick Walton 2beb2bb126 Apply path transforms to paints 2020-03-03 14:26:38 -08:00
Patrick Walton 12574101e5 Add a transform field to `DrawPath`.
This is currently applied to the outline and should eventually be applied to
paints as well.
2020-03-03 11:18:01 -08:00
Patrick Walton 468848086a Use the paint texture uniform belonging to the appropriate program 2020-03-03 10:56:32 -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 40bb1b412c Implement radial gradients along a line, following Pixman. 2020-02-27 16:24:10 -08:00
Adam Nemecek 3d39c5e9b7 trimmed whitespace 2020-02-27 08:13:14 -08:00
Patrick Walton e913f83eee Remove obsolete TODOs 2020-02-27 04:03:08 -08:00
Patrick Walton 3a014d78eb Implement a blur filter for canvas shadows 2020-02-26 18:43:41 -08:00
Patrick Walton d1c7da8bd2 Implement pattern repeating and image smoothing control 2020-02-26 14:56:05 -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 e7de50eb67 Fix sub-Z-buffer indexing error with render targets 2020-02-25 18:36:46 -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 149efeb672 Fix `is_fully_transparent()` for colors.
Oops!
2020-02-24 21:22:36 -08:00
Patrick Walton 99d980c0c7 Fix batch breaking logic for blend modes 2020-02-24 21:22:15 -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 67d12adb6c Replace layers with render targets, which can be used as patterns.
This allows us to efficiently handle a lot of workloads that require multiple
HTML canvases, without CPU readback. For example, you can render paths to a
render target, then turn that render target into a repeating pattern that you
fill other paths with. Or you can render paths to a render target and then
composite that render target as a whole with a blend mode.

This introduces a new `DrawRenderTarget` render command that blits a render
target without any paths involved. This is basically just a hack that works
around the fact that our tiled renderer doesn't yet support effects that widen
the ink region (i.e. blurs). It can be removed once we have that support.
2020-02-21 22:14:18 -08:00
Patrick Walton 3245796445 Add support for multiple paint texture pages.
This avoids arbitrary limits on the number of images, gradients, etc. you can
have.
2020-02-21 14:46:10 -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 4933efb513 Add Lighten and Darken composite ops 2020-02-20 20:38:43 -08:00
Patrick Walton ab55b9509b Fix handling of solid tiles with the Clear blend mode 2020-02-20 18:15:20 -08:00
Patrick Walton 6acd2d91f7 Implement `clear_rect()` in the canvas front-end by introducing the concept of
per-path blend modes.

These should be useful for some canvas composite operations as well.
2020-02-20 15:52:40 -08:00
Patrick Walton 0c3dad974f Expose individual blend factors in `pathfinder_gpu` 2020-02-20 15:28:37 -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 d9e994e46d Transition the existing postprocessing system to a layers system.
This is preparatory work for composite ops and blurs.

Closes #261.
2020-02-20 11:21:45 -08:00
Patrick Walton cc9711e151 Transform some paints in the canvas API 2020-02-18 16:06:39 -08:00
Patrick Walton 3f79927eb1 Allow the paint texture to grow a bit 2020-02-18 15:06:09 -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 0d3bbbd506 Clip entire tiles appropriately.
This doesn't composite masks together, so it's currently incomplete.
2020-02-15 18:01:23 -08:00
Patrick Walton 631e16ce9b Fix flipped Y axis in mask texture positioning 2020-02-15 14:08:22 -08:00
Patrick Walton f26eecae7a Build clip paths before draw paths 2020-02-15 14:04:01 -08:00
Patrick Walton 496b55ee4e Add front-end support for clip paths. They don't do anything yet. 2020-02-15 13:21:12 -08:00
Patrick Walton fefa3c3cd3 Rename `PathObject` to `DrawPath` to differentiate it from a clip path 2020-02-15 12:39:15 -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 6a73a63336 Factor out mask texture UV calculation, and rename a couple of render commands 2020-02-14 21:37:20 -08:00
Patrick Walton 31becb1570 Flatten objects' tiles ourselves instead of having Rayon do it.
A prerequisite for clips.
2020-02-14 21:20:19 -08:00
Patrick Walton 84ffc3151e Split shaders out into a separate module. 2020-02-14 11:56:38 -08:00
Patrick Walton 90445bac7e Implement basic support for non-repeating image patterns. 2020-02-11 17:20:21 -08:00
Patrick Walton aad467e716 Implement basic radial gradients.
This doesn't handle the case where the circles are not concentric yet.
2020-02-10 22:15:50 -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 740597d886
Merge pull request #254 from arturoc/remove-log-restriction
Remove log restriction
2020-02-06 08:38:08 -08:00
Emmanuel Gil Peyrot 6ce416e77c Bump all outdated dependencies
I’m pleasantly surprised that none of these required any (visible) code
change, but tests pass so let’s go with that. :)
2020-02-06 09:39:50 +01:00
Patrick Walton 706b6dbd1d Add an API for gradients to the canvas frontend, not implemented yet 2020-02-05 20:01:11 -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 1e84ddf1ff Use the texture allocator to allocate solid colors 2020-02-03 22:24:34 -08:00
Patrick Walton b8f622203a Add a simple quadtree-based texture allocator 2020-01-31 14:38:01 +01:00
Patrick Walton 2db43797c3 Split colors out into their own crate.
A lot of downstream consumers of `pathfinder_gpu` want to use colors without
the path stuff.
2020-01-31 09:17:04 +01:00
Arturo Castro 3be6d70577 remove log restrictions from renderer, demo/common and gl crates 2020-01-28 15:24:21 +01:00
Patrick Walton ce3b40cd5c Make timer queries and framebuffer readback async 2020-01-07 13:03:15 -08:00