Metal on iOS: `newCommandQueueWithMaxCommandBufferCount` not working

472 views Asked by At

I have a complex Metal renderer that utilizes numerous MTLCommandBuffer objects, and so I've started using newCommandQueueWithMaxCommandBufferCount to allow my MTLCommandQueue to support more than the default 64 active command buffers, but as far as I can tell, it is not working. No matter what value I pass in as the MaxCommandBufferCount, I am only able to create up to 64 simultaneous command buffers.

Here is my call to create the command queue:

    commandQueue = [_device newCommandQueueWithMaxCommandBufferCount: 128];

And here is the code I use to test this:

- (id <MTLCommandBuffer>) makeCommandBuffer
{
    id <MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
    commandBufferCounter ++;
    NSLog(@"command buffer created. Total count = %d", commandBufferCounter);
    [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> _Nonnull buffer) {
        commandBufferCounter--;
        NSLog(@"command buffer completed. Total count = %d", commandBufferCounter);
    }];

    return commandBuffer;
}

This function is the sole creator of command buffers in my program, and so I can always see an exact count of how many active, non-completed buffers I have. As soon as I hit 64, the call to [commandQueue commandBuffer] hangs, which leads me to suspect a bug in newCommandQueueWithMaxCommandBufferCount.

I've confirmed this behavior on both iOS 9 and 10, and so I tend to doubt that such an obvious bug would have lasted this long.

0

There are 0 answers