CPU usage during rendering graphics using TinyGL
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 453 from 2003/7/26
    From: Wroclaw/Poland
    I would like to ask about something regarding TinyGL because I probably something don’t understand.

    Disclaimer
    I am talking about current final public version of TinyGL in MorphOS 3.17 which doesn’t support shaders (fixed pipeline). Please forget for a moment about amazing public beta-versions of TinyGL which have been released by Bigfoot. :)

    Introduction
    There may be two reasons for low performance of a program which uses OpenGL 1.x (fixed pipeline) for rendering a graphics on screen:
    1. Geometry of graphics is too high and CPU (in case of fixed pipeline) is not able to recalculate all transformations.
    2. Huge polygons (especially with transparency) with big textures cause problems with fillrate performance.

    Observation
    I see that I can create very very simple geometry (which is not a challenge for 68040) with huge polygons for achieve low performance. In this case CPU gauge shows 100% usage. If I resize window from 1440x960 to 320x200, CPU usage is about 10-15%.

    Questions
    1. Is it normal situation that CPU usage is very high when geometry is extremely low but big polygons kill fillrate? Should I observe 100% CPU usage in this case? Should rendering of huge polygons (using 3d accelerator) influence very high to CPU usage?
    2. Does CPU gauge in MorphOS shows only CPU usage or also GPU usage?

    I don’t want to say that there is something wrong in TinyGL. I am sure it is not. :) I would like to increase my knowledge and understand something. I have already found somewhere a very old post (from fixed pipeline ages) where someone written that there is no general rules and it depends on gfx driver.

    One more thing
    I run examples from beta-versions of TinyGL NG wich support shaders. Why do I see 100% CPU usage if geometry is calculated by GPU, gfx is rendered by GPU. CPU should be unoccupied. Am I right? Of course, theoretically.. :)

    I hope I was able to explain what I wanted using my English… :) :)

    [ Edited by MDW 05.12.2022 - 19:08 ]
  • »05.12.22 - 19:02
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2972 from 2003/3/5
    From: Canada
    1. Did you check what thread is using the CPU? You might want to use a custom screen for 3D since high rate of large screen updates on the Ambient screen will be costly if you are using enhanced display.

    As for your own code, I recommend using SDK's EventProfiler.

    2. That's CPU usage
  • »05.12.22 - 20:43
    Profile Visit Website
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 453 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    jacadcaps wrote:
    1. Did you check what thread is using the CPU?

    No, I didn't check it. Good suggestion.

    Quote:

    jacadcaps wrote:
    You might want to use a custom screen for 3D since high rate of large screen updates on the Ambient screen will be costly if you are using enhanced display.

    Yes, I allow to a user select screen resolution.
    Generally I have no problems with performance (I have 60fps in 1440x960 on my PowerBookG4). I am not looking for reason of a problem. I just wanted to find answer to question which I have im my head for about 20 years and nobody is able to answer me. :) I just would like to know how much is CPU used during drawing accelerated graphics. I though that scaling/rendering (without calculating geometry in cause of OpenGL 1.x) is only GPU-task. I am a bit surprised (for almost 25 years, also on MiniGL, StormMESA) that CPU is used also for rendering.

    Quote:

    jacadcaps wrote:
    As for your own code, I recommend using SDK's EventProfiler.

    Good idea! I haven't used the profiler yet. I must use the tool because it can be very useful for me. Thank you for the suggestion.
  • »05.12.22 - 21:14
    Profile Visit Website
  • MorphOS Developer
    bigfoot
    Posts: 508 from 2003/4/11
    Quote:

    MDW wrote:
    Introduction
    There may be two reasons for low performance of a program which uses OpenGL 1.x (fixed pipeline) for rendering a graphics on screen:
    1. Geometry of graphics is too high and CPU (in case of fixed pipeline) is not able to recalculate all transformations.
    2. Huge polygons (especially with transparency) with big textures cause problems with fillrate performance.



    In the current TinyGL, vertex transformations are (in almost all cases) done on the GPU already. However, the general assessment is almost right. There are a few more cases that might be relevant, such as how pipeline stalls are handled and/or avoided, such as when texture data is updated, or how video memory is managed, and so on.

    Quote:

    MDW wrote:
    Observation
    I see that I can create very very simple geometry (which is not a challenge for 68040) with huge polygons for achieve low performance. In this case CPU gauge shows 100% usage. If I resize window from 1440x960 to 320x200, CPU usage is about 10-15%.


    In MorphOS 3.17, if you keep the GPU busy at all times, you'll see something very close to 100% CPU usage. If you see less than that, then you've introduced some waiting at some point. I'd guess you're running your test in full screen mode and in the latter case you've reached the monitor's refresh rate, and the system is mostly waiting for the monitor to finish its refresh.

    Quote:

    MDW wrote:
    Questions
    1. Is it normal situation that CPU usage is very high when geometry is extremely low but big polygons kill fillrate? Should I observe 100% CPU usage in this case? Should rendering of huge polygons (using 3d accelerator) influence very high to CPU usage?


    Yes, that's completely expected as it is now. I've implemented a fix for that, although that fix is not 100% ready for prime time yet, but it'll hopefully be ready in time for MorphOS 3.18. I'll email you an update so you can test it yourself.

    Quote:

    2. Does CPU gauge in MorphOS shows only CPU usage or also GPU usage?


    Not directly, but indirectly there are many cases where the CPU will be busy while waiting for the GPU to finish what it's doing.

    Quote:

    MDW wrote:
    One more thing
    I run examples from beta-versions of TinyGL NG wich support shaders. Why do I see 100% CPU usage if geometry is calculated by GPU, gfx is rendered by GPU. CPU should be unoccupied. Am I right? Of course, theoretically.. :)


    Because there's a misunderstanding there :) The CPU usage you're seeing is not due to vertex transformations, but due to the CPU waiting for the GPU to finish rendering. As mentioned earlier in this reply, and to expand a bit on that, ever since MorphOS 3.0, vertex transformations have taken place on the GPU.
    I rarely log in to MorphZone which means that I often miss private messages sent on here. If you wish to contact me, please email me at [username]@asgaard.morphos-team.net, where [username] is my username here on MorphZone.
  • »06.12.22 - 05:52
    Profile Visit Website
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 453 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    bigfoot wrote:
    The CPU usage you're seeing is not due to vertex transformations, but due to the CPU waiting for the GPU to finish rendering.


    This is something I wanted to read. :) The answer is enough for me. I will not worry that I do something wrong if a simple geometry causes higher CPU usage.
    Thank you!

    I want to point out that I have no problem, I don't look for a solution for something unexpected. I have 60fps in 1440x960. :) I just wanted to understand the process.

    I couldn't ask on other forums, other websites because there are no authors of 3D-drivers, GL-implementations. Everywhere I meet GL-users which usually don't know (like me) how the process exactly works on a low level.
    On MorphZone we have unique opportunity of asking authors of operating system/drivers... So I took this opportunity. Thank you for answers.
  • »06.12.22 - 13:55
    Profile Visit Website