The input to this metal shader is a bgra image from iOS camera (in 0-1 range) and output is supposed to be rgba scaled to 0-255 range (note the x256 in kernel). But I don't understand why the output of the kernel appears to be getting clamped back to 0-1 range. Does Metal bake a clamp into their texture write? Or am I missing something?
kernel void bgraScaleKernel(
texture2d<float, access::read> inputImage [[texture(0)]],
texture2d<float, access::write> outputImage [[texture(1)]],
const device int *starting [[ buffer(0) ]],
uint2 gid [[thread_position_in_grid]])
{
uint i = gid.x+starting[0];
uint j = gid.y+starting[1];
float4 pixel_new = (inputImage.read(uint2 (i, j)).bgra)*256;
outputImage.write(pixel_new, (uint2)(i,j));
};
I have a bunch of other filter layers that are applied after this and they assume rgba (0-255) float values (its ported from OpenCL and changing it will require changing Androi, Windows and Mac versions too). So I need the output of the metal layers to be in 0-255 range.
texture(1)
? – Ken Thomases