Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bde8ee30 authored by Jesse Hall's avatar Jesse Hall
Browse files

vulkan: warn on bogus CreateBuffer args

Change-Id: I415a367f3952ef08f8b659d15ce4278da8c4b70a
(cherry picked from commit f96997afd168a31582217d19fc237163c963dad0)
parent c7a6eb56
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
#include <hardware/hwvulkan.h>

#include <array>
#include <string.h>
#include <algorithm>
#include <inttypes.h>
#include <string.h>

// #define LOG_NDEBUG 0
#include <log/log.h>
@@ -77,6 +78,9 @@ enum Enum {
};
}  // namespace HandleType
uint64_t AllocHandle(VkDevice device, HandleType::Enum type);

const VkDeviceSize kMaxDeviceMemory = VkDeviceSize(INTPTR_MAX) + 1;

}  // anonymous namespace

struct VkDevice_T {
@@ -169,8 +173,7 @@ VkInstance_T* GetInstanceFromPhysicalDevice(
uint64_t AllocHandle(VkDevice device, HandleType::Enum type) {
    const uint64_t kHandleMask = (UINT64_C(1) << 56) - 1;
    ALOGE_IF(device->next_handle[type] == kHandleMask,
        "non-dispatchable handles of type=%u are about to overflow",
        type);
             "non-dispatchable handles of type=%u are about to overflow", type);
    return (UINT64_C(1) << 63) | ((uint64_t(type) & 0x7) << 56) |
           (device->next_handle[type]++ & kHandleMask);
}
@@ -256,8 +259,7 @@ VkResult GetPhysicalDeviceMemoryProperties(
        VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
    properties->memoryTypes[0].heapIndex = 0;
    properties->memoryHeapCount = 1;
    properties->memoryHeaps[0].size =
        INTPTR_MAX;  // TODO: do something smarter?
    properties->memoryHeaps[0].size = kMaxDeviceMemory;
    properties->memoryHeaps[0].flags = VK_MEMORY_HEAP_HOST_LOCAL;
    return VK_SUCCESS;
}
@@ -385,6 +387,11 @@ struct HandleTraits<VkBuffer> {
VkResult CreateBuffer(VkDevice device,
                      const VkBufferCreateInfo* create_info,
                      VkBuffer* buffer_handle) {
    ALOGW_IF(create_info->size > kMaxDeviceMemory,
             "CreateBuffer: requested size 0x%" PRIx64
             " exceeds max device memory size 0x%" PRIx64,
             create_info->size, kMaxDeviceMemory);

    const VkAllocCallbacks* alloc = device->instance->alloc;
    Buffer* buffer = static_cast<Buffer*>(
        alloc->pfnAlloc(alloc->pUserData, sizeof(Buffer), alignof(Buffer),