Can multiple MTLRenderPipelineStates be used in one MTLRenderCommandEncoder?

I am currently doing a simple UI for a game, and I need to use 2 pipeline states (same vertex shader for each) to draw each of the buttons. One to draw the stripe line for the border, with a static fragment color shader, and one to draw the inside of the button with a ripple gradient. I'm wondering if I need two different command rendering coders, one per pipeline, or if I can do the following:

let encoder = command.makeRenderCommandEncoder(descriptor: renderPassDesc)
encoder.setRenderPipelineState(stateWithStaticFragmentShader)
// encode some buffers and draw line-strips
encoder.setRenderPipelineState(stateWithGradientFragmentShader)
// encode some buffers and draw button background
encoder.endEncoding()

      

+3


source to share


1 answer


Yes, you can use multiple pipeline states in the same command rendering code. This is why there is a method setRenderPipelineState()

, and not a pipeline state, that is part of the render pass descriptor. Properties in the render pass descriptor are read only during the creation of the renderer's encoder and cannot be changed during that encoder's lifetime. Anything that is independently configured on the encoder can be changed during its lifetime.



+4


source







All Articles