Renderdoc has a friendly Python API for writing custom scripts. It allows both modes:
- QRenderDoc is the host, scripts are embeded. Scripts runs in its UI
- Python Interpreter is the host, Renderdoc is library. In this case, scripts can freely use third-party libraries, and writes just like a normal Python script.
With custom Python scripts, developers have free access to all the data stored in a capture, and can analyze some additional information, such as how many drawcalls in a pass, how many textures/render targets are used, and sort them by their sizes in top-down order when analyzing some bottlenecks about VRAM/memory.
The installer from official website doesn't include Renderdoc Python libraries, which means that only Mode-1 is allowed(RenderDoc has an embedded Python3.6.4 which is distributted with the installer). We have to build RenderDoc from source if Python libraries are needed. The good news is that maintainers do a great job, and it's very easy to build it. With a MSVC environment, it's just a simple click on the green triangle, and that's enough.
After build, check
<PATH>\renderdoc-1.26\x64\Development\pymodules for renderdoc libs.
There should be
qrenderdoc.pyd(on Linux it may be
qrenderdoc.so) in it.
How to Generate Stubs?
Official documentations provides a basic description about the dev environment and a detailed reference about the Python API.
Renderdoc is not a native Python application, which is actually based on cpp.
It employs Swig to generate its Python bindings, which make python linter difficult to work with.
Whatsworse, it doesn't provide any Python stub files.
Instead, it provides an
Pycharm Patch for developers to generate stubs by themselves.
Although I'm a big fan of JetBrains and have a valid subscription of Pycharm, I feel uncomfortable with installing Pycharm just to generate stubs. Also, it has a strict version requirement(PyCharm 2020.3.2), which is not friendly. So I decide to find other ways to generate it.
There are some others facing the same problem, and uploads their result to github, such as this repo. However, neither it is up-to-date nor it provides any instructions about how to regenerate it on latest version.
After some search, I found
mypy provides a tool
stubgen to generate stubs from
It's relatively easy to use.
pip install --user mypy cd <PATH>\renderdoc-1.26\x64\Development\pymodules stubgen --parse-only -m renderdoc stubgen --parse-only -m qrenderdoc
It should generate
qrenderdoc.pyi in the folder, which holds API infos of Renderdoc libraries.
Copy the two
typings folder in the same level with our Renderdoc scripts, Python linters will found them.
. ├── iter_actions.py └── typings ├── qrenderdoc.pyi └── renderdoc.pyi
From now on, although not perfect(it doesn't provide any type information of function return values), we have a basic auto-completion.
For those who just want to take and go, there are two files generated by me from RenderDoc v1.26 available: https://gist.github.com/BlurryLight/5718987e699515ba480ba823c113ca83