vulkaninfo: Add Android build support
authorAndrew Poole <a.poole@samsung.com>
Tue, 28 Mar 2023 09:05:10 +0000 (10:05 +0100)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Thu, 6 Apr 2023 16:18:16 +0000 (10:18 -0600)
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
vulkaninfo/android/.gitignore [new file with mode: 0644]
vulkaninfo/android/jni/Android.mk [new file with mode: 0644]
vulkaninfo/android/jni/Application.mk [new file with mode: 0644]
vulkaninfo/vulkaninfo.h

index ecc4911..9f50245 100755 (executable)
@@ -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 (file)
index 0000000..8008f25
--- /dev/null
@@ -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 (file)
index 0000000..f3adbd5
--- /dev/null
@@ -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 (file)
index 0000000..c294bc5
--- /dev/null
@@ -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
index da7d647..d75a3ef 100644 (file)
@@ -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;