SKEffectNode combined with CIFilter runs out of memory
Asked Answered
A

0

1

I tried to combine a SKEffectNode with a CIFilter and a child SKSpriteNode and while its seems to work for a few moments, the result is that all device memory is consumed and my iPad Retina (A7 GPU) just reboots. I also sometime see "Message from debugger: Terminated due to memory issue" printed to the debugger log. The full source is on github at SKEffectNodeFiltered.

I am creating the filter like so:

  // Pixelate CoreImage filter

  CIFilter *pixellateFilter = [CIFilter filterWithName:@"CIPixellate"];
  [pixellateFilter setDefaults]; // Remember to setDefaults...
  [pixellateFilter setValue:@(25.0) forKey:@"inputScale"];

  SKEffectNode *effectNode = [[SKEffectNode alloc] init];
  effectNode.shouldEnableEffects = TRUE; // enable CoreImage filtering
  effectNode.shouldRasterize = FALSE; // generate and then discard tmp framebuffer
  effectNode.shouldCenterFilter = TRUE;
  effectNode.filter = pixellateFilter;
  self.effectNode = effectNode;

  [effectNode addChild:background];
  [self addChild:effectNode];

  effectNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));

I looked at the allocations tool, I do see a triple buffered set of CoreSurface objects, but there is not an obvious memory leak. The memory usage is quite large at around 140 Megs total, this is large but this is testing the use of a very large input image at 4096x4096 which is the max texture size. What is going on here? If I did not use a filter, then performance is 60 FPS and there is no problem with memory usage.

Atrioventricular answered 30/1, 2019 at 0:50 Comment(2)
Do you experience the same issue with a smaller input image? Is the memory consumption growing over time? Your iPad only has 1 GB RAM and the image (uncompressed) takes half of that alone...Shunt
I added a 1024x1024 example texture to the github project, when running with this significantly smaller texture, it does not crash straight away. Performance with the 1024x1204 image is about 35 FPS, not great. Just FYI, but a 4096 texture should only consume 64 Megs of memory, this is a lot less than half the system memory. The problem seems to be with the tmp framebuffer memory being allocated to pass data to CoreImage via the filter approach.Atrioventricular

© 2022 - 2024 — McMap. All rights reserved.