It turns out Metal still supports a very straight-forward way to access non-2B-aligned element:
define the element layout first:
typedef struct __attribute__((__packed__))
{
unsigned char r;
unsigned char g;
unsigned char b;
} TryRGB888;
then compute works just as charm:
_tryBufferSize = _inputTexture.width * _inputTexture.height * 3; // CPU side memory alloc size, *3 for BGR888
...
device TryRGB888 *outBuffer [[buffer(0)]], // shader side
...
uint index = gid.y * inTexture.get_width() + gid.x;
outBuffer[index].r = 1;
outBuffer[index].g = 1;
outBuffer[index].b = 1;
Topic:
Graphics & Games
SubTopic:
General
Tags: