Skip to content

Commit cdcf94c

Browse files
committed
Various code formatting
1 parent 35f2419 commit cdcf94c

8 files changed

+346
-163
lines changed

layer_gpu_support/README_LAYER.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ allocated and handled by the driver.
176176
level that meets this bit rate requirement will be left at the original
177177
application setting.
178178
* If `disable_external_compression` option is set to `1` , all the possible measures
179-
are taken so that external compression is disabled. In case is not possible to garantuee
180-
that external compression is used, the layer will return VK_ERROR_FEATURE_NOT_PRESENT.
181-
It should be set to `2` only if the application is not presenting, and is targeting vkCreateImage.
182-
Option `2` is an heuristic, compression could be disabled accidentally on internal images,
183-
and is also possible that it misses external images, if they lack COLOR_ATTACHMENT_BIT.
179+
are taken to ensure that external compression is disabled. In case is not possible to guarantee
180+
that external compression is used, the layer will return `VK_ERROR_FEATURE_NOT_PRESENT`.
181+
Option `2`, in addition to what happens with option `1`, enables a heuristic useful when the
182+
application is not presenting; compression could be disabled accidentally on internal images,
183+
and it may also miss external images if they lack `COLOR_ATTACHMENT_BIT`.
184184
Feel free to tune the heuristic to your specific use case.
185185

186186
#### Configuration options

layer_gpu_support/source/layer_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class LayerConfig
170170
* @brief External compression control for swapchains/images.
171171
* 0 = passthrough (default),
172172
* 1 = strip compression on external images,
173-
* 2 = strip compression on external images even without presentation, using heuristic (no garantuee!)
173+
* 2 = strip compression on external images even without presentation, using heuristic (no guarantee!)
174174
*/
175175
int disable_external_compression() const;
176176

layer_gpu_support/source/layer_device_functions.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,20 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage<user_tag>(VkDevice device,
370370
const VkAllocationCallbacks* pAllocator,
371371
VkImage* pImage);
372372

373-
374373
// Functions for swapchains
375374

376375
/* See Vulkan API for documentation. */
377376
template <>
378377
VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateSwapchainKHR<user_tag>(VkDevice device,
379378
const VkSwapchainCreateInfoKHR* pCreateInfo,
380379
const VkAllocationCallbacks* pAllocator,
381-
VkSwapchainKHR* pSwapchain
382-
);
380+
VkSwapchainKHR* pSwapchain);
383381

384382
// Functions for external DMA-buf
385383

384+
/* See Vulkan API for documentation. */
386385
template <>
387386
VKAPI_ATTR VkResult VKAPI_CALL layer_vkAllocateMemory<user_tag>(VkDevice device,
388387
const VkMemoryAllocateInfo* pAllocateInfo,
389388
const VkAllocationCallbacks* pAllocator,
390-
VkDeviceMemory* pMemory
391-
);
389+
VkDeviceMemory* pMemory);

layer_gpu_support/source/layer_device_functions_allocate_memory.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)