I'm learning Metal, and there's a conceptual question that I'm trying to wrap my head around: at what level, exactly, should my code handle successive drawing operations that require different pipeline states? As I understand it (from answers like this: https://stackoverflow.com/a/43827775/2752221), I can use a single MTLRenderCommandEncoder
and change its pipeline state, the vertex buffer it's using, etc., between calls to drawPrimitives:
, and the encoder state that was current at the time of each call to drawPrimitives:
will be preserved. So that's great. But it also seems like the design of Metal is such that one can make multiple MTLRenderCommandEncoder
instances, and use them to sequentially throw batches of commands into a MTLCommandBuffer
. Given that the former works – using one MTLRenderCommandEncoder
and changing its state – why would one do the latter? Under what circumstances is it correct to do the former, and under what circumstances is it necessary to do the latter? What is an example of a situation where the latter would be necessary/appropriate?
If it matters, I'm working on a macOS app, using Objective-C. Thanks.