-
Notifications
You must be signed in to change notification settings - Fork 419
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
Decouple shader programs from the C++ backend infra #116
Conversation
For this to work with EDIT: Nevermind, hadn't full thought this out -- the path of the shaders needed to load them would be hard to figure out from c++. |
Or, maybe we can compile the shader source files into the binary itself? |
Actually, doing the setup.py thing is probably best as it keeps the spirit of the PR. The path of the shader directory will just need to be set-able at runtime. The shader directory is then just |
In my current implementation, the system tries to find the shaders by the shaderPath + shaderFilename. By the current design, "shaderFilename" can be provided during run-time by the user. After all shaders (e.g., vert, tcs, tes, geom, frag) are provided, user calls the function "loadShaders()" to equip the simulator with them; |
Yes, but if the user deletes |
Thanks for opening this PR @bigbike -- this has long been a pain point, and it would be great to decouple shader source from C++ code as we flesh out our shading more fully. A high-level comment (before reviewing the code in any depth). I think we can achieve decoupling of shaders from other source code in a more lightweight and flexible way by leveraging the file resource management functionality that Magnum+Corrade already provides for us 🙂You can see how this is used in the the textured-triangle example and relevant documentation is here. I'm sure @mosra could offer even more pointers and advice regarding this. |
I have to admit I'm not a big fan of the The main goal of this PR is to make shaders tweakable without recompiling the C++ code, right? I think that doesn't necessarily mean we need to store them as separate files loaded at runtime -- because that means you need to hardcode or somehow detect the path to them, unnecessarily complicating things. As @msavva pointed out, I'd suggest using Utility::Resource and compile the shader sources into the final executable. With that you get:
By the way (we discussed this with @mathfac at CVPR): there's the Utility::Tweakable class that allows you to live-edit constants in C++ code with realtime feedback in the app. Right now it supports only numeric constants (color and angle literals as well), but could be extended for strings as well, if there's interest. That could be an alternative solution to avoid recompiling while iterating on shaders or other stuff that needs a lot of fiddling with. |
@msavva, @mosra : "Use Utility::Resource". I read the "textured triangle" code before coding. My concern is that an extra config file (specifying shader filenames) would be introduced to the system. @mosra: When you mentioned "you are not a big fan of GenericShader", are you actually talking about the "BaseShader" introduced in this PR? If yes, I have the same feelings. I already explained my initial purpose above, and found it was not practical afterwards. The code is just heavily shader-specific. So I tried to make a compromise here, only storing the {vert, geom, frag} shaders' filenames, and defining a pure virtual function loadShaders, which required developer to implement (based on her shaders). In terms of "GenericShader": it exists in the code since the very beginning. And I agree with the naming is confusing. It just refers to the shaders that can render any meshes other than "PTexMesh", according to my understanding. In terms of "Utility::Tweakable": When it is fully implemented, user can modify the shader source code without re-compiling the system (assuming shaders are already compiled into binary)? It is fancy. But I doubt if we can used it due to our urgent needs. In terms of "configure_file": It seems it can avoid the config file. Do you think it is still a good idea after reading my comments? @ALL: Let me know your thoughts towards the final solutions. Thanks! |
The configure file suggested by @mosra is not something users would need to worry about. It is just a nicer way to do |
@erikwijmans : The method, which does require the extra config file can be found here: https://doc.magnum.graphics/magnum/examples-textured-triangle.html It is totally different from the "configure.h" method that Vladimir mentioned in this PR. (I like the "configure.h" idea by the way.) |
Yeah, that WRT to |
I actually think the right way to go is to remove the For the more specific points:
Definitely 👍-- this is the most important improvement in my mind, and can be cleanly achieved using the
👍I think this is the way to go and will avoid all sorts of "path-to-the-shader-file" headaches down the line.
There are convenient functions for querying GL version and extension support in Magnum that can be used for this (see example with conditional GL version handling in the WebGL branch)
For the purpose of cleaning up our current shader code, I don't think the addition of a
Yes, updates to |
Yes, that's what I'm saying -- the shader code and its application interface (whether C++ or Python) are highly coupled and making a generic interface that can accept any shader code is practically impossible. Suppose you improve a builtin shader to access lightprobe data in order to figure out dynamic lighting. That means you need to supply it some uniform or bind a texture for every object it renders -- which means you need to add an C++/Python API for that, it's never about just supplying a different GLSL source. The only way out of this I can see is, as @msavva says, removing
This is purely a build-time thing -- the
Looking at the sources, the only thing that requires GLSL 4.30 is the SSBO in |
.circleci/config.yml
Outdated
python setup.py develop --all | ||
python -u habitat_baselines/train_ppo.py --log-file "train.log" --checkpoint-folder "data/checkpoints" --sim-gpu-id 0 --pth-gpu-id 0 --num-processes 1 --num-mini-batch 1 --num-updates 10 | ||
python setup.py test | ||
python -u habitat_baselines/run.py --exp-config habitat_baselines/config/pointnav/ppo_train_test.yaml --run-type train |
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.
hmm...
Rebased on or merged from master branch, and it shows in my branch as change.
Strange.
How can I get rid of it?
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.
Did you merge with master or did you just cherry-pick the commit of #118 (the commit history makes it seems like the latter was done).
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.
@erikwijmans : No, I did not do cherry-pick. I did rebase or merge master though. Very strange.
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.
This can be easily fixed with a manual merge (squash everything into a single commit and then remove this change). I can do that once we all approve :)
@mosra : I have not tried the headless mode with python. I suspect in order to make the python simulator work, I may also need to apply it somewhere else (e.g., Simulator.cpp in the gfx module), shall I? |
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.
Thank you!
@mosra :
I do not think it is related to the CORRADE_USE_PEDANTIC_FLAGS as I also saw similar ones from the "datatools". @ALL: |
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 great to me! For the CircleCI change, I can do a manual merge and revert that while merging.
Added the CORRADE_USE_PEDANTIC_FLAGS
to the list in #42, together with the Assimp warning (I think it's related to -fvisibility-inline-hidden
I was fixing elsewhere some time ago, so could be fixed by enabling this flag for Assimp as well).
@mosra : Thank you. Update: I just tested it on the dev server which was linux system. I tested the system (headless mode) with Replica model (vertex colored) and glb model. Result pictures from both experiments look 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.
LGTM! 👍 I like the minimalism and cleanliness now that we're relying on Utility::Resource
!
Keep them compiled-in, but use Utility::Resource for that, so these can be edited as external files.
Pushed a squashed commit w/o the |
@mosra: Thank you, Vladimir. Also many thanks to the other reviewers. Merge and close it. |
…bookresearch#116) * Adding jupyter notebook illustrating demonstrating how to extract camera parameters in the scene and how these camera parameters relate to the given views with proper testing.
Decouple shader programs from the C++ backend infra
Motivation and Context
This PR is to separate the shader programs, which is currently hard coded, from the C++ infra. Individual shader programs are now put in the folder called "shaders". In the future, user can code it up her own shaders and apply them in our simulator.
Benefit:
-) This is the 1st step to fully support rendering Replica model with advanced features, such as PTex textures, mirror reflections, HDR etc.
-) Provide more rendering flexibility. User can customize the shader based on their needs without recompiling the simulator;
How Has This Been Tested
Tested it on mac so far. I will test on Linux as well.
Tested the rendering in the viewer (utility) with MP3D and Replica model (vertex colored). Everything is OK.
Types of changes
Checklist