From ae6787114fb59b76d37b6d8d64752b98bd01ff03 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Wed, 8 Apr 2020 16:07:25 -0600 Subject: mockicd: Track memory allocation size Save the size of memory allocations. If a vkMapMemory is called on a known allocation with VK_WHOLE_SIZE, then map based on the actual size of the allocation. --- scripts/mock_icd_generator.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mock_icd_generator.py b/scripts/mock_icd_generator.py index edd9c95e..1686d089 100644 --- a/scripts/mock_icd_generator.py +++ b/scripts/mock_icd_generator.py @@ -57,6 +57,9 @@ using std::unordered_map; // Map device memory handle to any mapped allocations that we'll need to free on unmap static unordered_map> mapped_memory_map; +// Map device memory allocation handle to the size +static unordered_map allocated_memory_size_map; + static VkPhysicalDevice physical_device = (VkPhysicalDevice)CreateDispObjHandle(); static unordered_map>> queue_map; static unordered_map> buffer_map; @@ -857,9 +860,12 @@ CUSTOM_C_INTERCEPTS = { ''', 'vkMapMemory': ''' unique_lock_t lock(global_lock); - // TODO: Just hard-coding 64k whole size for now - if (VK_WHOLE_SIZE == size) - size = 0x10000; + if (VK_WHOLE_SIZE == size) { + if (allocated_memory_size_map.count(memory) != 0) + size = allocated_memory_size_map[memory] - offset; + else + size = 0x10000; + } void* map_addr = malloc((size_t)size); mapped_memory_map[memory].push_back(map_addr); *ppData = map_addr; @@ -1316,9 +1322,15 @@ class MockICDOutputGenerator(OutputGenerator): self.appendSection('command', ' }') else: #print("Single %s last param is '%s' w/ type '%s'" % (handle_type, lp_txt, lp_type)) + if 'AllocateMemory' in api_function_name: + # Store allocation size in case it's mapped + self.appendSection('command', ' allocated_memory_size_map[(VkDeviceMemory)global_unique_handle] = pAllocateInfo->allocationSize;') self.appendSection('command', ' *%s = (%s)%s;' % (lp_txt, lp_type, allocator_txt)) elif True in [ftxt in api_function_name for ftxt in ['Destroy', 'Free']]: self.appendSection('command', '//Destroy object') + if 'FreeMemory' in api_function_name: + # Remove from allocation map + self.appendSection('command', ' allocated_memory_size_map.erase(memory);') else: self.appendSection('command', '//Not a CREATE or DESTROY function') -- cgit v1.2.3