MPSImage data layout

I'm having trouble working with the underlying memory of an MPSImage. I've been using the methods

getBytes
and
replace
on MPSImage's
texture
member variable to read and write the underlying data. The problem is I can't find documentation of how the memory is interpreted as an image (i.e. how the rows, columns, and channels are layed out). Part of what complicates the issue is that regardless of the number of feature channels, the data is stored as a stack of RGBA texture slices, with some channels possibly left unused. For instance, with 3 feature channels, there will be one RGBA texture slice, and one channel's worth of space will be left unused.


The problem is, how is the MPSImage data actually arranged within the texture? It seems more complicated than I originally would have guessed.


After much experimentation, it seems like the data is arranged differently depending on whether the number of feature channels is < 4 or > 4. But I'm still having trouble figuring it out.


Can anyone explain the MPSImage data layout to me?

MPSImage data layout
 
 
Q