I have a number of cached MTLTexture
's which I would like to set to purgeable
using MTLTexture
's setPurgeableState API. In order to do this I follow the process outlined in Apple's 2019 WWDC video which suggests:
- Setting cached
MTLTexture
instances tovolatile
- Flagging
MTLTexture
instances asnonVolatile
while 'in use' as part of a command buffer - Using
MTLCommandBuffer
'saddCompletedHandler
to set allMTLTexture
instances back tovolatile
after the command buffer completes its work
This approach works great, but quickly runs into issues in a triple buffered renderer where more than one command buffer is in-flight simultaneously. In these instances I receive the following error:
Cannot set purgeability state to volatile while resource is in use by a command buffer.
... which makes sense. I'm obviously attempting to flag a MTLTexture
as volatile
while it's in-flight as part of a subsequent command buffer. But what's the best way around this without obliterating the performance advantages afforded by triple buffering in the first place?