From e94ace8db9f48d872109d0d30fcbd1f85866a6ce Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Thu, 18 Feb 2016 14:54:48 -0700 Subject: [PATCH] layers: Fix descriptor resource tracking in mem_tracker Add tracking for the buffers associated with bufferViews of texel buffer desriptor types. Update tracking for all relevant descriptor types to track resources for each descriptor in descriptorCount instead of just the first resource. --- layers/mem_tracker.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/layers/mem_tracker.cpp b/layers/mem_tracker.cpp index ac58c23..5a0759f 100644 --- a/layers/mem_tracker.cpp +++ b/layers/mem_tracker.cpp @@ -77,6 +77,7 @@ struct layer_data { // Images and Buffers are 2 objects that can have memory bound to them so they get special treatment unordered_map imageMap; unordered_map bufferMap; + unordered_map bufferViewMap; layer_data() : report_data(nullptr), @@ -2162,11 +2163,27 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView( validate_buffer_usage_flags(my_data, device, pCreateInfo->buffer, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, VK_FALSE, "vkCreateBufferView()", "VK_BUFFER_USAGE_[STORAGE|UNIFORM]_TEXEL_BUFFER_BIT"); + my_data->bufferViewMap[*pView] = *pCreateInfo; loader_platform_thread_unlock_mutex(&globalLock); } return result; } +VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL +vkDestroyBufferView(VkDevice device, VkBufferView bufferView, + const VkAllocationCallbacks *pAllocator) { + layer_data *my_data = + get_my_data_ptr(get_dispatch_key(device), layer_data_map); + my_data->device_dispatch_table->DestroyBufferView(device, bufferView, + pAllocator); + loader_platform_thread_lock_mutex(&globalLock); + auto item = my_data->bufferViewMap.find(bufferView); + if (item != my_data->bufferViewMap.end()) { + my_data->bufferViewMap.erase(item); + } + loader_platform_thread_unlock_mutex(&globalLock); +} + VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers( VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, @@ -2465,16 +2482,34 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets( const VkCopyDescriptorSet* pDescriptorCopies) { layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); + uint32_t j = 0; for (uint32_t i = 0; i < descriptorWriteCount; ++i) { if (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) { - my_data->descriptorSetMap[pDescriptorWrites[i].dstSet].images.push_back(pDescriptorWrites[i].pImageInfo->imageView); + for (j = 0; j < pDescriptorWrites[i].descriptorCount; ++j) { + my_data->descriptorSetMap[pDescriptorWrites[i].dstSet] + .images.push_back( + pDescriptorWrites[i].pImageInfo[j].imageView); + } } else if (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER ) { - // TODO: Handle texel buffer writes + for (j = 0; j < pDescriptorWrites[i].descriptorCount; ++j) { + my_data->descriptorSetMap[pDescriptorWrites[i].dstSet] + .buffers.push_back( + my_data + ->bufferViewMap[pDescriptorWrites[i] + .pTexelBufferView[j]] + .buffer); + } } else if (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { - my_data->descriptorSetMap[pDescriptorWrites[i].dstSet].buffers.push_back(pDescriptorWrites[i].pBufferInfo->buffer); + for (j = 0; j < pDescriptorWrites[i].descriptorCount; ++j) { + my_data->descriptorSetMap[pDescriptorWrites[i].dstSet] + .buffers.push_back( + pDescriptorWrites[i].pBufferInfo[j].buffer); + } } } + // TODO : Need to handle descriptor copies. Will wait on this until merge w/ + // draw_state my_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies); } @@ -3419,6 +3454,8 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( return (PFN_vkVoidFunction) vkDestroyFence; if (!strcmp(funcName, "vkDestroyBuffer")) return (PFN_vkVoidFunction) vkDestroyBuffer; + if (!strcmp(funcName, "vkDestroyBufferView")) + return (PFN_vkVoidFunction)vkDestroyBufferView; if (!strcmp(funcName, "vkDestroyImage")) return (PFN_vkVoidFunction) vkDestroyImage; if (!strcmp(funcName, "vkBindBufferMemory")) -- 2.7.4