Port memory flags from VulkanMemoryAllocator

This commit is contained in:
Denis Pauk 2020-11-21 00:06:29 +02:00 committed by Yamagi
parent 16eb7f5c27
commit ff82bb5a78
3 changed files with 45 additions and 16 deletions

View file

@ -132,6 +132,8 @@ QVk_CreateStagingBuffer(VkDeviceSize size, qvkstagingbuffer_t *dstBuffer,
.pQueueFamilyIndices = NULL,
};
reqMemFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
dstBuffer->currentOffset = 0;
return buffer_create(&dstBuffer->resource, bcInfo, reqMemFlags,
prefMemFlags);
@ -148,6 +150,13 @@ QVk_CreateUniformBuffer(VkDeviceSize size, qvkbuffer_t *dstBuffer,
.prefMemFlags = prefMemFlags,
};
dstOpts.reqMemFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
if((dstOpts.prefMemFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
{
dstOpts.prefMemFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
return QVk_CreateBuffer(size, dstBuffer, dstOpts);
}
@ -164,6 +173,11 @@ QVk_CreateVertexBuffer(const void *data, VkDeviceSize size,
.prefMemFlags = prefMemFlags,
};
if ((dstOpts.prefMemFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
{
dstOpts.prefMemFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
createStagedBuffer(data, size, dstBuffer, dstOpts);
}
@ -179,5 +193,10 @@ QVk_CreateIndexBuffer(const void *data, VkDeviceSize size,
.prefMemFlags = prefMemFlags,
};
if ((dstOpts.prefMemFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0)
{
dstOpts.prefMemFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
}
createStagedBuffer(data, size, dstBuffer, dstOpts);
}

View file

@ -339,7 +339,10 @@ VkResult QVk_CreateImage(uint32_t width, uint32_t height, VkFormat format, VkIma
}
texture->sharingMode = imageInfo.sharingMode;
return image_create(&texture->resource, imageInfo, /*mem_properties*/ 0, /*mem_preferences*/ 0);
return image_create(
&texture->resource, imageInfo,
/*mem_properties*/ 0,
/*mem_preferences*/ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
}
void QVk_CreateDepthBuffer(VkSampleCountFlagBits sampleCount, qvktexture_t *depthBuffer)

View file

@ -67,32 +67,39 @@ vulkan_memory_init(void)
memset(used_memory, 0, used_memory_size * sizeof(MemoryResource_t));
}
static void
memory_type_print(VkMemoryPropertyFlags mem_prop)
{
#define MPSTR(r, prop) \
if((prop & VK_ ##r) != 0) \
{ R_Printf(PRINT_ALL, " %s", "VK_"#r); };
MPSTR(MEMORY_PROPERTY_DEVICE_LOCAL_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_HOST_VISIBLE_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_HOST_COHERENT_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_HOST_CACHED_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_PROTECTED_BIT, mem_prop);
MPSTR(MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD, mem_prop);
MPSTR(MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD, mem_prop);
#undef PMSTR
}
void
vulkan_memory_types_show(void)
{
#define MPSTR(r, i) \
if((vk_device.mem_properties.memoryTypes[i].propertyFlags & VK_ ##r) != 0) \
{ R_Printf(PRINT_ALL, " %s", "VK_"#r); };
R_Printf(PRINT_ALL, "\nMemory blocks:\n");
R_Printf(PRINT_ALL, "\nMemory blocks:");
for(uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; i++)
{
if (vk_device.mem_properties.memoryTypes[i].propertyFlags)
{
R_Printf(PRINT_ALL, "\n#%d:", i);
MPSTR(MEMORY_PROPERTY_DEVICE_LOCAL_BIT, i);
MPSTR(MEMORY_PROPERTY_HOST_VISIBLE_BIT, i);
MPSTR(MEMORY_PROPERTY_HOST_COHERENT_BIT, i);
MPSTR(MEMORY_PROPERTY_HOST_CACHED_BIT, i);
MPSTR(MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, i);
MPSTR(MEMORY_PROPERTY_PROTECTED_BIT, i);
MPSTR(MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD, i);
MPSTR(MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD, i);
R_Printf(PRINT_ALL, "\n #%d:", i);
memory_type_print(vk_device.mem_properties.memoryTypes[i].propertyFlags);
}
}
R_Printf(PRINT_ALL, "\n");
#undef PMSTR
}
static VkBool32