2

What i'm used to from opengl was that inside the command buffer resources are bound to the shader, like glUniformMatrix4fv. Now as far I can see the only equivalent is vkCmdPushConstants.

But there is also the option to create a large buffer with the data of all the objects. And then use vkCmdBindDescriptorSetsto change the offset so the shader gets uses the data for the corresponding object (correct me is something is wrong here, this is how i suppose it could be done). But now what is the "right" way to get per-object data to your shader? And in what way does it depend on the amount of data the shader needs to change per object.

The the other question I have has to do with synchronized gpu and cpu. You need to wait for a frame to be ready before you copy the data for the next frame onto the gpu. So how can you let the buffer copy happen in a command buffer? something like vkFlushMappedMemoryRanges that takes a command buffer Then you could set semaphores and wait for the usages of the data to be complete before overwriting the old data on the gpu with new data for the next frame from RAM. And in RAM use a separate buffer for each image in the swapchain so you can already start writing the data for the next frames (upto the swapchain image count). If you cannot synchronize that buffer copy it seems to me you would need a buffer on the gpu with per-object data for each swpachain image. And that seems like a waste of space to me.

The problem that i see a bit explained, if there is only 1 buffer containing shader data both in RAM on on GPU memory, and if you do not want for the gpu to be idle after each frame (I think you only want to wait if you already submitted the command buffers for all the frames that fit in the swapchain)

  • cpu pushes objects positions for frame 0 to the gpu
  • cpu commits the command buffer for frame 1
  • gpu starts rendering frame 0
  • cpu pushes object positions for frame 1 to the gpu
  • cpu commits the command buffer for frame 1
  • gpu finishes frame 0
  • gpu starts frame 1
  • gpu finishes frame 1

In the example the data for frame 1 is allready pushed to the gpu while it is still rendering frame 0, and this corrupts frame 0.

I'm sorry if my post is a bit incoherent or vague, but it's hard to explain a problem that you do not fully understand.

EDIT: per-vertex should have been per-object.

A function i would be looking for is: VkCmdFillGpuMemory(VkCommandBuffer commandbuffer, VkDeviceMemory myMemory, void* ramData). Preferrably also with a range option to copy only a part of the data (so there is the option to copy data only for objects whose data changed)

4

1 回答 1

2

统一数据现在都必须通过推送缓冲区或类似 UBO 的缓冲区。

每个顶点状态(顶点属性)在 中设置,VkPipelineVertexInputStateCreateInfo并且VkGraphicsPipelineCreateInfo您设置要使用的缓冲区vkCmdBindVertexBuffers

有一个 vkCmdCopyBuffer 在缓冲区之间复制数据。

于 2016-07-17T16:32:09.230 回答