MPSImageIntegral spurious(?) assertion about mismatch texture formats

I'm trying to use MPSImageIntegral to sum the values in a 1D UInt32 buffer. My source buffer has been snapped to 64-byte row alignment, as has my destination buffer. Both buffers use .storageModeShared and the textures that wrap them both use the .r32Uint pixel format.


When I attempt to encode a image integral to sum up the ints in the source buffer into the first element of the destination, I get:


/BuildRoot/Library/Caches/com.apple.xbs/Sources/MetalImage/MetalImage-61.4/MetalPerformanceShaders/Filters/MPSIntegral.mm:109: failed assertion `Destination 0x174116770 texture format does not match source 0x1741160b0 texture format


If I `po` the two textures and diff the results, I get very few differences, and nothing that seems like it would be incompatible:


1c1
< <MTLDebugTexture: 0x1741160b0> -> <AGXA8Texture: 0x101333220>
---
> <MTLDebugTexture: 0x174116770> -> <AGXA8Texture: 0x101333e60>
5c5
<     width = 1920
---
>     width = 1
20c20
<     buffer = <AGXA8Buffer: 0x101332be0>
---
>     buffer = <AGXA8Buffer: 0x1013330e0>
22,23c22,23
<     bufferBytesPerRow = 7680
<  -> <MTLTextureDescriptorInternal: 0x17400de80>
---
>     bufferBytesPerRow = 64
>  -> <MTLTextureDescriptorInternal: 0x17400e130>
38c38
<     width = 1920;
---
>     width = 1;
40,41c40,41
<     buffer = "<MTLDebugBuffer: 0x1740fe980> -> <AGXA8Buffer: 0x101332be0> -> {\n    label = \"<null>\";\n    length = 7680;\n    options = \"MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeShared \";\n    purgeableState = MTLPurgeableStateNonVolatile;\n}";
<     bufferBytesPerRow = 7680;
---
>     buffer = "<MTLDebugBuffer: 0x1740fed80> -> <AGXA8Buffer: 0x1013330e0> -> {\n    label = \"<null>\";\n    length = 256;\n    options = \"MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeShared \";\n    purgeableState = MTLPurgeableStateNonVolatile;\n}";
>     bufferBytesPerRow = 64;


Am I missing something here? Is the error message referring to something else?

Replies

I'm finding the same issue. Any progres? Anybody? Hello?

I actaully fixed this error by setting: destinationTextureDescriptor.pixelFormat = .bgr10_xr_srgb. But now I get this error:


/BuildRoot/Library/Caches/com.apple.xbs/Sources/MetalImage/MetalImage-60.1/MetalPerformanceShaders/Filters/MPSKernel.mm:378: failed assertion `Destination 0x1703005a0 texture format 0 must be writable.

Can you file a bug report with a test case to reproduce the problem?

Here is what i found in the documentation:


The following Metal Performance Shaders image kernels also support source and destination textures with ordinary signed and unsigned integer pixel formats:

  • MPSImageTranspose
  • MPSImageIntegral
  • MPSImageIntegralOfSquares

The ordinary signed and unsigned integer pixel formats supported by these image kernels:

MTLPixelFormat.r8Sint
,
MTLPixelFormat.rg8Sint
,
MTLPixelFormat.rgba8Sint

Ordinary format with 8-bit signed integer components.

MTLPixelFormat.r8Uint
,
MTLPixelFormat.rg8Uint
,
MTLPixelFormat.rgba8Uint

Ordinary format with 8-bit unsigned integer components.

MTLPixelFormat.r16Sint
,
MTLPixelFormat.rg16Sint
,
MTLPixelFormat.rgba16Sint

Ordinary format with 16-bit signed integer components.

MTLPixelFormat.r16Uint
,
MTLPixelFormat.rg16Uint
,
MTLPixelFormat.rgba16Uint

Ordinary format with 16-bit unsigned integer components.

MTLPixelFormat.r32Sint
,
MTLPixelFormat.rg32Sint
,
MTLPixelFormat.rgba32Sint

Ordinary format with 32-bit signed integer components.

MTLPixelFormat.r32Uint
,
MTLPixelFormat.rg32Uint
,
MTLPixelFormat.rgba32Uint

Ordinary format four 32-bit unsigned integer components.


So, if you change pixel foirmat to suported one - everything should works fine. So - this is wrong assertion description. Ive spent almost two hours trying to fix it, thanks for you idea with pixel format.

The current docs for MPSImageIntegral read:


If the channels in the source image are normalized, half-float or floating values, the destination image is recommended to be a 32-bit floating-point image. If the channels in the source image are integer values, it is recommended that an appropriate 32-bit integer image destination format is used.


So, I created my input texture as MTLPixelFormatR8Uint and made the output texture MTLPixelFormatR32Uint and that avoided the assert:


results:


inputTexture as bytes

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15


outputTexture as ints

0 1 3 6

4 10 18 28

12 27 45 66

24 52 84 120