From 4a6a91647c57abb5c06cde57c57afe944f8cefa4 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 26 Mar 2016 07:17:34 +0800 Subject: [PATCH] vulkan: use driver::GetData everywhere Move away from the one-liners defined in loader.cpp. Change-Id: I73c39cbe21aa3b2079f67590bb40f0cd55563f84 --- vulkan/libvulkan/code-generator.tmpl | 1 - vulkan/libvulkan/debug_report.cpp | 46 +++++++++++++++++------------------- vulkan/libvulkan/driver.cpp | 1 - vulkan/libvulkan/driver.h | 1 + vulkan/libvulkan/driver_gen.cpp | 1 - vulkan/libvulkan/swapchain.cpp | 24 +++++++++---------- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl index 5b6c6d2271..afe0d8417c 100644 --- a/vulkan/libvulkan/code-generator.tmpl +++ b/vulkan/libvulkan/code-generator.tmpl @@ -219,7 +219,6 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc); #include ¶ #include "driver.h" -#include "loader.h" ¶ namespace vulkan {« namespace driver {« diff --git a/vulkan/libvulkan/debug_report.cpp b/vulkan/libvulkan/debug_report.cpp index 5055640947..c4a1174191 100644 --- a/vulkan/libvulkan/debug_report.cpp +++ b/vulkan/libvulkan/debug_report.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "loader.h" +#include "driver.h" namespace vulkan { namespace driver { @@ -26,24 +26,22 @@ VkResult DebugReportCallbackList::CreateCallback( VkDebugReportCallbackEXT* callback) { VkDebugReportCallbackEXT driver_callback = VK_NULL_HANDLE; - if (GetDriverDispatch(instance).CreateDebugReportCallbackEXT) { - VkResult result = - GetDriverDispatch(instance).CreateDebugReportCallbackEXT( - GetDriverInstance(instance), create_info, allocator, - &driver_callback); + if (GetData(instance).driver.CreateDebugReportCallbackEXT) { + VkResult result = GetData(instance).driver.CreateDebugReportCallbackEXT( + instance, create_info, allocator, &driver_callback); if (result != VK_SUCCESS) return result; } const VkAllocationCallbacks* alloc = - allocator ? allocator : GetAllocator(instance); + allocator ? allocator : &GetData(instance).allocator; void* mem = alloc->pfnAllocation(alloc->pUserData, sizeof(Node), alignof(Node), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!mem) { - if (GetDriverDispatch(instance).DestroyDebugReportCallbackEXT) { - GetDriverDispatch(instance).DestroyDebugReportCallbackEXT( - GetDriverInstance(instance), driver_callback, allocator); + if (GetData(instance).driver.DestroyDebugReportCallbackEXT) { + GetData(instance).driver.DestroyDebugReportCallbackEXT( + instance, driver_callback, allocator); } return VK_ERROR_OUT_OF_HOST_MEMORY; } @@ -69,13 +67,13 @@ void DebugReportCallbackList::DestroyCallback( prev->next = node->next; lock.unlock(); - if (GetDriverDispatch(instance).DestroyDebugReportCallbackEXT) { - GetDriverDispatch(instance).DestroyDebugReportCallbackEXT( - GetDriverInstance(instance), node->driver_callback, allocator); + if (GetData(instance).driver.DestroyDebugReportCallbackEXT) { + GetData(instance).driver.DestroyDebugReportCallbackEXT( + instance, node->driver_callback, allocator); } const VkAllocationCallbacks* alloc = - allocator ? allocator : GetAllocator(instance); + allocator ? allocator : &GetData(instance).allocator; alloc->pfnFree(alloc->pUserData, node); } @@ -101,7 +99,7 @@ VkResult CreateDebugReportCallbackEXT( const VkDebugReportCallbackCreateInfoEXT* create_info, const VkAllocationCallbacks* allocator, VkDebugReportCallbackEXT* callback) { - return GetDebugReportCallbacks(instance).CreateCallback( + return GetData(instance).debug_report_callbacks.CreateCallback( instance, create_info, allocator, callback); } @@ -109,8 +107,8 @@ void DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* allocator) { if (callback) - GetDebugReportCallbacks(instance).DestroyCallback(instance, callback, - allocator); + GetData(instance).debug_report_callbacks.DestroyCallback( + instance, callback, allocator); } void DebugReportMessageEXT(VkInstance instance, @@ -121,14 +119,14 @@ void DebugReportMessageEXT(VkInstance instance, int32_t message_code, const char* layer_prefix, const char* message) { - if (GetDriverDispatch(instance).DebugReportMessageEXT) { - GetDriverDispatch(instance).DebugReportMessageEXT( - GetDriverInstance(instance), flags, object_type, object, location, - message_code, layer_prefix, message); + if (GetData(instance).driver.DebugReportMessageEXT) { + GetData(instance).driver.DebugReportMessageEXT( + instance, flags, object_type, object, location, message_code, + layer_prefix, message); } - GetDebugReportCallbacks(instance).Message(flags, object_type, object, - location, message_code, - layer_prefix, message); + GetData(instance).debug_report_callbacks.Message(flags, object_type, object, + location, message_code, + layer_prefix, message); } } // namespace driver diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index f2f1d08656..007c54dd9d 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -23,7 +23,6 @@ #include #include "driver.h" -#include "loader.h" // #define ENABLE_ALLOC_CALLSTACKS 1 #if ENABLE_ALLOC_CALLSTACKS diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index 4cc3ee7df9..22db93f577 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -28,6 +28,7 @@ #include "api_gen.h" #include "driver_gen.h" #include "debug_report.h" +#include "swapchain.h" namespace vulkan { diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index 78a952abf3..8b816bac96 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -21,7 +21,6 @@ #include #include "driver.h" -#include "loader.h" namespace vulkan { namespace driver { diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 4aa1ed6508..bda6676285 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -21,7 +21,7 @@ #include #include -#include "loader.h" +#include "driver.h" // TODO(jessehall): Currently we don't have a good error code for when a native // window operation fails. Just returning INITIALIZATION_FAILED for now. Later @@ -98,9 +98,9 @@ template std::shared_ptr InitSharedPtr(Host host, T* obj) { try { obj->common.incRef(&obj->common); - return std::shared_ptr( - obj, NativeBaseDeleter(), - VulkanAllocator(*GetAllocator(host), AllocScope::kScope)); + return std::shared_ptr(obj, NativeBaseDeleter(), + VulkanAllocator(GetData(host).allocator, + AllocScope::kScope)); } catch (std::bad_alloc&) { obj->common.decRef(&obj->common); return nullptr; @@ -231,7 +231,7 @@ VkResult CreateAndroidSurfaceKHR( const VkAllocationCallbacks* allocator, VkSurfaceKHR* out_surface) { if (!allocator) - allocator = GetAllocator(instance); + allocator = &GetData(instance).allocator; void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Surface), alignof(Surface), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); @@ -274,7 +274,7 @@ void DestroySurfaceKHR(VkInstance instance, native_window_api_disconnect(surface->window.get(), NATIVE_WINDOW_API_EGL); surface->~Surface(); if (!allocator) - allocator = GetAllocator(instance); + allocator = &GetData(instance).allocator; allocator->pfnFree(allocator->pUserData, surface); } @@ -411,7 +411,7 @@ VkResult CreateSwapchainKHR(VkDevice device, VkResult result = VK_SUCCESS; if (!allocator) - allocator = GetAllocator(device); + allocator = &GetData(device).allocator; ALOGV_IF(create_info->imageArrayLayers != 1, "Swapchain imageArrayLayers (%u) != 1 not supported", @@ -432,7 +432,7 @@ VkResult CreateSwapchainKHR(VkDevice device, // -- Configure the native window -- Surface& surface = *SurfaceFromHandle(create_info->surface); - const auto& dispatch = GetDriverDispatch(device); + const auto& dispatch = GetData(device).driver; int native_format = HAL_PIXEL_FORMAT_RGBA_8888; switch (create_info->imageFormat) { @@ -680,7 +680,7 @@ VKAPI_ATTR void DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain_handle, const VkAllocationCallbacks* allocator) { - const auto& dispatch = GetDriverDispatch(device); + const auto& dispatch = GetData(device).driver; Swapchain* swapchain = SwapchainFromHandle(swapchain_handle); const std::shared_ptr& window = swapchain->surface.window; @@ -698,7 +698,7 @@ void DestroySwapchainKHR(VkDevice device, } if (!allocator) - allocator = GetAllocator(device); + allocator = &GetData(device).allocator; swapchain->~Swapchain(); allocator->pfnFree(allocator->pUserData, swapchain); } @@ -773,7 +773,7 @@ VkResult AcquireNextImageKHR(VkDevice device, } } - result = GetDriverDispatch(device).AcquireImageANDROID( + result = GetData(device).driver.AcquireImageANDROID( device, swapchain.images[idx].image, fence_clone, semaphore, vk_fence); if (result != VK_SUCCESS) { // NOTE: we're relying on AcquireImageANDROID to close fence_clone, @@ -800,7 +800,7 @@ VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info) { present_info->sType); ALOGV_IF(present_info->pNext, "VkPresentInfo::pNext != NULL"); - const auto& dispatch = GetDriverDispatch(queue); + const auto& dispatch = GetData(queue).driver; VkResult final_result = VK_SUCCESS; for (uint32_t sc = 0; sc < present_info->swapchainCount; sc++) { Swapchain& swapchain = -- 2.11.0