[Impeller] ASAN/LSAN fixes for the mock Vulkan implementation (flutter/engine#51115)

This commit is contained in:
Jason Simmons 2024-03-01 14:18:22 -08:00 committed by GitHub
parent 0d6adc6ec3
commit 46259ce840

View File

@ -36,10 +36,12 @@ struct MockDescriptorPool {};
struct MockSurfaceKHR {};
struct MockSwapchainKHR {};
struct MockImage {};
struct MockSwapchainKHR {
std::array<MockImage, 3> images;
};
struct MockSemaphore {};
static ISize currentImageSize = ISize{1, 1};
@ -539,6 +541,14 @@ VkResult vkCreateQueryPool(VkDevice device,
return VK_SUCCESS;
}
void vkDestroyQueryPool(VkDevice device,
VkQueryPool queryPool,
const VkAllocationCallbacks* pAllocator) {
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
mock_device->AddCalledFunction("vkDestroyQueryPool");
delete reinterpret_cast<MockQueryPool*>(queryPool);
}
VkResult vkGetQueryPoolResults(VkDevice device,
VkQueryPool queryPool,
uint32_t firstQuery,
@ -574,6 +584,14 @@ VkResult vkCreateDescriptorPool(VkDevice device,
return VK_SUCCESS;
}
void vkDestroyDescriptorPool(VkDevice device,
VkDescriptorPool descriptorPool,
const VkAllocationCallbacks* pAllocator) {
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
mock_device->AddCalledFunction("vkDestroyDescriptorPool");
delete reinterpret_cast<MockDescriptorPool*>(descriptorPool);
}
VkResult vkResetDescriptorPool(VkDevice device,
VkDescriptorPool descriptorPool,
VkDescriptorPoolResetFlags flags) {
@ -655,15 +673,24 @@ VkResult vkCreateSwapchainKHR(VkDevice device,
return VK_SUCCESS;
}
void vkDestroySwapchainKHR(VkDevice device,
VkSwapchainKHR swapchain,
const VkAllocationCallbacks* pAllocator) {
delete reinterpret_cast<MockSwapchainKHR*>(swapchain);
}
VkResult vkGetSwapchainImagesKHR(VkDevice device,
VkSwapchainKHR swapchain,
uint32_t* pSwapchainImageCount,
VkImage* pSwapchainImages) {
*pSwapchainImageCount = 3;
MockSwapchainKHR* mock_swapchain =
reinterpret_cast<MockSwapchainKHR*>(swapchain);
auto& images = mock_swapchain->images;
*pSwapchainImageCount = images.size();
if (pSwapchainImages != nullptr) {
pSwapchainImages[0] = reinterpret_cast<VkImage>(new MockImage());
pSwapchainImages[1] = reinterpret_cast<VkImage>(new MockImage());
pSwapchainImages[2] = reinterpret_cast<VkImage>(new MockImage());
for (size_t i = 0; i < images.size(); i++) {
pSwapchainImages[i] = reinterpret_cast<VkImage>(&images[i]);
}
}
return VK_SUCCESS;
}
@ -676,6 +703,12 @@ VkResult vkCreateSemaphore(VkDevice device,
return VK_SUCCESS;
}
void vkDestroySemaphore(VkDevice device,
VkSemaphore semaphore,
const VkAllocationCallbacks* pAllocator) {
delete reinterpret_cast<MockSemaphore*>(semaphore);
}
VkResult vkAcquireNextImageKHR(VkDevice device,
VkSwapchainKHR swapchain,
uint64_t timeout,
@ -790,10 +823,14 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
return (PFN_vkVoidFunction)vkSetDebugUtilsObjectNameEXT;
} else if (strcmp("vkCreateQueryPool", pName) == 0) {
return (PFN_vkVoidFunction)vkCreateQueryPool;
} else if (strcmp("vkDestroyQueryPool", pName) == 0) {
return (PFN_vkVoidFunction)vkDestroyQueryPool;
} else if (strcmp("vkGetQueryPoolResults", pName) == 0) {
return (PFN_vkVoidFunction)vkGetQueryPoolResults;
} else if (strcmp("vkCreateDescriptorPool", pName) == 0) {
return (PFN_vkVoidFunction)vkCreateDescriptorPool;
} else if (strcmp("vkDestroyDescriptorPool", pName) == 0) {
return (PFN_vkVoidFunction)vkDestroyDescriptorPool;
} else if (strcmp("vkResetDescriptorPool", pName) == 0) {
return (PFN_vkVoidFunction)vkResetDescriptorPool;
} else if (strcmp("vkAllocateDescriptorSets", pName) == 0) {
@ -806,10 +843,14 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
return (PFN_vkVoidFunction)vkGetPhysicalDeviceSurfaceSupportKHR;
} else if (strcmp("vkCreateSwapchainKHR", pName) == 0) {
return (PFN_vkVoidFunction)vkCreateSwapchainKHR;
} else if (strcmp("vkDestroySwapchainKHR", pName) == 0) {
return (PFN_vkVoidFunction)vkDestroySwapchainKHR;
} else if (strcmp("vkGetSwapchainImagesKHR", pName) == 0) {
return (PFN_vkVoidFunction)vkGetSwapchainImagesKHR;
} else if (strcmp("vkCreateSemaphore", pName) == 0) {
return (PFN_vkVoidFunction)vkCreateSemaphore;
} else if (strcmp("vkDestroySemaphore", pName) == 0) {
return (PFN_vkVoidFunction)vkDestroySemaphore;
} else if (strcmp("vkDestroySurfaceKHR", pName) == 0) {
return (PFN_vkVoidFunction)vkDestroySurfaceKHR;
} else if (strcmp("vkAcquireNextImageKHR", pName) == 0) {