I wanted to try making a small python control panel to monitor viewport OpenGL memory usage. I was also going to explore methods to force a reduction in VRAM usage.
However, I've noticed several pieces that seem to be missing or non-functional in the Python API and was hoping I could get some info on them.
First it seems that several of the flags returned by c4d.GeGetSystemInfo() are missing from the python API. The only ones that appear to exist are c4d.SYSTEMINFO_NOGUI and c4d.SYSTEMINFO_OSX. I was hoping that c4d.SYSTEMINFO_OPENGL would be in there.
Second and more importantly I can't seem to get any information that's useful in my case from c4d.storage.GeGetMemoryStat(). The BaseContainer returned seems to only have values for c4d.C4D_MEMORY_STAT_MEMORY_INUSE and c4d.C4D_MEMORY_STAT_MEMORY_PEAK. All of the other keys return 0 or the keys don't exist in the BaseContainer at all. The latter is the case for c4d.C4D_MEMORY_STAT_OPENGL_USED and c4d.C4D_MEMORY_STAT_OPENGL_ALLOCATED which are the ones I was hoping for.
thank you for reaching out to us. Regarding the first part of your question, you have to use GeGetCinemaInfo() in R21+ which is the replacement for GeGetSystemInfo(), see end of the post for details.
About the second part of your question. I can confirm that c4d.storage.GeGetMemoryStat() will indeed not properly populate the returned container. I will have to investigate why this is happening, which might take some time.
# GeGetSystemInfo() has been deprecated in R21, see:
is_opengl = c4d.GeGetCinemaInfo(c4d.CINEMAINFO_OPENGL)
print ("is_opengl:", is_opengl)
@zipit thank you so much! c4d.GeGetCinemaInfo() makes sense. Unfortunately the current Python documentation is a bit misleading as c4d.GeGetSystemInfo() is not listed as deprecated and the description for c4d.GeGetCinemaInfo() makes it sound like it's exclusively for determining if the current C4D session is NFR.
Thank you very much for looking into c4d.storage.GeGetMemoryStat(). I'm excited to work on my little OpenGL control panel and stretch my GUI knowledge further
this is unfortunately a shortcoming of Python bindings at the moment and this issue will be fixed in an upcoming version of the Python API.
As a workaround you could use for now one of the 3rd party libraries listed in the Python Package Index (or anywhere else when you are brave) to get the gpu information you need. The first thing that comes up on PyPI is gpuinfo, but it does not instill much confidence, since it basically just runs a command line tool (see get_info()). Handling all the different GPU architectures is the problem here, and should be done by yourself if you want some sort of reliability. Or alternatively wait for a fix in Cinema's Python bindings.
Thanks again for the update. GPUtil came up as an option when I was researching external modules but it only works with NVIDIA hardware. That might not be so bad for now especially as the Python check for GPU hardware vendor in Cinema 4D does seem to be working.
I'll mark this as solved for now. I look forward to the API updates!
@ferdinand it looks like this hasn't changed in S24. Is there an expected timeline for a fix to these bindings?
thank you for reaching out to us. I am sorry if I gave you the impression that this will be fixed with S24. This issue is still on our radar, but it does not have the highest priority. I am also unfortunately not a liberty to give you a time frame when this will be done.
Thank you for your understanding,