Hello,
Even if I create a buffer with flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ,
creating buffer and copying data into it are successful and no validation error occurs
How can I create a buffer with flag = device local and host coherent together?
Also, I checked that a buffer with flag = device local and host visible has property of automatical flushing
That is, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT flag is not required there
So why is the buffer automatically flushed without flag = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ?
How did you “checked” that? That’s not something you can ask an implementation about.
Also, do implementations even offer non-coherent access to host visible memory? They certainly can, but I don’t think I’ve seen an implementation actually do it.
I checked when I did with device local and host visible, without flushing, uniform buffer data is updated automatically and no validation error occurs
but when I did without any flags (set flag = 0), then validation error occurs when creating uniform buffer
You cannot “set flag = 0”. You cannot “set flag” at all.
Memory is allocated by specifying which memory type to use. That memory type has property flags associated with it, but those flags are not set by you. The device advertises a number of memory types, and those types advertise certain memory properties. You must pick from a specific set of property flag settings by picking a memory type that has the property flags you want.
So:
- Does your device advertise a memory type that is both device local and host visible, but is not host coherent?
- Does your device advertise a memory type whose flags are 0?
- If there is a memory type whose flags are 0, does that memory type allow being used as a uniform buffer? Because if not, then you only verified that you cannot create a buffer with a usage that isn’t supported by the attached memory type.
1 Like
Oh, I understand what you mean, Alfonse
the code below is doing what you are saying inside the createbuffer function
I will analyze the source below as you say
Thank you so much and see you, Alfonse
VkMemoryRequirements memReqs;
VkMemoryAllocateInfo memAlloc = vks::initializers::memoryAllocateInfo();
vkGetBufferMemoryRequirements(logicalDevice, buffer->buffer, &memReqs);
memAlloc.allocationSize = memReqs.size;
// Find a memory type index that fits the properties of the buffer
memAlloc.memoryTypeIndex = getMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags);
// If the buffer has VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT set we also need to enable the appropriate flag during allocation
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo{};
if (usageFlags & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
allocFlagsInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR;
allocFlagsInfo.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
memAlloc.pNext = &allocFlagsInfo;
}
VK_CHECK_RESULT(vkAllocateMemory(logicalDevice, &memAlloc, nullptr, &buffer->memory));
buffer->alignment = memReqs.alignment;
buffer->size = size;
buffer->usageFlags = usageFlags;
buffer->memoryPropertyFlags = memoryPropertyFlags;