I'm currently making simple UI for a game, and to draw each of the buttons I need to use 2 pipeline states (same vertex shader for each). One to draw a line strip for the border, with a static color fragment shader, and one to draw the inside of the button with a rippling gradient. I'm wondering if I need two different render command encoders, 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()
Yes, you can use multiple pipeline states in one render command encoder. That's precisely why the setRenderPipelineState()
method exists, rather than the pipeline state being part of the render pass descriptor. The properties in the render pass descriptor are only read at the time of the creation of the render command encoder and can't be changed during the lifetime of that encoder. Anything which is independently settable on the encoder can be changed during its lifetime.