From: Mark Lobodzinski Date: Tue, 15 Nov 2016 14:59:58 +0000 (-0700) Subject: layers: Fixup MappedMemRanges call ordering X-Git-Tag: upstream/1.1.92~2149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5d21d96f32824e04999e5452d614ff85f48029c;p=platform%2Fupstream%2FVulkan-Tools.git layers: Fixup MappedMemRanges call ordering Moved validation out of API calls. Change-Id: I95f3b24d69d469ea98b7c955bbab56c9b47ad487 --- diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index e62a367..93521c1 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -11260,35 +11260,51 @@ static void CopyNoncoherentMemoryFromDriver(layer_data *dev_data, uint32_t mem_r } } +static bool PreCallValidateFlushMappedMemoryRanges(layer_data *dev_data, uint32_t mem_range_count, + const VkMappedMemoryRange *mem_ranges) { + bool skip = false; + std::lock_guard lock(global_lock); + skip |= ValidateAndCopyNoncoherentMemoryToDriver(dev_data, mem_range_count, mem_ranges); + skip |= validateMemoryIsMapped(dev_data, "vkFlushMappedMemoryRanges", mem_range_count, mem_ranges); + return skip; +} + VKAPI_ATTR VkResult VKAPI_CALL FlushMappedMemoryRanges(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange *pMemRanges) { VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; - bool skip = false; layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); - std::unique_lock lock(global_lock); - skip |= ValidateAndCopyNoncoherentMemoryToDriver(dev_data, memRangeCount, pMemRanges); - skip |= validateMemoryIsMapped(dev_data, "vkFlushMappedMemoryRanges", memRangeCount, pMemRanges); - lock.unlock(); - if (!skip) { + if (!PreCallValidateFlushMappedMemoryRanges(dev_data, memRangeCount, pMemRanges)) { result = dev_data->dispatch_table.FlushMappedMemoryRanges(device, memRangeCount, pMemRanges); } return result; } +static bool PreCallValidateInvalidateMappedMemoryRanges(layer_data *dev_data, uint32_t mem_range_count, + const VkMappedMemoryRange *mem_ranges) { + bool skip = false; + std::lock_guard lock(global_lock); + skip |= validateMemoryIsMapped(dev_data, "vkInvalidateMappedMemoryRanges", mem_range_count, mem_ranges); + return skip; +} + +static void PostCallRecordInvalidateMappedMemoryRanges(layer_data *dev_data, uint32_t mem_range_count, + const VkMappedMemoryRange *mem_ranges) { + std::lock_guard lock(global_lock); + // Update our shadow copy with modified driver data + CopyNoncoherentMemoryFromDriver(dev_data, mem_range_count, mem_ranges); +} + VKAPI_ATTR VkResult VKAPI_CALL InvalidateMappedMemoryRanges(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange *pMemRanges) { VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; - bool skip = false; layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); - std::unique_lock lock(global_lock); - skip |= validateMemoryIsMapped(dev_data, "vkInvalidateMappedMemoryRanges", memRangeCount, pMemRanges); - lock.unlock(); - if (!skip) { + if (!PreCallValidateInvalidateMappedMemoryRanges(dev_data, memRangeCount, pMemRanges)) { result = dev_data->dispatch_table.InvalidateMappedMemoryRanges(device, memRangeCount, pMemRanges); - // Update our shadow copy with modified driver data - CopyNoncoherentMemoryFromDriver(dev_data, memRangeCount, pMemRanges); + if (result == VK_SUCCESS) { + PostCallRecordInvalidateMappedMemoryRanges(dev_data, memRangeCount, pMemRanges); + } } return result; }