Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] ASAN/LSAN fixes for the mock Vulkan implementation #51115

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions impeller/renderer/backend/vulkan/test/mock_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down