Page 1 of 1

[SOLVED] BlackmagicRawResourceFormat & MTLPixelFormat

PostPosted: Fri Sep 30, 2022 10:26 pm
by Chris Hocking
I'm having trouble matching the 32-bit BlackmagicRawResourceFormat's to their MTLPixelFormat equivalent.

For example:

blackmagicRawResourceFormatRGBAU8 = MTLPixelFormatRGBA8Unorm
blackmagicRawResourceFormatRGBAU16 = MTLPixelFormatRGBA16Unorm
blackmagicRawResourceFormatRGBF32 = ??
blackmagicRawResourceFormatRGBF32Planar = ??
blackmagicRawResourceFormatBGRAF32 = ??

Is there any reason why 8-bit and 16-bit use RGBA, but 32-bit uses just RGB (or BGRA)?

To give some back story, essentially, I'm trying to take the output from the MTLBuffer of the BRAW API, and use it as a texture on a different MTLDevice. I'm only just starting to play with Metal and the BRAW SDK, so apologies if I'm asking something silly. Thanks team!

Re: BlackmagicRawResourceFormat & MTLPixelFormat?

PostPosted: Wed Oct 05, 2022 1:15 am
by Chris Hocking
For anyone playing along at home, I was able to use
Code: Select all
MTLTextureSwizzleChannels
to solve this issue.

For example:

Code: Select all
MTLTextureSwizzleChannels channels;
   
if (bitDepth == blackmagicRawResourceFormatRGBAU16) {
    //---------------------------------------------------------
    // 16-bit (Unsigned 16bit interleaved RGBA):
    //---------------------------------------------------------
    bitsPerPixel        = 64;
    brawPixelFormat     = MTLPixelFormatRGBA16Unorm;
    bytesPerRow         = (bitsPerPixel * processedImageWidthPixels) / 8U;
    channels            = MTLTextureSwizzleChannelsDefault;
} else if (bitDepth == blackmagicRawResourceFormatBGRAF32) {
    //---------------------------------------------------------
    // 32-bit (Floating point interleaved RGB)
    //---------------------------------------------------------
    bitsPerPixel        = 128;
    brawPixelFormat     = MTLPixelFormatRGBA32Float;
    bytesPerRow         = (bitsPerPixel * processedImageWidthPixels) / 8U;
    channels            = MTLTextureSwizzleChannelsMake(MTLTextureSwizzleBlue, MTLTextureSwizzleGreen, MTLTextureSwizzleRed, MTLTextureSwizzleAlpha);
} else {
    //---------------------------------------------------------
    // 8-bit (Unsigned 8bit interleaved RGBA):
    //---------------------------------------------------------
    bitsPerPixel        = 32;
    brawPixelFormat     = MTLPixelFormatRGBA8Unorm;
    bytesPerRow         = (bitsPerPixel * processedImageWidthPixels) / 8U;
    channels            = MTLTextureSwizzleChannelsDefault;
}