I've got the following code that attempts to use MPSImageScale
shader to flip and convert a texture:
/// mtlDevice and mtlCommandBuffer are obtained earlier
/// srcTex and dstTex are valid and existing MTLTexture objects with the same descriptors
MPSScaleTransform scale{};
scale.scaleX = 1;
scale.scaleY = -1;
auto scaleShader = [[MPSImageScale alloc] initWithDevice:mtlDevice];
if ( scaleShader == nil ) {
return ErrorType::OUT_OF_MEMORY;
}
scaleShader.scaleTransform = &scale;
[scaleShader encodeToCommandBuffer:mtlCommandBuffer
sourceTexture:srcTex
destinationTexture:dstTex;
No matter what I do, I keep getting the EXC_BAD_ACCESS with the last line with the assembly stopping before endEncoding
:
0x7ff81492d804 <+1078>: callq 0x7ff81492ce5b ; ___lldb_unnamed_symbol373$$MPSImage
-> 0x7ff81492d809 <+1083>: movq -0x98(%rbp), %rdi
0x7ff81492d810 <+1090>: movq 0x3756f991(%rip), %rsi ; "endEncoding"
All Metal objects are valid and I did all that I could to ensure that they are not culprits here, including making sure that the pixel format of both textures is the same, even if this is not required for MPS shaders. What am I missing?