diff options
author | 2018-06-08 15:11:57 -0700 | |
---|---|---|
committer | 2018-06-08 15:11:57 -0700 | |
commit | f11e2bd016d886a333345dea853ebda23a408d5c (patch) | |
tree | 905bd4d25d6ab2b046620ff459777d8dcfa5d7de /vulkan/libvulkan | |
parent | aabd6b7fa343654cd85b3b2da392e424d037d15a (diff) | |
parent | 5c947cdf72270fd1f766b2248d526ebc8c7227f6 (diff) |
Merge pi-dev-plus-aosp-without-vendor into stage-aosp-master
Bug: 79597307
Change-Id: I6d6bee71b9424eb478780bbfc06b830eb8ded342
Diffstat (limited to 'vulkan/libvulkan')
-rw-r--r-- | vulkan/libvulkan/Android.bp | 5 | ||||
-rw-r--r-- | vulkan/libvulkan/api.cpp | 37 | ||||
-rw-r--r-- | vulkan/libvulkan/driver.cpp | 13 | ||||
-rw-r--r-- | vulkan/libvulkan/layers_extensions.cpp | 47 | ||||
-rw-r--r-- | vulkan/libvulkan/swapchain.cpp | 140 | ||||
-rw-r--r-- | vulkan/libvulkan/vulkan_loader_data.cpp | 24 |
6 files changed, 202 insertions, 64 deletions
diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index b55fa27a76..7f4f2c4ab3 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -61,7 +61,6 @@ cc_library_shared { "layers_extensions.cpp", "stubhal.cpp", "swapchain.cpp", - "vulkan_loader_data.cpp", ], export_header_lib_headers: ["vulkan_headers"], @@ -69,10 +68,14 @@ cc_library_shared { "vulkan_headers", ], shared_libs: [ + "android.hardware.configstore@1.0", + "android.hardware.configstore-utils", "libziparchive", "libhardware", "libsync", "libbase", + "libhidlbase", + "libhidltransport", "liblog", "libui", "libgraphicsenv", diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index d840786ae5..673a066182 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -29,14 +29,17 @@ #include <new> #include <utility> +#include <android-base/strings.h> #include <cutils/properties.h> #include <log/log.h> #include <vulkan/vk_layer_interface.h> +#include <graphicsenv/GraphicsEnv.h> #include "api.h" #include "driver.h" #include "layers_extensions.h" + namespace vulkan { namespace api { @@ -121,15 +124,33 @@ class OverrideLayerNames { if (!is_instance_ || !driver::Debuggable()) return; - ParseDebugVulkanLayers(); - property_list(ParseDebugVulkanLayer, this); + GetLayersFromSettings(); - // sort by priorities - auto& arr = implicit_layers_; - std::sort(arr.elements, arr.elements + arr.count, - [](const ImplicitLayer& a, const ImplicitLayer& b) { - return (a.priority < b.priority); - }); + // If no layers specified via Settings, check legacy properties + if (implicit_layers_.count <= 0) { + ParseDebugVulkanLayers(); + property_list(ParseDebugVulkanLayer, this); + + // sort by priorities + auto& arr = implicit_layers_; + std::sort(arr.elements, arr.elements + arr.count, + [](const ImplicitLayer& a, const ImplicitLayer& b) { + return (a.priority < b.priority); + }); + } + } + + void GetLayersFromSettings() { + // These will only be available if conditions are met in GraphicsEnvironemnt + // gpu_debug_layers = layer1:layer2:layerN + const std::string layers = android::GraphicsEnv::getInstance().getDebugLayers(); + if (!layers.empty()) { + ALOGV("Debug layer list: %s", layers.c_str()); + std::vector<std::string> paths = android::base::Split(layers, ":"); + for (uint32_t i = 0; i < paths.size(); i++) { + AddImplicitLayer(int(i), paths[i].c_str(), paths[i].length()); + } + } } void ParseDebugVulkanLayers() { diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 4beb315a65..56bc35ec70 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -27,6 +27,8 @@ #include <log/log.h> #include <android/dlext.h> +#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> +#include <configstore/Utils.h> #include <cutils/properties.h> #include <graphicsenv/GraphicsEnv.h> #include <utils/Vector.h> @@ -36,6 +38,9 @@ #include "driver.h" #include "stubhal.h" +using namespace android::hardware::configstore; +using namespace android::hardware::configstore::V1_0; + // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); @@ -884,6 +889,14 @@ VkResult EnumerateDeviceExtensionProperties( VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION}); + bool hdrBoardConfig = + getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>( + false); + if (hdrBoardConfig) { + loader_extensions.push_back({VK_EXT_HDR_METADATA_EXTENSION_NAME, + VK_EXT_HDR_METADATA_SPEC_VERSION}); + } + VkPhysicalDevicePresentationPropertiesANDROID presentation_properties; if (QueryPresentationProperties(physicalDevice, &presentation_properties) && presentation_properties.sharedImage) { diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index 05856d3c1c..3a59208446 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -29,11 +29,10 @@ #include <android/dlext.h> #include <android-base/strings.h> #include <cutils/properties.h> +#include <graphicsenv/GraphicsEnv.h> #include <log/log.h> #include <ziparchive/zip_archive.h> -#include <vulkan/vulkan_loader_data.h> - // TODO(jessehall): The whole way we deal with extensions is pretty hokey, and // not a good long-term solution. Having a hard-coded enum of extensions is // bad, of course. Representing sets of extensions (requested, supported, etc.) @@ -69,11 +68,16 @@ const char kSystemLayerLibraryDir[] = "/data/local/debug/vulkan"; class LayerLibrary { public: - explicit LayerLibrary(const std::string& path) - : path_(path), dlhandle_(nullptr), refcount_(0) {} + explicit LayerLibrary(const std::string& path, + const std::string& filename) + : path_(path), + filename_(filename), + dlhandle_(nullptr), + refcount_(0) {} LayerLibrary(LayerLibrary&& other) : path_(std::move(other.path_)), + filename_(std::move(other.filename_)), dlhandle_(other.dlhandle_), refcount_(other.refcount_) { other.dlhandle_ = nullptr; @@ -94,9 +98,14 @@ class LayerLibrary { const char* gpa_name, size_t gpa_name_len) const; + const std::string GetFilename() { return filename_; } + private: const std::string path_; + // Track the filename alone so we can detect duplicates + const std::string filename_; + std::mutex mutex_; void* dlhandle_; size_t refcount_; @@ -111,7 +120,7 @@ bool LayerLibrary::Open() { // any symbol dependencies will be resolved by system libraries. They // can't safely use libc++_shared, for example. Which is one reason // (among several) we only allow them in non-user builds. - auto app_namespace = LoaderData::GetInstance().app_namespace; + auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace(); if (app_namespace && !android::base::StartsWith(path_, kSystemLayerLibraryDir)) { android_dlextinfo dlextinfo = {}; @@ -305,8 +314,8 @@ void* LayerLibrary::GetGPA(const Layer& layer, std::vector<LayerLibrary> g_layer_libraries; std::vector<Layer> g_instance_layers; -void AddLayerLibrary(const std::string& path) { - LayerLibrary library(path); +void AddLayerLibrary(const std::string& path, const std::string& filename) { + LayerLibrary library(path + "/" + filename, filename); if (!library.Open()) return; @@ -398,7 +407,25 @@ void DiscoverLayersInPathList(const std::string& pathstr) { ForEachFileInPath(path, [&](const std::string& filename) { if (android::base::StartsWith(filename, "libVkLayer") && android::base::EndsWith(filename, ".so")) { - AddLayerLibrary(path + "/" + filename); + + // Check to ensure we haven't seen this layer already + // Let the first instance of the shared object be enumerated + // We're searching for layers in following order: + // 1. system path + // 2. libraryPermittedPath (if enabled) + // 3. libraryPath + + bool duplicate = false; + for (auto& layer : g_layer_libraries) { + if (layer.GetFilename() == filename) { + ALOGV("Skipping duplicate layer %s in %s", + filename.c_str(), path.c_str()); + duplicate = true; + } + } + + if (!duplicate) + AddLayerLibrary(path, filename); } }); } @@ -428,8 +455,8 @@ void DiscoverLayers() { prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { DiscoverLayersInPathList(kSystemLayerLibraryDir); } - if (!LoaderData::GetInstance().layer_path.empty()) - DiscoverLayersInPathList(LoaderData::GetInstance().layer_path); + if (!android::GraphicsEnv::getInstance().getLayerPaths().empty()) + DiscoverLayersInPathList(android::GraphicsEnv::getInstance().getLayerPaths()); } uint32_t GetLayerCount() { diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 03e6ee0870..3db8a3962e 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -185,6 +185,7 @@ class TimingInfo { struct Surface { android::sp<ANativeWindow> window; VkSwapchainKHR swapchain_handle; + uint64_t consumer_usage; }; VkSurfaceKHR HandleFromSurface(Surface* surface) { @@ -496,9 +497,18 @@ VkResult CreateAndroidSurfaceKHR( surface->window = pCreateInfo->window; surface->swapchain_handle = VK_NULL_HANDLE; + int err = native_window_get_consumer_usage(surface->window.get(), + &surface->consumer_usage); + if (err != android::NO_ERROR) { + ALOGE("native_window_get_consumer_usage() failed: %s (%d)", + strerror(-err), err); + surface->~Surface(); + allocator->pfnFree(allocator->pUserData, surface); + return VK_ERROR_INITIALIZATION_FAILED; + } // TODO(jessehall): Create and use NATIVE_WINDOW_API_VULKAN. - int err = + err = native_window_api_connect(surface->window.get(), NATIVE_WINDOW_API_EGL); if (err != 0) { // TODO(jessehall): Improve error reporting. Can we enumerate possible @@ -536,9 +546,45 @@ void DestroySurfaceKHR(VkInstance instance, VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice /*pdev*/, uint32_t /*queue_family*/, - VkSurfaceKHR /*surface*/, + VkSurfaceKHR surface_handle, VkBool32* supported) { - *supported = VK_TRUE; + const Surface* surface = SurfaceFromHandle(surface_handle); + if (!surface) { + return VK_ERROR_SURFACE_LOST_KHR; + } + const ANativeWindow* window = surface->window.get(); + + int query_value; + int err = window->query(window, NATIVE_WINDOW_FORMAT, &query_value); + if (err != 0 || query_value < 0) { + ALOGE("NATIVE_WINDOW_FORMAT query failed: %s (%d) value=%d", + strerror(-err), err, query_value); + return VK_ERROR_SURFACE_LOST_KHR; + } + + android_pixel_format native_format = + static_cast<android_pixel_format>(query_value); + + bool format_supported = false; + switch (native_format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGB_565: + format_supported = true; + break; + default: + break; + } + + // USAGE_CPU_READ_MASK 0xFUL + // USAGE_CPU_WRITE_MASK (0xFUL << 4) + // The currently used bits are as below: + // USAGE_CPU_READ_RARELY = 2UL + // USAGE_CPU_READ_OFTEN = 3UL + // USAGE_CPU_WRITE_RARELY = (2UL << 4) + // USAGE_CPU_WRITE_OFTEN = (3UL << 4) + *supported = static_cast<VkBool32>(format_supported || + (surface->consumer_usage & 0xFFUL) == 0); + return VK_SUCCESS; } @@ -573,8 +619,15 @@ VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR( } // TODO(jessehall): Figure out what the min/max values should be. - capabilities->minImageCount = 2; - capabilities->maxImageCount = 3; + int max_buffer_count; + err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &max_buffer_count); + if (err != 0) { + ALOGE("NATIVE_WINDOW_MAX_BUFFER_COUNT query failed: %s (%d)", + strerror(-err), err); + return VK_ERROR_SURFACE_LOST_KHR; + } + capabilities->minImageCount = max_buffer_count == 1 ? 1 : 2; + capabilities->maxImageCount = static_cast<uint32_t>(max_buffer_count); capabilities->currentExtent = VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)}; @@ -744,11 +797,32 @@ VkResult GetPhysicalDeviceSurfaceFormats2KHR( VKAPI_ATTR VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev, - VkSurfaceKHR /*surface*/, + VkSurfaceKHR surface, uint32_t* count, VkPresentModeKHR* modes) { + int err; + int query_value; + ANativeWindow* window = SurfaceFromHandle(surface)->window.get(); + + err = window->query(window, NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &query_value); + if (err != 0 || query_value < 0) { + ALOGE("NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS query failed: %s (%d) value=%d", + strerror(-err), err, query_value); + return VK_ERROR_SURFACE_LOST_KHR; + } + uint32_t min_undequeued_buffers = static_cast<uint32_t>(query_value); + + err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &query_value); + if (err != 0 || query_value < 0) { + ALOGE("NATIVE_WINDOW_MAX_BUFFER_COUNT query failed: %s (%d) value=%d", + strerror(-err), err, query_value); + return VK_ERROR_SURFACE_LOST_KHR; + } + uint32_t max_buffer_count = static_cast<uint32_t>(query_value); + android::Vector<VkPresentModeKHR> present_modes; - present_modes.push_back(VK_PRESENT_MODE_MAILBOX_KHR); + if (min_undequeued_buffers + 1 < max_buffer_count) + present_modes.push_back(VK_PRESENT_MODE_MAILBOX_KHR); present_modes.push_back(VK_PRESENT_MODE_FIFO_KHR); VkPhysicalDevicePresentationPropertiesANDROID present_properties; @@ -1194,19 +1268,19 @@ VkResult CreateSwapchainKHR(VkDevice device, // // TODO(jessehall): The error path here is the same as DestroySwapchain, // but not the non-error path. Should refactor/unify. - if (!swapchain->shared) { - for (uint32_t i = 0; i < num_images; i++) { - Swapchain::Image& img = swapchain->images[i]; - if (img.dequeued) { + for (uint32_t i = 0; i < num_images; i++) { + Swapchain::Image& img = swapchain->images[i]; + if (img.dequeued) { + if (!swapchain->shared) { surface.window->cancelBuffer(surface.window.get(), img.buffer.get(), img.dequeue_fence); img.dequeue_fence = -1; img.dequeued = false; } - if (result != VK_SUCCESS) { - if (img.image) - dispatch.DestroyImage(device, img.image, nullptr); - } + } + if (result != VK_SUCCESS) { + if (img.image) + dispatch.DestroyImage(device, img.image, nullptr); } } @@ -1650,15 +1724,39 @@ VkResult GetSwapchainStatusKHR( } VKAPI_ATTR void SetHdrMetadataEXT( - VkDevice device, + VkDevice, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pHdrMetadataEXTs) { - // TODO: courtneygo: implement actual function - (void)device; - (void)swapchainCount; - (void)pSwapchains; - (void)pHdrMetadataEXTs; + + for (uint32_t idx = 0; idx < swapchainCount; idx++) { + Swapchain* swapchain = SwapchainFromHandle(pSwapchains[idx]); + if (!swapchain) + continue; + + if (swapchain->surface.swapchain_handle != pSwapchains[idx]) continue; + + ANativeWindow* window = swapchain->surface.window.get(); + + VkHdrMetadataEXT vulkanMetadata = pHdrMetadataEXTs[idx]; + const android_smpte2086_metadata smpteMetdata = { + {vulkanMetadata.displayPrimaryRed.x, + vulkanMetadata.displayPrimaryRed.y}, + {vulkanMetadata.displayPrimaryGreen.x, + vulkanMetadata.displayPrimaryGreen.y}, + {vulkanMetadata.displayPrimaryBlue.x, + vulkanMetadata.displayPrimaryBlue.y}, + {vulkanMetadata.whitePoint.x, vulkanMetadata.whitePoint.y}, + vulkanMetadata.maxLuminance, + vulkanMetadata.minLuminance}; + native_window_set_buffers_smpte2086_metadata(window, &smpteMetdata); + + const android_cta861_3_metadata cta8613Metadata = { + vulkanMetadata.maxContentLightLevel, + vulkanMetadata.maxFrameAverageLightLevel}; + native_window_set_buffers_cta861_3_metadata(window, &cta8613Metadata); + } + return; } diff --git a/vulkan/libvulkan/vulkan_loader_data.cpp b/vulkan/libvulkan/vulkan_loader_data.cpp deleted file mode 100644 index 0eda0af59a..0000000000 --- a/vulkan/libvulkan/vulkan_loader_data.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015 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. - */ - -#include <vulkan/vulkan_loader_data.h> - -using namespace vulkan; - -LoaderData& LoaderData::GetInstance() { - static LoaderData loader_data = {}; - return loader_data; -} |