I guess I didn’t ask my question well. I am indeed thinking about the resources on the GPU. But there are also Swift objects that refer to those resources on the GPU. The GPU resources and the Swift resources each have their own lifecycles, which I assume are coupled in some way.
I understand, in general, the lifecycle of Swift objects. What I don’t understand is how they are coupled to the corresponding resources on the GPU. For example, let’s say I load a MTLTexture that I’m going to use for a particular game level. Does the resource live on the GPU for as long as I keep the MTLTexture object referenced on the CPU? What determines when the GPU can release that texture? The same would go for vertex buffers I’m holding on the GPU and their corresponding MTLBuffer objects on the CPU.
Let’s say I decide I know I know longer need a particular MTLBuffer object and want to allocate a new one with new geometry to replace it? Is there an explicit way to tell the GPU I don’t need this anymore? Or is releasing the reference to the MTLBuffer object in Swift (letting it go out of scope or setting an optional to nil) sufficient to know the resource will be released on the GPU?
I suppose it would also be good to understand how Metal deals with multiple programs contending for GPU resources? Can one process force the GPU to discard the resources for another process? Does Metal automatically put resources back in place when a process needs them?