vulkan: Implement new vkGet*ProcAddrBehavior
The primary goal of this change is to switch to the revised GPA
behavior:
- GIPA(NULL, ..) only works for non-dispatched (global) commands
- GIPA(instance, ..) returns functions for commands that dispatch on any
object type, and the function works for any object of the appropriate
type if it is a child of the instance.
- GDPA(NULL, ..) returns NULL.
- GDPA(device, ..) returns a device-specific function for the command.
This change refactors/tidies many of the things it modified. Some
notable changes:
- All the loader generated code is now in dispatch.tmpl ->
dispatch_gen.{h,cpp}, instead of two separate templates.
- Reorganization allowed generating the dispatch table structures,
eliminating one source of frequent bugs.
- Removes some error-prone macro duplication.
- Handling of extensions and special loader functions is now much
more uniform and hopefully clearer.
- Loader top- and bottom-level functions are now consistently named with
_Top and _Bottom suffixes, and are grouped by level in loader.cpp.
- The VkInstance and VkDevice implementations are no longer derived from
::VkInstance_T and ::VkDevice_T. Was more trouble than it was worth.
- Renamed 'vtbl' to 'dispatch' in most places.
- Renamed nulldrv template and generated files to match the loader
naming pattern: null_driver.tmpl -> null_driver_gen.{h,cpp}
- Now all the entry point prototypes are generated, instead of having
to be updated by hand (another source of several bugs).
Change-Id: Ic263f802d0d523b18a0f00420b3a722aa04ce299
(cherry picked from commit 3cffb8e837222f413a1fe53522e2cc33366b8eeb)
diff --git a/vulkan/nulldrv/null_driver.cpp b/vulkan/nulldrv/null_driver.cpp
index 8e654f1..76593ee 100644
--- a/vulkan/nulldrv/null_driver.cpp
+++ b/vulkan/nulldrv/null_driver.cpp
@@ -16,16 +16,16 @@
#include <hardware/hwvulkan.h>
-#include <array>
-#include <algorithm>
#include <inttypes.h>
#include <string.h>
+#include <algorithm>
+#include <array>
// #define LOG_NDEBUG 0
#include <log/log.h>
#include <utils/Errors.h>
-#include "null_driver.h"
+#include "null_driver_gen.h"
using namespace null_driver;
@@ -129,30 +129,6 @@
namespace {
-VKAPI_ATTR
-VkResult CreateInstance(const VkInstanceCreateInfo* /*create_info*/,
- const VkAllocationCallbacks* allocator,
- VkInstance* out_instance) {
- // Assume the loader provided alloc callbacks even if the app didn't.
- ALOG_ASSERT(
- allocator,
- "Missing alloc callbacks, loader or app should have provided them");
-
- VkInstance_T* instance =
- static_cast<VkInstance_T*>(allocator->pfnAllocation(
- allocator->pUserData, sizeof(VkInstance_T), alignof(VkInstance_T),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE));
- if (!instance)
- return VK_ERROR_OUT_OF_HOST_MEMORY;
-
- instance->dispatch.magic = HWVULKAN_DISPATCH_MAGIC;
- instance->allocator = *allocator;
- instance->physical_device.dispatch.magic = HWVULKAN_DISPATCH_MAGIC;
-
- *out_instance = instance;
- return VK_SUCCESS;
-}
-
int CloseDevice(struct hw_device_t* /*device*/) {
// nothing to do - opening a device doesn't allocate any resources
return 0;
@@ -224,27 +200,37 @@
}
VKAPI_ATTR
-PFN_vkVoidFunction GetInstanceProcAddr(VkInstance, const char* name) {
- PFN_vkVoidFunction proc = LookupInstanceProcAddr(name);
- if (!proc && strcmp(name, "vkGetDeviceProcAddr") == 0)
- proc = reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr);
- return proc;
+VkResult CreateInstance(const VkInstanceCreateInfo* /*create_info*/,
+ const VkAllocationCallbacks* allocator,
+ VkInstance* out_instance) {
+ // Assume the loader provided alloc callbacks even if the app didn't.
+ ALOG_ASSERT(
+ allocator,
+ "Missing alloc callbacks, loader or app should have provided them");
+
+ VkInstance_T* instance =
+ static_cast<VkInstance_T*>(allocator->pfnAllocation(
+ allocator->pUserData, sizeof(VkInstance_T), alignof(VkInstance_T),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE));
+ if (!instance)
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+
+ instance->dispatch.magic = HWVULKAN_DISPATCH_MAGIC;
+ instance->allocator = *allocator;
+ instance->physical_device.dispatch.magic = HWVULKAN_DISPATCH_MAGIC;
+
+ *out_instance = instance;
+ return VK_SUCCESS;
+}
+
+VKAPI_ATTR
+PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) {
+ return instance ? GetInstanceProcAddr(name) : GetGlobalProcAddr(name);
}
VKAPI_ATTR
PFN_vkVoidFunction GetDeviceProcAddr(VkDevice, const char* name) {
- PFN_vkVoidFunction proc = LookupDeviceProcAddr(name);
- if (proc)
- return proc;
- if (strcmp(name, "vkGetSwapchainGrallocUsageANDROID") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(
- GetSwapchainGrallocUsageANDROID);
- if (strcmp(name, "vkAcquireImageANDROID") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(AcquireImageANDROID);
- if (strcmp(name, "vkQueueSignalReleaseImageANDROID") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(
- QueueSignalReleaseImageANDROID);
- return nullptr;
+ return GetInstanceProcAddr(name);
}
// -----------------------------------------------------------------------------
@@ -730,7 +716,11 @@
return VK_SUCCESS;
}
-VkResult AcquireImageANDROID(VkDevice, VkImage, int fence, VkSemaphore) {
+VkResult AcquireImageANDROID(VkDevice,
+ VkImage,
+ int fence,
+ VkSemaphore,
+ VkFence) {
close(fence);
return VK_SUCCESS;
}