libvulkan: Implement new VkFence parameter in vkAcquireNextImageKHR
This parameter was added recently but wasn't hooked up. This adds a
new parameter to the vkAcquireImageANDROID extension function, and
plumbs the fence through from vkAcquireNextImageKHR to it.
This change also fixes some function signatures for API functions that
are implemented in the loader bottom rather than the driver. These
functions are only ever called through function pointers returned by
vkGet*ProcAddr, and therefore pass through a cast to
PFN_vkVoidFunction. So the compiler had no way to know they were
supposed to match a particular prototype, and couldn't issue an error
when they didn't. This change adds explicit static casts to the
expected function pointer type before reinterpret casting to the
generic function pointer type to enable compile errors.
Change-Id: I8a7e065502f783d5f2381b43c880644868234f8f
(cherry picked from commit f62f5de0c60212796b6d910cbd194c7002226264)
diff --git a/vulkan/libvulkan/loader.cpp b/vulkan/libvulkan/loader.cpp
index defd691..ee9af85 100644
--- a/vulkan/libvulkan/loader.cpp
+++ b/vulkan/libvulkan/loader.cpp
@@ -539,33 +539,44 @@
return false;
}
-VkResult Noop(...) {
+VkResult Noop() {
return VK_SUCCESS;
}
VKAPI_ATTR PFN_vkVoidFunction
GetLayerDeviceProcAddr(VkDevice device, const char* name) {
+ // The static_casts are used to ensure that our function actually
+ // matches the API function prototype. Otherwise, if the API function
+ // prototype changes (only a problem during API development), the compiler
+ // has no way of knowing that the function is supposed to match the
+ // prototype, so won't warn us if they don't.
if (strcmp(name, "vkGetDeviceProcAddr") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(GetLayerDeviceProcAddr);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkGetDeviceProcAddr>(GetLayerDeviceProcAddr));
}
if (strcmp(name, "vkCreateDevice") == 0) {
return reinterpret_cast<PFN_vkVoidFunction>(Noop);
}
// WSI extensions are not in the driver so return the loader functions
if (strcmp(name, "vkCreateSwapchainKHR") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkCreateSwapchainKHR>(CreateSwapchainKHR));
}
if (strcmp(name, "vkDestroySwapchainKHR") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkDestroySwapchainKHR>(DestroySwapchainKHR));
}
if (strcmp(name, "vkGetSwapchainImagesKHR") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkGetSwapchainImagesKHR>(GetSwapchainImagesKHR));
}
if (strcmp(name, "vkAcquireNextImageKHR") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkAcquireNextImageKHR>(AcquireNextImageKHR));
}
if (strcmp(name, "vkQueuePresentKHR") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkQueuePresentKHR>(QueuePresentKHR));
}
if (!device)
return GetGlobalDeviceProcAddr(name);
@@ -927,7 +938,8 @@
return reinterpret_cast<PFN_vkVoidFunction>(Noop);
}
if (strcmp(name, "vkCreateInstance") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(CreateInstanceBottom);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkCreateInstance>(CreateInstanceBottom));
}
return GetSpecificInstanceProcAddr(&kBottomInstanceFunctions, name);
}
@@ -1116,16 +1128,20 @@
if (!device)
return GetGlobalDeviceProcAddr(name);
if (strcmp(name, "vkGetDeviceProcAddr") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkGetDeviceProcAddr>(GetDeviceProcAddr));
}
if (strcmp(name, "vkGetDeviceQueue") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkGetDeviceQueue>(GetDeviceQueue));
}
if (strcmp(name, "vkAllocateCommandBuffers") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkAllocateCommandBuffers>(AllocateCommandBuffers));
}
if (strcmp(name, "vkDestroyDevice") == 0) {
- return reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice);
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ static_cast<PFN_vkDestroyDevice>(DestroyDevice));
}
return GetSpecificDeviceProcAddr(GetVtbl(device), name);
}
@@ -1164,8 +1180,8 @@
return VK_SUCCESS;
}
-VkResult DestroyDevice(VkDevice drv_device,
- const VkAllocationCallbacks* /*allocator*/) {
+void DestroyDevice(VkDevice drv_device,
+ const VkAllocationCallbacks* /*allocator*/) {
const DeviceVtbl* vtbl = GetVtbl(drv_device);
Device* device = static_cast<Device*>(vtbl->device);
for (auto it = device->active_layers.begin();
@@ -1174,7 +1190,6 @@
}
vtbl->DestroyDevice(drv_device, device->instance->alloc);
DestroyDevice(device);
- return VK_SUCCESS;
}
void* AllocMem(VkInstance instance,
diff --git a/vulkan/libvulkan/loader.h b/vulkan/libvulkan/loader.h
index e007f8d..65f11f4 100644
--- a/vulkan/libvulkan/loader.h
+++ b/vulkan/libvulkan/loader.h
@@ -215,16 +215,18 @@
const VkAllocationCallbacks* allocator,
VkInstance* instance);
PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
-PFN_vkVoidFunction GetDeviceProcAddr(VkDevice drv_device, const char* name);
-void GetDeviceQueue(VkDevice drv_device,
- uint32_t family,
- uint32_t index,
- VkQueue* out_queue);
-VkResult AllocateCommandBuffers(VkDevice device,
- const VkCommandBufferAllocateInfo* alloc_info,
- VkCommandBuffer* cmdbufs);
-VkResult DestroyDevice(VkDevice drv_device,
- const VkAllocationCallbacks* allocator);
+VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr(VkDevice drv_device,
+ const char* name);
+VKAPI_ATTR void GetDeviceQueue(VkDevice drv_device,
+ uint32_t family,
+ uint32_t index,
+ VkQueue* out_queue);
+VKAPI_ATTR VkResult
+AllocateCommandBuffers(VkDevice device,
+ const VkCommandBufferAllocateInfo* alloc_info,
+ VkCommandBuffer* cmdbufs);
+VKAPI_ATTR void DestroyDevice(VkDevice drv_device,
+ const VkAllocationCallbacks* allocator);
void* AllocMem(VkInstance instance,
size_t size,
@@ -292,9 +294,9 @@
const VkSwapchainCreateInfoKHR* create_info,
const VkAllocationCallbacks* allocator,
VkSwapchainKHR* swapchain_handle);
-VKAPI_ATTR VkResult DestroySwapchainKHR(VkDevice device,
- VkSwapchainKHR swapchain_handle,
- const VkAllocationCallbacks* allocator);
+VKAPI_ATTR void DestroySwapchainKHR(VkDevice device,
+ VkSwapchainKHR swapchain_handle,
+ const VkAllocationCallbacks* allocator);
VKAPI_ATTR VkResult GetSwapchainImagesKHR(VkDevice device,
VkSwapchainKHR swapchain_handle,
uint32_t* count,
@@ -303,6 +305,7 @@
VkSwapchainKHR swapchain_handle,
uint64_t timeout,
VkSemaphore semaphore,
+ VkFence fence,
uint32_t* image_index);
VKAPI_ATTR VkResult
QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info);
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 39a581c..88e4d6f 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -487,9 +487,9 @@
}
VKAPI_ATTR
-VkResult DestroySwapchainKHR(VkDevice device,
- VkSwapchainKHR swapchain_handle,
- const VkAllocationCallbacks* /*allocator*/) {
+void DestroySwapchainKHR(VkDevice device,
+ VkSwapchainKHR swapchain_handle,
+ const VkAllocationCallbacks* /*allocator*/) {
const DeviceVtbl& driver_vtbl = GetDriverVtbl(device);
Swapchain* swapchain = SwapchainFromHandle(swapchain_handle);
const std::shared_ptr<ANativeWindow>& window = swapchain->surface.window;
@@ -509,8 +509,6 @@
swapchain->~Swapchain();
FreeMem(device, swapchain);
-
- return VK_SUCCESS;
}
VKAPI_ATTR
@@ -538,6 +536,7 @@
VkSwapchainKHR swapchain_handle,
uint64_t timeout,
VkSemaphore semaphore,
+ VkFence vk_fence,
uint32_t* image_index) {
Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle);
ANativeWindow* window = swapchain.surface.window.get();
@@ -549,8 +548,8 @@
"vkAcquireNextImageKHR: non-infinite timeouts not yet implemented");
ANativeWindowBuffer* buffer;
- int fence;
- err = window->dequeueBuffer(window, &buffer, &fence);
+ int fence_fd;
+ err = window->dequeueBuffer(window, &buffer, &fence_fd);
if (err != 0) {
// TODO(jessehall): Improve error reporting. Can we enumerate possible
// errors and translate them to valid Vulkan result codes?
@@ -562,30 +561,31 @@
for (idx = 0; idx < swapchain.num_images; idx++) {
if (swapchain.images[idx].buffer.get() == buffer) {
swapchain.images[idx].dequeued = true;
- swapchain.images[idx].dequeue_fence = fence;
+ swapchain.images[idx].dequeue_fence = fence_fd;
break;
}
}
if (idx == swapchain.num_images) {
ALOGE("dequeueBuffer returned unrecognized buffer");
- window->cancelBuffer(window, buffer, fence);
+ window->cancelBuffer(window, buffer, fence_fd);
return VK_ERROR_OUT_OF_DATE_KHR;
}
int fence_clone = -1;
- if (fence != -1) {
- fence_clone = dup(fence);
+ if (fence_fd != -1) {
+ fence_clone = dup(fence_fd);
if (fence_clone == -1) {
ALOGE("dup(fence) failed, stalling until signalled: %s (%d)",
strerror(errno), errno);
- sync_wait(fence, -1 /* forever */);
+ sync_wait(fence_fd, -1 /* forever */);
}
}
const DeviceVtbl& driver_vtbl = GetDriverVtbl(device);
if (driver_vtbl.AcquireImageANDROID) {
- result = driver_vtbl.AcquireImageANDROID(
- device, swapchain.images[idx].image, fence_clone, semaphore);
+ result =
+ driver_vtbl.AcquireImageANDROID(device, swapchain.images[idx].image,
+ fence_clone, semaphore, vk_fence);
} else {
ALOG_ASSERT(driver_vtbl.ImportNativeFenceANDROID,
"Have neither vkAcquireImageANDROID nor "
@@ -601,7 +601,7 @@
// number between the time the driver closes it and the time we close
// it. We must assume one of: the driver *always* closes it even on
// failure, or *never* closes it on failure.
- window->cancelBuffer(window, buffer, fence);
+ window->cancelBuffer(window, buffer, fence_fd);
swapchain.images[idx].dequeued = false;
swapchain.images[idx].dequeue_fence = -1;
return result;