[AO migration] async rendering#1229
Conversation
|
@erikwijmans I'd appreciate your input on this PR since you created this feature. 🙂 |
|
|
||
| #include <atomic_wait.h> | ||
|
|
||
| contended_t contention[256]; |
There was a problem hiding this comment.
How about some comments here, and let's avoid unnamed magic numbers like 256 and 255.
There was a problem hiding this comment.
Oops, didn't notice this is a dependency from Nvidia. Would be nice to document where exactly we got this (since it's not a submodule). For example, do they version this?
There was a problem hiding this comment.
This is a reference implementation for cpp20's atomic wait, it isn't part of a library so that's why it's not a submodule (it isn't intended to be compiled by another project) and it is not versioned (as this is the only version).
eundersander
left a comment
There was a problem hiding this comment.
I still consider it an open question whether we should merge this to master. It would be nice if the PR description listed the known caveats/issues with this approach. (@aclegg3 mentioned that it was unsafe to reset the scene or something like that).
Anyway I left some comments.
|
|
||
| #include <atomic_wait.h> | ||
|
|
||
| contended_t contention[256]; |
There was a problem hiding this comment.
Oops, didn't notice this is a dependency from Nvidia. Would be nice to document where exactly we got this (since it's not a submodule). For example, do they version this?
| self.drawAsync(visualSensor, sceneGraph, view, | ||
| RenderCamera::Flags{flags}); | ||
| }, | ||
| R"(Draw given scene using the visual sensor)", "visualSensor"_a, |
There was a problem hiding this comment.
Need better comments for all these new bindings.
| .def("reconfigure", &Simulator::reconfigure, "configuration"_a) | ||
| .def("reset", &Simulator::reset) | ||
| .def("close", &Simulator::close) | ||
| .def("close", &Simulator::close, "destroy"_a = false) |
There was a problem hiding this comment.
Needs a comment. What is close versus close-and-destroy?
| #include "esp/sensor/VisualSensor.h" | ||
| #include "esp/sim/Simulator.h" | ||
|
|
||
| #if !defined(CORRADE_TARGET_EMSCRIPTEN) |
There was a problem hiding this comment.
I'd prefer to see #ifdef ENABLE_ASYNC_RENDERING everywhere instead of !defined(CORRADE_TARGET_EMSCRIPTEN) everywhere. It would be more readable. And we may want to enable/disable this code based on other reasons in the future.
|
|
||
| #if !defined(CORRADE_TARGET_EMSCRIPTEN) | ||
|
|
||
| struct BackgroundRenderThread { |
There was a problem hiding this comment.
This is a big struct with lots of code so let's move it to its own file.
| Mn::GL::Context::makeCurrent(threadContext_); | ||
| threadOwnsContext_ = true; | ||
|
|
||
| Mn::GL::Renderer::enable(Mn::GL::Renderer::Feature::DepthTest); |
There was a problem hiding this comment.
Is this bit of render-state logic copy-pasted from Renderer::Impl constructor? I'm worried about maintaining this. Can we avoid the code duplication?
|
|
||
| bool makeCurrentPlatform() { | ||
| if (!windowlessGLContext_.makeCurrent()) | ||
| Mn::Fatal{} << "Failed to make platform current"; |
There was a problem hiding this comment.
As far as detecting/throwing fatal errors, we also have ESP_CHECK and CORRADE_ASSERT. This style here is new to me. Is it correct?
|
Have we tested this on Mac? |
|
@eundersander @aclegg3 @bigbike I refactored this and tried to make the API a little more user friendly, i.e. force people to set physics immediately after starting the async draw. I also made initialization of the background render thread lazy, so that if people never make async render calls, it will never be initialized and everything will work exactly like before. |
|
@erikwijmans Thanks for the work on this. I think it can land if we add a short python smoke test / tutorial script which can be checked on CI by |
…okresearch/habitat-sim into ao-migration-async-render
|
@erikwijmans Thanks for adding the example! Agreed with @eundersander that some docstrings for new functions and python bindings would be ideal, but I think this is ready. |
|
@erikwijmans thanks for adding I'm surprised this passed our CI (which is also Ubuntu, I think). How confident are we that this python actually ran as part of https://app.circleci.com/pipelines/github/facebookresearch/habitat-sim/6961/workflows/26578358-7348-4169-ad02-d840053f266c/jobs/34364 ? Is it possible the CI machine ran it with a single hardware thread or otherwise somehow avoided the crash I hit? |
Motivation and Context
This PR introduces async rendering in a background thread allowing overlap of CPU physics simulation and GPU rendering operations resulting in a significant performance improvement. For training scenarios, this does result in delayed observation (the visual observations passed to the model will be one step behind the physical state) which is, however, analogous with sensor latency on physical systems.
Note: this feature is not enabled by default due to instability on some systems and potential for memory leaks if not properly used. See
examples/tutorials/async_rendering.pyfor details.Thanks @erikwijmans for building the vast majority of this feature.
How Has This Been Tested
Adds a python example with CI testing.
Types of changes
Checklist