diff options
author | Jason Ekstrand <jason.ekstrand@intel.com> | 2017-05-17 12:32:00 -0700 |
---|---|---|
committer | Jason Ekstrand <jason.ekstrand@intel.com> | 2017-05-17 12:32:00 -0700 |
commit | 1e1be2451b0757902ecd2405ade0c0186a952b2a (patch) | |
tree | 925b68376c89b103a4ea9ee75fba687d4aac7b4e | |
parent | 5434da8a316d5432bb0ed54441c06e24d8880581 (diff) |
qonos: Select a memory type if the client doesn't ask for one
-rw-r--r-- | include/qonos/qonos.h | 34 | ||||
-rw-r--r-- | src/qonos/qonos.c | 41 |
2 files changed, 51 insertions, 24 deletions
diff --git a/include/qonos/qonos.h b/include/qonos/qonos.h index fe48503..ef9ef19 100644 --- a/include/qonos/qonos.h +++ b/include/qonos/qonos.h @@ -94,6 +94,13 @@ extern "C" { #define QO_MEMORY_TYPE_INDEX_INVALID UINT32_MAX +typedef struct QoMemoryAllocateFromRequirementsInfo { + const void * pNext; + VkDeviceSize allocationSize; + uint32_t memoryTypeIndex; + VkMemoryPropertyFlags properties; +} QoMemoryAllocateFromRequirementsInfo; + typedef struct QoExtraGraphicsPipelineCreateInfo_ { VkGraphicsPipelineCreateInfo *pNext; VkPrimitiveTopology topology; @@ -119,6 +126,9 @@ typedef struct QoShaderModuleCreateInfo_ { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, \ .memoryTypeIndex = QO_MEMORY_TYPE_INDEX_INVALID +#define QO_MEMORY_ALLOCATE_FROM_REQUIREMENTS_INFO_DEFAULTS \ + .memoryTypeIndex = QO_MEMORY_TYPE_INDEX_INVALID + #define QO_BUFFER_CREATE_INFO_DEFAULTS \ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO @@ -279,12 +289,12 @@ VkDeviceMemory qoAllocMemory(VkDevice dev, ...); VkDeviceMemory qoAllocMemoryFromRequirements(VkDevice dev, const VkMemoryRequirements *mem_reqs, - const VkMemoryAllocateInfo *va_args override_info); + const QoMemoryAllocateFromRequirementsInfo *info); #else #define qoAllocMemoryFromRequirements(dev, mem_reqs, ...) \ __qoAllocMemoryFromRequirements((dev), (mem_reqs), \ - &(VkMemoryAllocateInfo) { \ - QO_MEMORY_ALLOCATE_INFO_DEFAULTS, \ + &(QoMemoryAllocateFromRequirementsInfo) { \ + QO_MEMORY_ALLOCATE_FROM_REQUIREMENTS_INFO_DEFAULTS, \ ##__VA_ARGS__, \ }) #endif @@ -292,12 +302,12 @@ qoAllocMemoryFromRequirements(VkDevice dev, #ifdef DOXYGEN VkDeviceMemory qoAllocBufferMemory(VkDevice dev, VkBuffer buffer, - const VkMemoryAllocateInfo *va_args override_info); + const QoMemoryAllocateFromRequirementsInfo *va_args override_info); #else #define qoAllocBufferMemory(dev, buffer, ...) \ __qoAllocBufferMemory((dev), (buffer), \ - &(VkMemoryAllocateInfo) { \ - QO_MEMORY_ALLOCATE_INFO_DEFAULTS, \ + &(QoMemoryAllocateFromRequirementsInfo) { \ + QO_MEMORY_ALLOCATE_FROM_REQUIREMENTS_INFO_DEFAULTS, \ ##__VA_ARGS__ , \ }) #endif @@ -305,12 +315,12 @@ qoAllocBufferMemory(VkDevice dev, VkBuffer buffer, #ifdef DOXYGEN VkDeviceMemory qoAllocImageMemory(VkDevice dev, VkImage image, - const VkMemoryAllocateInfo *va_args override_info); + const QoMemoryAllocateFromRequirementsInfo *va_args override_info); #else #define qoAllocImageMemory(dev, image, ...) \ __qoAllocImageMemory((dev), (image), \ - &(VkMemoryAllocateInfo) { \ - QO_MEMORY_ALLOCATE_INFO_DEFAULTS, \ + &(QoMemoryAllocateFromRequirementsInfo) { \ + QO_MEMORY_ALLOCATE_FROM_REQUIREMENTS_INFO_DEFAULTS, \ ##__VA_ARGS__ , \ }) #endif @@ -486,9 +496,9 @@ void qoGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physical_dev, VkPhysic VkResult qoQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer *cmdBuffers, VkFence fence); VkResult qoQueueWaitIdle(VkQueue queue); VkDeviceMemory __qoAllocMemory(VkDevice dev, const VkMemoryAllocateInfo *info); -VkDeviceMemory __qoAllocMemoryFromRequirements(VkDevice dev, const VkMemoryRequirements *mem_reqs, const VkMemoryAllocateInfo *override_info); -VkDeviceMemory __qoAllocBufferMemory(VkDevice dev, VkBuffer buffer, const VkMemoryAllocateInfo *override_info); -VkDeviceMemory __qoAllocImageMemory(VkDevice dev, VkImage image, const VkMemoryAllocateInfo *override_info); +VkDeviceMemory __qoAllocMemoryFromRequirements(VkDevice dev, const VkMemoryRequirements *mem_reqs, const QoMemoryAllocateFromRequirementsInfo *info); +VkDeviceMemory __qoAllocBufferMemory(VkDevice dev, VkBuffer buffer, const QoMemoryAllocateFromRequirementsInfo *info); +VkDeviceMemory __qoAllocImageMemory(VkDevice dev, VkImage image, const QoMemoryAllocateFromRequirementsInfo *info); VkBuffer __qoCreateBuffer(VkDevice dev, const VkBufferCreateInfo *info); VkBufferView __qoCreateBufferView(VkDevice dev, const VkBufferViewCreateInfo *info); VkPipelineCache __qoCreatePipelineCache(VkDevice dev, const VkPipelineCacheCreateInfo *info); diff --git a/src/qonos/qonos.c b/src/qonos/qonos.c index 88d500b..3839752 100644 --- a/src/qonos/qonos.c +++ b/src/qonos/qonos.c @@ -141,38 +141,55 @@ __qoAllocMemory(VkDevice dev, const VkMemoryAllocateInfo *info) VkDeviceMemory __qoAllocMemoryFromRequirements(VkDevice dev, const VkMemoryRequirements *mem_reqs, - const VkMemoryAllocateInfo *override_info) + const QoMemoryAllocateFromRequirementsInfo *info) { - VkMemoryAllocateInfo info = *override_info; + VkMemoryAllocateInfo alloc_info = { + .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = info->allocationSize, + .memoryTypeIndex = info->memoryTypeIndex, + }; - if (info.allocationSize == 0) - info.allocationSize = mem_reqs->size; + if (alloc_info.allocationSize == 0) + alloc_info.allocationSize = mem_reqs->size; + + t_assert(alloc_info.allocationSize >= mem_reqs->size); + + if (alloc_info.memoryTypeIndex == QO_MEMORY_TYPE_INDEX_INVALID) { + const VkPhysicalDeviceMemoryProperties *props = t_physical_dev_mem_props; + for (uint32_t i = 0; i < props->memoryTypeCount; i++) { + const VkMemoryType *type = &props->memoryTypes[i]; + if ((mem_reqs->memoryTypeBits & (1 << i)) && + (type->propertyFlags & info->properties) == info->properties) { + alloc_info.memoryTypeIndex = i; + break; + } + } + } - t_assert(info.allocationSize >= mem_reqs->size); - t_assert(info.memoryTypeIndex != QO_MEMORY_TYPE_INDEX_INVALID); - t_assert((1 << info.memoryTypeIndex) & mem_reqs->memoryTypeBits); + t_assert(alloc_info.memoryTypeIndex != QO_MEMORY_TYPE_INDEX_INVALID); + t_assert((1 << alloc_info.memoryTypeIndex) & mem_reqs->memoryTypeBits); - return __qoAllocMemory(dev, &info); + return __qoAllocMemory(dev, &alloc_info); } VkDeviceMemory __qoAllocBufferMemory(VkDevice dev, VkBuffer buffer, - const VkMemoryAllocateInfo *override_info) + const QoMemoryAllocateFromRequirementsInfo *info) { VkMemoryRequirements mem_reqs = qoGetBufferMemoryRequirements(dev, buffer); - return __qoAllocMemoryFromRequirements(dev, &mem_reqs, override_info); + return __qoAllocMemoryFromRequirements(dev, &mem_reqs, info); } VkDeviceMemory __qoAllocImageMemory(VkDevice dev, VkImage image, - const VkMemoryAllocateInfo *override_info) + const QoMemoryAllocateFromRequirementsInfo *info) { VkMemoryRequirements mem_reqs = qoGetImageMemoryRequirements(dev, image); - return __qoAllocMemoryFromRequirements(dev, &mem_reqs, override_info); + return __qoAllocMemoryFromRequirements(dev, &mem_reqs, info); } void * |