Is rebinding a graphics pipeline in Vulkan a guaranteed no-op?

守給你的承諾、 提交于 2019-12-07 16:26:50

问题


In the simplified scenario where each object to be rendered is translated into a secondary command buffer and each of those command buffers bind a graphics pipeline initially: is a guaranteed no-op to bind the pipeline that was immediately bound before? Or the order of execution of the secondary command buffers is not guaranteed at all?


回答1:


is a guaranteed no-op to bind the pipeline that was immediately bound before?

No. In fact, in the case you're outlining, you should assume precisely the opposite. Why?

Since each of your CBs is isolated from the others, the vkCmdBindPipeline function has no way to know what was bound beforehand. Remember: the state of a command buffer that has started recording is undefined. Which means that the command buffer building code cannot make any assumptions about any state which you did not set within this CB.

In order for the driver to implement the optimization you're talking about, it would have to, at vkCmdExecuteCommands time, introspect into each secondary command buffer and start ripping out anything that is duplicated across CB boundaries.

That might be viable if vkCmdExecuteCommands has to copy all of the commands out of secondary CBs into primary ones. But that would only be reasonable for systems where secondary CBs don't exist at a hardware level and thus have to be implemented by copying their commands into the primary CB. But even in this case, implementing such culling would make the command take longer to execute compared to simply copying some tokens into the primary CB's storage.

When dealing with a low-level API, do not assume that the driver is going to use information outside of its immediate purview to optimize your code. Especially when you have the tools for doing that optimization yourself.

This is (yet another) a reason why you should not give each individual object its own CB.

Or the order of execution of the secondary command buffers is not guaranteed at all?

The order of execution of commands is unchanged by their presence in CBs. However, the well-defined nature of the state these commands use is affected.

Outside of state inherited by secondary CBs, every secondary CB's state begins undefined. That's why you have to bind a pipeline for each one. Commands that rely on previously issued state only have well-defined behavior if that previously issued state is within the CB containing that command (or is inherited state).



来源:https://stackoverflow.com/questions/49985913/is-rebinding-a-graphics-pipeline-in-vulkan-a-guaranteed-no-op

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