PDA

View Full Version : Graphics CPU usage


bozmillar
02-17-2011, 12:08 PM
I'm working on a spectrograph. It all works, but drawing out the spectrograph is pretty hard on my CPU. The processing thread is doing very little work (1%).

I'm trying to pin it down, and I'm noticing that my FillIRect() functions are pretty draining, especially if I draw a large rectangle. For example, I have a DrawBG() function that draws a rectangle the size of the canvas and that alone takes 40-45% of my CPU. Is there a more efficient way to make a gray background that doesn't involve making a bitmap? (I'd like the size to be dynamic.)

Edit:

Ok, so for a little more background, here is a class called DrawBG. It basically draws a rectangle:



#include "Sampler.h"

class DrawBG : public IControl
{
public:
DrawBG(IPlugBase *pPlug, int x, int y, int Width, int Height, int paramIdx)
: IControl(pPlug, &IRECT(x,y,x+Width,y+Height )){}

bool Draw(IGraphics* pGraphics);
//bool IsDirty(){return false;}

private:
IPlugBase *m_pPlug;
};



and


#include "DrawBG.h"

bool DrawBG::Draw(IGraphics* pGraphics)
{

IColor color1(255, 100, 100, 100);
pGraphics->FillIRect(&color1, &mRECT, 0);

return true;
}



(yes, it's a dumb as it looks, it just draws a rectangle) But if the rectangle is big, it chews up my CPU. Is Draw() really being called only 24 times a second? Why would this be such a hog?

Update: I have confirmed that Draw() is only gets called 24 times a second. Is FillIRect() just an extremely inefficient way to draw a rectangle?

bozmillar
02-28-2011, 11:18 AM
Has nobody ever noticed this before? Or am I doing something wrong? The CPU taken up by the draw functions don't show up on the CPU usage meter in Reaper, you have to look at the task manager's CPU meter.

Here are a couple screen shots:

The plugin that I'm interested is the second to the bottom called sampler DEBUG. It's running, but the graphics are not being drawn because I have a different plugin selected. http://www.bozrecords.com/pics/screenShots/ScreenHunter_02%20Feb.%2028%2010.10.gif

On this pictrue, the only thing I did was bring the sampler plugin into view so that it would draw. Notice that according to Reaper, it's only using 1.1% of my CPU (this is because reaper shows how much the processing thread takes, not all the other junk going on). But notice also how much the CPU on my machine jumps up. http://www.bozrecords.com/pics/screenShots/ScreenHunter_03%20Feb.%2028%2010.11.gif

The only difference between these two images is that on the second one, the rectangles are being drawn and on the first one, they are not.

schwa
02-28-2011, 11:40 AM
iplug's fillrect should just be passing through to LICE's fillrect, and with alpha=255 that should be about as efficient as possible a way to draw a rectangle. Having said that, you are drawing a big rectangle, and if you are in debug mode, nothing is getting vectorized by the compiler.

But, are you sure it's the rectangle drawing that is using so much CPU? Is your spectrograph calculation itself in the graphics thread?

bozmillar
02-28-2011, 12:11 PM
I think I'm sure that it's the FillIRect function that is causing the CPU issues. My spectrograph is doing all the calculation in the processing thread. Here'a better screen shot example. I took out the spectrograph and now all it does is draw a rectangle. The only difference between these two screenshots is that I comment out the

pGraphics->FillIRect(&color1, &mRECT, 0);

line in my "drawBG" class (shown above);

With rectangle:
http://www.bozrecords.com/pics/screenShots/ScreenHunter_04%20Feb.%2028%2010.53.gif

without rectangle:
http://www.bozrecords.com/pics/screenShots/ScreenHunter_05%20Feb.%2028%2010.55.gif

Also, (not sure if this is helpful or not) I checked "very sleepy" against the most CPU intensive thread in reaper and it is showing that it's spending 72% of it's time in the "LICE_CombinePixelsClobberFAST::doPixFAST" function.

Here's a screenshot of the results: http://www.bozrecords.com/pics/screenShots/ScreenHunter_06%20Feb.%2028%2011.07.gif

bozmillar
02-28-2011, 12:56 PM
if you are in debug mode, nothing is getting vectorized by the compiler.

could this be the issue? If it's just that, that would be great. It gives me errors when I try compiling in release mode, but I'm pretty sure I've seen a million threads about that on here, so I'll look around.

bozmillar
02-28-2011, 02:29 PM
wait. I compiled in release mode and it doesn't have the CPU issue any more. Thanks for the help.