From d3d887ab4640fd948834651b8e82782955f53941 Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Mon, 5 Mar 2018 13:34:45 -0800 Subject: Enable VK_KHR_swapchain for instances. This is a specific instance of a general capability. Beginning with Vulkan 1.1, physical-device commands can part of device extensions, and can be called before the application creates a device. vkGetInstanceProcAddr only returns commands for enabled extensions, and so we must internally enable device extensions inside of the instance. This commit enables VK_KHR_swapchain so that GIPA will return vkGetPhysicalDevicePresentRectanglesKHR. Bug: b/71744435 Test: Modified LunarG cube demo that can successfully GIPA the command. Change-Id: Iefb9f82d3f21e110d45f7d6aae7c8c9ea3af20b9 --- vulkan/libvulkan/driver.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index a9d473dcb1..dec39e0b0f 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -407,6 +407,12 @@ VkResult CreateInfoWrapper::SanitizeExtensions() { for (uint32_t i = 0; i < ext_count; i++) FilterExtension(ext_names[i]); + // Enable device extensions that contain physical-device commands, so that + // vkGetInstanceProcAddr will return those physical-device commands. + if (is_instance_) { + hook_extensions_.set(ProcHook::KHR_swapchain); + } + ext_names = extension_filter_.names; ext_count = extension_filter_.name_count; -- cgit v1.2.3-59-g8ed1b From 922b1e377d4247ab40f2c7c0467b3cda60b4fd7c Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 13 Mar 2018 17:12:11 -0700 Subject: libvulkan: correctly expose VK_KHR_shared_presentable_image The current libvulkan still make VK_KHR_shared_presentable_image depends on VK_KHR_get_physical_device_properties2 even with proper VK1.1. This change makes a change in code-generator.tmpl which results in adding vkGetPhysicalDeviceProperties2 into the driver table. Test: dEQP-VK.wsi.android.shared_presentable_image* Bug: b/74605332 Change-Id: I5925dbc438decdc841ed4131c4f3df2a9dd1805a --- vulkan/libvulkan/code-generator.tmpl | 1 + vulkan/libvulkan/driver.cpp | 11 ++++++++--- vulkan/libvulkan/driver_gen.cpp | 1 + vulkan/libvulkan/driver_gen.h | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl index 84644a9ada..1f4df1e59d 100644 --- a/vulkan/libvulkan/code-generator.tmpl +++ b/vulkan/libvulkan/code-generator.tmpl @@ -983,6 +983,7 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkDestroyImage"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true + {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true {{end}} diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index dec39e0b0f..8b8b2809fe 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -801,7 +801,8 @@ bool QueryPresentationProperties( const InstanceData& data = GetData(physicalDevice); // GPDP2 must be present and enabled on the instance. - if (!data.driver.GetPhysicalDeviceProperties2KHR) + if (!data.driver.GetPhysicalDeviceProperties2KHR && + !data.driver.GetPhysicalDeviceProperties2) return false; // Request the android-specific presentation properties via GPDP2 @@ -819,8 +820,12 @@ bool QueryPresentationProperties( presentation_properties->pNext = nullptr; presentation_properties->sharedImage = VK_FALSE; - data.driver.GetPhysicalDeviceProperties2KHR(physicalDevice, - &properties); + if (data.driver.GetPhysicalDeviceProperties2KHR) { + data.driver.GetPhysicalDeviceProperties2KHR(physicalDevice, + &properties); + } else { + data.driver.GetPhysicalDeviceProperties2(physicalDevice, &properties); + } return true; } diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index 51e3abf262..ec98b9fe04 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -494,6 +494,7 @@ bool InitDriverTable(VkInstance instance, INIT_PROC(true, instance, CreateDevice); INIT_PROC(true, instance, EnumerateDeviceExtensionProperties); INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups); + INIT_PROC(false, instance, GetPhysicalDeviceProperties2); INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT); INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT); INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT); diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h index 99dc8898d0..14c3aba75a 100644 --- a/vulkan/libvulkan/driver_gen.h +++ b/vulkan/libvulkan/driver_gen.h @@ -69,6 +69,7 @@ struct InstanceDriverTable { PFN_vkCreateDevice CreateDevice; PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties; PFN_vkEnumeratePhysicalDeviceGroups EnumeratePhysicalDeviceGroups; + PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2; PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallbackEXT; PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallbackEXT; PFN_vkDebugReportMessageEXT DebugReportMessageEXT; -- cgit v1.2.3-59-g8ed1b From bcbc73aa7cf87b45c8243f209c3dfbc8ca83f7b5 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Wed, 18 Jul 2018 10:13:04 -0700 Subject: [vulkan] Modernize codebase by replacing NULL with nullptr Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I75cc812c35076e6121998945e7fdb1ebe2462663 --- vulkan/libvulkan/driver.cpp | 2 +- vulkan/libvulkan/swapchain.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 56bc35ec70..4c2d223127 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -984,7 +984,7 @@ VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, uint32_t icd_api_version; PFN_vkEnumerateInstanceVersion pfn_enumerate_instance_version = reinterpret_cast( - Hal::Device().GetInstanceProcAddr(NULL, + Hal::Device().GetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion")); if (!pfn_enumerate_instance_version) { icd_api_version = VK_API_VERSION_1_0; diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index def1ecac49..915de45961 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -335,15 +335,15 @@ uint32_t get_num_ready_timings(Swapchain& swapchain) { swapchain.surface.window.get(), ti.native_frame_id_, &desired_present_time, &render_complete_time, &composition_latch_time, - NULL, //&first_composition_start_time, - NULL, //&last_composition_start_time, - NULL, //&composition_finish_time, + nullptr, //&first_composition_start_time, + nullptr, //&last_composition_start_time, + nullptr, //&composition_finish_time, // TODO(ianelliott): Maybe ask if this one is // supported, at startup time (since it may not be // supported): &actual_present_time, - NULL, //&dequeue_ready_time, - NULL /*&reads_done_time*/); + nullptr, //&dequeue_ready_time, + nullptr /*&reads_done_time*/); if (ret != android::NO_ERROR) { continue; -- cgit v1.2.3-59-g8ed1b From fdd0c2ad1323babd4eeaa7318d826be1eb90643a Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 30 Jan 2019 20:16:37 -0800 Subject: Vulkan: add atrace support Test: build, flash and take traces Change-Id: Idab6d748519c4f5bc6aac3d51efd26cad28c94ec --- vulkan/libvulkan/api.cpp | 21 +++++++++++++ vulkan/libvulkan/driver.cpp | 45 ++++++++++++++++++++++++++++ vulkan/libvulkan/layers_extensions.cpp | 7 +++++ vulkan/libvulkan/swapchain.cpp | 55 +++++++++++++++++++++++++++++++++- 4 files changed, 127 insertions(+), 1 deletion(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index 673a066182..71048db920 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -21,6 +21,8 @@ // There are a few of them requiring manual code for things such as layer // discovery or chaining. They call into functions defined in this file. +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + #include #include @@ -32,6 +34,7 @@ #include #include #include +#include #include #include @@ -1176,6 +1179,8 @@ bool EnsureInitialized() { VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { + ATRACE_CALL(); + if (!EnsureInitialized()) return VK_ERROR_INITIALIZATION_FAILED; @@ -1184,6 +1189,8 @@ VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, void DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) { + ATRACE_CALL(); + if (instance != VK_NULL_HANDLE) LayerChain::DestroyInstance(instance, pAllocator); } @@ -1192,17 +1199,23 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { + ATRACE_CALL(); + return LayerChain::CreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); } void DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { + ATRACE_CALL(); + if (device != VK_NULL_HANDLE) LayerChain::DestroyDevice(device, pAllocator); } VkResult EnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties) { + ATRACE_CALL(); + if (!EnsureInitialized()) return VK_ERROR_INITIALIZATION_FAILED; @@ -1225,6 +1238,8 @@ VkResult EnumerateInstanceExtensionProperties( const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties) { + ATRACE_CALL(); + if (!EnsureInitialized()) return VK_ERROR_INITIALIZATION_FAILED; @@ -1253,6 +1268,8 @@ VkResult EnumerateInstanceExtensionProperties( VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties) { + ATRACE_CALL(); + uint32_t count; const LayerChain::ActiveLayer* layers = LayerChain::GetActiveLayers(physicalDevice, count); @@ -1275,6 +1292,8 @@ VkResult EnumerateDeviceExtensionProperties( const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties) { + ATRACE_CALL(); + if (pLayerName) { // EnumerateDeviceLayerProperties enumerates active layers for // backward compatibility. The extension query here should work for @@ -1302,6 +1321,8 @@ VkResult EnumerateDeviceExtensionProperties( } VkResult EnumerateInstanceVersion(uint32_t* pApiVersion) { + ATRACE_CALL(); + *pApiVersion = VK_API_VERSION_1_1; return VK_SUCCESS; } diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index a607a5d098..421f7274ff 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + #include #include #include @@ -31,6 +33,7 @@ #include #include #include +#include #include #include "android-base/properties.h" @@ -150,6 +153,8 @@ Hal Hal::hal_; void* LoadLibrary(const android_dlextinfo& dlextinfo, const char* subname, int subname_len) { + ATRACE_CALL(); + const char kLibFormat[] = "vulkan.%*s.so"; char* name = static_cast( alloca(sizeof(kLibFormat) + static_cast(subname_len))); @@ -164,6 +169,8 @@ const std::array HAL_SUBNAME_KEY_PROPERTIES = {{ int LoadDriver(android_namespace_t* library_namespace, const hwvulkan_module_t** module) { + ATRACE_CALL(); + const android_dlextinfo dlextinfo = { .flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = library_namespace, @@ -198,6 +205,8 @@ int LoadDriver(android_namespace_t* library_namespace, } int LoadBuiltinDriver(const hwvulkan_module_t** module) { + ATRACE_CALL(); + auto ns = android_get_exported_namespace("sphal"); if (!ns) return -ENOENT; @@ -205,6 +214,8 @@ int LoadBuiltinDriver(const hwvulkan_module_t** module) { } int LoadUpdatedDriver(const hwvulkan_module_t** module) { + ATRACE_CALL(); + auto ns = android::GraphicsEnv::getInstance().getDriverNamespace(); if (!ns) return -ENOENT; @@ -212,6 +223,8 @@ int LoadUpdatedDriver(const hwvulkan_module_t** module) { } bool Hal::Open() { + ATRACE_CALL(); + ALOG_ASSERT(!hal_.dev_, "OpenHAL called more than once"); // Use a stub device unless we successfully open a real HAL device. @@ -242,9 +255,11 @@ bool Hal::Open() { } hwvulkan_device_t* device; + ATRACE_BEGIN("hwvulkan module open"); result = module->common.methods->open(&module->common, HWVULKAN_DEVICE_0, reinterpret_cast(&device)); + ATRACE_END(); if (result != 0) { // Any device with a Vulkan HAL should be able to open the device. ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result), @@ -260,6 +275,8 @@ bool Hal::Open() { } bool Hal::InitDebugReportIndex() { + ATRACE_CALL(); + uint32_t count; if (dev_->EnumerateInstanceExtensionProperties(nullptr, &count, nullptr) != VK_SUCCESS) { @@ -821,8 +838,10 @@ VkResult EnumerateInstanceExtensionProperties( } } + ATRACE_BEGIN("driver.EnumerateInstanceExtensionProperties"); VkResult result = Hal::Device().EnumerateInstanceExtensionProperties( pLayerName, pPropertyCount, pProperties); + ATRACE_END(); if (!pLayerName && (result == VK_SUCCESS || result == VK_INCOMPLETE)) { int idx = Hal::Get().GetDebugReportIndex(); @@ -931,8 +950,10 @@ VkResult EnumerateDeviceExtensionProperties( *pPropertyCount -= count; } + ATRACE_BEGIN("driver.EnumerateDeviceExtensionProperties"); VkResult result = data.driver.EnumerateDeviceExtensionProperties( physicalDevice, pLayerName, pPropertyCount, pProperties); + ATRACE_END(); if (pProperties) { // map VK_ANDROID_native_buffer to VK_KHR_swapchain @@ -968,12 +989,15 @@ VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, if (result != VK_SUCCESS) return result; + ATRACE_BEGIN("AllocateInstanceData"); InstanceData* data = AllocateInstanceData(data_allocator); + ATRACE_END(); if (!data) return VK_ERROR_OUT_OF_HOST_MEMORY; data->hook_extensions |= wrapper.GetHookExtensions(); + ATRACE_BEGIN("autoDowngradeApiVersion"); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wold-style-cast" uint32_t api_version = ((pCreateInfo->pApplicationInfo) @@ -989,7 +1013,9 @@ VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, if (!pfn_enumerate_instance_version) { icd_api_version = VK_API_VERSION_1_0; } else { + ATRACE_BEGIN("pfn_enumerate_instance_version"); result = (*pfn_enumerate_instance_version)(&icd_api_version); + ATRACE_END(); } uint32_t icd_api_major_version = VK_VERSION_MAJOR(icd_api_version); uint32_t icd_api_minor_version = VK_VERSION_MINOR(icd_api_version); @@ -1000,12 +1026,15 @@ VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo, wrapper.DowngradeApiVersion(); } #pragma clang diagnostic pop + ATRACE_END(); // call into the driver VkInstance instance; + ATRACE_BEGIN("driver.CreateInstance"); result = Hal::Device().CreateInstance( static_cast(wrapper), pAllocator, &instance); + ATRACE_END(); if (result != VK_SUCCESS) { FreeInstanceData(data, data_allocator); return result; @@ -1066,8 +1095,10 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, if (result != VK_SUCCESS) return result; + ATRACE_BEGIN("AllocateDeviceData"); DeviceData* data = AllocateDeviceData(data_allocator, instance_data.debug_report_callbacks); + ATRACE_END(); if (!data) return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -1075,9 +1106,11 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, // call into the driver VkDevice dev; + ATRACE_BEGIN("driver.CreateDevice"); result = instance_data.driver.CreateDevice( physicalDevice, static_cast(wrapper), pAllocator, &dev); + ATRACE_END(); if (result != VK_SUCCESS) { FreeDeviceData(data, data_allocator); return result; @@ -1114,8 +1147,10 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, } VkPhysicalDeviceProperties properties; + ATRACE_BEGIN("driver.GetPhysicalDeviceProperties"); instance_data.driver.GetPhysicalDeviceProperties(physicalDevice, &properties); + ATRACE_END(); data->driver_device = dev; data->driver_version = properties.driverVersion; @@ -1141,6 +1176,8 @@ void DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { VkResult EnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) { + ATRACE_CALL(); + const auto& data = GetData(instance); VkResult result = data.driver.EnumeratePhysicalDevices( @@ -1157,6 +1194,8 @@ VkResult EnumeratePhysicalDeviceGroups( VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) { + ATRACE_CALL(); + VkResult result = VK_SUCCESS; const auto& data = GetData(instance); @@ -1217,6 +1256,8 @@ void GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) { + ATRACE_CALL(); + const auto& data = GetData(device); data.driver.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); @@ -1226,6 +1267,8 @@ void GetDeviceQueue(VkDevice device, void GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) { + ATRACE_CALL(); + const auto& data = GetData(device); data.driver.GetDeviceQueue2(device, pQueueInfo, pQueue); @@ -1236,6 +1279,8 @@ VKAPI_ATTR VkResult AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers) { + ATRACE_CALL(); + const auto& data = GetData(device); VkResult result = data.driver.AllocateCommandBuffers(device, pAllocateInfo, diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index ba4cf00451..af1adcff62 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + #include "layers_extensions.h" #include @@ -33,6 +35,7 @@ #include #include #include +#include #include // TODO(jessehall): The whole way we deal with extensions is pretty hokey, and @@ -428,6 +431,8 @@ void ForEachFileInPath(const std::string& path, Functor functor) { } void DiscoverLayersInPathList(const std::string& pathstr) { + ATRACE_CALL(); + std::vector paths = android::base::Split(pathstr, ":"); for (const auto& path : paths) { ForEachFileInPath(path, [&](const std::string& filename) { @@ -477,6 +482,8 @@ void* GetLayerGetProcAddr(const Layer& layer, } // anonymous namespace void DiscoverLayers() { + ATRACE_CALL(); + if (property_get_bool("ro.debuggable", false) && prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { DiscoverLayersInPathList(kSystemLayerLibraryDir); diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 86013737c6..ea1119ac3c 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + #include #include @@ -21,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -486,6 +489,8 @@ VkResult CreateAndroidSurfaceKHR( const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* allocator, VkSurfaceKHR* out_surface) { + ATRACE_CALL(); + if (!allocator) allocator = &GetData(instance).allocator; void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Surface), @@ -528,6 +533,8 @@ VKAPI_ATTR void DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface_handle, const VkAllocationCallbacks* allocator) { + ATRACE_CALL(); + Surface* surface = SurfaceFromHandle(surface_handle); if (!surface) return; @@ -548,6 +555,8 @@ VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice /*pdev*/, uint32_t /*queue_family*/, VkSurfaceKHR surface_handle, VkBool32* supported) { + ATRACE_CALL(); + const Surface* surface = SurfaceFromHandle(surface_handle); if (!surface) { return VK_ERROR_SURFACE_LOST_KHR; @@ -589,6 +598,8 @@ VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR( VkPhysicalDevice /*pdev*/, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* capabilities) { + ATRACE_CALL(); + int err; ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); @@ -662,6 +673,8 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, VkSurfaceKHR surface_handle, uint32_t* count, VkSurfaceFormatKHR* formats) { + ATRACE_CALL(); + const InstanceData& instance_data = GetData(pdev); // TODO(jessehall): Fill out the set of supported formats. Longer term, add @@ -734,6 +747,8 @@ VkResult GetPhysicalDeviceSurfaceCapabilities2KHR( VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities) { + ATRACE_CALL(); + VkResult result = GetPhysicalDeviceSurfaceCapabilitiesKHR( physicalDevice, pSurfaceInfo->surface, &pSurfaceCapabilities->surfaceCapabilities); @@ -769,6 +784,8 @@ VkResult GetPhysicalDeviceSurfaceFormats2KHR( const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats) { + ATRACE_CALL(); + if (!pSurfaceFormats) { return GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, pSurfaceInfo->surface, @@ -800,6 +817,8 @@ VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count, VkPresentModeKHR* modes) { + ATRACE_CALL(); + int err; int query_value; ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); @@ -851,6 +870,8 @@ VKAPI_ATTR VkResult GetDeviceGroupPresentCapabilitiesKHR( VkDevice, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) { + ATRACE_CALL(); + ALOGV_IF(pDeviceGroupPresentCapabilities->sType != VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR, "vkGetDeviceGroupPresentCapabilitiesKHR: invalid " @@ -873,6 +894,8 @@ VkResult GetDeviceGroupSurfacePresentModesKHR( VkDevice, VkSurfaceKHR, VkDeviceGroupPresentModeFlagsKHR* pModes) { + ATRACE_CALL(); + *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR; return VK_SUCCESS; } @@ -882,6 +905,8 @@ VkResult GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects) { + ATRACE_CALL(); + if (!pRects) { *pRectCount = 1; } else { @@ -923,6 +948,8 @@ VkResult CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* create_info, const VkAllocationCallbacks* allocator, VkSwapchainKHR* swapchain_handle) { + ATRACE_CALL(); + int err; VkResult result = VK_SUCCESS; @@ -1147,9 +1174,11 @@ VkResult CreateSwapchainKHR(VkDevice device, int32_t legacy_usage = 0; if (dispatch.GetSwapchainGrallocUsage2ANDROID) { uint64_t consumer_usage, producer_usage; + ATRACE_BEGIN("dispatch.GetSwapchainGrallocUsage2ANDROID"); result = dispatch.GetSwapchainGrallocUsage2ANDROID( device, create_info->imageFormat, create_info->imageUsage, swapchain_image_usage, &consumer_usage, &producer_usage); + ATRACE_END(); if (result != VK_SUCCESS) { ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result); return VK_ERROR_SURFACE_LOST_KHR; @@ -1157,9 +1186,11 @@ VkResult CreateSwapchainKHR(VkDevice device, legacy_usage = android_convertGralloc1To0Usage(producer_usage, consumer_usage); } else if (dispatch.GetSwapchainGrallocUsageANDROID) { + ATRACE_BEGIN("dispatch.GetSwapchainGrallocUsageANDROID"); result = dispatch.GetSwapchainGrallocUsageANDROID( device, create_info->imageFormat, create_info->imageUsage, &legacy_usage); + ATRACE_END(); if (result != VK_SUCCESS) { ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result); return VK_ERROR_SURFACE_LOST_KHR; @@ -1254,8 +1285,10 @@ VkResult CreateSwapchainKHR(VkDevice device, &image_native_buffer.usage2.producer, &image_native_buffer.usage2.consumer); + ATRACE_BEGIN("dispatch.CreateImage"); result = dispatch.CreateImage(device, &image_create, nullptr, &img.image); + ATRACE_END(); if (result != VK_SUCCESS) { ALOGD("vkCreateImage w/ native buffer failed: %u", result); break; @@ -1279,8 +1312,11 @@ VkResult CreateSwapchainKHR(VkDevice device, } } if (result != VK_SUCCESS) { - if (img.image) + if (img.image) { + ATRACE_BEGIN("dispatch.DestroyImage"); dispatch.DestroyImage(device, img.image, nullptr); + ATRACE_END(); + } } } @@ -1299,6 +1335,8 @@ VKAPI_ATTR void DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain_handle, const VkAllocationCallbacks* allocator) { + ATRACE_CALL(); + const auto& dispatch = GetData(device).driver; Swapchain* swapchain = SwapchainFromHandle(swapchain_handle); if (!swapchain) @@ -1324,6 +1362,8 @@ VkResult GetSwapchainImagesKHR(VkDevice, VkSwapchainKHR swapchain_handle, uint32_t* count, VkImage* images) { + ATRACE_CALL(); + Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); ALOGW_IF(swapchain.surface.swapchain_handle != swapchain_handle, "getting images for non-active swapchain 0x%" PRIx64 @@ -1352,6 +1392,8 @@ VkResult AcquireNextImageKHR(VkDevice device, VkSemaphore semaphore, VkFence vk_fence, uint32_t* image_index) { + ATRACE_CALL(); + Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); ANativeWindow* window = swapchain.surface.window.get(); VkResult result; @@ -1432,6 +1474,8 @@ VKAPI_ATTR VkResult AcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex) { + ATRACE_CALL(); + // TODO: this should actually be the other way around and this function // should handle any additional structures that get passed in return AcquireNextImageKHR(device, pAcquireInfo->swapchain, @@ -1461,6 +1505,8 @@ static VkResult WorstPresentResult(VkResult a, VkResult b) { VKAPI_ATTR VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info) { + ATRACE_CALL(); + ALOGV_IF(present_info->sType != VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, "vkQueuePresentKHR: invalid VkPresentInfoKHR structure type %d", present_info->sType); @@ -1672,6 +1718,8 @@ VkResult GetRefreshCycleDurationGOOGLE( VkDevice, VkSwapchainKHR swapchain_handle, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) { + ATRACE_CALL(); + Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); VkResult result = VK_SUCCESS; @@ -1687,6 +1735,8 @@ VkResult GetPastPresentationTimingGOOGLE( VkSwapchainKHR swapchain_handle, uint32_t* count, VkPastPresentationTimingGOOGLE* timings) { + ATRACE_CALL(); + Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); ANativeWindow* window = swapchain.surface.window.get(); VkResult result = VK_SUCCESS; @@ -1711,6 +1761,8 @@ VKAPI_ATTR VkResult GetSwapchainStatusKHR( VkDevice, VkSwapchainKHR swapchain_handle) { + ATRACE_CALL(); + Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle); VkResult result = VK_SUCCESS; @@ -1728,6 +1780,7 @@ VKAPI_ATTR void SetHdrMetadataEXT( uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pHdrMetadataEXTs) { + ATRACE_CALL(); for (uint32_t idx = 0; idx < swapchainCount; idx++) { Swapchain* swapchain = SwapchainFromHandle(pSwapchains[idx]); -- cgit v1.2.3-59-g8ed1b From cb9d4e403492412f83be15df7e279fb6a8d9bb17 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 6 Feb 2019 20:22:59 -0800 Subject: Game Driver: make GpuService the GpuStats holder Move IGpuService to graphicsenv to avoid dependency circle. Add ATRACE to GraphicsEnv. Implement the prototype SET_GPU_STATS IPC to collect GpuStats from applications. Bug: 123529932 Test: Build, flash and boot. Change-Id: I7d76324c5adb6ad00f1e5420ab2c7f4067f33253 --- libs/graphicsenv/Android.bp | 3 + libs/graphicsenv/GraphicsEnv.cpp | 47 +++++++++-- libs/graphicsenv/IGpuService.cpp | 96 ++++++++++++++++++++++ libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 1 + libs/graphicsenv/include/graphicsenv/IGpuService.h | 54 ++++++++++++ opengl/libs/EGL/Loader.cpp | 2 + services/gpuservice/Android.bp | 3 + services/gpuservice/GpuService.cpp | 59 ++++++------- services/gpuservice/GpuService.h | 35 +++----- vulkan/libvulkan/driver.cpp | 2 + 10 files changed, 239 insertions(+), 63 deletions(-) create mode 100644 libs/graphicsenv/IGpuService.cpp create mode 100644 libs/graphicsenv/include/graphicsenv/IGpuService.h (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/libs/graphicsenv/Android.bp b/libs/graphicsenv/Android.bp index 280c14a3ea..d940752396 100644 --- a/libs/graphicsenv/Android.bp +++ b/libs/graphicsenv/Android.bp @@ -17,14 +17,17 @@ cc_library_shared { srcs: [ "GraphicsEnv.cpp", + "IGpuService.cpp" ], cflags: ["-Wall", "-Werror"], shared_libs: [ "libbase", + "libbinder", "libcutils", "liblog", + "libutils", ], export_include_dirs: ["include"], diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 337308b813..c20d54b7f2 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -14,8 +14,11 @@ * limitations under the License. */ +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + //#define LOG_NDEBUG 1 #define LOG_TAG "GraphicsEnv" + #include #include @@ -25,15 +28,16 @@ #include #include #include +#include #include +#include #include #include +#include #include #include -#include - // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); @@ -155,9 +159,16 @@ void GraphicsEnv::setDriverPath(const std::string path) { void GraphicsEnv::setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) { - ALOGV("setGpuStats: drvPkgName[%s], drvVerName[%s], drvVerCode[%lld], appPkgName[%s]", - driverPackageName.c_str(), driverVersionName.c_str(), (long long)driverVersionCode, - appPackageName.c_str()); + ATRACE_CALL(); + + ALOGV("setGpuStats:\n" + "\tdriverPackageName[%s]\n" + "\tdriverVersionName[%s]\n" + "\tdriverVersionCode[%llu]\n" + "\tappPackageName[%s]\n", + driverPackageName.c_str(), driverVersionName.c_str(), + (unsigned long long)driverVersionCode, appPackageName.c_str()); + mGpuStats = { .driverPackageName = driverPackageName, .driverVersionName = driverVersionName, @@ -166,6 +177,32 @@ void GraphicsEnv::setGpuStats(const std::string driverPackageName, }; } +void GraphicsEnv::sendGpuStats() { + ATRACE_CALL(); + + // Do not sendGpuStats for those skipping the GraphicsEnvironment setup + if (mGpuStats.appPackageName.empty()) return; + + ALOGV("sendGpuStats:\n" + "\tdriverPackageName[%s]\n" + "\tdriverVersionName[%s]\n" + "\tdriverVersionCode[%llu]\n" + "\tappPackageName[%s]\n", + mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(), + (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str()); + + const sp binder = defaultServiceManager()->checkService(String16("gpu")); + if (!binder) { + ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str()); + return; + } + + interface_cast(binder)->setGpuStats(mGpuStats.driverPackageName, + mGpuStats.driverVersionName, + mGpuStats.driverVersionCode, + mGpuStats.appPackageName); +} + void* GraphicsEnv::loadLibrary(std::string name) { const android_dlextinfo dlextinfo = { .flags = ANDROID_DLEXT_USE_NAMESPACE, diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp new file mode 100644 index 0000000000..98a63952c7 --- /dev/null +++ b/libs/graphicsenv/IGpuService.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GpuService" + +#include + +#include +#include + +namespace android { + +class BpGpuService : public BpInterface { +public: + explicit BpGpuService(const sp& impl) : BpInterface(impl) {} + + virtual void setGpuStats(const std::string driverPackageName, + const std::string driverVersionName, const uint64_t driverVersionCode, + const std::string appPackageName) { + Parcel data, reply; + data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); + + data.writeUtf8AsUtf16(driverPackageName); + data.writeUtf8AsUtf16(driverVersionName); + data.writeUint64(driverVersionCode); + data.writeUtf8AsUtf16(appPackageName); + + remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply); + } +}; + +IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); + +status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags) { + ALOGV("onTransact code[0x%X]", code); + + status_t status; + switch (code) { + case SET_GPU_STATS: { + CHECK_INTERFACE(IGpuService, data, reply); + + std::string driverPackageName; + if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; + + std::string driverVersionName; + if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; + + uint64_t driverVersionCode; + if ((status = data.readUint64(&driverVersionCode)) != OK) return status; + + std::string appPackageName; + if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; + + setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName); + + return OK; + } + case SHELL_COMMAND_TRANSACTION: { + int in = data.readFileDescriptor(); + int out = data.readFileDescriptor(); + int err = data.readFileDescriptor(); + + std::vector args; + data.readString16Vector(&args); + + sp unusedCallback; + if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; + + sp resultReceiver; + if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; + + status = shellCommand(in, out, err, args); + if (resultReceiver != nullptr) resultReceiver->send(status); + + return OK; + } + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + +} // namespace android diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index a247bec4fb..d4edfa0e7d 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -49,6 +49,7 @@ public: android_namespace_t* getDriverNamespace(); void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t versionCode, const std::string appPackageName); + void sendGpuStats(); bool shouldUseAngle(std::string appName); bool shouldUseAngle(); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h new file mode 100644 index 0000000000..c080c53f98 --- /dev/null +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -0,0 +1,54 @@ +/* + * Copyright 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include + +namespace android { + +/* + * This class defines the Binder IPC interface for GPU-related queries and + * control. + */ +class IGpuService : public IInterface { +public: + DECLARE_META_INTERFACE(GpuService); + + // set GPU stats from GraphicsEnvironment. + virtual void setGpuStats(const std::string driverPackageName, + const std::string driverVersionName, const uint64_t driverVersionCode, + const std::string appPackageName) = 0; +}; + +class BnGpuService : public BnInterface { +public: + enum IGpuServiceTag { + SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, + // Always append new enum to the end. + }; + + status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags = 0) override; + +protected: + virtual status_t shellCommand(int in, int out, int err, std::vector& args) = 0; +}; + +} // namespace android diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 8a409aeb36..4cafe2b819 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -255,6 +255,8 @@ void* Loader::open(egl_connection_t* cnx) LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1, "couldn't load system OpenGL ES wrapper libraries"); + android::GraphicsEnv::getInstance().sendGpuStats(); + return (void*)hnd; } diff --git a/services/gpuservice/Android.bp b/services/gpuservice/Android.bp index 47bed65a2b..e21d8e779d 100644 --- a/services/gpuservice/Android.bp +++ b/services/gpuservice/Android.bp @@ -30,6 +30,8 @@ cc_defaults { ], shared_libs: [ "libbinder", + "libcutils", + "libgraphicsenv", "liblog", "libutils", "libvulkan", @@ -59,6 +61,7 @@ cc_defaults { ], shared_libs: [ "libbinder", + "libcutils", "liblog", "libutils", ], diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index 150896cf91..9906dea31c 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -14,48 +14,19 @@ * limitations under the License. */ +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + #include "GpuService.h" #include #include #include +#include + #include namespace android { -class BpGpuService : public BpInterface { -public: - explicit BpGpuService(const sp& impl) : BpInterface(impl) {} -}; - -IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService"); - -status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, - Parcel* reply, uint32_t flags) { - status_t status; - switch (code) { - case SHELL_COMMAND_TRANSACTION: { - int in = data.readFileDescriptor(); - int out = data.readFileDescriptor(); - int err = data.readFileDescriptor(); - std::vector args; - data.readString16Vector(&args); - sp unusedCallback; - sp resultReceiver; - if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) - return status; - if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) - return status; - status = shellCommand(in, out, err, args); - if (resultReceiver != nullptr) - resultReceiver->send(status); - return OK; - } - - default: - return BBinder::onTransact(code, data, reply, flags); - } -} namespace { status_t cmd_help(int out); @@ -66,9 +37,25 @@ const char* const GpuService::SERVICE_NAME = "gpu"; GpuService::GpuService() = default; -status_t GpuService::shellCommand(int /*in*/, int out, int err, - std::vector& args) { - ALOGV("GpuService::shellCommand"); +void GpuService::setGpuStats(const std::string driverPackageName, + const std::string driverVersionName, const uint64_t driverVersionCode, + const std::string appPackageName) { + ATRACE_CALL(); + + std::lock_guard lock(mStateLock); + ALOGV("Received:\n" + "\tdriverPackageName[%s]\n" + "\tdriverVersionName[%s]\n" + "\tdriverVersionCode[%llu]\n" + "\tappPackageName[%s]\n", + driverPackageName.c_str(), driverVersionName.c_str(), + (unsigned long long)driverVersionCode, appPackageName.c_str()); +} + +status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector& args) { + ATRACE_CALL(); + + ALOGV("shellCommand"); for (size_t i = 0, n = args.size(); i < n; i++) ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string()); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index e2b396ec7b..edfd364bdd 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -17,30 +17,14 @@ #ifndef ANDROID_GPUSERVICE_H #define ANDROID_GPUSERVICE_H -#include - #include #include +#include -namespace android { - -/* - * This class defines the Binder IPC interface for GPU-related queries and - * control. - */ -class IGpuService : public IInterface { -public: - DECLARE_META_INTERFACE(GpuService); -}; - -class BnGpuService: public BnInterface { -protected: - virtual status_t shellCommand(int in, int out, int err, - std::vector& args) = 0; +#include +#include - status_t onTransact(uint32_t code, const Parcel& data, - Parcel* reply, uint32_t flags = 0) override; -}; +namespace android { class GpuService : public BnGpuService { public: @@ -49,8 +33,15 @@ public: GpuService() ANDROID_API; protected: - status_t shellCommand(int in, int out, int err, - std::vector& args) override; + status_t shellCommand(int in, int out, int err, std::vector& args) override; + +private: + // IGpuService interface + void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, + const uint64_t driverVersionCode, const std::string appPackageName); + + // GpuStats access must be protected by mStateLock + std::mutex mStateLock; }; } // namespace android diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 421f7274ff..3a8e34eff2 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -254,6 +254,8 @@ bool Hal::Open() { return true; } + android::GraphicsEnv::getInstance().sendGpuStats(); + hwvulkan_device_t* device; ATRACE_BEGIN("hwvulkan module open"); result = -- cgit v1.2.3-59-g8ed1b From d986181df8ff886301adaf20404f886c730ba2c7 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 13 Feb 2019 11:51:55 -0800 Subject: Game Driver: plumb driver choice and loading time to GpuStats This change plumb the below info from GL and Vulkan loader: 1. Intended driver to use 2. Whether intended driver is loaded 3. Total driver loading time Bug: 123529932 Test: Build, flash and boot. Verify the GpuService receiver side. Change-Id: I967d4361bf0e04c02390c7555617575c19ecadd4 --- libs/graphicsenv/GraphicsEnv.cpp | 117 +++++++++++++++++---- libs/graphicsenv/IGpuService.cpp | 21 +++- libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 38 ++++++- libs/graphicsenv/include/graphicsenv/IGpuService.h | 8 +- opengl/libs/EGL/Loader.cpp | 21 +++- services/gpuservice/GpuService.cpp | 13 ++- services/gpuservice/GpuService.h | 3 +- vulkan/libvulkan/driver.cpp | 15 ++- 8 files changed, 200 insertions(+), 36 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 75fe2d31df..a07627a657 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -157,10 +157,11 @@ void GraphicsEnv::setDriverPath(const std::string path) { } void GraphicsEnv::setGpuStats(const std::string& driverPackageName, - const std::string& driverVersionName, - const uint64_t driverVersionCode, const std::string& appPackageName) { + const std::string& driverVersionName, uint64_t driverVersionCode, + const std::string& appPackageName) { ATRACE_CALL(); + std::lock_guard lock(mStatsLock); ALOGV("setGpuStats:\n" "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" @@ -169,15 +170,89 @@ void GraphicsEnv::setGpuStats(const std::string& driverPackageName, driverPackageName.c_str(), driverVersionName.c_str(), (unsigned long long)driverVersionCode, appPackageName.c_str()); - mGpuStats = { - .driverPackageName = driverPackageName, - .driverVersionName = driverVersionName, - .driverVersionCode = driverVersionCode, - .appPackageName = appPackageName, - }; + mGpuStats.driverPackageName = driverPackageName; + mGpuStats.driverVersionName = driverVersionName; + mGpuStats.driverVersionCode = driverVersionCode; + mGpuStats.appPackageName = appPackageName; +} + +void GraphicsEnv::setDriverToLoad(GraphicsEnv::Driver driver) { + ATRACE_CALL(); + + std::lock_guard lock(mStatsLock); + switch (driver) { + case GraphicsEnv::Driver::GL: + case GraphicsEnv::Driver::GL_UPDATED: + case GraphicsEnv::Driver::ANGLE: { + if (mGpuStats.glDriverToLoad == GraphicsEnv::Driver::NONE) { + mGpuStats.glDriverToLoad = driver; + break; + } + + if (mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) { + mGpuStats.glDriverFallback = driver; + } + break; + } + case Driver::VULKAN: + case Driver::VULKAN_UPDATED: { + if (mGpuStats.vkDriverToLoad == GraphicsEnv::Driver::NONE) { + mGpuStats.vkDriverToLoad = driver; + break; + } + + if (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE) { + mGpuStats.vkDriverFallback = driver; + } + break; + } + default: + break; + } +} + +void GraphicsEnv::setDriverLoaded(GraphicsEnv::Api api, bool isLoaded, int64_t driverLoadingTime) { + ATRACE_CALL(); + + std::lock_guard lock(mStatsLock); + GraphicsEnv::Driver driver = GraphicsEnv::Driver::NONE; + bool isIntendedDriverLoaded = false; + if (api == GraphicsEnv::Api::API_GL) { + driver = mGpuStats.glDriverToLoad; + isIntendedDriverLoaded = isLoaded && + ((mGpuStats.glDriverFallback == GraphicsEnv::Driver::NONE) || + (mGpuStats.glDriverToLoad == mGpuStats.glDriverFallback)); + } else { + driver = mGpuStats.vkDriverToLoad; + isIntendedDriverLoaded = + isLoaded && (mGpuStats.vkDriverFallback == GraphicsEnv::Driver::NONE); + } + + sendGpuStatsLocked(driver, isIntendedDriverLoaded, driverLoadingTime); } -void GraphicsEnv::sendGpuStats() { +void GraphicsEnv::clearDriverLoadingInfo(GraphicsEnv::Api api) { + ATRACE_CALL(); + + std::lock_guard lock(mStatsLock); + if (api == GraphicsEnv::Api::API_GL) { + mGpuStats.glDriverToLoad = GraphicsEnv::Driver::NONE; + mGpuStats.glDriverFallback = GraphicsEnv::Driver::NONE; + } +} + +static sp getGpuService() { + const sp binder = defaultServiceManager()->checkService(String16("gpu")); + if (!binder) { + ALOGE("Failed to get gpu service"); + return nullptr; + } + + return interface_cast(binder); +} + +void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Driver driver, bool isDriverLoaded, + int64_t driverLoadingTime) { ATRACE_CALL(); // Do not sendGpuStats for those skipping the GraphicsEnvironment setup @@ -187,20 +262,20 @@ void GraphicsEnv::sendGpuStats() { "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" - "\tappPackageName[%s]\n", + "\tappPackageName[%s]\n" + "\tdriver[%d]\n" + "\tisDriverLoaded[%d]\n" + "\tdriverLoadingTime[%lld]", mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(), - (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str()); - - const sp binder = defaultServiceManager()->checkService(String16("gpu")); - if (!binder) { - ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str()); - return; + (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str(), + static_cast(driver), isDriverLoaded, (long long)driverLoadingTime); + + const sp gpuService = getGpuService(); + if (gpuService) { + gpuService->setGpuStats(mGpuStats.driverPackageName, mGpuStats.driverVersionName, + mGpuStats.driverVersionCode, mGpuStats.appPackageName, driver, + isDriverLoaded, driverLoadingTime); } - - interface_cast(binder)->setGpuStats(mGpuStats.driverPackageName, - mGpuStats.driverVersionName, - mGpuStats.driverVersionCode, - mGpuStats.appPackageName); } void* GraphicsEnv::loadLibrary(std::string name) { diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 762a27b799..2a57caf739 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -28,8 +28,9 @@ public: explicit BpGpuService(const sp& impl) : BpInterface(impl) {} virtual void setGpuStats(const std::string& driverPackageName, - const std::string& driverVersionName, const uint64_t driverVersionCode, - const std::string& appPackageName) { + const std::string& driverVersionName, uint64_t driverVersionCode, + const std::string& appPackageName, GraphicsEnv::Driver driver, + bool isDriverLoaded, int64_t driverLoadingTime) { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); @@ -37,6 +38,9 @@ public: data.writeUtf8AsUtf16(driverVersionName); data.writeUint64(driverVersionCode); data.writeUtf8AsUtf16(appPackageName); + data.writeInt32(static_cast(driver)); + data.writeBool(isDriverLoaded); + data.writeInt64(driverLoadingTime); remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply); } @@ -65,7 +69,18 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep std::string appPackageName; if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; - setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName); + int32_t driver; + if ((status = data.readInt32(&driver)) != OK) return status; + + bool isDriverLoaded; + if ((status = data.readBool(&isDriverLoaded)) != OK) return status; + + int64_t driverLoadingTime; + if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; + + setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName, + static_cast(driver), isDriverLoaded, + driverLoadingTime); return OK; } diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index c4482b7b63..d88a5c1f76 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -28,11 +28,41 @@ namespace android { struct NativeLoaderNamespace; class GraphicsEnv { +public: + enum Api { + API_GL = 0, + API_VK = 1, + }; + + enum Driver { + NONE = 0, + GL = 1, + GL_UPDATED = 2, + VULKAN = 3, + VULKAN_UPDATED = 4, + ANGLE = 5, + }; + +private: struct GpuStats { std::string driverPackageName; std::string driverVersionName; uint64_t driverVersionCode; std::string appPackageName; + Driver glDriverToLoad; + Driver glDriverFallback; + Driver vkDriverToLoad; + Driver vkDriverFallback; + + GpuStats() + : driverPackageName(""), + driverVersionName(""), + driverVersionCode(0), + appPackageName(""), + glDriverToLoad(Driver::NONE), + glDriverFallback(Driver::NONE), + vkDriverToLoad(Driver::NONE), + vkDriverFallback(Driver::NONE) {} }; public: @@ -48,8 +78,11 @@ public: void setDriverPath(const std::string path); android_namespace_t* getDriverNamespace(); void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, - const uint64_t versionCode, const std::string& appPackageName); - void sendGpuStats(); + uint64_t versionCode, const std::string& appPackageName); + void setDriverToLoad(Driver driver); + void setDriverLoaded(Api api, bool isDriverLoaded, int64_t driverLoadingTime); + void clearDriverLoadingInfo(Api api); + void sendGpuStatsLocked(Driver driver, bool isDriverLoaded, int64_t driverLoadingTime); bool shouldUseAngle(std::string appName); bool shouldUseAngle(); @@ -82,6 +115,7 @@ private: GraphicsEnv() = default; std::string mDriverPath; + std::mutex mStatsLock; GpuStats mGpuStats; std::string mAnglePath; std::string mAngleAppName; diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index 1e74d607d1..bfde76fe26 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -18,6 +18,7 @@ #include #include +#include #include @@ -29,12 +30,13 @@ namespace android { */ class IGpuService : public IInterface { public: - DECLARE_META_INTERFACE(GpuService); + DECLARE_META_INTERFACE(GpuService) // set GPU stats from GraphicsEnvironment. virtual void setGpuStats(const std::string& driverPackageName, - const std::string& driverVersionName, const uint64_t driverVersionCode, - const std::string& appPackageName) = 0; + const std::string& driverVersionName, uint64_t driverVersionCode, + const std::string& appPackageName, GraphicsEnv::Driver driver, + bool isDriverLoaded, int64_t driverLoadingTime) = 0; }; class BnGpuService : public BnInterface { diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 4cafe2b819..259242b459 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifndef __ANDROID_VNDK__ #include @@ -217,6 +218,7 @@ static void setEmulatorGlesValue(void) { void* Loader::open(egl_connection_t* cnx) { ATRACE_CALL(); + const nsecs_t openTime = systemTime(); void* dso; driver_t* hnd = nullptr; @@ -234,6 +236,8 @@ void* Loader::open(egl_connection_t* cnx) if (dso) { hnd = new driver_t(dso); } else { + android::GraphicsEnv::getInstance().clearDriverLoadingInfo( + android::GraphicsEnv::Api::API_GL); // Always load EGL first dso = load_driver("EGL", cnx, EGL); if (dso) { @@ -243,19 +247,30 @@ void* Loader::open(egl_connection_t* cnx) } } + if (!hnd) { + android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL, + false, systemTime() - openTime); + } + LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation"); cnx->libEgl = load_wrapper(EGL_WRAPPER_DIR "/libEGL.so"); cnx->libGles2 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv2.so"); cnx->libGles1 = load_wrapper(EGL_WRAPPER_DIR "/libGLESv1_CM.so"); + if (!cnx->libEgl || !cnx->libGles2 || !cnx->libGles1) { + android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL, + false, systemTime() - openTime); + } + LOG_ALWAYS_FATAL_IF(!cnx->libEgl, "couldn't load system EGL wrapper libraries"); LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1, "couldn't load system OpenGL ES wrapper libraries"); - android::GraphicsEnv::getInstance().sendGpuStats(); + android::GraphicsEnv::getInstance().setDriverLoaded(android::GraphicsEnv::Api::API_GL, true, + systemTime() - openTime); return (void*)hnd; } @@ -591,17 +606,21 @@ void *Loader::load_driver(const char* kind, void* dso = nullptr; android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace(); if (ns) { + android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::ANGLE); dso = load_angle(kind, ns, cnx); } #ifndef __ANDROID_VNDK__ if (!dso) { android_namespace_t* ns = android::GraphicsEnv::getInstance().getDriverNamespace(); if (ns) { + android::GraphicsEnv::getInstance().setDriverToLoad( + android::GraphicsEnv::Driver::GL_UPDATED); dso = load_updated_driver(kind, ns); } } #endif if (!dso) { + android::GraphicsEnv::getInstance().setDriverToLoad(android::GraphicsEnv::Driver::GL); dso = load_system_driver(kind); if (!dso) return nullptr; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index 68c185c119..8a9778a081 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -38,8 +38,9 @@ const char* const GpuService::SERVICE_NAME = "gpu"; GpuService::GpuService() = default; void GpuService::setGpuStats(const std::string& driverPackageName, - const std::string& driverVersionName, const uint64_t driverVersionCode, - const std::string& appPackageName) { + const std::string& driverVersionName, uint64_t driverVersionCode, + const std::string& appPackageName, GraphicsEnv::Driver driver, + bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); std::lock_guard lock(mStateLock); @@ -47,9 +48,13 @@ void GpuService::setGpuStats(const std::string& driverPackageName, "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" - "\tappPackageName[%s]\n", + "\tappPackageName[%s]\n" + "\tdriver[%d]\n" + "\tisDriverLoaded[%d]\n" + "\tdriverLoadingTime[%lld]", driverPackageName.c_str(), driverVersionName.c_str(), - (unsigned long long)driverVersionCode, appPackageName.c_str()); + (unsigned long long)driverVersionCode, appPackageName.c_str(), + static_cast(driver), isDriverLoaded, (long long)driverLoadingTime); } status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector& args) { diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index 5304fa1279..27565572f6 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -38,7 +38,8 @@ protected: private: // IGpuService interface void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, - const uint64_t driverVersionCode, const std::string& appPackageName); + uint64_t driverVersionCode, const std::string& appPackageName, + GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime); // GpuStats access must be protected by mStateLock std::mutex mStateLock; diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 3a8e34eff2..b3259de6ea 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -210,6 +211,8 @@ int LoadBuiltinDriver(const hwvulkan_module_t** module) { auto ns = android_get_exported_namespace("sphal"); if (!ns) return -ENOENT; + android::GraphicsEnv::getInstance().setDriverToLoad( + android::GraphicsEnv::Driver::VULKAN); return LoadDriver(ns, module); } @@ -219,12 +222,16 @@ int LoadUpdatedDriver(const hwvulkan_module_t** module) { auto ns = android::GraphicsEnv::getInstance().getDriverNamespace(); if (!ns) return -ENOENT; + android::GraphicsEnv::getInstance().setDriverToLoad( + android::GraphicsEnv::Driver::VULKAN_UPDATED); return LoadDriver(ns, module); } bool Hal::Open() { ATRACE_CALL(); + const nsecs_t openTime = systemTime(); + ALOG_ASSERT(!hal_.dev_, "OpenHAL called more than once"); // Use a stub device unless we successfully open a real HAL device. @@ -250,11 +257,12 @@ bool Hal::Open() { } } if (result != 0) { + android::GraphicsEnv::getInstance().setDriverLoaded( + android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime); ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result); return true; } - android::GraphicsEnv::getInstance().sendGpuStats(); hwvulkan_device_t* device; ATRACE_BEGIN("hwvulkan module open"); @@ -263,6 +271,8 @@ bool Hal::Open() { reinterpret_cast(&device)); ATRACE_END(); if (result != 0) { + android::GraphicsEnv::getInstance().setDriverLoaded( + android::GraphicsEnv::Api::API_VK, false, systemTime() - openTime); // Any device with a Vulkan HAL should be able to open the device. ALOGE("failed to open Vulkan HAL device: %s (%d)", strerror(-result), result); @@ -273,6 +283,9 @@ bool Hal::Open() { hal_.InitDebugReportIndex(); + android::GraphicsEnv::getInstance().setDriverLoaded( + android::GraphicsEnv::Api::API_VK, true, systemTime() - openTime); + return true; } -- cgit v1.2.3-59-g8ed1b From 231431083918751a0faefca8d9c081a58964d420 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 10 Apr 2019 18:24:05 -0700 Subject: libvulkan: intercept vkBindImageMemory2(KHR) at driver level This change just updates the code generator template to add the interception of vkBindImageMemory2 and vkBindImageMemory2KHR at vulkan::driver level. Bug: 130182551 Test: CtsDeqpTestCases Change-Id: I2083d7048bba93bea80c010ba89dbc5f8ab6de0c --- vulkan/libvulkan/code-generator.tmpl | 8 ++++++++ vulkan/libvulkan/driver.cpp | 2 ++ vulkan/libvulkan/driver_gen.cpp | 26 ++++++++++++++++++++++++++ vulkan/libvulkan/driver_gen.h | 3 +++ vulkan/libvulkan/swapchain.cpp | 20 ++++++++++++++++++++ vulkan/libvulkan/swapchain.h | 2 ++ 6 files changed, 61 insertions(+) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl index f04eb03eac..bdd3573b11 100644 --- a/vulkan/libvulkan/code-generator.tmpl +++ b/vulkan/libvulkan/code-generator.tmpl @@ -703,6 +703,7 @@ VK_KHR_get_surface_capabilities2 {{Macro "driver.InterceptedExtensions"}} VK_KHR_get_physical_device_properties2 VK_ANDROID_external_memory_android_hardware_buffer +VK_KHR_bind_memory2 {{end}} @@ -750,6 +751,9 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetInstanceProcAddr"}}true {{else if eq $.Name "vkGetDeviceProcAddr"}}true + {{/* VK_KHR_swapchain v69 requirement */}} + {{else if eq $.Name "vkBindImageMemory2"}}true + {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{$ext := GetAnnotation $ "extension"}} @@ -985,6 +989,10 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true + + {{/* VK_KHR_swapchain v69 requirement */}} + {{else if eq $.Name "vkBindImageMemory2"}}true + {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{$ext := GetAnnotation $ "extension"}} diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index b3259de6ea..491d4d1343 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -537,6 +537,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // Extensions we don't need to do anything about at this level break; + case ProcHook::KHR_bind_memory2: case ProcHook::KHR_incremental_present: case ProcHook::KHR_shared_presentable_image: case ProcHook::KHR_swapchain: @@ -577,6 +578,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // return now as these extensions do not require HAL support return; case ProcHook::EXT_hdr_metadata: + case ProcHook::KHR_bind_memory2: hook_extensions_.set(ext_bit); break; case ProcHook::ANDROID_external_memory_android_hardware_buffer: diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index ec98b9fe04..574c3273d0 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -137,6 +137,15 @@ VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR } } +VKAPI_ATTR VkResult checkedBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfoKHR* pBindInfos) { + if (GetData(device).hook_extensions[ProcHook::KHR_bind_memory2]) { + return BindImageMemory2KHR(device, bindInfoCount, pBindInfos); + } else { + Logger(device).Err(device, "VK_KHR_bind_memory2 not enabled. vkBindImageMemory2KHR not executed."); + return VK_SUCCESS; + } +} + // clang-format on const ProcHook g_proc_hooks[] = { @@ -169,6 +178,20 @@ const ProcHook g_proc_hooks[] = { reinterpret_cast(AllocateCommandBuffers), nullptr, }, + { + "vkBindImageMemory2", + ProcHook::DEVICE, + ProcHook::EXTENSION_CORE, + reinterpret_cast(BindImageMemory2), + nullptr, + }, + { + "vkBindImageMemory2KHR", + ProcHook::DEVICE, + ProcHook::KHR_bind_memory2, + reinterpret_cast(BindImageMemory2KHR), + reinterpret_cast(checkedBindImageMemory2KHR), + }, { "vkCreateAndroidSurfaceKHR", ProcHook::INSTANCE, @@ -458,6 +481,7 @@ ProcHook::Extension GetProcHookExtension(const char* name) { if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; + if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2; // clang-format on return ProcHook::EXTENSION_UNKNOWN; } @@ -517,11 +541,13 @@ bool InitDriverTable(VkDevice dev, INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, AllocateCommandBuffers); + INIT_PROC(false, dev, BindImageMemory2); INIT_PROC(false, dev, GetDeviceQueue2); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); + INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR); // clang-format on return success; diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h index 14c3aba75a..3faf6c0e32 100644 --- a/vulkan/libvulkan/driver_gen.h +++ b/vulkan/libvulkan/driver_gen.h @@ -46,6 +46,7 @@ struct ProcHook { KHR_get_surface_capabilities2, KHR_get_physical_device_properties2, ANDROID_external_memory_android_hardware_buffer, + KHR_bind_memory2, EXTENSION_CORE, // valid bit EXTENSION_COUNT, @@ -85,11 +86,13 @@ struct DeviceDriverTable { PFN_vkCreateImage CreateImage; PFN_vkDestroyImage DestroyImage; PFN_vkAllocateCommandBuffers AllocateCommandBuffers; + PFN_vkBindImageMemory2 BindImageMemory2; PFN_vkGetDeviceQueue2 GetDeviceQueue2; PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; PFN_vkGetSwapchainGrallocUsage2ANDROID GetSwapchainGrallocUsage2ANDROID; PFN_vkAcquireImageANDROID AcquireImageANDROID; PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; + PFN_vkBindImageMemory2KHR BindImageMemory2KHR; // clang-format on }; diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 73fc7b2467..611bb002cb 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -1818,5 +1818,25 @@ VKAPI_ATTR void SetHdrMetadataEXT( return; } +VKAPI_ATTR +VkResult BindImageMemory2(VkDevice device, + uint32_t bindInfoCount, + const VkBindImageMemoryInfo* pBindInfos) { + ATRACE_CALL(); + + return GetData(device).driver.BindImageMemory2(device, bindInfoCount, + pBindInfos); +} + +VKAPI_ATTR +VkResult BindImageMemory2KHR(VkDevice device, + uint32_t bindInfoCount, + const VkBindImageMemoryInfo* pBindInfos) { + ATRACE_CALL(); + + return GetData(device).driver.BindImageMemory2KHR(device, bindInfoCount, + pBindInfos); +} + } // namespace driver } // namespace vulkan diff --git a/vulkan/libvulkan/swapchain.h b/vulkan/libvulkan/swapchain.h index ed5718c75f..4912ef1a33 100644 --- a/vulkan/libvulkan/swapchain.h +++ b/vulkan/libvulkan/swapchain.h @@ -44,6 +44,8 @@ VKAPI_ATTR VkResult GetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapch VKAPI_ATTR void SetHdrMetadataEXT(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pHdrMetadataEXTs); VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities); VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats); +VKAPI_ATTR VkResult BindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos); +VKAPI_ATTR VkResult BindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos); // clang-format on } // namespace driver -- cgit v1.2.3-59-g8ed1b From 14f4d4296153a8d9118780ef7e43793da5e7685d Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 17 Apr 2019 12:24:39 -0700 Subject: libvulkan: Rev 8 of ANDROID_native_buffer This change ramps up the ANDROID_native_buffer spec version becasue of the new behavior introduced to support the new structure added in VK_KHR_swapchain v69. This change also advertise the swapchain spec verison based upon the ANDROID_native_buffer version the drivers are reporting. Bug: 130182551 Test: CtsDeqpTestCases Change-Id: Ic95489dac883726d10e1a949875a576116622f3c --- vulkan/api/vulkan.api | 2 +- vulkan/include/vulkan/vk_android_native_buffer.h | 12 +++++++++++- vulkan/libvulkan/driver.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/vulkan/api/vulkan.api b/vulkan/api/vulkan.api index 7604c955c6..76503c8c17 100644 --- a/vulkan/api/vulkan.api +++ b/vulkan/api/vulkan.api @@ -96,7 +96,7 @@ define NULL_HANDLE 0 @extension("VK_KHR_win32_surface") define VK_KHR_WIN32_SURFACE_NAME "VK_KHR_win32_surface" // 11 -@extension("VK_ANDROID_native_buffer") define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7 +@extension("VK_ANDROID_native_buffer") define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 @extension("VK_ANDROID_native_buffer") define VK_ANDROID_NATIVE_BUFFER_NAME "VK_ANDROID_native_buffer" // 12 diff --git a/vulkan/include/vulkan/vk_android_native_buffer.h b/vulkan/include/vulkan/vk_android_native_buffer.h index d3e5f0f6b1..23006fa6be 100644 --- a/vulkan/include/vulkan/vk_android_native_buffer.h +++ b/vulkan/include/vulkan/vk_android_native_buffer.h @@ -37,7 +37,17 @@ extern "C" { * backwards-compatibility support is temporary, and will likely be removed in * (along with all gralloc0 support) in a future release. */ -#define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7 +/* NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 + * + * This version of the extension doesn't introduce new types or structs, but is + * to accommodate the new struct VkBindImageMemorySwapchainInfoKHR added in + * VK_KHR_swapchain spec version 69. When VkBindImageMemorySwapchainInfoKHR is + * chained in the pNext chain of VkBindImageMemoryInfo, a VkNativeBufferANDROID + * that holds the correct gralloc handle according to the imageIndex specified + * in VkBindImageMemorySwapchainInfoKHR will be additionally chained to the + * pNext chain of VkBindImageMemoryInfo and passed down to the driver. + */ +#define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" #define VK_ANDROID_NATIVE_BUFFER_ENUM(type,id) ((type)(1000000000 + (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 491d4d1343..613fa1352a 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -983,7 +983,12 @@ VkResult EnumerateDeviceExtensionProperties( memcpy(prop.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME, sizeof(VK_KHR_SWAPCHAIN_EXTENSION_NAME)); - prop.specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION; + + if (prop.specVersion >= 8) { + prop.specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION; + } else { + prop.specVersion = 68; + } } } -- cgit v1.2.3-59-g8ed1b From 8c5e3bde15a3d4c09d002a2d53de39c45528e2c9 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 9 May 2019 14:34:19 -0700 Subject: GpuStats: track CPU Vulkan implementation usage Bug: 131927737 Test: test on both GPU and CPU Vulkan implementations Change-Id: I36de47e14cd132a779d9f39fdc19325d4772bb9a --- libs/graphicsenv/GpuStatsInfo.cpp | 3 +++ libs/graphicsenv/GraphicsEnv.cpp | 11 ++++++++++ libs/graphicsenv/IGpuService.cpp | 24 ++++++++++++++++++++++ .../graphicsenv/include/graphicsenv/GpuStatsInfo.h | 1 + libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 1 + libs/graphicsenv/include/graphicsenv/IGpuService.h | 5 +++++ services/gpuservice/GpuService.cpp | 7 +++++++ services/gpuservice/GpuService.h | 2 ++ services/gpuservice/gpustats/GpuStats.cpp | 20 +++++++++++++----- services/gpuservice/gpustats/GpuStats.h | 2 ++ vulkan/libvulkan/driver.cpp | 5 +++++ 11 files changed, 76 insertions(+), 5 deletions(-) (limited to 'vulkan/libvulkan/driver.cpp') diff --git a/libs/graphicsenv/GpuStatsInfo.cpp b/libs/graphicsenv/GpuStatsInfo.cpp index 047d6833fa..4a801bec38 100644 --- a/libs/graphicsenv/GpuStatsInfo.cpp +++ b/libs/graphicsenv/GpuStatsInfo.cpp @@ -85,6 +85,7 @@ status_t GpuStatsAppInfo::writeToParcel(Parcel* parcel) const { if ((status = parcel->writeInt64Vector(glDriverLoadingTime)) != OK) return status; if ((status = parcel->writeInt64Vector(vkDriverLoadingTime)) != OK) return status; if ((status = parcel->writeInt64Vector(angleDriverLoadingTime)) != OK) return status; + if ((status = parcel->writeBool(cpuVulkanInUse)) != OK) return status; return OK; } @@ -95,6 +96,7 @@ status_t GpuStatsAppInfo::readFromParcel(const Parcel* parcel) { if ((status = parcel->readInt64Vector(&glDriverLoadingTime)) != OK) return status; if ((status = parcel->readInt64Vector(&vkDriverLoadingTime)) != OK) return status; if ((status = parcel->readInt64Vector(&angleDriverLoadingTime)) != OK) return status; + if ((status = parcel->readBool(&cpuVulkanInUse)) != OK) return status; return OK; } @@ -102,6 +104,7 @@ std::string GpuStatsAppInfo::toString() const { std::string result; StringAppendF(&result, "appPackageName = %s\n", appPackageName.c_str()); StringAppendF(&result, "driverVersionCode = %" PRIu64 "\n", driverVersionCode); + StringAppendF(&result, "cpuVulkanInUse = %d\n", cpuVulkanInUse); result.append("glDriverLoadingTime:"); for (int32_t loadingTime : glDriverLoadingTime) { StringAppendF(&result, " %d", loadingTime); diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 2f84f86431..407f77d88b 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -263,6 +263,17 @@ static sp getGpuService() { return interface_cast(binder); } +void GraphicsEnv::setCpuVulkanInUse() { + ATRACE_CALL(); + + // Use the same stats lock to protect getGpuService() as well. + std::lock_guard lock(mStatsLock); + const sp gpuService = getGpuService(); + if (gpuService) { + gpuService->setCpuVulkanInUse(mGpuStats.appPackageName, mGpuStats.driverVersionCode); + } +} + void GraphicsEnv::sendGpuStatsLocked(GraphicsEnv::Api api, bool isDriverLoaded, int64_t driverLoadingTime) { ATRACE_CALL(); diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp index 100dca598b..5f9624918f 100644 --- a/libs/graphicsenv/IGpuService.cpp +++ b/libs/graphicsenv/IGpuService.cpp @@ -91,6 +91,17 @@ public: outStats->clear(); return reply.readParcelableVector(outStats); } + + virtual void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + Parcel data, reply; + data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); + + data.writeUtf8AsUtf16(appPackageName); + data.writeUint64(driverVersionCode); + + remote()->transact(BnGpuService::SET_CPU_VULKAN_IN_USE, data, &reply, IBinder::FLAG_ONEWAY); + } }; IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); @@ -163,6 +174,19 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* rep return OK; } + case SET_CPU_VULKAN_IN_USE: { + CHECK_INTERFACE(IGpuService, data, reply); + + std::string appPackageName; + if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; + + uint64_t driverVersionCode; + if ((status = data.readUint64(&driverVersionCode)) != OK) return status; + + setCpuVulkanInUse(appPackageName, driverVersionCode); + + return OK; + } case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); diff --git a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h index bdcf0d67f5..edcccfea4a 100644 --- a/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h +++ b/libs/graphicsenv/include/graphicsenv/GpuStatsInfo.h @@ -69,6 +69,7 @@ public: std::vector glDriverLoadingTime = {}; std::vector vkDriverLoadingTime = {}; std::vector angleDriverLoadingTime = {}; + bool cpuVulkanInUse = false; }; } // namespace android diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index ca8f834b95..7d627500fd 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -96,6 +96,7 @@ public: void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, uint64_t versionCode, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion); + void setCpuVulkanInUse(); void setDriverToLoad(Driver driver); void setDriverLoaded(Api api, bool isDriverLoaded, int64_t driverLoadingTime); void sendGpuStatsLocked(Api api, bool isDriverLoaded, int64_t driverLoadingTime); diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h index 5bf0269430..34f1c7ee7e 100644 --- a/libs/graphicsenv/include/graphicsenv/IGpuService.h +++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h @@ -40,6 +40,10 @@ public: const int32_t vulkanVersion, GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime) = 0; + // set CPU Vulkan in use signal from GraphicsEnvironment. + virtual void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) = 0; + // get GPU global stats from GpuStats module. virtual status_t getGpuStatsGlobalInfo(std::vector* outStats) const = 0; @@ -53,6 +57,7 @@ public: SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, GET_GPU_STATS_GLOBAL_INFO, GET_GPU_STATS_APP_INFO, + SET_CPU_VULKAN_IN_USE, // Always append new enum to the end. }; diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp index b42884e139..8accf9d450 100644 --- a/services/gpuservice/GpuService.cpp +++ b/services/gpuservice/GpuService.cpp @@ -75,6 +75,13 @@ status_t GpuService::getGpuStatsAppInfo(std::vector* outStats) return OK; } +void GpuService::setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + ATRACE_CALL(); + + mGpuStats->setCpuVulkanInUse(appPackageName, driverVersionCode); +} + status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector& args) { ATRACE_CALL(); diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h index 3e02b4a073..822690134a 100644 --- a/services/gpuservice/GpuService.h +++ b/services/gpuservice/GpuService.h @@ -50,6 +50,8 @@ private: int64_t driverLoadingTime) override; status_t getGpuStatsGlobalInfo(std::vector* outStats) const override; status_t getGpuStatsAppInfo(std::vector* outStats) const override; + void setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) override; /* * IBinder interface diff --git a/services/gpuservice/gpustats/GpuStats.cpp b/services/gpuservice/gpustats/GpuStats.cpp index 8b01c282cc..37c6abc96b 100644 --- a/services/gpuservice/gpustats/GpuStats.cpp +++ b/services/gpuservice/gpustats/GpuStats.cpp @@ -108,13 +108,13 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d addLoadingCount(driver, isDriverLoaded, &mGlobalStats[driverVersionCode]); } - if (mAppStats.size() >= MAX_NUM_APP_RECORDS) { - ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats."); - return; - } - const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); if (!mAppStats.count(appStatsKey)) { + if (mAppStats.size() >= MAX_NUM_APP_RECORDS) { + ALOGV("GpuStatsAppInfo has reached maximum size. Ignore new stats."); + return; + } + GpuStatsAppInfo appInfo; addLoadingTime(driver, driverLoadingTime, &appInfo); appInfo.appPackageName = appPackageName; @@ -126,6 +126,16 @@ void GpuStats::insert(const std::string& driverPackageName, const std::string& d addLoadingTime(driver, driverLoadingTime, &mAppStats[appStatsKey]); } +void GpuStats::setCpuVulkanInUse(const std::string& appPackageName, + const uint64_t driverVersionCode) { + const std::string appStatsKey = appPackageName + std::to_string(driverVersionCode); + if (!mAppStats.count(appStatsKey)) { + return; + } + + mAppStats[appStatsKey].cpuVulkanInUse = true; +} + void GpuStats::interceptSystemDriverStatsLocked() { // Append cpuVulkanVersion and glesVersion to system driver stats if (!mGlobalStats.count(0) || mGlobalStats[0].glesVersion) { diff --git a/services/gpuservice/gpustats/GpuStats.h b/services/gpuservice/gpustats/GpuStats.h index 49699ee813..b293f5988d 100644 --- a/services/gpuservice/gpustats/GpuStats.h +++ b/services/gpuservice/gpustats/GpuStats.h @@ -37,6 +37,8 @@ public: uint64_t driverVersionCode, int64_t driverBuildTime, const std::string& appPackageName, const int32_t vulkanVersion, GraphicsEnv::Driver driver, bool isDriverLoaded, int64_t driverLoadingTime); + // Set CPU Vulkan in use signal into app stats. + void setCpuVulkanInUse(const std::string& appPackageName, const uint64_t driverVersionCode); // dumpsys interface void dump(const Vector& args, std::string* result); // Pull gpu global stats diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 613fa1352a..23506bad54 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -1174,6 +1174,11 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, &properties); ATRACE_END(); + if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) { + // Log that the app is hitting software Vulkan implementation + android::GraphicsEnv::getInstance().setCpuVulkanInUse(); + } + data->driver_device = dev; data->driver_version = properties.driverVersion; -- cgit v1.2.3-59-g8ed1b