You'd most likely want to have these both called on the same thread, so never at the same time. This is the default behavior from MTLView.
With above assumption:
Your onVsync() call uses existing members to record rendering operations. As such, any created command buffer has references to objects existing with the old size. Due to ref-counting mechanism, these objects have their refcount increased when they get recorded in the command buffer.
Now when onWindowResized() is called, you'd recreate these member resources. By doing so, your class loses references to the resources potentially still in use by the previously recorded command buffer. However, since the command buffer holds its own strong references to these, it's not an issue.
So when recreating resources, you're effectively just preparing Metal resources that'll be used in the next onVsync() call.
If you modify (rather than recreate) resources used by still in-flight command buffers, then you can indeed run into concurrency issues.
And if you have both methods called on distinct threads like you initially suggested, you not only have a resource consistency issue with the GPU, but also a potential race condition on your CPU code.
Topic:
Graphics & Games
SubTopic:
Metal
Tags: