Can I use multiple MTLRenderPipelineStates in one MTLRenderCommandEncoder?

倖福魔咒の 提交于 2020-05-13 08:17:44

问题


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()

回答1:


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.



来源:https://stackoverflow.com/questions/43827284/can-i-use-multiple-mtlrenderpipelinestates-in-one-mtlrendercommandencoder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!