Commit graph

853 commits

Author SHA1 Message Date
Raph Levien bfccd006e9
Tweak features for cargo check
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2023-05-20 12:35:55 -07:00
Raph Levien 6fb757266e Add dependencies
I wasn't sure the linux dependencies were needed just for a clippy check, but apparently so.
2023-05-18 16:18:42 -07:00
Raph Levien 3774928b24 Enforce clippy lints
This turns on clippy checking and also fixes all lints in the code.

Many lints are obvious improvements. Only a small number are slightly annoying, so I think overall worth having a vanilla default config.
2023-05-18 16:13:32 -07:00
Raph Levien 8eb02ce330 Suppress one more warning in wasm case 2023-05-18 15:45:44 -07:00
Raph Levien 1f6b47bd78 Quiet warnings
Fixes the warnings remaining in the code, which should in turn let us check that in CI.

Also checks the optional features, which are easy enough to break.
2023-05-18 15:40:40 -07:00
Daniel McNab abfe9fbb56
Add a stats display for scene complexity (#322) 2023-05-18 18:50:57 +01:00
Daniel McNab 2c394aa265
Add a CI check that everything compiles (#321) 2023-05-18 16:14:46 +01:00
Arman Uguray ef2630ad9c
Merge pull request #323 from armansito/shaders-fixes-for-bazel
[shaders] Shader path look up fixes for hermetic builds
2023-05-16 15:38:00 -07:00
Arman Uguray d82bd409ff [shaders] Shader path look up fixes for hermetic builds
* Bazel builds seem to fail to open relative paths to parent directories
  due to hermetic sandboxing of third-party repositories. This adds a
  WORKSPACE_MANIFEST_FILE environment variable that allows the caller to
  optionally provide an absolute path to the workspace root manifest
  file.
* The existing code processed a shader file only if
  `FileType::is_file` returns true for it. This is not the case when
  sources are accessed via symbolic links, which is possible in a Bazel
  sandbox. The code now filters for the ".wgsl" file extension instead
  of the file type which should generally be safe.
2023-05-16 15:08:54 -07:00
Chad Brokaw 14eef3fafb
Merge pull request #316 from linebender/gradient-fixes
General gradient improvements
2023-05-16 02:36:42 -04:00
Chad Brokaw 780cff09db add examples from COLRv1 spec 2023-05-16 02:35:20 -04:00
Chad Brokaw 7b68630d6a refactor common scale ratio code 2023-05-15 14:54:44 -04:00
Chad Brokaw 58c7df469d Address review feedback
* replace one_minus_focal_x and abs_one_minus_focal_x variables with the actual expressions
* replace division by r^2-1 with multiplication by reciprocal
* revert chain selects to branchy code for clarity. Branching is dynamically uniform so shouldn't affect performance
* add suggested comment describing gradient kind/flags constants
2023-05-15 14:45:38 -04:00
Chad Brokaw 5e1188f968 replace branches with chained selects
This exchanges the per-pixel branching with additional ALU + selects. My expectation is that this will be faster, but that may be hardware/driver dependent and likely requires profiling and examination of generated code.

The original code is kept in a comment with notes to explain the more obfuscated select version.
2023-05-11 12:37:36 -04:00
Arman Uguray b0303ccf98
Merge pull request #320 from armansito/revise-backend-src-access
[shaders] Revise access to backend-agnostic metadata
2023-05-10 14:46:07 -07:00
Arman Uguray b4ffb88494 [shaders] Revise access to backend-agnostic metadata
Previously the generated shader data structures were rooted in
backend-specific top-level mods (`mod wgsl`, `mod msl`, etc). This made
access to per-shader information that is common to all backends (e.g.
workgroup sizes, shader name etc) awkward to access from backend
agnostic code, especially when feature-gated conditional compilation is
used on the client side.

The data structures have been rearranged such that there is a top-level
`ComputeShader` declaration for each stage under a `gen` mod. The
`ComputeShader` struct declares feature-gated fields for backend shader
sources, such that backend specific data is now a leaf node in the
structure rather than the root. This has some additional benefits:

1. Common data doesn't have to be redeclared, saving on code size when
   multiple backends are enabled.

2. The backend specific source code was previously encoded as a `[u8]`.
   We can now use types that more closely match the expected format, for
   example `&str` for WGSL and MSL, `[u32]` for SPIR-V, etc.

3. If we ever need to expose additional backend-specific metadata in the
   future, we can bundle them alongside the source code in a
   backend-specific data structure at this level of the tree.
2023-05-10 14:12:13 -07:00
Chad Brokaw 006faab69f
Merge pull request #318 from linebender/export-font-api
Re-export font API
2023-05-10 13:59:29 -04:00
Chad Brokaw 570a0f3ce4 Re-export font API
Just exports fello from the glyph module so we can construct FontRefs in xilem.
2023-05-10 13:54:42 -04:00
Chad Brokaw b103a55301 rework radial gradients
Adds full support for COLRv1 radial gradients based on the two-point conical gradient algorithm at https://skia.org/docs/dev/design/conical/

Also adds robustness to degenerate cases in gradient encoding:
* Radial where p0 == p1 && r0 == r1 renders transparent solid
* Empty stops render as transparent solid
* Single stop renders as solid
2023-05-09 18:09:53 -04:00
Chad Brokaw ced6309a3b support two point radial with r0 > 0.0 2023-05-06 03:27:53 -04:00
Chad Brokaw 2db555145e clean up test scene code 2023-05-03 15:29:45 -04:00
Chad Brokaw e9c2ce1623 resolve merge conflicts 2023-05-03 14:53:36 -04:00
Chad Brokaw 4f9ae4c937 Merge branch 'main' into gradient-fixes 2023-05-03 14:49:57 -04:00
Chad Brokaw 6b69bff394
Merge pull request #317 from linebender/simple-resolve
[encoding] Add feature gate for full pipeline support
2023-05-03 14:46:12 -04:00
Chad Brokaw c68d011c7c feature gate full pipeline encoding support
Adds a new feature called "full" (on by default) that enables encoding support for the full pipeline.
2023-05-03 12:22:51 -04:00
Chad Brokaw 46328c7a2c cleanup for review
* rename resolve_simple to resolve_solid_paths_only to better capture the semantics of the function
* move duplicated buffer size computation code to separate function
* change Resolver::resolve to call resolve_solid_paths_only when encoding.patches.is_empty() is true. This is likely to be slightly faster and will ensure that the "simple" code path is actually used.
2023-05-02 16:42:50 -04:00
Chad Brokaw c3ca624c1e Add resolve function for path only pipeline
Adds a new `resolve_simple` function that doesn't handle late bound resources (gradients, images and glyph runs).
2023-05-02 14:07:25 -04:00
Chad Brokaw 15cd306af6 Extend modes for gradients
This patch implements the pad, repeat and reflect extend modes for gradient brushes. Adds a new example demonstrating the functionality.

Also fixes a few bugs:
* Clamps alpha in blend.wgsl for the `blend_compose` function. The `Plus` mode was generating `alpha > 1.0` leading to incorrect rendering.
* Small change to radial gradients in fine.wgsl to reject pixels outside the cone when the circles don't nest. This requires further work to properly extend the cone when one of the radii is not 0.
2023-04-30 23:11:57 -04:00
Daniel McNab 299b47ea06
Update the bevy example to wgpu 0.16 (#313)
* Update the bevy example to wgpu 0.16

After https://github.com/bevyengine/bevy/pull/8446

* Remove inaccurate README warning
2023-04-27 08:41:17 +01:00
Arman Uguray 8b2ea0132a
Merge pull request #312 from armansito/fix-wasm
Fix WASM build

- Rolled wgpu to 0.16.
- Incorprated the instant crate in lieu of std::time::Instant which works on WASM and native builds.
- Fixed the issue with window scaling by setting the canvas size based on winit Window dimensions.
- Fixed a division-by-zero issue in path_coarse_full

This resolves #276
2023-04-25 00:40:08 -07:00
Arman Uguray c9d7a15fad
Put the Warning label in its own line
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2023-04-25 00:37:06 -07:00
Arman Uguray b0cc221d7a Add warning to README about the Bevy example's compilation status 2023-04-24 16:03:09 -07:00
Arman Uguray b442ba550b Update wgpu version badge in README 2023-04-24 15:56:46 -07:00
Arman Uguray d3c54ed12d Include --bin with_winit_bin in run_wasm instructions 2023-04-24 15:49:49 -07:00
Daniel McNab 1529945a5a Update cargo-run-wasm 2023-04-24 15:46:18 -07:00
Arman Uguray 51f00fbd1f Fix the headless example for wgpu 0.16 2023-04-24 10:41:25 -07:00
Arman Uguray bc903d1c3b Add check for division-by-zero in path_coarse_full
The potential division by zero in this line led to visible visual
artifacts when running against WebGPU in Chrome.
2023-04-23 16:28:52 -07:00
Arman Uguray 7526d1ca26 Update run_wasm instructions 2023-04-23 16:09:17 -07:00
Arman Uguray 84915dc289 Use expect instead of unwrap on image format block size 2023-04-23 16:09:17 -07:00
Arman Uguray bb117da352 Enable wasm-bindgen feature of instant crate 2023-04-23 16:00:01 -07:00
Arman Uguray 4642fa024f [with_winit] Set the canvas size to thw winit Window's inner size
This prevents the scaling caused by the hardcoded canvas dimensions on
high dpi platforms.
2023-04-23 12:02:39 -07:00
Arman Uguray 5543ad01fe [examples] Use instant crate's time::Instant
crates.io/crates/instant provides a std::time::Instant implementation
that works on both WASM and non-wasm builds.
2023-04-23 12:02:39 -07:00
Arman Uguray 8a35c51289 Roll wgpu to 0.16 2023-04-23 12:02:39 -07:00
Arman Uguray fa027978ed
Merge pull request #310 from armansito/svg-timing
[svg] Log parse and render times separately
2023-04-23 11:31:19 -07:00
Arman Uguray 97250fb2dc
Merge pull request #311 from armansito/clip-leaf-bounds-check
[shaders] Explicitly guard writes to clip_bboxes
2023-04-23 11:27:27 -07:00
Arman Uguray ceeb0b33b6 [shaders] Explicitly guard writes to clip_bboxes
The very last statement of the `clip_leaf` shader is the assignment to
the `clip_bboxes` buffer. The buffer write is indexed on the global
invocation ID. It is possible for this index to be larger than the total
number of clips in at least one workgroup since the clip count isn't
strictly a multiple of workgroup size.

Currently the size of the clip_bboxes buffer matches the number of
clips. This means the buffer index is likely to run past the buffer.
This is not an issue when running on wgpu as it internally enables
bounds checking when compiling WGSL (so all buffer accesses are
implicitly conditional). When compiling the shaders to native backends
the vello_shaders crate currently does not enable implicit bounds
checking, so a buffer overrun is possible.

There are a few potential solutions:

1. Have an explicit bounds check in the shader. This is straightforward
   and consistent with the existing code that reads from clip_inp. The
   downside is that with bounds checking enabled, this extra check is
   redundant in the generated code. This is the solution included in
   this PR.

2. Make sure that the clip_bboxes buffer has a size that is a multiple
   of clip_leaf's workgroup size. This was the approach taken by
   piet-gpu on its native HALs. This effectively wastes up to 4080 bytes
   (255 * 16) to store unused bbox values.

3. Enable Naga's implicit bounds checks when compiling to native. This
   would make the behavior consistent with the wgpu backend, however it
   comes at the cost of increased renderer complexity as the native
   implementation must supply the sizes of each buffer in an implicitly
   generated buffer binding to every shader stage.
2023-04-21 18:43:51 -07:00
Arman Uguray 23f26ef2a1 [svg] Log parse and render times separately
The examples logged the total processing time for an SVG including both
parse and GPU buffer encoding times. Times for these two operations are
now logged separately.
2023-04-21 18:31:20 -07:00
Arman Uguray 3d83bd7fa0
Merge pull request #307 from linebender/vello_encoding
vello_encoding crate
2023-04-19 12:25:42 -07:00
Arman Uguray 2b0eab2bbc fix some clippy errors/warnings 2023-04-18 15:15:01 -07:00
Arman Uguray e9278a9253 [vello_encoding] Declare bump buffer sizes in terms of element count 2023-04-18 15:02:31 -07:00