Confused about maximum CVPixelBuffer sizes

I'm trying to figure out the maximum usable size of a CVPixelBuffer. Here's my sample code:

    CGSize frameSize = CGSizeMake(32768,16384);
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
                             [NSNumber numberWithBool:YES], kCVPixelBufferMetalCompatibilityKey,
                             [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
                             nil];
    CVPixelBufferRef pxBuffer = NULL;

    CVReturn status = CVPixelBufferCreate( kCFAllocatorDefault, frameSize.width, frameSize.height, kCVPixelFormatType_32BGRA, (__bridge CFDictionaryRef)options, &pxBuffer);
    if (status != kCVReturnSuccess || pxBuffer==nil)
        NSBeep();  // error creating buffer


Here's a little table of (x,y) pixel sizes and their failure status:

(32768,16384) FAILS

(32768,16383) OK

(131072,4095) OK
(131072,4096) FAILS


(4095,131072) FAILS

(16383,32768) FAILS

(16384,32768) FAILS

(16384,32767) OK


(pow(2,24),pow(2,4)) OK

(pow(2,24),pow(2,5)) FAILS

(pow(2,24),pow(2,5)-1) OK


(pow(2,4),pow(2,24)) OK

(pow(2,5),pow(2,24)) FAILS

(pow(2,5),pow(2,24)-1) OK


I can't quite figure out the criteria for what makes for valid (extreme) dimensions of an RGBA32 CVPixelBuffer. An (M,N) size might work but then (N,M) won't.


Is there documentation about for these maximum sizes? It would seem that they exceed the Metal Specs given here:

https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf

which leads me to believe creation of a CVPixelBuffer is not a GPU-bound activity.


I'm trying this on a late-2015 iMac 5K, Radeon R9-M395, OS 10.12.6.

Well, if I'm doing my mental binary arithmetic right, all of the M * N pixel sizes work if they fit in 30 bits (or, equivalently, if the numbers of bytes fit in 32 bits), except for 2 anomalous cases:


>>(4095,131072) FAILS

>>(16383,32768) FAILS


Those cases would stop being anomalous if you assumed that for the purposes of memory allocation, the X size is rounded up to a multiple of 2 or 4, which is not a totally silly assumption.

Now that I think of it, i believe all CVPIxelBuffers are allocated so that their "rowBytes" are 16-byte aligned. That would make sense in this use case. I'd forgotten about that quirk of disparity between the horizontal pixel count and the allocated memory for a row.

Confused about maximum CVPixelBuffer sizes
 
 
Q