1

Does changing the blend function in Metal needs setting a whole new MTLRenderPipelineState?

I assume YES, because the MTLRenderPipelineState is immutable, so I cannot change its descriptor and, for example descriptor's sourceRGBBlendFactor property. But I wanted to confirm, as this sounds a little inefficient to generate large objects to change a single parameter.

Edit: I am thinking about a case, where I am drawing one vertex buffer with series of meshes and multiple call to -drawPrimitives:. Each mesh can use a different blend mode but all use the same vertex and fragment shader. In OpenGL I could switch glBlendFunc() between the draw calls. In Metal I need to set a whole separate MTLRenderPipelineState with several state values.

Greg
  • 442
  • 4
  • 16
  • This answer might give you more info. https://stackoverflow.com/a/51414629/409315 – codetiger Aug 10 '20 at 04:32
  • Yes, I saw this answer before but it is about setting a blend mode in general, but not about switching it frequently. By now, I just use two almost identical MTLRenderPipelineState instances to perform the same shading. The only difference between them is the applied blend mode. – Greg Aug 10 '20 at 17:51

1 Answers1

1

Some objects in Metal are designed to be transient and extremely lightweight, while others are more expensive and can last for a long time, perhaps for the lifetime of the app.

Command buffer and command encoder objects are transient and designed for a single use. They are very inexpensive to allocate and deallocate, so their creation methods return autoreleased objects.

MTLRenderPipelineState is not transient.

Does changing the blend function in Metal needs setting a whole new MTLRenderPipelineState?

Yes, you must create a whole new MTLRenderPipelineState object for each blending configuration.

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48