GPU channels, how do they work?

Does someone know how they GPU channels work exactly in Metal?

I implemented a blit command encoder in two different ways and metal system traces showed me that one blit command was sheduled to the GPUs blit channel while the other is running on the gfx channel.


- First Blit Copy: Shared MTLBuffer -> Private MTLBuffer

- Second Blit Copy: CVMetalTexture -> Private MTLTexture


Both blit commands were commited to the queue in seperate command buffers and on seperate threads.


A blit commander for generateMipmaps() on the private MTLTexture from above is also running on the gfx channel and not on the blit channel. Copying parts from one private texture to another region of a destination private texture also runs on the gfx channel.

So only the blit copy from one buffer to another buffer seems to run in the blit channel or is this wrong?

Replies

Aboutthose buffers, are you doing any CPU sharing?


See https://developer.apple.com/documentation/metal/synchronization/synchronizing_cpu_and_gpu_work

After pulling out my last hair I found the problem:


If you don't set a label on the blit encoder then instruments shows this command in the DMA channel.

If you set a label like in the code below (line 4) then the command uses the GPUs BLIT channel.


if let commandBuffer = engine.commandQueue.makeCommandBuffer() {
    commandBuffer.label = "Copy Image to GPU [\(processorID)]"
    if let encoder = commandBuffer.makeBlitCommandEncoder() {
         encoder.label = "Copy Image to GPU [\(processorID)]"
         encoder.copy(from: inputBufferSystemMemory, sourceOffset: 0, to: inputBuffer, destinationOffset: 0, size: inp
         encoder.endEncoding()
    }
    commandBuffer.commit()
 }


Maybe someone knows if this is correct otherwise I would file a radar because for me it looks like a bug. Unfortunately I cannot add the screenshots to show the gpu channels from instruments.

That's really weird. The label is just there to identify the different encoders (which is mostly useful for debugging), it shouldn't have any effect on how anything gets executed!


I'd assume DMA is the correct channel there - DMA to copy between GPU and system memory, blitter to copy GPU to GPU.