I m trying to render a layer tree, via CARenderer, ideally on a background thread. I m seeing flicking when I run the render method on a non-main thread (see renderLayerToMTLTexture). If I run on a main thread its better but there is still flicker, just much less.
For video, see: https://www.dropbox.com/s/7uhg7nyjde3h1rt/Purple%20flicker%20of%20doom.mov?dl=0
- note: the background is being cleared to pink to make it more obvious.
The code producing the texture: https://gist.github.com/scornflake/0f42841e377e99440910c43f7424f0a5
The context is that events are being generated (throttled to 60fps), requesting render to texture for a given layer (that layer being a composition of other layers). These textures are either painted to the screen (in preview mode) or sent to a video writer (to create a movie).
Flicking occurs both on screen & in the movie. Thus I am so far presuming that the flickering is not a result of my texture preview MTKView, but rather a problem in my CALayerToMetalRenderer.
我迄今所尝试的是:
- double/tripple buffering (helps a bit, but problem still there even with tripple buffers)
- doing a blit to synchronize on the texture resource (seems to have no effect at all)
- creating the texture with a storageMode of .private - since I never need the texture available to the CPU. In doing this I have to remove the synchronization blit, I m guessing because the texture is now no longer CPU accessible thus sync is invalid.
- passing my own MTLCommandQueue queue to CARenderer (options, in constructor), to see if manually synchronizing on the texture resources works. No change.
我没有一位金属专家,但像最初的指挥(以明确案文)一样,它向我投了feels,但安放人有时不是/或有时是晚? (es, grasp at grraws here a bit)
任何想法?