When are parameters to vkCmd* functions consumed?

2019-07-15 10:20发布

Some of the vkCmd* functions specify when some parameters are consumed or not. For example, in the documentation of vkCmdBindDescriptorSets:

The contents of pDynamicOffsets are consumed immediately during execution of vkCmdBindDescriptorSets.

However most of them do not clarify. Are all parameters consumed during the the vkCmd* call? For example, in the following code:

void copyHelper() {
  VkBufferCopy copy_region = {...};
  vkCmdCopyBuffer(cmd_buffer, from_buffer, to_buffer, 1, &copy_region);
}

after calling copyHelper(), copy_region is not in scope anymore although cmd_buffer hasn't been submitted yet. Do I need to store copy_region somewhere so that it stays valid? Or is it immediately consumed when calling vkCmdCopyBuffer? What about the rest of the vkCmd* functions?

Thanks.

标签: c++ vulkan
1条回答
贪生不怕死
2楼-- · 2019-07-15 10:30

There is no per-command clarification, because all commands operate under the following blanket statement:

The ownership of application-owned memory is immediately acquired by any Vulkan command it is passed into. Ownership of such memory must be released back to the application at the end of the duration of the command, so that the application can alter or free this memory as soon as all the commands that acquired it have returned.

Emphasis in the specification. The implementation has to be finished using the contents of any memory you pass by the time the function returns. Whether unformatted memory like a void* or data structures.

Note that "duration" is defined as:

The duration of a Vulkan command refers to the interval between calling the command and its return to the caller.

查看更多
登录 后发表回答