vello/shader
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
..
shared move atlas rect to info 2023-03-10 01:42:50 -05:00
backdrop.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
backdrop_dyn.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
bbox_clear.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
binning.wgsl Address review feedback 2023-01-18 21:36:32 -05:00
clip_leaf.wgsl [shaders] Explicitly guard writes to clip_bboxes 2023-04-21 18:43:51 -07:00
clip_reduce.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
coarse.wgsl move atlas rect to info 2023-03-10 01:42:50 -05:00
draw_leaf.wgsl move atlas rect to info 2023-03-10 01:42:50 -05:00
draw_reduce.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
fine.wgsl predicate image loads on non-zero mask 2023-03-15 08:37:00 -04:00
path_coarse.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
path_coarse_full.wgsl Address review feedback 2023-01-18 21:36:32 -05:00
pathseg.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
pathtag_reduce.wgsl Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00
pathtag_reduce2.wgsl Support for larger pathtags 2023-01-05 14:25:21 -08:00
pathtag_scan.wgsl Fix missing barriers in the pathtag_scans (#255) 2023-01-16 20:20:20 +00:00
pathtag_scan1.wgsl Fix missing barriers in the pathtag_scans (#255) 2023-01-16 20:20:20 +00:00
permutations Playing with shader permutations and AOT compilation 2023-03-29 10:38:10 -07:00
tile_alloc.wgsl Partially revert uniform load of bump.failed 2023-01-29 09:01:13 -08:00
UNLICENSE Move the vello crate to the workspace root (#231) 2023-01-05 09:32:09 +00:00