Skip to content

Commit 29f70b5

Browse files
committed
Properly write-protect segments
Extracted from linebender#606
1 parent 3c8dc79 commit 29f70b5

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

vello/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl Render {
429429
recording.dispatch(
430430
shaders.path_tiling_setup,
431431
wg_counts.path_tiling_setup,
432-
[bump_buf, indirect_count_buf.into(), ptcl_buf],
432+
[config_buf, bump_buf, indirect_count_buf.into(), ptcl_buf],
433433
);
434434
recording.dispatch_indirect(
435435
shaders.path_tiling,

vello/src/shaders.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub(crate) fn full_shaders(
194194
Buffer,
195195
]
196196
);
197-
let path_tiling_setup = add_shader!(path_tiling_setup, [Buffer, Buffer, Buffer]);
197+
let path_tiling_setup = add_shader!(path_tiling_setup, [Uniform, Buffer, Buffer, Buffer]);
198198
let path_tiling = add_shader!(
199199
path_tiling,
200200
[

vello_shaders/shader/path_tiling_setup.wgsl

+16-5
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,41 @@
33

44
// Set up dispatch size for path tiling stage.
55

6+
#import config
67
#import bump
78

89
@group(0) @binding(0)
9-
var<storage, read_write> bump: BumpAllocators;
10+
var<uniform> config: Config;
1011

1112
@group(0) @binding(1)
12-
var<storage, read_write> indirect: IndirectCount;
13+
var<storage, read_write> bump: BumpAllocators;
1314

1415
@group(0) @binding(2)
16+
var<storage, read_write> indirect: IndirectCount;
17+
18+
@group(0) @binding(3)
1519
var<storage, read_write> ptcl: array<u32>;
1620

1721
// Partition size for path tiling stage
1822
let WG_SIZE = 256u;
1923

2024
@compute @workgroup_size(1)
2125
fn main() {
22-
if atomicLoad(&bump.failed) != 0u {
26+
indirect.count_y = 1u;
27+
indirect.count_z = 1u;
28+
let segments = atomicLoad(&bump.seg_counts);
29+
let overflowed = segments > config.segments_size;
30+
if atomicLoad(&bump.failed) != 0u || overflowed {
31+
if overflowed {
32+
// Report the failure so that the CPU can know we have failed.
33+
atomicOr(&bump.failed, STAGE_COARSE);
34+
}
35+
// Cancel path_tiling
2336
indirect.count_x = 0u;
2437
// signal fine rasterizer that failure happened (it doesn't bind bump)
2538
ptcl[0] = ~0u;
2639
} else {
2740
let segments = atomicLoad(&bump.seg_counts);
2841
indirect.count_x = (segments + (WG_SIZE - 1u)) / WG_SIZE;
2942
}
30-
indirect.count_y = 1u;
31-
indirect.count_z = 1u;
3243
}
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// Copyright 2023 the Vello Authors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense
33

4-
use vello_encoding::{BumpAllocators, IndirectCount};
4+
use vello_encoding::{BumpAllocators, ConfigUniform, IndirectCount};
55

66
use super::CpuBinding;
77

88
const WG_SIZE: usize = 256;
99

10-
fn path_tiling_setup_main(bump: &BumpAllocators, indirect: &mut IndirectCount) {
10+
fn path_tiling_setup_main(_: &ConfigUniform, bump: &BumpAllocators, indirect: &mut IndirectCount) {
1111
let segments = bump.seg_counts;
1212
indirect.count_x = (segments + (WG_SIZE as u32 - 1)) / WG_SIZE as u32;
1313
indirect.count_y = 1;
1414
indirect.count_z = 1;
1515
}
1616

1717
pub fn path_tiling_setup(_n_wg: u32, resources: &[CpuBinding]) {
18-
let bump = resources[0].as_typed();
19-
let mut indirect = resources[1].as_typed_mut();
18+
let config = resources[0].as_typed();
19+
let bump = resources[1].as_typed();
20+
let mut indirect = resources[2].as_typed_mut();
2021
// binding 2 is ptcl, which we would need if we propagate failure
21-
path_tiling_setup_main(&bump, &mut indirect);
22+
path_tiling_setup_main(&config, &bump, &mut indirect);
2223
}

0 commit comments

Comments
 (0)