From ce07b33c285a8af7edbb8d60123d3a0e79001cf8 Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Sat, 3 Oct 2020 10:55:53 +0100 Subject: [PATCH] Adding extra changes to make kompute work with older version of vulkan --- src/Algorithm.cpp | 12 +++--- src/CMakeLists.txt | 83 ++++++++++++++++++++++++++++-------- src/Manager.cpp | 2 +- src/include/kompute/Core.hpp | 17 +++++++- 4 files changed, 89 insertions(+), 25 deletions(-) diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 8748b10b6..6dea1c3d6 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -264,17 +264,17 @@ Algorithm::createPipeline(std::vector specializationData) &pipelineCacheInfo, nullptr, this->mPipelineCache.get()); this->mFreePipelineCache = true; - vk::ResultValue pipelineResult = + vk::Pipeline pipelineResult = this->mDevice->createComputePipeline(*this->mPipelineCache, pipelineInfo); this->mFreePipeline = true; - if (pipelineResult.result != vk::Result::eSuccess) { - throw std::runtime_error("Failed to create pipeline result: " + - vk::to_string(pipelineResult.result)); - } + //if (pipelineResult.result != vk::Result::eSuccess) { + // throw std::runtime_error("Failed to create pipeline result: " + + // vk::to_string(pipelineResult.result)); + //} this->mFreePipeline = true; - this->mPipeline = std::make_shared(pipelineResult.value); + this->mPipeline = std::make_shared(pipelineResult); } void diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b0c88185..570f7b40d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,13 @@ if(KOMPUTE_OPT_ENABLE_SPDLOG) find_package(fmt REQUIRED) endif() -find_package(Vulkan REQUIRED) +if(KOMPUTE_OPT_ANDOID_BUILD) + find_library(android android) +endif() + +if(NOT KOMPUTE_OPT_ANDOID_BUILD) + find_package(Vulkan REQUIRED) +endif() if(KOMPUTE_OPT_BUILD_SHADERS) # all shaders are compiled into cpp files @@ -23,8 +29,33 @@ file(GLOB kompute_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" ) +if(KOMPUTE_OPT_ANDOID_BUILD) + set(ANDROID_APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue) + set(VK_ANDROID_COMMON_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/common) + set(VK_ANDROID_PATCH_DIR ${PROJECT_SOURCE_DIR}/vulkan_ndk_patch_include/) + set(VK_ANDROID_INCLUDE_DIR ${ANDROID_NDK}/sources/third_party/vulkan/src/include) + + include_directories( + ${ANDROID_APP_GLUE_DIR} + ${VK_ANDROID_COMMON_DIR} + ${VK_ANDROID_PATCH_DIR} + ${VK_ANDROID_INCLUDE_DIR}) + + add_library(android_app_glue STATIC + ${ANDROID_APP_GLUE_DIR}/android_native_app_glue.c) + + #add_library(android_vulkan_wrapper STATIC + # ${VK_ANDROID_COMMON_DIR}/vulkan_wrapper.cpp) +endif() + +if(KOMPUTE_OPT_BUILD_SINGLE_HEADER) + add_library(kompute + ${kompute_CPP}) +endif() + add_library(kompute - ${kompute_CPP}) + ${kompute_CPP} + ${PROJECT_SOURCE_DIR}/vulkan_ndk_patch_include/kompute_vulkan_wrapper.cpp) target_include_directories( kompute PUBLIC @@ -32,10 +63,17 @@ target_include_directories( $ ) -target_link_libraries( - kompute - Vulkan::Vulkan -) +if(NOT KOMPUTE_OPT_ANDOID_BUILD) + target_link_libraries( + kompute + Vulkan::Vulkan + ) +else() + target_link_libraries( + kompute + "libvulkan.so" + ) +endif() if(KOMPUTE_OPT_ENABLE_SPDLOG) target_link_libraries( @@ -45,6 +83,15 @@ if(KOMPUTE_OPT_ENABLE_SPDLOG) ) endif() +if(KOMPUTE_OPT_ANDOID_BUILD) + target_link_libraries( + kompute + android_app_glue + log + android + ) +endif() + if(KOMPUTE_OPT_BUILD_SHADERS) add_dependencies(kompute build_shaders) @@ -57,18 +104,20 @@ endif() add_library(kompute::kompute ALIAS kompute) -install(TARGETS kompute EXPORT KomputeTargets - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - INCLUDES DESTINATION include) +if(KOMPUTE_OPT_INSTALL) + install(TARGETS kompute EXPORT KomputeTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + INCLUDES DESTINATION include) -install(DIRECTORY include/ DESTINATION include) + install(DIRECTORY include/ DESTINATION include) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/single_include/ - DESTINATION include) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/single_include/ + DESTINATION include) -install(EXPORT KomputeTargets - FILE komputeConfig.cmake - NAMESPACE kompute:: - DESTINATION lib/cmake/kompute) + install(EXPORT KomputeTargets + FILE komputeConfig.cmake + NAMESPACE kompute:: + DESTINATION lib/cmake/kompute) +endif() diff --git a/src/Manager.cpp b/src/Manager.cpp index b46b701a5..40c81b2de 100644 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -118,7 +118,7 @@ Manager::createInstance() vk::ApplicationInfo applicationInfo; applicationInfo.pApplicationName = "Vulkan Kompute"; applicationInfo.pEngineName = "VulkanKompute"; - applicationInfo.apiVersion = VK_API_VERSION_1_2; + applicationInfo.apiVersion = VK_API_VERSION_1_1; std::vector applicationExtensions; applicationExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); diff --git a/src/include/kompute/Core.hpp b/src/include/kompute/Core.hpp index 4f1174f3f..078e284c7 100644 --- a/src/include/kompute/Core.hpp +++ b/src/include/kompute/Core.hpp @@ -1,5 +1,20 @@ +#pragma once -#include +#if defined(VK_USE_PLATFORM_ANDROID_KHR) +#include +#include +#endif + +//#define VK_NO_PROTOTYPES 1 +//#undef VK_NO_PROTOTYPES +#undef DEBUG +#ifndef RELEASE +#define RELEASE 1 +#endif +//#define USE_DEBUG_EXTENTIONS +//#include + +//#undef VK_NO_PROTOTYPES #include // SPDLOG_ACTIVE_LEVEL must be defined before spdlog.h import