iOS Metal "The pixel format of the texture is incompatible with the data type"

795 Views Asked by At

I added another texture to one of my metal Kernel functions, and get the following error. I searched, and see a lot of confusion about this error.

How to solve Metal error "The pixel format of the texture is incompatible with the data type" ?

validateComputeFunctionArguments:841: failed assertion `Compute Function(screenSampleWithScreenshot): 
The pixel format (MTLPixelFormatBGRA8Unorm) of the texture (name:CAMetalLayer Display Drawable)
 bound at index 4 is incompatible with the data type (MTLDataTypeUInt) of the texture parameter
 (myTexture [[texture(0)]]). MTLPixelFormatBGRA8Unorm is compatible with the data type(s) (
        float,
        half
    ).'
1

There are 1 best solutions below

0
Alex Stone On

The solution is simple: metal validation has detected that your function signature is incorrect. It found unsigned int (or other unexpected) data type, while you are passing in a texture with a float color format.

kernel void myComputeFunction(
texture2d<unsigned int, access::read> integerTexture [[texture(0)]],
texture2d<unsigned int, access::read> myTexture [[texture(1)]],

//change unsigned int to float if your texture MTLPixelFormatBGRA8Unorm:
texture2d<unsigned int, access::read> integerTexture [[texture(0)]],
texture2d<float, access::read> myTexture [[texture(1)]],
)