From 0d4857ea576af2207b6debc965a242cdcadc1b15 Mon Sep 17 00:00:00 2001 From: Petr Kraus Date: Wed, 15 Apr 2020 00:29:33 +0200 Subject: icd: Make VkPhysicalDevice unique --- scripts/mock_icd_generator.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/mock_icd_generator.py b/scripts/mock_icd_generator.py index 0b1062cf..75227b48 100644 --- a/scripts/mock_icd_generator.py +++ b/scripts/mock_icd_generator.py @@ -54,18 +54,20 @@ static void DestroyDispObjHandle(void* handle) { SOURCE_CPP_PREFIX = ''' using std::unordered_map; +static constexpr uint32_t icd_physical_device_count = 1; +static unordered_map> physical_device_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; static constexpr uint32_t icd_swapchain_image_count = 1; -static std::unordered_map swapchain_image_map; +static unordered_map swapchain_image_map; // TODO: Would like to codegen this but limits aren't in XML static VkPhysicalDeviceLimits SetLimits(VkPhysicalDeviceLimits *limits) { @@ -427,19 +429,30 @@ CUSTOM_C_INTERCEPTS = { return VK_ERROR_INCOMPATIBLE_DRIVER; } *pInstance = (VkInstance)CreateDispObjHandle(); + for (auto& physical_device : physical_device_map[*pInstance]) + physical_device = (VkPhysicalDevice)CreateDispObjHandle(); // TODO: If emulating specific device caps, will need to add intelligence here return VK_SUCCESS; ''', 'vkDestroyInstance': ''' - DestroyDispObjHandle((void*)instance); + if (instance) { + for (const auto physical_device : physical_device_map.at(instance)) + DestroyDispObjHandle((void*)physical_device); + physical_device_map.erase(instance); + DestroyDispObjHandle((void*)instance); + } ''', 'vkEnumeratePhysicalDevices': ''' + VkResult result_code = VK_SUCCESS; if (pPhysicalDevices) { - *pPhysicalDevices = physical_device; + const auto return_count = (std::min)(*pPhysicalDeviceCount, icd_physical_device_count); + for (uint32_t i = 0; i < return_count; ++i) pPhysicalDevices[i] = physical_device_map.at(instance)[i]; + if (return_count < icd_physical_device_count) result_code = VK_INCOMPLETE; + *pPhysicalDeviceCount = return_count; } else { - *pPhysicalDeviceCount = 1; + *pPhysicalDeviceCount = icd_physical_device_count; } - return VK_SUCCESS; + return result_code; ''', 'vkCreateDevice': ''' *pDevice = (VkDevice)CreateDispObjHandle(); @@ -1093,6 +1106,7 @@ class MockICDOutputGenerator(OutputGenerator): write('#include "mock_icd.h"', file=self.outFile) write('#include ', file=self.outFile) write('#include ', file=self.outFile) + write('#include ', file=self.outFile) write('#include ', file=self.outFile) write('#include "vk_typemap_helper.h"', file=self.outFile) -- cgit v1.2.3