Hi, I just implemented a Metal layer for my game engine
When I run the game on OpenGL ES 3, it takes about 60% cpu
Then I switch to Metal, it runs ok, but CPU usage raises to more than 100%
I did an instrumentation, some metal lib function is taking 50% of my CPU usage, see below
thread com.apple.libdispatch-manager (serial)
52.2% CA::Display::DisplayLinkItem::dispatch
52.2% -> 0x47f4dca libMTLInterpose.dylib
And a system trace shows that 90% of CPU is spent on "BLOCK"
In my code, I follow the MetalBasic3D example to use a semaphore to sync the constant buffers
Then I used another thread with 2 more semaphores to do blit encoding, to generate mipmaps
The basic code path is like
CADisplayLink
-> dispatch_semaphore_wait(constant_sem);
-> blit_buffer enqueue
-> render_buffer enqueue
-> dispatch_semaphore_signal(blit_sem_1) -> dispatch_semaphore_wait(blit_sem_1)
-> render_buffer encode render commands blit_buffer encode blit commands
-> render_buffer addCompleteHandler: blit_buffer commit
dispatch_semaphore_signal(constant_sem); dispatch_semaphore_signal(blit_sem_2)
-> render_buffer presentDrawable
-> render_buffer commit
-> dispatch_semaphore_wait(blit_sem_2)
I'm not using GCD in this engine, I just used raw pthreads, with dispatch_semaphores
What could I do wrong to make libdispatch-manager uses so much CPUS