简体   繁体   English

Vulkan - 顶点缓冲区更新

[英]Vulkan - vertex buffer update

I want to perform the vertex buffer update.我想执行顶点缓冲区更新。 I'm starting from empty buffer and I will add new points.我从空缓冲区开始,我将添加新点。 The amount of added points is not frame-dependent.添加的点数与帧无关。 It can by one per frame, few or none.它可以每帧一个,很少或没有。

In OpenGL I just allocated memory for all points which will be added (constant max size), use the glBufferSubData and modify the number of points which will be rendered (so only part of the buffer will be visible).在 OpenGL 中,我只是为将要添加的所有点分配了内存(最大大小恒定),使用 glBufferSubData 并修改将要渲染的点数(因此只有部分缓冲区可见)。

In Vulkan - I suppose I will need to use createBuffer with constant max size but what about modifications?在 Vulkan 中 - 我想我需要使用具有恒定最大大小的 createBuffer 但修改呢? I didn't found the "dedicated" approach for it.我没有找到它的“专用”方法。 I think about sth like:我想……

void* data;
vkMapMemory(src, data);
memcpy(data, modifiedInput);
vkUnmapMemory(src);

VkBufferCopy copyParams = {};
copyRegion.srcOffset = currOffset;//starting from last point in buffer
copyRegion.dstOffset = copyRegion.srcOffset;
copyRegion.size = size;

vkCmdCopyBuffer(src, dest, copyParams);
currOffset += size;

I'm not sure it's the correct way.我不确定这是正确的方法。 Do I need to recreate the command buffers in this case or I should use totally different approach?在这种情况下我需要重新创建命令缓冲区还是应该使用完全不同的方法?

That is a good enough way to add data to a buffer.这是将数据添加到缓冲区的一种很好的方法。

Though there is a small bug.虽然有一个小错误。 It should be.它应该是。

VkBufferCopy copyParams = {};
copyRegion.srcOffset = 0; //start copy from start of src
copyRegion.dstOffset = currOffset; //starting from last point in existing buffer
copyRegion.size = size;

Assuming you only upload the new points.假设您只上传新积分。 And ensure you don't overflow the buffer;并确保您不会溢出缓冲区; splitting the copy into 2 copies when it wraps.包装时将副本分成 2 个副本。

You can also use vkCmdUpdateBuffer to skip using the staging buffer.您还可以使用vkCmdUpdateBuffer跳过使用暂存缓冲区。 Though that should only be for small bits of data.虽然这应该只适用于少量数据。

You still need some synchronization between the vkCmdCopyBuffer and where you use the new points.您仍然需要在vkCmdCopyBuffer和使用新点的位置之间进行一些同步。

You'll need to rerecord the command buffer per frame anyway to make use of the new amount of points (unless you use indirect rendering?).无论如何,您都需要重新记录每帧的命令缓冲区以利用新的点数(除非您使用间接渲染?)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM