As my question title says, I want update texture for every frame.
I got an idea :
create a VkImage
as a texture buffer with bellow configurations :initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED
usage= VK_IMAGE_USAGE_SAMPLED_BIT
and it's memory type is VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
VkImage
(use vkMapMemory
). VkImage
layout from VK_IMAGE_LAYOUT_PREINITIALIZED
to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
. VkImage
as texture buffer.The layout will be VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
after the first frame , can I map next texure data to this VkImage
directly without change it's layout ? if I can not do that, which layout can I change this VkImage
to ?
In vkspec 11.4 it says :
The new layout used in a transition must not be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED
So , I can not change layout back to _PREINITIALIZED
.
Any help will be appreciated.
For your case you do not need LAYOUT_PREINITIALIZED
. That would only complicate your code (forcing you to provide separate code for the first frame).
LAYOUT_PREINITIALIZED
is indeed a very special layout intended only for the start of the life of the Image. It is more useful for static textures.
Start with LAYOUT_UNDEFINED
and use LAYOUT_GENERAL
when you need to write the Image from CPU side.
I propose this scheme:
berfore render loop
VkImage
with UNDEFINED
1st to Nth frame (aka render loop)
GENERAL
VkFence
)It is a naive implementation but should suffice for ordinary hobbyist uses.
Double buffered access can be implemented — that is e.g. VkBuffer
for CPU access and VkImage
of the same for GPU access. And VkCmdCopy*
must be done for the data hand-off.
It is not that much more complicated than the above approach and there can be some performance benefits (if you need those at your stage of your project). You usually want your resources in device local memory, which often is not also host visible.
It would go something like:
berfore render loop
VkBuffer
b
with UNDEFINED
backed by HOST_VISIBLE
memory and map itVkImage
i
with UNDEFINED
backed by DEVICE_LOCAL
memoryi
and b
: E.g. two Semaphores, or Events could be used or Barriers if the transfer is in the same queue1st to Nth frame (aka render loop)
Operations on b
and i
can be pretty detached (even can be on different queues) so:
For b
:
b
to GENERAL
VkFence
or vkQueueIdle
)b
to TRANSFER
i
is not in use (likely waiting on a VkSemaphore
)i
to TRANSFER
vkCmdCopy*
from b
to i
i
(likely signalling a VkSemaphore
)(The fence at 2. and semaphore at 6. have to be pre-signalled or skipped for first frame to work)
For i
:
i
is free to use (likely waiting on a VkSemaphore
)i
to whatever neededi
(likely signalling a VkSemaphore
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With