I have SpriteKit nodes on which I apply Core Image filters using SKEffectNode. The sprites are images added by the user on the scene, and can be of any size. Some of the filters change the size of the rendered sprites. When that size exceeds the limit allowed by Metal, the app crashes with an error like this:
-[MTLTextureDescriptorInternal validateWithDevice:]:1357: failed assertion `Texture Descriptor Validation
MTLTextureDescriptor has width (9050) greater than the maximum allowed size of 8192.
MTLTextureDescriptor has height (9050) greater than the maximum allowed size of 8192.
How can I prevent any image processing I make in real-time from exceeding Metal's limits?
Here's the SpriteKit code:
var mySprite: SKSpriteNode!
var myEffectNode: SKEffectNode!
var sliderInput: Double = 0
override func didMove(to view: SKView) {
// Sprite from an image
// The user picks the image, it could be of any size
mySprite = SKSpriteNode(imageNamed: "myImage")
mySprite.name = "mySprite"
myEffectNode = SKEffectNode()
myEffectNode.addChild(mySprite)
addChild(myEffectNode)
}
// Called by SwiftUI
// The filter changes dynamically in real-time
func updateEffects() {
myEffectNode.filter = CIFilter(name: "CIZoomBlur", parameters: [
"inputAmount": sliderInput
])
}
Desired pseudo code:
func carefullyUpdateEffects() {
// Compute the image processing
// Get the texture size limit on this device
// Check if the expected output of the processing exceeds the limit
// If no, proceed and render
// If yes, handle case
}