From 01e0a0a5bebd27fcfb836f133cfe1562d7de45cb Mon Sep 17 00:00:00 2001 From: Andrew Poole Date: Tue, 28 Mar 2023 10:05:10 +0100 Subject: [PATCH] vulkaninfo: Add Android build support VULKANINFO_WSI_ENABLED is currently disabled for Android as it is not possible to create an ANativeWindow for a native binary app using just the NDK. --- build-android/build_all.sh | 27 ++++++++++++++++++++++++++- vulkaninfo/android/.gitignore | 3 +++ vulkaninfo/android/jni/Android.mk | 28 ++++++++++++++++++++++++++++ vulkaninfo/android/jni/Application.mk | 22 ++++++++++++++++++++++ vulkaninfo/vulkaninfo.h | 29 +++++++++++++++++------------ 5 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 vulkaninfo/android/.gitignore create mode 100644 vulkaninfo/android/jni/Android.mk create mode 100644 vulkaninfo/android/jni/Application.mk diff --git a/build-android/build_all.sh b/build-android/build_all.sh index ecc4911..9f50245 100755 --- a/build-android/build_all.sh +++ b/build-android/build_all.sh @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +ANDROID_BUILD_DIR=$(dirname $(readlink -f $0)) +PROJECT_DIR=$ANDROID_BUILD_DIR/.. + if [ -z "${ANDROID_SDK_HOME}" ]; then echo "Please set ANDROID_SDK_HOME, exiting"; exit 1; else echo "ANDROID_SDK_HOME is ${ANDROID_SDK_HOME}"; @@ -44,7 +47,10 @@ findtool jarsigner set -ev -DEMO_BUILD_DIR=$PWD/../cube/android +VULKANINFO_BUILD_DIR=$PROJECT_DIR/vulkaninfo/android +echo VULKANINFO_BUILD_DIR="${VULKANINFO_BUILD_DIR}" + +DEMO_BUILD_DIR=$PROJECT_DIR/cube/android echo DEMO_BUILD_DIR="${DEMO_BUILD_DIR}" function create_APK() { @@ -54,7 +60,26 @@ function create_APK() { zipalign -f 4 bin/$1-unaligned.apk bin/$1.apk } +# +# update dependencies +# +( +pushd $ANDROID_BUILD_DIR ./update_external_sources_android.sh --no-build +popd +pushd $PROJECT_DIR +python3 scripts/generate_source.py $ANDROID_BUILD_DIR/third_party/Vulkan-Headers/registry --incremental +popd +) + +# +# build vulkaninfo +# +( +pushd $VULKANINFO_BUILD_DIR +ndk-build -j $cores +popd +) # # build vkcube APK diff --git a/vulkaninfo/android/.gitignore b/vulkaninfo/android/.gitignore new file mode 100644 index 0000000..8008f25 --- /dev/null +++ b/vulkaninfo/android/.gitignore @@ -0,0 +1,3 @@ +bin +libs +obj diff --git a/vulkaninfo/android/jni/Android.mk b/vulkaninfo/android/jni/Android.mk new file mode 100644 index 0000000..f3adbd5 --- /dev/null +++ b/vulkaninfo/android/jni/Android.mk @@ -0,0 +1,28 @@ +# Copyright 2015 The Android Open Source Project +# Copyright (C) 2015 Valve Corporation + +# 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. + +LOCAL_PATH := $(abspath $(call my-dir)) +SRC_DIR := $(LOCAL_PATH)/../../.. +VULKANINFO_DIR := $(SRC_DIR)/vulkaninfo + +include $(CLEAR_VARS) +LOCAL_MODULE := vulkaninfo +LOCAL_SRC_FILES += $(VULKANINFO_DIR)/vulkaninfo.cpp +LOCAL_C_INCLUDES += $(SRC_DIR)/build-android/third_party/Vulkan-Headers/include \ + $(VULKANINFO_DIR) \ + $(VULKANINFO_DIR)/generated +LOCAL_CFLAGS += -DVK_USE_PLATFORM_ANDROID_KHR -DVK_ENABLE_BETA_EXTENSIONS +LOCAL_LDLIBS := -llog -landroid +include $(BUILD_EXECUTABLE) diff --git a/vulkaninfo/android/jni/Application.mk b/vulkaninfo/android/jni/Application.mk new file mode 100644 index 0000000..c294bc5 --- /dev/null +++ b/vulkaninfo/android/jni/Application.mk @@ -0,0 +1,22 @@ +# Copyright 2015 The Android Open Source Project +# Copyright (C) 2015 Valve Corporation + +# 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. + +APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 +APP_PLATFORM := android-23 +APP_STL := c++_static +APP_MODULES := vulkaninfo +APP_CPPFLAGS += -std=c++11 -fexceptions -Wall -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers +APP_CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers +NDK_TOOLCHAIN_VERSION := clang diff --git a/vulkaninfo/vulkaninfo.h b/vulkaninfo/vulkaninfo.h index da7d647..d75a3ef 100644 --- a/vulkaninfo/vulkaninfo.h +++ b/vulkaninfo/vulkaninfo.h @@ -742,9 +742,18 @@ struct AppInstance { #if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \ defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_WAYLAND_KHR) || \ - defined(VK_USE_PLATFORM_DIRECTFB_EXT) || defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(VK_USE_PLATFORM_GGP) + defined(VK_USE_PLATFORM_DIRECTFB_EXT) || defined(VK_USE_PLATFORM_GGP) #define VULKANINFO_WSI_ENABLED #endif + +//----------------------------------------------------------- +#if defined(VULKANINFO_WSI_ENABLED) +static void AppDestroySurface(AppInstance &inst, VkSurfaceKHR surface) { // same for all platforms + inst.dll.fp_vkDestroySurfaceKHR(inst.instance, surface, nullptr); +} +#endif // defined(VULKANINFO_WSI_ENABLED) +//----------------------------------------------------------- + //---------------------------Win32--------------------------- #ifdef VK_USE_PLATFORM_WIN32_KHR @@ -816,13 +825,7 @@ static void AppDestroyWin32Window(AppInstance &inst) { user32_handles->pfnDestro #endif // VK_USE_PLATFORM_WIN32_KHR //----------------------------------------------------------- -#if defined(VULKANINFO_WSI_ENABLED) -static void AppDestroySurface(AppInstance &inst, VkSurfaceKHR surface) { // same for all platforms - inst.dll.fp_vkDestroySurfaceKHR(inst.instance, surface, nullptr); -} -#endif // defined(VULKANINFO_WSI_ENABLED) //----------------------------XCB---------------------------- - #ifdef VK_USE_PLATFORM_XCB_KHR static void AppCreateXcbWindow(AppInstance &inst) { //--Init Connection-- @@ -1078,10 +1081,12 @@ static VkSurfaceKHR AppCreateAndroidSurface(AppInstance &inst) { createInfo.flags = 0; createInfo.window = (struct ANativeWindow *)(inst.window); - err = inst.dll.fp_vkCreateAndroidSurfaceKHR(inst.inst, &createInfo, NULL, &inst.surface); - THROW_VK_ERR("vkCreateAndroidSurfaceKHR", err); + VkSurfaceKHR surface; + VkResult err = inst.dll.fp_vkCreateAndroidSurfaceKHR(inst.instance, &createInfo, NULL, &surface); + if (err) THROW_VK_ERR("vkCreateAndroidSurfaceKHR", err); + return surface; } -static VkSurfaceKHR AppDestroyAndroidSurface(AppInstance &inst) {} +static void AppDestroyAndroidWindow(AppInstance &inst) {} #endif //----------------------------------------------------------- //---------------------------GGP----------------------------- @@ -1213,8 +1218,8 @@ void SetupWindowExtensions(AppInstance &inst) { //--ANDROID-- #ifdef VK_USE_PLATFORM_ANDROID_KHR SurfaceExtension surface_ext_android; - if (inst.CheckExtensionEnabled(VK_ANDROID_SURFACE_EXTENSION_NAME)) { - surface_ext_android.name = VK_ANDROID_SURFACE_EXTENSION_NAME; + if (inst.CheckExtensionEnabled(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME)) { + surface_ext_android.name = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; surface_ext_android.create_window = AppCreateAndroidWindow; surface_ext_android.create_surface = AppCreateAndroidSurface; surface_ext_android.destroy_window = AppDestroyAndroidWindow; -- 2.7.4