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

Use neighbor info to optimize performance #8

Open
ConnyOnny opened this issue Jan 23, 2022 · 0 comments
Open

Use neighbor info to optimize performance #8

ConnyOnny opened this issue Jan 23, 2022 · 0 comments

Comments

@ConnyOnny
Copy link
Owner

After an initial SDF calculation for some pixel yielding distance "D", we know that the result for the neighboring pixel will be off by at most 1. So when iterating the mipmap, we can throw out any regions, whose farthest point is nearer than D-1 and regions whose nearest point is farer than D+1.

Unfortunately this makes parallelisation more complicated. Each Thread has to track this neighbor pixel info separately, because they all work on different parts of the image. We need to use a thread local variable for that; either using thread_local!(static LAST_PIXEL_INFO: RefCell<Option<LastPixelInfo>> = RefCell::new(None)); or manually using Thread::spawn to create an actually local variable in there. Also it makes long consequtive runs of pixels more effective, s.t. a manual allocation of work regions to threads may be beneficial, although I guess Rayon already tries to allocate consequtive regions as much as possible, so a comparison benchmark should be done first.

To avoid a reset at the end of each line of pixels, we can either also store the data for the first pixel of the last visited line and refer to that on line switch, or we can switch direction (right-to-left vs left-to-right) for each line.

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

No branches or pull requests

1 participant