aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYilong Li <liyl@google.com>2021-06-23 12:43:57 -0700
committerYahan Zhou <yahan@google.com>2021-06-23 15:21:12 -0700
commit68b584f970048e2dd542941684abe48a95dad28b (patch)
treeae573095273b4918e491991f969b127844b6d567
parent75164d849aa19d18cb942db1046b86cc67b78587 (diff)
downloadgoldfish-opengl-68b584f970048e2dd542941684abe48a95dad28b.tar.gz
vk: only set MemoryReportFeatures if it exists in the struct chain
vkGetPhysicalDeviceProperties2() should only sets the VkPhysicalDeviceDeviceMemoryReportFeaturesEXT struct if it exists in the pProperties struct chain, otherwise it violates the Vulkan specs and could cause a memory leak. Bug: 189960236 Test: com.google.android.graphics.gts.VulkanTest#checkVulkanDeviceMemoryReportSupport Change-Id: Icde88dfd7eab73b88513a1493c942119a6f064fc
-rw-r--r--system/vulkan_enc/ResourceTracker.cpp13
-rw-r--r--system/vulkan_enc/vk_struct_id.h2
2 files changed, 8 insertions, 7 deletions
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 62566fc3..3fa037a5 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -129,6 +129,7 @@ VkResult getMemoryAndroidHardwareBufferANDROID(struct AHardwareBuffer **) { retu
#include "goldfish_address_space.h"
#include "goldfish_vk_private_defs.h"
#include "vk_format_info.h"
+#include "vk_struct_id.h"
#include "vk_util.h"
#include <set>
@@ -1607,13 +1608,11 @@ public:
pProperties->properties.deviceType =
VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
- VkPhysicalDeviceDeviceMemoryReportFeaturesEXT *memoryReportFeaturesEXT
- = new VkPhysicalDeviceDeviceMemoryReportFeaturesEXT();
- memoryReportFeaturesEXT->sType
- = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT;
- memoryReportFeaturesEXT->pNext = pProperties->pNext;
- memoryReportFeaturesEXT->deviceMemoryReport = VK_TRUE;
- pProperties->pNext = memoryReportFeaturesEXT;
+ VkPhysicalDeviceDeviceMemoryReportFeaturesEXT* memoryReportFeaturesEXT =
+ vk_find_struct<VkPhysicalDeviceDeviceMemoryReportFeaturesEXT>(pProperties);
+ if (memoryReportFeaturesEXT) {
+ memoryReportFeaturesEXT->deviceMemoryReport = VK_TRUE;
+ }
}
}
diff --git a/system/vulkan_enc/vk_struct_id.h b/system/vulkan_enc/vk_struct_id.h
index 5cfb7955..5a7328a9 100644
--- a/system/vulkan_enc/vk_struct_id.h
+++ b/system/vulkan_enc/vk_struct_id.h
@@ -56,5 +56,7 @@ REGISTER_VK_STRUCT_ID(VkExternalImageFormatProperties, VK_STRUCTURE_TYPE_EXTERNA
REGISTER_VK_STRUCT_ID(VkPhysicalDeviceImageFormatInfo2, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2);
REGISTER_VK_STRUCT_ID(VkPhysicalDeviceExternalImageFormatInfo, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO);
REGISTER_VK_STRUCT_ID(VkSemaphoreTypeCreateInfo, VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO);
+REGISTER_VK_STRUCT_ID(VkPhysicalDeviceProperties2, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2);
+REGISTER_VK_STRUCT_ID(VkPhysicalDeviceDeviceMemoryReportFeaturesEXT, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_MEMORY_REPORT_FEATURES_EXT);
#undef REGISTER_VK_STRUCT_ID