Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in clip reduction #659

Merged
merged 2 commits into from
Aug 9, 2024
Merged

Fix error in clip reduction #659

merged 2 commits into from
Aug 9, 2024

Conversation

raphlinus
Copy link
Contributor

One bit of logic from the GLSL (piet-gpu) version of clip_reduce didn't get copied over.

Fixes #648

One bit of logic from the GLSL (piet-gpu) version of clip_reduce didn't get copied over.

Fixes #648
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs a test to be added.

I'm presuming that would just involve creating 256 clip areas?

@DJMcNab DJMcNab added this to the Vello 0.3 release milestone Aug 7, 2024
Add many_clips test scene and snapshot test.

Note that doing more than 128 clips, while it would exceed the 256 clip object limit (counting both begin and end clip), would not trigger the failure, as the end clip would be on a workgroup boundary. Using multiples of 3 (as in the original report) triggers the bug, and a full system hang was verified with the fix disabled.
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so nice seeing new scenes come with a test, because seeing them like this is much easier than running them.

I have not really dove into understanding the shader code, but it seems to fix the underlying issue based on the provided test.

Affine::translate((100. * (x as f64 + 0.5), 100. * (y as f64 + 0.5)));
const CLIPS_PER_FILL: usize = 3;
for _ in 0..CLIPS_PER_FILL {
let rot = Affine::rotate(rng.gen_range(0.0..PI));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the root path is rotationally symmetric every $$\frac{2\pi}{3}$$ radians, but this is doing a rotation every $$\pi$$ radians.

I think that means there's a bias towards the range which is equivalent to $$[0, \frac{\pi}{3})$$.

Practically, I don't think this matters here, but I'm wondering if this is an intentional choice.

(And of course, my maths understanding could be very wrong :P)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, you're right, there is a bias. Not thinking it through carefully, I assumed the symmetry would make it still uniform, and I wanted to make the code concise. I think I'll leave it, in the sprit of kintsugi.

Copy link
Member

@DJMcNab DJMcNab Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use $$\tau$$ (TAU) here to still be fairly concise.

But practically, this is great, and the bias isn't an issue!

scene.push_layer(Mix::Clip, 1.0, translate * rot, &base_tri);
}
let rot = Affine::rotate(rng.gen_range(0.0..PI));
let color = Color::rgb(rng.gen(), rng.gen(), rng.gen());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces remarkably pleasing colours considering that it's completely random - it's probably a good technique to use in other examples.

@raphlinus raphlinus added this pull request to the merge queue Aug 9, 2024
Merged via the queue into main with commit eecbf55 Aug 9, 2024
17 checks passed
@raphlinus raphlinus deleted the clip_reduce branch August 9, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clips cause compute shaders to take 10 seconds and results in corruption
2 participants