-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Add lightmap bake canceling #99483
Add lightmap bake canceling #99483
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposal enhancement makes sense to me.
I have yet to review the pull request, but this is good from a usability point of view. Cancelling a potentially 30-minute plus bake is essential rather than forcing quitting.
1857ef4
to
b8911da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected.
However, a memory leak occurs if I cancel baking while indirect light is being calculated:
lightmap_bake_leak.mp4
Every time I cancel baking, VRAM utilization grows by 600 MB without shrinking after.
No leak occurs if I cancel baking just after it starts (by pressing Space immediately after the progress dialog pops up, which presses the autofocused Cancel button).
I'm not surprised, these early return error conditions will need to free the GPU resources before returning as we do with the current error handling. See for example godot/modules/lightmapper_rd/lightmapper_rd.cpp Lines 1453 to 1465 in 9e60984
|
b8911da
to
5bca028
Compare
I updated the PR, it should release memory now (thanks to @Calinou 's video i also learned the AMD equivalent to the tool he uses - There were already some existing early exits in the function so i thought it was ok to exit, i guess they are also leaks. There are a lot of exit points in this so it should probably be refactored to have a single exit point with some sort of "if (error) goto fail" at the end of the function that cleans up everything, so perhaps someone more familiar with the code could clean it up (i could do it in the future if nobody does but i think some stuff may need to be moved around and at the moment i do not feel confident enough to touch anything that would affect the code's logic). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, there are no more memory leaks now, regardless of how many times I cancel the bake (at different stages).
Thanks! Congratulations on your first merged contribution! 🎉 |
This enables the "Cancel" button in the lightmap baking progress window and checks the cancel request whenever a progress is updated/reported during lightmap baking. Most of the functionality was already there, including a potential cancel request by the callback, but callback's return value was never checked.
This adds some checks where possible. A couple of progress updates wouldn't forward a cancellation result so i didn't add them but in practice i never saw them when testing cancelling (though i mainly tested with the GI demo). The main part that takes most of the time, indirect light integration, does get cancelled.
The patch just stops the lightmap calculation when it gets cancelled. I didn't notice this creating any leaks, but i might have missed them as this is the first time i saw the lightmapper code, so someone who is more familiar with this should review it.
This should address godotengine/godot-proposals#8181.