Commit 6f22a89
authored
Fix: Properly handle scene resets to ensure correct alpha rendering (#859)
### Overview
This PR addresses the visual artifacts (dotted/dashed lines) that appear
when rendering the same scene multiple times using the `vello_hybrid`
renderer.
<img width="532" alt="image"
src="https://github.com/user-attachments/assets/da632491-987e-4f6f-a4dc-2ad4fb730282"
/>
### Issue Description
Previously, when resetting the scene and re-rendering repeatedly,
strange visual artifacts would appear at the boundaries between shapes -
specifically dotted or dashed lines along what should be properly alpha
sampled boundaries. These artifacts only appeared when:
- The scene was reset and re-rendered in `RedrawRequested` event handler
- The `prepare` method was called after each re-render
### Root Cause
The root cause was a misalignment between the alpha values stored in the
scene and the GPU alpha texture:
- When `Scene::reset` was called, it correctly cleared the alphas array
in the scene (reset added as a separate commit)
- When `render_svg` was called, it populated the scene with new alpha
values
- However, `Renderer::prepare` method only created a new alpha texture
when the strips buffer size increased
- This led to a situation where new alpha values were being written to a
texture sized for previous frames, or, if alphas weren’t properly reset,
they retained stale data from previous frames, causing textures to grow
larger each frame, meantime alpha data copying size was restricted to
the current texture size.
- The shader was calculating texture coordinates based on strip `col`
values, but these values pointed to positions that might exceed the
texture dimensions
- Due to GPU texture addressing behavior, these out-of-bounds accesses
"wrapped around" silently, causing the shader to sample completely
unrelated alpha values
The critical issue was that we were only checking if the strips buffer
needed to be recreated, but not independently verifying if the alpha
texture needed to be recreated when only the alpha values changed.
### Solution
Fixed the issue by modifying `prepare` method to:
- Separately check if the strips buffer or alpha texture needs to be
recreated
- Create a new alpha texture whenever the required texture size exceeds
the current texture size
- Ensure both resources are properly sized for the current frame's data
before writing to them
- Add assertions to verify the alpha texture is large enough to hold all
the alpha values
This ensures that the alpha texture always matches the current frame's
alpha values, maintaining the correct relationship between strip `col`
indices and texture coordinates, eliminating the visual artifacts.
### Notes
- `Scene::reset` method has been updated to properly (fully) reset the
scene state by clearing all data1 parent 654e47c commit 6f22a89
4 files changed
+230
-113
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 98 | | |
112 | 99 | | |
113 | 100 | | |
| |||
132 | 119 | | |
133 | 120 | | |
134 | 121 | | |
135 | | - | |
136 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
137 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
| |||
169 | 167 | | |
170 | 168 | | |
171 | 169 | | |
172 | | - | |
| 170 | + | |
173 | 171 | | |
174 | 172 | | |
175 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
| |||
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
71 | 92 | | |
72 | 93 | | |
73 | 94 | | |
| |||
100 | 121 | | |
101 | 122 | | |
102 | 123 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | 124 | | |
107 | 125 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 126 | + | |
120 | 127 | | |
121 | 128 | | |
122 | 129 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
157 | 201 | | |
158 | | - | |
159 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
160 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
161 | 220 | | |
162 | 221 | | |
163 | 222 | | |
| |||
190 | 249 | | |
191 | 250 | | |
192 | 251 | | |
193 | | - | |
| 252 | + | |
194 | 253 | | |
195 | 254 | | |
196 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
212 | 210 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
220 | 217 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
226 | 221 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
232 | 226 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
249 | 249 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
259 | 255 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
267 | 262 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
274 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
275 | 305 | | |
276 | 306 | | |
277 | 307 | | |
278 | 308 | | |
279 | 309 | | |
280 | | - | |
| 310 | + | |
281 | 311 | | |
282 | 312 | | |
283 | 313 | | |
| |||
291 | 321 | | |
292 | 322 | | |
293 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
294 | 328 | | |
295 | 329 | | |
296 | 330 | | |
| |||
0 commit comments