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

Commit 2706c73

Browse files
[Impeller] ASAN/LSAN fixes for the mock Vulkan implementation (#51115)
1 parent 8ef8543 commit 2706c73

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

impeller/renderer/backend/vulkan/test/mock_vulkan.cc

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ struct MockDescriptorPool {};
3636

3737
struct MockSurfaceKHR {};
3838

39-
struct MockSwapchainKHR {};
40-
4139
struct MockImage {};
4240

41+
struct MockSwapchainKHR {
42+
std::array<MockImage, 3> images;
43+
};
44+
4345
struct MockSemaphore {};
4446

4547
static ISize currentImageSize = ISize{1, 1};
@@ -539,6 +541,14 @@ VkResult vkCreateQueryPool(VkDevice device,
539541
return VK_SUCCESS;
540542
}
541543

544+
void vkDestroyQueryPool(VkDevice device,
545+
VkQueryPool queryPool,
546+
const VkAllocationCallbacks* pAllocator) {
547+
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
548+
mock_device->AddCalledFunction("vkDestroyQueryPool");
549+
delete reinterpret_cast<MockQueryPool*>(queryPool);
550+
}
551+
542552
VkResult vkGetQueryPoolResults(VkDevice device,
543553
VkQueryPool queryPool,
544554
uint32_t firstQuery,
@@ -574,6 +584,14 @@ VkResult vkCreateDescriptorPool(VkDevice device,
574584
return VK_SUCCESS;
575585
}
576586

587+
void vkDestroyDescriptorPool(VkDevice device,
588+
VkDescriptorPool descriptorPool,
589+
const VkAllocationCallbacks* pAllocator) {
590+
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
591+
mock_device->AddCalledFunction("vkDestroyDescriptorPool");
592+
delete reinterpret_cast<MockDescriptorPool*>(descriptorPool);
593+
}
594+
577595
VkResult vkResetDescriptorPool(VkDevice device,
578596
VkDescriptorPool descriptorPool,
579597
VkDescriptorPoolResetFlags flags) {
@@ -655,15 +673,24 @@ VkResult vkCreateSwapchainKHR(VkDevice device,
655673
return VK_SUCCESS;
656674
}
657675

676+
void vkDestroySwapchainKHR(VkDevice device,
677+
VkSwapchainKHR swapchain,
678+
const VkAllocationCallbacks* pAllocator) {
679+
delete reinterpret_cast<MockSwapchainKHR*>(swapchain);
680+
}
681+
658682
VkResult vkGetSwapchainImagesKHR(VkDevice device,
659683
VkSwapchainKHR swapchain,
660684
uint32_t* pSwapchainImageCount,
661685
VkImage* pSwapchainImages) {
662-
*pSwapchainImageCount = 3;
686+
MockSwapchainKHR* mock_swapchain =
687+
reinterpret_cast<MockSwapchainKHR*>(swapchain);
688+
auto& images = mock_swapchain->images;
689+
*pSwapchainImageCount = images.size();
663690
if (pSwapchainImages != nullptr) {
664-
pSwapchainImages[0] = reinterpret_cast<VkImage>(new MockImage());
665-
pSwapchainImages[1] = reinterpret_cast<VkImage>(new MockImage());
666-
pSwapchainImages[2] = reinterpret_cast<VkImage>(new MockImage());
691+
for (size_t i = 0; i < images.size(); i++) {
692+
pSwapchainImages[i] = reinterpret_cast<VkImage>(&images[i]);
693+
}
667694
}
668695
return VK_SUCCESS;
669696
}
@@ -676,6 +703,12 @@ VkResult vkCreateSemaphore(VkDevice device,
676703
return VK_SUCCESS;
677704
}
678705

706+
void vkDestroySemaphore(VkDevice device,
707+
VkSemaphore semaphore,
708+
const VkAllocationCallbacks* pAllocator) {
709+
delete reinterpret_cast<MockSemaphore*>(semaphore);
710+
}
711+
679712
VkResult vkAcquireNextImageKHR(VkDevice device,
680713
VkSwapchainKHR swapchain,
681714
uint64_t timeout,
@@ -790,10 +823,14 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
790823
return (PFN_vkVoidFunction)vkSetDebugUtilsObjectNameEXT;
791824
} else if (strcmp("vkCreateQueryPool", pName) == 0) {
792825
return (PFN_vkVoidFunction)vkCreateQueryPool;
826+
} else if (strcmp("vkDestroyQueryPool", pName) == 0) {
827+
return (PFN_vkVoidFunction)vkDestroyQueryPool;
793828
} else if (strcmp("vkGetQueryPoolResults", pName) == 0) {
794829
return (PFN_vkVoidFunction)vkGetQueryPoolResults;
795830
} else if (strcmp("vkCreateDescriptorPool", pName) == 0) {
796831
return (PFN_vkVoidFunction)vkCreateDescriptorPool;
832+
} else if (strcmp("vkDestroyDescriptorPool", pName) == 0) {
833+
return (PFN_vkVoidFunction)vkDestroyDescriptorPool;
797834
} else if (strcmp("vkResetDescriptorPool", pName) == 0) {
798835
return (PFN_vkVoidFunction)vkResetDescriptorPool;
799836
} else if (strcmp("vkAllocateDescriptorSets", pName) == 0) {
@@ -806,10 +843,14 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
806843
return (PFN_vkVoidFunction)vkGetPhysicalDeviceSurfaceSupportKHR;
807844
} else if (strcmp("vkCreateSwapchainKHR", pName) == 0) {
808845
return (PFN_vkVoidFunction)vkCreateSwapchainKHR;
846+
} else if (strcmp("vkDestroySwapchainKHR", pName) == 0) {
847+
return (PFN_vkVoidFunction)vkDestroySwapchainKHR;
809848
} else if (strcmp("vkGetSwapchainImagesKHR", pName) == 0) {
810849
return (PFN_vkVoidFunction)vkGetSwapchainImagesKHR;
811850
} else if (strcmp("vkCreateSemaphore", pName) == 0) {
812851
return (PFN_vkVoidFunction)vkCreateSemaphore;
852+
} else if (strcmp("vkDestroySemaphore", pName) == 0) {
853+
return (PFN_vkVoidFunction)vkDestroySemaphore;
813854
} else if (strcmp("vkDestroySurfaceKHR", pName) == 0) {
814855
return (PFN_vkVoidFunction)vkDestroySurfaceKHR;
815856
} else if (strcmp("vkAcquireNextImageKHR", pName) == 0) {

0 commit comments

Comments
 (0)