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

Cancel build +progress monitor #67

Open
Silverlan opened this issue Oct 22, 2023 · 4 comments
Open

Cancel build +progress monitor #67

Silverlan opened this issue Oct 22, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Silverlan
Copy link

Embree has a progress monitor for build operations, that also allows you to cancel the build operation:
https://github.com/embree/embree/blob/master/README.md#description-description-21

It would be great to have something like this for this library as well. The ability to cancel in particular can be very handy for large scenes where building the bvh can take a very long time.

@madmann91 madmann91 added the enhancement New feature or request label Oct 27, 2023
@madmann91
Copy link
Owner

It should be possible to implement it, and by the way feel free to submit a PR for review. The issue though is that this requires some sort of knowledge of the build algorithm, in the sense that the notion of "progress" is really not going to be super accurate (it's -- for the most part -- a recursive process and you may not know the cost of building the subtree until you actually do it).

That said, a reasonable assumption that the cost of a subtree of size N is somewhat proportional to N log(N) might make sense. There's still the problem that the mini-tree builder runs in parallel so you have to take care of sending the progress information only once (or at least send it in an ordered fashion somehow). Maybe an atomic number is enough, so that you can start building the BVH, then check the progress at regular intervals by looking at the value held by that atomic.

So all in all it's a pretty complicated implementation for a small feature that, although nice to have, is not strictly necessary. I'll keep that in mind when doing further development work on the library though, if I can find the time for it.

@Silverlan
Copy link
Author

Silverlan commented Oct 28, 2023

Thanks for the response! Personally I'd be more interested in the ability to cancel anyway, the progress callback would just be nice-to-have.
In my case I have scenes where building the BVH can take several minutes and if the user closes the program during that, they currently have to wait until the BVH building is complete.

I haven't looked too closely at the source code for bvh, but I'll try and see if I can whip up a PR for that in the near future.

@madmann91
Copy link
Owner

For this specific use case, I don't think you need the ability to cancel the build per se. I would imagine that through OS services you can send a kill signal to the process that builds the BVH, without having to wait for the threads to join. If you want to kill your own process on Linux, use kill(getpid(), sig) or raise(sig) (where sig is the signal to send, SIGTERM or SIGKILL).

@madmann91
Copy link
Owner

If you don't want to kill the current process but want to continue executing the program, you could use a subprocess to build the BVH as a work around. This would allow you to kill it before it terminates. The downside is that you'll have to communicate via files or pipes. The serialization API allows you to do that, by sending a stream of bytes over, instead of writing to a file on disk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants