diff options
26 files changed, 253 insertions, 118 deletions
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 67f12e8efe..584d7c50db 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -960,6 +960,7 @@ static void DumpDynamicPartitionInfo() { } RunCommand("LPDUMP", {"lpdump", "--all"}); + RunCommand("DEVICE-MAPPER", {"gsid", "dump-device-mapper"}); } static void AddAnrTraceDir(const bool add_to_zip, const std::string& anr_traces_dir) { diff --git a/cmds/servicemanager/ServiceManager.cpp b/cmds/servicemanager/ServiceManager.cpp index 934436847e..934646da41 100644 --- a/cmds/servicemanager/ServiceManager.cpp +++ b/cmds/servicemanager/ServiceManager.cpp @@ -165,7 +165,7 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi #endif // !VENDORSERVICEMANAGER // implicitly unlinked when the binder is removed - if (OK != binder->linkToDeath(this)) { + if (binder->remoteBinder() != nullptr && binder->linkToDeath(this) != OK) { LOG(ERROR) << "Could not linkToDeath when adding " << name; return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); } diff --git a/cmds/servicemanager/main.cpp b/cmds/servicemanager/main.cpp index 11d43a6ee3..4b12fc6e72 100644 --- a/cmds/servicemanager/main.cpp +++ b/cmds/servicemanager/main.cpp @@ -23,11 +23,12 @@ #include "Access.h" #include "ServiceManager.h" -using ::android::sp; -using ::android::ProcessState; +using ::android::Access; using ::android::IPCThreadState; +using ::android::ProcessState; using ::android::ServiceManager; -using ::android::Access; +using ::android::os::IServiceManager; +using ::android::sp; int main(int argc, char** argv) { if (argc > 2) { @@ -41,6 +42,10 @@ int main(int argc, char** argv) { ps->setCallRestriction(ProcessState::CallRestriction::FATAL_IF_NOT_ONEWAY); sp<ServiceManager> manager = new ServiceManager(std::make_unique<Access>()); + if (!manager->addService("manager", manager, false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()) { + LOG(ERROR) << "Could not self register servicemanager"; + } + IPCThreadState::self()->setTheContextObject(manager); ps->becomeContextManager(nullptr, nullptr); diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index e5646ef701..7ee4882b6a 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -165,3 +165,16 @@ filegroup { ], path: "aidl", } + +aidl_interface { + name: "libbinder_aidl_test_stub", + local_include_dir: "aidl", + srcs: [":libbinder_aidl"], + visibility: [":__subpackages__"], + vendor_available: true, + backend: { + java: { + enabled: false, + }, + }, +} diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 0336d3ebd4..ea61dc5aff 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -188,6 +188,30 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; } +// Queries the driver for the current strong reference count of the node +// that the handle points to. Can only be used by the servicemanager. +// +// Returns -1 in case of failure, otherwise the strong reference count. +ssize_t ProcessState::getStrongRefCountForNodeByHandle(int32_t handle) { + binder_node_info_for_ref info; + memset(&info, 0, sizeof(binder_node_info_for_ref)); + + info.handle = handle; + + status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info); + + if (result != OK) { + static bool logged = false; + if (!logged) { + ALOGW("Kernel does not support BINDER_GET_NODE_INFO_FOR_REF."); + logged = true; + } + return -1; + } + + return info.strong_count; +} + void ProcessState::setCallRestriction(CallRestriction restriction) { LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr, "Call restrictions must be set before the threadpool is started."); diff --git a/libs/binder/aidl/android/os/IServiceManager.aidl b/libs/binder/aidl/android/os/IServiceManager.aidl index 60c2cceaf2..471b63fb5e 100644 --- a/libs/binder/aidl/android/os/IServiceManager.aidl +++ b/libs/binder/aidl/android/os/IServiceManager.aidl @@ -31,22 +31,22 @@ interface IServiceManager { * Must update values in IServiceManager.h */ /* Allows services to dump sections according to priorities. */ - const int DUMP_FLAG_PRIORITY_CRITICAL = 1; // 1 << 0 - const int DUMP_FLAG_PRIORITY_HIGH = 2; // 1 << 1 - const int DUMP_FLAG_PRIORITY_NORMAL = 4; // 1 << 2 + const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0; + const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1; + const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2; /** * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the * same priority as NORMAL priority but the services are not called with dump priority * arguments. */ - const int DUMP_FLAG_PRIORITY_DEFAULT = 8; // 1 << 3 + const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3; const int DUMP_FLAG_PRIORITY_ALL = 15; // DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH // | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; /* Allows services to dump sections in protobuf format. */ - const int DUMP_FLAG_PROTO = 16; // 1 << 4 + const int DUMP_FLAG_PROTO = 1 << 4; /** * Retrieve an existing service called @a name from the diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index f7c38f418d..e57ff1c260 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -69,6 +69,14 @@ public: ssize_t getKernelReferences(size_t count, uintptr_t* buf); + // Only usable by the context manager. + // This refcount includes: + // 1. Strong references to the node by this and other processes + // 2. Temporary strong references held by the kernel during a + // transaction on the node. + // It does NOT include local strong references to the node + ssize_t getStrongRefCountForNodeByHandle(int32_t handle); + enum class CallRestriction { // all calls okay NONE, diff --git a/libs/binder/ndk/test/Android.bp b/libs/binder/ndk/test/Android.bp index 1c5dba3736..ebd08b2f71 100644 --- a/libs/binder/ndk/test/Android.bp +++ b/libs/binder/ndk/test/Android.bp @@ -77,6 +77,7 @@ cc_test { static_libs: [ "IBinderVendorDoubleLoadTest-cpp", "IBinderVendorDoubleLoadTest-ndk_platform", + "libbinder_aidl_test_stub-ndk_platform", ], shared_libs: [ "libbase", diff --git a/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp index f72dc36cfd..d3ccdc2878 100644 --- a/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp +++ b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp @@ -16,6 +16,7 @@ #include <BnBinderVendorDoubleLoadTest.h> #include <aidl/BnBinderVendorDoubleLoadTest.h> +#include <aidl/android/os/IServiceManager.h> #include <android-base/logging.h> #include <android-base/properties.h> #include <android-base/strings.h> @@ -109,6 +110,24 @@ TEST(DoubleBinder, CallIntoNdk) { } } +TEST(DoubleBinder, CallIntoSystemStabilityNdk) { + // picking an arbitrary system service + SpAIBinder binder = SpAIBinder(AServiceManager_checkService("manager")); + ASSERT_NE(nullptr, binder.get()); + + // can make stable transaction to system server + EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get())); + + using aidl::android::os::IServiceManager; + std::shared_ptr<IServiceManager> manager = IServiceManager::fromBinder(binder); + ASSERT_NE(nullptr, manager.get()); + + std::vector<std::string> services; + ASSERT_EQ( + STATUS_BAD_TYPE, + manager->listServices(IServiceManager::DUMP_FLAG_PRIORITY_ALL, &services).getStatus()); +} + void initDrivers() { // Explicitly instantiated with the same driver that system would use. // __ANDROID_VNDK__ right now uses /dev/vndbinder by default. diff --git a/libs/math/include/math/quat.h b/libs/math/include/math/quat.h index 1936a2baec..07573c5ecf 100644 --- a/libs/math/include/math/quat.h +++ b/libs/math/include/math/quat.h @@ -109,7 +109,7 @@ public: // initialize from 4 values to w + xi + yj + zk template<typename A, typename B, typename C, typename D> - constexpr TQuaternion(A w, B x, C y, D z) : x(x), y(y), z(z), w(w) { } + constexpr TQuaternion(A w, B x, C y, D z) : x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(z)), w(static_cast<T>(w)) { } // initialize from a vec3 + a value to : v.xi + v.yj + v.zk + w template<typename A, typename B> diff --git a/libs/math/include/math/vec2.h b/libs/math/include/math/vec2.h index a34763347c..e0adb7f6cc 100644 --- a/libs/math/include/math/vec2.h +++ b/libs/math/include/math/vec2.h @@ -89,7 +89,7 @@ public: constexpr TVec2(A v) : x(v), y(v) { } template<typename A, typename B> - constexpr TVec2(A x, B y) : x(x), y(y) { } + constexpr TVec2(A x, B y) : x(static_cast<T>(x)), y(static_cast<T>(y)) { } template<typename A> explicit diff --git a/libs/math/include/math/vec3.h b/libs/math/include/math/vec3.h index 009fd84e3b..21fb684efc 100644 --- a/libs/math/include/math/vec3.h +++ b/libs/math/include/math/vec3.h @@ -86,13 +86,13 @@ public: // handles implicit conversion to a tvec4. must not be explicit. template<typename A, typename = typename std::enable_if<std::is_arithmetic<A>::value >::type> - constexpr TVec3(A v) : x(v), y(v), z(v) { } + constexpr TVec3(A v) : x(static_cast<T>(v)), y(static_cast<T>(v)), z(static_cast<T>(v)) { } template<typename A, typename B, typename C> - constexpr TVec3(A x, B y, C z) : x(x), y(y), z(z) { } + constexpr TVec3(A x, B y, C z) : x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(z)) { } template<typename A, typename B> - constexpr TVec3(const TVec2<A>& v, B z) : x(v.x), y(v.y), z(z) { } + constexpr TVec3(const TVec2<A>& v, B z) : x(v.x), y(v.y), z(static_cast<T>(z)) { } template<typename A> explicit diff --git a/libs/ui/ColorSpace.cpp b/libs/ui/ColorSpace.cpp index 7a14af1c9d..df390e2588 100644 --- a/libs/ui/ColorSpace.cpp +++ b/libs/ui/ColorSpace.cpp @@ -364,7 +364,11 @@ std::unique_ptr<float3[]> ColorSpace::createLUT(uint32_t size, const ColorSpace& for (uint32_t z = 0; z < size; z++) { for (int32_t y = int32_t(size - 1); y >= 0; y--) { for (uint32_t x = 0; x < size; x++) { - *data++ = connector.transform({x * m, y * m, z * m}); + *data++ = connector.transform({ + static_cast<float>(x) * m, + static_cast<float>(y) * m, + static_cast<float>(z) * m, + }); } } } diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index 0861a1f9a3..1dd59f43a7 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -80,7 +80,7 @@ void GraphicBufferAllocator::dump(std::string& result) const { if (rec.size) { StringAppendF(&result, "%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 " | %s\n", - list.keyAt(i), rec.size / 1024.0, rec.width, rec.stride, rec.height, + list.keyAt(i), static_cast<double>(rec.size) / 1024.0, rec.width, rec.stride, rec.height, rec.layerCount, rec.format, rec.usage, rec.requestorName.c_str()); } else { StringAppendF(&result, @@ -90,7 +90,7 @@ void GraphicBufferAllocator::dump(std::string& result) const { } total += rec.size; } - StringAppendF(&result, "Total allocated (estimate): %.2f KB\n", total / 1024.0); + StringAppendF(&result, "Total allocated (estimate): %.2f KB\n", static_cast<double>(total) / 1024.0); result.append(mAllocator->dumpDebugInfo()); } diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 55e3b99aa1..1222cd6fad 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -339,10 +339,10 @@ Region& Region::scaleSelf(float sx, float sy) { size_t count = mStorage.size(); Rect* rects = mStorage.editArray(); while (count) { - rects->left = static_cast<int32_t>(rects->left * sx + 0.5f); - rects->right = static_cast<int32_t>(rects->right * sx + 0.5f); - rects->top = static_cast<int32_t>(rects->top * sy + 0.5f); - rects->bottom = static_cast<int32_t>(rects->bottom * sy + 0.5f); + rects->left = static_cast<int32_t>(static_cast<float>(rects->left) * sx + 0.5f); + rects->right = static_cast<int32_t>(static_cast<float>(rects->right) * sx + 0.5f); + rects->top = static_cast<int32_t>(static_cast<float>(rects->top) * sy + 0.5f); + rects->bottom = static_cast<int32_t>(static_cast<float>(rects->bottom) * sy + 0.5f); rects++; count--; } diff --git a/libs/ui/include/ui/Size.h b/libs/ui/include/ui/Size.h index c39d8af1d6..d9b713df4c 100644 --- a/libs/ui/include/ui/Size.h +++ b/libs/ui/include/ui/Size.h @@ -132,7 +132,7 @@ struct Size { // Otherwise we leverage implicit conversion to safely compare values of // different types, to ensure we return a value clamped to the range of // ToType. - return v < toLowest ? toLowest : (v > toHighest ? toHighest : static_cast<ToType>(v)); + return v < toLowest ? toLowest : (static_cast<ToType>(v) > toHighest ? toHighest : static_cast<ToType>(v)); } }; diff --git a/services/surfaceflinger/TimeStats/OWNERS b/services/surfaceflinger/TimeStats/OWNERS index ac02d12fcd..1441f91489 100644 --- a/services/surfaceflinger/TimeStats/OWNERS +++ b/services/surfaceflinger/TimeStats/OWNERS @@ -1 +1,2 @@ -zzyiwei@google.com
\ No newline at end of file +alecmouri@google.com +zzyiwei@google.com diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index 71048db920..3d56656896 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -519,7 +519,11 @@ LayerChain::LayerChain(bool is_instance, get_device_proc_addr_(nullptr), driver_extensions_(nullptr), driver_extension_count_(0) { - enabled_extensions_.set(driver::ProcHook::EXTENSION_CORE); + // advertise the loader supported core Vulkan API version at vulkan::api + for (uint32_t i = driver::ProcHook::EXTENSION_CORE_1_0; + i != driver::ProcHook::EXTENSION_COUNT; ++i) { + enabled_extensions_.set(i); + } } LayerChain::~LayerChain() { diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl index bdd3573b11..a5a0405f2d 100644 --- a/vulkan/libvulkan/code-generator.tmpl +++ b/vulkan/libvulkan/code-generator.tmpl @@ -765,6 +765,19 @@ VK_KHR_bind_memory2 {{end}} + +{{/* +------------------------------------------------------------------------------ + Emits the ProcHook enum for core Vulkan API verions. +------------------------------------------------------------------------------ +*/}} +{{define "driver.GetProcHookEnum"}} + {{if GetAnnotation $ "vulkan1_1"}}ProcHook::EXTENSION_CORE_1_1 + {{else}}ProcHook::EXTENSION_CORE_1_0 + {{end}} +{{end}} + + {{/* ------------------------------------------------------------------------------ Emits true if a function needs a ProcHook stub. @@ -778,6 +791,8 @@ VK_KHR_bind_memory2 {{if $ext}} {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}} {{end}} + + {{if GetAnnotation $ "vulkan1_1"}}true{{end}} {{end}} {{end}} @@ -801,7 +816,8 @@ VK_KHR_bind_memory2 {{TrimPrefix "VK_" $e}}, {{end}} ¶ - EXTENSION_CORE, // valid bit + EXTENSION_CORE_1_0, + EXTENSION_CORE_1_1, EXTENSION_COUNT, EXTENSION_UNKNOWN, }; @@ -838,14 +854,21 @@ VK_KHR_bind_memory2 {{AssertType $ "Function"}} {{if (Macro "driver.NeedProcHookStub" $)}} + {{$ext_name := Strings ("")}} + {{$ext_hook := Strings ("")}} {{$ext := GetAnnotation $ "extension"}} - {{$ext_name := index $ext.Arguments 0}} + {{if $ext}} + {{$ext_name = index $ext.Arguments 0}} + {{$ext_hook = Strings ("ProcHook::") (Macro "BaseName" $ext)}} + {{else}} + {{$ext_name = Strings ("VK_VERSION_1_0")}} + {{$ext_hook = (Macro "driver.GetProcHookEnum" $)}} + {{end}} {{$base := (Macro "BaseName" $)}} VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) { {{$p0 := index $.CallParameters 0}} - {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}} if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) { {{if not (IsVoid $.Return.Type)}}return §{{end}} @@ -878,7 +901,7 @@ VK_KHR_bind_memory2 { "{{$.Name}}", ProcHook::GLOBAL, - ProcHook::EXTENSION_CORE, + {{Macro "driver.GetProcHookEnum" $}}, reinterpret_cast<PFN_vkVoidFunction>({{$base}}), nullptr, }, @@ -911,7 +934,7 @@ VK_KHR_bind_memory2 nullptr, {{end}} {{else}} - ProcHook::EXTENSION_CORE, + {{Macro "driver.GetProcHookEnum" $}}, reinterpret_cast<PFN_vkVoidFunction>({{$base}}), nullptr, {{end}} @@ -934,18 +957,23 @@ VK_KHR_bind_memory2 ProcHook::DEVICE, {{$ext := GetAnnotation $ "extension"}} - {{if $ext}} - ProcHook::{{Macro "BaseName" $ext}}, - - {{if (Macro "IsExtensionInternal" $ext)}} - nullptr, - nullptr, + {{if or $ext (GetAnnotation $ "vulkan1_1")}} + {{if $ext}} + ProcHook::{{Macro "BaseName" $ext}}, + {{if Macro "IsExtensionInternal" $ext}} + nullptr, + nullptr, + {{else}} + reinterpret_cast<PFN_vkVoidFunction>({{$base}}), + reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}), + {{end}} {{else}} + {{Macro "driver.GetProcHookEnum" $}}, reinterpret_cast<PFN_vkVoidFunction>({{$base}}), reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}), {{end}} {{else}} - ProcHook::EXTENSION_CORE, + {{Macro "driver.GetProcHookEnum" $}}, reinterpret_cast<PFN_vkVoidFunction>({{$base}}), nullptr, {{end}} diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 23506bad54..85e1c923e7 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -24,7 +24,10 @@ #include <dlfcn.h> #include <algorithm> #include <array> +#include <climits> #include <new> +#include <sstream> +#include <string> #include <log/log.h> @@ -104,6 +107,7 @@ class CreateInfoWrapper { VkResult Validate(); void DowngradeApiVersion(); + void UpgradeDeviceCoreApiVersion(uint32_t api_version); const std::bitset<ProcHook::EXTENSION_COUNT>& GetHookExtensions() const; const std::bitset<ProcHook::EXTENSION_COUNT>& GetHalExtensions() const; @@ -152,15 +156,12 @@ class CreateInfoWrapper { Hal Hal::hal_; void* LoadLibrary(const android_dlextinfo& dlextinfo, - const char* subname, - int subname_len) { + const std::string_view subname) { ATRACE_CALL(); - const char kLibFormat[] = "vulkan.%*s.so"; - char* name = static_cast<char*>( - alloca(sizeof(kLibFormat) + static_cast<size_t>(subname_len))); - sprintf(name, kLibFormat, subname_len, subname); - return android_dlopen_ext(name, RTLD_LOCAL | RTLD_NOW, &dlextinfo); + std::stringstream ss; + ss << "vulkan." << subname << ".so"; + return android_dlopen_ext(ss.str().c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); } const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{ @@ -180,8 +181,9 @@ int LoadDriver(android_namespace_t* library_namespace, char prop[PROPERTY_VALUE_MAX]; for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { int prop_len = property_get(key, prop, nullptr); - if (prop_len > 0) { - so = LoadLibrary(dlextinfo, prop, prop_len); + if (prop_len > 0 && prop_len <= UINT_MAX) { + std::string_view lib_name(prop, static_cast<unsigned int>(prop_len)); + so = LoadLibrary(dlextinfo, lib_name); if (so) break; } @@ -333,8 +335,12 @@ CreateInfoWrapper::CreateInfoWrapper(const VkInstanceCreateInfo& create_info, physical_dev_(VK_NULL_HANDLE), instance_info_(create_info), extension_filter_() { - hook_extensions_.set(ProcHook::EXTENSION_CORE); - hal_extensions_.set(ProcHook::EXTENSION_CORE); + // instance core versions need to match the loader api version + for (uint32_t i = ProcHook::EXTENSION_CORE_1_0; + i != ProcHook::EXTENSION_COUNT; ++i) { + hook_extensions_.set(i); + hal_extensions_.set(i); + } } CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev, @@ -345,8 +351,9 @@ CreateInfoWrapper::CreateInfoWrapper(VkPhysicalDevice physical_dev, physical_dev_(physical_dev), dev_info_(create_info), extension_filter_() { - hook_extensions_.set(ProcHook::EXTENSION_CORE); - hal_extensions_.set(ProcHook::EXTENSION_CORE); + // initialize with baseline core API version + hook_extensions_.set(ProcHook::EXTENSION_CORE_1_0); + hal_extensions_.set(ProcHook::EXTENSION_CORE_1_0); } CreateInfoWrapper::~CreateInfoWrapper() { @@ -545,7 +552,8 @@ void CreateInfoWrapper::FilterExtension(const char* name) { case ProcHook::ANDROID_external_memory_android_hardware_buffer: case ProcHook::ANDROID_native_buffer: case ProcHook::GOOGLE_display_timing: - case ProcHook::EXTENSION_CORE: + case ProcHook::EXTENSION_CORE_1_0: + case ProcHook::EXTENSION_CORE_1_1: case ProcHook::EXTENSION_COUNT: // Device and meta extensions. If we ever get here it's a bug in // our code. But enumerating them lets us avoid having a default @@ -593,7 +601,8 @@ void CreateInfoWrapper::FilterExtension(const char* name) { case ProcHook::EXT_debug_report: case ProcHook::EXT_swapchain_colorspace: case ProcHook::ANDROID_native_buffer: - case ProcHook::EXTENSION_CORE: + case ProcHook::EXTENSION_CORE_1_0: + case ProcHook::EXTENSION_CORE_1_1: case ProcHook::EXTENSION_COUNT: // Instance and meta extensions. If we ever get here it's a bug // in our code. But enumerating them lets us avoid having a @@ -641,6 +650,28 @@ void CreateInfoWrapper::DowngradeApiVersion() { } } +void CreateInfoWrapper::UpgradeDeviceCoreApiVersion(uint32_t api_version) { + ALOG_ASSERT(!is_instance_, "Device only API called by instance wrapper."); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" + api_version ^= VK_VERSION_PATCH(api_version); +#pragma clang diagnostic pop + // cap the API version to the loader supported highest version + if (api_version > VK_API_VERSION_1_1) + api_version = VK_API_VERSION_1_1; + switch (api_version) { + case VK_API_VERSION_1_1: + hook_extensions_.set(ProcHook::EXTENSION_CORE_1_1); + hal_extensions_.set(ProcHook::EXTENSION_CORE_1_1); + [[clang::fallthrough]]; + case VK_API_VERSION_1_0: + break; + default: + ALOGD("Unknown upgrade API version[%u]", api_version); + break; + } +} + VKAPI_ATTR void* DefaultAllocate(void*, size_t size, size_t alignment, @@ -776,7 +807,7 @@ PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName) { : nullptr; break; case ProcHook::DEVICE: - proc = (hook->extension == ProcHook::EXTENSION_CORE) + proc = (hook->extension == ProcHook::EXTENSION_CORE_1_0) ? hook->proc : hook->checked_proc; break; @@ -1124,6 +1155,13 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, if (!data) return VK_ERROR_OUT_OF_HOST_MEMORY; + VkPhysicalDeviceProperties properties; + ATRACE_BEGIN("driver.GetPhysicalDeviceProperties"); + instance_data.driver.GetPhysicalDeviceProperties(physicalDevice, + &properties); + ATRACE_END(); + + wrapper.UpgradeDeviceCoreApiVersion(properties.apiVersion); data->hook_extensions |= wrapper.GetHookExtensions(); // call into the driver @@ -1168,12 +1206,6 @@ VkResult CreateDevice(VkPhysicalDevice physicalDevice, return VK_ERROR_INCOMPATIBLE_DRIVER; } - VkPhysicalDeviceProperties properties; - ATRACE_BEGIN("driver.GetPhysicalDeviceProperties"); - instance_data.driver.GetPhysicalDeviceProperties(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(); diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index 57c956d9a4..047a27adc9 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -67,9 +67,7 @@ struct InstanceData { : opaque_api_data(), allocator(alloc), driver(), - get_device_proc_addr(nullptr) { - hook_extensions.set(ProcHook::EXTENSION_CORE); - } + get_device_proc_addr(nullptr) {} api::InstanceData opaque_api_data; @@ -89,9 +87,7 @@ struct DeviceData { : opaque_api_data(), allocator(alloc), debug_report_callbacks(debug_report_callbacks_), - driver() { - hook_extensions.set(ProcHook::EXTENSION_CORE); - } + driver() {} api::DeviceData opaque_api_data; diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp index 574c3273d0..aa31735eef 100644 --- a/vulkan/libvulkan/driver_gen.cpp +++ b/vulkan/libvulkan/driver_gen.cpp @@ -31,6 +31,23 @@ namespace { // clang-format off +VKAPI_ATTR VkResult checkedBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) { + if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) { + return BindImageMemory2(device, bindInfoCount, pBindInfos); + } else { + Logger(device).Err(device, "VK_VERSION_1_0 not enabled. vkBindImageMemory2 not executed."); + return VK_SUCCESS; + } +} + +VKAPI_ATTR void checkedGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) { + if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) { + GetDeviceQueue2(device, pQueueInfo, pQueue); + } else { + Logger(device).Err(device, "VK_VERSION_1_0 not enabled. vkGetDeviceQueue2 not executed."); + } +} + VKAPI_ATTR VkResult checkedCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) { if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) { return CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); @@ -174,16 +191,16 @@ const ProcHook g_proc_hooks[] = { { "vkAllocateCommandBuffers", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers), nullptr, }, { "vkBindImageMemory2", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_1, reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2), - nullptr, + reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2), }, { "vkBindImageMemory2KHR", @@ -209,14 +226,14 @@ const ProcHook g_proc_hooks[] = { { "vkCreateDevice", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(CreateDevice), nullptr, }, { "vkCreateInstance", ProcHook::GLOBAL, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(CreateInstance), nullptr, }, @@ -244,14 +261,14 @@ const ProcHook g_proc_hooks[] = { { "vkDestroyDevice", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice), nullptr, }, { "vkDestroyInstance", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance), nullptr, }, @@ -272,28 +289,28 @@ const ProcHook g_proc_hooks[] = { { "vkEnumerateDeviceExtensionProperties", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties), nullptr, }, { "vkEnumerateInstanceExtensionProperties", ProcHook::GLOBAL, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties), nullptr, }, { "vkEnumeratePhysicalDeviceGroups", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_1, reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDeviceGroups), nullptr, }, { "vkEnumeratePhysicalDevices", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices), nullptr, }, @@ -314,28 +331,28 @@ const ProcHook g_proc_hooks[] = { { "vkGetDeviceProcAddr", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr), nullptr, }, { "vkGetDeviceQueue", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue), nullptr, }, { "vkGetDeviceQueue2", ProcHook::DEVICE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_1, reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue2), - nullptr, + reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceQueue2), }, { "vkGetInstanceProcAddr", ProcHook::INSTANCE, - ProcHook::EXTENSION_CORE, + ProcHook::EXTENSION_CORE_1_0, reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr), nullptr, }, diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h index 3faf6c0e32..831efb7026 100644 --- a/vulkan/libvulkan/driver_gen.h +++ b/vulkan/libvulkan/driver_gen.h @@ -48,7 +48,8 @@ struct ProcHook { ANDROID_external_memory_android_hardware_buffer, KHR_bind_memory2, - EXTENSION_CORE, // valid bit + EXTENSION_CORE_1_0, + EXTENSION_CORE_1_1, EXTENSION_COUNT, EXTENSION_UNKNOWN, }; diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index 5679412732..dd917393d1 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -24,6 +24,7 @@ #include <string.h> #include <sys/prctl.h> +#include <memory> #include <mutex> #include <string> #include <vector> @@ -101,9 +102,7 @@ class LayerLibrary { bool EnumerateLayers(size_t library_idx, std::vector<Layer>& instance_layers) const; - void* GetGPA(const Layer& layer, - const char* gpa_name, - size_t gpa_name_len) const; + void* GetGPA(const Layer& layer, const std::string_view gpa_name) const; const std::string GetFilename() { return filename_; } @@ -226,17 +225,10 @@ bool LayerLibrary::EnumerateLayers(size_t library_idx, } // get layer properties - VkLayerProperties* properties = static_cast<VkLayerProperties*>(alloca( - (num_instance_layers + num_device_layers) * sizeof(VkLayerProperties))); - result = enumerate_instance_layers(&num_instance_layers, properties); - if (result != VK_SUCCESS) { - ALOGE("vkEnumerateInstanceLayerProperties failed for library '%s': %d", - path_.c_str(), result); - return false; - } + auto properties = std::make_unique<VkLayerProperties[]>(num_instance_layers + num_device_layers); if (num_device_layers > 0) { result = enumerate_device_layers(VK_NULL_HANDLE, &num_device_layers, - properties + num_instance_layers); + properties.get() + num_instance_layers); if (result != VK_SUCCESS) { ALOGE( "vkEnumerateDeviceLayerProperties failed for library '%s': %d", @@ -321,21 +313,11 @@ bool LayerLibrary::EnumerateLayers(size_t library_idx, return true; } -void* LayerLibrary::GetGPA(const Layer& layer, - const char* gpa_name, - size_t gpa_name_len) const { - void* gpa; - size_t layer_name_len = - std::max(size_t{2}, strlen(layer.properties.layerName)); - char* name = static_cast<char*>(alloca(layer_name_len + gpa_name_len + 1)); - strcpy(name, layer.properties.layerName); - strcpy(name + layer_name_len, gpa_name); - if (!(gpa = GetTrampoline(name))) { - strcpy(name, "vk"); - strcpy(name + 2, gpa_name); - gpa = GetTrampoline(name); - } - return gpa; +void* LayerLibrary::GetGPA(const Layer& layer, const std::string_view gpa_name) const { + std::string layer_name { layer.properties.layerName }; + if (void* gpa = GetTrampoline((layer_name.append(gpa_name).c_str()))) + return gpa; + return GetTrampoline((std::string {"vk"}.append(gpa_name)).c_str()); } // ---------------------------------------------------------------------------- @@ -470,10 +452,9 @@ const VkExtensionProperties* FindExtension( } void* GetLayerGetProcAddr(const Layer& layer, - const char* gpa_name, - size_t gpa_name_len) { + const std::string_view gpa_name) { const LayerLibrary& library = g_layer_libraries[layer.library_idx]; - return library.GetGPA(layer, gpa_name, gpa_name_len); + return library.GetGPA(layer, gpa_name); } } // anonymous namespace @@ -556,13 +537,13 @@ LayerRef::LayerRef(LayerRef&& other) noexcept : layer_(other.layer_) { PFN_vkGetInstanceProcAddr LayerRef::GetGetInstanceProcAddr() const { return layer_ ? reinterpret_cast<PFN_vkGetInstanceProcAddr>( - GetLayerGetProcAddr(*layer_, "GetInstanceProcAddr", 19)) + GetLayerGetProcAddr(*layer_, "GetInstanceProcAddr")) : nullptr; } PFN_vkGetDeviceProcAddr LayerRef::GetGetDeviceProcAddr() const { return layer_ ? reinterpret_cast<PFN_vkGetDeviceProcAddr>( - GetLayerGetProcAddr(*layer_, "GetDeviceProcAddr", 17)) + GetLayerGetProcAddr(*layer_, "GetDeviceProcAddr")) : nullptr; } diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 5f4c6b1305..cc0df08835 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -1280,6 +1280,7 @@ VkResult CreateSwapchainKHR(VkDevice device, VkImageCreateInfo image_create = { .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .pNext = &image_native_buffer, + .flags = createProtectedSwapchain ? VK_IMAGE_CREATE_PROTECTED_BIT : 0u, .imageType = VK_IMAGE_TYPE_2D, .format = create_info->imageFormat, .extent = {0, 0, 1}, @@ -1288,7 +1289,6 @@ VkResult CreateSwapchainKHR(VkDevice device, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = create_info->imageUsage, - .flags = createProtectedSwapchain ? VK_IMAGE_CREATE_PROTECTED_BIT : 0u, .sharingMode = create_info->imageSharingMode, .queueFamilyIndexCount = create_info->queueFamilyIndexCount, .pQueueFamilyIndices = create_info->pQueueFamilyIndices, diff --git a/vulkan/tools/vkinfo.cpp b/vulkan/tools/vkinfo.cpp index 89bc926aa6..f9e4916722 100644 --- a/vulkan/tools/vkinfo.cpp +++ b/vulkan/tools/vkinfo.cpp @@ -195,10 +195,10 @@ void GatherGpuInfo(VkPhysicalDevice gpu, .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .queueCreateInfoCount = 1, .pQueueCreateInfos = &queue_create_info, - .enabledExtensionCount = num_extensions, - .ppEnabledExtensionNames = extensions, .enabledLayerCount = (options.validate) ? num_layers : 0, .ppEnabledLayerNames = kValidationLayers, + .enabledExtensionCount = num_extensions, + .ppEnabledExtensionNames = extensions, .pEnabledFeatures = &info.features, }; result = vkCreateDevice(gpu, &create_info, nullptr, &device); @@ -272,10 +272,10 @@ void GatherInfo(VulkanInfo* info, const Options& options) { const VkInstanceCreateInfo create_info = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &application_info, - .enabledExtensionCount = num_extensions, - .ppEnabledExtensionNames = extensions, .enabledLayerCount = (options.validate) ? num_layers : 0, .ppEnabledLayerNames = kValidationLayers, + .enabledExtensionCount = num_extensions, + .ppEnabledExtensionNames = extensions, }; VkInstance instance; result = vkCreateInstance(&create_info, nullptr, &instance); |