Cleanup and development of flag to enable/disable rendering#1308
Cleanup and development of flag to enable/disable rendering#1308ldcWV merged 37 commits intofacebookresearch:masterfrom
Conversation
…mulator without a Magnum/OpenGL context
…te_magnum_renderer=False
…createDrawable to constructors of GenericDrawable and PbrDrawable
eundersander
left a comment
There was a problem hiding this comment.
Good progress here. I left some comments.
|
|
||
| scene::SceneNode& node_; | ||
| Magnum::GL::Mesh& mesh_; | ||
| Magnum::GL::Mesh* mesh_ = nullptr; |
There was a problem hiding this comment.
Can you post a reply here and explain to other reviewers why we did this change?
There was a problem hiding this comment.
The createRenderer flag prevents the function GenericMeshData::uploadBuffersToGPU from running, which is the function that creates GL::Mesh. This means that the GenericMeshData that are inserted into ResourceManager::meshes_ will not have set GL::Mesh fields.
However, getMagnumGLMesh is still being called on elements of meshes_. These calls will return NULL because no GL::Mesh objects were ever created. Yet we are still trying to do things with the returned values, which is unsafe.
Therefore, we instead store pointers to the GL::Mesh objects so that we must explicitly dereference them, which requires first checking that they are not nullptr. This allows us to avoid undefined behavior by failing fast.
Skylion007
left a comment
There was a problem hiding this comment.
@bigbike Should be the one to look at this considering how it intertwines with the GFX system.
|
FYI the Same is for textures and other GL objects ( (Apologies if this suggestion came too late, was too busy to check PR reviews regularly.) |
eundersander
left a comment
There was a problem hiding this comment.
LGTM. Let's get the unit tests passing and get this merged.
bigbike
left a comment
There was a problem hiding this comment.
Please fix all the places that I mentioned, before committing it in.
As you say, this suggestion is coming a bit late. :) For this PR, we removed GL::Mesh creation as you originally requested in our Slack discussions. This PR has been under review for a while and we'd like to get it merged. Let's do the switch to |
@mosra : Great. Good to know. However, I guess one reason they changed them to pointer is that they can easily tell if the simulator is initialized with the renderer (just checking if the pointer is NULL). |
|
|
||
| void GenericDrawable::draw(const Mn::Matrix4& transformationMatrix, | ||
| Mn::SceneGraph::Camera3D& camera) { | ||
| if (!isRendererCreated) { |
There was a problem hiding this comment.
It turns out that this block is not necessary because the GenericDrawable::draw codepath is impossible to reach when createRenderer==false.
| cfg.createRenderer = false; | ||
| metadataMediator_ = MetadataMediator::create(cfg); | ||
| resourceManager_ = std::make_unique<ResourceManager>(metadataMediator_); | ||
| context_ = esp::gfx::WindowlessContext::create_unique(0); |
There was a problem hiding this comment.
Wait, if you change this, then we lose the protection from the unit test when the context needs to be created.
In your case, you need to create a brand new test function to test when the Renderer is not created.
There was a problem hiding this comment.
Doing this shows that you don't need a context in order to do physics when createRenderer==false, which is good to know. Maybe I can modify the tests to try both with and without context. Do you think this is a good idea?
I already added a non-physics test with createRenderer=false in SimTest.cpp by the way.
There was a problem hiding this comment.
Sorry for late reply here. I want to see this change stay as-is.
I actually love that we're now guaranteed not to use OpenGL in our Physics unit tests. Conceptually, physics tests shouldn't rely on rendering. Let's imagine a future day where we've completely decoupled physics and rendering code--it'll be nice that these tests just port over directly, without having to be fixed up. By never creating a context here, we're guaranteed that our physics test code is "clean"--not accidentally relying on some rendering feature.
we lose the protection from the unit test when the context needs to be created.
If you have in mind a unit test that involves physics and rendering, the best place for that is SimTest. Simulator is where we integrate physics and rendering. You can add objects, make them interact with physics, then call draw() or whatever and check the result.
There was a problem hiding this comment.
This has nothing to do with the visualization verification. We do that in the SimTest. No problem.
My opinion is that by doing both (with or without gl context) in the physicsTest, we have solid proof that physics simulation and the rendering are totally orthogonal to each other. Both tests should pass.
There was a problem hiding this comment.
Do we have a test in the SimTest that creates a GL context and enabled and timestepped physics? No, we do not have.
We used to count on this physicsTest here until this change.
There was a problem hiding this comment.
My opinion is that by doing both (with or without gl context) in the physicsTest, we have solid proof that physics simulation and the rendering are totally orthogonal to each other. Both tests should pass.
Ok, fair enough. We'll try to find a way to run both versions of the physics tests, hopefully without duplicating a lot of code.
There was a problem hiding this comment.
Yeah, I hear you.
Too bad we are using the google test, not the corrade test (used in the SimTest).
Corrade test supports instanced tests. See here.
This diff is to add a new feature which can enable/disable the rendering. I saw Lawrence added tests in the SimTest. So I assume this feature is well covered.
We also know the current solution is a temporary solution as we will refactor this code in the near future. So I am totally fine if we do not touch the PhysicsTest.cpp at all in this PR. I think it is the easiest way to unblock it.
Are you comfortable with this solution?
There was a problem hiding this comment.
I've made a commit to run PhysicsTest both with and without the flag set.
Motivation and Context
This PR is a continuation of Eric's PR here: #1258
Here is the todo list in the PR and how I addressed them:
The flag is now stored in SimulatorConfiguration and passed around using getter methods. GenericDrawable also has a copy of the flag that is set in its constructor.
Turns out the PbrDrawable codepath is impossible to reach when
createRenderer=false. See #1308 (comment)See SimTest.cpp.
This was referring to the skipping of the
ResourceManager::initDefaultPrimAttributesmethod if the flag is off. The concern was that because of this, primitives would not be loaded correctly and thus should not be used. However, it appears that the only thing disabling this method affects is the visualization of bounding boxes, which doesn't matter when not using a renderer anyways.The old createRenderer flag and its codepath have been deleted. The new flag has been renamed to createRenderer.
Decided in meeting against this approach.
Done (first feature). GL::Mesh and Shaders::FlatGL are no longer created when the flag is set.
How Has This Been Tested
A test case demonstrating the functionality (what still works, what doesn't work) when the flag is disabled has been added in
SimTest.cpp.Types of changes
Checklist