@@ -67,46 +67,48 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkAllocateMemory<user_tag>(
6767 const VkAllocationCallbacks* pAllocator,
6868 VkDeviceMemory* pMemory
6969) {
70-
7170 LAYER_TRACE (__func__);
72-
73- // fprintf(stderr, "[libGPULayers] HIT %s\n", __func__); fflush(stderr);
7471
75- std::unique_lock<std::mutex> lock { g_vulkanLock };
72+ std::unique_lock<std::mutex> lock{ g_vulkanLock};
7673 auto * layer = Device::retrieve (device);
7774 const auto & config = layer->instance ->config ;
7875
79- int disable_external_compression = config.disable_external_compression ();
76+ const int disable_external_compression = config.disable_external_compression ();
8077
81- // absolute passthrough if feature is off
82- if (disable_external_compression == 0 ) {
78+ // Absolute passthrough if feature is off
79+ if (disable_external_compression == 0 )
80+ {
8381 lock.unlock ();
8482 return layer->driver .vkAllocateMemory (device, pAllocateInfo, pAllocator, pMemory);
8583 }
8684
8785 // Scan pNext for imports that we cannot sanitize -> hard-fail to keep the 100% guarantee that we can disable external compression
88- for (const VkBaseInStructure* n = (const VkBaseInStructure*)pAllocateInfo->pNext ; n; n = n->pNext ) {
86+ for (const auto * n = reinterpret_cast <const VkBaseInStructure*>(pAllocateInfo->pNext ); n; n = n->pNext )
87+ {
8988
90- if (n->sType == VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID) {
91- printf (" [libGPULayers] vkAllocateMemory: AHardwareBuffer IMPORT detected. "
92- " Cannot guarantee external compression is disabled (buffer created outside Vulkan). Failing by policy.\n " );
89+ if (n->sType == VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID)
90+ {
91+ LAYER_LOG (" [libGPULayers] vkAllocateMemory: AHardwareBuffer IMPORT detected. "
92+ " Cannot guarantee external compression is disabled (buffer created outside Vulkan). Failing by policy." );
9393 return VK_ERROR_FEATURE_NOT_PRESENT;
9494 }
9595
96- if (n->sType == VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR) {
97- const VkImportMemoryFdInfoKHR* fdInfo = (const VkImportMemoryFdInfoKHR*)n;
98- if (fdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT) {
99- printf (" [libGPULayers] vkAllocateMemory: DMA-BUF memory IMPORT detected (fd=%d). "
100- " Cannot guarantee external compression (DRM modifier may imply compression). Failing by policy.\n " ,
101- fdInfo->fd );
96+ if (n->sType == VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR)
97+ {
98+ const auto * fdInfo = reinterpret_cast <const VkImportMemoryFdInfoKHR*>(n);
99+
100+ if (fdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT)
101+ {
102+ LAYER_LOG (" [libGPULayers] vkAllocateMemory: DMA-BUF memory IMPORT detected (fd=%d). "
103+ " Cannot guarantee external compression (DRM modifier may imply compression). Failing by policy." ,
104+ fdInfo->fd );
102105 return VK_ERROR_FEATURE_NOT_PRESENT;
103106 }
104107 }
105-
108+
106109 }
107110
108111 // Release the lock to call into the driver
109112 lock.unlock ();
110113 return layer->driver .vkAllocateMemory (device, pAllocateInfo, pAllocator, pMemory);
111-
112114}
0 commit comments