Page 1 of 1

High CPU usage on macOS using COffscreenContext

Posted: Fri Jul 17, 2020 1:28 am
by yeahtuna
Hi,

I'm trying to diagnose high cpu usage on macOS with vstgui 4.4. My application is standalone using the plugguieditor. The problem seems to be with a COffscreenContext that I'm using as a ring buffer for a scrolling meter. I'm attaching a pic showing the part of the UI with the scrolling meter and some information from instruments. The scrolling meter that uses the COffsreenContext as a ring buffer is outlined in red in the picture.

I'm running the application on a i3 mac mini, but I also see high cpu using on my 2017 MacBook Pro. The same code runs very smoothly on my PC. Any ideas?

Also, would I be better off using a CBitmap as my ring buffer and drawing to it using CBitmapPixelAccess? It seems that if I want to use vstgui 4.5 or greater, this might be my only option as COffscreenContexts work differently from 4.5 and up.

Regards,
Rob
pic.png

Re: High CPU usage on macOS using COffscreenContext

Posted: Sat Jul 18, 2020 12:26 am
by yeahtuna
After full days of optimizations and verifying that my UI is only updating the correct views, I'm still making no progress on this.

I'm trying to set a breakpoint in VSTGUI_NSView_drawRect from nsviewframe.mm to see what is actually being drawn by the system, but xcode refuses to break there. Any ideas how I can verify what rectangle the system is actually drawing?

Re: High CPU usage on macOS using COffscreenContext

Posted: Sat Jul 18, 2020 12:33 am
by yeahtuna
Not sure if it helps, but here is how I'm creating my editor.

Code: Select all

    [self.window setFrame:frame display:YES animate:YES];
    
    NSView* view = self.window.contentView;
    CRect r (0, 0, view.bounds.size.width, view.bounds.size.height);

    [[self window] setContentAspectRatio:NSMakeSize(view.bounds.size.width, view.bounds.size.height)];    
    
    editor = new Editor((__bridge void*)view);

Re: High CPU usage on macOS using COffscreenContext

Posted: Sat Jul 18, 2020 3:28 am
by yeahtuna
Would implementing that view as a COoenGLView help?

Re: High CPU usage on macOS using COffscreenContext

Posted: Sat Jul 18, 2020 4:12 am
by yeahtuna
I'm going to go ahead and say the OpenGLView is the way to go. I cut and pasted some code from the OpenGLView example in the tests folder, and the 3D pyramid run smoothly on macOS, adding almost no additional CPU load.

Re: High CPU usage on macOS using COffscreenContext

Posted: Mon Jul 20, 2020 6:32 am
by Arne Scheffler
Hi,
you can try to put your view with the "scrolling meter" into a CLayeredViewContainer and see if it helps.

Cheers,
Arne

Re: High CPU usage on macOS using COffscreenContext

Posted: Tue Jul 21, 2020 1:00 pm
by yeahtuna
Thank-you. I will try that.

Re: High CPU usage on macOS using COffscreenContext

Posted: Wed Jul 22, 2020 6:30 am
by yeahtuna
Hi Arne,

Putting the view in a CLayeredViewContainer did not improve performance. I'm seeing significant performance issues when using COffscreenContexts on macOS / iOS in general. Drawing with OGL is by far the most efficient, but even redrawing the entire scrolling view from scratch each time (which is about 300 line segments) is significantly more efficient, at least in terms of CPU, than using a COffscreenContext as a ring buffer.

Regards,
Rob

Re: High CPU usage on macOS using COffscreenContext

Posted: Wed Jul 22, 2020 1:13 pm
by pongasoft
I am not sure if it will be 100% relevant, but for my vst plugin, I use a COfffScreenContext to generate a bitmap (which is then cached) and the bitmap is drawn into the view. I have no performance problems (on macOS).

Here is the code (source: https://github.com/pongasoft/vst-sam-sp ... ew.cpp#L63)

Code: Select all

void SampleDisplayView::generateBitmap(SampleData const &iSampleData)
{
  // TODO: optimization: load -> mono -> compute summary at the same time

  auto buffers = iSampleData.load(*fSampleRate);
  if(buffers && buffers->hasSamples())
  {
    //buffers = buffers->toMono();

    auto context = COffscreenContext::create(getFrame(), getWidth(), getHeight(), getFrame()->getScaleFactor());

    fBitmap = Waveform::createBitmap(context,
                                     buffers.get(),
                                     {getWaveformColor(), getWaveformAxisColor(), 2, getMargin()});
  }
  else
    fBitmap = nullptr;
}
The content is pretty complicated because it is the waveform of a sample

Yan

Re: High CPU usage on macOS using COffscreenContext

Posted: Sat Nov 21, 2020 4:20 am
by yeahtuna
After updating to version 4.9, performance on macOS has improved dramatically.