1
+ use std:: ops:: ControlFlow ;
2
+
1
3
use vello_encoding:: {
2
4
BinHeader , BufferSize , BumpAllocators , Clip , ClipBbox , ClipBic , ClipElement , DrawBbox ,
3
- DrawMonoid , Encoding , IndirectCount , Layout , LineSoup , Path , PathBbox , PathMonoid , PathSegment ,
5
+ DrawMonoid , Encoding , IndirectCount , LineSoup , Path , PathBbox , PathMonoid , PathSegment ,
4
6
RenderConfig , Resolver , SegmentCount , Tile ,
5
7
} ;
6
8
use vello_shaders:: {
@@ -28,7 +30,7 @@ pub struct Buffer<T: bytemuck::Zeroable + bytemuck::NoUninit> {
28
30
}
29
31
30
32
impl < T : bytemuck:: Zeroable + bytemuck:: NoUninit > Buffer < T > {
31
- fn to_fit ( & mut self , size : BufferSize < T > ) -> & mut [ T ] {
33
+ fn fit_slice ( & mut self , size : BufferSize < T > ) -> & mut [ T ] {
32
34
self . inner
33
35
. resize_with ( size. len ( ) . try_into ( ) . expect ( "32 bit platform" ) , || {
34
36
T :: zeroed ( )
@@ -67,11 +69,36 @@ pub struct CoarseBuffers {
67
69
ptcl : Buffer < u32 > ,
68
70
}
69
71
72
+ pub enum Stages {
73
+ PathTagReduce ,
74
+ PathTagScan ,
75
+ BboxClear ,
76
+ Flatten ,
77
+ DrawReduce ,
78
+ DrawLeaf ,
79
+ ClipReduce ,
80
+ ClipLeaf ,
81
+ Binning ,
82
+ TileAlloc ,
83
+ PathCount ,
84
+ Backdrop ,
85
+ Coarse ,
86
+ PathTiling ,
87
+ }
88
+
70
89
pub fn run_coarse_cpu (
71
90
params : & RenderParams ,
72
91
buffers : & mut CoarseBuffers ,
73
92
cpu_config : & RenderConfig ,
74
93
) {
94
+ let _ = run_coarse_cpu_internal ( params, buffers, cpu_config) ;
95
+ }
96
+
97
+ fn run_coarse_cpu_internal (
98
+ params : & RenderParams ,
99
+ buffers : & mut CoarseBuffers ,
100
+ cpu_config : & RenderConfig ,
101
+ ) -> ControlFlow < ( ) > {
75
102
let packed = & mut buffers. packed ;
76
103
77
104
// HACK: The coarse workgroup counts is the number of active bins.
@@ -90,47 +117,52 @@ pub fn run_coarse_cpu(
90
117
let buffer_sizes = & cpu_config. buffer_sizes ;
91
118
let wg_counts = & cpu_config. workgroup_counts ;
92
119
120
+ // Some buffers are marked as "write-only". This means that they will be performant to
121
+ // write into https://docs.rs/wgpu/latest/wgpu/struct.BufferViewMut.html directly (not yet set up)
122
+
93
123
// TODO: This is an alignment hazard, which just happens to work on mainstream platforms
94
124
// Maybe don't merge as-is?
95
125
let scene_buf = bytemuck:: cast_slice ( packed) ;
96
126
let config_buf = cpu_config. gpu ;
97
- let info_bin_data_buf = buffers. bin_data . to_fit ( buffer_sizes. bin_data ) ;
98
- let tile_buf = buffers. tiles . to_fit ( buffer_sizes. tiles ) ;
99
- let segments_buf = buffers. segments . to_fit ( buffer_sizes. segments ) ;
127
+ let info_bin_data_buf = buffers. bin_data . fit_slice ( buffer_sizes. bin_data ) ;
128
+ let tile_buf = buffers. tiles . fit_slice ( buffer_sizes. tiles ) ;
129
+ // Write-only
130
+ let segments_buf = buffers. segments . fit_slice ( buffer_sizes. segments ) ;
131
+ // Write-only
132
+ let ptcl_buf = buffers. ptcl . fit_slice ( buffer_sizes. ptcl ) ;
100
133
101
- let ptcl_buf = buffers. ptcl . to_fit ( buffer_sizes. ptcl ) ;
102
- let reduced_buf = buffers. path_reduced . to_fit ( buffer_sizes. path_reduced ) ;
134
+ let reduced_buf = buffers. path_reduced . fit_slice ( buffer_sizes. path_reduced ) ;
103
135
104
136
pathtag_reduce_main ( wg_counts. path_reduce . 0 , & config_buf, scene_buf, reduced_buf) ;
105
137
106
- let tagmonoid_buf = buffers. path_monoids . to_fit ( buffer_sizes. path_monoids ) ;
138
+ let tagmonoid_buf = buffers. path_monoids . fit_slice ( buffer_sizes. path_monoids ) ;
107
139
108
140
pathtag_scan_main (
109
141
wg_counts. path_scan . 0 ,
110
142
& config_buf,
111
143
scene_buf,
112
- reduced_buf,
144
+ & * reduced_buf,
113
145
tagmonoid_buf,
114
146
) ;
115
147
116
148
// Could re-use `reduced_buf` from this point
117
149
118
- let path_bbox_buf = buffers. path_bboxes . to_fit ( buffer_sizes. path_bboxes ) ;
150
+ let path_bbox_buf = buffers. path_bboxes . fit_slice ( buffer_sizes. path_bboxes ) ;
119
151
120
152
bbox_clear_main ( & config_buf, path_bbox_buf) ;
121
153
let bump_buf = & mut buffers. bump_alloc ;
122
- let lines_buf = buffers. lines . to_fit ( buffer_sizes. lines ) ;
154
+ let lines_buf = buffers. lines . fit_slice ( buffer_sizes. lines ) ;
123
155
flatten_main (
124
156
wg_counts. flatten . 0 ,
125
157
& config_buf,
126
158
scene_buf,
127
- tagmonoid_buf,
159
+ & * tagmonoid_buf,
128
160
path_bbox_buf,
129
161
bump_buf,
130
162
lines_buf,
131
163
) ;
132
164
133
- let draw_reduced_buf = buffers. draw_reduced . to_fit ( buffer_sizes. draw_reduced ) ;
165
+ let draw_reduced_buf = buffers. draw_reduced . fit_slice ( buffer_sizes. draw_reduced ) ;
134
166
135
167
draw_reduce_main (
136
168
wg_counts. draw_reduce . 0 ,
@@ -139,58 +171,58 @@ pub fn run_coarse_cpu(
139
171
draw_reduced_buf,
140
172
) ;
141
173
142
- let draw_monoid_buf = buffers. draw_monoids . to_fit ( buffer_sizes. draw_monoids ) ;
143
- let clip_inp_buf = buffers. clip_inps . to_fit ( buffer_sizes. clip_inps ) ;
174
+ let draw_monoid_buf = buffers. draw_monoids . fit_slice ( buffer_sizes. draw_monoids ) ;
175
+ let clip_inp_buf = buffers. clip_inps . fit_slice ( buffer_sizes. clip_inps ) ;
144
176
draw_leaf_main (
145
177
wg_counts. draw_leaf . 0 ,
146
178
& config_buf,
147
179
scene_buf,
148
- draw_reduced_buf,
149
- path_bbox_buf,
180
+ & * draw_reduced_buf,
181
+ & * path_bbox_buf,
150
182
draw_monoid_buf,
151
183
info_bin_data_buf,
152
184
clip_inp_buf,
153
185
) ;
154
186
155
187
// Could re-use `draw_reduced_buf` from this point
156
188
157
- let clip_el_buf = buffers. clip_els . to_fit ( buffer_sizes. clip_els ) ;
189
+ let clip_el_buf = buffers. clip_els . fit_slice ( buffer_sizes. clip_els ) ;
158
190
159
- let clip_bic_buf = buffers. clip_bics . to_fit ( buffer_sizes. clip_bics ) ;
191
+ let clip_bic_buf = buffers. clip_bics . fit_slice ( buffer_sizes. clip_bics ) ;
160
192
161
193
if wg_counts. clip_reduce . 0 > 0 {
162
194
clip_reduce_main (
163
195
wg_counts. clip_reduce . 0 ,
164
- clip_inp_buf,
165
- path_bbox_buf,
196
+ & * clip_inp_buf,
197
+ & * path_bbox_buf,
166
198
clip_bic_buf,
167
199
clip_el_buf,
168
200
) ;
169
201
}
170
- let clip_bbox_buf = buffers. clip_bboxes . to_fit ( buffer_sizes. clip_bboxes ) ;
202
+ let clip_bbox_buf = buffers. clip_bboxes . fit_slice ( buffer_sizes. clip_bboxes ) ;
171
203
172
204
if wg_counts. clip_leaf . 0 > 0 {
173
205
clip_leaf_main (
174
206
& config_buf,
175
207
clip_inp_buf,
176
- path_bbox_buf,
208
+ & * path_bbox_buf,
177
209
draw_monoid_buf,
178
210
clip_bbox_buf,
179
211
) ;
180
212
}
181
213
182
214
// Could re-use `clip_inp_buf`, `clip_bic_buf`, and `clip_el_buf` from this point
183
215
184
- let draw_bbox_buf = buffers. draw_bboxes . to_fit ( buffer_sizes. draw_bboxes ) ;
216
+ let draw_bbox_buf = buffers. draw_bboxes . fit_slice ( buffer_sizes. draw_bboxes ) ;
185
217
186
- let bin_header_buf = buffers. bin_headers . to_fit ( buffer_sizes. bin_headers ) ;
218
+ let bin_header_buf = buffers. bin_headers . fit_slice ( buffer_sizes. bin_headers ) ;
187
219
188
220
binning_main (
189
221
wg_counts. binning . 0 ,
190
222
& config_buf,
191
- draw_monoid_buf,
192
- path_bbox_buf,
193
- clip_bbox_buf,
223
+ & * draw_monoid_buf,
224
+ & * path_bbox_buf,
225
+ & * clip_bbox_buf,
194
226
draw_bbox_buf,
195
227
bump_buf,
196
228
info_bin_data_buf,
@@ -202,11 +234,11 @@ pub fn run_coarse_cpu(
202
234
// TODO: What does this comment mean?
203
235
// Note: this only needs to be rounded up because of the workaround to store the tile_offset
204
236
// in storage rather than workgroup memory.
205
- let path_buf = buffers. paths . to_fit ( buffer_sizes. paths ) ;
237
+ let path_buf = buffers. paths . fit_slice ( buffer_sizes. paths ) ;
206
238
tile_alloc_main (
207
239
& config_buf,
208
240
scene_buf,
209
- draw_bbox_buf,
241
+ & * draw_bbox_buf,
210
242
bump_buf,
211
243
path_buf,
212
244
tile_buf,
@@ -218,36 +250,38 @@ pub fn run_coarse_cpu(
218
250
219
251
path_count_setup_main ( bump_buf, & mut indirect_count_buf) ;
220
252
221
- let seg_counts_buf = buffers. seg_counts . to_fit ( buffer_sizes. seg_counts ) ;
222
- path_count_main ( bump_buf, lines_buf, path_buf, tile_buf, seg_counts_buf) ;
253
+ let seg_counts_buf = buffers. seg_counts . fit_slice ( buffer_sizes. seg_counts ) ;
254
+ path_count_main ( bump_buf, & * lines_buf, & * path_buf, tile_buf, seg_counts_buf) ;
223
255
224
- backdrop_main ( & config_buf, bump_buf, path_buf, tile_buf) ;
256
+ backdrop_main ( & config_buf, & * bump_buf, & * path_buf, tile_buf) ;
225
257
226
258
coarse_main (
227
259
& config_buf,
228
260
scene_buf,
229
- draw_monoid_buf,
230
- bin_header_buf,
231
- info_bin_data_buf,
232
- path_buf,
261
+ & * draw_monoid_buf,
262
+ & * bin_header_buf,
263
+ & * info_bin_data_buf,
264
+ & * path_buf,
233
265
tile_buf,
234
266
bump_buf,
235
267
ptcl_buf,
236
268
) ;
237
269
270
+ // TODO: Remove
238
271
path_tiling_setup_main (
239
272
bump_buf,
240
273
& mut indirect_count_buf, /* ptcl_buf (for forwarding errors to fine)*/
241
274
) ;
242
275
243
276
path_tiling_main (
244
277
bump_buf,
245
- seg_counts_buf,
246
- lines_buf,
247
- path_buf,
248
- tile_buf,
278
+ & * seg_counts_buf,
279
+ & * lines_buf,
280
+ & * path_buf,
281
+ & * tile_buf,
249
282
segments_buf,
250
283
) ;
284
+ ControlFlow :: Continue ( ( ) )
251
285
}
252
286
253
287
pub fn render_to_texture (
0 commit comments