Skip to content

Add fast path for stripping rectangles #900

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

Closed
wants to merge 20 commits into from
Closed

Add fast path for stripping rectangles #900

wants to merge 20 commits into from

Conversation

LaurenzV
Copy link
Contributor

@LaurenzV LaurenzV commented Apr 6, 2025

This re-adds my previously implemented fast path for rectangles. In my test scene with 20000 rectangles, this reduces the rendering time from around 37ms to 19ms!

@LaurenzV LaurenzV requested a review from tomcur April 6, 2025 09:33
Copy link
Member

@tomcur tomcur left a comment

Choose a reason for hiding this comment

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

An initial thought inline, I'll look more in-depth in the coming days.

Copy link
Member

@tomcur tomcur left a comment

Choose a reason for hiding this comment

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

Most tests with rectangles call RenderContext::fill_rect, which now uses the specialized path for rectangles. It would be good to continue exercising the general case as well.

I don't know what the best solution looks like. Perhaps performing multiple tests against the same snapshot could work, though we'd have to be robust against small rounding errors.

@LaurenzV
Copy link
Contributor Author

I've added a few more test cases which check against the same snapshot as the rectangle case, I feel like this should already be an improvement? As you mentioned, there are few other test cases with rectangles, but there's also only so many ways to draw a rectangle. :P So I think this should already be a good coverage.

Copy link
Contributor

@taj-p taj-p left a comment

Choose a reason for hiding this comment

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

Nice! This was a great read! Certainly adding a fast path for rects makes sense and I can see how it is so much faster.

edit: If it isn't clear, please don't let any of my comments block this from merging!

// and pattern fills.
let (x0, x1, y0, y1) = (
rect.min_x().max(0.0) as f32,
rect.max_x().min(width as f64) as f32,
Copy link
Contributor

Choose a reason for hiding this comment

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

for min_x() == 30, max_x() == 40, width == 10, this sets x0 = 30 and x1 = 10. This propagates through to x_start and x_end. Later we check that x_end - x_start >= 1, but due to wraparound, that'll be true. The end result is that we write a lot of unnecessary alpha values.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented Jun 3, 2025

Maybe we can revisit in the future, but I'm pretty sure that for performant fine rasterization with SIMD, we will want to uphold the assumption that strips are always a multiple of 4 in width, which isn't the case with this fast path, and it might be tricky to change the PR to uphold this. So I'll close this for now.

@LaurenzV LaurenzV closed this Jun 3, 2025
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.

6 participants